0000-raspberry-pi.patch 3.6 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980979819798297983979849798597986979879798897989979909799197992979939799497995979969799797998979999800098001980029800398004980059800698007980089800998010980119801298013980149801598016980179801898019980209802198022980239802498025980269802798028980299803098031980329803398034980359803698037980389803998040980419804298043980449804598046980479804898049980509805198052980539805498055980569805798058980599806098061980629806398064980659806698067980689806998070980719807298073980749807598076980779807898079980809808198082980839808498085980869808798088980899809098091980929809398094980959809698097980989809998100981019810298103981049810598106981079810898109981109811198112981139811498115981169811798118981199812098121981229812398124981259812698127981289812998130981319813298133981349813598136981379813898139981409814198142981439814498145981469814798148981499815098151981529815398154981559815698157981589815998160981619816298163981649816598166981679816898169981709817198172981739817498175981769817798178981799818098181981829818398184981859818698187981889818998190981919819298193981949819598196981979819898199982009820198202982039820498205982069820798208982099821098211982129821398214982159821698217982189821998220982219822298223982249822598226982279822898229982309823198232982339823498235982369823798238982399824098241982429824398244982459824698247982489824998250982519825298253982549825598256982579825898259982609826198262982639826498265982669826798268982699827098271982729827398274982759827698277982789827998280982819828298283982849828598286982879828898289982909829198292982939829498295982969829798298982999830098301983029830398304983059830698307983089830998310983119831298313983149831598316983179831898319983209832198322983239832498325983269832798328983299833098331983329833398334983359833698337983389833998340983419834298343983449834598346983479834898349983509835198352983539835498355983569835798358983599836098361983629836398364983659836698367983689836998370983719837298373983749837598376983779837898379983809838198382983839838498385983869838798388983899839098391983929839398394983959839698397983989839998400984019840298403984049840598406984079840898409984109841198412984139841498415984169841798418984199842098421984229842398424984259842698427984289842998430984319843298433984349843598436984379843898439984409844198442984439844498445984469844798448984499845098451984529845398454984559845698457984589845998460984619846298463984649846598466984679846898469984709847198472984739847498475984769847798478984799848098481984829848398484984859848698487984889848998490984919849298493984949849598496984979849898499985009850198502985039850498505985069850798508985099851098511985129851398514985159851698517985189851998520985219852298523985249852598526985279852898529985309853198532985339853498535985369853798538985399854098541985429854398544985459854698547985489854998550985519855298553985549855598556985579855898559985609856198562985639856498565985669856798568985699857098571985729857398574985759857698577985789857998580985819858298583985849858598586985879858898589985909859198592985939859498595985969859798598985999860098601986029860398604986059860698607986089860998610986119861298613986149861598616986179861898619986209862198622986239862498625986269862798628986299863098631986329863398634986359863698637986389863998640986419864298643986449864598646986479864898649986509865198652986539865498655986569865798658986599866098661986629866398664986659866698667986689866998670986719867298673986749867598676986779867898679986809868198682986839868498685986869868798688986899869098691986929869398694986959869698697986989869998700987019870298703987049870598706987079870898709987109871198712987139871498715987169871798718987199872098721987229872398724987259872698727987289872998730987319873298733987349873598736987379873898739987409874198742987439874498745987469874798748987499875098751987529875398754987559875698757987589875998760987619876298763987649876598766987679876898769987709877198772987739877498775987769877798778987799878098781987829878398784987859878698787987889878998790987919879298793987949879598796987979879898799988009880198802988039880498805988069880798808988099881098811988129881398814988159881698817988189881998820988219882298823988249882598826988279882898829988309883198832988339883498835988369883798838988399884098841988429884398844988459884698847988489884998850988519885298853988549885598856988579885898859988609886198862988639886498865988669886798868988699887098871988729887398874988759887698877988789887998880988819888298883988849888598886988879888898889988909889198892988939889498895988969889798898988999890098901989029890398904989059890698907989089890998910989119891298913989149891598916989179891898919989209892198922989239892498925989269892798928989299893098931989329893398934989359893698937989389893998940989419894298943989449894598946989479894898949989509895198952989539895498955989569895798958989599896098961989629896398964989659896698967989689896998970989719897298973989749897598976989779897898979989809898198982989839898498985989869898798988989899899098991989929899398994989959899698997989989899999000990019900299003990049900599006990079900899009990109901199012990139901499015990169901799018990199902099021990229902399024990259902699027990289902999030990319903299033990349903599036990379903899039990409904199042990439904499045990469904799048990499905099051990529905399054990559905699057990589905999060990619906299063990649906599066990679906899069990709907199072990739907499075990769907799078990799908099081990829908399084990859908699087990889908999090990919909299093990949909599096990979909899099991009910199102991039910499105991069910799108991099911099111991129911399114991159911699117991189911999120991219912299123991249912599126991279912899129991309913199132991339913499135991369913799138991399914099141991429914399144991459914699147991489914999150991519915299153991549915599156991579915899159991609916199162991639916499165991669916799168991699917099171991729917399174991759917699177991789917999180991819918299183991849918599186991879918899189991909919199192991939919499195991969919799198991999920099201992029920399204992059920699207992089920999210992119921299213992149921599216992179921899219992209922199222992239922499225992269922799228992299923099231992329923399234992359923699237992389923999240992419924299243992449924599246992479924899249992509925199252992539925499255992569925799258992599926099261992629926399264992659926699267992689926999270992719927299273992749927599276992779927899279992809928199282992839928499285992869928799288992899929099291992929929399294992959929699297992989929999300993019930299303993049930599306993079930899309993109931199312993139931499315993169931799318993199932099321993229932399324993259932699327993289932999330993319933299333993349933599336993379933899339993409934199342993439934499345993469934799348993499935099351993529935399354993559935699357993589935999360993619936299363993649936599366993679936899369993709937199372993739937499375993769937799378993799938099381993829938399384993859938699387993889938999390993919939299393993949939599396993979939899399994009940199402994039940499405994069940799408994099941099411994129941399414994159941699417994189941999420994219942299423994249942599426994279942899429994309943199432994339943499435994369943799438994399944099441994429944399444994459944699447994489944999450994519945299453994549945599456994579945899459994609946199462994639946499465994669946799468994699947099471994729947399474994759947699477994789947999480994819948299483994849948599486994879948899489994909949199492994939949499495994969949799498994999950099501995029950399504995059950699507995089950999510995119951299513995149951599516995179951899519995209952199522995239952499525995269952799528995299953099531995329953399534995359953699537995389953999540995419954299543995449954599546995479954899549995509955199552995539955499555995569955799558995599956099561995629956399564995659956699567995689956999570995719957299573995749957599576995779957899579995809958199582995839958499585995869958799588995899959099591995929959399594995959959699597995989959999600996019960299603996049960599606996079960899609996109961199612996139961499615996169961799618996199962099621996229962399624996259962699627996289962999630996319963299633996349963599636996379963899639996409964199642996439964499645996469964799648996499965099651996529965399654996559965699657996589965999660996619966299663996649966599666996679966899669996709967199672996739967499675996769967799678996799968099681996829968399684996859968699687996889968999690996919969299693996949969599696996979969899699997009970199702997039970499705997069970799708997099971099711997129971399714997159971699717997189971999720997219972299723997249972599726997279972899729997309973199732997339973499735997369973799738997399974099741997429974399744997459974699747997489974999750997519975299753997549975599756997579975899759997609976199762997639976499765997669976799768997699977099771997729977399774997759977699777997789977999780997819978299783997849978599786997879978899789997909979199792997939979499795997969979799798997999980099801998029980399804998059980699807998089980999810998119981299813998149981599816998179981899819998209982199822998239982499825998269982799828998299983099831998329983399834998359983699837998389983999840998419984299843998449984599846998479984899849998509985199852998539985499855998569985799858998599986099861998629986399864998659986699867998689986999870998719987299873998749987599876998779987899879998809988199882998839988499885998869988799888998899989099891998929989399894998959989699897998989989999900999019990299903999049990599906999079990899909999109991199912999139991499915999169991799918999199992099921999229992399924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999100000100001100002100003100004100005100006100007100008100009100010100011100012100013100014100015100016100017100018100019100020100021100022100023100024100025100026100027100028100029100030100031100032100033100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054100055100056100057100058100059100060100061100062100063100064100065100066100067100068100069100070100071100072100073100074100075100076100077100078100079100080100081100082100083100084100085100086100087100088100089100090100091100092100093100094100095100096100097100098100099100100100101100102100103100104100105100106100107100108100109100110100111100112100113100114100115100116100117100118100119100120100121100122100123100124100125100126100127100128100129100130100131100132100133100134100135100136100137100138100139100140100141100142100143100144100145100146100147100148100149100150100151100152100153100154100155100156100157100158100159100160100161100162100163100164100165100166100167100168100169100170100171100172100173100174100175100176100177100178100179100180100181100182100183100184100185100186100187100188100189100190100191100192100193100194100195100196100197100198100199100200100201100202100203100204100205100206100207100208100209100210100211100212100213100214100215100216100217100218100219100220100221100222100223100224100225100226100227100228100229100230100231100232100233100234100235100236100237100238100239100240100241100242100243100244100245100246100247100248100249100250100251100252100253100254100255100256100257100258100259100260100261100262100263100264100265100266100267100268100269100270100271100272100273100274100275100276100277100278100279100280100281100282100283100284100285100286100287100288100289100290100291100292100293100294100295100296100297100298100299100300100301100302100303100304100305100306100307100308100309100310100311100312100313100314100315100316100317100318100319100320100321100322100323100324100325100326100327100328100329100330100331100332100333100334100335100336100337100338100339100340100341100342100343100344100345100346100347100348100349100350100351100352100353100354100355100356100357100358100359100360100361100362100363100364100365100366100367100368100369100370100371100372100373100374100375100376100377100378100379100380100381100382100383100384100385100386100387100388100389100390100391100392100393100394100395100396100397100398100399100400100401100402100403100404100405100406100407100408100409100410100411100412100413100414100415100416100417100418100419100420100421100422100423100424100425100426100427100428100429100430100431100432100433100434100435100436100437100438100439100440100441100442100443100444100445100446100447100448100449100450100451100452100453100454100455100456100457100458100459100460100461100462100463100464100465100466100467100468100469100470100471100472100473100474100475100476100477100478100479100480100481100482100483100484100485100486100487100488100489100490100491100492100493100494100495100496100497100498100499100500100501100502100503100504100505100506100507100508100509100510100511100512100513100514100515100516100517100518100519100520100521100522100523100524100525100526100527100528100529100530100531100532100533100534100535100536100537100538100539100540100541100542100543100544100545100546100547100548100549100550100551100552100553100554100555100556100557100558100559100560100561100562100563100564100565100566100567100568100569100570100571100572100573100574100575100576100577100578100579100580100581100582100583100584100585100586100587100588100589100590100591100592100593100594100595100596100597100598100599100600100601100602100603100604100605100606100607100608100609100610100611100612100613100614100615100616100617100618100619100620100621100622100623100624100625100626100627100628100629100630100631100632100633100634100635100636100637100638100639100640100641100642100643100644100645100646100647100648100649100650100651100652100653100654100655100656100657100658100659100660100661100662100663100664100665100666100667100668100669100670100671100672100673100674100675100676100677100678100679100680100681100682100683100684100685100686100687100688100689100690100691100692100693100694100695100696100697100698100699100700100701100702100703100704100705100706100707100708100709100710100711100712100713100714100715100716100717100718100719100720100721100722100723100724100725100726100727100728100729100730100731100732100733100734100735100736100737100738100739100740100741100742100743100744100745100746100747100748100749100750100751100752100753100754100755100756100757100758100759100760100761100762100763100764100765100766100767100768100769100770100771100772100773100774100775100776100777100778100779100780100781100782100783100784100785100786100787100788100789100790100791100792100793100794100795100796100797100798100799100800100801100802100803100804100805100806100807100808100809100810100811100812100813100814100815100816100817100818100819100820100821100822100823100824100825100826100827100828100829100830100831100832100833100834100835100836100837100838100839100840100841100842100843100844100845100846100847100848100849100850100851100852100853100854100855100856100857100858100859100860100861100862100863100864100865100866100867100868100869100870100871100872100873100874100875100876100877100878100879100880100881100882100883100884100885100886100887100888100889100890100891100892100893100894100895100896100897100898100899100900100901100902100903100904100905100906100907100908100909100910100911100912100913100914100915100916100917100918100919100920100921100922100923100924100925100926100927100928100929100930100931100932100933100934100935100936100937100938100939100940100941100942100943100944100945100946100947100948100949100950100951100952100953100954100955100956100957100958100959100960100961100962100963100964100965100966100967100968100969100970100971100972100973100974100975100976100977100978100979100980100981100982100983100984100985100986100987100988100989100990100991100992100993100994100995100996100997100998100999101000101001101002101003101004101005101006101007101008101009101010101011101012101013101014101015101016101017101018101019101020101021101022101023101024101025101026101027101028101029101030101031101032101033101034101035101036101037101038101039101040101041101042101043101044101045101046101047101048101049101050101051101052101053101054101055101056101057101058101059101060101061101062101063101064101065101066101067101068101069101070101071101072101073101074101075101076101077101078101079101080101081101082101083101084101085101086101087101088101089101090101091101092101093101094101095101096101097101098101099101100101101101102101103101104101105101106101107101108101109101110101111101112101113101114101115101116101117101118101119101120101121101122101123101124101125101126101127101128101129101130101131101132101133101134101135101136101137101138101139101140101141101142101143101144101145101146101147101148101149101150101151101152101153101154101155101156101157101158101159101160101161101162101163101164101165101166101167101168101169101170101171101172101173101174101175101176101177101178101179101180101181101182101183101184101185101186101187101188101189101190101191101192101193101194101195101196101197101198101199101200101201101202101203101204101205101206101207101208101209101210101211101212101213101214101215101216101217101218101219101220101221101222101223101224101225101226101227101228101229101230101231101232101233101234101235101236101237101238101239101240101241101242101243101244101245101246101247101248101249101250101251101252101253101254101255101256101257101258101259101260101261101262101263101264101265101266101267101268101269101270101271101272101273101274101275101276101277101278101279101280101281101282101283101284101285101286101287101288101289101290101291101292101293101294101295101296101297101298101299101300101301101302101303101304101305101306101307101308101309101310101311101312101313101314101315101316101317101318101319101320101321101322101323101324101325101326101327101328101329101330101331101332101333101334101335101336101337101338101339101340101341101342101343101344101345101346101347101348101349101350101351101352101353101354101355101356101357101358101359101360101361101362101363101364101365101366101367101368101369101370101371101372101373101374101375101376101377101378101379101380101381101382101383101384101385101386101387101388101389101390101391101392101393101394101395101396101397101398101399101400101401101402101403101404101405101406101407101408101409101410101411101412101413101414101415101416101417101418101419101420101421101422101423101424101425101426101427101428101429101430101431101432101433101434101435101436101437101438101439101440101441101442101443101444101445101446101447101448101449101450101451101452101453101454101455101456101457101458101459101460101461101462101463101464101465101466101467101468101469101470101471101472101473101474101475101476101477101478101479101480101481101482101483101484101485101486101487101488101489101490101491101492101493101494101495101496101497101498101499101500101501101502101503101504101505101506101507101508101509101510101511101512101513101514101515101516101517101518101519101520101521101522101523101524101525101526101527101528101529101530101531101532101533101534101535101536101537101538101539101540101541101542101543101544101545101546101547101548101549101550101551101552101553101554101555101556101557101558101559101560101561101562101563101564101565101566101567101568101569101570101571101572101573101574101575101576101577101578101579101580101581101582101583101584101585101586101587101588101589101590101591101592101593101594101595101596101597101598101599101600101601101602101603101604101605101606101607101608101609101610101611101612101613101614101615101616101617101618101619101620101621101622101623101624101625101626101627101628101629101630101631101632101633101634101635101636101637101638101639101640101641101642101643101644101645101646101647101648101649101650101651101652101653101654101655101656101657101658101659101660101661101662101663101664101665101666101667101668101669101670101671101672101673101674101675101676101677101678101679101680101681101682101683101684101685101686101687101688101689101690101691101692101693101694101695101696101697101698101699101700101701101702101703101704101705101706101707101708101709101710101711101712101713101714101715101716101717101718101719101720101721101722101723101724101725101726101727101728101729101730101731101732101733101734101735101736101737101738101739101740101741101742101743101744101745101746101747101748101749101750101751101752101753101754101755101756101757101758101759101760101761101762101763101764101765101766101767101768101769101770101771101772101773101774101775101776101777101778101779101780101781101782101783101784101785101786101787101788101789101790101791101792101793101794101795101796101797101798101799101800101801101802101803101804101805101806101807101808101809101810101811101812101813101814101815101816101817101818101819101820101821101822101823101824101825101826101827101828101829101830101831101832101833101834101835101836101837101838101839101840101841101842101843101844101845101846101847101848101849101850101851101852101853101854101855101856101857101858101859101860101861101862101863101864101865101866101867101868101869101870101871101872101873101874101875101876101877101878101879101880101881101882101883101884101885101886101887101888101889101890101891101892101893101894101895101896101897101898101899101900101901101902101903101904101905101906101907101908101909101910101911101912101913101914101915101916101917101918101919101920101921101922101923101924101925101926101927101928101929101930101931101932101933101934101935101936101937101938101939101940101941101942101943101944101945101946101947101948101949101950101951101952101953101954101955101956101957101958101959101960101961101962101963101964101965101966101967101968101969101970101971101972101973101974101975101976101977101978101979101980101981101982101983101984101985101986101987101988101989101990101991101992101993101994101995101996101997101998101999102000102001102002102003102004102005102006102007102008102009102010102011102012102013102014102015102016102017102018102019102020102021102022102023102024102025102026102027102028102029102030102031102032102033102034102035102036102037102038102039102040102041102042102043102044102045102046102047102048102049102050102051102052102053102054102055102056102057102058102059102060102061102062102063102064102065102066102067102068102069102070102071102072102073102074102075102076102077102078102079102080102081102082102083102084102085102086102087102088102089102090102091102092102093102094102095102096102097102098102099102100102101102102102103102104102105102106102107102108102109102110102111102112102113102114102115102116102117102118102119102120102121102122102123102124102125102126102127102128102129102130102131102132102133102134102135102136102137102138102139102140102141102142102143102144102145102146102147102148102149102150102151102152102153102154102155102156102157102158102159102160102161102162102163102164102165102166102167102168102169102170102171102172102173102174102175102176102177102178102179102180102181102182102183102184102185102186102187102188102189102190102191102192102193102194102195102196102197102198102199102200102201102202102203102204102205102206102207102208102209102210102211102212102213102214102215102216102217102218102219102220102221102222102223102224102225102226102227102228102229102230102231102232102233102234102235102236102237102238102239102240102241102242102243102244102245102246102247102248102249102250102251102252102253102254102255102256102257102258102259102260102261102262102263102264102265102266102267102268102269102270102271102272102273102274102275102276102277102278102279102280102281102282102283102284102285102286102287102288102289102290102291102292102293102294102295102296102297102298102299102300102301102302102303102304102305102306102307102308102309102310102311102312102313102314102315102316102317102318102319102320102321102322102323102324102325102326102327102328102329102330102331102332102333102334102335102336102337102338102339102340102341102342102343102344102345102346102347102348102349102350102351102352102353102354102355102356102357102358102359102360102361102362102363102364102365102366102367102368102369102370102371102372102373102374102375102376102377102378102379102380102381102382102383102384102385102386102387102388102389102390102391102392102393102394102395102396102397102398102399102400102401102402102403102404102405102406102407102408102409102410102411102412102413102414102415102416102417102418102419102420102421102422102423102424102425102426102427102428102429102430102431102432102433102434102435102436102437102438102439102440102441102442102443102444102445102446102447102448102449102450102451102452102453102454102455102456102457102458102459102460102461102462102463102464102465102466102467102468102469102470102471102472102473102474102475102476102477102478102479102480102481102482102483102484102485102486102487102488102489102490102491102492102493102494102495102496102497102498102499102500102501102502102503102504102505102506102507102508102509102510102511102512102513102514102515102516102517102518102519102520102521102522102523102524102525102526102527102528102529102530102531102532102533102534102535102536102537102538102539102540102541102542102543102544102545102546102547102548102549102550102551102552102553102554102555102556102557102558102559102560102561102562102563102564102565102566102567102568102569102570102571102572102573102574102575102576102577102578102579102580102581102582102583102584102585102586102587102588102589102590102591102592102593102594102595102596102597102598102599102600102601102602102603102604102605102606102607102608102609102610102611102612102613102614102615102616102617102618102619102620102621102622102623102624102625102626102627102628102629102630102631102632102633102634102635102636102637102638102639102640102641102642102643102644102645102646102647102648102649102650102651102652102653102654102655102656102657102658102659102660102661102662102663102664102665102666102667102668102669102670102671102672102673102674102675102676102677102678102679102680102681102682102683102684102685102686102687102688102689102690102691102692102693102694102695102696102697102698102699102700102701102702102703102704102705102706102707102708102709102710102711102712102713102714102715102716102717102718102719102720102721102722102723102724102725102726102727102728102729102730102731102732102733102734102735102736102737102738102739102740102741102742102743102744102745102746102747102748102749102750102751102752102753102754102755102756102757102758102759102760102761102762102763102764102765102766102767102768102769102770102771102772102773102774102775102776102777102778102779102780102781102782102783102784102785102786102787102788102789102790102791102792102793102794102795102796102797102798102799102800102801102802102803102804102805102806102807102808102809102810102811102812102813102814102815102816102817102818102819102820102821102822102823102824102825102826102827102828102829102830102831102832102833102834102835102836102837102838102839102840102841102842102843102844102845102846102847102848102849102850102851102852102853102854102855102856102857102858102859102860102861102862102863102864102865102866102867102868102869102870102871102872102873102874102875102876102877102878102879102880102881102882102883102884102885102886102887102888102889102890102891102892102893102894102895102896102897102898102899102900102901102902102903102904102905102906102907102908102909102910102911102912102913102914102915102916102917102918102919102920102921102922102923102924102925102926102927102928102929102930102931102932102933102934102935102936102937102938102939102940102941102942102943102944102945102946102947102948102949102950102951102952102953102954102955102956102957102958102959102960102961102962102963102964102965102966102967102968102969102970102971102972102973102974102975102976102977102978102979102980102981102982102983102984102985102986102987102988102989102990102991102992102993102994102995102996102997102998102999103000103001103002103003103004103005103006103007103008103009103010103011103012103013103014103015103016103017103018103019103020103021103022103023103024103025103026103027103028103029103030103031103032103033103034103035103036103037103038103039103040103041103042103043103044103045103046103047103048103049103050103051103052103053103054103055103056103057103058103059103060103061103062103063103064103065103066103067103068103069103070103071103072103073103074103075103076103077103078103079103080103081103082103083103084103085103086103087103088103089103090103091103092103093103094103095103096103097103098103099103100103101103102103103103104103105103106103107103108103109103110103111103112103113103114103115103116103117103118103119103120103121103122103123103124103125103126103127103128103129103130103131103132103133103134103135103136103137103138103139103140103141103142103143103144103145103146103147103148103149103150103151103152103153103154103155103156103157103158103159103160103161103162103163103164103165103166103167103168103169103170103171103172103173103174103175103176103177103178103179103180103181103182103183103184103185103186103187103188103189103190103191103192103193103194103195103196103197103198103199103200103201103202103203103204103205103206103207103208103209103210103211103212103213103214103215103216103217103218103219103220103221103222103223103224103225103226103227103228103229103230103231103232103233103234103235103236103237103238103239103240103241103242103243103244103245103246103247103248103249103250103251103252103253103254103255103256103257103258103259103260103261103262103263103264103265103266103267103268103269103270103271103272103273103274103275103276103277103278103279103280103281103282103283103284103285103286103287103288103289103290103291103292103293103294103295103296103297103298103299103300103301103302103303103304103305103306103307103308103309103310103311103312103313103314103315103316103317103318103319103320103321103322103323103324103325103326103327103328103329103330103331103332103333103334103335103336103337103338103339103340103341103342103343103344103345103346103347103348103349103350103351103352103353103354103355103356103357103358103359103360103361103362103363103364103365103366103367103368103369103370103371103372103373103374103375103376103377103378103379103380103381103382103383103384103385103386103387103388103389103390103391103392103393103394103395103396103397103398103399103400103401103402103403103404103405103406103407103408103409103410103411103412103413103414103415103416103417103418103419103420103421103422103423103424103425103426103427103428103429103430103431103432103433103434103435103436103437103438103439103440103441103442103443103444103445103446103447103448103449103450103451103452103453103454103455103456103457103458103459103460103461103462103463103464103465103466103467103468103469103470103471103472103473103474103475103476103477103478103479103480103481103482103483103484103485103486103487103488103489103490103491103492103493103494103495103496103497103498103499103500103501103502103503103504103505103506103507103508103509103510103511103512103513103514103515103516103517103518103519103520103521103522103523103524103525103526103527103528103529103530103531103532103533103534103535103536103537103538103539103540103541103542103543103544103545103546103547103548103549103550103551103552103553103554103555103556103557103558103559103560103561103562103563103564103565103566103567103568103569103570103571103572103573103574103575103576103577103578103579103580103581103582103583103584103585103586103587103588103589103590103591103592103593103594103595103596103597103598103599103600103601103602103603103604103605103606103607103608103609103610103611103612103613103614103615103616103617103618103619103620103621103622103623103624103625103626103627103628103629103630103631103632103633103634103635103636103637103638103639103640103641103642103643103644103645103646103647103648103649103650103651103652103653103654103655103656103657103658103659103660103661103662103663103664103665103666103667103668103669103670103671103672103673103674103675103676103677103678103679103680103681103682103683103684103685103686103687103688103689103690103691103692103693103694103695103696103697103698103699103700103701103702103703103704103705103706103707103708103709103710103711103712103713103714103715103716103717103718103719103720103721103722103723103724103725103726103727103728103729103730103731103732103733103734103735103736103737103738103739103740103741103742103743103744103745103746103747103748103749103750103751103752103753103754103755103756103757103758103759103760103761103762103763103764103765103766103767103768103769103770103771103772103773103774103775103776103777103778103779103780103781103782103783103784103785103786103787103788103789103790103791103792103793103794103795103796103797103798103799103800103801103802103803103804103805103806103807103808103809103810103811103812103813103814103815103816103817103818103819103820103821103822103823103824103825103826103827103828103829103830103831103832103833103834103835103836103837103838103839103840103841103842103843103844103845103846103847103848103849103850103851103852103853103854103855103856103857103858103859103860103861103862103863103864103865103866103867103868103869103870103871103872103873103874103875103876103877103878103879103880103881103882103883103884103885103886103887103888103889103890103891103892103893103894103895103896103897103898103899103900103901103902103903103904103905103906103907103908103909103910103911103912103913103914103915103916103917103918103919103920103921103922103923103924103925103926103927103928103929103930103931103932103933103934103935103936103937103938103939103940103941103942103943103944103945103946103947103948103949103950103951103952103953103954103955103956103957103958103959103960103961103962103963103964103965103966103967103968103969103970103971103972103973103974103975103976103977103978103979103980103981103982103983103984103985103986103987103988103989103990103991103992103993103994103995103996103997103998103999104000104001104002104003104004104005104006104007104008104009104010104011104012104013104014104015104016104017104018104019104020104021104022104023104024104025104026104027104028104029104030104031104032104033104034104035104036104037104038104039104040104041104042104043104044104045104046104047104048104049104050104051104052104053104054104055104056104057104058104059104060104061104062104063104064104065104066104067104068104069104070104071104072104073104074104075104076104077104078104079104080104081104082104083104084104085104086104087104088104089104090104091104092104093104094104095104096104097104098104099104100104101104102104103104104104105104106104107104108104109104110104111104112104113104114104115104116104117104118104119104120104121104122104123104124104125104126104127104128104129104130104131104132104133104134104135104136104137104138104139104140104141104142104143104144104145104146104147104148104149104150104151104152104153104154104155104156104157104158104159104160104161104162104163104164104165104166104167104168104169104170104171104172104173104174104175104176104177104178104179104180104181104182104183104184104185104186104187104188104189104190104191104192104193104194104195104196104197104198104199104200104201104202104203104204104205104206104207104208104209104210104211104212104213104214104215104216104217104218104219104220104221104222104223104224104225104226104227104228104229104230104231104232104233104234104235104236104237104238104239104240104241104242104243104244104245104246104247104248104249104250104251104252104253104254104255104256104257104258104259104260104261104262104263104264104265104266104267104268104269104270104271104272104273104274104275104276104277104278104279104280104281104282104283104284104285104286104287104288104289104290104291104292104293104294104295104296104297104298104299104300104301104302104303104304104305104306104307104308104309104310104311104312104313104314104315104316104317104318104319104320104321104322104323104324104325104326104327104328104329104330104331104332104333104334104335104336104337104338104339104340104341104342104343104344104345104346104347104348104349104350104351104352104353104354104355104356104357104358104359104360104361104362104363104364104365104366104367104368104369104370104371104372104373104374104375104376104377104378104379104380104381104382104383104384104385104386104387104388104389104390104391104392104393104394104395104396104397104398104399104400104401104402104403104404104405104406104407104408104409104410104411104412104413104414104415104416104417104418104419104420104421104422104423104424104425104426104427104428104429104430104431104432104433104434104435104436104437104438104439104440104441104442104443104444104445104446104447104448104449104450104451104452104453104454104455104456104457104458104459104460104461104462104463104464104465104466104467104468104469104470104471104472104473104474104475104476104477104478104479104480104481104482104483104484104485104486104487104488104489104490104491104492104493104494104495104496104497104498104499104500104501104502104503104504104505104506104507104508104509104510104511104512104513104514104515104516104517104518104519104520104521104522104523104524104525104526104527104528104529104530104531104532104533104534104535104536104537104538104539104540104541104542104543104544104545104546104547104548104549104550104551104552104553104554104555104556104557104558104559104560104561104562104563104564104565104566104567104568104569104570104571104572104573104574104575104576104577104578104579104580104581104582104583104584104585104586104587104588104589104590104591104592104593104594104595104596104597104598104599104600104601104602104603104604104605104606104607104608104609104610104611104612104613104614104615104616104617104618104619104620104621104622104623104624104625104626104627104628104629104630104631104632104633104634104635104636104637104638104639104640104641104642104643104644104645104646104647104648104649104650104651104652104653104654104655104656104657104658104659104660104661104662104663104664104665104666104667104668104669104670104671104672104673104674104675104676104677104678104679104680104681104682104683104684104685104686104687104688104689104690104691104692104693104694104695104696104697104698104699104700104701104702104703104704104705104706104707104708104709104710104711104712104713104714104715104716104717104718104719104720104721104722104723104724104725104726104727104728104729104730104731104732104733104734104735104736104737104738104739104740104741104742104743104744104745104746104747104748104749104750104751104752104753104754104755104756104757104758104759104760104761104762104763104764104765104766104767104768104769104770104771104772104773104774104775104776104777104778104779104780104781104782104783104784104785104786104787104788104789104790104791104792104793104794104795104796104797104798104799104800104801104802104803104804104805104806104807104808104809104810104811104812104813104814104815104816104817104818104819104820104821104822104823104824104825104826104827104828104829104830104831104832104833104834104835104836104837104838104839104840104841104842104843104844104845104846104847104848104849104850104851104852104853104854104855104856104857104858104859104860104861104862104863104864104865104866104867104868104869104870104871104872104873104874104875104876104877104878104879104880104881104882104883104884104885104886104887104888104889104890104891104892104893104894104895104896104897104898104899104900104901104902104903104904104905104906104907104908104909104910104911104912104913104914104915104916104917104918104919104920104921104922104923104924104925104926104927104928104929104930104931104932104933104934104935104936104937104938104939104940104941104942104943104944104945104946104947104948104949104950104951104952104953104954104955104956104957104958104959104960104961104962104963104964104965104966104967104968104969104970104971104972104973104974104975104976104977104978104979104980104981104982104983104984104985104986104987104988104989104990104991104992104993104994104995104996104997104998104999105000105001105002105003105004105005105006105007105008105009105010105011105012105013105014105015105016105017105018105019105020105021105022105023105024105025105026105027105028105029105030105031105032105033105034105035105036105037105038105039105040105041105042105043105044105045105046105047105048105049105050105051105052105053105054105055105056105057105058105059105060105061105062105063105064105065105066105067105068105069105070105071105072105073105074105075105076105077105078105079105080105081105082105083105084105085105086105087105088105089105090105091105092105093105094105095105096105097105098105099105100105101105102105103105104105105105106105107105108105109105110105111105112105113105114105115105116105117105118105119105120105121105122105123105124105125105126105127105128105129105130105131105132105133105134105135105136105137105138105139105140105141105142105143105144105145105146105147105148105149105150105151105152105153105154105155105156105157105158105159105160105161105162105163105164105165105166105167105168105169105170105171105172105173105174105175105176105177105178105179105180105181105182105183105184105185105186105187105188105189105190105191105192105193105194105195105196105197105198105199105200105201105202105203105204105205105206105207105208105209105210105211105212105213105214105215105216105217105218105219105220105221105222105223105224105225105226105227105228105229105230105231105232105233105234105235105236105237105238105239105240105241105242105243105244105245105246105247105248105249105250105251105252105253105254105255105256105257105258105259105260105261105262105263105264105265105266105267105268105269105270105271105272105273105274105275105276105277105278105279105280105281105282105283105284105285105286105287105288105289105290105291105292105293105294105295105296105297105298105299105300105301105302105303105304105305105306105307105308105309105310105311105312105313105314105315105316105317105318105319105320105321105322105323105324105325105326105327105328105329105330105331105332105333105334105335105336105337105338105339105340105341105342105343105344105345105346105347105348105349105350105351105352105353105354105355105356105357105358105359105360105361105362105363105364105365105366105367105368105369105370105371105372105373105374105375105376105377105378105379105380105381105382105383105384105385105386105387105388105389105390105391105392105393105394105395105396105397105398105399105400105401105402105403105404105405105406105407105408105409105410105411105412105413105414105415105416105417105418105419105420105421105422105423105424105425105426105427105428105429105430105431105432105433105434105435105436105437105438105439105440105441105442105443105444105445105446105447105448105449105450105451105452105453105454105455105456105457105458105459105460105461105462105463105464105465105466105467105468105469105470105471105472105473105474105475105476105477105478105479105480105481105482105483105484105485105486105487105488105489105490105491105492105493105494105495105496105497105498105499105500105501105502105503105504105505105506105507105508105509105510105511105512105513105514105515105516105517105518105519105520105521105522105523105524105525105526105527105528105529105530105531105532105533105534105535105536105537105538105539105540105541105542105543105544105545105546105547105548105549105550105551105552105553105554105555105556105557105558105559105560105561105562105563105564105565105566105567105568105569105570105571105572105573105574105575105576105577105578105579105580105581105582105583105584105585105586105587105588105589105590105591105592105593105594105595105596105597105598105599105600105601105602105603105604105605105606105607105608105609105610105611105612105613105614105615105616105617105618105619105620105621105622105623105624105625105626105627105628105629105630105631105632105633105634105635105636105637105638105639105640105641105642105643105644105645105646105647105648105649105650105651105652105653105654105655105656105657105658105659105660105661105662105663105664105665105666105667105668105669105670105671105672105673105674105675105676105677105678105679105680105681105682105683105684105685105686105687105688105689105690105691105692105693105694105695105696105697105698105699105700105701105702105703105704105705105706105707105708105709105710105711105712105713105714105715105716105717105718105719105720105721105722105723105724105725105726105727105728105729105730105731105732105733105734105735105736105737105738105739105740105741105742105743105744105745105746105747105748105749105750105751105752105753105754105755105756105757105758105759105760105761105762105763105764105765105766105767105768105769105770105771105772105773105774105775105776105777105778105779105780105781105782105783105784105785105786105787105788105789105790105791105792105793105794105795105796105797105798105799105800105801105802105803105804105805105806105807105808105809105810105811105812105813105814105815105816105817105818105819105820105821105822105823105824105825105826105827105828105829105830105831105832105833105834105835105836105837105838105839105840105841105842105843105844105845105846105847105848105849105850105851105852105853105854105855105856105857105858105859105860105861105862105863105864105865105866105867105868105869105870105871105872105873105874105875105876105877105878105879105880105881105882105883105884105885105886105887105888105889105890105891105892105893105894105895105896105897105898105899105900105901105902105903105904105905105906105907105908105909105910105911105912105913105914105915105916105917105918105919105920105921105922105923105924105925105926105927105928105929105930105931105932105933105934105935105936105937105938105939105940105941105942105943105944105945105946105947105948105949105950105951105952105953105954105955105956105957105958105959105960105961105962105963105964105965105966105967105968105969105970105971105972105973105974105975105976105977105978105979105980105981105982105983105984105985105986105987105988105989105990105991105992105993105994105995105996105997105998105999106000106001106002106003106004106005106006106007106008106009106010106011106012106013106014106015106016106017106018106019106020106021106022106023106024106025106026106027106028106029106030106031106032106033106034106035106036106037106038106039106040106041106042106043106044106045106046106047106048106049106050106051106052106053106054106055106056106057106058106059106060106061106062106063106064106065106066106067106068106069106070106071106072106073106074106075106076106077106078106079106080106081106082106083106084106085106086106087106088106089106090106091106092106093106094106095106096106097106098106099106100106101106102106103106104106105106106106107106108106109106110106111106112106113106114106115106116106117106118106119106120106121106122106123106124106125106126106127106128106129106130106131106132106133106134106135106136106137106138106139106140106141106142106143106144106145106146106147106148106149106150106151106152106153106154106155106156106157106158106159106160106161106162106163106164106165106166106167106168106169106170106171106172106173106174106175106176106177106178106179106180106181106182106183106184106185106186106187106188106189106190106191106192106193106194106195106196106197106198106199106200106201106202106203106204106205106206106207106208106209106210106211106212106213106214106215106216106217106218106219106220106221106222106223106224106225106226106227106228106229106230106231106232106233106234106235106236106237106238106239106240106241106242106243106244106245106246106247106248106249106250106251106252106253106254106255106256106257106258106259106260106261106262106263106264106265106266106267106268106269106270106271106272106273106274106275106276106277106278106279106280106281106282106283106284106285106286106287106288106289106290106291106292106293106294106295106296106297106298106299106300106301106302106303106304106305106306106307106308106309106310106311106312106313106314106315106316106317106318106319106320106321106322106323106324106325106326106327106328106329106330106331106332106333106334106335106336106337106338106339106340106341106342106343106344106345106346106347106348106349106350106351106352106353106354106355106356106357106358106359106360106361106362106363106364106365106366106367106368106369106370106371106372106373106374106375106376106377106378106379106380106381106382106383106384106385106386106387106388106389106390106391106392106393106394106395106396106397106398106399106400106401106402106403106404106405106406106407106408106409106410106411106412106413106414106415106416106417106418106419106420106421106422106423106424106425106426106427106428106429106430106431106432106433106434106435106436106437106438106439106440106441106442106443106444106445106446106447106448106449106450106451106452106453106454106455106456106457106458106459106460106461106462106463106464106465106466106467106468106469106470106471106472106473106474106475106476106477106478106479106480106481106482106483106484106485106486106487106488106489106490106491106492106493106494106495106496106497106498106499106500106501106502106503106504106505106506106507106508106509106510106511106512106513106514106515106516106517106518106519106520106521106522106523106524106525106526106527106528106529106530106531106532106533106534106535106536106537106538106539106540106541106542106543106544106545106546106547106548106549106550106551106552106553106554106555106556106557106558106559106560106561106562106563106564106565106566106567106568106569106570106571106572106573106574106575106576106577106578106579106580106581106582106583106584106585106586106587106588106589106590106591106592106593106594106595106596106597106598106599106600106601106602106603106604106605106606106607106608106609106610106611106612106613106614106615106616106617106618106619106620106621106622106623106624106625106626106627106628106629106630106631106632106633106634106635106636106637106638106639106640106641106642106643106644106645106646106647106648106649106650106651106652106653106654106655106656106657106658106659106660106661106662106663106664106665106666106667106668106669106670106671106672106673106674106675106676106677106678106679106680106681106682106683106684106685106686106687106688106689106690106691106692106693106694106695106696106697106698106699106700106701106702106703106704106705106706106707106708106709106710106711106712106713106714106715106716106717106718106719106720106721106722106723106724106725106726106727106728106729106730106731106732106733106734106735106736106737106738106739106740106741106742106743106744106745106746106747106748106749106750106751106752106753106754106755106756106757106758106759106760106761106762106763106764106765106766106767106768106769106770106771106772106773106774106775106776106777106778106779106780106781106782106783106784106785106786106787106788106789106790106791106792106793106794106795106796106797106798106799106800106801106802106803106804106805106806106807106808106809106810106811106812106813106814106815106816106817106818106819106820106821106822106823106824106825106826106827106828106829106830106831106832106833106834106835106836106837106838106839106840106841106842106843106844106845106846106847106848106849106850106851106852106853106854106855106856106857106858106859106860106861106862106863106864106865106866106867106868106869106870106871106872106873106874106875106876106877106878106879106880106881106882106883106884106885106886106887106888106889106890106891106892106893106894106895106896106897106898106899106900106901106902106903106904106905106906106907106908106909106910106911106912106913106914106915106916106917106918106919106920106921106922106923106924106925106926106927106928106929106930106931106932106933106934106935106936106937106938106939106940106941106942106943106944106945106946106947106948106949106950106951106952106953106954106955106956106957106958106959106960106961106962106963106964106965106966106967106968106969106970106971106972106973106974106975106976106977106978106979106980106981106982106983106984106985106986106987106988106989106990106991106992106993106994106995106996106997106998106999107000107001107002107003107004107005107006107007107008107009107010107011107012107013107014107015107016107017107018107019107020107021107022107023107024107025107026107027107028107029107030107031107032107033107034107035107036107037107038107039107040107041107042107043107044107045107046107047107048107049107050107051107052107053107054107055107056107057107058107059107060107061107062107063107064107065107066107067107068107069107070107071107072107073107074107075107076107077107078107079107080107081107082107083107084107085107086107087107088107089107090107091107092107093107094107095107096107097107098107099107100107101107102107103107104107105107106107107107108107109107110107111107112107113107114107115107116107117107118107119107120107121107122107123107124107125107126107127107128107129107130107131107132107133107134107135107136107137107138107139107140107141107142107143107144107145107146107147107148107149107150107151107152107153107154107155107156107157107158107159107160107161107162107163107164107165107166107167107168107169107170107171107172107173107174107175107176107177107178107179107180107181107182107183107184107185107186107187107188107189107190107191107192107193107194107195107196107197107198107199107200107201107202107203107204107205107206107207107208107209107210107211107212107213107214107215107216107217107218107219107220107221107222107223107224107225107226107227107228107229107230107231107232107233107234107235107236107237107238107239107240107241107242107243107244107245107246107247107248107249107250107251107252107253107254107255107256107257107258107259107260107261107262107263107264107265107266107267107268107269107270107271107272107273107274107275107276107277107278107279107280107281107282107283107284107285107286107287107288107289107290107291107292107293107294107295107296107297107298107299107300107301107302107303107304107305107306107307107308107309107310107311107312107313107314107315107316107317107318107319107320107321107322107323107324107325107326107327107328107329107330107331107332107333107334107335107336107337107338107339107340107341107342107343107344107345107346107347107348107349107350107351107352107353107354107355107356107357107358107359107360107361107362107363107364107365107366107367107368107369107370107371107372107373107374107375107376107377107378107379107380107381107382107383107384107385107386107387107388107389107390107391107392107393107394107395107396107397107398107399107400107401107402107403107404107405107406107407107408107409107410107411107412107413107414107415107416107417107418107419107420107421107422107423107424107425107426107427107428107429107430107431107432107433107434107435107436107437107438107439107440107441107442107443107444107445107446107447107448107449107450107451107452107453107454107455107456107457107458107459107460107461107462107463107464107465107466107467107468107469107470107471107472107473107474107475107476107477107478107479107480107481107482107483107484107485107486107487107488107489107490107491107492107493107494107495107496107497107498107499107500107501107502107503107504107505107506107507107508107509107510107511107512107513107514107515107516107517107518107519107520107521107522107523107524107525107526107527107528107529107530107531107532107533107534107535107536107537107538107539107540107541107542107543107544107545107546107547107548107549107550107551107552107553107554107555107556107557107558107559107560107561107562107563107564107565107566107567107568107569107570107571107572107573107574107575107576107577107578107579107580107581107582107583107584107585107586107587107588107589107590107591107592107593107594107595107596107597107598107599107600107601107602107603107604107605107606107607107608107609107610107611107612107613107614107615107616107617107618107619107620107621107622107623107624107625107626107627107628107629107630107631107632107633107634107635107636107637107638107639107640107641107642107643107644107645107646107647107648107649107650107651107652107653107654107655107656107657107658107659107660107661107662107663107664107665107666107667107668107669107670107671107672107673107674107675107676107677107678107679107680107681107682107683107684107685107686107687107688107689107690107691107692107693107694107695107696107697107698107699107700107701107702107703107704107705107706107707107708107709107710107711107712107713107714107715107716107717107718107719107720107721107722107723107724107725107726107727107728107729107730107731107732107733107734107735107736107737107738107739107740107741107742107743107744107745107746107747107748107749107750107751107752107753107754107755107756107757107758107759107760107761107762107763107764107765107766107767107768107769107770107771107772107773107774107775107776107777107778107779107780107781107782107783107784107785107786107787107788107789107790107791107792107793107794107795107796107797107798107799107800107801107802107803107804107805107806107807107808107809107810107811107812107813107814107815107816107817107818107819107820107821107822107823107824107825107826107827107828107829107830107831107832107833107834107835107836107837107838107839107840107841107842107843107844107845107846107847107848107849107850107851107852107853107854107855107856107857107858107859107860107861107862107863107864107865107866107867107868107869107870107871107872107873107874107875107876107877107878107879107880107881107882107883107884107885107886107887107888107889107890107891107892107893107894107895107896107897107898107899107900107901107902107903107904107905107906107907107908107909107910107911107912107913107914107915107916107917107918107919107920107921107922107923107924107925107926107927107928107929107930107931107932107933107934107935107936107937107938107939107940107941107942107943107944107945107946107947107948107949107950107951107952107953107954107955107956107957107958107959107960107961107962107963107964107965107966107967107968107969107970107971107972107973107974107975107976107977107978107979107980107981107982107983107984107985107986107987107988107989107990107991107992107993107994107995107996107997107998107999108000108001108002108003108004108005108006108007108008108009108010108011108012108013108014108015108016108017108018108019108020108021108022108023108024108025108026108027108028108029108030108031108032108033108034108035108036108037108038108039108040108041108042108043108044108045108046108047108048108049108050108051108052108053108054108055108056108057108058108059108060108061108062108063108064108065108066108067108068108069108070108071108072108073108074108075108076108077108078108079108080108081108082108083108084108085108086108087108088108089108090108091108092108093108094108095108096108097108098108099108100108101108102108103108104108105108106108107108108108109108110108111108112108113108114108115108116108117108118108119108120108121108122108123108124108125108126108127108128108129108130108131108132108133108134108135108136108137108138108139108140108141108142108143108144108145108146108147108148108149108150108151108152108153108154108155108156108157108158108159108160108161108162108163108164108165108166108167108168108169108170108171108172108173108174108175108176108177108178108179108180108181108182108183108184108185108186108187108188108189108190108191108192108193108194108195108196108197108198108199108200108201108202108203108204108205108206108207108208108209108210108211108212108213108214108215108216108217108218108219108220108221108222108223108224108225108226108227108228108229108230108231108232108233108234108235108236108237108238108239108240108241108242108243108244108245108246108247108248108249108250108251108252108253108254108255108256108257108258108259108260108261108262108263108264108265108266108267108268108269108270108271108272108273108274108275108276108277108278108279108280108281108282108283108284108285108286108287108288108289108290108291108292108293108294108295108296108297108298108299108300108301108302108303108304108305108306108307108308108309108310108311108312108313108314108315108316108317108318108319108320108321108322108323108324108325108326108327108328108329108330108331108332108333108334108335108336108337108338108339108340108341108342108343108344108345108346108347108348108349108350108351108352108353108354108355108356108357108358108359108360108361108362108363108364108365108366108367108368108369108370108371108372108373108374108375108376108377108378108379108380108381108382108383108384108385108386108387108388108389108390108391108392108393108394108395108396108397108398108399108400108401108402108403108404108405108406108407108408108409108410108411108412108413108414108415108416108417108418108419108420108421108422108423108424108425108426108427108428108429108430108431108432108433108434108435108436108437108438108439108440108441108442108443108444108445108446108447108448108449108450108451108452108453108454108455108456108457108458108459108460108461108462108463108464108465108466108467108468108469108470108471108472108473108474108475108476108477108478108479108480108481108482108483108484108485108486108487108488108489108490108491108492108493108494108495108496108497108498108499108500108501108502108503108504108505108506108507108508108509108510108511108512108513108514108515108516108517108518108519108520108521108522108523108524108525108526108527108528108529108530108531108532108533108534108535108536108537108538108539108540108541108542108543108544108545108546108547108548108549108550108551108552108553108554108555108556108557108558108559108560108561108562108563108564108565108566108567108568108569108570108571108572108573108574108575108576108577108578108579108580108581108582108583108584108585108586108587108588108589108590108591108592108593108594108595108596108597108598108599108600108601108602108603108604108605108606108607108608108609108610108611108612108613108614108615108616108617108618108619108620108621108622108623108624108625108626108627108628108629108630108631108632108633108634108635108636108637108638108639108640108641108642108643108644108645108646108647108648108649108650108651108652108653108654108655108656108657108658108659108660108661108662108663108664108665108666108667108668108669108670108671108672108673108674108675108676108677108678108679108680108681108682108683108684108685108686108687108688108689108690108691108692108693108694108695108696108697108698108699108700108701108702108703108704108705108706108707108708108709108710108711108712108713108714108715108716108717108718108719108720108721108722108723108724108725108726108727108728108729108730108731108732108733108734108735108736108737108738108739108740108741108742108743108744108745108746108747108748108749108750108751108752108753108754108755108756108757108758108759108760108761108762108763108764108765108766108767108768108769108770108771108772108773108774108775108776108777108778108779108780108781108782108783108784108785108786108787108788108789108790108791108792108793108794108795108796108797108798108799108800108801108802108803108804108805108806108807108808108809108810108811108812108813108814108815108816108817108818108819108820108821108822108823108824108825108826108827108828108829108830108831108832108833108834108835108836108837108838108839108840108841108842108843108844108845108846108847108848108849108850108851108852108853108854108855108856108857108858108859108860108861108862108863108864108865108866108867108868108869108870108871108872108873108874108875108876108877108878108879108880108881108882108883108884108885108886108887108888108889108890108891108892108893108894108895108896108897108898108899108900108901108902108903108904108905108906108907108908108909108910108911108912108913108914108915108916108917108918108919108920108921108922108923108924108925108926108927108928108929108930108931108932108933108934108935108936108937108938108939108940108941108942108943108944108945108946108947108948108949108950108951108952108953108954108955108956108957108958108959108960108961108962108963108964108965108966108967108968108969108970108971108972108973108974108975108976108977108978108979108980108981108982108983108984108985108986108987108988108989108990108991108992108993108994108995108996108997108998108999109000109001109002109003109004109005109006109007109008109009109010109011109012109013109014109015109016109017109018109019109020109021109022109023109024109025109026109027109028109029109030109031109032109033109034109035109036109037109038109039109040109041109042109043109044109045109046109047109048109049109050109051109052109053109054109055109056109057109058109059109060109061109062109063109064109065109066109067109068109069109070109071109072109073109074109075109076109077109078109079109080109081109082109083109084109085109086109087109088109089109090109091109092109093109094109095109096109097109098109099109100109101109102109103109104109105109106109107109108109109109110109111109112109113109114109115109116109117109118109119109120109121109122109123109124109125109126109127109128109129109130109131109132109133109134109135109136109137109138109139109140109141109142109143109144109145109146109147109148109149109150109151109152109153109154109155109156109157109158109159109160109161109162109163109164109165109166109167109168109169109170109171109172109173109174109175109176109177109178109179109180109181109182109183109184109185109186109187109188109189109190109191109192109193109194109195109196109197109198109199109200109201109202109203109204109205109206109207109208109209109210109211109212109213109214109215109216109217109218109219109220109221109222109223109224109225109226109227109228109229109230109231109232109233109234109235109236109237109238109239109240109241109242109243109244109245109246109247109248109249109250109251109252109253109254109255109256109257109258109259109260109261109262109263109264109265109266109267109268109269109270109271109272109273109274109275109276109277109278109279109280109281109282109283109284109285109286109287109288109289109290109291109292109293109294109295109296109297109298109299109300109301109302109303109304109305109306109307109308109309109310109311109312109313109314109315109316109317109318109319109320109321109322109323109324109325109326109327109328109329109330109331109332109333109334109335109336109337109338109339109340109341109342109343109344109345109346109347109348109349109350109351109352109353109354109355109356109357109358109359109360109361109362109363109364109365109366109367109368109369109370109371109372109373109374109375109376109377109378109379109380109381109382109383109384109385109386109387109388109389109390109391109392109393109394109395109396109397109398109399109400109401109402109403109404109405109406109407109408109409109410109411109412109413109414109415109416109417109418109419109420109421109422109423109424109425109426109427109428109429109430109431109432109433109434109435109436109437109438109439109440109441109442109443109444109445109446109447109448109449109450109451109452109453109454109455109456109457109458109459109460109461109462109463109464109465109466109467109468109469109470109471109472109473109474109475109476109477109478109479109480109481109482109483109484109485109486109487109488109489109490109491109492109493109494109495109496109497109498109499109500109501109502109503109504109505109506109507109508109509109510109511109512109513109514109515109516109517109518109519109520109521109522109523109524109525109526109527109528109529109530109531109532109533109534109535109536109537109538109539109540109541109542109543109544109545109546109547109548109549109550109551109552109553109554109555109556109557109558109559109560109561109562109563109564109565109566109567109568109569109570109571109572109573109574109575109576109577109578109579109580109581109582109583109584109585109586109587109588109589109590109591109592109593109594109595109596109597109598109599109600109601109602109603109604109605109606109607109608109609109610109611109612109613109614109615109616109617109618109619109620109621109622109623109624109625109626109627109628109629109630109631109632109633109634109635109636109637109638109639109640109641109642109643109644109645109646109647109648109649109650109651109652109653109654109655109656109657109658109659109660109661109662109663109664109665109666109667109668109669109670109671109672109673109674109675109676109677109678109679109680109681109682109683109684109685109686109687109688109689109690109691109692109693109694109695109696109697109698109699109700109701109702109703109704109705109706109707109708109709109710109711109712109713109714109715109716109717109718109719109720109721109722109723109724109725109726109727109728109729109730109731109732109733109734109735109736109737109738109739109740109741109742109743109744109745109746109747109748109749109750109751109752109753109754109755109756109757109758109759109760109761109762109763109764109765109766109767109768109769109770109771109772109773109774109775109776109777109778109779109780109781109782109783109784109785109786109787109788109789109790109791109792109793109794109795109796109797109798109799109800109801109802109803109804109805109806109807109808109809109810109811109812109813109814109815109816109817109818109819109820109821109822109823109824109825109826109827109828109829109830109831109832109833109834109835109836109837109838109839109840109841109842109843109844109845109846109847109848109849109850109851109852109853109854109855109856109857109858109859109860109861109862109863109864109865109866109867109868109869109870109871109872109873109874109875109876109877109878109879109880109881109882109883109884109885109886109887109888109889109890109891109892109893109894109895109896109897109898109899109900109901109902109903109904109905109906109907109908109909109910109911109912109913109914109915109916109917109918109919109920109921109922109923109924109925109926109927109928109929109930109931109932109933109934109935109936109937109938109939109940109941109942109943109944109945109946109947109948109949109950109951109952109953109954109955109956109957109958109959109960109961109962109963109964109965109966109967109968109969109970109971109972109973109974109975109976109977109978109979109980109981109982109983109984109985109986109987109988109989109990109991109992109993109994109995109996109997109998109999110000110001110002110003110004110005110006110007110008110009110010110011110012110013110014110015110016110017110018110019110020110021110022110023110024110025110026110027110028110029110030110031110032110033110034110035110036110037110038110039110040110041110042110043110044110045110046110047110048110049110050110051110052110053110054110055110056110057110058110059110060110061110062110063110064110065110066110067110068110069110070110071110072110073110074110075110076110077110078110079110080110081110082110083110084110085110086110087110088110089110090110091110092110093110094110095110096110097110098110099110100110101110102110103110104110105110106110107110108110109110110110111110112110113110114110115110116110117110118110119110120110121110122110123110124110125110126110127110128110129110130110131110132110133110134110135110136110137110138110139110140110141110142110143110144110145110146110147110148110149110150110151110152110153110154110155110156110157110158110159110160110161110162110163110164110165110166110167110168110169110170110171110172110173110174110175110176110177110178110179110180110181110182110183110184110185110186110187110188110189110190110191110192110193110194110195110196110197110198110199110200110201110202110203110204110205110206110207110208110209110210110211110212110213110214110215110216110217110218110219110220110221110222110223110224110225110226110227110228110229110230110231110232110233110234110235110236110237110238110239110240110241110242110243110244110245110246110247110248110249110250110251110252110253110254110255110256110257110258110259110260110261110262110263110264110265110266110267110268110269110270110271110272110273110274110275110276110277110278110279110280110281110282110283110284110285110286110287110288110289110290110291110292110293110294110295110296110297110298110299110300110301110302110303110304110305110306110307110308110309110310110311110312110313110314110315110316110317110318110319110320110321110322110323110324110325110326110327110328110329110330110331110332110333110334110335110336110337110338110339110340110341110342110343110344110345110346110347110348110349110350110351110352110353110354110355110356110357110358110359110360110361110362110363110364110365110366110367110368110369110370110371110372110373110374110375110376110377110378110379110380110381110382110383110384110385110386110387110388110389110390110391110392110393110394110395110396110397110398110399110400110401110402110403110404110405110406110407110408110409110410110411110412110413110414110415110416110417110418110419110420110421110422110423110424110425110426110427110428110429110430110431110432110433110434110435110436110437110438110439110440110441110442110443110444110445110446110447110448110449110450110451110452110453110454110455110456110457110458110459110460110461110462110463110464110465110466110467110468110469110470110471110472110473110474110475110476110477110478110479110480110481110482110483110484110485110486110487110488110489110490110491110492110493110494110495110496110497110498110499110500110501110502110503110504110505110506110507110508110509110510110511110512110513110514110515110516110517110518110519110520110521110522110523110524110525110526110527110528110529110530110531110532110533110534110535110536110537110538110539110540110541110542110543110544110545110546110547110548110549110550110551110552110553110554110555110556110557110558110559110560110561110562110563110564110565110566110567110568110569110570110571110572110573110574110575110576110577110578110579110580110581110582110583110584110585110586110587110588110589110590110591110592110593110594110595110596110597110598110599110600110601110602110603110604110605110606110607110608110609110610110611110612110613110614110615110616110617110618110619110620110621110622110623110624110625110626110627110628110629110630110631110632110633110634110635110636110637110638110639110640110641110642110643110644110645110646110647110648110649110650110651110652110653110654110655110656110657110658110659110660110661110662110663110664110665110666110667110668110669110670110671110672110673110674110675110676110677110678110679110680110681110682110683110684110685110686110687110688110689110690110691110692110693110694110695110696110697110698110699110700110701110702110703110704110705110706110707110708110709110710110711110712110713110714110715110716110717110718110719110720110721110722110723110724110725110726110727110728110729110730110731110732110733110734110735110736110737110738110739110740110741110742110743110744110745110746110747110748110749110750110751110752110753110754110755110756110757110758110759110760110761110762110763110764110765110766110767110768110769110770110771110772110773110774110775110776110777110778110779110780110781110782110783110784110785110786110787110788110789110790110791110792110793110794110795110796110797110798110799110800110801110802110803110804110805110806110807110808110809110810110811110812110813110814110815110816110817110818110819110820110821110822110823110824110825110826110827110828110829110830110831110832110833110834110835110836110837110838110839110840110841110842110843110844110845110846110847110848110849110850110851110852110853110854110855110856110857110858110859110860110861110862110863110864110865110866110867110868110869110870110871110872110873110874110875110876110877110878110879110880110881110882110883110884110885110886110887110888110889110890110891110892110893110894110895110896110897110898110899110900110901110902110903110904110905110906110907110908110909110910110911110912110913110914110915110916110917110918110919110920110921110922110923110924110925110926110927110928110929110930110931110932110933110934110935110936110937110938110939110940110941110942110943110944110945110946110947110948110949110950110951110952110953110954110955110956110957110958110959110960110961110962110963110964110965110966110967110968110969110970110971110972110973110974110975110976110977110978110979110980110981110982110983110984110985110986110987110988110989110990110991110992110993110994110995110996110997110998110999111000111001111002111003111004111005111006111007111008111009111010111011111012111013111014111015111016111017111018111019111020111021111022111023111024111025111026111027111028111029111030111031111032111033111034111035111036111037111038111039111040111041111042111043111044111045111046111047111048111049111050111051111052111053111054111055111056111057111058111059111060111061111062111063111064111065111066111067111068111069111070111071111072111073111074111075111076111077111078111079111080111081111082111083111084111085111086111087111088111089111090111091111092111093111094111095111096111097111098111099111100111101111102111103111104111105111106111107111108111109111110111111111112111113111114111115111116111117111118111119111120111121111122111123111124111125111126111127111128111129111130111131111132111133111134111135111136111137111138111139111140111141111142111143111144111145111146111147111148111149111150111151111152111153111154111155111156111157111158111159111160111161111162111163111164111165111166111167111168111169111170111171111172111173111174111175111176111177111178111179111180111181111182111183111184111185111186111187111188111189111190111191111192111193111194111195111196111197111198111199111200111201111202111203111204111205111206111207111208111209111210111211111212111213111214111215111216111217111218111219111220111221111222111223111224111225111226111227111228111229111230111231111232111233111234111235111236111237111238111239111240111241111242111243111244111245111246111247111248111249111250111251111252111253111254111255111256111257111258111259111260111261111262111263111264111265111266111267111268111269111270111271111272111273111274111275111276111277111278111279111280111281111282111283111284111285111286111287111288111289111290111291111292111293111294111295111296111297111298111299111300111301111302111303111304111305111306111307111308111309111310111311111312111313111314111315111316111317111318111319111320111321111322111323111324111325111326111327111328111329111330111331111332111333111334111335111336111337111338111339111340111341111342111343111344111345111346111347111348111349111350111351111352111353111354111355111356111357111358111359111360111361111362111363111364111365111366111367111368111369111370111371111372111373111374111375111376111377111378111379111380111381111382111383111384111385111386111387111388111389111390111391111392111393111394111395111396111397111398111399111400111401111402111403111404111405111406111407111408111409111410111411111412111413111414111415111416111417111418111419111420111421111422111423111424111425111426111427111428111429111430111431111432111433111434111435111436111437111438111439111440111441111442111443111444111445111446111447111448111449111450111451111452111453111454111455111456111457111458111459111460111461111462111463111464111465111466111467111468111469111470111471111472111473111474111475111476111477111478111479111480111481111482111483111484111485111486111487111488111489111490111491111492111493111494111495111496111497111498111499111500111501111502111503111504111505111506111507111508111509111510111511111512111513111514111515111516111517111518111519111520111521111522111523111524111525111526111527111528111529111530111531111532111533111534111535111536111537111538111539111540111541111542111543111544111545111546111547111548111549111550111551111552111553111554111555111556111557111558111559111560111561111562111563111564111565111566111567111568111569111570111571111572111573111574111575111576111577111578111579111580111581111582111583111584111585111586111587111588111589111590111591111592111593111594111595111596111597111598111599111600111601111602111603111604111605111606111607111608111609111610111611111612111613111614111615111616111617111618111619111620111621111622111623111624111625111626111627111628111629111630111631111632111633111634111635111636111637111638111639111640111641111642111643111644111645111646111647111648111649111650111651111652111653111654111655111656111657111658111659111660111661111662111663111664111665111666111667111668111669111670111671111672111673111674111675111676111677111678111679111680111681111682111683111684111685111686111687111688111689111690111691111692111693111694111695111696111697111698111699111700111701111702111703111704111705111706111707111708111709111710111711111712111713111714111715111716111717111718111719111720111721111722111723111724111725111726111727111728111729111730111731111732111733111734111735111736111737111738111739111740111741111742111743111744111745111746111747111748111749111750111751111752111753111754111755111756111757111758111759111760111761111762111763111764111765111766111767111768111769111770111771111772111773111774111775111776111777111778111779111780111781111782111783111784111785111786111787111788111789111790111791111792111793111794111795111796111797111798111799111800111801111802111803111804111805111806111807111808111809111810111811111812111813111814111815111816111817111818111819111820111821111822111823111824111825111826111827111828111829111830111831111832111833111834111835111836111837111838111839111840111841111842111843111844111845111846111847111848111849111850111851111852111853111854111855111856111857111858111859111860111861111862111863111864111865111866111867111868111869111870111871111872111873111874111875111876111877111878111879111880111881111882111883111884111885111886111887111888111889111890111891111892111893111894111895111896111897111898111899111900111901111902111903111904111905111906111907111908111909111910111911111912111913111914111915111916111917111918111919111920111921111922111923111924111925111926111927111928111929111930111931111932111933111934111935111936111937111938111939111940111941111942111943111944111945111946111947111948111949111950111951111952111953111954111955111956111957111958111959111960111961111962111963111964111965111966111967111968111969111970111971111972111973111974111975111976111977111978111979111980111981111982111983111984111985111986111987111988111989111990111991111992111993111994111995111996111997111998111999112000112001112002112003112004112005112006112007112008112009112010112011112012112013112014112015112016112017112018112019112020112021112022112023112024112025112026112027112028112029112030112031112032112033112034112035112036112037112038112039112040112041112042112043112044112045112046112047112048112049112050112051112052112053112054112055112056112057112058112059112060112061112062112063112064112065112066112067112068112069112070112071112072112073112074112075112076112077112078112079112080112081112082112083112084112085112086112087112088112089112090112091112092112093112094112095112096112097112098112099112100112101112102112103112104112105112106112107112108112109112110112111112112112113112114112115112116112117112118112119112120112121112122112123112124112125112126112127112128112129112130112131112132112133112134112135112136112137112138112139112140112141112142112143112144112145112146112147112148112149112150112151112152112153112154112155112156112157112158112159112160112161112162112163112164112165112166112167112168112169112170112171112172112173112174112175112176112177112178112179112180112181112182112183112184112185112186112187112188112189112190112191112192112193112194112195112196112197112198112199112200112201112202112203112204112205112206112207112208112209112210112211112212112213112214112215112216112217112218112219112220112221112222112223112224112225112226112227112228112229112230112231112232112233112234112235112236112237112238112239112240112241112242112243112244112245112246112247112248112249112250112251112252112253112254112255112256112257112258112259112260112261112262112263112264112265112266112267112268112269112270112271112272112273112274112275112276112277112278112279112280112281112282112283112284112285112286112287112288112289112290112291112292112293112294112295112296112297112298112299112300112301112302112303112304112305112306112307112308112309112310112311112312112313112314112315112316112317112318112319112320112321112322112323112324112325112326112327112328112329112330112331112332112333112334112335112336112337112338112339112340112341112342112343112344112345112346112347112348112349112350112351112352112353112354112355112356112357112358112359112360112361112362112363112364112365112366112367112368112369112370112371112372112373112374112375112376112377112378112379112380112381112382112383112384112385112386112387112388112389112390112391112392112393112394112395112396112397112398112399112400112401112402112403112404112405112406112407112408112409112410112411112412112413112414112415112416112417112418112419112420112421112422112423112424112425112426112427112428112429112430112431112432112433112434112435112436112437112438112439112440112441112442112443112444112445112446112447112448112449112450112451112452112453112454112455112456112457112458112459112460112461112462112463112464112465112466112467112468112469112470112471112472112473112474112475112476112477112478112479112480112481112482112483112484112485112486112487112488112489112490112491112492112493112494112495112496112497112498112499112500112501112502112503112504112505112506112507112508112509112510112511112512112513112514112515112516112517112518112519112520112521112522112523112524112525112526112527112528112529112530112531112532112533112534112535112536112537112538112539112540112541112542112543112544112545112546112547112548112549112550112551112552112553112554112555112556112557112558112559112560112561112562112563112564112565112566112567112568112569112570112571112572112573112574112575112576112577112578112579112580112581112582112583112584112585112586112587112588112589112590112591112592112593112594112595112596112597112598112599112600112601112602112603112604112605112606112607112608112609112610112611112612112613112614112615112616112617112618112619112620112621112622112623112624112625112626112627112628112629112630112631112632112633112634112635112636112637112638112639112640112641112642112643112644112645112646112647112648112649112650112651112652112653112654112655112656112657112658112659112660112661112662112663112664112665112666112667112668112669112670112671112672112673112674112675112676112677112678112679112680112681112682112683112684112685112686112687112688112689112690112691112692112693112694112695112696112697112698112699112700112701112702112703112704112705112706112707112708112709112710112711112712112713112714112715112716112717112718112719112720112721112722112723112724112725112726112727112728112729112730112731112732112733112734112735112736112737112738112739112740112741112742112743112744112745112746112747112748112749112750112751112752112753112754112755112756112757112758112759112760112761112762112763112764112765112766112767112768112769112770112771112772112773112774112775112776112777112778112779112780112781112782112783112784112785112786112787112788112789112790112791112792112793112794112795112796112797112798112799112800112801112802112803112804112805112806112807112808112809112810112811112812112813112814112815112816112817112818112819112820112821112822112823112824112825112826112827112828112829112830112831112832112833112834112835112836112837112838112839112840112841112842112843112844112845112846112847112848112849112850112851112852112853112854112855112856112857112858112859112860112861112862112863112864112865112866112867112868112869112870112871112872112873112874112875112876112877112878112879112880112881112882112883112884112885112886112887112888112889112890112891112892112893112894112895112896112897112898112899112900112901112902112903112904112905112906112907112908112909112910112911112912112913112914112915112916112917112918112919112920112921112922112923112924112925112926112927112928112929112930112931112932112933112934112935112936112937112938112939112940112941112942112943112944112945112946112947112948112949112950112951112952112953112954112955112956112957112958112959112960112961112962112963112964112965112966112967112968112969112970112971112972112973112974112975112976112977112978112979112980112981112982112983112984112985112986112987112988112989112990112991112992112993112994112995112996112997112998112999113000113001113002113003113004113005113006113007113008113009113010113011113012113013113014113015113016113017113018113019113020113021113022113023113024113025113026113027113028113029113030113031113032113033113034113035113036113037113038113039113040113041113042113043113044113045113046113047113048113049113050113051113052113053113054113055113056113057113058113059113060113061113062113063113064113065113066113067113068113069113070113071113072113073113074113075113076113077113078113079113080113081113082113083113084113085113086113087113088113089113090113091113092113093113094113095113096113097113098113099113100113101113102113103113104113105113106113107113108113109113110113111113112113113113114113115113116113117113118113119113120113121113122113123113124113125113126113127113128113129113130113131113132113133113134113135113136113137113138113139113140113141113142113143113144113145113146113147113148113149113150113151113152113153113154113155113156113157113158113159113160113161113162113163113164113165113166113167113168113169113170113171113172113173113174113175113176113177113178113179113180113181113182113183113184113185113186113187113188113189113190113191113192113193113194113195113196113197113198113199113200113201113202113203113204113205113206113207113208113209113210113211113212113213113214113215113216113217113218113219113220113221113222113223113224113225113226113227113228113229113230113231113232113233113234113235113236113237113238113239113240113241113242113243113244113245113246113247113248113249113250113251113252113253113254113255113256113257113258113259113260113261113262113263113264113265113266113267113268113269113270113271113272113273113274113275113276113277113278113279113280113281113282113283113284113285113286113287113288113289113290113291113292113293113294113295113296113297113298113299113300113301113302113303113304113305113306113307113308113309113310113311113312113313113314113315113316113317113318113319113320113321113322113323113324113325113326113327113328113329113330113331113332113333113334113335113336113337113338113339113340113341113342113343113344113345113346113347113348113349113350113351113352113353113354113355113356113357113358113359113360113361113362113363113364113365113366113367113368113369113370113371113372113373113374113375113376113377113378113379113380113381113382113383113384113385113386113387113388113389113390113391113392113393113394113395113396113397113398113399113400113401113402113403113404113405113406113407113408113409113410113411113412113413113414113415113416113417113418113419113420113421113422113423113424113425113426113427113428113429113430113431113432113433113434113435113436113437113438113439113440113441113442113443113444113445113446113447113448113449113450113451113452113453113454113455113456113457113458113459113460113461113462113463113464113465113466113467113468113469113470113471113472113473113474113475113476113477113478113479113480113481113482113483113484113485113486113487113488113489113490113491113492113493113494113495113496113497113498113499113500113501113502113503113504113505113506113507113508113509113510113511113512113513113514113515113516113517113518113519113520113521113522113523113524113525113526113527113528113529113530113531113532113533113534113535113536113537113538113539113540113541113542113543113544113545113546113547113548113549113550113551113552113553113554113555113556113557113558113559113560113561113562113563113564113565113566113567113568113569113570113571113572113573113574113575113576113577113578113579113580113581113582113583113584113585113586113587113588113589113590113591113592113593113594113595113596113597113598113599113600113601113602113603113604113605113606113607113608113609113610113611113612113613113614113615113616113617113618113619113620113621113622113623113624113625113626113627113628113629113630113631113632113633113634113635113636113637113638113639113640113641113642113643113644113645113646113647113648113649113650113651113652113653113654113655113656113657113658113659113660113661113662113663113664113665113666113667113668113669113670113671113672113673113674113675113676113677113678113679113680113681113682113683113684113685113686113687113688113689113690113691113692113693113694113695113696113697113698113699113700113701113702113703113704113705113706113707113708113709113710113711113712113713113714113715113716113717113718113719113720113721113722113723113724113725113726113727113728113729113730113731113732113733113734113735113736113737113738113739113740113741113742113743113744113745113746113747113748113749113750113751113752113753113754113755113756113757113758113759113760113761113762113763113764113765113766113767113768113769113770113771113772113773113774113775113776113777113778113779113780113781113782113783113784113785113786113787113788113789113790113791113792113793113794113795113796113797113798113799113800113801113802113803113804113805113806113807113808113809113810113811113812113813113814113815113816113817113818113819113820113821113822113823113824113825113826113827113828113829113830113831113832113833113834113835113836113837113838113839113840113841113842113843113844113845113846113847113848113849113850113851113852113853113854113855113856113857113858113859113860113861113862113863113864113865113866113867113868113869113870113871113872113873113874113875113876113877113878113879113880113881113882113883113884113885113886113887113888113889113890113891113892113893113894113895113896113897113898113899113900113901113902113903113904113905113906113907113908113909113910113911113912113913113914113915113916113917113918113919113920113921113922113923113924113925113926113927113928113929113930113931113932113933113934113935113936113937113938113939113940113941113942113943113944113945113946113947113948113949113950113951113952113953113954113955113956113957113958113959113960113961113962113963113964113965113966113967113968113969113970113971113972113973113974113975113976113977113978113979113980113981113982113983113984113985113986113987113988113989113990113991113992113993113994113995113996113997113998113999114000114001114002114003114004114005114006114007114008114009114010114011114012114013114014114015114016114017114018114019114020114021114022114023114024114025114026114027114028114029114030114031114032114033114034114035114036114037114038114039114040114041114042114043114044114045114046114047114048114049114050114051114052114053114054114055114056114057114058114059114060114061114062114063114064114065114066114067114068114069114070114071114072114073114074114075114076114077114078114079114080114081114082114083114084114085114086114087114088114089114090114091114092114093114094114095114096114097114098114099114100114101114102114103114104114105114106114107114108114109114110114111114112114113114114114115114116114117114118114119114120114121114122114123114124114125114126114127114128114129114130114131114132114133114134114135114136114137114138114139114140114141114142114143114144114145114146114147114148114149114150114151114152114153114154114155114156114157114158114159114160114161114162114163114164114165114166114167114168114169114170114171114172114173114174114175114176114177114178114179114180114181114182114183114184114185114186114187114188114189114190114191114192114193114194114195114196114197114198114199114200114201114202114203114204114205114206114207114208114209114210114211114212114213114214114215114216114217114218114219114220114221114222114223114224114225114226114227114228114229114230114231114232114233114234114235114236114237114238114239114240114241114242114243114244114245114246114247114248114249114250114251114252114253114254114255114256114257114258114259114260114261114262114263114264114265114266114267114268114269114270114271114272114273114274114275114276114277114278114279114280114281114282114283114284114285114286114287114288114289114290114291114292114293114294114295114296114297114298114299114300114301114302114303114304114305114306114307114308114309114310114311114312114313114314114315114316114317114318114319114320114321114322114323114324114325114326114327114328114329114330114331114332114333114334114335114336114337114338114339114340114341114342114343114344114345114346114347114348114349114350114351114352114353114354114355114356114357114358114359114360114361114362114363114364114365114366114367114368114369114370114371114372114373114374114375114376114377114378114379114380114381114382114383114384114385114386114387114388114389114390114391114392114393114394114395114396114397114398114399114400114401114402114403114404114405114406114407114408114409114410114411114412114413114414114415114416114417114418114419114420114421114422114423114424114425114426114427114428114429114430114431114432114433114434114435114436114437114438114439114440114441114442114443114444114445114446114447114448114449114450114451114452114453114454114455114456114457114458114459114460114461114462114463114464114465114466114467114468114469114470114471114472114473114474114475114476114477114478114479114480114481114482114483114484114485114486114487114488114489114490114491114492114493114494114495114496114497114498114499114500114501114502114503114504114505114506114507114508114509114510114511114512114513114514114515114516114517114518114519114520114521114522114523114524114525114526114527114528114529114530114531114532114533114534114535114536114537114538114539114540114541114542114543114544114545114546114547114548114549114550114551114552114553114554114555114556114557114558114559114560114561114562114563114564114565114566114567114568114569114570114571114572114573114574114575114576114577114578114579114580114581114582114583114584114585114586114587114588114589114590114591114592114593114594114595114596114597114598114599114600114601114602114603114604114605114606114607114608114609114610114611114612114613114614114615114616114617114618114619114620114621114622114623114624114625114626114627114628114629114630114631114632114633114634114635114636114637114638114639114640114641114642114643114644114645114646114647114648114649114650114651114652114653114654114655114656114657114658114659114660114661114662114663114664114665114666114667114668114669114670114671114672114673114674114675114676114677114678114679114680114681114682114683114684114685114686114687114688114689114690114691114692114693114694114695114696114697114698114699114700114701114702114703114704114705114706114707114708114709114710114711114712114713114714114715114716114717114718114719114720114721114722114723114724114725114726114727114728114729114730114731114732114733114734114735114736114737114738114739114740114741114742114743114744114745114746114747114748114749114750114751114752114753114754114755114756114757114758114759114760114761114762114763114764114765114766114767114768114769114770114771114772114773114774114775114776114777114778114779114780114781114782114783114784114785114786114787114788114789114790114791114792114793114794114795114796114797114798114799114800114801114802114803114804114805114806114807114808114809114810114811114812114813114814114815114816114817114818114819114820114821114822114823114824114825114826114827114828114829114830114831114832114833114834114835114836114837114838114839114840114841114842114843114844114845114846114847114848114849114850114851114852114853114854114855114856114857114858114859114860114861114862114863114864114865114866114867114868114869114870114871114872114873114874114875114876114877114878114879114880114881114882114883114884114885114886114887114888114889114890114891114892114893114894114895114896114897114898114899114900114901114902114903114904114905114906114907114908114909114910114911114912114913114914114915114916114917114918114919114920114921114922114923114924114925114926114927114928114929114930114931114932114933114934114935114936114937114938114939114940114941114942114943114944114945114946114947114948114949114950114951114952114953114954114955114956114957114958114959114960114961114962114963114964114965114966114967114968114969114970114971114972114973114974114975114976114977114978114979114980114981114982114983114984114985114986114987114988114989114990114991114992114993114994114995114996114997114998114999115000115001115002115003115004115005115006115007115008115009115010115011115012115013115014115015115016115017115018115019115020115021115022115023115024115025115026115027115028115029115030115031115032115033115034115035115036115037115038115039115040115041115042115043115044115045115046115047115048115049115050115051115052115053115054115055115056115057115058115059115060115061115062115063115064115065115066115067115068115069115070115071115072115073115074115075115076115077115078115079115080115081115082115083115084115085115086115087115088115089115090115091115092115093115094115095115096115097115098115099115100115101115102115103115104115105115106115107115108115109115110115111115112115113115114115115115116115117115118115119115120115121115122115123115124115125115126115127115128115129115130115131115132115133115134115135115136115137115138115139115140115141115142115143115144115145115146115147115148115149115150115151115152115153115154115155115156115157115158115159115160115161115162115163115164115165115166115167115168115169115170115171115172115173115174115175115176115177115178115179115180115181115182115183115184115185115186115187115188115189115190115191115192115193115194115195115196115197115198115199115200115201115202115203115204115205115206115207115208115209115210115211115212115213115214115215115216115217115218115219115220115221115222115223115224115225115226115227115228115229115230115231115232115233115234115235115236115237115238115239115240115241115242115243115244115245115246115247115248115249115250115251115252115253115254115255115256115257115258115259115260115261115262115263115264115265115266115267115268115269115270115271115272115273115274115275115276115277115278115279115280115281115282115283115284115285115286115287115288115289115290115291115292115293115294115295115296115297115298115299115300115301115302115303115304115305115306115307115308115309115310115311115312115313115314115315115316115317115318115319115320115321115322115323115324115325115326115327115328115329115330115331115332115333115334115335115336115337115338115339115340115341115342115343115344115345115346115347115348115349115350115351115352115353115354115355115356115357115358115359115360115361115362115363115364115365115366115367115368115369115370115371115372115373115374115375115376115377115378115379115380115381115382115383115384115385115386115387115388115389115390115391115392115393115394115395115396115397115398115399115400115401115402115403115404115405115406115407115408115409115410115411115412115413115414115415115416115417115418115419115420115421115422115423115424115425115426115427115428115429115430115431115432115433115434115435115436115437115438115439115440115441115442115443115444115445115446115447115448115449115450115451115452115453115454115455115456115457115458115459115460115461115462115463115464115465115466115467115468115469115470115471115472115473115474115475115476115477115478115479115480115481115482115483115484115485115486115487115488115489115490115491115492115493115494115495115496115497115498115499115500115501115502115503115504115505115506115507115508115509115510115511115512115513115514115515115516115517115518115519115520115521115522115523115524115525115526115527115528115529115530115531115532115533115534115535115536115537115538115539115540115541115542115543115544115545115546115547115548115549115550115551115552115553115554115555115556115557115558115559115560115561115562115563115564115565115566115567115568115569115570115571115572115573115574115575115576115577115578115579115580115581115582115583115584115585115586115587115588115589115590115591115592115593115594115595115596115597115598115599115600115601115602115603115604115605115606115607115608115609115610115611115612115613115614115615115616115617115618115619115620115621115622115623115624115625115626115627115628115629115630115631115632115633115634115635115636115637115638115639115640115641115642115643115644115645115646115647115648115649115650115651115652115653115654115655115656115657115658115659115660115661115662115663115664115665115666115667115668115669115670115671115672115673115674115675115676115677115678115679115680115681115682115683115684115685115686115687115688115689115690115691115692115693115694115695115696115697115698115699115700115701115702115703115704115705115706115707115708115709115710115711115712115713115714115715115716115717115718115719115720115721115722115723115724115725115726115727115728115729115730115731115732115733115734115735115736115737115738115739115740115741115742115743115744115745115746115747115748115749115750115751115752115753115754115755115756115757115758115759115760115761115762115763115764115765115766115767115768115769115770115771115772115773115774115775115776115777115778115779115780115781115782115783115784115785115786115787115788115789115790115791115792115793115794115795115796115797115798115799115800115801115802115803115804115805115806115807115808115809115810115811115812115813115814115815115816115817115818115819115820115821115822115823115824115825115826115827115828115829115830115831115832115833115834115835115836115837115838115839115840115841115842115843115844115845115846115847115848115849115850115851115852115853115854115855115856115857115858115859115860115861115862115863115864115865115866115867115868115869115870115871115872115873115874115875115876115877115878115879115880115881115882115883115884115885115886115887115888115889115890115891115892115893115894115895115896115897115898115899115900115901115902115903115904115905115906115907115908115909115910115911115912115913115914115915115916115917115918115919115920115921115922115923115924115925115926115927115928115929115930115931115932115933115934115935115936115937115938115939115940115941115942115943115944115945115946115947115948115949115950115951115952115953115954115955115956115957115958115959115960115961115962115963115964115965115966115967115968115969115970115971115972115973115974115975115976115977115978115979115980115981115982115983115984115985115986115987115988115989115990115991115992115993115994115995115996115997115998115999116000116001116002116003116004116005116006116007116008116009116010116011116012116013116014116015116016116017116018116019116020116021116022116023116024116025116026116027116028116029116030116031116032116033116034116035116036116037116038116039116040116041116042116043116044116045116046116047116048116049116050116051116052116053116054116055116056116057116058116059116060116061116062116063116064116065116066116067116068116069116070116071116072116073116074116075116076116077116078116079116080116081116082116083116084116085116086116087116088116089116090116091116092116093116094116095116096116097116098116099116100116101116102116103116104116105116106116107116108116109116110116111116112116113116114116115116116116117116118116119116120116121116122116123116124116125116126116127116128116129116130116131116132116133116134116135116136116137116138116139116140116141116142116143116144116145116146116147116148116149116150116151116152116153116154116155116156116157116158116159116160116161116162116163116164116165116166116167116168116169116170116171116172116173116174116175116176116177116178116179116180116181116182116183116184116185116186116187116188116189116190116191116192116193116194116195116196116197116198116199116200116201116202116203116204116205116206116207116208116209116210116211116212116213116214116215116216116217116218116219116220116221116222116223116224116225116226116227116228116229116230116231116232116233116234116235116236116237116238116239116240116241116242116243116244116245116246116247116248116249116250116251116252116253116254116255116256116257116258116259116260116261116262116263116264116265116266116267116268116269116270116271116272116273116274116275116276116277116278116279116280116281116282116283116284116285116286116287116288116289116290116291116292116293116294116295116296116297116298116299116300116301116302116303116304116305116306116307116308116309116310116311116312116313116314116315116316116317116318116319116320116321116322116323116324116325116326116327116328116329116330116331116332116333116334116335116336116337116338116339116340116341116342116343116344116345116346116347116348116349116350116351116352116353116354116355116356116357116358116359116360116361116362116363116364116365116366116367116368116369116370116371116372116373116374116375116376116377116378116379116380116381116382116383116384116385116386116387116388116389116390116391116392116393116394116395116396116397116398116399116400116401116402116403116404116405116406116407116408116409116410116411116412116413116414116415116416116417116418116419116420116421116422116423116424116425116426116427116428116429116430116431116432116433116434116435116436116437116438116439116440116441116442116443116444116445116446116447116448116449116450116451116452116453116454116455116456116457116458116459116460116461116462116463116464116465116466116467116468116469116470116471116472116473116474116475116476116477116478116479116480116481116482116483116484116485116486116487116488116489116490116491116492116493116494116495116496116497116498116499116500116501116502116503116504116505116506116507116508116509116510116511116512116513116514116515116516116517116518116519116520116521116522116523116524116525116526116527116528116529116530116531116532116533116534116535116536116537116538116539116540116541116542116543116544116545116546116547116548116549116550116551116552116553116554116555116556116557116558116559116560116561116562116563116564116565116566116567116568116569116570116571116572116573116574116575116576116577116578116579116580116581116582116583116584116585116586116587116588116589116590116591116592116593116594116595116596116597116598116599116600116601116602116603116604116605116606116607116608116609116610116611116612116613116614116615116616116617116618116619116620116621116622116623116624116625116626116627116628116629116630116631116632116633116634116635116636116637116638116639116640116641116642116643116644116645116646116647116648116649116650116651116652116653116654116655116656116657116658116659116660116661116662116663116664116665116666116667116668116669116670116671116672116673116674116675116676116677116678116679116680116681116682116683116684116685116686116687116688116689116690116691116692116693116694116695116696116697116698116699116700116701116702116703116704116705116706116707116708116709116710116711116712116713116714116715116716116717116718116719116720116721116722116723116724116725116726116727116728116729116730116731116732116733116734116735116736116737116738116739116740116741116742116743116744116745116746116747116748116749116750116751116752116753116754116755116756116757116758116759116760116761116762116763116764116765116766116767116768116769116770116771116772116773116774116775116776116777116778116779116780116781116782116783116784116785116786116787116788116789116790116791116792116793116794116795116796116797116798116799116800116801116802116803116804116805116806116807116808116809116810116811116812116813116814116815116816116817116818116819116820116821116822116823116824116825116826116827116828116829116830116831116832116833116834116835116836116837116838116839116840116841116842116843116844116845116846116847116848116849116850116851116852116853116854116855116856116857116858116859116860116861116862116863116864116865116866116867116868116869116870116871116872116873116874116875116876116877116878116879116880116881116882116883116884116885116886116887116888116889116890116891116892116893116894116895116896116897116898116899116900116901116902116903116904116905116906116907116908116909116910116911116912116913116914116915116916116917116918116919116920116921116922116923116924116925116926116927116928116929116930116931116932116933116934116935116936116937116938116939116940116941116942116943116944116945116946116947116948116949116950116951116952116953116954116955116956116957116958116959116960116961116962116963116964116965116966116967116968116969116970116971116972116973116974116975116976116977116978116979116980116981116982116983116984116985116986116987116988116989116990116991116992116993116994116995116996116997116998116999117000117001117002117003117004117005117006117007117008117009117010117011117012117013117014117015117016117017117018117019117020117021117022117023117024117025117026117027117028117029117030117031117032117033117034117035117036117037117038117039117040117041117042117043117044117045117046117047117048117049117050117051117052117053117054117055117056117057117058117059117060117061117062117063117064117065117066117067117068117069117070117071117072117073117074117075117076117077117078117079117080117081117082117083117084117085117086117087117088117089117090117091117092117093117094117095117096117097117098117099117100117101117102117103117104117105117106117107117108117109117110117111117112117113117114117115117116117117117118117119117120117121117122117123117124117125117126117127117128117129117130117131117132117133117134117135117136117137117138117139117140117141117142117143117144117145117146117147117148117149117150117151117152117153117154117155117156117157117158117159117160117161117162117163117164117165117166117167117168117169117170117171117172117173117174117175117176117177117178117179117180117181117182117183117184117185117186117187117188117189117190117191117192117193117194117195117196117197117198117199117200117201117202117203117204117205117206117207117208117209117210117211117212117213117214117215117216117217117218117219117220117221117222117223117224117225117226117227117228117229117230117231117232117233117234117235117236117237117238117239117240117241117242117243117244117245117246117247117248117249117250117251117252117253117254117255117256117257117258117259117260117261117262117263117264117265117266117267117268117269117270117271117272117273117274117275117276117277117278117279117280117281117282117283117284117285117286117287117288117289117290117291117292117293117294117295117296117297117298117299117300117301117302117303117304117305117306117307117308117309117310117311117312117313117314117315117316117317117318117319117320117321117322117323117324117325117326117327117328117329117330117331117332117333117334117335117336117337117338117339117340117341117342117343117344117345117346117347117348117349117350117351117352117353117354117355117356117357117358117359117360117361117362117363117364117365117366117367117368117369117370117371117372117373117374117375117376117377117378117379117380117381117382117383117384117385117386117387117388117389117390117391117392117393117394117395117396117397117398117399117400117401117402117403117404117405117406117407117408117409117410117411117412117413117414117415117416117417117418117419117420117421117422117423117424117425117426117427117428117429117430117431117432117433117434117435117436117437117438117439117440117441117442117443117444117445117446117447117448117449117450117451117452117453117454117455117456117457117458117459117460117461117462117463117464117465117466117467117468117469117470117471117472117473117474117475117476117477117478117479117480117481117482117483117484117485117486117487117488117489117490117491117492117493117494117495117496117497117498117499117500117501117502117503117504117505117506117507117508117509117510117511117512117513117514117515117516117517117518117519117520117521117522117523117524117525117526117527117528117529117530117531117532117533117534117535117536117537117538117539117540117541117542117543117544117545117546117547117548117549117550117551117552117553117554117555117556117557117558117559117560117561117562117563117564117565117566117567117568117569117570117571117572117573117574117575117576117577117578117579117580117581117582117583117584117585117586117587117588117589117590117591117592117593117594117595117596117597117598117599117600117601117602117603117604117605117606117607117608117609117610117611117612117613117614117615117616117617117618117619117620117621117622117623117624117625117626117627117628117629117630117631117632117633117634117635117636117637117638117639117640117641117642117643117644117645117646117647117648117649117650117651117652117653117654117655117656117657117658117659117660117661117662117663117664117665117666117667117668117669117670117671117672117673117674117675117676117677117678117679117680117681117682117683117684117685117686117687117688117689117690117691117692117693117694117695117696117697117698117699117700117701117702117703117704117705117706117707117708117709117710117711117712117713117714117715117716117717117718117719117720117721117722117723117724117725117726117727117728117729117730117731117732117733117734117735117736117737117738117739117740117741117742117743117744117745117746117747117748117749117750117751117752117753117754117755117756117757117758117759117760117761117762117763117764117765117766117767117768117769117770117771117772117773117774117775117776117777117778117779117780117781117782117783117784117785117786117787117788117789117790117791117792117793117794117795117796117797117798117799117800117801117802117803117804117805117806117807117808117809117810117811117812117813117814117815117816117817117818117819117820117821117822117823117824117825117826117827117828117829117830117831117832117833117834117835117836117837117838117839117840117841117842117843117844117845117846117847117848117849117850117851117852117853117854117855117856117857117858117859117860117861117862117863117864117865117866117867117868117869117870117871117872117873117874117875117876117877117878117879117880117881117882117883117884117885117886117887117888117889117890117891117892117893117894117895117896117897117898117899117900117901117902117903117904117905117906117907117908117909117910117911117912117913117914117915117916117917117918117919117920117921117922117923117924117925117926117927117928117929117930117931117932117933117934117935117936117937117938117939117940117941117942117943117944117945117946117947117948117949117950117951117952117953117954117955117956117957117958117959117960117961117962117963117964117965117966117967117968117969117970117971117972117973117974117975117976117977117978117979117980117981117982117983117984117985117986117987117988117989117990117991117992117993117994117995117996117997117998117999118000118001118002118003118004118005118006118007118008118009118010118011118012118013118014118015118016118017118018118019118020118021118022118023118024118025118026118027118028118029118030118031118032118033118034118035118036118037118038118039118040118041118042118043118044118045118046118047118048118049118050118051118052118053118054118055118056118057118058118059118060118061118062118063118064118065118066118067118068118069118070118071118072118073118074118075118076118077118078118079118080118081118082118083118084118085118086118087118088118089118090118091118092118093118094118095118096118097118098118099118100118101118102118103118104118105118106118107118108118109118110118111118112118113118114118115118116118117118118118119118120118121118122118123118124118125118126118127118128118129118130118131118132118133118134118135118136118137118138118139118140118141118142118143118144118145118146118147118148118149118150118151118152118153118154118155118156118157118158118159118160118161118162118163118164118165118166118167118168118169118170118171118172118173118174118175118176118177118178118179118180118181118182118183118184118185118186118187118188118189118190118191118192118193118194118195118196118197118198118199118200118201118202118203118204118205118206118207118208118209118210118211118212118213118214118215118216118217118218118219118220118221118222118223118224118225118226118227118228118229118230118231118232118233118234118235118236118237118238118239118240118241118242118243118244118245118246118247118248118249118250118251118252118253118254118255118256118257118258118259118260118261118262118263118264118265118266118267118268118269118270118271118272118273118274118275118276118277118278118279118280118281118282118283118284118285118286118287118288118289118290118291118292118293118294118295118296118297118298118299118300118301118302118303118304118305118306118307118308118309118310118311118312118313118314118315118316118317118318118319118320118321118322118323118324118325118326118327118328118329118330118331118332118333118334118335118336118337118338118339118340118341118342118343118344118345118346118347118348118349118350118351118352118353118354118355118356118357118358118359118360118361118362118363118364118365118366118367118368118369118370118371118372118373118374118375118376118377118378118379118380118381118382118383118384118385118386118387118388118389118390118391118392118393118394118395118396118397118398118399118400118401118402118403118404118405118406118407118408118409118410118411118412118413118414118415118416118417118418118419118420118421118422118423118424118425118426118427118428118429118430118431118432118433118434118435118436118437118438118439118440118441118442118443118444118445118446118447118448118449118450118451118452118453118454118455118456118457118458118459118460118461118462118463118464118465118466118467118468118469118470118471118472118473118474118475118476118477118478118479118480118481118482118483118484118485118486118487118488118489118490118491118492118493118494118495118496118497118498118499118500118501118502118503118504118505118506118507118508118509118510118511118512118513118514118515118516118517118518118519118520118521118522118523118524118525118526118527118528118529118530118531118532118533118534118535118536118537118538118539118540118541118542118543118544118545118546118547118548118549118550118551118552118553118554118555118556118557118558118559118560118561118562118563118564118565118566118567118568118569118570118571118572118573118574118575118576118577118578118579118580118581118582118583118584118585118586118587118588118589118590118591118592118593118594118595118596118597118598118599118600118601118602118603118604118605118606118607118608118609118610118611118612118613118614118615118616118617118618118619118620118621118622118623118624118625118626118627118628118629118630118631118632118633118634118635118636118637118638118639118640118641118642118643118644118645118646118647118648118649118650118651118652118653118654118655118656118657118658118659118660118661118662118663118664118665118666118667118668118669118670118671118672118673118674118675118676118677118678118679118680118681118682118683118684118685118686118687118688118689118690118691118692118693118694118695118696118697118698118699118700118701118702118703118704118705118706118707118708118709118710118711118712118713118714118715118716118717118718118719118720118721118722118723118724118725118726118727118728118729118730118731118732118733118734118735118736118737118738118739118740118741118742118743118744118745118746118747118748118749118750118751118752118753118754118755118756118757118758118759118760118761118762118763118764118765118766118767118768118769118770118771118772118773118774118775118776118777118778118779118780118781118782118783118784118785118786118787118788118789118790118791118792118793118794118795118796118797118798118799118800118801118802118803118804118805118806118807118808118809118810118811118812118813118814118815118816118817118818118819118820118821118822118823118824118825118826118827118828118829118830118831118832118833118834118835118836118837118838118839118840118841118842118843118844118845118846118847118848118849118850118851118852118853118854118855118856118857118858118859118860118861118862118863118864118865118866118867118868118869118870118871118872118873118874118875118876118877118878118879118880118881118882118883118884118885118886118887118888118889118890118891118892118893118894118895118896118897118898118899118900118901118902118903118904118905118906118907118908118909118910118911118912118913118914118915118916118917118918118919118920118921118922118923118924118925118926118927118928118929118930118931118932118933118934118935118936118937118938118939118940118941118942118943118944118945118946118947118948118949118950118951118952118953118954118955118956118957118958118959118960118961118962118963118964118965118966118967118968118969118970118971118972118973118974118975118976118977118978118979118980118981118982118983118984118985118986118987118988118989118990118991118992118993118994118995118996118997118998118999119000119001119002119003119004119005119006119007119008119009119010119011119012119013119014119015119016119017119018119019119020119021119022119023119024119025119026119027119028119029119030119031119032119033119034119035119036119037119038119039119040119041119042119043119044119045119046119047119048119049119050119051119052119053119054119055119056119057119058119059119060119061119062119063119064119065119066119067119068119069119070119071119072119073119074119075119076119077119078119079119080119081119082119083119084119085119086119087119088119089119090119091119092119093119094119095119096119097119098119099119100119101119102119103119104119105119106119107119108119109119110119111119112119113119114119115119116119117119118119119119120119121119122119123119124119125119126119127119128119129119130119131119132119133119134119135119136119137119138119139119140119141119142119143119144119145119146119147119148119149119150119151119152119153119154119155119156119157119158119159119160119161119162119163119164119165119166119167119168119169119170119171119172119173119174119175119176119177119178119179119180119181119182119183119184119185119186119187119188119189119190119191119192119193119194119195119196119197119198119199119200119201119202119203119204119205119206119207119208119209119210119211119212119213119214119215119216119217119218119219119220119221119222119223119224119225119226119227119228119229119230119231119232119233119234119235119236119237119238119239119240119241119242119243119244119245119246119247119248119249119250119251119252119253119254119255119256119257119258119259119260119261119262119263119264119265119266119267119268119269119270119271119272119273119274119275119276119277119278119279119280119281119282119283119284119285119286119287119288119289119290119291119292119293119294119295119296119297119298119299119300119301119302119303119304119305119306119307119308119309119310119311119312119313119314119315119316119317119318119319119320119321119322119323119324119325119326119327119328119329119330119331119332119333119334119335119336119337119338119339119340119341119342119343119344119345119346119347119348119349119350119351119352119353119354119355119356119357119358119359119360119361119362119363119364119365119366119367119368119369119370119371119372119373119374119375119376119377119378119379119380119381119382119383119384119385119386119387119388119389119390119391119392119393119394119395119396119397119398119399119400119401119402119403119404119405119406119407119408119409119410119411119412119413119414119415119416119417119418119419119420119421119422119423119424119425119426119427119428119429119430119431119432119433119434119435119436119437119438119439119440119441119442119443119444119445119446119447119448119449119450119451119452119453119454119455119456119457119458119459119460119461119462119463119464119465119466119467119468119469119470119471119472119473119474119475119476119477119478119479119480119481119482119483119484119485119486119487119488119489119490119491119492119493119494119495119496119497119498119499119500119501119502119503119504119505119506119507119508119509119510119511119512119513119514119515119516119517119518119519119520119521119522119523119524119525119526119527119528119529119530119531119532119533119534119535119536119537119538119539119540119541119542119543119544119545119546119547119548119549119550119551119552119553119554119555119556119557119558119559119560119561119562119563119564119565119566119567119568119569119570119571119572119573119574119575119576119577119578119579119580119581119582119583119584119585119586119587119588119589119590119591119592119593119594119595119596119597119598119599119600119601119602119603119604119605119606119607119608119609119610119611119612119613119614119615119616119617119618119619119620119621119622119623119624119625119626119627119628119629119630119631119632119633119634119635119636119637119638119639119640119641119642119643119644119645119646119647119648119649119650119651119652119653119654119655119656119657119658119659119660119661119662119663119664119665119666119667119668119669119670119671119672119673119674119675119676119677119678119679119680119681119682119683119684119685119686119687119688119689119690119691119692119693119694119695119696119697119698119699119700119701119702119703119704119705119706119707119708119709119710119711119712119713119714119715119716119717119718119719119720119721119722119723119724119725119726119727119728119729119730119731119732119733119734119735119736119737119738119739119740119741119742119743119744119745119746119747119748119749119750119751119752119753119754119755119756119757119758119759119760119761119762119763119764119765119766119767119768119769119770119771119772119773119774119775119776119777119778119779119780119781119782119783119784119785119786119787119788119789119790119791119792119793119794119795119796119797119798119799119800119801119802119803119804119805119806119807119808119809119810119811119812119813119814119815119816119817119818119819119820119821119822119823119824119825119826119827119828119829119830119831119832119833119834119835119836119837119838119839119840119841119842119843119844119845119846119847119848119849119850119851119852119853119854119855119856119857119858119859119860119861119862119863119864119865119866119867119868119869119870119871119872119873119874119875119876119877119878119879119880119881119882119883119884119885119886119887119888119889119890119891119892119893119894119895119896119897119898119899119900119901119902119903119904119905119906119907119908119909119910119911119912119913119914119915119916119917119918119919119920119921119922119923119924119925119926119927119928119929119930119931119932119933119934119935119936119937119938119939119940119941119942119943119944119945119946119947119948119949119950119951119952119953119954119955119956119957119958119959119960119961119962119963119964119965119966119967119968119969119970119971119972119973119974119975119976119977119978119979119980119981119982119983119984119985119986119987119988119989119990119991119992119993119994119995119996119997119998119999120000120001120002120003120004120005120006120007120008120009120010120011120012120013120014120015120016120017120018120019120020120021120022120023120024120025120026120027120028120029120030120031120032120033120034120035120036120037120038120039120040120041120042120043120044120045120046120047120048120049120050120051120052120053120054120055120056120057120058120059120060120061120062120063120064120065120066120067120068120069120070120071120072120073120074120075120076120077120078120079120080120081120082120083120084120085120086120087120088120089120090120091120092120093120094120095120096120097120098120099120100120101120102120103120104120105120106120107120108120109120110120111120112120113120114120115120116120117120118120119120120120121120122120123120124120125120126120127120128120129120130120131120132120133120134120135120136120137120138120139120140120141120142120143120144120145120146120147120148120149120150120151120152120153120154120155120156120157120158120159120160120161120162120163120164120165120166120167120168120169120170120171120172120173120174120175120176120177120178120179120180120181120182120183120184120185120186120187120188120189120190120191120192120193120194120195120196120197120198120199120200120201120202120203120204120205120206120207120208120209120210120211120212120213120214120215120216120217120218120219120220120221120222120223120224120225120226120227120228120229120230120231120232120233120234120235120236120237120238120239120240120241120242120243120244120245120246120247120248120249120250120251120252120253120254120255120256120257120258120259120260120261120262120263120264120265120266120267120268120269120270120271120272120273120274120275120276120277120278120279120280120281120282120283120284120285120286120287120288120289120290120291120292120293120294120295120296120297120298120299120300120301120302120303120304120305120306120307120308120309120310120311120312120313120314120315120316120317120318120319120320120321120322120323120324120325120326120327120328120329120330120331120332120333120334120335120336120337120338120339120340120341120342120343120344120345120346120347120348120349120350120351120352120353120354120355120356120357120358120359120360120361120362120363120364120365120366120367120368120369120370120371120372120373120374120375120376120377120378120379120380120381120382120383120384120385120386120387120388120389120390120391120392120393120394120395120396120397120398120399120400120401120402120403120404120405120406120407120408120409120410120411120412120413120414120415120416120417120418120419120420120421120422120423120424120425120426120427120428120429120430120431120432120433120434120435120436120437120438120439120440120441120442120443120444120445120446120447120448120449120450120451120452120453120454120455120456120457120458120459120460120461120462120463120464120465120466120467120468120469120470120471120472120473120474120475120476120477120478120479120480120481120482120483120484120485120486120487120488120489120490120491120492120493120494120495120496120497120498120499120500120501120502120503120504120505120506120507120508120509120510120511120512120513120514120515120516120517120518120519120520120521120522120523120524120525120526120527120528120529120530120531120532120533120534120535120536120537120538120539120540120541120542120543120544120545120546120547120548120549120550120551120552120553120554120555120556120557120558120559120560120561120562120563120564120565120566120567120568120569120570120571120572120573120574120575120576120577120578120579120580120581120582120583120584120585120586120587120588120589120590120591120592120593120594120595120596120597120598120599120600120601120602120603120604120605120606120607120608120609120610120611120612120613120614120615120616120617120618120619120620120621120622120623120624120625120626120627120628120629120630120631120632120633120634120635120636120637120638120639120640120641120642120643120644120645120646120647120648120649120650120651120652120653120654120655120656120657120658120659120660120661120662120663120664120665120666120667120668120669120670120671120672120673120674120675120676120677120678120679120680120681120682120683120684120685120686120687120688120689120690120691120692120693120694120695120696120697120698120699120700120701120702120703120704120705120706120707120708120709120710120711120712120713120714120715120716120717120718120719120720120721120722120723120724120725120726120727120728120729120730120731120732120733120734120735120736120737120738120739120740120741120742120743120744120745120746120747120748120749120750120751120752120753120754120755120756120757120758120759120760120761120762120763120764120765120766120767120768120769120770120771120772120773120774120775120776120777120778120779120780120781120782120783120784120785120786120787120788120789120790120791120792120793120794120795120796120797120798120799120800120801120802120803120804120805120806120807120808120809120810120811120812120813120814120815120816120817120818120819120820120821120822120823120824120825120826120827120828120829120830120831120832120833120834120835120836120837120838120839120840120841120842120843120844120845120846120847120848120849120850120851120852120853120854120855120856120857120858120859120860120861120862120863120864120865120866120867120868120869120870120871120872120873120874120875120876120877120878120879120880120881120882120883120884120885120886120887120888120889120890120891120892120893120894120895120896120897120898120899120900120901120902120903120904120905120906120907120908120909120910120911120912120913120914120915120916120917120918120919120920120921120922120923120924120925120926120927120928120929120930120931120932120933120934120935120936120937120938120939120940120941120942120943120944120945120946120947120948120949120950120951120952120953120954120955120956120957120958120959120960120961120962120963120964120965120966120967120968120969120970120971120972120973120974120975120976120977120978120979120980120981120982120983120984120985120986120987120988120989120990120991120992120993120994120995120996120997120998120999121000121001121002121003121004121005121006121007121008121009121010121011121012121013121014121015121016121017121018121019121020121021121022121023121024121025121026121027121028121029121030121031121032121033121034121035121036121037121038121039121040121041121042121043121044121045121046121047121048121049121050121051121052121053121054121055121056121057121058121059121060121061121062121063121064121065121066121067121068121069121070121071121072121073121074121075121076121077121078121079121080121081121082121083121084121085121086121087121088121089121090121091121092121093121094121095121096121097121098121099121100121101121102121103121104121105121106121107121108121109121110121111121112121113121114121115121116121117121118121119121120121121121122121123121124121125121126121127121128121129121130121131121132121133121134121135121136121137121138121139121140121141121142121143121144121145121146121147121148121149121150121151121152121153121154121155121156121157121158121159121160121161121162121163121164121165121166121167121168121169121170121171121172121173121174121175121176121177121178121179121180121181121182121183121184121185121186121187121188121189121190121191121192121193121194121195121196121197121198121199121200121201121202121203121204121205121206121207121208121209121210121211121212121213121214121215121216121217121218121219121220121221121222121223121224121225121226121227121228121229121230121231121232121233121234121235121236121237121238121239121240121241121242121243121244121245121246121247121248121249121250121251121252121253121254121255121256121257121258121259121260121261121262121263121264121265121266121267121268121269121270121271121272121273121274121275121276121277121278121279121280121281121282121283121284121285121286121287121288121289121290121291121292121293121294121295121296121297121298121299121300121301121302121303121304121305121306121307121308121309121310121311121312121313121314121315121316121317121318121319121320121321121322121323121324121325121326121327121328121329121330121331121332121333121334121335121336121337121338121339121340121341121342121343121344121345121346121347121348121349121350121351121352121353121354121355121356121357121358121359121360121361121362121363121364121365121366121367121368121369121370121371121372121373121374121375121376121377121378121379121380121381121382121383121384121385121386121387121388121389121390121391121392121393121394121395121396121397121398121399121400121401121402121403121404121405121406121407121408121409121410121411121412121413121414121415121416121417121418121419121420121421121422121423121424121425121426121427121428121429121430121431121432121433121434121435121436121437121438121439121440121441121442121443121444121445121446121447121448121449121450121451121452121453121454121455121456121457121458121459121460121461121462121463121464121465121466121467121468121469121470121471121472121473121474121475121476121477121478121479121480121481121482121483121484121485121486121487121488121489121490121491121492121493121494121495121496121497121498121499121500121501121502121503121504121505121506121507121508121509121510121511121512121513121514121515121516121517121518121519121520121521121522121523121524121525121526121527121528121529121530121531121532121533121534121535121536121537121538121539121540121541121542121543121544121545121546121547121548121549121550121551121552121553121554121555121556121557121558121559121560121561121562121563121564121565121566121567121568121569121570121571121572121573121574121575121576121577121578121579121580121581121582121583121584121585121586121587121588121589121590121591121592121593121594121595121596121597121598121599121600121601121602121603121604121605121606121607121608121609121610121611121612121613121614121615121616121617121618121619121620121621121622121623121624121625121626121627121628121629121630121631121632121633121634121635121636121637121638121639121640121641121642121643121644121645121646121647121648121649121650121651121652121653121654121655121656121657121658121659121660121661121662121663121664121665121666121667121668121669121670121671121672121673121674121675121676121677121678121679121680121681121682121683121684121685121686121687121688121689121690121691121692121693121694121695121696121697121698121699121700121701121702121703121704121705121706121707121708121709121710121711121712121713121714121715121716121717121718121719121720121721121722121723121724121725121726121727121728121729121730121731121732121733121734121735121736121737121738121739121740121741121742121743121744121745121746121747121748121749121750121751121752121753121754121755121756121757121758121759121760121761121762121763121764121765121766121767121768121769121770121771121772121773121774121775121776121777121778121779121780121781121782121783121784121785121786121787121788121789121790121791121792121793121794121795121796121797121798121799121800121801121802121803121804121805121806121807121808121809121810121811121812121813121814121815121816121817121818121819121820121821121822121823121824121825121826121827121828121829121830121831121832121833121834121835121836121837121838121839121840121841121842121843121844121845121846121847121848121849121850121851121852121853121854121855121856121857121858121859121860121861121862121863121864121865121866121867121868121869121870121871121872121873121874121875121876121877121878121879121880121881121882121883121884121885121886121887121888121889121890121891121892121893121894121895121896121897121898121899121900121901121902121903121904121905121906121907121908121909121910121911121912121913121914121915121916121917121918121919121920121921121922121923121924121925121926121927121928121929121930121931121932121933121934121935121936121937121938121939121940121941121942121943121944121945121946121947121948121949121950121951121952121953121954121955121956121957121958121959121960121961121962121963121964121965121966121967121968121969121970121971121972121973121974121975121976121977121978121979121980121981121982121983121984121985121986121987121988121989121990121991121992121993121994121995121996121997121998121999122000122001122002122003122004122005122006122007122008122009122010122011122012122013122014122015122016122017122018122019122020122021122022122023122024122025122026122027122028122029122030122031122032122033122034122035122036122037122038122039122040122041122042122043122044122045122046122047122048122049122050122051122052122053122054122055122056122057122058122059122060122061122062122063122064122065122066122067122068122069122070122071122072122073122074122075122076122077122078122079122080122081122082122083122084122085122086122087122088122089122090122091122092122093122094122095122096122097122098122099122100122101122102122103122104122105122106122107122108122109122110122111122112122113122114122115122116122117122118122119122120122121122122122123122124122125122126122127122128122129122130122131122132122133122134122135122136122137122138122139122140122141122142122143122144122145122146122147122148122149122150122151122152122153122154122155122156122157122158122159122160122161122162122163122164122165122166122167122168122169122170122171122172122173122174122175122176122177122178122179122180122181122182122183122184122185122186122187122188122189122190122191122192122193122194122195122196122197122198122199122200122201122202122203122204122205122206122207122208122209122210122211122212122213122214122215122216122217122218122219122220122221122222122223122224122225122226122227122228122229122230122231122232122233122234122235122236122237122238122239122240122241122242122243122244122245122246122247122248122249122250122251122252122253122254122255122256122257122258122259122260122261122262122263122264122265122266122267122268122269122270122271122272122273122274122275122276122277122278122279122280122281122282122283122284122285122286122287122288122289122290122291122292122293122294122295122296122297122298122299122300122301122302122303122304122305122306122307122308122309122310122311122312122313122314122315122316122317122318122319122320122321122322122323122324122325122326122327122328122329122330122331122332122333122334122335122336122337122338122339122340122341122342122343122344122345122346122347122348122349122350122351122352122353122354122355122356122357122358122359122360122361122362122363122364122365122366122367122368122369122370122371122372122373122374122375122376122377122378122379122380122381122382122383122384122385122386122387122388122389122390122391122392122393122394122395122396122397122398122399122400122401122402122403122404122405122406122407122408122409122410122411122412122413122414122415122416122417122418122419122420122421122422122423122424122425122426122427122428122429122430122431122432122433122434122435122436122437122438122439122440122441122442122443122444122445122446122447122448122449122450122451122452122453122454122455122456122457122458122459122460122461122462122463122464122465122466122467122468122469122470122471122472122473122474122475122476122477122478122479122480122481122482122483122484122485122486122487122488122489122490122491122492122493122494122495122496122497122498122499122500122501122502122503122504122505122506122507122508122509122510122511122512122513122514122515122516122517122518122519122520122521122522122523122524122525122526122527122528122529122530122531122532122533122534122535122536122537122538122539122540122541122542122543122544122545122546122547122548122549122550122551122552122553122554122555122556122557122558122559122560122561122562122563122564122565122566122567122568122569122570122571122572122573122574122575122576122577122578122579122580122581122582122583122584122585122586122587122588122589122590122591122592122593122594122595122596122597122598122599122600122601122602122603122604122605122606122607122608122609122610122611122612122613122614122615122616122617122618122619122620122621122622122623122624122625122626122627122628122629122630122631122632122633122634122635122636122637122638122639122640122641122642122643122644122645122646122647122648122649122650122651122652122653122654122655122656122657122658122659122660122661122662122663122664122665122666122667122668122669122670122671122672122673122674122675122676122677122678122679122680122681122682122683122684122685122686122687122688122689122690122691122692122693122694122695122696122697122698122699122700122701122702122703122704122705122706122707122708122709122710122711122712122713122714122715122716122717122718122719122720122721122722122723122724122725122726122727122728122729122730122731122732122733122734122735122736122737122738122739122740122741122742122743122744122745122746122747122748122749122750122751122752122753122754122755122756122757122758122759122760122761122762122763122764122765122766122767122768122769122770122771122772122773122774122775122776122777122778122779122780122781122782122783122784122785122786122787122788122789122790122791122792122793122794122795122796122797122798122799122800122801122802122803122804122805122806122807122808122809122810122811122812122813122814122815122816122817122818122819122820122821122822122823122824122825122826122827122828122829122830122831122832122833122834122835122836122837122838122839122840122841122842122843122844122845122846122847122848122849122850122851122852122853122854122855122856122857122858122859122860122861122862122863122864122865122866122867122868122869122870122871122872122873122874122875122876122877122878122879122880122881122882122883122884122885122886122887122888122889122890122891122892122893122894122895122896122897122898122899122900122901122902122903122904122905122906122907122908122909122910122911122912122913122914122915122916122917122918122919122920122921122922122923122924122925122926122927122928122929122930122931122932122933122934122935122936122937122938122939122940122941122942122943122944122945122946122947122948122949122950122951122952122953122954122955122956122957122958122959122960122961122962122963122964122965122966122967122968122969122970122971122972122973122974122975122976122977122978122979122980122981122982122983122984122985122986122987122988122989122990122991122992122993122994122995122996122997122998122999123000123001123002123003123004123005123006123007123008123009123010123011123012123013123014123015123016123017123018123019123020123021123022123023123024123025123026123027123028123029123030123031123032123033123034123035123036123037123038123039123040123041123042123043123044123045123046123047123048123049123050123051123052123053123054123055123056123057123058123059123060123061123062123063123064123065123066123067123068123069123070123071123072123073123074123075123076123077123078123079123080123081123082123083123084123085123086123087123088123089123090123091123092123093123094123095123096123097123098123099123100123101123102123103123104123105123106123107123108123109123110123111123112123113123114123115123116123117123118123119123120123121123122123123123124123125123126123127123128123129123130123131123132123133123134123135123136123137123138123139123140123141123142123143123144123145123146123147123148123149123150123151123152123153123154123155123156123157123158123159123160123161123162123163123164123165123166123167123168123169123170123171123172123173123174123175123176123177123178123179123180123181123182123183123184123185123186123187123188123189123190123191123192123193123194123195123196123197123198123199123200123201123202123203123204123205123206123207123208123209123210123211123212123213123214123215123216123217123218123219123220123221123222123223123224123225123226123227123228123229123230123231123232123233123234123235123236123237123238123239123240123241123242123243123244123245123246123247123248123249123250123251123252123253123254123255123256123257123258123259123260123261123262123263123264123265123266123267123268123269123270123271123272123273123274123275123276123277123278123279123280123281123282123283123284123285123286123287123288123289123290123291123292123293123294123295123296123297123298123299123300123301123302123303123304123305123306123307123308123309123310123311123312123313123314123315123316123317123318123319123320123321123322123323123324123325123326123327123328123329123330123331123332123333123334123335123336123337123338123339123340123341123342123343123344123345123346123347123348123349123350123351123352123353123354123355123356123357123358123359123360123361123362123363123364123365123366123367123368123369123370123371123372123373123374123375123376123377123378123379123380123381123382123383123384123385123386123387123388123389123390123391123392123393123394123395123396123397123398123399123400123401123402123403123404123405123406123407123408123409123410123411123412123413123414123415123416123417123418123419123420123421123422123423123424123425123426123427123428123429123430123431123432123433123434123435123436123437123438123439123440123441123442123443123444123445123446123447123448123449123450123451123452123453123454123455123456123457123458123459123460123461123462123463123464123465123466123467123468123469123470123471123472123473123474123475123476123477123478123479123480123481123482123483123484123485123486123487123488123489123490123491123492123493123494123495123496123497123498123499123500123501123502123503123504123505123506123507123508123509123510123511123512123513123514123515123516123517123518123519123520123521123522123523123524123525123526123527123528123529123530123531123532123533123534123535123536123537123538123539123540123541123542123543123544123545123546123547123548123549123550123551123552123553123554123555123556123557123558123559123560123561123562123563123564123565123566123567123568123569123570123571123572123573123574123575123576123577123578123579123580123581123582123583123584123585123586123587123588123589123590123591123592123593123594123595123596123597123598123599123600123601123602123603123604123605123606123607123608123609123610123611123612123613123614123615123616123617123618123619123620123621123622123623123624123625123626123627123628123629123630123631123632123633123634123635123636123637123638123639123640123641123642123643123644123645123646123647123648123649123650123651123652123653123654123655123656123657123658123659123660123661123662123663123664123665123666123667123668123669123670123671123672123673123674123675123676123677123678123679123680123681123682123683123684123685123686123687123688123689123690123691123692123693123694123695123696123697123698123699123700123701123702123703123704123705123706123707123708123709123710123711123712123713123714123715123716123717123718123719123720123721123722123723123724123725123726123727123728123729123730123731123732123733123734123735123736123737123738123739123740123741123742123743123744123745123746123747123748123749123750123751123752123753123754123755123756123757123758123759123760123761123762123763123764123765123766123767123768123769123770123771123772123773123774123775123776123777123778123779123780123781123782123783123784123785123786123787123788123789123790123791123792123793123794123795123796123797123798123799123800123801123802123803123804123805123806123807123808123809123810123811123812123813123814123815123816123817123818123819123820123821123822123823123824123825123826123827123828123829123830123831123832123833123834123835123836123837123838123839123840123841123842123843123844123845123846123847123848123849123850123851123852123853123854123855123856123857123858123859123860123861123862123863123864123865123866123867123868123869123870123871123872123873123874123875123876123877123878123879123880123881123882123883123884123885123886123887123888123889123890123891123892123893123894123895123896123897123898123899123900123901123902123903123904123905123906123907123908123909123910123911123912123913123914123915123916123917123918123919123920123921123922123923123924123925123926123927123928123929123930123931123932123933123934123935123936123937123938123939123940123941123942123943123944123945123946123947123948123949123950123951123952123953123954123955123956123957123958123959123960123961123962123963123964123965123966123967123968123969123970123971123972123973123974123975123976123977123978123979123980123981123982123983123984123985123986123987123988123989123990123991123992123993123994123995123996123997123998123999124000124001124002124003124004124005124006124007124008124009124010124011124012124013124014124015124016124017124018124019124020124021124022124023124024124025124026124027124028124029124030124031124032124033124034124035124036124037124038124039124040124041124042124043124044124045124046124047124048124049124050124051124052124053124054124055124056124057124058124059124060124061124062124063124064124065124066124067124068124069124070124071124072124073124074124075124076124077124078124079124080124081124082124083124084124085124086124087124088124089124090124091124092124093124094124095124096124097124098124099124100124101124102124103124104124105124106124107124108124109124110124111124112124113124114124115124116124117124118124119124120124121124122124123124124124125124126124127124128124129124130124131124132124133124134124135124136124137124138124139124140124141124142124143124144124145124146124147124148124149124150124151124152124153124154124155124156124157124158124159124160124161124162124163124164124165124166124167124168124169124170124171124172124173124174124175124176124177124178124179124180124181124182124183124184124185124186124187124188124189124190124191124192124193124194124195124196124197124198124199124200124201124202124203124204124205124206124207124208124209124210124211124212124213124214124215124216124217124218124219124220124221124222124223124224124225124226124227124228124229124230124231124232124233124234124235124236124237124238124239124240124241124242124243124244124245124246124247124248124249124250124251124252124253124254124255124256124257124258124259124260124261124262124263124264124265124266124267124268124269124270124271124272124273124274124275124276124277124278124279124280124281124282124283124284124285124286124287124288124289124290124291124292124293124294124295124296124297124298124299124300124301124302124303124304124305124306124307124308124309124310124311124312124313124314124315124316124317124318124319124320124321124322124323124324124325124326124327124328124329124330124331124332124333124334124335124336124337124338124339124340124341124342124343124344124345124346124347124348124349124350124351124352124353124354124355124356124357124358124359124360124361124362124363124364124365124366124367124368124369124370124371124372124373124374124375124376124377124378124379124380124381124382124383124384124385124386124387124388124389124390124391124392124393124394124395124396124397124398124399124400124401124402124403124404124405124406124407124408124409124410124411124412124413124414124415124416124417124418124419124420124421124422124423124424124425124426124427124428124429124430124431124432124433124434124435124436124437124438124439124440124441124442124443124444124445124446124447124448124449124450124451124452124453124454124455124456124457124458124459124460124461124462124463124464124465124466124467124468124469124470124471124472124473124474124475124476124477124478124479124480124481124482124483124484124485124486124487124488124489124490124491124492124493124494124495124496124497124498124499124500124501124502124503124504124505124506124507124508124509124510124511124512124513124514124515124516124517124518124519124520124521124522124523124524124525124526124527124528124529124530124531124532124533124534124535124536124537124538124539124540124541124542124543124544124545124546124547124548124549124550124551124552124553124554124555124556124557124558124559124560124561124562124563124564124565124566124567124568124569124570124571124572124573124574124575124576124577124578124579124580124581124582124583124584124585124586124587124588124589124590124591124592124593124594124595124596124597124598124599124600124601124602124603124604124605124606124607124608124609124610124611124612124613124614124615124616124617124618124619124620124621124622124623124624124625124626124627124628124629124630124631124632124633124634124635124636124637124638124639124640124641124642124643124644124645124646124647124648124649124650124651124652124653124654124655124656124657124658124659124660124661124662124663124664124665124666124667124668124669124670124671124672124673124674124675124676124677124678124679124680124681124682124683124684124685124686124687124688124689124690124691124692124693124694124695124696124697124698124699124700124701124702124703124704124705124706124707124708124709124710124711124712124713124714124715124716124717124718124719124720124721124722124723124724124725124726124727124728124729124730124731124732124733124734124735124736124737124738124739124740124741124742124743124744124745124746124747124748124749124750124751124752124753124754124755124756124757124758124759124760124761124762124763124764124765124766124767124768124769124770124771124772124773124774124775124776124777124778124779124780124781124782124783124784124785124786124787124788124789124790124791124792124793124794124795124796124797124798124799124800124801124802124803124804124805124806124807124808124809124810124811124812124813124814124815124816124817124818124819124820124821124822124823124824124825124826124827124828124829124830124831124832124833124834124835124836124837124838124839124840124841124842124843124844124845124846124847124848124849124850124851124852124853124854124855124856124857124858124859124860124861124862124863124864124865124866124867124868124869124870124871124872124873124874124875124876124877124878124879124880124881124882124883124884124885124886124887124888124889124890124891124892124893124894124895124896124897124898124899124900124901124902124903124904124905124906124907124908124909124910124911124912124913124914124915124916124917124918124919124920124921124922124923124924124925124926124927124928124929124930124931124932124933124934124935124936124937124938124939124940124941124942124943124944124945124946124947124948124949124950124951124952124953124954124955124956124957124958124959124960124961124962124963124964124965124966124967124968124969124970124971124972124973124974124975124976124977124978124979124980124981124982124983124984124985124986124987124988124989124990124991124992124993124994124995124996124997124998124999125000125001125002125003125004125005125006125007125008125009125010125011125012125013125014125015125016125017125018125019125020125021125022125023125024125025125026125027125028125029125030125031125032125033125034125035125036125037125038125039125040125041125042125043125044125045125046125047125048125049125050125051125052125053125054125055125056125057125058125059125060125061125062125063125064125065125066125067125068
  1. diff -Nur linux-3.18.6/arch/arm/boot/dts/bcm2708.dtsi linux-rpi/arch/arm/boot/dts/bcm2708.dtsi
  2. --- linux-3.18.6/arch/arm/boot/dts/bcm2708.dtsi 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-rpi/arch/arm/boot/dts/bcm2708.dtsi 2015-02-09 04:39:42.000000000 +0100
  4. @@ -0,0 +1,105 @@
  5. +/include/ "skeleton.dtsi"
  6. +
  7. +/ {
  8. + compatible = "brcm,bcm2708";
  9. + model = "BCM2708";
  10. +
  11. + interrupt-parent = <&intc>;
  12. +
  13. + chosen {
  14. + /* No padding required - the boot loader can do that. */
  15. + bootargs = "";
  16. + };
  17. +
  18. + soc: soc {
  19. + compatible = "simple-bus";
  20. + #address-cells = <1>;
  21. + #size-cells = <1>;
  22. + ranges = <0x7e000000 0x20000000 0x01000000>;
  23. +
  24. + intc: interrupt-controller {
  25. + compatible = "brcm,bcm2708-armctrl-ic";
  26. + reg = <0x7e00b200 0x200>;
  27. + interrupt-controller;
  28. + #interrupt-cells = <2>;
  29. + };
  30. +
  31. + gpio: gpio {
  32. + compatible = "brcm,bcm2835-gpio";
  33. + reg = <0x7e200000 0xb4>;
  34. + interrupts = <2 17>, <2 18>;
  35. +
  36. + gpio-controller;
  37. + #gpio-cells = <2>;
  38. +
  39. + interrupt-controller;
  40. + #interrupt-cells = <2>;
  41. + };
  42. +
  43. + i2s: i2s@7e203000 {
  44. + compatible = "brcm,bcm2708-i2s";
  45. + reg = <0x7e203000 0x20>,
  46. + <0x7e101098 0x02>;
  47. +
  48. + //dmas = <&dma 2>,
  49. + // <&dma 3>;
  50. + dma-names = "tx", "rx";
  51. + status = "disabled";
  52. + };
  53. +
  54. + spi0: spi@7e204000 {
  55. + compatible = "brcm,bcm2708-spi";
  56. + reg = <0x7e204000 0x1000>;
  57. + interrupts = <2 22>;
  58. + clocks = <&clk_spi>;
  59. + #address-cells = <1>;
  60. + #size-cells = <0>;
  61. + status = "disabled";
  62. + };
  63. +
  64. + i2c0: i2c@7e205000 {
  65. + compatible = "brcm,bcm2708-i2c";
  66. + reg = <0x7e205000 0x1000>;
  67. + interrupts = <2 21>;
  68. + clocks = <&clk_i2c>;
  69. + #address-cells = <1>;
  70. + #size-cells = <0>;
  71. + status = "disabled";
  72. + };
  73. +
  74. + i2c1: i2c@7e804000 {
  75. + compatible = "brcm,bcm2708-i2c";
  76. + reg = <0x7e804000 0x1000>;
  77. + interrupts = <2 21>;
  78. + clocks = <&clk_i2c>;
  79. + #address-cells = <1>;
  80. + #size-cells = <0>;
  81. + status = "disabled";
  82. + };
  83. +
  84. + leds: leds {
  85. + compatible = "gpio-leds";
  86. + };
  87. + };
  88. +
  89. + clocks {
  90. + compatible = "simple-bus";
  91. + #address-cells = <1>;
  92. + #size-cells = <0>;
  93. +
  94. + clk_i2c: i2c {
  95. + compatible = "fixed-clock";
  96. + reg = <1>;
  97. + #clock-cells = <0>;
  98. + clock-frequency = <250000000>;
  99. + };
  100. +
  101. + clk_spi: clock@2 {
  102. + compatible = "fixed-clock";
  103. + reg = <2>;
  104. + #clock-cells = <0>;
  105. + clock-output-names = "spi";
  106. + clock-frequency = <250000000>;
  107. + };
  108. + };
  109. +};
  110. diff -Nur linux-3.18.6/arch/arm/boot/dts/bcm2708-rpi-b.dts linux-rpi/arch/arm/boot/dts/bcm2708-rpi-b.dts
  111. --- linux-3.18.6/arch/arm/boot/dts/bcm2708-rpi-b.dts 1970-01-01 01:00:00.000000000 +0100
  112. +++ linux-rpi/arch/arm/boot/dts/bcm2708-rpi-b.dts 2015-02-09 04:39:42.000000000 +0100
  113. @@ -0,0 +1,107 @@
  114. +/dts-v1/;
  115. +
  116. +/include/ "bcm2708.dtsi"
  117. +
  118. +/ {
  119. + compatible = "brcm,bcm2708";
  120. + model = "Raspberry Pi Model B";
  121. +
  122. + aliases {
  123. + soc = &soc;
  124. + spi0 = &spi0;
  125. + i2c0 = &i2c0;
  126. + i2c1 = &i2c1;
  127. + i2s = &i2s;
  128. + gpio = &gpio;
  129. + intc = &intc;
  130. + leds = &leds;
  131. + sound = &sound;
  132. + };
  133. +
  134. + sound: sound {
  135. + };
  136. +};
  137. +
  138. +&gpio {
  139. + spi0_pins: spi0_pins {
  140. + brcm,pins = <7 8 9 10 11>;
  141. + brcm,function = <4>; /* alt0 */
  142. + };
  143. +
  144. + i2c0_pins: i2c0 {
  145. + brcm,pins = <0 1>;
  146. + brcm,function = <4>;
  147. + };
  148. +
  149. + i2c1_pins: i2c1 {
  150. + brcm,pins = <2 3>;
  151. + brcm,function = <4>;
  152. + };
  153. +
  154. + i2s_pins: i2s {
  155. + brcm,pins = <28 29 30 31>;
  156. + brcm,function = <4>; /* alt0 */
  157. + };
  158. +};
  159. +
  160. +&spi0 {
  161. + pinctrl-names = "default";
  162. + pinctrl-0 = <&spi0_pins>;
  163. +
  164. + spidev@0{
  165. + compatible = "spidev";
  166. + reg = <0>; /* CE0 */
  167. + #address-cells = <1>;
  168. + #size-cells = <0>;
  169. + spi-max-frequency = <500000>;
  170. + };
  171. +
  172. + spidev@1{
  173. + compatible = "spidev";
  174. + reg = <1>; /* CE1 */
  175. + #address-cells = <1>;
  176. + #size-cells = <0>;
  177. + spi-max-frequency = <500000>;
  178. + };
  179. +};
  180. +
  181. +&i2c0 {
  182. + pinctrl-names = "default";
  183. + pinctrl-0 = <&i2c0_pins>;
  184. + clock-frequency = <100000>;
  185. +};
  186. +
  187. +&i2c1 {
  188. + pinctrl-names = "default";
  189. + pinctrl-0 = <&i2c1_pins>;
  190. + clock-frequency = <100000>;
  191. +};
  192. +
  193. +&i2s {
  194. + #sound-dai-cells = <0>;
  195. + pinctrl-names = "default";
  196. + pinctrl-0 = <&i2s_pins>;
  197. +};
  198. +
  199. +&leds {
  200. + act_led: act {
  201. + label = "led0";
  202. + linux,default-trigger = "mmc0";
  203. + gpios = <&gpio 16 1>;
  204. + };
  205. +};
  206. +
  207. +/ {
  208. + __overrides__ {
  209. + i2s = <&i2s>,"status";
  210. + spi = <&spi0>,"status";
  211. + i2c0 = <&i2c0>,"status";
  212. + i2c1 = <&i2c1>,"status";
  213. + i2c0_baudrate = <&i2c0>,"clock-frequency:0";
  214. + i2c1_baudrate = <&i2c1>,"clock-frequency:0";
  215. +
  216. + act_led_gpio = <&act_led>,"gpios:4";
  217. + act_led_activelow = <&act_led>,"gpios:8";
  218. + act_led_trigger = <&act_led>,"linux,default-trigger";
  219. + };
  220. +};
  221. diff -Nur linux-3.18.6/arch/arm/boot/dts/bcm2708-rpi-b-plus.dts linux-rpi/arch/arm/boot/dts/bcm2708-rpi-b-plus.dts
  222. --- linux-3.18.6/arch/arm/boot/dts/bcm2708-rpi-b-plus.dts 1970-01-01 01:00:00.000000000 +0100
  223. +++ linux-rpi/arch/arm/boot/dts/bcm2708-rpi-b-plus.dts 2015-02-09 04:39:42.000000000 +0100
  224. @@ -0,0 +1,117 @@
  225. +/dts-v1/;
  226. +
  227. +/include/ "bcm2708.dtsi"
  228. +
  229. +/ {
  230. + compatible = "brcm,bcm2708";
  231. + model = "Raspberry Pi Model B+";
  232. +
  233. + aliases {
  234. + soc = &soc;
  235. + spi0 = &spi0;
  236. + i2c0 = &i2c0;
  237. + i2c1 = &i2c1;
  238. + i2s = &i2s;
  239. + gpio = &gpio;
  240. + intc = &intc;
  241. + leds = &leds;
  242. + sound = &sound;
  243. + };
  244. +
  245. + sound: sound {
  246. + };
  247. +};
  248. +
  249. +&gpio {
  250. + spi0_pins: spi0_pins {
  251. + brcm,pins = <7 8 9 10 11>;
  252. + brcm,function = <4>; /* alt0 */
  253. + };
  254. +
  255. + i2c0_pins: i2c0 {
  256. + brcm,pins = <0 1>;
  257. + brcm,function = <4>;
  258. + };
  259. +
  260. + i2c1_pins: i2c1 {
  261. + brcm,pins = <2 3>;
  262. + brcm,function = <4>;
  263. + };
  264. +
  265. + i2s_pins: i2s {
  266. + brcm,pins = <18 19 20 21>;
  267. + brcm,function = <4>; /* alt0 */
  268. + };
  269. +};
  270. +
  271. +&spi0 {
  272. + pinctrl-names = "default";
  273. + pinctrl-0 = <&spi0_pins>;
  274. +
  275. + spidev@0{
  276. + compatible = "spidev";
  277. + reg = <0>; /* CE0 */
  278. + #address-cells = <1>;
  279. + #size-cells = <0>;
  280. + spi-max-frequency = <500000>;
  281. + };
  282. +
  283. + spidev@1{
  284. + compatible = "spidev";
  285. + reg = <1>; /* CE1 */
  286. + #address-cells = <1>;
  287. + #size-cells = <0>;
  288. + spi-max-frequency = <500000>;
  289. + };
  290. +};
  291. +
  292. +&i2c0 {
  293. + pinctrl-names = "default";
  294. + pinctrl-0 = <&i2c0_pins>;
  295. + clock-frequency = <100000>;
  296. +};
  297. +
  298. +&i2c1 {
  299. + pinctrl-names = "default";
  300. + pinctrl-0 = <&i2c1_pins>;
  301. + clock-frequency = <100000>;
  302. +};
  303. +
  304. +&i2s {
  305. + #sound-dai-cells = <0>;
  306. + pinctrl-names = "default";
  307. + pinctrl-0 = <&i2s_pins>;
  308. +};
  309. +
  310. +&leds {
  311. + act_led: act {
  312. + label = "led0";
  313. + linux,default-trigger = "mmc0";
  314. + gpios = <&gpio 47 0>;
  315. + };
  316. +
  317. + pwr_led: pwr {
  318. + label = "led1";
  319. + linux,default-trigger = "input";
  320. + gpios = <&gpio 35 0>;
  321. + };
  322. +};
  323. +
  324. +/ {
  325. + __overrides__ {
  326. + i2s = <&i2s>,"status";
  327. + spi = <&spi0>,"status";
  328. + i2c0 = <&i2c0>,"status";
  329. + i2c1 = <&i2c1>,"status";
  330. + i2c0_baudrate = <&i2c0>,"clock-frequency:0";
  331. + i2c1_baudrate = <&i2c1>,"clock-frequency:0";
  332. +
  333. + act_led_gpio = <&act_led>,"gpios:4";
  334. + act_led_activelow = <&act_led>,"gpios:8";
  335. + act_led_trigger = <&act_led>,"linux,default-trigger";
  336. +
  337. + pwr_led_gpio = <&pwr_led>,"gpios:4";
  338. + pwr_led_activelow = <&pwr_led>,"gpios:8";
  339. + pwr_led_trigger = <&pwr_led>,"linux,default-trigger";
  340. + };
  341. +};
  342. diff -Nur linux-3.18.6/arch/arm/boot/dts/bcm2709.dtsi linux-rpi/arch/arm/boot/dts/bcm2709.dtsi
  343. --- linux-3.18.6/arch/arm/boot/dts/bcm2709.dtsi 1970-01-01 01:00:00.000000000 +0100
  344. +++ linux-rpi/arch/arm/boot/dts/bcm2709.dtsi 2015-02-09 04:39:42.000000000 +0100
  345. @@ -0,0 +1,155 @@
  346. +/include/ "skeleton.dtsi"
  347. +
  348. +/ {
  349. + compatible = "brcm,bcm2709";
  350. + model = "BCM2709";
  351. +
  352. + interrupt-parent = <&intc>;
  353. +
  354. + chosen {
  355. + /* No padding required - the boot loader can do that. */
  356. + bootargs = "";
  357. + };
  358. +
  359. + soc: soc {
  360. + compatible = "simple-bus";
  361. + #address-cells = <1>;
  362. + #size-cells = <1>;
  363. + ranges = <0x7e000000 0x3f000000 0x01000000>;
  364. +
  365. + intc: interrupt-controller {
  366. + compatible = "brcm,bcm2708-armctrl-ic";
  367. + reg = <0x7e00b200 0x200>;
  368. + interrupt-controller;
  369. + #interrupt-cells = <2>;
  370. + };
  371. +
  372. + gpio: gpio {
  373. + compatible = "brcm,bcm2835-gpio";
  374. + reg = <0x7e200000 0xb4>;
  375. + interrupts = <2 17>, <2 18>;
  376. +
  377. + gpio-controller;
  378. + #gpio-cells = <2>;
  379. +
  380. + interrupt-controller;
  381. + #interrupt-cells = <2>;
  382. + };
  383. +
  384. + i2s: i2s@7e203000 {
  385. + compatible = "brcm,bcm2708-i2s";
  386. + reg = <0x7e203000 0x20>,
  387. + <0x7e101098 0x02>;
  388. +
  389. + //dmas = <&dma 2>,
  390. + // <&dma 3>;
  391. + dma-names = "tx", "rx";
  392. + status = "disabled";
  393. + };
  394. +
  395. + spi0: spi@7e204000 {
  396. + compatible = "brcm,bcm2708-spi";
  397. + reg = <0x7e204000 0x1000>;
  398. + interrupts = <2 22>;
  399. + clocks = <&clk_spi>;
  400. + #address-cells = <1>;
  401. + #size-cells = <0>;
  402. + status = "disabled";
  403. + };
  404. +
  405. + i2c0: i2c@7e205000 {
  406. + compatible = "brcm,bcm2708-i2c";
  407. + reg = <0x7e205000 0x1000>;
  408. + interrupts = <2 21>;
  409. + clocks = <&clk_i2c>;
  410. + #address-cells = <1>;
  411. + #size-cells = <0>;
  412. + status = "disabled";
  413. + };
  414. +
  415. + i2c1: i2c@7e804000 {
  416. + compatible = "brcm,bcm2708-i2c";
  417. + reg = <0x7e804000 0x1000>;
  418. + interrupts = <2 21>;
  419. + clocks = <&clk_i2c>;
  420. + #address-cells = <1>;
  421. + #size-cells = <0>;
  422. + status = "disabled";
  423. + };
  424. +
  425. + leds: leds {
  426. + compatible = "gpio-leds";
  427. + };
  428. + };
  429. +
  430. + clocks {
  431. + compatible = "simple-bus";
  432. + #address-cells = <1>;
  433. + #size-cells = <0>;
  434. +
  435. + clk_i2c: i2c {
  436. + compatible = "fixed-clock";
  437. + reg = <1>;
  438. + #clock-cells = <0>;
  439. + clock-frequency = <250000000>;
  440. + };
  441. +
  442. + clk_spi: clock@2 {
  443. + compatible = "fixed-clock";
  444. + reg = <2>;
  445. + #clock-cells = <0>;
  446. + clock-output-names = "spi";
  447. + clock-frequency = <250000000>;
  448. + };
  449. + };
  450. +
  451. + timer {
  452. + compatible = "arm,armv7-timer";
  453. + clock-frequency = <19200000>;
  454. + interrupts = <3 0>, // PHYS_SECURE_PPI
  455. + <3 1>, // PHYS_NONSECURE_PPI
  456. + <3 3>, // VIRT_PPI
  457. + <3 2>; // HYP_PPI
  458. + always-on;
  459. + };
  460. +
  461. + cpus: cpus {
  462. + #address-cells = <1>;
  463. + #size-cells = <0>;
  464. +
  465. + v7_cpu0: cpu@0 {
  466. + device_type = "cpu";
  467. + compatible = "arm,cortex-a7";
  468. + reg = <0xf00>;
  469. + clock-frequency = <800000000>;
  470. + };
  471. +
  472. + v7_cpu1: cpu@1 {
  473. + device_type = "cpu";
  474. + compatible = "arm,cortex-a7";
  475. + reg = <0xf01>;
  476. + clock-frequency = <800000000>;
  477. + };
  478. +
  479. + v7_cpu2: cpu@2 {
  480. + device_type = "cpu";
  481. + compatible = "arm,cortex-a7";
  482. + reg = <0xf02>;
  483. + clock-frequency = <800000000>;
  484. + };
  485. +
  486. + v7_cpu3: cpu@3 {
  487. + device_type = "cpu";
  488. + compatible = "arm,cortex-a7";
  489. + reg = <0xf03>;
  490. + clock-frequency = <800000000>;
  491. + };
  492. + };
  493. +
  494. + __overrides__ {
  495. + arm_freq = <&v7_cpu0>, "clock-frequency:0",
  496. + <&v7_cpu1>, "clock-frequency:0",
  497. + <&v7_cpu2>, "clock-frequency:0",
  498. + <&v7_cpu3>, "clock-frequency:0";
  499. + };
  500. +};
  501. diff -Nur linux-3.18.6/arch/arm/boot/dts/bcm2709-rpi-2-b.dts linux-rpi/arch/arm/boot/dts/bcm2709-rpi-2-b.dts
  502. --- linux-3.18.6/arch/arm/boot/dts/bcm2709-rpi-2-b.dts 1970-01-01 01:00:00.000000000 +0100
  503. +++ linux-rpi/arch/arm/boot/dts/bcm2709-rpi-2-b.dts 2015-02-09 04:39:42.000000000 +0100
  504. @@ -0,0 +1,117 @@
  505. +/dts-v1/;
  506. +
  507. +/include/ "bcm2709.dtsi"
  508. +
  509. +/ {
  510. + compatible = "brcm,bcm2709";
  511. + model = "Raspberry Pi 2 Model B";
  512. +
  513. + aliases {
  514. + soc = &soc;
  515. + spi0 = &spi0;
  516. + i2c0 = &i2c0;
  517. + i2c1 = &i2c1;
  518. + i2s = &i2s;
  519. + gpio = &gpio;
  520. + intc = &intc;
  521. + leds = &leds;
  522. + sound = &sound;
  523. + };
  524. +
  525. + sound: sound {
  526. + };
  527. +};
  528. +
  529. +&gpio {
  530. + spi0_pins: spi0_pins {
  531. + brcm,pins = <7 8 9 10 11>;
  532. + brcm,function = <4>; /* alt0 */
  533. + };
  534. +
  535. + i2c0_pins: i2c0 {
  536. + brcm,pins = <0 1>;
  537. + brcm,function = <4>;
  538. + };
  539. +
  540. + i2c1_pins: i2c1 {
  541. + brcm,pins = <2 3>;
  542. + brcm,function = <4>;
  543. + };
  544. +
  545. + i2s_pins: i2s {
  546. + brcm,pins = <18 19 20 21>;
  547. + brcm,function = <4>; /* alt0 */
  548. + };
  549. +};
  550. +
  551. +&spi0 {
  552. + pinctrl-names = "default";
  553. + pinctrl-0 = <&spi0_pins>;
  554. +
  555. + spidev@0{
  556. + compatible = "spidev";
  557. + reg = <0>; /* CE0 */
  558. + #address-cells = <1>;
  559. + #size-cells = <0>;
  560. + spi-max-frequency = <500000>;
  561. + };
  562. +
  563. + spidev@1{
  564. + compatible = "spidev";
  565. + reg = <1>; /* CE1 */
  566. + #address-cells = <1>;
  567. + #size-cells = <0>;
  568. + spi-max-frequency = <500000>;
  569. + };
  570. +};
  571. +
  572. +&i2c0 {
  573. + pinctrl-names = "default";
  574. + pinctrl-0 = <&i2c0_pins>;
  575. + clock-frequency = <100000>;
  576. +};
  577. +
  578. +&i2c1 {
  579. + pinctrl-names = "default";
  580. + pinctrl-0 = <&i2c1_pins>;
  581. + clock-frequency = <100000>;
  582. +};
  583. +
  584. +&i2s {
  585. + #sound-dai-cells = <0>;
  586. + pinctrl-names = "default";
  587. + pinctrl-0 = <&i2s_pins>;
  588. +};
  589. +
  590. +&leds {
  591. + act_led: act {
  592. + label = "led0";
  593. + linux,default-trigger = "mmc0";
  594. + gpios = <&gpio 47 0>;
  595. + };
  596. +
  597. + pwr_led: pwr {
  598. + label = "led1";
  599. + linux,default-trigger = "input";
  600. + gpios = <&gpio 35 0>;
  601. + };
  602. +};
  603. +
  604. +/ {
  605. + __overrides__ {
  606. + i2s = <&i2s>,"status";
  607. + spi = <&spi0>,"status";
  608. + i2c0 = <&i2c0>,"status";
  609. + i2c1 = <&i2c1>,"status";
  610. + i2c0_baudrate = <&i2c0>,"clock-frequency:0";
  611. + i2c1_baudrate = <&i2c1>,"clock-frequency:0";
  612. +
  613. + act_led_gpio = <&act_led>,"gpios:4";
  614. + act_led_activelow = <&act_led>,"gpios:8";
  615. + act_led_trigger = <&act_led>,"linux,default-trigger";
  616. +
  617. + pwr_led_gpio = <&pwr_led>,"gpios:4";
  618. + pwr_led_activelow = <&pwr_led>,"gpios:8";
  619. + pwr_led_trigger = <&pwr_led>,"linux,default-trigger";
  620. + };
  621. +};
  622. diff -Nur linux-3.18.6/arch/arm/boot/dts/ds1307-rtc-overlay.dts linux-rpi/arch/arm/boot/dts/ds1307-rtc-overlay.dts
  623. --- linux-3.18.6/arch/arm/boot/dts/ds1307-rtc-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  624. +++ linux-rpi/arch/arm/boot/dts/ds1307-rtc-overlay.dts 2015-02-09 04:39:42.000000000 +0100
  625. @@ -0,0 +1,22 @@
  626. +// Definitions for DS1307 Real Time Clock
  627. +/dts-v1/;
  628. +/plugin/;
  629. +
  630. +/ {
  631. + compatible = "brcm,bcm2708";
  632. +
  633. + fragment@0 {
  634. + target = <&i2c1>;
  635. + __overlay__ {
  636. + #address-cells = <1>;
  637. + #size-cells = <0>;
  638. + status = "okay";
  639. +
  640. + ds1307@68 {
  641. + compatible = "maxim,ds1307";
  642. + reg = <0x68>;
  643. + status = "okay";
  644. + };
  645. + };
  646. + };
  647. +};
  648. diff -Nur linux-3.18.6/arch/arm/boot/dts/hifiberry-amp-overlay.dts linux-rpi/arch/arm/boot/dts/hifiberry-amp-overlay.dts
  649. --- linux-3.18.6/arch/arm/boot/dts/hifiberry-amp-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  650. +++ linux-rpi/arch/arm/boot/dts/hifiberry-amp-overlay.dts 2015-02-09 04:39:42.000000000 +0100
  651. @@ -0,0 +1,39 @@
  652. +// Definitions for HiFiBerry Amp/Amp+
  653. +/dts-v1/;
  654. +/plugin/;
  655. +
  656. +/ {
  657. + compatible = "brcm,bcm2708";
  658. +
  659. + fragment@0 {
  660. + target = <&sound>;
  661. + __overlay__ {
  662. + compatible = "hifiberry,hifiberry-amp";
  663. + i2s-controller = <&i2s>;
  664. + status = "okay";
  665. + };
  666. + };
  667. +
  668. + fragment@1 {
  669. + target = <&i2s>;
  670. + __overlay__ {
  671. + status = "okay";
  672. + };
  673. + };
  674. +
  675. + fragment@2 {
  676. + target = <&i2c1>;
  677. + __overlay__ {
  678. + #address-cells = <1>;
  679. + #size-cells = <0>;
  680. + status = "okay";
  681. +
  682. + tas5713@1b {
  683. + #sound-dai-cells = <0>;
  684. + compatible = "ti,tas5713";
  685. + reg = <0x1b>;
  686. + status = "okay";
  687. + };
  688. + };
  689. + };
  690. +};
  691. diff -Nur linux-3.18.6/arch/arm/boot/dts/hifiberry-dac-overlay.dts linux-rpi/arch/arm/boot/dts/hifiberry-dac-overlay.dts
  692. --- linux-3.18.6/arch/arm/boot/dts/hifiberry-dac-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  693. +++ linux-rpi/arch/arm/boot/dts/hifiberry-dac-overlay.dts 2015-02-09 04:39:42.000000000 +0100
  694. @@ -0,0 +1,34 @@
  695. +// Definitions for HiFiBerry DAC
  696. +/dts-v1/;
  697. +/plugin/;
  698. +
  699. +/ {
  700. + compatible = "brcm,bcm2708";
  701. +
  702. + fragment@0 {
  703. + target = <&sound>;
  704. + __overlay__ {
  705. + compatible = "hifiberry,hifiberry-dac";
  706. + i2s-controller = <&i2s>;
  707. + status = "okay";
  708. + };
  709. + };
  710. +
  711. + fragment@1 {
  712. + target = <&i2s>;
  713. + __overlay__ {
  714. + status = "okay";
  715. + };
  716. + };
  717. +
  718. + fragment@2 {
  719. + target-path = "/";
  720. + __overlay__ {
  721. + pcm5102a-codec {
  722. + #sound-dai-cells = <0>;
  723. + compatible = "ti,pcm5102a";
  724. + status = "okay";
  725. + };
  726. + };
  727. + };
  728. +};
  729. diff -Nur linux-3.18.6/arch/arm/boot/dts/hifiberry-dacplus-overlay.dts linux-rpi/arch/arm/boot/dts/hifiberry-dacplus-overlay.dts
  730. --- linux-3.18.6/arch/arm/boot/dts/hifiberry-dacplus-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  731. +++ linux-rpi/arch/arm/boot/dts/hifiberry-dacplus-overlay.dts 2015-02-09 04:39:42.000000000 +0100
  732. @@ -0,0 +1,39 @@
  733. +// Definitions for HiFiBerry DAC+
  734. +/dts-v1/;
  735. +/plugin/;
  736. +
  737. +/ {
  738. + compatible = "brcm,bcm2708";
  739. +
  740. + fragment@0 {
  741. + target = <&sound>;
  742. + __overlay__ {
  743. + compatible = "hifiberry,hifiberry-dacplus";
  744. + i2s-controller = <&i2s>;
  745. + status = "okay";
  746. + };
  747. + };
  748. +
  749. + fragment@1 {
  750. + target = <&i2s>;
  751. + __overlay__ {
  752. + status = "okay";
  753. + };
  754. + };
  755. +
  756. + fragment@2 {
  757. + target = <&i2c1>;
  758. + __overlay__ {
  759. + #address-cells = <1>;
  760. + #size-cells = <0>;
  761. + status = "okay";
  762. +
  763. + pcm5122@4d {
  764. + #sound-dai-cells = <0>;
  765. + compatible = "ti,pcm5122";
  766. + reg = <0x4d>;
  767. + status = "okay";
  768. + };
  769. + };
  770. + };
  771. +};
  772. diff -Nur linux-3.18.6/arch/arm/boot/dts/hifiberry-digi-overlay.dts linux-rpi/arch/arm/boot/dts/hifiberry-digi-overlay.dts
  773. --- linux-3.18.6/arch/arm/boot/dts/hifiberry-digi-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  774. +++ linux-rpi/arch/arm/boot/dts/hifiberry-digi-overlay.dts 2015-02-09 04:39:42.000000000 +0100
  775. @@ -0,0 +1,39 @@
  776. +// Definitions for HiFiBerry Digi
  777. +/dts-v1/;
  778. +/plugin/;
  779. +
  780. +/ {
  781. + compatible = "brcm,bcm2708";
  782. +
  783. + fragment@0 {
  784. + target = <&sound>;
  785. + __overlay__ {
  786. + compatible = "hifiberry,hifiberry-digi";
  787. + i2s-controller = <&i2s>;
  788. + status = "okay";
  789. + };
  790. + };
  791. +
  792. + fragment@1 {
  793. + target = <&i2s>;
  794. + __overlay__ {
  795. + status = "okay";
  796. + };
  797. + };
  798. +
  799. + fragment@2 {
  800. + target = <&i2c1>;
  801. + __overlay__ {
  802. + #address-cells = <1>;
  803. + #size-cells = <0>;
  804. + status = "okay";
  805. +
  806. + wm8804@3b {
  807. + #sound-dai-cells = <0>;
  808. + compatible = "wlf,wm8804";
  809. + reg = <0x3b>;
  810. + status = "okay";
  811. + };
  812. + };
  813. + };
  814. +};
  815. diff -Nur linux-3.18.6/arch/arm/boot/dts/iqaudio-dac-overlay.dts linux-rpi/arch/arm/boot/dts/iqaudio-dac-overlay.dts
  816. --- linux-3.18.6/arch/arm/boot/dts/iqaudio-dac-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  817. +++ linux-rpi/arch/arm/boot/dts/iqaudio-dac-overlay.dts 2015-02-09 04:39:42.000000000 +0100
  818. @@ -0,0 +1,39 @@
  819. +// Definitions for IQaudIO DAC
  820. +/dts-v1/;
  821. +/plugin/;
  822. +
  823. +/ {
  824. + compatible = "brcm,bcm2708";
  825. +
  826. + fragment@0 {
  827. + target = <&sound>;
  828. + __overlay__ {
  829. + compatible = "iqaudio,iqaudio-dac";
  830. + i2s-controller = <&i2s>;
  831. + status = "okay";
  832. + };
  833. + };
  834. +
  835. + fragment@1 {
  836. + target = <&i2s>;
  837. + __overlay__ {
  838. + status = "okay";
  839. + };
  840. + };
  841. +
  842. + fragment@2 {
  843. + target = <&i2c1>;
  844. + __overlay__ {
  845. + #address-cells = <1>;
  846. + #size-cells = <0>;
  847. + status = "okay";
  848. +
  849. + pcm5122@4c {
  850. + #sound-dai-cells = <0>;
  851. + compatible = "ti,pcm5122";
  852. + reg = <0x4c>;
  853. + status = "okay";
  854. + };
  855. + };
  856. + };
  857. +};
  858. diff -Nur linux-3.18.6/arch/arm/boot/dts/iqaudio-dacplus-overlay.dts linux-rpi/arch/arm/boot/dts/iqaudio-dacplus-overlay.dts
  859. --- linux-3.18.6/arch/arm/boot/dts/iqaudio-dacplus-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  860. +++ linux-rpi/arch/arm/boot/dts/iqaudio-dacplus-overlay.dts 2015-02-09 04:39:42.000000000 +0100
  861. @@ -0,0 +1,39 @@
  862. +// Definitions for IQaudIO DAC+
  863. +/dts-v1/;
  864. +/plugin/;
  865. +
  866. +/ {
  867. + compatible = "brcm,bcm2708";
  868. +
  869. + fragment@0 {
  870. + target = <&sound>;
  871. + __overlay__ {
  872. + compatible = "iqaudio,iqaudio-dac";
  873. + i2s-controller = <&i2s>;
  874. + status = "okay";
  875. + };
  876. + };
  877. +
  878. + fragment@1 {
  879. + target = <&i2s>;
  880. + __overlay__ {
  881. + status = "okay";
  882. + };
  883. + };
  884. +
  885. + fragment@2 {
  886. + target = <&i2c1>;
  887. + __overlay__ {
  888. + #address-cells = <1>;
  889. + #size-cells = <0>;
  890. + status = "okay";
  891. +
  892. + pcm5122@4c {
  893. + #sound-dai-cells = <0>;
  894. + compatible = "ti,pcm5122";
  895. + reg = <0x4c>;
  896. + status = "okay";
  897. + };
  898. + };
  899. + };
  900. +};
  901. diff -Nur linux-3.18.6/arch/arm/boot/dts/lirc-rpi-overlay.dts linux-rpi/arch/arm/boot/dts/lirc-rpi-overlay.dts
  902. --- linux-3.18.6/arch/arm/boot/dts/lirc-rpi-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  903. +++ linux-rpi/arch/arm/boot/dts/lirc-rpi-overlay.dts 2015-02-09 04:39:42.000000000 +0100
  904. @@ -0,0 +1,57 @@
  905. +// Definitions for lirc-rpi module
  906. +/dts-v1/;
  907. +/plugin/;
  908. +
  909. +/ {
  910. + compatible = "brcm,bcm2708";
  911. +
  912. + fragment@0 {
  913. + target-path = "/";
  914. + __overlay__ {
  915. + lirc_rpi: lirc_rpi {
  916. + compatible = "rpi,lirc-rpi";
  917. + pinctrl-names = "default";
  918. + pinctrl-0 = <&lirc_pins>;
  919. + status = "okay";
  920. +
  921. + // Override autodetection of IR receiver circuit
  922. + // (0 = active high, 1 = active low, -1 = no override )
  923. + rpi,sense = <0xffffffff>;
  924. +
  925. + // Software carrier
  926. + // (0 = off, 1 = on)
  927. + rpi,softcarrier = <1>;
  928. +
  929. + // Invert output
  930. + // (0 = off, 1 = on)
  931. + rpi,invert = <0>;
  932. +
  933. + // Enable debugging messages
  934. + // (0 = off, 1 = on)
  935. + rpi,debug = <0>;
  936. + };
  937. + };
  938. + };
  939. +
  940. + fragment@1 {
  941. + target = <&gpio>;
  942. + __overlay__ {
  943. + lirc_pins: lirc_pins {
  944. + brcm,pins = <17 18>;
  945. + brcm,function = <1 0>; // out in
  946. + brcm,pull = <0 1>; // off down
  947. + };
  948. + };
  949. + };
  950. +
  951. + __overrides__ {
  952. + gpio_out_pin = <&lirc_pins>,"brcm,pins:0";
  953. + gpio_in_pin = <&lirc_pins>,"brcm,pins:4";
  954. + gpio_in_pull = <&lirc_pins>,"brcm,pull:4";
  955. +
  956. + sense = <&lirc_rpi>,"rpi,sense:0";
  957. + softcarrier = <&lirc_rpi>,"rpi,softcarrier:0";
  958. + invert = <&lirc_rpi>,"rpi,invert:0";
  959. + debug = <&lirc_rpi>,"rpi,debug:0";
  960. + };
  961. +};
  962. diff -Nur linux-3.18.6/arch/arm/boot/dts/Makefile linux-rpi/arch/arm/boot/dts/Makefile
  963. --- linux-3.18.6/arch/arm/boot/dts/Makefile 2015-02-06 15:53:48.000000000 +0100
  964. +++ linux-rpi/arch/arm/boot/dts/Makefile 2015-02-09 04:39:42.000000000 +0100
  965. @@ -53,7 +53,32 @@
  966. dtb-$(CONFIG_ARCH_ATLAS6) += atlas6-evb.dtb
  967. dtb-$(CONFIG_ARCH_AXXIA) += axm5516-amarillo.dtb
  968. +
  969. +# Raspberry Pi
  970. +ifeq ($(CONFIG_BCM2708_DT),y)
  971. + RPI_DT_OVERLAYS=y
  972. +endif
  973. +ifeq ($(CONFIG_BCM2709_DT),y)
  974. + RPI_DT_OVERLAYS=y
  975. +endif
  976. +dtb-$(CONFIG_BCM2708_DT) += bcm2708-rpi-b.dtb
  977. +dtb-$(CONFIG_BCM2708_DT) += bcm2708-rpi-b-plus.dtb
  978. +dtb-$(CONFIG_BCM2709_DT) += bcm2709-rpi-2-b.dtb
  979. +dtb-$(RPI_DT_OVERLAYS) += ds1307-rtc-overlay.dtb
  980. +dtb-$(RPI_DT_OVERLAYS) += hifiberry-dac-overlay.dtb
  981. +dtb-$(RPI_DT_OVERLAYS) += hifiberry-dacplus-overlay.dtb
  982. +dtb-$(RPI_DT_OVERLAYS) += hifiberry-digi-overlay.dtb
  983. +dtb-$(RPI_DT_OVERLAYS) += hifiberry-amp-overlay.dtb
  984. +dtb-$(RPI_DT_OVERLAYS) += iqaudio-dac-overlay.dtb
  985. +dtb-$(RPI_DT_OVERLAYS) += iqaudio-dacplus-overlay.dtb
  986. +dtb-$(RPI_DT_OVERLAYS) += lirc-rpi-overlay.dtb
  987. +dtb-$(RPI_DT_OVERLAYS) += pcf2127-rtc-overlay.dtb
  988. +dtb-$(RPI_DT_OVERLAYS) += pcf8523-rtc-overlay.dtb
  989. +dtb-$(RPI_DT_OVERLAYS) += pps-gpio-overlay.dtb
  990. +dtb-$(RPI_DT_OVERLAYS) += w1-gpio-overlay.dtb
  991. +dtb-$(RPI_DT_OVERLAYS) += w1-gpio-pullup-overlay.dtb
  992. dtb-$(CONFIG_ARCH_BCM2835) += bcm2835-rpi-b.dtb
  993. +
  994. dtb-$(CONFIG_ARCH_BCM_5301X) += bcm4708-netgear-r6250.dtb
  995. dtb-$(CONFIG_ARCH_BCM_63XX) += bcm963138dvt.dtb
  996. dtb-$(CONFIG_ARCH_BCM_MOBILE) += bcm28155-ap.dtb \
  997. @@ -519,6 +544,12 @@
  998. targets += dtbs dtbs_install
  999. targets += $(dtb-y)
  1000. +
  1001. +endif
  1002. +
  1003. +# Enable fixups to support overlays on BCM2708 platforms
  1004. +ifeq ($(RPI_DT_OVERLAYS),y)
  1005. + DTC_FLAGS ?= -@
  1006. endif
  1007. # *.dtb used to be generated in the directory above. Clean out the
  1008. diff -Nur linux-3.18.6/arch/arm/boot/dts/pcf2127-rtc-overlay.dts linux-rpi/arch/arm/boot/dts/pcf2127-rtc-overlay.dts
  1009. --- linux-3.18.6/arch/arm/boot/dts/pcf2127-rtc-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1010. +++ linux-rpi/arch/arm/boot/dts/pcf2127-rtc-overlay.dts 2015-02-09 04:39:42.000000000 +0100
  1011. @@ -0,0 +1,22 @@
  1012. +// Definitions for PCF2127 Real Time Clock
  1013. +/dts-v1/;
  1014. +/plugin/;
  1015. +
  1016. +/ {
  1017. + compatible = "brcm,bcm2708";
  1018. +
  1019. + fragment@0 {
  1020. + target = <&i2c1>;
  1021. + __overlay__ {
  1022. + #address-cells = <1>;
  1023. + #size-cells = <0>;
  1024. + status = "okay";
  1025. +
  1026. + pcf2127@51 {
  1027. + compatible = "nxp,pcf2127";
  1028. + reg = <0x51>;
  1029. + status = "okay";
  1030. + };
  1031. + };
  1032. + };
  1033. +};
  1034. diff -Nur linux-3.18.6/arch/arm/boot/dts/pcf8523-rtc-overlay.dts linux-rpi/arch/arm/boot/dts/pcf8523-rtc-overlay.dts
  1035. --- linux-3.18.6/arch/arm/boot/dts/pcf8523-rtc-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1036. +++ linux-rpi/arch/arm/boot/dts/pcf8523-rtc-overlay.dts 2015-02-09 04:39:42.000000000 +0100
  1037. @@ -0,0 +1,22 @@
  1038. +// Definitions for PCF8523 Real Time Clock
  1039. +/dts-v1/;
  1040. +/plugin/;
  1041. +
  1042. +/ {
  1043. + compatible = "brcm,bcm2708";
  1044. +
  1045. + fragment@0 {
  1046. + target = <&i2c1>;
  1047. + __overlay__ {
  1048. + #address-cells = <1>;
  1049. + #size-cells = <0>;
  1050. + status = "okay";
  1051. +
  1052. + pcf8523@68 {
  1053. + compatible = "nxp,pcf8523";
  1054. + reg = <0x68>;
  1055. + status = "okay";
  1056. + };
  1057. + };
  1058. + };
  1059. +};
  1060. diff -Nur linux-3.18.6/arch/arm/boot/dts/pps-gpio-overlay.dts linux-rpi/arch/arm/boot/dts/pps-gpio-overlay.dts
  1061. --- linux-3.18.6/arch/arm/boot/dts/pps-gpio-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1062. +++ linux-rpi/arch/arm/boot/dts/pps-gpio-overlay.dts 2015-02-09 04:39:42.000000000 +0100
  1063. @@ -0,0 +1,34 @@
  1064. +/dts-v1/;
  1065. +/plugin/;
  1066. +
  1067. +/ {
  1068. + compatible = "brcm,bcm2708";
  1069. + fragment@0 {
  1070. + target-path = "/";
  1071. + __overlay__ {
  1072. + pps: pps {
  1073. + compatible = "pps-gpio";
  1074. + pinctrl-names = "default";
  1075. + pinctrl-0 = <&pps_pins>;
  1076. + gpios = <&gpio 18 0>;
  1077. + status = "okay";
  1078. + };
  1079. + };
  1080. + };
  1081. +
  1082. + fragment@1 {
  1083. + target = <&gpio>;
  1084. + __overlay__ {
  1085. + pps_pins: pps_pins {
  1086. + brcm,pins = <18>;
  1087. + brcm,function = <0>; // in
  1088. + brcm,pull = <0>; // off
  1089. + };
  1090. + };
  1091. + };
  1092. +
  1093. + __overrides__ {
  1094. + gpiopin = <&pps>,"gpios:4",
  1095. + <&pps_pins>,"brcm,pins:0";
  1096. + };
  1097. +};
  1098. diff -Nur linux-3.18.6/arch/arm/boot/dts/w1-gpio-overlay.dts linux-rpi/arch/arm/boot/dts/w1-gpio-overlay.dts
  1099. --- linux-3.18.6/arch/arm/boot/dts/w1-gpio-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1100. +++ linux-rpi/arch/arm/boot/dts/w1-gpio-overlay.dts 2015-02-09 04:39:42.000000000 +0100
  1101. @@ -0,0 +1,39 @@
  1102. +// Definitions for w1-gpio module (without external pullup)
  1103. +/dts-v1/;
  1104. +/plugin/;
  1105. +
  1106. +/ {
  1107. + compatible = "brcm,bcm2708";
  1108. +
  1109. + fragment@0 {
  1110. + target-path = "/";
  1111. + __overlay__ {
  1112. +
  1113. + w1: onewire@0 {
  1114. + compatible = "w1-gpio";
  1115. + pinctrl-names = "default";
  1116. + pinctrl-0 = <&w1_pins>;
  1117. + gpios = <&gpio 4 0>;
  1118. + rpi,parasitic-power = <0>;
  1119. + status = "okay";
  1120. + };
  1121. + };
  1122. + };
  1123. +
  1124. + fragment@1 {
  1125. + target = <&gpio>;
  1126. + __overlay__ {
  1127. + w1_pins: w1_pins {
  1128. + brcm,pins = <4>;
  1129. + brcm,function = <0>; // in (initially)
  1130. + brcm,pull = <0>; // off
  1131. + };
  1132. + };
  1133. + };
  1134. +
  1135. + __overrides__ {
  1136. + gpiopin = <&w1>,"gpios:4",
  1137. + <&w1_pins>,"brcm,pins:0";
  1138. + pullup = <&w1>,"rpi,parasitic-power:0";
  1139. + };
  1140. +};
  1141. diff -Nur linux-3.18.6/arch/arm/boot/dts/w1-gpio-pullup-overlay.dts linux-rpi/arch/arm/boot/dts/w1-gpio-pullup-overlay.dts
  1142. --- linux-3.18.6/arch/arm/boot/dts/w1-gpio-pullup-overlay.dts 1970-01-01 01:00:00.000000000 +0100
  1143. +++ linux-rpi/arch/arm/boot/dts/w1-gpio-pullup-overlay.dts 2015-02-09 04:39:42.000000000 +0100
  1144. @@ -0,0 +1,41 @@
  1145. +// Definitions for w1-gpio module (with external pullup)
  1146. +/dts-v1/;
  1147. +/plugin/;
  1148. +
  1149. +/ {
  1150. + compatible = "brcm,bcm2708";
  1151. +
  1152. + fragment@0 {
  1153. + target-path = "/";
  1154. + __overlay__ {
  1155. +
  1156. + w1: onewire@0 {
  1157. + compatible = "w1-gpio";
  1158. + pinctrl-names = "default";
  1159. + pinctrl-0 = <&w1_pins>;
  1160. + gpios = <&gpio 4 0>, <&gpio 5 1>;
  1161. + rpi,parasitic-power = <0>;
  1162. + status = "okay";
  1163. + };
  1164. + };
  1165. + };
  1166. +
  1167. + fragment@1 {
  1168. + target = <&gpio>;
  1169. + __overlay__ {
  1170. + w1_pins: w1_pins {
  1171. + brcm,pins = <4 5>;
  1172. + brcm,function = <0 1>; // in out
  1173. + brcm,pull = <0 0>; // off off
  1174. + };
  1175. + };
  1176. + };
  1177. +
  1178. + __overrides__ {
  1179. + gpiopin = <&w1>,"gpios:4",
  1180. + <&w1_pins>,"brcm,pins:0";
  1181. + extpullup = <&w1>,"gpios:16",
  1182. + <&w1_pins>,"brcm,pins:4";
  1183. + pullup = <&w1>,"rpi,parasitic-power:0";
  1184. + };
  1185. +};
  1186. diff -Nur linux-3.18.6/arch/arm/configs/bcm2709_defconfig linux-rpi/arch/arm/configs/bcm2709_defconfig
  1187. --- linux-3.18.6/arch/arm/configs/bcm2709_defconfig 1970-01-01 01:00:00.000000000 +0100
  1188. +++ linux-rpi/arch/arm/configs/bcm2709_defconfig 2015-02-09 04:39:42.000000000 +0100
  1189. @@ -0,0 +1,1157 @@
  1190. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  1191. +CONFIG_PHYS_OFFSET=0
  1192. +CONFIG_LOCALVERSION="-v7"
  1193. +# CONFIG_LOCALVERSION_AUTO is not set
  1194. +CONFIG_SYSVIPC=y
  1195. +CONFIG_POSIX_MQUEUE=y
  1196. +CONFIG_FHANDLE=y
  1197. +CONFIG_AUDIT=y
  1198. +CONFIG_NO_HZ=y
  1199. +CONFIG_HIGH_RES_TIMERS=y
  1200. +CONFIG_BSD_PROCESS_ACCT=y
  1201. +CONFIG_BSD_PROCESS_ACCT_V3=y
  1202. +CONFIG_TASKSTATS=y
  1203. +CONFIG_TASK_DELAY_ACCT=y
  1204. +CONFIG_TASK_XACCT=y
  1205. +CONFIG_TASK_IO_ACCOUNTING=y
  1206. +CONFIG_IKCONFIG=y
  1207. +CONFIG_IKCONFIG_PROC=y
  1208. +CONFIG_CGROUP_FREEZER=y
  1209. +CONFIG_CGROUP_DEVICE=y
  1210. +CONFIG_CGROUP_CPUACCT=y
  1211. +CONFIG_RESOURCE_COUNTERS=y
  1212. +CONFIG_MEMCG=y
  1213. +CONFIG_BLK_CGROUP=y
  1214. +CONFIG_NAMESPACES=y
  1215. +CONFIG_SCHED_AUTOGROUP=y
  1216. +CONFIG_BLK_DEV_INITRD=y
  1217. +CONFIG_EMBEDDED=y
  1218. +# CONFIG_COMPAT_BRK is not set
  1219. +CONFIG_PROFILING=y
  1220. +CONFIG_OPROFILE=m
  1221. +CONFIG_KPROBES=y
  1222. +CONFIG_JUMP_LABEL=y
  1223. +CONFIG_MODULES=y
  1224. +CONFIG_MODULE_UNLOAD=y
  1225. +CONFIG_MODVERSIONS=y
  1226. +CONFIG_MODULE_SRCVERSION_ALL=y
  1227. +CONFIG_BLK_DEV_THROTTLING=y
  1228. +CONFIG_PARTITION_ADVANCED=y
  1229. +CONFIG_MAC_PARTITION=y
  1230. +CONFIG_CFQ_GROUP_IOSCHED=y
  1231. +CONFIG_ARCH_BCM2709=y
  1232. +CONFIG_BCM2709_DT=y
  1233. +# CONFIG_CACHE_L2X0 is not set
  1234. +CONFIG_SMP=y
  1235. +CONFIG_HAVE_ARM_ARCH_TIMER=y
  1236. +CONFIG_VMSPLIT_2G=y
  1237. +CONFIG_PREEMPT=y
  1238. +CONFIG_AEABI=y
  1239. +CONFIG_CLEANCACHE=y
  1240. +CONFIG_FRONTSWAP=y
  1241. +CONFIG_CMA=y
  1242. +CONFIG_UACCESS_WITH_MEMCPY=y
  1243. +CONFIG_SECCOMP=y
  1244. +CONFIG_ZBOOT_ROM_TEXT=0x0
  1245. +CONFIG_ZBOOT_ROM_BSS=0x0
  1246. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  1247. +CONFIG_KEXEC=y
  1248. +CONFIG_CPU_FREQ=y
  1249. +CONFIG_CPU_FREQ_STAT=m
  1250. +CONFIG_CPU_FREQ_STAT_DETAILS=y
  1251. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  1252. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  1253. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  1254. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  1255. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  1256. +CONFIG_CPU_IDLE=y
  1257. +CONFIG_VFP=y
  1258. +CONFIG_NEON=y
  1259. +CONFIG_KERNEL_MODE_NEON=y
  1260. +CONFIG_BINFMT_MISC=m
  1261. +CONFIG_NET=y
  1262. +CONFIG_PACKET=y
  1263. +CONFIG_UNIX=y
  1264. +CONFIG_XFRM_USER=y
  1265. +CONFIG_NET_KEY=m
  1266. +CONFIG_INET=y
  1267. +CONFIG_IP_MULTICAST=y
  1268. +CONFIG_IP_ADVANCED_ROUTER=y
  1269. +CONFIG_IP_MULTIPLE_TABLES=y
  1270. +CONFIG_IP_ROUTE_MULTIPATH=y
  1271. +CONFIG_IP_ROUTE_VERBOSE=y
  1272. +CONFIG_IP_PNP=y
  1273. +CONFIG_IP_PNP_DHCP=y
  1274. +CONFIG_IP_PNP_RARP=y
  1275. +CONFIG_NET_IPIP=m
  1276. +CONFIG_NET_IPGRE_DEMUX=m
  1277. +CONFIG_NET_IPGRE=m
  1278. +CONFIG_IP_MROUTE=y
  1279. +CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
  1280. +CONFIG_IP_PIMSM_V1=y
  1281. +CONFIG_IP_PIMSM_V2=y
  1282. +CONFIG_SYN_COOKIES=y
  1283. +CONFIG_INET_AH=m
  1284. +CONFIG_INET_ESP=m
  1285. +CONFIG_INET_IPCOMP=m
  1286. +CONFIG_INET_XFRM_MODE_TRANSPORT=m
  1287. +CONFIG_INET_XFRM_MODE_TUNNEL=m
  1288. +CONFIG_INET_XFRM_MODE_BEET=m
  1289. +CONFIG_INET_LRO=m
  1290. +CONFIG_INET_DIAG=m
  1291. +CONFIG_INET6_AH=m
  1292. +CONFIG_INET6_ESP=m
  1293. +CONFIG_INET6_IPCOMP=m
  1294. +CONFIG_IPV6_TUNNEL=m
  1295. +CONFIG_IPV6_MULTIPLE_TABLES=y
  1296. +CONFIG_IPV6_MROUTE=y
  1297. +CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
  1298. +CONFIG_IPV6_PIMSM_V2=y
  1299. +CONFIG_NETFILTER=y
  1300. +CONFIG_NF_CONNTRACK=m
  1301. +CONFIG_NF_CONNTRACK_ZONES=y
  1302. +CONFIG_NF_CONNTRACK_EVENTS=y
  1303. +CONFIG_NF_CONNTRACK_TIMESTAMP=y
  1304. +CONFIG_NF_CT_PROTO_DCCP=m
  1305. +CONFIG_NF_CT_PROTO_UDPLITE=m
  1306. +CONFIG_NF_CONNTRACK_AMANDA=m
  1307. +CONFIG_NF_CONNTRACK_FTP=m
  1308. +CONFIG_NF_CONNTRACK_H323=m
  1309. +CONFIG_NF_CONNTRACK_IRC=m
  1310. +CONFIG_NF_CONNTRACK_NETBIOS_NS=m
  1311. +CONFIG_NF_CONNTRACK_SNMP=m
  1312. +CONFIG_NF_CONNTRACK_PPTP=m
  1313. +CONFIG_NF_CONNTRACK_SANE=m
  1314. +CONFIG_NF_CONNTRACK_SIP=m
  1315. +CONFIG_NF_CONNTRACK_TFTP=m
  1316. +CONFIG_NF_CT_NETLINK=m
  1317. +CONFIG_NETFILTER_XT_SET=m
  1318. +CONFIG_NETFILTER_XT_TARGET_AUDIT=m
  1319. +CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
  1320. +CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
  1321. +CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
  1322. +CONFIG_NETFILTER_XT_TARGET_DSCP=m
  1323. +CONFIG_NETFILTER_XT_TARGET_HMARK=m
  1324. +CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m
  1325. +CONFIG_NETFILTER_XT_TARGET_LED=m
  1326. +CONFIG_NETFILTER_XT_TARGET_LOG=m
  1327. +CONFIG_NETFILTER_XT_TARGET_MARK=m
  1328. +CONFIG_NETFILTER_XT_TARGET_NFLOG=m
  1329. +CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
  1330. +CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
  1331. +CONFIG_NETFILTER_XT_TARGET_TEE=m
  1332. +CONFIG_NETFILTER_XT_TARGET_TPROXY=m
  1333. +CONFIG_NETFILTER_XT_TARGET_TRACE=m
  1334. +CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
  1335. +CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
  1336. +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
  1337. +CONFIG_NETFILTER_XT_MATCH_BPF=m
  1338. +CONFIG_NETFILTER_XT_MATCH_CLUSTER=m
  1339. +CONFIG_NETFILTER_XT_MATCH_COMMENT=m
  1340. +CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
  1341. +CONFIG_NETFILTER_XT_MATCH_CONNLABEL=m
  1342. +CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
  1343. +CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
  1344. +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
  1345. +CONFIG_NETFILTER_XT_MATCH_CPU=m
  1346. +CONFIG_NETFILTER_XT_MATCH_DCCP=m
  1347. +CONFIG_NETFILTER_XT_MATCH_DEVGROUP=m
  1348. +CONFIG_NETFILTER_XT_MATCH_DSCP=m
  1349. +CONFIG_NETFILTER_XT_MATCH_ESP=m
  1350. +CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
  1351. +CONFIG_NETFILTER_XT_MATCH_HELPER=m
  1352. +CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
  1353. +CONFIG_NETFILTER_XT_MATCH_IPVS=m
  1354. +CONFIG_NETFILTER_XT_MATCH_LENGTH=m
  1355. +CONFIG_NETFILTER_XT_MATCH_LIMIT=m
  1356. +CONFIG_NETFILTER_XT_MATCH_MAC=m
  1357. +CONFIG_NETFILTER_XT_MATCH_MARK=m
  1358. +CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
  1359. +CONFIG_NETFILTER_XT_MATCH_NFACCT=m
  1360. +CONFIG_NETFILTER_XT_MATCH_OSF=m
  1361. +CONFIG_NETFILTER_XT_MATCH_OWNER=m
  1362. +CONFIG_NETFILTER_XT_MATCH_POLICY=m
  1363. +CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
  1364. +CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
  1365. +CONFIG_NETFILTER_XT_MATCH_QUOTA=m
  1366. +CONFIG_NETFILTER_XT_MATCH_RATEEST=m
  1367. +CONFIG_NETFILTER_XT_MATCH_REALM=m
  1368. +CONFIG_NETFILTER_XT_MATCH_RECENT=m
  1369. +CONFIG_NETFILTER_XT_MATCH_SOCKET=m
  1370. +CONFIG_NETFILTER_XT_MATCH_STATE=m
  1371. +CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
  1372. +CONFIG_NETFILTER_XT_MATCH_STRING=m
  1373. +CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
  1374. +CONFIG_NETFILTER_XT_MATCH_TIME=m
  1375. +CONFIG_NETFILTER_XT_MATCH_U32=m
  1376. +CONFIG_IP_SET=m
  1377. +CONFIG_IP_SET_BITMAP_IP=m
  1378. +CONFIG_IP_SET_BITMAP_IPMAC=m
  1379. +CONFIG_IP_SET_BITMAP_PORT=m
  1380. +CONFIG_IP_SET_HASH_IP=m
  1381. +CONFIG_IP_SET_HASH_IPPORT=m
  1382. +CONFIG_IP_SET_HASH_IPPORTIP=m
  1383. +CONFIG_IP_SET_HASH_IPPORTNET=m
  1384. +CONFIG_IP_SET_HASH_NET=m
  1385. +CONFIG_IP_SET_HASH_NETPORT=m
  1386. +CONFIG_IP_SET_HASH_NETIFACE=m
  1387. +CONFIG_IP_SET_LIST_SET=m
  1388. +CONFIG_IP_VS=m
  1389. +CONFIG_IP_VS_PROTO_TCP=y
  1390. +CONFIG_IP_VS_PROTO_UDP=y
  1391. +CONFIG_IP_VS_PROTO_ESP=y
  1392. +CONFIG_IP_VS_PROTO_AH=y
  1393. +CONFIG_IP_VS_PROTO_SCTP=y
  1394. +CONFIG_IP_VS_RR=m
  1395. +CONFIG_IP_VS_WRR=m
  1396. +CONFIG_IP_VS_LC=m
  1397. +CONFIG_IP_VS_WLC=m
  1398. +CONFIG_IP_VS_LBLC=m
  1399. +CONFIG_IP_VS_LBLCR=m
  1400. +CONFIG_IP_VS_DH=m
  1401. +CONFIG_IP_VS_SH=m
  1402. +CONFIG_IP_VS_SED=m
  1403. +CONFIG_IP_VS_NQ=m
  1404. +CONFIG_IP_VS_FTP=m
  1405. +CONFIG_IP_VS_PE_SIP=m
  1406. +CONFIG_NF_CONNTRACK_IPV4=m
  1407. +CONFIG_IP_NF_IPTABLES=m
  1408. +CONFIG_IP_NF_MATCH_AH=m
  1409. +CONFIG_IP_NF_MATCH_ECN=m
  1410. +CONFIG_IP_NF_MATCH_TTL=m
  1411. +CONFIG_IP_NF_FILTER=m
  1412. +CONFIG_IP_NF_TARGET_REJECT=m
  1413. +CONFIG_IP_NF_NAT=m
  1414. +CONFIG_IP_NF_TARGET_MASQUERADE=m
  1415. +CONFIG_IP_NF_TARGET_NETMAP=m
  1416. +CONFIG_IP_NF_TARGET_REDIRECT=m
  1417. +CONFIG_IP_NF_MANGLE=m
  1418. +CONFIG_IP_NF_TARGET_CLUSTERIP=m
  1419. +CONFIG_IP_NF_TARGET_ECN=m
  1420. +CONFIG_IP_NF_TARGET_TTL=m
  1421. +CONFIG_IP_NF_RAW=m
  1422. +CONFIG_IP_NF_ARPTABLES=m
  1423. +CONFIG_IP_NF_ARPFILTER=m
  1424. +CONFIG_IP_NF_ARP_MANGLE=m
  1425. +CONFIG_NF_CONNTRACK_IPV6=m
  1426. +CONFIG_IP6_NF_IPTABLES=m
  1427. +CONFIG_IP6_NF_MATCH_AH=m
  1428. +CONFIG_IP6_NF_MATCH_EUI64=m
  1429. +CONFIG_IP6_NF_MATCH_FRAG=m
  1430. +CONFIG_IP6_NF_MATCH_OPTS=m
  1431. +CONFIG_IP6_NF_MATCH_HL=m
  1432. +CONFIG_IP6_NF_MATCH_IPV6HEADER=m
  1433. +CONFIG_IP6_NF_MATCH_MH=m
  1434. +CONFIG_IP6_NF_MATCH_RT=m
  1435. +CONFIG_IP6_NF_TARGET_HL=m
  1436. +CONFIG_IP6_NF_FILTER=m
  1437. +CONFIG_IP6_NF_TARGET_REJECT=m
  1438. +CONFIG_IP6_NF_MANGLE=m
  1439. +CONFIG_IP6_NF_RAW=m
  1440. +CONFIG_IP6_NF_NAT=m
  1441. +CONFIG_IP6_NF_TARGET_MASQUERADE=m
  1442. +CONFIG_IP6_NF_TARGET_NPT=m
  1443. +CONFIG_BRIDGE_NF_EBTABLES=m
  1444. +CONFIG_BRIDGE_EBT_BROUTE=m
  1445. +CONFIG_BRIDGE_EBT_T_FILTER=m
  1446. +CONFIG_BRIDGE_EBT_T_NAT=m
  1447. +CONFIG_BRIDGE_EBT_802_3=m
  1448. +CONFIG_BRIDGE_EBT_AMONG=m
  1449. +CONFIG_BRIDGE_EBT_ARP=m
  1450. +CONFIG_BRIDGE_EBT_IP=m
  1451. +CONFIG_BRIDGE_EBT_IP6=m
  1452. +CONFIG_BRIDGE_EBT_LIMIT=m
  1453. +CONFIG_BRIDGE_EBT_MARK=m
  1454. +CONFIG_BRIDGE_EBT_PKTTYPE=m
  1455. +CONFIG_BRIDGE_EBT_STP=m
  1456. +CONFIG_BRIDGE_EBT_VLAN=m
  1457. +CONFIG_BRIDGE_EBT_ARPREPLY=m
  1458. +CONFIG_BRIDGE_EBT_DNAT=m
  1459. +CONFIG_BRIDGE_EBT_MARK_T=m
  1460. +CONFIG_BRIDGE_EBT_REDIRECT=m
  1461. +CONFIG_BRIDGE_EBT_SNAT=m
  1462. +CONFIG_BRIDGE_EBT_LOG=m
  1463. +CONFIG_BRIDGE_EBT_NFLOG=m
  1464. +CONFIG_SCTP_COOKIE_HMAC_SHA1=y
  1465. +CONFIG_ATM=m
  1466. +CONFIG_L2TP=m
  1467. +CONFIG_L2TP_V3=y
  1468. +CONFIG_L2TP_IP=m
  1469. +CONFIG_L2TP_ETH=m
  1470. +CONFIG_BRIDGE=m
  1471. +CONFIG_VLAN_8021Q=m
  1472. +CONFIG_VLAN_8021Q_GVRP=y
  1473. +CONFIG_ATALK=m
  1474. +CONFIG_NET_SCHED=y
  1475. +CONFIG_NET_SCH_CBQ=m
  1476. +CONFIG_NET_SCH_HTB=m
  1477. +CONFIG_NET_SCH_HFSC=m
  1478. +CONFIG_NET_SCH_PRIO=m
  1479. +CONFIG_NET_SCH_MULTIQ=m
  1480. +CONFIG_NET_SCH_RED=m
  1481. +CONFIG_NET_SCH_SFB=m
  1482. +CONFIG_NET_SCH_SFQ=m
  1483. +CONFIG_NET_SCH_TEQL=m
  1484. +CONFIG_NET_SCH_TBF=m
  1485. +CONFIG_NET_SCH_GRED=m
  1486. +CONFIG_NET_SCH_DSMARK=m
  1487. +CONFIG_NET_SCH_NETEM=m
  1488. +CONFIG_NET_SCH_DRR=m
  1489. +CONFIG_NET_SCH_MQPRIO=m
  1490. +CONFIG_NET_SCH_CHOKE=m
  1491. +CONFIG_NET_SCH_QFQ=m
  1492. +CONFIG_NET_SCH_CODEL=m
  1493. +CONFIG_NET_SCH_FQ_CODEL=m
  1494. +CONFIG_NET_SCH_INGRESS=m
  1495. +CONFIG_NET_SCH_PLUG=m
  1496. +CONFIG_NET_CLS_BASIC=m
  1497. +CONFIG_NET_CLS_TCINDEX=m
  1498. +CONFIG_NET_CLS_ROUTE4=m
  1499. +CONFIG_NET_CLS_FW=m
  1500. +CONFIG_NET_CLS_U32=m
  1501. +CONFIG_CLS_U32_MARK=y
  1502. +CONFIG_NET_CLS_RSVP=m
  1503. +CONFIG_NET_CLS_RSVP6=m
  1504. +CONFIG_NET_CLS_FLOW=m
  1505. +CONFIG_NET_CLS_CGROUP=m
  1506. +CONFIG_NET_EMATCH=y
  1507. +CONFIG_NET_EMATCH_CMP=m
  1508. +CONFIG_NET_EMATCH_NBYTE=m
  1509. +CONFIG_NET_EMATCH_U32=m
  1510. +CONFIG_NET_EMATCH_META=m
  1511. +CONFIG_NET_EMATCH_TEXT=m
  1512. +CONFIG_NET_EMATCH_IPSET=m
  1513. +CONFIG_NET_CLS_ACT=y
  1514. +CONFIG_NET_ACT_POLICE=m
  1515. +CONFIG_NET_ACT_GACT=m
  1516. +CONFIG_GACT_PROB=y
  1517. +CONFIG_NET_ACT_MIRRED=m
  1518. +CONFIG_NET_ACT_IPT=m
  1519. +CONFIG_NET_ACT_NAT=m
  1520. +CONFIG_NET_ACT_PEDIT=m
  1521. +CONFIG_NET_ACT_SIMP=m
  1522. +CONFIG_NET_ACT_SKBEDIT=m
  1523. +CONFIG_NET_ACT_CSUM=m
  1524. +CONFIG_BATMAN_ADV=m
  1525. +CONFIG_OPENVSWITCH=m
  1526. +CONFIG_NET_PKTGEN=m
  1527. +CONFIG_HAMRADIO=y
  1528. +CONFIG_AX25=m
  1529. +CONFIG_NETROM=m
  1530. +CONFIG_ROSE=m
  1531. +CONFIG_MKISS=m
  1532. +CONFIG_6PACK=m
  1533. +CONFIG_BPQETHER=m
  1534. +CONFIG_BAYCOM_SER_FDX=m
  1535. +CONFIG_BAYCOM_SER_HDX=m
  1536. +CONFIG_YAM=m
  1537. +CONFIG_IRDA=m
  1538. +CONFIG_IRLAN=m
  1539. +CONFIG_IRNET=m
  1540. +CONFIG_IRCOMM=m
  1541. +CONFIG_IRDA_ULTRA=y
  1542. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  1543. +CONFIG_IRDA_FAST_RR=y
  1544. +CONFIG_IRTTY_SIR=m
  1545. +CONFIG_KINGSUN_DONGLE=m
  1546. +CONFIG_KSDAZZLE_DONGLE=m
  1547. +CONFIG_KS959_DONGLE=m
  1548. +CONFIG_USB_IRDA=m
  1549. +CONFIG_SIGMATEL_FIR=m
  1550. +CONFIG_MCS_FIR=m
  1551. +CONFIG_BT=m
  1552. +CONFIG_BT_RFCOMM=m
  1553. +CONFIG_BT_RFCOMM_TTY=y
  1554. +CONFIG_BT_BNEP=m
  1555. +CONFIG_BT_BNEP_MC_FILTER=y
  1556. +CONFIG_BT_BNEP_PROTO_FILTER=y
  1557. +CONFIG_BT_HIDP=m
  1558. +CONFIG_BT_HCIBTUSB=m
  1559. +CONFIG_BT_HCIBCM203X=m
  1560. +CONFIG_BT_HCIBPA10X=m
  1561. +CONFIG_BT_HCIBFUSB=m
  1562. +CONFIG_BT_HCIVHCI=m
  1563. +CONFIG_BT_MRVL=m
  1564. +CONFIG_BT_MRVL_SDIO=m
  1565. +CONFIG_BT_ATH3K=m
  1566. +CONFIG_BT_WILINK=m
  1567. +CONFIG_CFG80211_WEXT=y
  1568. +CONFIG_MAC80211=m
  1569. +CONFIG_MAC80211_MESH=y
  1570. +CONFIG_WIMAX=m
  1571. +CONFIG_RFKILL=m
  1572. +CONFIG_RFKILL_INPUT=y
  1573. +CONFIG_NET_9P=m
  1574. +CONFIG_NFC=m
  1575. +CONFIG_NFC_PN533=m
  1576. +CONFIG_DEVTMPFS=y
  1577. +CONFIG_DEVTMPFS_MOUNT=y
  1578. +CONFIG_DMA_CMA=y
  1579. +CONFIG_CMA_SIZE_MBYTES=5
  1580. +CONFIG_BLK_DEV_LOOP=y
  1581. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  1582. +CONFIG_BLK_DEV_DRBD=m
  1583. +CONFIG_BLK_DEV_NBD=m
  1584. +CONFIG_BLK_DEV_RAM=y
  1585. +CONFIG_CDROM_PKTCDVD=m
  1586. +CONFIG_EEPROM_AT24=m
  1587. +CONFIG_SCSI=y
  1588. +# CONFIG_SCSI_PROC_FS is not set
  1589. +CONFIG_BLK_DEV_SD=y
  1590. +CONFIG_CHR_DEV_ST=m
  1591. +CONFIG_CHR_DEV_OSST=m
  1592. +CONFIG_BLK_DEV_SR=m
  1593. +CONFIG_CHR_DEV_SG=m
  1594. +CONFIG_SCSI_ISCSI_ATTRS=y
  1595. +CONFIG_ISCSI_TCP=m
  1596. +CONFIG_ISCSI_BOOT_SYSFS=m
  1597. +CONFIG_MD=y
  1598. +CONFIG_MD_LINEAR=m
  1599. +CONFIG_MD_RAID0=m
  1600. +CONFIG_BLK_DEV_DM=m
  1601. +CONFIG_DM_CRYPT=m
  1602. +CONFIG_DM_SNAPSHOT=m
  1603. +CONFIG_DM_MIRROR=m
  1604. +CONFIG_DM_LOG_USERSPACE=m
  1605. +CONFIG_DM_RAID=m
  1606. +CONFIG_DM_ZERO=m
  1607. +CONFIG_DM_DELAY=m
  1608. +CONFIG_NETDEVICES=y
  1609. +CONFIG_BONDING=m
  1610. +CONFIG_DUMMY=m
  1611. +CONFIG_IFB=m
  1612. +CONFIG_MACVLAN=m
  1613. +CONFIG_NETCONSOLE=m
  1614. +CONFIG_TUN=m
  1615. +CONFIG_VETH=m
  1616. +CONFIG_ENC28J60=m
  1617. +CONFIG_MDIO_BITBANG=m
  1618. +CONFIG_PPP=m
  1619. +CONFIG_PPP_BSDCOMP=m
  1620. +CONFIG_PPP_DEFLATE=m
  1621. +CONFIG_PPP_FILTER=y
  1622. +CONFIG_PPP_MPPE=m
  1623. +CONFIG_PPP_MULTILINK=y
  1624. +CONFIG_PPPOATM=m
  1625. +CONFIG_PPPOE=m
  1626. +CONFIG_PPPOL2TP=m
  1627. +CONFIG_PPP_ASYNC=m
  1628. +CONFIG_PPP_SYNC_TTY=m
  1629. +CONFIG_SLIP=m
  1630. +CONFIG_SLIP_COMPRESSED=y
  1631. +CONFIG_SLIP_SMART=y
  1632. +CONFIG_USB_CATC=m
  1633. +CONFIG_USB_KAWETH=m
  1634. +CONFIG_USB_PEGASUS=m
  1635. +CONFIG_USB_RTL8150=m
  1636. +CONFIG_USB_RTL8152=m
  1637. +CONFIG_USB_USBNET=y
  1638. +CONFIG_USB_NET_AX8817X=m
  1639. +CONFIG_USB_NET_AX88179_178A=m
  1640. +CONFIG_USB_NET_CDCETHER=m
  1641. +CONFIG_USB_NET_CDC_EEM=m
  1642. +CONFIG_USB_NET_CDC_NCM=m
  1643. +CONFIG_USB_NET_HUAWEI_CDC_NCM=m
  1644. +CONFIG_USB_NET_CDC_MBIM=m
  1645. +CONFIG_USB_NET_DM9601=m
  1646. +CONFIG_USB_NET_SR9700=m
  1647. +CONFIG_USB_NET_SR9800=m
  1648. +CONFIG_USB_NET_SMSC75XX=m
  1649. +CONFIG_USB_NET_SMSC95XX=y
  1650. +CONFIG_USB_NET_GL620A=m
  1651. +CONFIG_USB_NET_NET1080=m
  1652. +CONFIG_USB_NET_PLUSB=m
  1653. +CONFIG_USB_NET_MCS7830=m
  1654. +CONFIG_USB_NET_CDC_SUBSET=m
  1655. +CONFIG_USB_ALI_M5632=y
  1656. +CONFIG_USB_AN2720=y
  1657. +CONFIG_USB_EPSON2888=y
  1658. +CONFIG_USB_KC2190=y
  1659. +CONFIG_USB_NET_ZAURUS=m
  1660. +CONFIG_USB_NET_CX82310_ETH=m
  1661. +CONFIG_USB_NET_KALMIA=m
  1662. +CONFIG_USB_NET_QMI_WWAN=m
  1663. +CONFIG_USB_HSO=m
  1664. +CONFIG_USB_NET_INT51X1=m
  1665. +CONFIG_USB_IPHETH=m
  1666. +CONFIG_USB_SIERRA_NET=m
  1667. +CONFIG_USB_VL600=m
  1668. +CONFIG_LIBERTAS_THINFIRM=m
  1669. +CONFIG_LIBERTAS_THINFIRM_USB=m
  1670. +CONFIG_AT76C50X_USB=m
  1671. +CONFIG_USB_ZD1201=m
  1672. +CONFIG_USB_NET_RNDIS_WLAN=m
  1673. +CONFIG_RTL8187=m
  1674. +CONFIG_MAC80211_HWSIM=m
  1675. +CONFIG_ATH_CARDS=m
  1676. +CONFIG_ATH9K=m
  1677. +CONFIG_ATH9K_HTC=m
  1678. +CONFIG_CARL9170=m
  1679. +CONFIG_ATH6KL=m
  1680. +CONFIG_ATH6KL_USB=m
  1681. +CONFIG_AR5523=m
  1682. +CONFIG_B43=m
  1683. +# CONFIG_B43_PHY_N is not set
  1684. +CONFIG_B43LEGACY=m
  1685. +CONFIG_BRCMFMAC=m
  1686. +CONFIG_BRCMFMAC_USB=y
  1687. +CONFIG_HOSTAP=m
  1688. +CONFIG_LIBERTAS=m
  1689. +CONFIG_LIBERTAS_USB=m
  1690. +CONFIG_LIBERTAS_SDIO=m
  1691. +CONFIG_P54_COMMON=m
  1692. +CONFIG_P54_USB=m
  1693. +CONFIG_RT2X00=m
  1694. +CONFIG_RT2500USB=m
  1695. +CONFIG_RT73USB=m
  1696. +CONFIG_RT2800USB=m
  1697. +CONFIG_RT2800USB_RT3573=y
  1698. +CONFIG_RT2800USB_RT53XX=y
  1699. +CONFIG_RT2800USB_RT55XX=y
  1700. +CONFIG_RT2800USB_UNKNOWN=y
  1701. +CONFIG_RTL8192CU=m
  1702. +CONFIG_ZD1211RW=m
  1703. +CONFIG_MWIFIEX=m
  1704. +CONFIG_MWIFIEX_SDIO=m
  1705. +CONFIG_WIMAX_I2400M_USB=m
  1706. +CONFIG_INPUT_POLLDEV=m
  1707. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1708. +CONFIG_INPUT_JOYDEV=m
  1709. +CONFIG_INPUT_EVDEV=m
  1710. +# CONFIG_INPUT_KEYBOARD is not set
  1711. +# CONFIG_INPUT_MOUSE is not set
  1712. +CONFIG_INPUT_JOYSTICK=y
  1713. +CONFIG_JOYSTICK_IFORCE=m
  1714. +CONFIG_JOYSTICK_IFORCE_USB=y
  1715. +CONFIG_JOYSTICK_XPAD=m
  1716. +CONFIG_JOYSTICK_XPAD_FF=y
  1717. +CONFIG_INPUT_TOUCHSCREEN=y
  1718. +CONFIG_TOUCHSCREEN_ADS7846=m
  1719. +CONFIG_INPUT_MISC=y
  1720. +CONFIG_INPUT_AD714X=m
  1721. +CONFIG_INPUT_ATI_REMOTE2=m
  1722. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1723. +CONFIG_INPUT_POWERMATE=m
  1724. +CONFIG_INPUT_YEALINK=m
  1725. +CONFIG_INPUT_CM109=m
  1726. +CONFIG_INPUT_UINPUT=m
  1727. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1728. +CONFIG_INPUT_ADXL34X=m
  1729. +CONFIG_INPUT_CMA3000=m
  1730. +CONFIG_SERIO=m
  1731. +CONFIG_SERIO_RAW=m
  1732. +CONFIG_GAMEPORT=m
  1733. +CONFIG_GAMEPORT_NS558=m
  1734. +CONFIG_GAMEPORT_L4=m
  1735. +CONFIG_DEVPTS_MULTIPLE_INSTANCES=y
  1736. +# CONFIG_LEGACY_PTYS is not set
  1737. +# CONFIG_DEVKMEM is not set
  1738. +CONFIG_SERIAL_AMBA_PL011=y
  1739. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1740. +CONFIG_TTY_PRINTK=y
  1741. +CONFIG_HW_RANDOM=y
  1742. +CONFIG_HW_RANDOM_BCM2708=m
  1743. +CONFIG_RAW_DRIVER=y
  1744. +CONFIG_BRCM_CHAR_DRIVERS=y
  1745. +CONFIG_BCM_VC_CMA=y
  1746. +CONFIG_BCM_VC_SM=y
  1747. +CONFIG_I2C=y
  1748. +CONFIG_I2C_CHARDEV=m
  1749. +CONFIG_I2C_MUX=m
  1750. +CONFIG_I2C_BCM2708=m
  1751. +CONFIG_SPI=y
  1752. +CONFIG_SPI_BCM2708=m
  1753. +CONFIG_SPI_SPIDEV=y
  1754. +CONFIG_PPS=m
  1755. +CONFIG_PPS_CLIENT_LDISC=m
  1756. +CONFIG_PPS_CLIENT_GPIO=m
  1757. +CONFIG_GPIO_SYSFS=y
  1758. +CONFIG_GPIO_ARIZONA=m
  1759. +CONFIG_W1=m
  1760. +CONFIG_W1_MASTER_DS2490=m
  1761. +CONFIG_W1_MASTER_DS2482=m
  1762. +CONFIG_W1_MASTER_DS1WM=m
  1763. +CONFIG_W1_MASTER_GPIO=m
  1764. +CONFIG_W1_SLAVE_THERM=m
  1765. +CONFIG_W1_SLAVE_SMEM=m
  1766. +CONFIG_W1_SLAVE_DS2408=m
  1767. +CONFIG_W1_SLAVE_DS2413=m
  1768. +CONFIG_W1_SLAVE_DS2406=m
  1769. +CONFIG_W1_SLAVE_DS2423=m
  1770. +CONFIG_W1_SLAVE_DS2431=m
  1771. +CONFIG_W1_SLAVE_DS2433=m
  1772. +CONFIG_W1_SLAVE_DS2760=m
  1773. +CONFIG_W1_SLAVE_DS2780=m
  1774. +CONFIG_W1_SLAVE_DS2781=m
  1775. +CONFIG_W1_SLAVE_DS28E04=m
  1776. +CONFIG_W1_SLAVE_BQ27000=m
  1777. +CONFIG_BATTERY_DS2760=m
  1778. +# CONFIG_HWMON is not set
  1779. +CONFIG_THERMAL=y
  1780. +CONFIG_THERMAL_BCM2835=y
  1781. +CONFIG_WATCHDOG=y
  1782. +CONFIG_BCM2708_WDT=m
  1783. +CONFIG_UCB1400_CORE=m
  1784. +CONFIG_MFD_ARIZONA_I2C=m
  1785. +CONFIG_MFD_ARIZONA_SPI=m
  1786. +CONFIG_MFD_WM5102=y
  1787. +CONFIG_MEDIA_SUPPORT=m
  1788. +CONFIG_MEDIA_CAMERA_SUPPORT=y
  1789. +CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  1790. +CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  1791. +CONFIG_MEDIA_RADIO_SUPPORT=y
  1792. +CONFIG_MEDIA_RC_SUPPORT=y
  1793. +CONFIG_MEDIA_CONTROLLER=y
  1794. +CONFIG_LIRC=m
  1795. +CONFIG_RC_DEVICES=y
  1796. +CONFIG_RC_ATI_REMOTE=m
  1797. +CONFIG_IR_IMON=m
  1798. +CONFIG_IR_MCEUSB=m
  1799. +CONFIG_IR_REDRAT3=m
  1800. +CONFIG_IR_STREAMZAP=m
  1801. +CONFIG_IR_IGUANA=m
  1802. +CONFIG_IR_TTUSBIR=m
  1803. +CONFIG_RC_LOOPBACK=m
  1804. +CONFIG_IR_GPIO_CIR=m
  1805. +CONFIG_MEDIA_USB_SUPPORT=y
  1806. +CONFIG_USB_VIDEO_CLASS=m
  1807. +CONFIG_USB_M5602=m
  1808. +CONFIG_USB_STV06XX=m
  1809. +CONFIG_USB_GL860=m
  1810. +CONFIG_USB_GSPCA_BENQ=m
  1811. +CONFIG_USB_GSPCA_CONEX=m
  1812. +CONFIG_USB_GSPCA_CPIA1=m
  1813. +CONFIG_USB_GSPCA_DTCS033=m
  1814. +CONFIG_USB_GSPCA_ETOMS=m
  1815. +CONFIG_USB_GSPCA_FINEPIX=m
  1816. +CONFIG_USB_GSPCA_JEILINJ=m
  1817. +CONFIG_USB_GSPCA_JL2005BCD=m
  1818. +CONFIG_USB_GSPCA_KINECT=m
  1819. +CONFIG_USB_GSPCA_KONICA=m
  1820. +CONFIG_USB_GSPCA_MARS=m
  1821. +CONFIG_USB_GSPCA_MR97310A=m
  1822. +CONFIG_USB_GSPCA_NW80X=m
  1823. +CONFIG_USB_GSPCA_OV519=m
  1824. +CONFIG_USB_GSPCA_OV534=m
  1825. +CONFIG_USB_GSPCA_OV534_9=m
  1826. +CONFIG_USB_GSPCA_PAC207=m
  1827. +CONFIG_USB_GSPCA_PAC7302=m
  1828. +CONFIG_USB_GSPCA_PAC7311=m
  1829. +CONFIG_USB_GSPCA_SE401=m
  1830. +CONFIG_USB_GSPCA_SN9C2028=m
  1831. +CONFIG_USB_GSPCA_SN9C20X=m
  1832. +CONFIG_USB_GSPCA_SONIXB=m
  1833. +CONFIG_USB_GSPCA_SONIXJ=m
  1834. +CONFIG_USB_GSPCA_SPCA500=m
  1835. +CONFIG_USB_GSPCA_SPCA501=m
  1836. +CONFIG_USB_GSPCA_SPCA505=m
  1837. +CONFIG_USB_GSPCA_SPCA506=m
  1838. +CONFIG_USB_GSPCA_SPCA508=m
  1839. +CONFIG_USB_GSPCA_SPCA561=m
  1840. +CONFIG_USB_GSPCA_SPCA1528=m
  1841. +CONFIG_USB_GSPCA_SQ905=m
  1842. +CONFIG_USB_GSPCA_SQ905C=m
  1843. +CONFIG_USB_GSPCA_SQ930X=m
  1844. +CONFIG_USB_GSPCA_STK014=m
  1845. +CONFIG_USB_GSPCA_STK1135=m
  1846. +CONFIG_USB_GSPCA_STV0680=m
  1847. +CONFIG_USB_GSPCA_SUNPLUS=m
  1848. +CONFIG_USB_GSPCA_T613=m
  1849. +CONFIG_USB_GSPCA_TOPRO=m
  1850. +CONFIG_USB_GSPCA_TV8532=m
  1851. +CONFIG_USB_GSPCA_VC032X=m
  1852. +CONFIG_USB_GSPCA_VICAM=m
  1853. +CONFIG_USB_GSPCA_XIRLINK_CIT=m
  1854. +CONFIG_USB_GSPCA_ZC3XX=m
  1855. +CONFIG_USB_PWC=m
  1856. +CONFIG_VIDEO_CPIA2=m
  1857. +CONFIG_USB_ZR364XX=m
  1858. +CONFIG_USB_STKWEBCAM=m
  1859. +CONFIG_USB_S2255=m
  1860. +CONFIG_VIDEO_USBTV=m
  1861. +CONFIG_VIDEO_PVRUSB2=m
  1862. +CONFIG_VIDEO_HDPVR=m
  1863. +CONFIG_VIDEO_TLG2300=m
  1864. +CONFIG_VIDEO_USBVISION=m
  1865. +CONFIG_VIDEO_STK1160_COMMON=m
  1866. +CONFIG_VIDEO_STK1160_AC97=y
  1867. +CONFIG_VIDEO_GO7007=m
  1868. +CONFIG_VIDEO_GO7007_USB=m
  1869. +CONFIG_VIDEO_GO7007_USB_S2250_BOARD=m
  1870. +CONFIG_VIDEO_AU0828=m
  1871. +CONFIG_VIDEO_AU0828_RC=y
  1872. +CONFIG_VIDEO_CX231XX=m
  1873. +CONFIG_VIDEO_CX231XX_ALSA=m
  1874. +CONFIG_VIDEO_CX231XX_DVB=m
  1875. +CONFIG_VIDEO_TM6000=m
  1876. +CONFIG_VIDEO_TM6000_ALSA=m
  1877. +CONFIG_VIDEO_TM6000_DVB=m
  1878. +CONFIG_DVB_USB=m
  1879. +CONFIG_DVB_USB_A800=m
  1880. +CONFIG_DVB_USB_DIBUSB_MB=m
  1881. +CONFIG_DVB_USB_DIBUSB_MB_FAULTY=y
  1882. +CONFIG_DVB_USB_DIBUSB_MC=m
  1883. +CONFIG_DVB_USB_DIB0700=m
  1884. +CONFIG_DVB_USB_UMT_010=m
  1885. +CONFIG_DVB_USB_CXUSB=m
  1886. +CONFIG_DVB_USB_M920X=m
  1887. +CONFIG_DVB_USB_DIGITV=m
  1888. +CONFIG_DVB_USB_VP7045=m
  1889. +CONFIG_DVB_USB_VP702X=m
  1890. +CONFIG_DVB_USB_GP8PSK=m
  1891. +CONFIG_DVB_USB_NOVA_T_USB2=m
  1892. +CONFIG_DVB_USB_TTUSB2=m
  1893. +CONFIG_DVB_USB_DTT200U=m
  1894. +CONFIG_DVB_USB_OPERA1=m
  1895. +CONFIG_DVB_USB_AF9005=m
  1896. +CONFIG_DVB_USB_AF9005_REMOTE=m
  1897. +CONFIG_DVB_USB_PCTV452E=m
  1898. +CONFIG_DVB_USB_DW2102=m
  1899. +CONFIG_DVB_USB_CINERGY_T2=m
  1900. +CONFIG_DVB_USB_DTV5100=m
  1901. +CONFIG_DVB_USB_FRIIO=m
  1902. +CONFIG_DVB_USB_AZ6027=m
  1903. +CONFIG_DVB_USB_TECHNISAT_USB2=m
  1904. +CONFIG_DVB_USB_V2=m
  1905. +CONFIG_DVB_USB_AF9015=m
  1906. +CONFIG_DVB_USB_AF9035=m
  1907. +CONFIG_DVB_USB_ANYSEE=m
  1908. +CONFIG_DVB_USB_AU6610=m
  1909. +CONFIG_DVB_USB_AZ6007=m
  1910. +CONFIG_DVB_USB_CE6230=m
  1911. +CONFIG_DVB_USB_EC168=m
  1912. +CONFIG_DVB_USB_GL861=m
  1913. +CONFIG_DVB_USB_LME2510=m
  1914. +CONFIG_DVB_USB_MXL111SF=m
  1915. +CONFIG_DVB_USB_RTL28XXU=m
  1916. +CONFIG_DVB_USB_DVBSKY=m
  1917. +CONFIG_SMS_USB_DRV=m
  1918. +CONFIG_DVB_B2C2_FLEXCOP_USB=m
  1919. +CONFIG_DVB_AS102=m
  1920. +CONFIG_VIDEO_EM28XX=m
  1921. +CONFIG_VIDEO_EM28XX_V4L2=m
  1922. +CONFIG_VIDEO_EM28XX_ALSA=m
  1923. +CONFIG_VIDEO_EM28XX_DVB=m
  1924. +CONFIG_V4L_PLATFORM_DRIVERS=y
  1925. +CONFIG_VIDEO_BCM2835=y
  1926. +CONFIG_VIDEO_BCM2835_MMAL=m
  1927. +CONFIG_RADIO_SI470X=y
  1928. +CONFIG_USB_SI470X=m
  1929. +CONFIG_I2C_SI470X=m
  1930. +CONFIG_RADIO_SI4713=m
  1931. +CONFIG_I2C_SI4713=m
  1932. +CONFIG_USB_MR800=m
  1933. +CONFIG_USB_DSBR=m
  1934. +CONFIG_RADIO_SHARK=m
  1935. +CONFIG_RADIO_SHARK2=m
  1936. +CONFIG_USB_KEENE=m
  1937. +CONFIG_USB_MA901=m
  1938. +CONFIG_RADIO_TEA5764=m
  1939. +CONFIG_RADIO_SAA7706H=m
  1940. +CONFIG_RADIO_TEF6862=m
  1941. +CONFIG_RADIO_WL1273=m
  1942. +CONFIG_RADIO_WL128X=m
  1943. +# CONFIG_MEDIA_SUBDRV_AUTOSELECT is not set
  1944. +CONFIG_VIDEO_UDA1342=m
  1945. +CONFIG_VIDEO_SONY_BTF_MPX=m
  1946. +CONFIG_VIDEO_TVP5150=m
  1947. +CONFIG_VIDEO_TW2804=m
  1948. +CONFIG_VIDEO_TW9903=m
  1949. +CONFIG_VIDEO_TW9906=m
  1950. +CONFIG_VIDEO_OV7640=m
  1951. +CONFIG_VIDEO_MT9V011=m
  1952. +CONFIG_FB=y
  1953. +CONFIG_FB_BCM2708=y
  1954. +# CONFIG_BACKLIGHT_GENERIC is not set
  1955. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1956. +CONFIG_LOGO=y
  1957. +# CONFIG_LOGO_LINUX_MONO is not set
  1958. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1959. +CONFIG_SOUND=y
  1960. +CONFIG_SND=m
  1961. +CONFIG_SND_SEQUENCER=m
  1962. +CONFIG_SND_SEQ_DUMMY=m
  1963. +CONFIG_SND_MIXER_OSS=m
  1964. +CONFIG_SND_PCM_OSS=m
  1965. +CONFIG_SND_SEQUENCER_OSS=y
  1966. +CONFIG_SND_HRTIMER=m
  1967. +CONFIG_SND_DUMMY=m
  1968. +CONFIG_SND_ALOOP=m
  1969. +CONFIG_SND_VIRMIDI=m
  1970. +CONFIG_SND_MTPAV=m
  1971. +CONFIG_SND_SERIAL_U16550=m
  1972. +CONFIG_SND_MPU401=m
  1973. +CONFIG_SND_BCM2835=m
  1974. +CONFIG_SND_USB_AUDIO=m
  1975. +CONFIG_SND_USB_UA101=m
  1976. +CONFIG_SND_USB_CAIAQ=m
  1977. +CONFIG_SND_USB_CAIAQ_INPUT=y
  1978. +CONFIG_SND_USB_6FIRE=m
  1979. +CONFIG_SND_SOC=m
  1980. +CONFIG_SND_BCM2708_SOC_I2S=m
  1981. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  1982. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
  1983. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  1984. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m
  1985. +CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  1986. +CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  1987. +CONFIG_SND_SIMPLE_CARD=m
  1988. +CONFIG_SOUND_PRIME=m
  1989. +CONFIG_HIDRAW=y
  1990. +CONFIG_HID_A4TECH=m
  1991. +CONFIG_HID_ACRUX=m
  1992. +CONFIG_HID_APPLE=m
  1993. +CONFIG_HID_BELKIN=m
  1994. +CONFIG_HID_CHERRY=m
  1995. +CONFIG_HID_CHICONY=m
  1996. +CONFIG_HID_CYPRESS=m
  1997. +CONFIG_HID_DRAGONRISE=m
  1998. +CONFIG_HID_EMS_FF=m
  1999. +CONFIG_HID_ELECOM=m
  2000. +CONFIG_HID_ELO=m
  2001. +CONFIG_HID_EZKEY=m
  2002. +CONFIG_HID_HOLTEK=m
  2003. +CONFIG_HID_KEYTOUCH=m
  2004. +CONFIG_HID_KYE=m
  2005. +CONFIG_HID_UCLOGIC=m
  2006. +CONFIG_HID_WALTOP=m
  2007. +CONFIG_HID_GYRATION=m
  2008. +CONFIG_HID_TWINHAN=m
  2009. +CONFIG_HID_KENSINGTON=m
  2010. +CONFIG_HID_LCPOWER=m
  2011. +CONFIG_HID_LOGITECH=m
  2012. +CONFIG_HID_MAGICMOUSE=m
  2013. +CONFIG_HID_MICROSOFT=m
  2014. +CONFIG_HID_MONTEREY=m
  2015. +CONFIG_HID_MULTITOUCH=m
  2016. +CONFIG_HID_NTRIG=m
  2017. +CONFIG_HID_ORTEK=m
  2018. +CONFIG_HID_PANTHERLORD=m
  2019. +CONFIG_HID_PETALYNX=m
  2020. +CONFIG_HID_PICOLCD=m
  2021. +CONFIG_HID_ROCCAT=m
  2022. +CONFIG_HID_SAMSUNG=m
  2023. +CONFIG_HID_SONY=m
  2024. +CONFIG_HID_SPEEDLINK=m
  2025. +CONFIG_HID_SUNPLUS=m
  2026. +CONFIG_HID_GREENASIA=m
  2027. +CONFIG_HID_SMARTJOYPLUS=m
  2028. +CONFIG_HID_TOPSEED=m
  2029. +CONFIG_HID_THINGM=m
  2030. +CONFIG_HID_THRUSTMASTER=m
  2031. +CONFIG_HID_WACOM=m
  2032. +CONFIG_HID_WIIMOTE=m
  2033. +CONFIG_HID_XINMO=m
  2034. +CONFIG_HID_ZEROPLUS=m
  2035. +CONFIG_HID_ZYDACRON=m
  2036. +CONFIG_HID_PID=y
  2037. +CONFIG_USB_HIDDEV=y
  2038. +CONFIG_USB=y
  2039. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  2040. +CONFIG_USB_MON=m
  2041. +CONFIG_USB_DWCOTG=y
  2042. +CONFIG_USB_PRINTER=m
  2043. +CONFIG_USB_STORAGE=y
  2044. +CONFIG_USB_STORAGE_REALTEK=m
  2045. +CONFIG_USB_STORAGE_DATAFAB=m
  2046. +CONFIG_USB_STORAGE_FREECOM=m
  2047. +CONFIG_USB_STORAGE_ISD200=m
  2048. +CONFIG_USB_STORAGE_USBAT=m
  2049. +CONFIG_USB_STORAGE_SDDR09=m
  2050. +CONFIG_USB_STORAGE_SDDR55=m
  2051. +CONFIG_USB_STORAGE_JUMPSHOT=m
  2052. +CONFIG_USB_STORAGE_ALAUDA=m
  2053. +CONFIG_USB_STORAGE_ONETOUCH=m
  2054. +CONFIG_USB_STORAGE_KARMA=m
  2055. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  2056. +CONFIG_USB_STORAGE_ENE_UB6250=m
  2057. +CONFIG_USB_UAS=m
  2058. +CONFIG_USB_MDC800=m
  2059. +CONFIG_USB_MICROTEK=m
  2060. +CONFIG_USBIP_CORE=m
  2061. +CONFIG_USBIP_VHCI_HCD=m
  2062. +CONFIG_USBIP_HOST=m
  2063. +CONFIG_USB_SERIAL=m
  2064. +CONFIG_USB_SERIAL_GENERIC=y
  2065. +CONFIG_USB_SERIAL_AIRCABLE=m
  2066. +CONFIG_USB_SERIAL_ARK3116=m
  2067. +CONFIG_USB_SERIAL_BELKIN=m
  2068. +CONFIG_USB_SERIAL_CH341=m
  2069. +CONFIG_USB_SERIAL_WHITEHEAT=m
  2070. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  2071. +CONFIG_USB_SERIAL_CP210X=m
  2072. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  2073. +CONFIG_USB_SERIAL_EMPEG=m
  2074. +CONFIG_USB_SERIAL_FTDI_SIO=m
  2075. +CONFIG_USB_SERIAL_VISOR=m
  2076. +CONFIG_USB_SERIAL_IPAQ=m
  2077. +CONFIG_USB_SERIAL_IR=m
  2078. +CONFIG_USB_SERIAL_EDGEPORT=m
  2079. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  2080. +CONFIG_USB_SERIAL_F81232=m
  2081. +CONFIG_USB_SERIAL_GARMIN=m
  2082. +CONFIG_USB_SERIAL_IPW=m
  2083. +CONFIG_USB_SERIAL_IUU=m
  2084. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  2085. +CONFIG_USB_SERIAL_KEYSPAN=m
  2086. +CONFIG_USB_SERIAL_KLSI=m
  2087. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  2088. +CONFIG_USB_SERIAL_MCT_U232=m
  2089. +CONFIG_USB_SERIAL_METRO=m
  2090. +CONFIG_USB_SERIAL_MOS7720=m
  2091. +CONFIG_USB_SERIAL_MOS7840=m
  2092. +CONFIG_USB_SERIAL_NAVMAN=m
  2093. +CONFIG_USB_SERIAL_PL2303=m
  2094. +CONFIG_USB_SERIAL_OTI6858=m
  2095. +CONFIG_USB_SERIAL_QCAUX=m
  2096. +CONFIG_USB_SERIAL_QUALCOMM=m
  2097. +CONFIG_USB_SERIAL_SPCP8X5=m
  2098. +CONFIG_USB_SERIAL_SAFE=m
  2099. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  2100. +CONFIG_USB_SERIAL_SYMBOL=m
  2101. +CONFIG_USB_SERIAL_TI=m
  2102. +CONFIG_USB_SERIAL_CYBERJACK=m
  2103. +CONFIG_USB_SERIAL_XIRCOM=m
  2104. +CONFIG_USB_SERIAL_OPTION=m
  2105. +CONFIG_USB_SERIAL_OMNINET=m
  2106. +CONFIG_USB_SERIAL_OPTICON=m
  2107. +CONFIG_USB_SERIAL_XSENS_MT=m
  2108. +CONFIG_USB_SERIAL_WISHBONE=m
  2109. +CONFIG_USB_SERIAL_SSU100=m
  2110. +CONFIG_USB_SERIAL_QT2=m
  2111. +CONFIG_USB_SERIAL_DEBUG=m
  2112. +CONFIG_USB_EMI62=m
  2113. +CONFIG_USB_EMI26=m
  2114. +CONFIG_USB_ADUTUX=m
  2115. +CONFIG_USB_SEVSEG=m
  2116. +CONFIG_USB_RIO500=m
  2117. +CONFIG_USB_LEGOTOWER=m
  2118. +CONFIG_USB_LCD=m
  2119. +CONFIG_USB_LED=m
  2120. +CONFIG_USB_CYPRESS_CY7C63=m
  2121. +CONFIG_USB_CYTHERM=m
  2122. +CONFIG_USB_IDMOUSE=m
  2123. +CONFIG_USB_FTDI_ELAN=m
  2124. +CONFIG_USB_APPLEDISPLAY=m
  2125. +CONFIG_USB_LD=m
  2126. +CONFIG_USB_TRANCEVIBRATOR=m
  2127. +CONFIG_USB_IOWARRIOR=m
  2128. +CONFIG_USB_TEST=m
  2129. +CONFIG_USB_ISIGHTFW=m
  2130. +CONFIG_USB_YUREX=m
  2131. +CONFIG_USB_ATM=m
  2132. +CONFIG_USB_SPEEDTOUCH=m
  2133. +CONFIG_USB_CXACRU=m
  2134. +CONFIG_USB_UEAGLEATM=m
  2135. +CONFIG_USB_XUSBATM=m
  2136. +CONFIG_MMC=y
  2137. +CONFIG_MMC_BLOCK_MINORS=32
  2138. +CONFIG_MMC_SDHCI=y
  2139. +CONFIG_MMC_SDHCI_PLTFM=y
  2140. +CONFIG_MMC_BCM2835=y
  2141. +CONFIG_MMC_BCM2835_DMA=y
  2142. +CONFIG_MMC_SPI=m
  2143. +CONFIG_LEDS_CLASS=y
  2144. +CONFIG_LEDS_GPIO=y
  2145. +CONFIG_LEDS_TRIGGER_TIMER=y
  2146. +CONFIG_LEDS_TRIGGER_ONESHOT=y
  2147. +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
  2148. +CONFIG_LEDS_TRIGGER_BACKLIGHT=y
  2149. +CONFIG_LEDS_TRIGGER_CPU=y
  2150. +CONFIG_LEDS_TRIGGER_GPIO=y
  2151. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
  2152. +CONFIG_LEDS_TRIGGER_TRANSIENT=m
  2153. +CONFIG_LEDS_TRIGGER_CAMERA=m
  2154. +CONFIG_LEDS_TRIGGER_INPUT=y
  2155. +CONFIG_RTC_CLASS=y
  2156. +# CONFIG_RTC_HCTOSYS is not set
  2157. +CONFIG_RTC_DRV_DS1307=m
  2158. +CONFIG_RTC_DRV_DS1374=m
  2159. +CONFIG_RTC_DRV_DS1672=m
  2160. +CONFIG_RTC_DRV_DS3232=m
  2161. +CONFIG_RTC_DRV_MAX6900=m
  2162. +CONFIG_RTC_DRV_RS5C372=m
  2163. +CONFIG_RTC_DRV_ISL1208=m
  2164. +CONFIG_RTC_DRV_ISL12022=m
  2165. +CONFIG_RTC_DRV_ISL12057=m
  2166. +CONFIG_RTC_DRV_X1205=m
  2167. +CONFIG_RTC_DRV_PCF2127=m
  2168. +CONFIG_RTC_DRV_PCF8523=m
  2169. +CONFIG_RTC_DRV_PCF8563=m
  2170. +CONFIG_RTC_DRV_PCF8583=m
  2171. +CONFIG_RTC_DRV_M41T80=m
  2172. +CONFIG_RTC_DRV_BQ32K=m
  2173. +CONFIG_RTC_DRV_S35390A=m
  2174. +CONFIG_RTC_DRV_FM3130=m
  2175. +CONFIG_RTC_DRV_RX8581=m
  2176. +CONFIG_RTC_DRV_RX8025=m
  2177. +CONFIG_RTC_DRV_EM3027=m
  2178. +CONFIG_RTC_DRV_RV3029C2=m
  2179. +CONFIG_RTC_DRV_M41T93=m
  2180. +CONFIG_RTC_DRV_M41T94=m
  2181. +CONFIG_RTC_DRV_DS1305=m
  2182. +CONFIG_RTC_DRV_DS1390=m
  2183. +CONFIG_RTC_DRV_MAX6902=m
  2184. +CONFIG_RTC_DRV_R9701=m
  2185. +CONFIG_RTC_DRV_RS5C348=m
  2186. +CONFIG_RTC_DRV_DS3234=m
  2187. +CONFIG_RTC_DRV_PCF2123=m
  2188. +CONFIG_RTC_DRV_RX4581=m
  2189. +CONFIG_DMADEVICES=y
  2190. +CONFIG_DMA_BCM2708=y
  2191. +CONFIG_UIO=m
  2192. +CONFIG_UIO_PDRV_GENIRQ=m
  2193. +CONFIG_STAGING=y
  2194. +CONFIG_PRISM2_USB=m
  2195. +CONFIG_R8712U=m
  2196. +CONFIG_R8188EU=m
  2197. +CONFIG_R8723AU=m
  2198. +CONFIG_VT6656=m
  2199. +CONFIG_SPEAKUP=m
  2200. +CONFIG_SPEAKUP_SYNTH_SOFT=m
  2201. +CONFIG_STAGING_MEDIA=y
  2202. +CONFIG_LIRC_STAGING=y
  2203. +CONFIG_LIRC_IGORPLUGUSB=m
  2204. +CONFIG_LIRC_IMON=m
  2205. +CONFIG_LIRC_RPI=m
  2206. +CONFIG_LIRC_SASEM=m
  2207. +CONFIG_LIRC_SERIAL=m
  2208. +# CONFIG_IOMMU_SUPPORT is not set
  2209. +CONFIG_EXTCON=m
  2210. +CONFIG_EXTCON_ARIZONA=m
  2211. +CONFIG_EXT4_FS=y
  2212. +CONFIG_EXT4_FS_POSIX_ACL=y
  2213. +CONFIG_EXT4_FS_SECURITY=y
  2214. +CONFIG_REISERFS_FS=m
  2215. +CONFIG_REISERFS_FS_XATTR=y
  2216. +CONFIG_REISERFS_FS_POSIX_ACL=y
  2217. +CONFIG_REISERFS_FS_SECURITY=y
  2218. +CONFIG_JFS_FS=m
  2219. +CONFIG_JFS_POSIX_ACL=y
  2220. +CONFIG_JFS_SECURITY=y
  2221. +CONFIG_JFS_STATISTICS=y
  2222. +CONFIG_XFS_FS=m
  2223. +CONFIG_XFS_QUOTA=y
  2224. +CONFIG_XFS_POSIX_ACL=y
  2225. +CONFIG_XFS_RT=y
  2226. +CONFIG_GFS2_FS=m
  2227. +CONFIG_OCFS2_FS=m
  2228. +CONFIG_BTRFS_FS=m
  2229. +CONFIG_BTRFS_FS_POSIX_ACL=y
  2230. +CONFIG_NILFS2_FS=m
  2231. +CONFIG_FANOTIFY=y
  2232. +CONFIG_QFMT_V1=m
  2233. +CONFIG_QFMT_V2=m
  2234. +CONFIG_AUTOFS4_FS=y
  2235. +CONFIG_FUSE_FS=m
  2236. +CONFIG_CUSE=m
  2237. +CONFIG_FSCACHE=y
  2238. +CONFIG_FSCACHE_STATS=y
  2239. +CONFIG_FSCACHE_HISTOGRAM=y
  2240. +CONFIG_CACHEFILES=y
  2241. +CONFIG_ISO9660_FS=m
  2242. +CONFIG_JOLIET=y
  2243. +CONFIG_ZISOFS=y
  2244. +CONFIG_UDF_FS=m
  2245. +CONFIG_MSDOS_FS=y
  2246. +CONFIG_VFAT_FS=y
  2247. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2248. +CONFIG_NTFS_FS=m
  2249. +CONFIG_NTFS_RW=y
  2250. +CONFIG_TMPFS=y
  2251. +CONFIG_TMPFS_POSIX_ACL=y
  2252. +CONFIG_CONFIGFS_FS=y
  2253. +CONFIG_ECRYPT_FS=m
  2254. +CONFIG_HFS_FS=m
  2255. +CONFIG_HFSPLUS_FS=m
  2256. +CONFIG_SQUASHFS=m
  2257. +CONFIG_SQUASHFS_XATTR=y
  2258. +CONFIG_SQUASHFS_LZO=y
  2259. +CONFIG_SQUASHFS_XZ=y
  2260. +CONFIG_F2FS_FS=y
  2261. +CONFIG_NFS_FS=y
  2262. +CONFIG_NFS_V3_ACL=y
  2263. +CONFIG_NFS_V4=y
  2264. +CONFIG_NFS_SWAP=y
  2265. +CONFIG_ROOT_NFS=y
  2266. +CONFIG_NFS_FSCACHE=y
  2267. +CONFIG_NFSD=m
  2268. +CONFIG_NFSD_V3_ACL=y
  2269. +CONFIG_NFSD_V4=y
  2270. +CONFIG_CIFS=m
  2271. +CONFIG_CIFS_WEAK_PW_HASH=y
  2272. +CONFIG_CIFS_XATTR=y
  2273. +CONFIG_CIFS_POSIX=y
  2274. +CONFIG_9P_FS=m
  2275. +CONFIG_9P_FS_POSIX_ACL=y
  2276. +CONFIG_NLS_DEFAULT="utf8"
  2277. +CONFIG_NLS_CODEPAGE_437=y
  2278. +CONFIG_NLS_CODEPAGE_737=m
  2279. +CONFIG_NLS_CODEPAGE_775=m
  2280. +CONFIG_NLS_CODEPAGE_850=m
  2281. +CONFIG_NLS_CODEPAGE_852=m
  2282. +CONFIG_NLS_CODEPAGE_855=m
  2283. +CONFIG_NLS_CODEPAGE_857=m
  2284. +CONFIG_NLS_CODEPAGE_860=m
  2285. +CONFIG_NLS_CODEPAGE_861=m
  2286. +CONFIG_NLS_CODEPAGE_862=m
  2287. +CONFIG_NLS_CODEPAGE_863=m
  2288. +CONFIG_NLS_CODEPAGE_864=m
  2289. +CONFIG_NLS_CODEPAGE_865=m
  2290. +CONFIG_NLS_CODEPAGE_866=m
  2291. +CONFIG_NLS_CODEPAGE_869=m
  2292. +CONFIG_NLS_CODEPAGE_936=m
  2293. +CONFIG_NLS_CODEPAGE_950=m
  2294. +CONFIG_NLS_CODEPAGE_932=m
  2295. +CONFIG_NLS_CODEPAGE_949=m
  2296. +CONFIG_NLS_CODEPAGE_874=m
  2297. +CONFIG_NLS_ISO8859_8=m
  2298. +CONFIG_NLS_CODEPAGE_1250=m
  2299. +CONFIG_NLS_CODEPAGE_1251=m
  2300. +CONFIG_NLS_ASCII=y
  2301. +CONFIG_NLS_ISO8859_1=m
  2302. +CONFIG_NLS_ISO8859_2=m
  2303. +CONFIG_NLS_ISO8859_3=m
  2304. +CONFIG_NLS_ISO8859_4=m
  2305. +CONFIG_NLS_ISO8859_5=m
  2306. +CONFIG_NLS_ISO8859_6=m
  2307. +CONFIG_NLS_ISO8859_7=m
  2308. +CONFIG_NLS_ISO8859_9=m
  2309. +CONFIG_NLS_ISO8859_13=m
  2310. +CONFIG_NLS_ISO8859_14=m
  2311. +CONFIG_NLS_ISO8859_15=m
  2312. +CONFIG_NLS_KOI8_R=m
  2313. +CONFIG_NLS_KOI8_U=m
  2314. +CONFIG_DLM=m
  2315. +CONFIG_PRINTK_TIME=y
  2316. +CONFIG_BOOT_PRINTK_DELAY=y
  2317. +CONFIG_DEBUG_MEMORY_INIT=y
  2318. +CONFIG_DETECT_HUNG_TASK=y
  2319. +CONFIG_TIMER_STATS=y
  2320. +# CONFIG_DEBUG_PREEMPT is not set
  2321. +CONFIG_IRQSOFF_TRACER=y
  2322. +CONFIG_SCHED_TRACER=y
  2323. +CONFIG_STACK_TRACER=y
  2324. +CONFIG_BLK_DEV_IO_TRACE=y
  2325. +# CONFIG_KPROBE_EVENT is not set
  2326. +CONFIG_FUNCTION_PROFILER=y
  2327. +CONFIG_KGDB=y
  2328. +CONFIG_KGDB_KDB=y
  2329. +CONFIG_KDB_KEYBOARD=y
  2330. +CONFIG_CRYPTO_USER=m
  2331. +CONFIG_CRYPTO_NULL=m
  2332. +CONFIG_CRYPTO_CBC=y
  2333. +CONFIG_CRYPTO_CTS=m
  2334. +CONFIG_CRYPTO_XTS=m
  2335. +CONFIG_CRYPTO_XCBC=m
  2336. +CONFIG_CRYPTO_SHA1_ARM_NEON=m
  2337. +CONFIG_CRYPTO_SHA512_ARM_NEON=m
  2338. +CONFIG_CRYPTO_TGR192=m
  2339. +CONFIG_CRYPTO_WP512=m
  2340. +CONFIG_CRYPTO_AES_ARM_BS=m
  2341. +CONFIG_CRYPTO_CAST5=m
  2342. +CONFIG_CRYPTO_DES=y
  2343. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2344. +# CONFIG_CRYPTO_HW is not set
  2345. +CONFIG_CRC_ITU_T=y
  2346. +CONFIG_LIBCRC32C=y
  2347. diff -Nur linux-3.18.6/arch/arm/configs/bcm2709_sdcard_defconfig linux-rpi/arch/arm/configs/bcm2709_sdcard_defconfig
  2348. --- linux-3.18.6/arch/arm/configs/bcm2709_sdcard_defconfig 1970-01-01 01:00:00.000000000 +0100
  2349. +++ linux-rpi/arch/arm/configs/bcm2709_sdcard_defconfig 2015-02-09 04:39:42.000000000 +0100
  2350. @@ -0,0 +1,129 @@
  2351. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  2352. +CONFIG_PHYS_OFFSET=0x0
  2353. +CONFIG_LOCALVERSION="-sdcard"
  2354. +# CONFIG_LOCALVERSION_AUTO is not set
  2355. +# CONFIG_SWAP is not set
  2356. +CONFIG_SYSVIPC=y
  2357. +CONFIG_POSIX_MQUEUE=y
  2358. +CONFIG_FHANDLE=y
  2359. +CONFIG_AUDIT=y
  2360. +CONFIG_NO_HZ=y
  2361. +CONFIG_HIGH_RES_TIMERS=y
  2362. +CONFIG_BSD_PROCESS_ACCT=y
  2363. +CONFIG_BSD_PROCESS_ACCT_V3=y
  2364. +CONFIG_TASKSTATS=y
  2365. +CONFIG_TASK_DELAY_ACCT=y
  2366. +CONFIG_TASK_XACCT=y
  2367. +CONFIG_TASK_IO_ACCOUNTING=y
  2368. +CONFIG_IKCONFIG=y
  2369. +CONFIG_IKCONFIG_PROC=y
  2370. +CONFIG_CGROUP_FREEZER=y
  2371. +CONFIG_CGROUP_DEVICE=y
  2372. +CONFIG_CGROUP_CPUACCT=y
  2373. +CONFIG_RESOURCE_COUNTERS=y
  2374. +CONFIG_MEMCG=y
  2375. +CONFIG_BLK_CGROUP=y
  2376. +CONFIG_NAMESPACES=y
  2377. +CONFIG_SCHED_AUTOGROUP=y
  2378. +CONFIG_RELAY=y
  2379. +CONFIG_BLK_DEV_INITRD=y
  2380. +CONFIG_EMBEDDED=y
  2381. +# CONFIG_PERF_EVENTS is not set
  2382. +# CONFIG_COMPAT_BRK is not set
  2383. +CONFIG_PROFILING=y
  2384. +CONFIG_JUMP_LABEL=y
  2385. +CONFIG_BLK_DEV_BSGLIB=y
  2386. +CONFIG_BLK_DEV_THROTTLING=y
  2387. +CONFIG_CFQ_GROUP_IOSCHED=y
  2388. +CONFIG_ARCH_BCM2709=y
  2389. +# CONFIG_CACHE_L2X0 is not set
  2390. +CONFIG_SMP=y
  2391. +CONFIG_HAVE_ARM_ARCH_TIMER=y
  2392. +CONFIG_HOTPLUG_CPU=y
  2393. +CONFIG_PREEMPT=y
  2394. +CONFIG_AEABI=y
  2395. +CONFIG_CMA=y
  2396. +CONFIG_UACCESS_WITH_MEMCPY=y
  2397. +CONFIG_SECCOMP=y
  2398. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2399. +CONFIG_ZBOOT_ROM_BSS=0x0
  2400. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  2401. +CONFIG_CPU_IDLE=y
  2402. +CONFIG_VFP=y
  2403. +# CONFIG_COREDUMP is not set
  2404. +# CONFIG_SUSPEND is not set
  2405. +CONFIG_NET=y
  2406. +CONFIG_UNIX=y
  2407. +CONFIG_CGROUP_NET_CLASSID=y
  2408. +# CONFIG_WIRELESS is not set
  2409. +CONFIG_DEVTMPFS=y
  2410. +CONFIG_DEVTMPFS_MOUNT=y
  2411. +CONFIG_DMA_CMA=y
  2412. +CONFIG_CMA_SIZE_MBYTES=8
  2413. +CONFIG_BLK_DEV_LOOP=y
  2414. +CONFIG_BLK_DEV_RAM=y
  2415. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  2416. +# CONFIG_INPUT_KEYBOARD is not set
  2417. +# CONFIG_INPUT_MOUSE is not set
  2418. +# CONFIG_SERIO is not set
  2419. +# CONFIG_LEGACY_PTYS is not set
  2420. +# CONFIG_DEVKMEM is not set
  2421. +CONFIG_SERIAL_AMBA_PL011=y
  2422. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2423. +CONFIG_TTY_PRINTK=y
  2424. +# CONFIG_HW_RANDOM is not set
  2425. +CONFIG_BRCM_CHAR_DRIVERS=y
  2426. +CONFIG_BCM_VC_CMA=y
  2427. +CONFIG_GPIO_SYSFS=y
  2428. +# CONFIG_HWMON is not set
  2429. +CONFIG_FB=y
  2430. +CONFIG_FB_BCM2708=y
  2431. +CONFIG_FRAMEBUFFER_CONSOLE=y
  2432. +# CONFIG_HID is not set
  2433. +# CONFIG_USB_SUPPORT is not set
  2434. +CONFIG_MMC=y
  2435. +CONFIG_MMC_BLOCK_MINORS=32
  2436. +CONFIG_MMC_SDHCI=y
  2437. +CONFIG_MMC_SDHCI_PLTFM=y
  2438. +CONFIG_MMC_BCM2835=y
  2439. +CONFIG_MMC_BCM2835_DMA=y
  2440. +CONFIG_DMADEVICES=y
  2441. +CONFIG_DMA_BCM2708=y
  2442. +# CONFIG_IOMMU_SUPPORT is not set
  2443. +CONFIG_EXT4_FS=y
  2444. +CONFIG_EXT4_FS_POSIX_ACL=y
  2445. +CONFIG_EXT4_FS_SECURITY=y
  2446. +CONFIG_FANOTIFY=y
  2447. +CONFIG_FSCACHE=y
  2448. +CONFIG_FSCACHE_STATS=y
  2449. +CONFIG_FSCACHE_HISTOGRAM=y
  2450. +CONFIG_CACHEFILES=y
  2451. +CONFIG_MSDOS_FS=y
  2452. +CONFIG_VFAT_FS=y
  2453. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2454. +CONFIG_TMPFS=y
  2455. +CONFIG_TMPFS_POSIX_ACL=y
  2456. +CONFIG_CONFIGFS_FS=y
  2457. +# CONFIG_MISC_FILESYSTEMS is not set
  2458. +# CONFIG_NETWORK_FILESYSTEMS is not set
  2459. +CONFIG_NLS_DEFAULT="utf8"
  2460. +CONFIG_NLS_CODEPAGE_437=y
  2461. +CONFIG_NLS_ASCII=y
  2462. +CONFIG_PRINTK_TIME=y
  2463. +CONFIG_BOOT_PRINTK_DELAY=y
  2464. +CONFIG_DEBUG_FS=y
  2465. +CONFIG_MAGIC_SYSRQ=y
  2466. +CONFIG_DETECT_HUNG_TASK=y
  2467. +CONFIG_TIMER_STATS=y
  2468. +# CONFIG_DEBUG_PREEMPT is not set
  2469. +CONFIG_DEBUG_LL=y
  2470. +CONFIG_EARLY_PRINTK=y
  2471. +CONFIG_KEYS=y
  2472. +CONFIG_CRYPTO_CBC=y
  2473. +CONFIG_CRYPTO_AES=y
  2474. +CONFIG_CRYPTO_DES=y
  2475. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2476. +# CONFIG_CRYPTO_HW is not set
  2477. +CONFIG_CRC_ITU_T=y
  2478. +CONFIG_LIBCRC32C=y
  2479. +CONFIG_AVERAGE=y
  2480. diff -Nur linux-3.18.6/arch/arm/configs/bcm2709_small_defconfig linux-rpi/arch/arm/configs/bcm2709_small_defconfig
  2481. --- linux-3.18.6/arch/arm/configs/bcm2709_small_defconfig 1970-01-01 01:00:00.000000000 +0100
  2482. +++ linux-rpi/arch/arm/configs/bcm2709_small_defconfig 2015-02-09 04:39:42.000000000 +0100
  2483. @@ -0,0 +1,61 @@
  2484. +CONFIG_LOCALVERSION="-small"
  2485. +# CONFIG_LOCALVERSION_AUTO is not set
  2486. +# CONFIG_SWAP is not set
  2487. +CONFIG_SYSVIPC=y
  2488. +CONFIG_HIGH_RES_TIMERS=y
  2489. +CONFIG_LOG_BUF_SHIFT=16
  2490. +CONFIG_BLK_DEV_INITRD=y
  2491. +CONFIG_INITRAMFS_SOURCE="../target_fs"
  2492. +CONFIG_SLAB=y
  2493. +# CONFIG_BLK_DEV_BSG is not set
  2494. +# CONFIG_IOSCHED_CFQ is not set
  2495. +CONFIG_ARCH_BCM2709=y
  2496. +# CONFIG_BCM2708_GPIO is not set
  2497. +# CONFIG_BCM2708_VCMEM is not set
  2498. +CONFIG_ARM_THUMBEE=y
  2499. +# CONFIG_SWP_EMULATE is not set
  2500. +# CONFIG_CACHE_L2X0 is not set
  2501. +CONFIG_ARM_ERRATA_720789=y
  2502. +CONFIG_SMP=y
  2503. +CONFIG_SCHED_MC=y
  2504. +CONFIG_SCHED_SMT=y
  2505. +CONFIG_HOTPLUG_CPU=y
  2506. +CONFIG_PREEMPT=y
  2507. +CONFIG_AEABI=y
  2508. +CONFIG_HIGHMEM=y
  2509. +CONFIG_HIGHPTE=y
  2510. +# CONFIG_COMPACTION is not set
  2511. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2512. +CONFIG_ZBOOT_ROM_BSS=0x0
  2513. +CONFIG_CMDLINE="earlyprintk=ttyAMA0,19200 loglevel=9 console=ttyAMA0,19200"
  2514. +CONFIG_AUTO_ZRELADDR=y
  2515. +CONFIG_BINFMT_MISC=y
  2516. +# CONFIG_SUSPEND is not set
  2517. +# CONFIG_UEVENT_HELPER is not set
  2518. +# CONFIG_FIRMWARE_IN_KERNEL is not set
  2519. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  2520. +# CONFIG_INPUT_KEYBOARD is not set
  2521. +# CONFIG_INPUT_MOUSE is not set
  2522. +# CONFIG_SERIO is not set
  2523. +# CONFIG_LEGACY_PTYS is not set
  2524. +# CONFIG_DEVKMEM is not set
  2525. +CONFIG_SERIAL_AMBA_PL011=y
  2526. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2527. +# CONFIG_HW_RANDOM is not set
  2528. +# CONFIG_HWMON is not set
  2529. +# CONFIG_HID is not set
  2530. +# CONFIG_USB_SUPPORT is not set
  2531. +# CONFIG_IOMMU_SUPPORT is not set
  2532. +CONFIG_AUTOFS4_FS=y
  2533. +# CONFIG_MISC_FILESYSTEMS is not set
  2534. +CONFIG_PRINTK_TIME=y
  2535. +CONFIG_FRAME_WARN=4096
  2536. +CONFIG_MAGIC_SYSRQ=y
  2537. +CONFIG_DEBUG_KERNEL=y
  2538. +CONFIG_RCU_CPU_STALL_TIMEOUT=60
  2539. +# CONFIG_FTRACE is not set
  2540. +# CONFIG_ARM_UNWIND is not set
  2541. +CONFIG_DEBUG_LL=y
  2542. +CONFIG_EARLY_PRINTK=y
  2543. +CONFIG_CRC16=y
  2544. +CONFIG_CRC_ITU_T=y
  2545. diff -Nur linux-3.18.6/arch/arm/configs/bcm2835_sdcard_defconfig linux-rpi/arch/arm/configs/bcm2835_sdcard_defconfig
  2546. --- linux-3.18.6/arch/arm/configs/bcm2835_sdcard_defconfig 1970-01-01 01:00:00.000000000 +0100
  2547. +++ linux-rpi/arch/arm/configs/bcm2835_sdcard_defconfig 2015-02-09 04:39:42.000000000 +0100
  2548. @@ -0,0 +1,176 @@
  2549. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  2550. +CONFIG_LOCALVERSION="-quick"
  2551. +# CONFIG_LOCALVERSION_AUTO is not set
  2552. +# CONFIG_SWAP is not set
  2553. +CONFIG_SYSVIPC=y
  2554. +CONFIG_POSIX_MQUEUE=y
  2555. +CONFIG_NO_HZ=y
  2556. +CONFIG_HIGH_RES_TIMERS=y
  2557. +CONFIG_IKCONFIG=y
  2558. +CONFIG_IKCONFIG_PROC=y
  2559. +CONFIG_KALLSYMS_ALL=y
  2560. +CONFIG_EMBEDDED=y
  2561. +CONFIG_PERF_EVENTS=y
  2562. +# CONFIG_COMPAT_BRK is not set
  2563. +CONFIG_SLAB=y
  2564. +# CONFIG_BLK_DEV_BSG is not set
  2565. +CONFIG_ARCH_BCM2708=y
  2566. +# CONFIG_BCM2708_GPIO is not set
  2567. +CONFIG_PREEMPT=y
  2568. +CONFIG_AEABI=y
  2569. +CONFIG_UACCESS_WITH_MEMCPY=y
  2570. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2571. +CONFIG_ZBOOT_ROM_BSS=0x0
  2572. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  2573. +CONFIG_CPU_FREQ=y
  2574. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  2575. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  2576. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  2577. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  2578. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  2579. +CONFIG_CPU_IDLE=y
  2580. +CONFIG_VFP=y
  2581. +CONFIG_BINFMT_MISC=y
  2582. +CONFIG_NET=y
  2583. +CONFIG_PACKET=y
  2584. +CONFIG_UNIX=y
  2585. +CONFIG_INET=y
  2586. +CONFIG_IP_MULTICAST=y
  2587. +CONFIG_IP_PNP=y
  2588. +CONFIG_IP_PNP_DHCP=y
  2589. +CONFIG_IP_PNP_RARP=y
  2590. +CONFIG_SYN_COOKIES=y
  2591. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  2592. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  2593. +# CONFIG_INET_XFRM_MODE_BEET is not set
  2594. +# CONFIG_INET_LRO is not set
  2595. +# CONFIG_INET_DIAG is not set
  2596. +# CONFIG_IPV6 is not set
  2597. +# CONFIG_WIRELESS is not set
  2598. +CONFIG_DEVTMPFS=y
  2599. +CONFIG_DEVTMPFS_MOUNT=y
  2600. +CONFIG_BLK_DEV_LOOP=y
  2601. +CONFIG_BLK_DEV_RAM=y
  2602. +CONFIG_SCSI=y
  2603. +# CONFIG_SCSI_PROC_FS is not set
  2604. +# CONFIG_SCSI_LOWLEVEL is not set
  2605. +CONFIG_NETDEVICES=y
  2606. +CONFIG_MII=y
  2607. +# CONFIG_NET_VENDOR_BROADCOM is not set
  2608. +# CONFIG_NET_VENDOR_CIRRUS is not set
  2609. +# CONFIG_NET_VENDOR_FARADAY is not set
  2610. +# CONFIG_NET_VENDOR_INTEL is not set
  2611. +# CONFIG_NET_VENDOR_MARVELL is not set
  2612. +# CONFIG_NET_VENDOR_MICREL is not set
  2613. +# CONFIG_NET_VENDOR_NATSEMI is not set
  2614. +# CONFIG_NET_VENDOR_SEEQ is not set
  2615. +# CONFIG_NET_VENDOR_STMICRO is not set
  2616. +# CONFIG_NET_VENDOR_WIZNET is not set
  2617. +CONFIG_PHYLIB=y
  2618. +# CONFIG_WLAN is not set
  2619. +# CONFIG_INPUT_MOUSEDEV is not set
  2620. +CONFIG_INPUT_EVDEV=y
  2621. +# CONFIG_INPUT_KEYBOARD is not set
  2622. +# CONFIG_INPUT_MOUSE is not set
  2623. +# CONFIG_SERIO is not set
  2624. +CONFIG_VT_HW_CONSOLE_BINDING=y
  2625. +# CONFIG_LEGACY_PTYS is not set
  2626. +# CONFIG_DEVKMEM is not set
  2627. +CONFIG_SERIAL_AMBA_PL011=y
  2628. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2629. +CONFIG_TTY_PRINTK=y
  2630. +CONFIG_RAW_DRIVER=y
  2631. +CONFIG_WATCHDOG=y
  2632. +CONFIG_REGULATOR=y
  2633. +CONFIG_REGULATOR_DEBUG=y
  2634. +CONFIG_REGULATOR_FIXED_VOLTAGE=y
  2635. +CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
  2636. +CONFIG_REGULATOR_USERSPACE_CONSUMER=y
  2637. +CONFIG_FB=y
  2638. +CONFIG_FRAMEBUFFER_CONSOLE=y
  2639. +CONFIG_LOGO=y
  2640. +# CONFIG_LOGO_LINUX_MONO is not set
  2641. +# CONFIG_LOGO_LINUX_VGA16 is not set
  2642. +CONFIG_SOUND=y
  2643. +CONFIG_SND=y
  2644. +CONFIG_MMC=y
  2645. +CONFIG_MMC_SDHCI=y
  2646. +CONFIG_MMC_SDHCI_PLTFM=y
  2647. +CONFIG_MMC_SDHCI_BCM2708=y
  2648. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2649. +CONFIG_NEW_LEDS=y
  2650. +CONFIG_LEDS_CLASS=y
  2651. +CONFIG_LEDS_TRIGGERS=y
  2652. +# CONFIG_IOMMU_SUPPORT is not set
  2653. +CONFIG_EXT4_FS=y
  2654. +CONFIG_EXT4_FS_POSIX_ACL=y
  2655. +CONFIG_EXT4_FS_SECURITY=y
  2656. +CONFIG_AUTOFS4_FS=y
  2657. +CONFIG_FSCACHE=y
  2658. +CONFIG_CACHEFILES=y
  2659. +CONFIG_MSDOS_FS=y
  2660. +CONFIG_VFAT_FS=y
  2661. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2662. +CONFIG_TMPFS=y
  2663. +CONFIG_TMPFS_POSIX_ACL=y
  2664. +CONFIG_CONFIGFS_FS=y
  2665. +# CONFIG_MISC_FILESYSTEMS is not set
  2666. +CONFIG_NFS_FS=y
  2667. +CONFIG_NFS_V3_ACL=y
  2668. +CONFIG_NFS_V4=y
  2669. +CONFIG_ROOT_NFS=y
  2670. +CONFIG_NFS_FSCACHE=y
  2671. +CONFIG_NLS_DEFAULT="utf8"
  2672. +CONFIG_NLS_CODEPAGE_437=y
  2673. +CONFIG_NLS_CODEPAGE_737=y
  2674. +CONFIG_NLS_CODEPAGE_775=y
  2675. +CONFIG_NLS_CODEPAGE_850=y
  2676. +CONFIG_NLS_CODEPAGE_852=y
  2677. +CONFIG_NLS_CODEPAGE_855=y
  2678. +CONFIG_NLS_CODEPAGE_857=y
  2679. +CONFIG_NLS_CODEPAGE_860=y
  2680. +CONFIG_NLS_CODEPAGE_861=y
  2681. +CONFIG_NLS_CODEPAGE_862=y
  2682. +CONFIG_NLS_CODEPAGE_863=y
  2683. +CONFIG_NLS_CODEPAGE_864=y
  2684. +CONFIG_NLS_CODEPAGE_865=y
  2685. +CONFIG_NLS_CODEPAGE_866=y
  2686. +CONFIG_NLS_CODEPAGE_869=y
  2687. +CONFIG_NLS_CODEPAGE_936=y
  2688. +CONFIG_NLS_CODEPAGE_950=y
  2689. +CONFIG_NLS_CODEPAGE_932=y
  2690. +CONFIG_NLS_CODEPAGE_949=y
  2691. +CONFIG_NLS_CODEPAGE_874=y
  2692. +CONFIG_NLS_ISO8859_8=y
  2693. +CONFIG_NLS_CODEPAGE_1250=y
  2694. +CONFIG_NLS_CODEPAGE_1251=y
  2695. +CONFIG_NLS_ASCII=y
  2696. +CONFIG_NLS_ISO8859_1=y
  2697. +CONFIG_NLS_ISO8859_2=y
  2698. +CONFIG_NLS_ISO8859_3=y
  2699. +CONFIG_NLS_ISO8859_4=y
  2700. +CONFIG_NLS_ISO8859_5=y
  2701. +CONFIG_NLS_ISO8859_6=y
  2702. +CONFIG_NLS_ISO8859_7=y
  2703. +CONFIG_NLS_ISO8859_9=y
  2704. +CONFIG_NLS_ISO8859_13=y
  2705. +CONFIG_NLS_ISO8859_14=y
  2706. +CONFIG_NLS_ISO8859_15=y
  2707. +CONFIG_NLS_UTF8=y
  2708. +CONFIG_PRINTK_TIME=y
  2709. +CONFIG_DEBUG_FS=y
  2710. +# CONFIG_DEBUG_PREEMPT is not set
  2711. +# CONFIG_DEBUG_BUGVERBOSE is not set
  2712. +# CONFIG_FTRACE is not set
  2713. +CONFIG_KGDB=y
  2714. +CONFIG_KGDB_KDB=y
  2715. +# CONFIG_ARM_UNWIND is not set
  2716. +CONFIG_CRYPTO_CBC=y
  2717. +CONFIG_CRYPTO_HMAC=y
  2718. +CONFIG_CRYPTO_MD5=y
  2719. +CONFIG_CRYPTO_SHA1=y
  2720. +CONFIG_CRYPTO_DES=y
  2721. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2722. +# CONFIG_CRYPTO_HW is not set
  2723. +CONFIG_CRC_ITU_T=y
  2724. +CONFIG_LIBCRC32C=y
  2725. diff -Nur linux-3.18.6/arch/arm/configs/bcmrpi_defconfig linux-rpi/arch/arm/configs/bcmrpi_defconfig
  2726. --- linux-3.18.6/arch/arm/configs/bcmrpi_defconfig 1970-01-01 01:00:00.000000000 +0100
  2727. +++ linux-rpi/arch/arm/configs/bcmrpi_defconfig 2015-02-09 04:39:42.000000000 +0100
  2728. @@ -0,0 +1,1152 @@
  2729. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  2730. +CONFIG_PHYS_OFFSET=0
  2731. +# CONFIG_LOCALVERSION_AUTO is not set
  2732. +CONFIG_SYSVIPC=y
  2733. +CONFIG_POSIX_MQUEUE=y
  2734. +CONFIG_FHANDLE=y
  2735. +CONFIG_AUDIT=y
  2736. +CONFIG_NO_HZ=y
  2737. +CONFIG_HIGH_RES_TIMERS=y
  2738. +CONFIG_BSD_PROCESS_ACCT=y
  2739. +CONFIG_BSD_PROCESS_ACCT_V3=y
  2740. +CONFIG_TASKSTATS=y
  2741. +CONFIG_TASK_DELAY_ACCT=y
  2742. +CONFIG_TASK_XACCT=y
  2743. +CONFIG_TASK_IO_ACCOUNTING=y
  2744. +CONFIG_IKCONFIG=y
  2745. +CONFIG_IKCONFIG_PROC=y
  2746. +CONFIG_CGROUP_FREEZER=y
  2747. +CONFIG_CGROUP_DEVICE=y
  2748. +CONFIG_CGROUP_CPUACCT=y
  2749. +CONFIG_RESOURCE_COUNTERS=y
  2750. +CONFIG_MEMCG=y
  2751. +CONFIG_BLK_CGROUP=y
  2752. +CONFIG_NAMESPACES=y
  2753. +CONFIG_SCHED_AUTOGROUP=y
  2754. +CONFIG_BLK_DEV_INITRD=y
  2755. +CONFIG_EMBEDDED=y
  2756. +# CONFIG_COMPAT_BRK is not set
  2757. +CONFIG_PROFILING=y
  2758. +CONFIG_OPROFILE=m
  2759. +CONFIG_KPROBES=y
  2760. +CONFIG_JUMP_LABEL=y
  2761. +CONFIG_MODULES=y
  2762. +CONFIG_MODULE_UNLOAD=y
  2763. +CONFIG_MODVERSIONS=y
  2764. +CONFIG_MODULE_SRCVERSION_ALL=y
  2765. +CONFIG_BLK_DEV_THROTTLING=y
  2766. +CONFIG_PARTITION_ADVANCED=y
  2767. +CONFIG_MAC_PARTITION=y
  2768. +CONFIG_CFQ_GROUP_IOSCHED=y
  2769. +CONFIG_ARCH_BCM2708=y
  2770. +CONFIG_BCM2708_DT=y
  2771. +CONFIG_PREEMPT=y
  2772. +CONFIG_AEABI=y
  2773. +CONFIG_CLEANCACHE=y
  2774. +CONFIG_FRONTSWAP=y
  2775. +CONFIG_CMA=y
  2776. +CONFIG_UACCESS_WITH_MEMCPY=y
  2777. +CONFIG_SECCOMP=y
  2778. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2779. +CONFIG_ZBOOT_ROM_BSS=0x0
  2780. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  2781. +CONFIG_KEXEC=y
  2782. +CONFIG_CPU_FREQ=y
  2783. +CONFIG_CPU_FREQ_STAT=m
  2784. +CONFIG_CPU_FREQ_STAT_DETAILS=y
  2785. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  2786. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  2787. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  2788. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  2789. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  2790. +CONFIG_CPU_IDLE=y
  2791. +CONFIG_VFP=y
  2792. +CONFIG_BINFMT_MISC=m
  2793. +CONFIG_NET=y
  2794. +CONFIG_PACKET=y
  2795. +CONFIG_UNIX=y
  2796. +CONFIG_XFRM_USER=y
  2797. +CONFIG_NET_KEY=m
  2798. +CONFIG_INET=y
  2799. +CONFIG_IP_MULTICAST=y
  2800. +CONFIG_IP_ADVANCED_ROUTER=y
  2801. +CONFIG_IP_MULTIPLE_TABLES=y
  2802. +CONFIG_IP_ROUTE_MULTIPATH=y
  2803. +CONFIG_IP_ROUTE_VERBOSE=y
  2804. +CONFIG_IP_PNP=y
  2805. +CONFIG_IP_PNP_DHCP=y
  2806. +CONFIG_IP_PNP_RARP=y
  2807. +CONFIG_NET_IPIP=m
  2808. +CONFIG_NET_IPGRE_DEMUX=m
  2809. +CONFIG_NET_IPGRE=m
  2810. +CONFIG_IP_MROUTE=y
  2811. +CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
  2812. +CONFIG_IP_PIMSM_V1=y
  2813. +CONFIG_IP_PIMSM_V2=y
  2814. +CONFIG_SYN_COOKIES=y
  2815. +CONFIG_INET_AH=m
  2816. +CONFIG_INET_ESP=m
  2817. +CONFIG_INET_IPCOMP=m
  2818. +CONFIG_INET_XFRM_MODE_TRANSPORT=m
  2819. +CONFIG_INET_XFRM_MODE_TUNNEL=m
  2820. +CONFIG_INET_XFRM_MODE_BEET=m
  2821. +CONFIG_INET_LRO=m
  2822. +CONFIG_INET_DIAG=m
  2823. +CONFIG_INET6_AH=m
  2824. +CONFIG_INET6_ESP=m
  2825. +CONFIG_INET6_IPCOMP=m
  2826. +CONFIG_IPV6_TUNNEL=m
  2827. +CONFIG_IPV6_MULTIPLE_TABLES=y
  2828. +CONFIG_IPV6_MROUTE=y
  2829. +CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
  2830. +CONFIG_IPV6_PIMSM_V2=y
  2831. +CONFIG_NETFILTER=y
  2832. +CONFIG_NF_CONNTRACK=m
  2833. +CONFIG_NF_CONNTRACK_ZONES=y
  2834. +CONFIG_NF_CONNTRACK_EVENTS=y
  2835. +CONFIG_NF_CONNTRACK_TIMESTAMP=y
  2836. +CONFIG_NF_CT_PROTO_DCCP=m
  2837. +CONFIG_NF_CT_PROTO_UDPLITE=m
  2838. +CONFIG_NF_CONNTRACK_AMANDA=m
  2839. +CONFIG_NF_CONNTRACK_FTP=m
  2840. +CONFIG_NF_CONNTRACK_H323=m
  2841. +CONFIG_NF_CONNTRACK_IRC=m
  2842. +CONFIG_NF_CONNTRACK_NETBIOS_NS=m
  2843. +CONFIG_NF_CONNTRACK_SNMP=m
  2844. +CONFIG_NF_CONNTRACK_PPTP=m
  2845. +CONFIG_NF_CONNTRACK_SANE=m
  2846. +CONFIG_NF_CONNTRACK_SIP=m
  2847. +CONFIG_NF_CONNTRACK_TFTP=m
  2848. +CONFIG_NF_CT_NETLINK=m
  2849. +CONFIG_NETFILTER_XT_SET=m
  2850. +CONFIG_NETFILTER_XT_TARGET_AUDIT=m
  2851. +CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
  2852. +CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
  2853. +CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
  2854. +CONFIG_NETFILTER_XT_TARGET_DSCP=m
  2855. +CONFIG_NETFILTER_XT_TARGET_HMARK=m
  2856. +CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m
  2857. +CONFIG_NETFILTER_XT_TARGET_LED=m
  2858. +CONFIG_NETFILTER_XT_TARGET_LOG=m
  2859. +CONFIG_NETFILTER_XT_TARGET_MARK=m
  2860. +CONFIG_NETFILTER_XT_TARGET_NFLOG=m
  2861. +CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
  2862. +CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
  2863. +CONFIG_NETFILTER_XT_TARGET_TEE=m
  2864. +CONFIG_NETFILTER_XT_TARGET_TPROXY=m
  2865. +CONFIG_NETFILTER_XT_TARGET_TRACE=m
  2866. +CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
  2867. +CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
  2868. +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
  2869. +CONFIG_NETFILTER_XT_MATCH_BPF=m
  2870. +CONFIG_NETFILTER_XT_MATCH_CLUSTER=m
  2871. +CONFIG_NETFILTER_XT_MATCH_COMMENT=m
  2872. +CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
  2873. +CONFIG_NETFILTER_XT_MATCH_CONNLABEL=m
  2874. +CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
  2875. +CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
  2876. +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
  2877. +CONFIG_NETFILTER_XT_MATCH_CPU=m
  2878. +CONFIG_NETFILTER_XT_MATCH_DCCP=m
  2879. +CONFIG_NETFILTER_XT_MATCH_DEVGROUP=m
  2880. +CONFIG_NETFILTER_XT_MATCH_DSCP=m
  2881. +CONFIG_NETFILTER_XT_MATCH_ESP=m
  2882. +CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
  2883. +CONFIG_NETFILTER_XT_MATCH_HELPER=m
  2884. +CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
  2885. +CONFIG_NETFILTER_XT_MATCH_IPVS=m
  2886. +CONFIG_NETFILTER_XT_MATCH_LENGTH=m
  2887. +CONFIG_NETFILTER_XT_MATCH_LIMIT=m
  2888. +CONFIG_NETFILTER_XT_MATCH_MAC=m
  2889. +CONFIG_NETFILTER_XT_MATCH_MARK=m
  2890. +CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
  2891. +CONFIG_NETFILTER_XT_MATCH_NFACCT=m
  2892. +CONFIG_NETFILTER_XT_MATCH_OSF=m
  2893. +CONFIG_NETFILTER_XT_MATCH_OWNER=m
  2894. +CONFIG_NETFILTER_XT_MATCH_POLICY=m
  2895. +CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
  2896. +CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
  2897. +CONFIG_NETFILTER_XT_MATCH_QUOTA=m
  2898. +CONFIG_NETFILTER_XT_MATCH_RATEEST=m
  2899. +CONFIG_NETFILTER_XT_MATCH_REALM=m
  2900. +CONFIG_NETFILTER_XT_MATCH_RECENT=m
  2901. +CONFIG_NETFILTER_XT_MATCH_SOCKET=m
  2902. +CONFIG_NETFILTER_XT_MATCH_STATE=m
  2903. +CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
  2904. +CONFIG_NETFILTER_XT_MATCH_STRING=m
  2905. +CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
  2906. +CONFIG_NETFILTER_XT_MATCH_TIME=m
  2907. +CONFIG_NETFILTER_XT_MATCH_U32=m
  2908. +CONFIG_IP_SET=m
  2909. +CONFIG_IP_SET_BITMAP_IP=m
  2910. +CONFIG_IP_SET_BITMAP_IPMAC=m
  2911. +CONFIG_IP_SET_BITMAP_PORT=m
  2912. +CONFIG_IP_SET_HASH_IP=m
  2913. +CONFIG_IP_SET_HASH_IPPORT=m
  2914. +CONFIG_IP_SET_HASH_IPPORTIP=m
  2915. +CONFIG_IP_SET_HASH_IPPORTNET=m
  2916. +CONFIG_IP_SET_HASH_NET=m
  2917. +CONFIG_IP_SET_HASH_NETPORT=m
  2918. +CONFIG_IP_SET_HASH_NETIFACE=m
  2919. +CONFIG_IP_SET_LIST_SET=m
  2920. +CONFIG_IP_VS=m
  2921. +CONFIG_IP_VS_PROTO_TCP=y
  2922. +CONFIG_IP_VS_PROTO_UDP=y
  2923. +CONFIG_IP_VS_PROTO_ESP=y
  2924. +CONFIG_IP_VS_PROTO_AH=y
  2925. +CONFIG_IP_VS_PROTO_SCTP=y
  2926. +CONFIG_IP_VS_RR=m
  2927. +CONFIG_IP_VS_WRR=m
  2928. +CONFIG_IP_VS_LC=m
  2929. +CONFIG_IP_VS_WLC=m
  2930. +CONFIG_IP_VS_LBLC=m
  2931. +CONFIG_IP_VS_LBLCR=m
  2932. +CONFIG_IP_VS_DH=m
  2933. +CONFIG_IP_VS_SH=m
  2934. +CONFIG_IP_VS_SED=m
  2935. +CONFIG_IP_VS_NQ=m
  2936. +CONFIG_IP_VS_FTP=m
  2937. +CONFIG_IP_VS_PE_SIP=m
  2938. +CONFIG_NF_CONNTRACK_IPV4=m
  2939. +CONFIG_IP_NF_IPTABLES=m
  2940. +CONFIG_IP_NF_MATCH_AH=m
  2941. +CONFIG_IP_NF_MATCH_ECN=m
  2942. +CONFIG_IP_NF_MATCH_TTL=m
  2943. +CONFIG_IP_NF_FILTER=m
  2944. +CONFIG_IP_NF_TARGET_REJECT=m
  2945. +CONFIG_IP_NF_NAT=m
  2946. +CONFIG_IP_NF_TARGET_MASQUERADE=m
  2947. +CONFIG_IP_NF_TARGET_NETMAP=m
  2948. +CONFIG_IP_NF_TARGET_REDIRECT=m
  2949. +CONFIG_IP_NF_MANGLE=m
  2950. +CONFIG_IP_NF_TARGET_CLUSTERIP=m
  2951. +CONFIG_IP_NF_TARGET_ECN=m
  2952. +CONFIG_IP_NF_TARGET_TTL=m
  2953. +CONFIG_IP_NF_RAW=m
  2954. +CONFIG_IP_NF_ARPTABLES=m
  2955. +CONFIG_IP_NF_ARPFILTER=m
  2956. +CONFIG_IP_NF_ARP_MANGLE=m
  2957. +CONFIG_NF_CONNTRACK_IPV6=m
  2958. +CONFIG_IP6_NF_IPTABLES=m
  2959. +CONFIG_IP6_NF_MATCH_AH=m
  2960. +CONFIG_IP6_NF_MATCH_EUI64=m
  2961. +CONFIG_IP6_NF_MATCH_FRAG=m
  2962. +CONFIG_IP6_NF_MATCH_OPTS=m
  2963. +CONFIG_IP6_NF_MATCH_HL=m
  2964. +CONFIG_IP6_NF_MATCH_IPV6HEADER=m
  2965. +CONFIG_IP6_NF_MATCH_MH=m
  2966. +CONFIG_IP6_NF_MATCH_RT=m
  2967. +CONFIG_IP6_NF_TARGET_HL=m
  2968. +CONFIG_IP6_NF_FILTER=m
  2969. +CONFIG_IP6_NF_TARGET_REJECT=m
  2970. +CONFIG_IP6_NF_MANGLE=m
  2971. +CONFIG_IP6_NF_RAW=m
  2972. +CONFIG_IP6_NF_NAT=m
  2973. +CONFIG_IP6_NF_TARGET_MASQUERADE=m
  2974. +CONFIG_IP6_NF_TARGET_NPT=m
  2975. +CONFIG_BRIDGE_NF_EBTABLES=m
  2976. +CONFIG_BRIDGE_EBT_BROUTE=m
  2977. +CONFIG_BRIDGE_EBT_T_FILTER=m
  2978. +CONFIG_BRIDGE_EBT_T_NAT=m
  2979. +CONFIG_BRIDGE_EBT_802_3=m
  2980. +CONFIG_BRIDGE_EBT_AMONG=m
  2981. +CONFIG_BRIDGE_EBT_ARP=m
  2982. +CONFIG_BRIDGE_EBT_IP=m
  2983. +CONFIG_BRIDGE_EBT_IP6=m
  2984. +CONFIG_BRIDGE_EBT_LIMIT=m
  2985. +CONFIG_BRIDGE_EBT_MARK=m
  2986. +CONFIG_BRIDGE_EBT_PKTTYPE=m
  2987. +CONFIG_BRIDGE_EBT_STP=m
  2988. +CONFIG_BRIDGE_EBT_VLAN=m
  2989. +CONFIG_BRIDGE_EBT_ARPREPLY=m
  2990. +CONFIG_BRIDGE_EBT_DNAT=m
  2991. +CONFIG_BRIDGE_EBT_MARK_T=m
  2992. +CONFIG_BRIDGE_EBT_REDIRECT=m
  2993. +CONFIG_BRIDGE_EBT_SNAT=m
  2994. +CONFIG_BRIDGE_EBT_LOG=m
  2995. +CONFIG_BRIDGE_EBT_NFLOG=m
  2996. +CONFIG_SCTP_COOKIE_HMAC_SHA1=y
  2997. +CONFIG_ATM=m
  2998. +CONFIG_L2TP=m
  2999. +CONFIG_L2TP_V3=y
  3000. +CONFIG_L2TP_IP=m
  3001. +CONFIG_L2TP_ETH=m
  3002. +CONFIG_BRIDGE=m
  3003. +CONFIG_VLAN_8021Q=m
  3004. +CONFIG_VLAN_8021Q_GVRP=y
  3005. +CONFIG_ATALK=m
  3006. +CONFIG_NET_SCHED=y
  3007. +CONFIG_NET_SCH_CBQ=m
  3008. +CONFIG_NET_SCH_HTB=m
  3009. +CONFIG_NET_SCH_HFSC=m
  3010. +CONFIG_NET_SCH_PRIO=m
  3011. +CONFIG_NET_SCH_MULTIQ=m
  3012. +CONFIG_NET_SCH_RED=m
  3013. +CONFIG_NET_SCH_SFB=m
  3014. +CONFIG_NET_SCH_SFQ=m
  3015. +CONFIG_NET_SCH_TEQL=m
  3016. +CONFIG_NET_SCH_TBF=m
  3017. +CONFIG_NET_SCH_GRED=m
  3018. +CONFIG_NET_SCH_DSMARK=m
  3019. +CONFIG_NET_SCH_NETEM=m
  3020. +CONFIG_NET_SCH_DRR=m
  3021. +CONFIG_NET_SCH_MQPRIO=m
  3022. +CONFIG_NET_SCH_CHOKE=m
  3023. +CONFIG_NET_SCH_QFQ=m
  3024. +CONFIG_NET_SCH_CODEL=m
  3025. +CONFIG_NET_SCH_FQ_CODEL=m
  3026. +CONFIG_NET_SCH_INGRESS=m
  3027. +CONFIG_NET_SCH_PLUG=m
  3028. +CONFIG_NET_CLS_BASIC=m
  3029. +CONFIG_NET_CLS_TCINDEX=m
  3030. +CONFIG_NET_CLS_ROUTE4=m
  3031. +CONFIG_NET_CLS_FW=m
  3032. +CONFIG_NET_CLS_U32=m
  3033. +CONFIG_CLS_U32_MARK=y
  3034. +CONFIG_NET_CLS_RSVP=m
  3035. +CONFIG_NET_CLS_RSVP6=m
  3036. +CONFIG_NET_CLS_FLOW=m
  3037. +CONFIG_NET_CLS_CGROUP=m
  3038. +CONFIG_NET_EMATCH=y
  3039. +CONFIG_NET_EMATCH_CMP=m
  3040. +CONFIG_NET_EMATCH_NBYTE=m
  3041. +CONFIG_NET_EMATCH_U32=m
  3042. +CONFIG_NET_EMATCH_META=m
  3043. +CONFIG_NET_EMATCH_TEXT=m
  3044. +CONFIG_NET_EMATCH_IPSET=m
  3045. +CONFIG_NET_CLS_ACT=y
  3046. +CONFIG_NET_ACT_POLICE=m
  3047. +CONFIG_NET_ACT_GACT=m
  3048. +CONFIG_GACT_PROB=y
  3049. +CONFIG_NET_ACT_MIRRED=m
  3050. +CONFIG_NET_ACT_IPT=m
  3051. +CONFIG_NET_ACT_NAT=m
  3052. +CONFIG_NET_ACT_PEDIT=m
  3053. +CONFIG_NET_ACT_SIMP=m
  3054. +CONFIG_NET_ACT_SKBEDIT=m
  3055. +CONFIG_NET_ACT_CSUM=m
  3056. +CONFIG_BATMAN_ADV=m
  3057. +CONFIG_OPENVSWITCH=m
  3058. +CONFIG_NET_PKTGEN=m
  3059. +CONFIG_HAMRADIO=y
  3060. +CONFIG_AX25=m
  3061. +CONFIG_NETROM=m
  3062. +CONFIG_ROSE=m
  3063. +CONFIG_MKISS=m
  3064. +CONFIG_6PACK=m
  3065. +CONFIG_BPQETHER=m
  3066. +CONFIG_BAYCOM_SER_FDX=m
  3067. +CONFIG_BAYCOM_SER_HDX=m
  3068. +CONFIG_YAM=m
  3069. +CONFIG_IRDA=m
  3070. +CONFIG_IRLAN=m
  3071. +CONFIG_IRNET=m
  3072. +CONFIG_IRCOMM=m
  3073. +CONFIG_IRDA_ULTRA=y
  3074. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  3075. +CONFIG_IRDA_FAST_RR=y
  3076. +CONFIG_IRTTY_SIR=m
  3077. +CONFIG_KINGSUN_DONGLE=m
  3078. +CONFIG_KSDAZZLE_DONGLE=m
  3079. +CONFIG_KS959_DONGLE=m
  3080. +CONFIG_USB_IRDA=m
  3081. +CONFIG_SIGMATEL_FIR=m
  3082. +CONFIG_MCS_FIR=m
  3083. +CONFIG_BT=m
  3084. +CONFIG_BT_RFCOMM=m
  3085. +CONFIG_BT_RFCOMM_TTY=y
  3086. +CONFIG_BT_BNEP=m
  3087. +CONFIG_BT_BNEP_MC_FILTER=y
  3088. +CONFIG_BT_BNEP_PROTO_FILTER=y
  3089. +CONFIG_BT_HIDP=m
  3090. +CONFIG_BT_HCIBTUSB=m
  3091. +CONFIG_BT_HCIBCM203X=m
  3092. +CONFIG_BT_HCIBPA10X=m
  3093. +CONFIG_BT_HCIBFUSB=m
  3094. +CONFIG_BT_HCIVHCI=m
  3095. +CONFIG_BT_MRVL=m
  3096. +CONFIG_BT_MRVL_SDIO=m
  3097. +CONFIG_BT_ATH3K=m
  3098. +CONFIG_BT_WILINK=m
  3099. +CONFIG_CFG80211_WEXT=y
  3100. +CONFIG_MAC80211=m
  3101. +CONFIG_MAC80211_MESH=y
  3102. +CONFIG_WIMAX=m
  3103. +CONFIG_RFKILL=m
  3104. +CONFIG_RFKILL_INPUT=y
  3105. +CONFIG_NET_9P=m
  3106. +CONFIG_NFC=m
  3107. +CONFIG_NFC_PN533=m
  3108. +CONFIG_DEVTMPFS=y
  3109. +CONFIG_DEVTMPFS_MOUNT=y
  3110. +CONFIG_DMA_CMA=y
  3111. +CONFIG_CMA_SIZE_MBYTES=5
  3112. +CONFIG_BLK_DEV_LOOP=y
  3113. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  3114. +CONFIG_BLK_DEV_DRBD=m
  3115. +CONFIG_BLK_DEV_NBD=m
  3116. +CONFIG_BLK_DEV_RAM=y
  3117. +CONFIG_CDROM_PKTCDVD=m
  3118. +CONFIG_EEPROM_AT24=m
  3119. +CONFIG_SCSI=y
  3120. +# CONFIG_SCSI_PROC_FS is not set
  3121. +CONFIG_BLK_DEV_SD=y
  3122. +CONFIG_CHR_DEV_ST=m
  3123. +CONFIG_CHR_DEV_OSST=m
  3124. +CONFIG_BLK_DEV_SR=m
  3125. +CONFIG_CHR_DEV_SG=m
  3126. +CONFIG_SCSI_ISCSI_ATTRS=y
  3127. +CONFIG_ISCSI_TCP=m
  3128. +CONFIG_ISCSI_BOOT_SYSFS=m
  3129. +CONFIG_MD=y
  3130. +CONFIG_MD_LINEAR=m
  3131. +CONFIG_MD_RAID0=m
  3132. +CONFIG_BLK_DEV_DM=m
  3133. +CONFIG_DM_CRYPT=m
  3134. +CONFIG_DM_SNAPSHOT=m
  3135. +CONFIG_DM_MIRROR=m
  3136. +CONFIG_DM_LOG_USERSPACE=m
  3137. +CONFIG_DM_RAID=m
  3138. +CONFIG_DM_ZERO=m
  3139. +CONFIG_DM_DELAY=m
  3140. +CONFIG_NETDEVICES=y
  3141. +CONFIG_BONDING=m
  3142. +CONFIG_DUMMY=m
  3143. +CONFIG_IFB=m
  3144. +CONFIG_MACVLAN=m
  3145. +CONFIG_NETCONSOLE=m
  3146. +CONFIG_TUN=m
  3147. +CONFIG_VETH=m
  3148. +CONFIG_ENC28J60=m
  3149. +CONFIG_MDIO_BITBANG=m
  3150. +CONFIG_PPP=m
  3151. +CONFIG_PPP_BSDCOMP=m
  3152. +CONFIG_PPP_DEFLATE=m
  3153. +CONFIG_PPP_FILTER=y
  3154. +CONFIG_PPP_MPPE=m
  3155. +CONFIG_PPP_MULTILINK=y
  3156. +CONFIG_PPPOATM=m
  3157. +CONFIG_PPPOE=m
  3158. +CONFIG_PPPOL2TP=m
  3159. +CONFIG_PPP_ASYNC=m
  3160. +CONFIG_PPP_SYNC_TTY=m
  3161. +CONFIG_SLIP=m
  3162. +CONFIG_SLIP_COMPRESSED=y
  3163. +CONFIG_SLIP_SMART=y
  3164. +CONFIG_USB_CATC=m
  3165. +CONFIG_USB_KAWETH=m
  3166. +CONFIG_USB_PEGASUS=m
  3167. +CONFIG_USB_RTL8150=m
  3168. +CONFIG_USB_RTL8152=m
  3169. +CONFIG_USB_USBNET=y
  3170. +CONFIG_USB_NET_AX8817X=m
  3171. +CONFIG_USB_NET_AX88179_178A=m
  3172. +CONFIG_USB_NET_CDCETHER=m
  3173. +CONFIG_USB_NET_CDC_EEM=m
  3174. +CONFIG_USB_NET_CDC_NCM=m
  3175. +CONFIG_USB_NET_HUAWEI_CDC_NCM=m
  3176. +CONFIG_USB_NET_CDC_MBIM=m
  3177. +CONFIG_USB_NET_DM9601=m
  3178. +CONFIG_USB_NET_SR9700=m
  3179. +CONFIG_USB_NET_SR9800=m
  3180. +CONFIG_USB_NET_SMSC75XX=m
  3181. +CONFIG_USB_NET_SMSC95XX=y
  3182. +CONFIG_USB_NET_GL620A=m
  3183. +CONFIG_USB_NET_NET1080=m
  3184. +CONFIG_USB_NET_PLUSB=m
  3185. +CONFIG_USB_NET_MCS7830=m
  3186. +CONFIG_USB_NET_CDC_SUBSET=m
  3187. +CONFIG_USB_ALI_M5632=y
  3188. +CONFIG_USB_AN2720=y
  3189. +CONFIG_USB_EPSON2888=y
  3190. +CONFIG_USB_KC2190=y
  3191. +CONFIG_USB_NET_ZAURUS=m
  3192. +CONFIG_USB_NET_CX82310_ETH=m
  3193. +CONFIG_USB_NET_KALMIA=m
  3194. +CONFIG_USB_NET_QMI_WWAN=m
  3195. +CONFIG_USB_HSO=m
  3196. +CONFIG_USB_NET_INT51X1=m
  3197. +CONFIG_USB_IPHETH=m
  3198. +CONFIG_USB_SIERRA_NET=m
  3199. +CONFIG_USB_VL600=m
  3200. +CONFIG_LIBERTAS_THINFIRM=m
  3201. +CONFIG_LIBERTAS_THINFIRM_USB=m
  3202. +CONFIG_AT76C50X_USB=m
  3203. +CONFIG_USB_ZD1201=m
  3204. +CONFIG_USB_NET_RNDIS_WLAN=m
  3205. +CONFIG_RTL8187=m
  3206. +CONFIG_MAC80211_HWSIM=m
  3207. +CONFIG_ATH_CARDS=m
  3208. +CONFIG_ATH9K=m
  3209. +CONFIG_ATH9K_HTC=m
  3210. +CONFIG_CARL9170=m
  3211. +CONFIG_ATH6KL=m
  3212. +CONFIG_ATH6KL_USB=m
  3213. +CONFIG_AR5523=m
  3214. +CONFIG_B43=m
  3215. +# CONFIG_B43_PHY_N is not set
  3216. +CONFIG_B43LEGACY=m
  3217. +CONFIG_BRCMFMAC=m
  3218. +CONFIG_BRCMFMAC_USB=y
  3219. +CONFIG_HOSTAP=m
  3220. +CONFIG_LIBERTAS=m
  3221. +CONFIG_LIBERTAS_USB=m
  3222. +CONFIG_LIBERTAS_SDIO=m
  3223. +CONFIG_P54_COMMON=m
  3224. +CONFIG_P54_USB=m
  3225. +CONFIG_RT2X00=m
  3226. +CONFIG_RT2500USB=m
  3227. +CONFIG_RT73USB=m
  3228. +CONFIG_RT2800USB=m
  3229. +CONFIG_RT2800USB_RT3573=y
  3230. +CONFIG_RT2800USB_RT53XX=y
  3231. +CONFIG_RT2800USB_RT55XX=y
  3232. +CONFIG_RT2800USB_UNKNOWN=y
  3233. +CONFIG_RTL8192CU=m
  3234. +CONFIG_ZD1211RW=m
  3235. +CONFIG_MWIFIEX=m
  3236. +CONFIG_MWIFIEX_SDIO=m
  3237. +CONFIG_WIMAX_I2400M_USB=m
  3238. +CONFIG_INPUT_POLLDEV=m
  3239. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  3240. +CONFIG_INPUT_JOYDEV=m
  3241. +CONFIG_INPUT_EVDEV=m
  3242. +# CONFIG_INPUT_KEYBOARD is not set
  3243. +# CONFIG_INPUT_MOUSE is not set
  3244. +CONFIG_INPUT_JOYSTICK=y
  3245. +CONFIG_JOYSTICK_IFORCE=m
  3246. +CONFIG_JOYSTICK_IFORCE_USB=y
  3247. +CONFIG_JOYSTICK_XPAD=m
  3248. +CONFIG_JOYSTICK_XPAD_FF=y
  3249. +CONFIG_INPUT_TOUCHSCREEN=y
  3250. +CONFIG_TOUCHSCREEN_ADS7846=m
  3251. +CONFIG_INPUT_MISC=y
  3252. +CONFIG_INPUT_AD714X=m
  3253. +CONFIG_INPUT_ATI_REMOTE2=m
  3254. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  3255. +CONFIG_INPUT_POWERMATE=m
  3256. +CONFIG_INPUT_YEALINK=m
  3257. +CONFIG_INPUT_CM109=m
  3258. +CONFIG_INPUT_UINPUT=m
  3259. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  3260. +CONFIG_INPUT_ADXL34X=m
  3261. +CONFIG_INPUT_CMA3000=m
  3262. +CONFIG_SERIO=m
  3263. +CONFIG_SERIO_RAW=m
  3264. +CONFIG_GAMEPORT=m
  3265. +CONFIG_GAMEPORT_NS558=m
  3266. +CONFIG_GAMEPORT_L4=m
  3267. +CONFIG_DEVPTS_MULTIPLE_INSTANCES=y
  3268. +# CONFIG_LEGACY_PTYS is not set
  3269. +# CONFIG_DEVKMEM is not set
  3270. +CONFIG_SERIAL_AMBA_PL011=y
  3271. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  3272. +CONFIG_TTY_PRINTK=y
  3273. +CONFIG_HW_RANDOM=y
  3274. +CONFIG_HW_RANDOM_BCM2708=m
  3275. +CONFIG_RAW_DRIVER=y
  3276. +CONFIG_BRCM_CHAR_DRIVERS=y
  3277. +CONFIG_BCM_VC_CMA=y
  3278. +CONFIG_BCM_VC_SM=y
  3279. +CONFIG_I2C=y
  3280. +CONFIG_I2C_CHARDEV=m
  3281. +CONFIG_I2C_MUX=m
  3282. +CONFIG_I2C_BCM2708=m
  3283. +CONFIG_SPI=y
  3284. +CONFIG_SPI_BCM2708=m
  3285. +CONFIG_SPI_SPIDEV=y
  3286. +CONFIG_PPS=m
  3287. +CONFIG_PPS_CLIENT_LDISC=m
  3288. +CONFIG_PPS_CLIENT_GPIO=m
  3289. +CONFIG_GPIO_SYSFS=y
  3290. +CONFIG_GPIO_ARIZONA=m
  3291. +CONFIG_W1=m
  3292. +CONFIG_W1_MASTER_DS2490=m
  3293. +CONFIG_W1_MASTER_DS2482=m
  3294. +CONFIG_W1_MASTER_DS1WM=m
  3295. +CONFIG_W1_MASTER_GPIO=m
  3296. +CONFIG_W1_SLAVE_THERM=m
  3297. +CONFIG_W1_SLAVE_SMEM=m
  3298. +CONFIG_W1_SLAVE_DS2408=m
  3299. +CONFIG_W1_SLAVE_DS2413=m
  3300. +CONFIG_W1_SLAVE_DS2406=m
  3301. +CONFIG_W1_SLAVE_DS2423=m
  3302. +CONFIG_W1_SLAVE_DS2431=m
  3303. +CONFIG_W1_SLAVE_DS2433=m
  3304. +CONFIG_W1_SLAVE_DS2760=m
  3305. +CONFIG_W1_SLAVE_DS2780=m
  3306. +CONFIG_W1_SLAVE_DS2781=m
  3307. +CONFIG_W1_SLAVE_DS28E04=m
  3308. +CONFIG_W1_SLAVE_BQ27000=m
  3309. +CONFIG_BATTERY_DS2760=m
  3310. +# CONFIG_HWMON is not set
  3311. +CONFIG_THERMAL=y
  3312. +CONFIG_THERMAL_BCM2835=y
  3313. +CONFIG_WATCHDOG=y
  3314. +CONFIG_BCM2708_WDT=m
  3315. +CONFIG_UCB1400_CORE=m
  3316. +CONFIG_MFD_ARIZONA_I2C=m
  3317. +CONFIG_MFD_ARIZONA_SPI=m
  3318. +CONFIG_MFD_WM5102=y
  3319. +CONFIG_MEDIA_SUPPORT=m
  3320. +CONFIG_MEDIA_CAMERA_SUPPORT=y
  3321. +CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  3322. +CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  3323. +CONFIG_MEDIA_RADIO_SUPPORT=y
  3324. +CONFIG_MEDIA_RC_SUPPORT=y
  3325. +CONFIG_MEDIA_CONTROLLER=y
  3326. +CONFIG_LIRC=m
  3327. +CONFIG_RC_DEVICES=y
  3328. +CONFIG_RC_ATI_REMOTE=m
  3329. +CONFIG_IR_IMON=m
  3330. +CONFIG_IR_MCEUSB=m
  3331. +CONFIG_IR_REDRAT3=m
  3332. +CONFIG_IR_STREAMZAP=m
  3333. +CONFIG_IR_IGUANA=m
  3334. +CONFIG_IR_TTUSBIR=m
  3335. +CONFIG_RC_LOOPBACK=m
  3336. +CONFIG_IR_GPIO_CIR=m
  3337. +CONFIG_MEDIA_USB_SUPPORT=y
  3338. +CONFIG_USB_VIDEO_CLASS=m
  3339. +CONFIG_USB_M5602=m
  3340. +CONFIG_USB_STV06XX=m
  3341. +CONFIG_USB_GL860=m
  3342. +CONFIG_USB_GSPCA_BENQ=m
  3343. +CONFIG_USB_GSPCA_CONEX=m
  3344. +CONFIG_USB_GSPCA_CPIA1=m
  3345. +CONFIG_USB_GSPCA_DTCS033=m
  3346. +CONFIG_USB_GSPCA_ETOMS=m
  3347. +CONFIG_USB_GSPCA_FINEPIX=m
  3348. +CONFIG_USB_GSPCA_JEILINJ=m
  3349. +CONFIG_USB_GSPCA_JL2005BCD=m
  3350. +CONFIG_USB_GSPCA_KINECT=m
  3351. +CONFIG_USB_GSPCA_KONICA=m
  3352. +CONFIG_USB_GSPCA_MARS=m
  3353. +CONFIG_USB_GSPCA_MR97310A=m
  3354. +CONFIG_USB_GSPCA_NW80X=m
  3355. +CONFIG_USB_GSPCA_OV519=m
  3356. +CONFIG_USB_GSPCA_OV534=m
  3357. +CONFIG_USB_GSPCA_OV534_9=m
  3358. +CONFIG_USB_GSPCA_PAC207=m
  3359. +CONFIG_USB_GSPCA_PAC7302=m
  3360. +CONFIG_USB_GSPCA_PAC7311=m
  3361. +CONFIG_USB_GSPCA_SE401=m
  3362. +CONFIG_USB_GSPCA_SN9C2028=m
  3363. +CONFIG_USB_GSPCA_SN9C20X=m
  3364. +CONFIG_USB_GSPCA_SONIXB=m
  3365. +CONFIG_USB_GSPCA_SONIXJ=m
  3366. +CONFIG_USB_GSPCA_SPCA500=m
  3367. +CONFIG_USB_GSPCA_SPCA501=m
  3368. +CONFIG_USB_GSPCA_SPCA505=m
  3369. +CONFIG_USB_GSPCA_SPCA506=m
  3370. +CONFIG_USB_GSPCA_SPCA508=m
  3371. +CONFIG_USB_GSPCA_SPCA561=m
  3372. +CONFIG_USB_GSPCA_SPCA1528=m
  3373. +CONFIG_USB_GSPCA_SQ905=m
  3374. +CONFIG_USB_GSPCA_SQ905C=m
  3375. +CONFIG_USB_GSPCA_SQ930X=m
  3376. +CONFIG_USB_GSPCA_STK014=m
  3377. +CONFIG_USB_GSPCA_STK1135=m
  3378. +CONFIG_USB_GSPCA_STV0680=m
  3379. +CONFIG_USB_GSPCA_SUNPLUS=m
  3380. +CONFIG_USB_GSPCA_T613=m
  3381. +CONFIG_USB_GSPCA_TOPRO=m
  3382. +CONFIG_USB_GSPCA_TV8532=m
  3383. +CONFIG_USB_GSPCA_VC032X=m
  3384. +CONFIG_USB_GSPCA_VICAM=m
  3385. +CONFIG_USB_GSPCA_XIRLINK_CIT=m
  3386. +CONFIG_USB_GSPCA_ZC3XX=m
  3387. +CONFIG_USB_PWC=m
  3388. +CONFIG_VIDEO_CPIA2=m
  3389. +CONFIG_USB_ZR364XX=m
  3390. +CONFIG_USB_STKWEBCAM=m
  3391. +CONFIG_USB_S2255=m
  3392. +CONFIG_VIDEO_USBTV=m
  3393. +CONFIG_VIDEO_PVRUSB2=m
  3394. +CONFIG_VIDEO_HDPVR=m
  3395. +CONFIG_VIDEO_TLG2300=m
  3396. +CONFIG_VIDEO_USBVISION=m
  3397. +CONFIG_VIDEO_STK1160_COMMON=m
  3398. +CONFIG_VIDEO_STK1160_AC97=y
  3399. +CONFIG_VIDEO_GO7007=m
  3400. +CONFIG_VIDEO_GO7007_USB=m
  3401. +CONFIG_VIDEO_GO7007_USB_S2250_BOARD=m
  3402. +CONFIG_VIDEO_AU0828=m
  3403. +CONFIG_VIDEO_AU0828_RC=y
  3404. +CONFIG_VIDEO_CX231XX=m
  3405. +CONFIG_VIDEO_CX231XX_ALSA=m
  3406. +CONFIG_VIDEO_CX231XX_DVB=m
  3407. +CONFIG_VIDEO_TM6000=m
  3408. +CONFIG_VIDEO_TM6000_ALSA=m
  3409. +CONFIG_VIDEO_TM6000_DVB=m
  3410. +CONFIG_DVB_USB=m
  3411. +CONFIG_DVB_USB_A800=m
  3412. +CONFIG_DVB_USB_DIBUSB_MB=m
  3413. +CONFIG_DVB_USB_DIBUSB_MB_FAULTY=y
  3414. +CONFIG_DVB_USB_DIBUSB_MC=m
  3415. +CONFIG_DVB_USB_DIB0700=m
  3416. +CONFIG_DVB_USB_UMT_010=m
  3417. +CONFIG_DVB_USB_CXUSB=m
  3418. +CONFIG_DVB_USB_M920X=m
  3419. +CONFIG_DVB_USB_DIGITV=m
  3420. +CONFIG_DVB_USB_VP7045=m
  3421. +CONFIG_DVB_USB_VP702X=m
  3422. +CONFIG_DVB_USB_GP8PSK=m
  3423. +CONFIG_DVB_USB_NOVA_T_USB2=m
  3424. +CONFIG_DVB_USB_TTUSB2=m
  3425. +CONFIG_DVB_USB_DTT200U=m
  3426. +CONFIG_DVB_USB_OPERA1=m
  3427. +CONFIG_DVB_USB_AF9005=m
  3428. +CONFIG_DVB_USB_AF9005_REMOTE=m
  3429. +CONFIG_DVB_USB_PCTV452E=m
  3430. +CONFIG_DVB_USB_DW2102=m
  3431. +CONFIG_DVB_USB_CINERGY_T2=m
  3432. +CONFIG_DVB_USB_DTV5100=m
  3433. +CONFIG_DVB_USB_FRIIO=m
  3434. +CONFIG_DVB_USB_AZ6027=m
  3435. +CONFIG_DVB_USB_TECHNISAT_USB2=m
  3436. +CONFIG_DVB_USB_V2=m
  3437. +CONFIG_DVB_USB_AF9015=m
  3438. +CONFIG_DVB_USB_AF9035=m
  3439. +CONFIG_DVB_USB_ANYSEE=m
  3440. +CONFIG_DVB_USB_AU6610=m
  3441. +CONFIG_DVB_USB_AZ6007=m
  3442. +CONFIG_DVB_USB_CE6230=m
  3443. +CONFIG_DVB_USB_EC168=m
  3444. +CONFIG_DVB_USB_GL861=m
  3445. +CONFIG_DVB_USB_LME2510=m
  3446. +CONFIG_DVB_USB_MXL111SF=m
  3447. +CONFIG_DVB_USB_RTL28XXU=m
  3448. +CONFIG_DVB_USB_DVBSKY=m
  3449. +CONFIG_SMS_USB_DRV=m
  3450. +CONFIG_DVB_B2C2_FLEXCOP_USB=m
  3451. +CONFIG_DVB_AS102=m
  3452. +CONFIG_VIDEO_EM28XX=m
  3453. +CONFIG_VIDEO_EM28XX_V4L2=m
  3454. +CONFIG_VIDEO_EM28XX_ALSA=m
  3455. +CONFIG_VIDEO_EM28XX_DVB=m
  3456. +CONFIG_V4L_PLATFORM_DRIVERS=y
  3457. +CONFIG_VIDEO_BCM2835=y
  3458. +CONFIG_VIDEO_BCM2835_MMAL=m
  3459. +CONFIG_RADIO_SI470X=y
  3460. +CONFIG_USB_SI470X=m
  3461. +CONFIG_I2C_SI470X=m
  3462. +CONFIG_RADIO_SI4713=m
  3463. +CONFIG_I2C_SI4713=m
  3464. +CONFIG_USB_MR800=m
  3465. +CONFIG_USB_DSBR=m
  3466. +CONFIG_RADIO_SHARK=m
  3467. +CONFIG_RADIO_SHARK2=m
  3468. +CONFIG_USB_KEENE=m
  3469. +CONFIG_USB_MA901=m
  3470. +CONFIG_RADIO_TEA5764=m
  3471. +CONFIG_RADIO_SAA7706H=m
  3472. +CONFIG_RADIO_TEF6862=m
  3473. +CONFIG_RADIO_WL1273=m
  3474. +CONFIG_RADIO_WL128X=m
  3475. +# CONFIG_MEDIA_SUBDRV_AUTOSELECT is not set
  3476. +CONFIG_VIDEO_UDA1342=m
  3477. +CONFIG_VIDEO_SONY_BTF_MPX=m
  3478. +CONFIG_VIDEO_TVP5150=m
  3479. +CONFIG_VIDEO_TW2804=m
  3480. +CONFIG_VIDEO_TW9903=m
  3481. +CONFIG_VIDEO_TW9906=m
  3482. +CONFIG_VIDEO_OV7640=m
  3483. +CONFIG_VIDEO_MT9V011=m
  3484. +CONFIG_FB=y
  3485. +CONFIG_FB_BCM2708=y
  3486. +# CONFIG_BACKLIGHT_GENERIC is not set
  3487. +CONFIG_FRAMEBUFFER_CONSOLE=y
  3488. +CONFIG_LOGO=y
  3489. +# CONFIG_LOGO_LINUX_MONO is not set
  3490. +# CONFIG_LOGO_LINUX_VGA16 is not set
  3491. +CONFIG_SOUND=y
  3492. +CONFIG_SND=m
  3493. +CONFIG_SND_SEQUENCER=m
  3494. +CONFIG_SND_SEQ_DUMMY=m
  3495. +CONFIG_SND_MIXER_OSS=m
  3496. +CONFIG_SND_PCM_OSS=m
  3497. +CONFIG_SND_SEQUENCER_OSS=y
  3498. +CONFIG_SND_HRTIMER=m
  3499. +CONFIG_SND_DUMMY=m
  3500. +CONFIG_SND_ALOOP=m
  3501. +CONFIG_SND_VIRMIDI=m
  3502. +CONFIG_SND_MTPAV=m
  3503. +CONFIG_SND_SERIAL_U16550=m
  3504. +CONFIG_SND_MPU401=m
  3505. +CONFIG_SND_BCM2835=m
  3506. +CONFIG_SND_USB_AUDIO=m
  3507. +CONFIG_SND_USB_UA101=m
  3508. +CONFIG_SND_USB_CAIAQ=m
  3509. +CONFIG_SND_USB_CAIAQ_INPUT=y
  3510. +CONFIG_SND_USB_6FIRE=m
  3511. +CONFIG_SND_SOC=m
  3512. +CONFIG_SND_BCM2708_SOC_I2S=m
  3513. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  3514. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
  3515. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  3516. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m
  3517. +CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  3518. +CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  3519. +CONFIG_SND_SIMPLE_CARD=m
  3520. +CONFIG_SOUND_PRIME=m
  3521. +CONFIG_HIDRAW=y
  3522. +CONFIG_HID_A4TECH=m
  3523. +CONFIG_HID_ACRUX=m
  3524. +CONFIG_HID_APPLE=m
  3525. +CONFIG_HID_BELKIN=m
  3526. +CONFIG_HID_CHERRY=m
  3527. +CONFIG_HID_CHICONY=m
  3528. +CONFIG_HID_CYPRESS=m
  3529. +CONFIG_HID_DRAGONRISE=m
  3530. +CONFIG_HID_EMS_FF=m
  3531. +CONFIG_HID_ELECOM=m
  3532. +CONFIG_HID_ELO=m
  3533. +CONFIG_HID_EZKEY=m
  3534. +CONFIG_HID_HOLTEK=m
  3535. +CONFIG_HID_KEYTOUCH=m
  3536. +CONFIG_HID_KYE=m
  3537. +CONFIG_HID_UCLOGIC=m
  3538. +CONFIG_HID_WALTOP=m
  3539. +CONFIG_HID_GYRATION=m
  3540. +CONFIG_HID_TWINHAN=m
  3541. +CONFIG_HID_KENSINGTON=m
  3542. +CONFIG_HID_LCPOWER=m
  3543. +CONFIG_HID_LOGITECH=m
  3544. +CONFIG_HID_MAGICMOUSE=m
  3545. +CONFIG_HID_MICROSOFT=m
  3546. +CONFIG_HID_MONTEREY=m
  3547. +CONFIG_HID_MULTITOUCH=m
  3548. +CONFIG_HID_NTRIG=m
  3549. +CONFIG_HID_ORTEK=m
  3550. +CONFIG_HID_PANTHERLORD=m
  3551. +CONFIG_HID_PETALYNX=m
  3552. +CONFIG_HID_PICOLCD=m
  3553. +CONFIG_HID_ROCCAT=m
  3554. +CONFIG_HID_SAMSUNG=m
  3555. +CONFIG_HID_SONY=m
  3556. +CONFIG_HID_SPEEDLINK=m
  3557. +CONFIG_HID_SUNPLUS=m
  3558. +CONFIG_HID_GREENASIA=m
  3559. +CONFIG_HID_SMARTJOYPLUS=m
  3560. +CONFIG_HID_TOPSEED=m
  3561. +CONFIG_HID_THINGM=m
  3562. +CONFIG_HID_THRUSTMASTER=m
  3563. +CONFIG_HID_WACOM=m
  3564. +CONFIG_HID_WIIMOTE=m
  3565. +CONFIG_HID_XINMO=m
  3566. +CONFIG_HID_ZEROPLUS=m
  3567. +CONFIG_HID_ZYDACRON=m
  3568. +CONFIG_HID_PID=y
  3569. +CONFIG_USB_HIDDEV=y
  3570. +CONFIG_USB=y
  3571. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  3572. +CONFIG_USB_MON=m
  3573. +CONFIG_USB_DWCOTG=y
  3574. +CONFIG_USB_PRINTER=m
  3575. +CONFIG_USB_STORAGE=y
  3576. +CONFIG_USB_STORAGE_REALTEK=m
  3577. +CONFIG_USB_STORAGE_DATAFAB=m
  3578. +CONFIG_USB_STORAGE_FREECOM=m
  3579. +CONFIG_USB_STORAGE_ISD200=m
  3580. +CONFIG_USB_STORAGE_USBAT=m
  3581. +CONFIG_USB_STORAGE_SDDR09=m
  3582. +CONFIG_USB_STORAGE_SDDR55=m
  3583. +CONFIG_USB_STORAGE_JUMPSHOT=m
  3584. +CONFIG_USB_STORAGE_ALAUDA=m
  3585. +CONFIG_USB_STORAGE_ONETOUCH=m
  3586. +CONFIG_USB_STORAGE_KARMA=m
  3587. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  3588. +CONFIG_USB_STORAGE_ENE_UB6250=m
  3589. +CONFIG_USB_UAS=m
  3590. +CONFIG_USB_MDC800=m
  3591. +CONFIG_USB_MICROTEK=m
  3592. +CONFIG_USBIP_CORE=m
  3593. +CONFIG_USBIP_VHCI_HCD=m
  3594. +CONFIG_USBIP_HOST=m
  3595. +CONFIG_USB_SERIAL=m
  3596. +CONFIG_USB_SERIAL_GENERIC=y
  3597. +CONFIG_USB_SERIAL_AIRCABLE=m
  3598. +CONFIG_USB_SERIAL_ARK3116=m
  3599. +CONFIG_USB_SERIAL_BELKIN=m
  3600. +CONFIG_USB_SERIAL_CH341=m
  3601. +CONFIG_USB_SERIAL_WHITEHEAT=m
  3602. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  3603. +CONFIG_USB_SERIAL_CP210X=m
  3604. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  3605. +CONFIG_USB_SERIAL_EMPEG=m
  3606. +CONFIG_USB_SERIAL_FTDI_SIO=m
  3607. +CONFIG_USB_SERIAL_VISOR=m
  3608. +CONFIG_USB_SERIAL_IPAQ=m
  3609. +CONFIG_USB_SERIAL_IR=m
  3610. +CONFIG_USB_SERIAL_EDGEPORT=m
  3611. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  3612. +CONFIG_USB_SERIAL_F81232=m
  3613. +CONFIG_USB_SERIAL_GARMIN=m
  3614. +CONFIG_USB_SERIAL_IPW=m
  3615. +CONFIG_USB_SERIAL_IUU=m
  3616. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  3617. +CONFIG_USB_SERIAL_KEYSPAN=m
  3618. +CONFIG_USB_SERIAL_KLSI=m
  3619. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  3620. +CONFIG_USB_SERIAL_MCT_U232=m
  3621. +CONFIG_USB_SERIAL_METRO=m
  3622. +CONFIG_USB_SERIAL_MOS7720=m
  3623. +CONFIG_USB_SERIAL_MOS7840=m
  3624. +CONFIG_USB_SERIAL_NAVMAN=m
  3625. +CONFIG_USB_SERIAL_PL2303=m
  3626. +CONFIG_USB_SERIAL_OTI6858=m
  3627. +CONFIG_USB_SERIAL_QCAUX=m
  3628. +CONFIG_USB_SERIAL_QUALCOMM=m
  3629. +CONFIG_USB_SERIAL_SPCP8X5=m
  3630. +CONFIG_USB_SERIAL_SAFE=m
  3631. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  3632. +CONFIG_USB_SERIAL_SYMBOL=m
  3633. +CONFIG_USB_SERIAL_TI=m
  3634. +CONFIG_USB_SERIAL_CYBERJACK=m
  3635. +CONFIG_USB_SERIAL_XIRCOM=m
  3636. +CONFIG_USB_SERIAL_OPTION=m
  3637. +CONFIG_USB_SERIAL_OMNINET=m
  3638. +CONFIG_USB_SERIAL_OPTICON=m
  3639. +CONFIG_USB_SERIAL_XSENS_MT=m
  3640. +CONFIG_USB_SERIAL_WISHBONE=m
  3641. +CONFIG_USB_SERIAL_SSU100=m
  3642. +CONFIG_USB_SERIAL_QT2=m
  3643. +CONFIG_USB_SERIAL_DEBUG=m
  3644. +CONFIG_USB_EMI62=m
  3645. +CONFIG_USB_EMI26=m
  3646. +CONFIG_USB_ADUTUX=m
  3647. +CONFIG_USB_SEVSEG=m
  3648. +CONFIG_USB_RIO500=m
  3649. +CONFIG_USB_LEGOTOWER=m
  3650. +CONFIG_USB_LCD=m
  3651. +CONFIG_USB_LED=m
  3652. +CONFIG_USB_CYPRESS_CY7C63=m
  3653. +CONFIG_USB_CYTHERM=m
  3654. +CONFIG_USB_IDMOUSE=m
  3655. +CONFIG_USB_FTDI_ELAN=m
  3656. +CONFIG_USB_APPLEDISPLAY=m
  3657. +CONFIG_USB_LD=m
  3658. +CONFIG_USB_TRANCEVIBRATOR=m
  3659. +CONFIG_USB_IOWARRIOR=m
  3660. +CONFIG_USB_TEST=m
  3661. +CONFIG_USB_ISIGHTFW=m
  3662. +CONFIG_USB_YUREX=m
  3663. +CONFIG_USB_ATM=m
  3664. +CONFIG_USB_SPEEDTOUCH=m
  3665. +CONFIG_USB_CXACRU=m
  3666. +CONFIG_USB_UEAGLEATM=m
  3667. +CONFIG_USB_XUSBATM=m
  3668. +CONFIG_MMC=y
  3669. +CONFIG_MMC_BLOCK_MINORS=32
  3670. +CONFIG_MMC_SDHCI=y
  3671. +CONFIG_MMC_SDHCI_PLTFM=y
  3672. +CONFIG_MMC_BCM2835=y
  3673. +CONFIG_MMC_BCM2835_DMA=y
  3674. +CONFIG_MMC_SPI=m
  3675. +CONFIG_LEDS_CLASS=y
  3676. +CONFIG_LEDS_GPIO=y
  3677. +CONFIG_LEDS_TRIGGER_TIMER=y
  3678. +CONFIG_LEDS_TRIGGER_ONESHOT=y
  3679. +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
  3680. +CONFIG_LEDS_TRIGGER_BACKLIGHT=y
  3681. +CONFIG_LEDS_TRIGGER_CPU=y
  3682. +CONFIG_LEDS_TRIGGER_GPIO=y
  3683. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
  3684. +CONFIG_LEDS_TRIGGER_TRANSIENT=m
  3685. +CONFIG_LEDS_TRIGGER_CAMERA=m
  3686. +CONFIG_LEDS_TRIGGER_INPUT=y
  3687. +CONFIG_RTC_CLASS=y
  3688. +# CONFIG_RTC_HCTOSYS is not set
  3689. +CONFIG_RTC_DRV_DS1307=m
  3690. +CONFIG_RTC_DRV_DS1374=m
  3691. +CONFIG_RTC_DRV_DS1672=m
  3692. +CONFIG_RTC_DRV_DS3232=m
  3693. +CONFIG_RTC_DRV_MAX6900=m
  3694. +CONFIG_RTC_DRV_RS5C372=m
  3695. +CONFIG_RTC_DRV_ISL1208=m
  3696. +CONFIG_RTC_DRV_ISL12022=m
  3697. +CONFIG_RTC_DRV_ISL12057=m
  3698. +CONFIG_RTC_DRV_X1205=m
  3699. +CONFIG_RTC_DRV_PCF2127=m
  3700. +CONFIG_RTC_DRV_PCF8523=m
  3701. +CONFIG_RTC_DRV_PCF8563=m
  3702. +CONFIG_RTC_DRV_PCF8583=m
  3703. +CONFIG_RTC_DRV_M41T80=m
  3704. +CONFIG_RTC_DRV_BQ32K=m
  3705. +CONFIG_RTC_DRV_S35390A=m
  3706. +CONFIG_RTC_DRV_FM3130=m
  3707. +CONFIG_RTC_DRV_RX8581=m
  3708. +CONFIG_RTC_DRV_RX8025=m
  3709. +CONFIG_RTC_DRV_EM3027=m
  3710. +CONFIG_RTC_DRV_RV3029C2=m
  3711. +CONFIG_RTC_DRV_M41T93=m
  3712. +CONFIG_RTC_DRV_M41T94=m
  3713. +CONFIG_RTC_DRV_DS1305=m
  3714. +CONFIG_RTC_DRV_DS1390=m
  3715. +CONFIG_RTC_DRV_MAX6902=m
  3716. +CONFIG_RTC_DRV_R9701=m
  3717. +CONFIG_RTC_DRV_RS5C348=m
  3718. +CONFIG_RTC_DRV_DS3234=m
  3719. +CONFIG_RTC_DRV_PCF2123=m
  3720. +CONFIG_RTC_DRV_RX4581=m
  3721. +CONFIG_DMADEVICES=y
  3722. +CONFIG_DMA_BCM2708=y
  3723. +CONFIG_UIO=m
  3724. +CONFIG_UIO_PDRV_GENIRQ=m
  3725. +CONFIG_STAGING=y
  3726. +CONFIG_PRISM2_USB=m
  3727. +CONFIG_R8712U=m
  3728. +CONFIG_R8188EU=m
  3729. +CONFIG_R8723AU=m
  3730. +CONFIG_VT6656=m
  3731. +CONFIG_SPEAKUP=m
  3732. +CONFIG_SPEAKUP_SYNTH_SOFT=m
  3733. +CONFIG_STAGING_MEDIA=y
  3734. +CONFIG_LIRC_STAGING=y
  3735. +CONFIG_LIRC_IGORPLUGUSB=m
  3736. +CONFIG_LIRC_IMON=m
  3737. +CONFIG_LIRC_RPI=m
  3738. +CONFIG_LIRC_SASEM=m
  3739. +CONFIG_LIRC_SERIAL=m
  3740. +# CONFIG_IOMMU_SUPPORT is not set
  3741. +CONFIG_EXTCON=m
  3742. +CONFIG_EXTCON_ARIZONA=m
  3743. +CONFIG_EXT4_FS=y
  3744. +CONFIG_EXT4_FS_POSIX_ACL=y
  3745. +CONFIG_EXT4_FS_SECURITY=y
  3746. +CONFIG_REISERFS_FS=m
  3747. +CONFIG_REISERFS_FS_XATTR=y
  3748. +CONFIG_REISERFS_FS_POSIX_ACL=y
  3749. +CONFIG_REISERFS_FS_SECURITY=y
  3750. +CONFIG_JFS_FS=m
  3751. +CONFIG_JFS_POSIX_ACL=y
  3752. +CONFIG_JFS_SECURITY=y
  3753. +CONFIG_JFS_STATISTICS=y
  3754. +CONFIG_XFS_FS=m
  3755. +CONFIG_XFS_QUOTA=y
  3756. +CONFIG_XFS_POSIX_ACL=y
  3757. +CONFIG_XFS_RT=y
  3758. +CONFIG_GFS2_FS=m
  3759. +CONFIG_OCFS2_FS=m
  3760. +CONFIG_BTRFS_FS=m
  3761. +CONFIG_BTRFS_FS_POSIX_ACL=y
  3762. +CONFIG_NILFS2_FS=m
  3763. +CONFIG_FANOTIFY=y
  3764. +CONFIG_QFMT_V1=m
  3765. +CONFIG_QFMT_V2=m
  3766. +CONFIG_AUTOFS4_FS=y
  3767. +CONFIG_FUSE_FS=m
  3768. +CONFIG_CUSE=m
  3769. +CONFIG_FSCACHE=y
  3770. +CONFIG_FSCACHE_STATS=y
  3771. +CONFIG_FSCACHE_HISTOGRAM=y
  3772. +CONFIG_CACHEFILES=y
  3773. +CONFIG_ISO9660_FS=m
  3774. +CONFIG_JOLIET=y
  3775. +CONFIG_ZISOFS=y
  3776. +CONFIG_UDF_FS=m
  3777. +CONFIG_MSDOS_FS=y
  3778. +CONFIG_VFAT_FS=y
  3779. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  3780. +CONFIG_NTFS_FS=m
  3781. +CONFIG_NTFS_RW=y
  3782. +CONFIG_TMPFS=y
  3783. +CONFIG_TMPFS_POSIX_ACL=y
  3784. +CONFIG_CONFIGFS_FS=y
  3785. +CONFIG_ECRYPT_FS=m
  3786. +CONFIG_HFS_FS=m
  3787. +CONFIG_HFSPLUS_FS=m
  3788. +CONFIG_SQUASHFS=m
  3789. +CONFIG_SQUASHFS_XATTR=y
  3790. +CONFIG_SQUASHFS_LZO=y
  3791. +CONFIG_SQUASHFS_XZ=y
  3792. +CONFIG_F2FS_FS=y
  3793. +CONFIG_NFS_FS=y
  3794. +CONFIG_NFS_V3_ACL=y
  3795. +CONFIG_NFS_V4=y
  3796. +CONFIG_NFS_SWAP=y
  3797. +CONFIG_ROOT_NFS=y
  3798. +CONFIG_NFS_FSCACHE=y
  3799. +CONFIG_NFSD=m
  3800. +CONFIG_NFSD_V3_ACL=y
  3801. +CONFIG_NFSD_V4=y
  3802. +CONFIG_CIFS=m
  3803. +CONFIG_CIFS_WEAK_PW_HASH=y
  3804. +CONFIG_CIFS_XATTR=y
  3805. +CONFIG_CIFS_POSIX=y
  3806. +CONFIG_9P_FS=m
  3807. +CONFIG_9P_FS_POSIX_ACL=y
  3808. +CONFIG_NLS_DEFAULT="utf8"
  3809. +CONFIG_NLS_CODEPAGE_437=y
  3810. +CONFIG_NLS_CODEPAGE_737=m
  3811. +CONFIG_NLS_CODEPAGE_775=m
  3812. +CONFIG_NLS_CODEPAGE_850=m
  3813. +CONFIG_NLS_CODEPAGE_852=m
  3814. +CONFIG_NLS_CODEPAGE_855=m
  3815. +CONFIG_NLS_CODEPAGE_857=m
  3816. +CONFIG_NLS_CODEPAGE_860=m
  3817. +CONFIG_NLS_CODEPAGE_861=m
  3818. +CONFIG_NLS_CODEPAGE_862=m
  3819. +CONFIG_NLS_CODEPAGE_863=m
  3820. +CONFIG_NLS_CODEPAGE_864=m
  3821. +CONFIG_NLS_CODEPAGE_865=m
  3822. +CONFIG_NLS_CODEPAGE_866=m
  3823. +CONFIG_NLS_CODEPAGE_869=m
  3824. +CONFIG_NLS_CODEPAGE_936=m
  3825. +CONFIG_NLS_CODEPAGE_950=m
  3826. +CONFIG_NLS_CODEPAGE_932=m
  3827. +CONFIG_NLS_CODEPAGE_949=m
  3828. +CONFIG_NLS_CODEPAGE_874=m
  3829. +CONFIG_NLS_ISO8859_8=m
  3830. +CONFIG_NLS_CODEPAGE_1250=m
  3831. +CONFIG_NLS_CODEPAGE_1251=m
  3832. +CONFIG_NLS_ASCII=y
  3833. +CONFIG_NLS_ISO8859_1=m
  3834. +CONFIG_NLS_ISO8859_2=m
  3835. +CONFIG_NLS_ISO8859_3=m
  3836. +CONFIG_NLS_ISO8859_4=m
  3837. +CONFIG_NLS_ISO8859_5=m
  3838. +CONFIG_NLS_ISO8859_6=m
  3839. +CONFIG_NLS_ISO8859_7=m
  3840. +CONFIG_NLS_ISO8859_9=m
  3841. +CONFIG_NLS_ISO8859_13=m
  3842. +CONFIG_NLS_ISO8859_14=m
  3843. +CONFIG_NLS_ISO8859_15=m
  3844. +CONFIG_NLS_KOI8_R=m
  3845. +CONFIG_NLS_KOI8_U=m
  3846. +CONFIG_DLM=m
  3847. +CONFIG_PRINTK_TIME=y
  3848. +CONFIG_BOOT_PRINTK_DELAY=y
  3849. +CONFIG_DEBUG_MEMORY_INIT=y
  3850. +CONFIG_DETECT_HUNG_TASK=y
  3851. +CONFIG_TIMER_STATS=y
  3852. +# CONFIG_DEBUG_PREEMPT is not set
  3853. +CONFIG_LATENCYTOP=y
  3854. +CONFIG_IRQSOFF_TRACER=y
  3855. +CONFIG_SCHED_TRACER=y
  3856. +CONFIG_STACK_TRACER=y
  3857. +CONFIG_BLK_DEV_IO_TRACE=y
  3858. +# CONFIG_KPROBE_EVENT is not set
  3859. +CONFIG_FUNCTION_PROFILER=y
  3860. +CONFIG_KGDB=y
  3861. +CONFIG_KGDB_KDB=y
  3862. +CONFIG_KDB_KEYBOARD=y
  3863. +CONFIG_CRYPTO_USER=m
  3864. +CONFIG_CRYPTO_NULL=m
  3865. +CONFIG_CRYPTO_CRYPTD=m
  3866. +CONFIG_CRYPTO_CBC=y
  3867. +CONFIG_CRYPTO_CTS=m
  3868. +CONFIG_CRYPTO_XTS=m
  3869. +CONFIG_CRYPTO_XCBC=m
  3870. +CONFIG_CRYPTO_SHA1_ARM=m
  3871. +CONFIG_CRYPTO_SHA512=m
  3872. +CONFIG_CRYPTO_TGR192=m
  3873. +CONFIG_CRYPTO_WP512=m
  3874. +CONFIG_CRYPTO_AES_ARM=m
  3875. +CONFIG_CRYPTO_CAST5=m
  3876. +CONFIG_CRYPTO_DES=y
  3877. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  3878. +# CONFIG_CRYPTO_HW is not set
  3879. +CONFIG_CRC_ITU_T=y
  3880. +CONFIG_LIBCRC32C=y
  3881. diff -Nur linux-3.18.6/arch/arm/configs/bcmrpi_quick_defconfig linux-rpi/arch/arm/configs/bcmrpi_quick_defconfig
  3882. --- linux-3.18.6/arch/arm/configs/bcmrpi_quick_defconfig 1970-01-01 01:00:00.000000000 +0100
  3883. +++ linux-rpi/arch/arm/configs/bcmrpi_quick_defconfig 2015-02-09 04:39:42.000000000 +0100
  3884. @@ -0,0 +1,197 @@
  3885. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  3886. +CONFIG_LOCALVERSION="-quick"
  3887. +# CONFIG_LOCALVERSION_AUTO is not set
  3888. +# CONFIG_SWAP is not set
  3889. +CONFIG_SYSVIPC=y
  3890. +CONFIG_POSIX_MQUEUE=y
  3891. +CONFIG_NO_HZ=y
  3892. +CONFIG_HIGH_RES_TIMERS=y
  3893. +CONFIG_IKCONFIG=y
  3894. +CONFIG_IKCONFIG_PROC=y
  3895. +CONFIG_KALLSYMS_ALL=y
  3896. +CONFIG_EMBEDDED=y
  3897. +CONFIG_PERF_EVENTS=y
  3898. +# CONFIG_COMPAT_BRK is not set
  3899. +CONFIG_SLAB=y
  3900. +CONFIG_MODULES=y
  3901. +CONFIG_MODULE_UNLOAD=y
  3902. +CONFIG_MODVERSIONS=y
  3903. +CONFIG_MODULE_SRCVERSION_ALL=y
  3904. +# CONFIG_BLK_DEV_BSG is not set
  3905. +CONFIG_ARCH_BCM2708=y
  3906. +CONFIG_PREEMPT=y
  3907. +CONFIG_AEABI=y
  3908. +CONFIG_UACCESS_WITH_MEMCPY=y
  3909. +CONFIG_ZBOOT_ROM_TEXT=0x0
  3910. +CONFIG_ZBOOT_ROM_BSS=0x0
  3911. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  3912. +CONFIG_CPU_FREQ=y
  3913. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  3914. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  3915. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  3916. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  3917. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  3918. +CONFIG_CPU_IDLE=y
  3919. +CONFIG_VFP=y
  3920. +CONFIG_BINFMT_MISC=y
  3921. +CONFIG_NET=y
  3922. +CONFIG_PACKET=y
  3923. +CONFIG_UNIX=y
  3924. +CONFIG_INET=y
  3925. +CONFIG_IP_MULTICAST=y
  3926. +CONFIG_IP_PNP=y
  3927. +CONFIG_IP_PNP_DHCP=y
  3928. +CONFIG_IP_PNP_RARP=y
  3929. +CONFIG_SYN_COOKIES=y
  3930. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  3931. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  3932. +# CONFIG_INET_XFRM_MODE_BEET is not set
  3933. +# CONFIG_INET_LRO is not set
  3934. +# CONFIG_INET_DIAG is not set
  3935. +# CONFIG_IPV6 is not set
  3936. +# CONFIG_WIRELESS is not set
  3937. +CONFIG_DEVTMPFS=y
  3938. +CONFIG_DEVTMPFS_MOUNT=y
  3939. +CONFIG_BLK_DEV_LOOP=y
  3940. +CONFIG_BLK_DEV_RAM=y
  3941. +CONFIG_SCSI=y
  3942. +# CONFIG_SCSI_PROC_FS is not set
  3943. +# CONFIG_SCSI_LOWLEVEL is not set
  3944. +CONFIG_NETDEVICES=y
  3945. +# CONFIG_NET_VENDOR_BROADCOM is not set
  3946. +# CONFIG_NET_VENDOR_CIRRUS is not set
  3947. +# CONFIG_NET_VENDOR_FARADAY is not set
  3948. +# CONFIG_NET_VENDOR_INTEL is not set
  3949. +# CONFIG_NET_VENDOR_MARVELL is not set
  3950. +# CONFIG_NET_VENDOR_MICREL is not set
  3951. +# CONFIG_NET_VENDOR_NATSEMI is not set
  3952. +# CONFIG_NET_VENDOR_SEEQ is not set
  3953. +# CONFIG_NET_VENDOR_STMICRO is not set
  3954. +# CONFIG_NET_VENDOR_WIZNET is not set
  3955. +CONFIG_USB_USBNET=y
  3956. +# CONFIG_USB_NET_AX8817X is not set
  3957. +# CONFIG_USB_NET_CDCETHER is not set
  3958. +# CONFIG_USB_NET_CDC_NCM is not set
  3959. +CONFIG_USB_NET_SMSC95XX=y
  3960. +# CONFIG_USB_NET_NET1080 is not set
  3961. +# CONFIG_USB_NET_CDC_SUBSET is not set
  3962. +# CONFIG_USB_NET_ZAURUS is not set
  3963. +# CONFIG_WLAN is not set
  3964. +# CONFIG_INPUT_MOUSEDEV is not set
  3965. +CONFIG_INPUT_EVDEV=y
  3966. +# CONFIG_INPUT_KEYBOARD is not set
  3967. +# CONFIG_INPUT_MOUSE is not set
  3968. +# CONFIG_SERIO is not set
  3969. +CONFIG_VT_HW_CONSOLE_BINDING=y
  3970. +# CONFIG_LEGACY_PTYS is not set
  3971. +# CONFIG_DEVKMEM is not set
  3972. +CONFIG_SERIAL_AMBA_PL011=y
  3973. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  3974. +CONFIG_TTY_PRINTK=y
  3975. +CONFIG_HW_RANDOM=y
  3976. +CONFIG_HW_RANDOM_BCM2708=y
  3977. +CONFIG_RAW_DRIVER=y
  3978. +CONFIG_THERMAL=y
  3979. +CONFIG_THERMAL_BCM2835=y
  3980. +CONFIG_WATCHDOG=y
  3981. +CONFIG_BCM2708_WDT=y
  3982. +CONFIG_REGULATOR=y
  3983. +CONFIG_REGULATOR_DEBUG=y
  3984. +CONFIG_REGULATOR_FIXED_VOLTAGE=y
  3985. +CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
  3986. +CONFIG_REGULATOR_USERSPACE_CONSUMER=y
  3987. +CONFIG_FB=y
  3988. +CONFIG_FB_BCM2708=y
  3989. +CONFIG_FRAMEBUFFER_CONSOLE=y
  3990. +CONFIG_LOGO=y
  3991. +# CONFIG_LOGO_LINUX_MONO is not set
  3992. +# CONFIG_LOGO_LINUX_VGA16 is not set
  3993. +CONFIG_SOUND=y
  3994. +CONFIG_SND=y
  3995. +CONFIG_SND_BCM2835=y
  3996. +# CONFIG_SND_USB is not set
  3997. +CONFIG_USB=y
  3998. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  3999. +CONFIG_USB_DWCOTG=y
  4000. +CONFIG_MMC=y
  4001. +CONFIG_MMC_SDHCI=y
  4002. +CONFIG_MMC_SDHCI_PLTFM=y
  4003. +CONFIG_MMC_SDHCI_BCM2708=y
  4004. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  4005. +CONFIG_NEW_LEDS=y
  4006. +CONFIG_LEDS_CLASS=y
  4007. +CONFIG_LEDS_TRIGGERS=y
  4008. +# CONFIG_IOMMU_SUPPORT is not set
  4009. +CONFIG_EXT4_FS=y
  4010. +CONFIG_EXT4_FS_POSIX_ACL=y
  4011. +CONFIG_EXT4_FS_SECURITY=y
  4012. +CONFIG_AUTOFS4_FS=y
  4013. +CONFIG_FSCACHE=y
  4014. +CONFIG_CACHEFILES=y
  4015. +CONFIG_MSDOS_FS=y
  4016. +CONFIG_VFAT_FS=y
  4017. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  4018. +CONFIG_TMPFS=y
  4019. +CONFIG_TMPFS_POSIX_ACL=y
  4020. +CONFIG_CONFIGFS_FS=y
  4021. +# CONFIG_MISC_FILESYSTEMS is not set
  4022. +CONFIG_NFS_FS=y
  4023. +CONFIG_NFS_V3_ACL=y
  4024. +CONFIG_NFS_V4=y
  4025. +CONFIG_ROOT_NFS=y
  4026. +CONFIG_NFS_FSCACHE=y
  4027. +CONFIG_NLS_DEFAULT="utf8"
  4028. +CONFIG_NLS_CODEPAGE_437=y
  4029. +CONFIG_NLS_CODEPAGE_737=y
  4030. +CONFIG_NLS_CODEPAGE_775=y
  4031. +CONFIG_NLS_CODEPAGE_850=y
  4032. +CONFIG_NLS_CODEPAGE_852=y
  4033. +CONFIG_NLS_CODEPAGE_855=y
  4034. +CONFIG_NLS_CODEPAGE_857=y
  4035. +CONFIG_NLS_CODEPAGE_860=y
  4036. +CONFIG_NLS_CODEPAGE_861=y
  4037. +CONFIG_NLS_CODEPAGE_862=y
  4038. +CONFIG_NLS_CODEPAGE_863=y
  4039. +CONFIG_NLS_CODEPAGE_864=y
  4040. +CONFIG_NLS_CODEPAGE_865=y
  4041. +CONFIG_NLS_CODEPAGE_866=y
  4042. +CONFIG_NLS_CODEPAGE_869=y
  4043. +CONFIG_NLS_CODEPAGE_936=y
  4044. +CONFIG_NLS_CODEPAGE_950=y
  4045. +CONFIG_NLS_CODEPAGE_932=y
  4046. +CONFIG_NLS_CODEPAGE_949=y
  4047. +CONFIG_NLS_CODEPAGE_874=y
  4048. +CONFIG_NLS_ISO8859_8=y
  4049. +CONFIG_NLS_CODEPAGE_1250=y
  4050. +CONFIG_NLS_CODEPAGE_1251=y
  4051. +CONFIG_NLS_ASCII=y
  4052. +CONFIG_NLS_ISO8859_1=y
  4053. +CONFIG_NLS_ISO8859_2=y
  4054. +CONFIG_NLS_ISO8859_3=y
  4055. +CONFIG_NLS_ISO8859_4=y
  4056. +CONFIG_NLS_ISO8859_5=y
  4057. +CONFIG_NLS_ISO8859_6=y
  4058. +CONFIG_NLS_ISO8859_7=y
  4059. +CONFIG_NLS_ISO8859_9=y
  4060. +CONFIG_NLS_ISO8859_13=y
  4061. +CONFIG_NLS_ISO8859_14=y
  4062. +CONFIG_NLS_ISO8859_15=y
  4063. +CONFIG_NLS_UTF8=y
  4064. +CONFIG_PRINTK_TIME=y
  4065. +CONFIG_DEBUG_FS=y
  4066. +CONFIG_DETECT_HUNG_TASK=y
  4067. +# CONFIG_DEBUG_PREEMPT is not set
  4068. +# CONFIG_DEBUG_BUGVERBOSE is not set
  4069. +# CONFIG_FTRACE is not set
  4070. +CONFIG_KGDB=y
  4071. +CONFIG_KGDB_KDB=y
  4072. +# CONFIG_ARM_UNWIND is not set
  4073. +CONFIG_CRYPTO_CBC=y
  4074. +CONFIG_CRYPTO_HMAC=y
  4075. +CONFIG_CRYPTO_MD5=y
  4076. +CONFIG_CRYPTO_SHA1=y
  4077. +CONFIG_CRYPTO_DES=y
  4078. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  4079. +# CONFIG_CRYPTO_HW is not set
  4080. +CONFIG_CRC_ITU_T=y
  4081. +CONFIG_LIBCRC32C=y
  4082. diff -Nur linux-3.18.6/arch/arm/configs/bcmrpi_sdcard_defconfig linux-rpi/arch/arm/configs/bcmrpi_sdcard_defconfig
  4083. --- linux-3.18.6/arch/arm/configs/bcmrpi_sdcard_defconfig 1970-01-01 01:00:00.000000000 +0100
  4084. +++ linux-rpi/arch/arm/configs/bcmrpi_sdcard_defconfig 2015-02-09 04:39:42.000000000 +0100
  4085. @@ -0,0 +1,176 @@
  4086. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  4087. +CONFIG_LOCALVERSION="-quick"
  4088. +# CONFIG_LOCALVERSION_AUTO is not set
  4089. +# CONFIG_SWAP is not set
  4090. +CONFIG_SYSVIPC=y
  4091. +CONFIG_POSIX_MQUEUE=y
  4092. +CONFIG_NO_HZ=y
  4093. +CONFIG_HIGH_RES_TIMERS=y
  4094. +CONFIG_IKCONFIG=y
  4095. +CONFIG_IKCONFIG_PROC=y
  4096. +CONFIG_KALLSYMS_ALL=y
  4097. +CONFIG_EMBEDDED=y
  4098. +CONFIG_PERF_EVENTS=y
  4099. +# CONFIG_COMPAT_BRK is not set
  4100. +CONFIG_SLAB=y
  4101. +# CONFIG_BLK_DEV_BSG is not set
  4102. +CONFIG_ARCH_BCM2708=y
  4103. +CONFIG_PREEMPT=y
  4104. +CONFIG_AEABI=y
  4105. +CONFIG_UACCESS_WITH_MEMCPY=y
  4106. +CONFIG_ZBOOT_ROM_TEXT=0x0
  4107. +CONFIG_ZBOOT_ROM_BSS=0x0
  4108. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  4109. +CONFIG_CPU_FREQ=y
  4110. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  4111. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  4112. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  4113. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  4114. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  4115. +CONFIG_CPU_IDLE=y
  4116. +CONFIG_VFP=y
  4117. +CONFIG_BINFMT_MISC=y
  4118. +CONFIG_NET=y
  4119. +CONFIG_PACKET=y
  4120. +CONFIG_UNIX=y
  4121. +CONFIG_INET=y
  4122. +CONFIG_IP_MULTICAST=y
  4123. +CONFIG_IP_PNP=y
  4124. +CONFIG_IP_PNP_DHCP=y
  4125. +CONFIG_IP_PNP_RARP=y
  4126. +CONFIG_SYN_COOKIES=y
  4127. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  4128. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  4129. +# CONFIG_INET_XFRM_MODE_BEET is not set
  4130. +# CONFIG_INET_LRO is not set
  4131. +# CONFIG_INET_DIAG is not set
  4132. +# CONFIG_IPV6 is not set
  4133. +# CONFIG_WIRELESS is not set
  4134. +CONFIG_DEVTMPFS=y
  4135. +CONFIG_DEVTMPFS_MOUNT=y
  4136. +CONFIG_BLK_DEV_LOOP=y
  4137. +CONFIG_BLK_DEV_RAM=y
  4138. +CONFIG_SCSI=y
  4139. +# CONFIG_SCSI_PROC_FS is not set
  4140. +# CONFIG_SCSI_LOWLEVEL is not set
  4141. +CONFIG_NETDEVICES=y
  4142. +CONFIG_MII=y
  4143. +# CONFIG_NET_VENDOR_BROADCOM is not set
  4144. +# CONFIG_NET_VENDOR_CIRRUS is not set
  4145. +# CONFIG_NET_VENDOR_FARADAY is not set
  4146. +# CONFIG_NET_VENDOR_INTEL is not set
  4147. +# CONFIG_NET_VENDOR_MARVELL is not set
  4148. +# CONFIG_NET_VENDOR_MICREL is not set
  4149. +# CONFIG_NET_VENDOR_NATSEMI is not set
  4150. +# CONFIG_NET_VENDOR_SEEQ is not set
  4151. +# CONFIG_NET_VENDOR_STMICRO is not set
  4152. +# CONFIG_NET_VENDOR_WIZNET is not set
  4153. +CONFIG_PHYLIB=y
  4154. +# CONFIG_WLAN is not set
  4155. +# CONFIG_INPUT_MOUSEDEV is not set
  4156. +CONFIG_INPUT_EVDEV=y
  4157. +# CONFIG_INPUT_KEYBOARD is not set
  4158. +# CONFIG_INPUT_MOUSE is not set
  4159. +# CONFIG_SERIO is not set
  4160. +CONFIG_VT_HW_CONSOLE_BINDING=y
  4161. +# CONFIG_LEGACY_PTYS is not set
  4162. +# CONFIG_DEVKMEM is not set
  4163. +CONFIG_SERIAL_AMBA_PL011=y
  4164. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  4165. +CONFIG_TTY_PRINTK=y
  4166. +CONFIG_RAW_DRIVER=y
  4167. +CONFIG_WATCHDOG=y
  4168. +CONFIG_REGULATOR=y
  4169. +CONFIG_REGULATOR_DEBUG=y
  4170. +CONFIG_REGULATOR_FIXED_VOLTAGE=y
  4171. +CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
  4172. +CONFIG_REGULATOR_USERSPACE_CONSUMER=y
  4173. +CONFIG_FB=y
  4174. +CONFIG_FRAMEBUFFER_CONSOLE=y
  4175. +CONFIG_LOGO=y
  4176. +# CONFIG_LOGO_LINUX_MONO is not set
  4177. +# CONFIG_LOGO_LINUX_VGA16 is not set
  4178. +CONFIG_SOUND=y
  4179. +CONFIG_SND=y
  4180. +CONFIG_MMC=y
  4181. +CONFIG_MMC_SDHCI=y
  4182. +CONFIG_MMC_SDHCI_PLTFM=y
  4183. +CONFIG_MMC_SDHCI_BCM2708=y
  4184. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  4185. +CONFIG_NEW_LEDS=y
  4186. +CONFIG_LEDS_CLASS=y
  4187. +CONFIG_LEDS_TRIGGERS=y
  4188. +# CONFIG_IOMMU_SUPPORT is not set
  4189. +CONFIG_EXT4_FS=y
  4190. +CONFIG_EXT4_FS_POSIX_ACL=y
  4191. +CONFIG_EXT4_FS_SECURITY=y
  4192. +CONFIG_AUTOFS4_FS=y
  4193. +CONFIG_FSCACHE=y
  4194. +CONFIG_CACHEFILES=y
  4195. +CONFIG_MSDOS_FS=y
  4196. +CONFIG_VFAT_FS=y
  4197. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  4198. +CONFIG_TMPFS=y
  4199. +CONFIG_TMPFS_POSIX_ACL=y
  4200. +CONFIG_CONFIGFS_FS=y
  4201. +# CONFIG_MISC_FILESYSTEMS is not set
  4202. +CONFIG_NFS_FS=y
  4203. +CONFIG_NFS_V3_ACL=y
  4204. +CONFIG_NFS_V4=y
  4205. +CONFIG_ROOT_NFS=y
  4206. +CONFIG_NFS_FSCACHE=y
  4207. +CONFIG_NLS_DEFAULT="utf8"
  4208. +CONFIG_NLS_CODEPAGE_437=y
  4209. +CONFIG_NLS_CODEPAGE_737=y
  4210. +CONFIG_NLS_CODEPAGE_775=y
  4211. +CONFIG_NLS_CODEPAGE_850=y
  4212. +CONFIG_NLS_CODEPAGE_852=y
  4213. +CONFIG_NLS_CODEPAGE_855=y
  4214. +CONFIG_NLS_CODEPAGE_857=y
  4215. +CONFIG_NLS_CODEPAGE_860=y
  4216. +CONFIG_NLS_CODEPAGE_861=y
  4217. +CONFIG_NLS_CODEPAGE_862=y
  4218. +CONFIG_NLS_CODEPAGE_863=y
  4219. +CONFIG_NLS_CODEPAGE_864=y
  4220. +CONFIG_NLS_CODEPAGE_865=y
  4221. +CONFIG_NLS_CODEPAGE_866=y
  4222. +CONFIG_NLS_CODEPAGE_869=y
  4223. +CONFIG_NLS_CODEPAGE_936=y
  4224. +CONFIG_NLS_CODEPAGE_950=y
  4225. +CONFIG_NLS_CODEPAGE_932=y
  4226. +CONFIG_NLS_CODEPAGE_949=y
  4227. +CONFIG_NLS_CODEPAGE_874=y
  4228. +CONFIG_NLS_ISO8859_8=y
  4229. +CONFIG_NLS_CODEPAGE_1250=y
  4230. +CONFIG_NLS_CODEPAGE_1251=y
  4231. +CONFIG_NLS_ASCII=y
  4232. +CONFIG_NLS_ISO8859_1=y
  4233. +CONFIG_NLS_ISO8859_2=y
  4234. +CONFIG_NLS_ISO8859_3=y
  4235. +CONFIG_NLS_ISO8859_4=y
  4236. +CONFIG_NLS_ISO8859_5=y
  4237. +CONFIG_NLS_ISO8859_6=y
  4238. +CONFIG_NLS_ISO8859_7=y
  4239. +CONFIG_NLS_ISO8859_9=y
  4240. +CONFIG_NLS_ISO8859_13=y
  4241. +CONFIG_NLS_ISO8859_14=y
  4242. +CONFIG_NLS_ISO8859_15=y
  4243. +CONFIG_NLS_UTF8=y
  4244. +CONFIG_PRINTK_TIME=y
  4245. +CONFIG_DEBUG_FS=y
  4246. +CONFIG_DETECT_HUNG_TASK=y
  4247. +# CONFIG_DEBUG_PREEMPT is not set
  4248. +# CONFIG_DEBUG_BUGVERBOSE is not set
  4249. +# CONFIG_FTRACE is not set
  4250. +CONFIG_KGDB=y
  4251. +CONFIG_KGDB_KDB=y
  4252. +# CONFIG_ARM_UNWIND is not set
  4253. +CONFIG_CRYPTO_CBC=y
  4254. +CONFIG_CRYPTO_HMAC=y
  4255. +CONFIG_CRYPTO_MD5=y
  4256. +CONFIG_CRYPTO_SHA1=y
  4257. +CONFIG_CRYPTO_DES=y
  4258. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  4259. +# CONFIG_CRYPTO_HW is not set
  4260. +CONFIG_CRC_ITU_T=y
  4261. +CONFIG_LIBCRC32C=y
  4262. diff -Nur linux-3.18.6/arch/arm/configs/bcmrpi_small_defconfig linux-rpi/arch/arm/configs/bcmrpi_small_defconfig
  4263. --- linux-3.18.6/arch/arm/configs/bcmrpi_small_defconfig 1970-01-01 01:00:00.000000000 +0100
  4264. +++ linux-rpi/arch/arm/configs/bcmrpi_small_defconfig 2015-02-09 04:39:42.000000000 +0100
  4265. @@ -0,0 +1,103 @@
  4266. +CONFIG_LOCALVERSION="-quick"
  4267. +# CONFIG_LOCALVERSION_AUTO is not set
  4268. +# CONFIG_SWAP is not set
  4269. +CONFIG_SYSVIPC=y
  4270. +CONFIG_NO_HZ=y
  4271. +CONFIG_HIGH_RES_TIMERS=y
  4272. +CONFIG_IKCONFIG=y
  4273. +CONFIG_IKCONFIG_PROC=y
  4274. +CONFIG_KALLSYMS_ALL=y
  4275. +CONFIG_PERF_EVENTS=y
  4276. +# CONFIG_COMPAT_BRK is not set
  4277. +# CONFIG_BLK_DEV_BSG is not set
  4278. +CONFIG_ARCH_BCM2836=y
  4279. +# CONFIG_BCM2708_GPIO is not set
  4280. +# CONFIG_BCM2708_VCMEM is not set
  4281. +# CONFIG_CACHE_L2X0 is not set
  4282. +CONFIG_SMP=y
  4283. +CONFIG_HAVE_ARM_ARCH_TIMER=y
  4284. +CONFIG_PREEMPT=y
  4285. +CONFIG_AEABI=y
  4286. +CONFIG_ZBOOT_ROM_TEXT=0x0
  4287. +CONFIG_ZBOOT_ROM_BSS=0x0
  4288. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  4289. +CONFIG_CPU_IDLE=y
  4290. +# CONFIG_SUSPEND is not set
  4291. +CONFIG_DEVTMPFS=y
  4292. +CONFIG_DEVTMPFS_MOUNT=y
  4293. +CONFIG_BLK_DEV_LOOP=y
  4294. +CONFIG_BLK_DEV_RAM=y
  4295. +# CONFIG_BCM2708_VCHIQ is not set
  4296. +# CONFIG_INPUT_MOUSEDEV is not set
  4297. +CONFIG_INPUT_EVDEV=y
  4298. +# CONFIG_INPUT_KEYBOARD is not set
  4299. +# CONFIG_INPUT_MOUSE is not set
  4300. +# CONFIG_SERIO is not set
  4301. +# CONFIG_LEGACY_PTYS is not set
  4302. +# CONFIG_DEVKMEM is not set
  4303. +CONFIG_SERIAL_AMBA_PL011=y
  4304. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  4305. +CONFIG_RAW_DRIVER=y
  4306. +# CONFIG_HID is not set
  4307. +CONFIG_DMADEVICES=y
  4308. +# CONFIG_IOMMU_SUPPORT is not set
  4309. +CONFIG_TMPFS=y
  4310. +CONFIG_TMPFS_POSIX_ACL=y
  4311. +# CONFIG_MISC_FILESYSTEMS is not set
  4312. +CONFIG_NLS=y
  4313. +CONFIG_NLS_DEFAULT="utf8"
  4314. +CONFIG_NLS_CODEPAGE_437=y
  4315. +CONFIG_NLS_CODEPAGE_737=y
  4316. +CONFIG_NLS_CODEPAGE_775=y
  4317. +CONFIG_NLS_CODEPAGE_850=y
  4318. +CONFIG_NLS_CODEPAGE_852=y
  4319. +CONFIG_NLS_CODEPAGE_855=y
  4320. +CONFIG_NLS_CODEPAGE_857=y
  4321. +CONFIG_NLS_CODEPAGE_860=y
  4322. +CONFIG_NLS_CODEPAGE_861=y
  4323. +CONFIG_NLS_CODEPAGE_862=y
  4324. +CONFIG_NLS_CODEPAGE_863=y
  4325. +CONFIG_NLS_CODEPAGE_864=y
  4326. +CONFIG_NLS_CODEPAGE_865=y
  4327. +CONFIG_NLS_CODEPAGE_866=y
  4328. +CONFIG_NLS_CODEPAGE_869=y
  4329. +CONFIG_NLS_CODEPAGE_936=y
  4330. +CONFIG_NLS_CODEPAGE_950=y
  4331. +CONFIG_NLS_CODEPAGE_932=y
  4332. +CONFIG_NLS_CODEPAGE_949=y
  4333. +CONFIG_NLS_CODEPAGE_874=y
  4334. +CONFIG_NLS_ISO8859_8=y
  4335. +CONFIG_NLS_CODEPAGE_1250=y
  4336. +CONFIG_NLS_CODEPAGE_1251=y
  4337. +CONFIG_NLS_ASCII=y
  4338. +CONFIG_NLS_ISO8859_1=y
  4339. +CONFIG_NLS_ISO8859_2=y
  4340. +CONFIG_NLS_ISO8859_3=y
  4341. +CONFIG_NLS_ISO8859_4=y
  4342. +CONFIG_NLS_ISO8859_5=y
  4343. +CONFIG_NLS_ISO8859_6=y
  4344. +CONFIG_NLS_ISO8859_7=y
  4345. +CONFIG_NLS_ISO8859_9=y
  4346. +CONFIG_NLS_ISO8859_13=y
  4347. +CONFIG_NLS_ISO8859_14=y
  4348. +CONFIG_NLS_ISO8859_15=y
  4349. +CONFIG_NLS_UTF8=y
  4350. +CONFIG_PRINTK_TIME=y
  4351. +CONFIG_DEBUG_KERNEL=y
  4352. +# CONFIG_DEBUG_PREEMPT is not set
  4353. +# CONFIG_FTRACE is not set
  4354. +CONFIG_KGDB=y
  4355. +CONFIG_KGDB_KDB=y
  4356. +# CONFIG_ARM_UNWIND is not set
  4357. +CONFIG_DEBUG_LL=y
  4358. +CONFIG_EARLY_PRINTK=y
  4359. +CONFIG_CRYPTO_CBC=y
  4360. +CONFIG_CRYPTO_HMAC=y
  4361. +CONFIG_CRYPTO_MD5=y
  4362. +CONFIG_CRYPTO_SHA1=y
  4363. +CONFIG_CRYPTO_DES=y
  4364. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  4365. +# CONFIG_CRYPTO_HW is not set
  4366. +CONFIG_CRC16=y
  4367. +CONFIG_CRC_ITU_T=y
  4368. +CONFIG_LIBCRC32C=y
  4369. diff -Nur linux-3.18.6/arch/arm/include/asm/dma-mapping.h linux-rpi/arch/arm/include/asm/dma-mapping.h
  4370. --- linux-3.18.6/arch/arm/include/asm/dma-mapping.h 2015-02-06 15:53:48.000000000 +0100
  4371. +++ linux-rpi/arch/arm/include/asm/dma-mapping.h 2015-02-09 04:39:42.000000000 +0100
  4372. @@ -58,37 +58,21 @@
  4373. #ifndef __arch_pfn_to_dma
  4374. static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
  4375. {
  4376. - if (dev)
  4377. - pfn -= dev->dma_pfn_offset;
  4378. return (dma_addr_t)__pfn_to_bus(pfn);
  4379. }
  4380. static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
  4381. {
  4382. - unsigned long pfn = __bus_to_pfn(addr);
  4383. -
  4384. - if (dev)
  4385. - pfn += dev->dma_pfn_offset;
  4386. -
  4387. - return pfn;
  4388. + return __bus_to_pfn(addr);
  4389. }
  4390. static inline void *dma_to_virt(struct device *dev, dma_addr_t addr)
  4391. {
  4392. - if (dev) {
  4393. - unsigned long pfn = dma_to_pfn(dev, addr);
  4394. -
  4395. - return phys_to_virt(__pfn_to_phys(pfn));
  4396. - }
  4397. -
  4398. return (void *)__bus_to_virt((unsigned long)addr);
  4399. }
  4400. static inline dma_addr_t virt_to_dma(struct device *dev, void *addr)
  4401. {
  4402. - if (dev)
  4403. - return pfn_to_dma(dev, virt_to_pfn(addr));
  4404. -
  4405. return (dma_addr_t)__virt_to_bus((unsigned long)(addr));
  4406. }
  4407. diff -Nur linux-3.18.6/arch/arm/include/asm/entry-macro-multi.S linux-rpi/arch/arm/include/asm/entry-macro-multi.S
  4408. --- linux-3.18.6/arch/arm/include/asm/entry-macro-multi.S 2015-02-06 15:53:48.000000000 +0100
  4409. +++ linux-rpi/arch/arm/include/asm/entry-macro-multi.S 2015-02-09 04:39:42.000000000 +0100
  4410. @@ -1,5 +1,6 @@
  4411. #include <asm/assembler.h>
  4412. +#ifndef CONFIG_ARCH_BCM2709
  4413. /*
  4414. * Interrupt handling. Preserves r7, r8, r9
  4415. */
  4416. @@ -28,6 +29,7 @@
  4417. #endif
  4418. 9997:
  4419. .endm
  4420. +#endif
  4421. .macro arch_irq_handler, symbol_name
  4422. .align 5
  4423. diff -Nur linux-3.18.6/arch/arm/include/asm/irqflags.h linux-rpi/arch/arm/include/asm/irqflags.h
  4424. --- linux-3.18.6/arch/arm/include/asm/irqflags.h 2015-02-06 15:53:48.000000000 +0100
  4425. +++ linux-rpi/arch/arm/include/asm/irqflags.h 2015-02-09 04:39:42.000000000 +0100
  4426. @@ -145,12 +145,22 @@
  4427. }
  4428. /*
  4429. - * restore saved IRQ & FIQ state
  4430. + * restore saved IRQ state
  4431. */
  4432. static inline void arch_local_irq_restore(unsigned long flags)
  4433. {
  4434. - asm volatile(
  4435. - " msr " IRQMASK_REG_NAME_W ", %0 @ local_irq_restore"
  4436. + unsigned long temp = 0;
  4437. + flags &= ~(1 << 6);
  4438. + asm volatile (
  4439. + " mrs %0, cpsr"
  4440. + : "=r" (temp)
  4441. + :
  4442. + : "memory", "cc");
  4443. + /* Preserve FIQ bit */
  4444. + temp &= (1 << 6);
  4445. + flags = flags | temp;
  4446. + asm volatile (
  4447. + " msr cpsr_c, %0 @ local_irq_restore"
  4448. :
  4449. : "r" (flags)
  4450. : "memory", "cc");
  4451. diff -Nur linux-3.18.6/arch/arm/include/asm/string.h linux-rpi/arch/arm/include/asm/string.h
  4452. --- linux-3.18.6/arch/arm/include/asm/string.h 2015-02-06 15:53:48.000000000 +0100
  4453. +++ linux-rpi/arch/arm/include/asm/string.h 2015-02-09 04:39:42.000000000 +0100
  4454. @@ -24,6 +24,11 @@
  4455. #define __HAVE_ARCH_MEMSET
  4456. extern void * memset(void *, int, __kernel_size_t);
  4457. +#ifdef CONFIG_MACH_BCM2708
  4458. +#define __HAVE_ARCH_MEMCMP
  4459. +extern int memcmp(const void *, const void *, size_t);
  4460. +#endif
  4461. +
  4462. extern void __memzero(void *ptr, __kernel_size_t n);
  4463. #define memset(p,v,n) \
  4464. diff -Nur linux-3.18.6/arch/arm/include/asm/uaccess.h linux-rpi/arch/arm/include/asm/uaccess.h
  4465. --- linux-3.18.6/arch/arm/include/asm/uaccess.h 2015-02-06 15:53:48.000000000 +0100
  4466. +++ linux-rpi/arch/arm/include/asm/uaccess.h 2015-02-09 04:39:42.000000000 +0100
  4467. @@ -475,6 +475,7 @@
  4468. #ifdef CONFIG_MMU
  4469. extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
  4470. +extern unsigned long __must_check __copy_from_user_std(void *to, const void __user *from, unsigned long n);
  4471. extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
  4472. extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
  4473. extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
  4474. diff -Nur linux-3.18.6/arch/arm/Kconfig linux-rpi/arch/arm/Kconfig
  4475. --- linux-3.18.6/arch/arm/Kconfig 2015-02-06 15:53:48.000000000 +0100
  4476. +++ linux-rpi/arch/arm/Kconfig 2015-02-09 04:39:42.000000000 +0100
  4477. @@ -381,6 +381,23 @@
  4478. This enables support for systems based on Atmel
  4479. AT91RM9200 and AT91SAM9* processors.
  4480. +config ARCH_BCM2708
  4481. + bool "Broadcom BCM2708 family"
  4482. + select CPU_V6
  4483. + select ARM_AMBA
  4484. + select HAVE_SCHED_CLOCK
  4485. + select NEED_MACH_GPIO_H
  4486. + select NEED_MACH_MEMORY_H
  4487. + select COMMON_CLK
  4488. + select ARCH_HAS_CPUFREQ
  4489. + select GENERIC_CLOCKEVENTS
  4490. + select ARM_ERRATA_411920
  4491. + select MACH_BCM2708
  4492. + select VC4
  4493. + select FIQ
  4494. + help
  4495. + This enables support for Broadcom BCM2708 boards.
  4496. +
  4497. config ARCH_CLPS711X
  4498. bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
  4499. select ARCH_REQUIRE_GPIOLIB
  4500. @@ -786,6 +803,26 @@
  4501. help
  4502. Support for older TI OMAP1 (omap7xx, omap15xx or omap16xx)
  4503. +config ARCH_BCM2709
  4504. + bool "Broadcom BCM2709 family"
  4505. + select ARCH_HAS_BARRIERS if SMP
  4506. + select CPU_V7
  4507. + select HAVE_SMP
  4508. + select ARM_AMBA
  4509. + select MIGHT_HAVE_CACHE_L2X0
  4510. + select HAVE_SCHED_CLOCK
  4511. + select NEED_MACH_MEMORY_H
  4512. + select NEED_MACH_IO_H
  4513. + select COMMON_CLK
  4514. + select ARCH_HAS_CPUFREQ
  4515. + select GENERIC_CLOCKEVENTS
  4516. + select MACH_BCM2709
  4517. + select VC4
  4518. + select FIQ
  4519. +# select ZONE_DMA
  4520. + help
  4521. + This enables support for Broadcom BCM2709 boards.
  4522. +
  4523. endchoice
  4524. menu "Multiple platform selection"
  4525. @@ -972,6 +1009,8 @@
  4526. source "arch/arm/mach-vt8500/Kconfig"
  4527. source "arch/arm/mach-w90x900/Kconfig"
  4528. +source "arch/arm/mach-bcm2708/Kconfig"
  4529. +source "arch/arm/mach-bcm2709/Kconfig"
  4530. source "arch/arm/mach-zynq/Kconfig"
  4531. diff -Nur linux-3.18.6/arch/arm/Kconfig.debug linux-rpi/arch/arm/Kconfig.debug
  4532. --- linux-3.18.6/arch/arm/Kconfig.debug 2015-02-06 15:53:48.000000000 +0100
  4533. +++ linux-rpi/arch/arm/Kconfig.debug 2015-02-09 04:39:42.000000000 +0100
  4534. @@ -985,6 +985,14 @@
  4535. options; the platform specific options are deprecated
  4536. and will be soon removed.
  4537. + config DEBUG_BCM2708_UART0
  4538. + bool "Broadcom BCM2708 UART0 (PL011)"
  4539. + depends on MACH_BCM2708
  4540. + help
  4541. + Say Y here if you want the debug print routines to direct
  4542. + their output to UART 0. The port must have been initialised
  4543. + by the boot-loader before use.
  4544. +
  4545. endchoice
  4546. config DEBUG_EXYNOS_UART
  4547. diff -Nur linux-3.18.6/arch/arm/kernel/fiqasm.S linux-rpi/arch/arm/kernel/fiqasm.S
  4548. --- linux-3.18.6/arch/arm/kernel/fiqasm.S 2015-02-06 15:53:48.000000000 +0100
  4549. +++ linux-rpi/arch/arm/kernel/fiqasm.S 2015-02-09 04:39:42.000000000 +0100
  4550. @@ -47,3 +47,7 @@
  4551. mov r0, r0 @ avoid hazard prior to ARMv4
  4552. ret lr
  4553. ENDPROC(__get_fiq_regs)
  4554. +
  4555. +ENTRY(__FIQ_Branch)
  4556. + mov pc, r8
  4557. +ENDPROC(__FIQ_Branch)
  4558. diff -Nur linux-3.18.6/arch/arm/kernel/head.S linux-rpi/arch/arm/kernel/head.S
  4559. --- linux-3.18.6/arch/arm/kernel/head.S 2015-02-06 15:53:48.000000000 +0100
  4560. +++ linux-rpi/arch/arm/kernel/head.S 2015-02-09 04:39:42.000000000 +0100
  4561. @@ -673,6 +673,14 @@
  4562. ldrcc r7, [r4], #4 @ use branch for delay slot
  4563. bcc 1b
  4564. ret lr
  4565. + nop
  4566. + nop
  4567. + nop
  4568. + nop
  4569. + nop
  4570. + nop
  4571. + nop
  4572. + nop
  4573. #endif
  4574. ENDPROC(__fixup_a_pv_table)
  4575. diff -Nur linux-3.18.6/arch/arm/kernel/process.c linux-rpi/arch/arm/kernel/process.c
  4576. --- linux-3.18.6/arch/arm/kernel/process.c 2015-02-06 15:53:48.000000000 +0100
  4577. +++ linux-rpi/arch/arm/kernel/process.c 2015-02-09 04:39:42.000000000 +0100
  4578. @@ -166,6 +166,16 @@
  4579. }
  4580. #endif
  4581. +char bcm2708_reboot_mode = 'h';
  4582. +
  4583. +int __init reboot_setup(char *str)
  4584. +{
  4585. + bcm2708_reboot_mode = str[0];
  4586. + return 1;
  4587. +}
  4588. +
  4589. +__setup("reboot=", reboot_setup);
  4590. +
  4591. /*
  4592. * Called by kexec, immediately prior to machine_kexec().
  4593. *
  4594. diff -Nur linux-3.18.6/arch/arm/lib/arm-mem.h linux-rpi/arch/arm/lib/arm-mem.h
  4595. --- linux-3.18.6/arch/arm/lib/arm-mem.h 1970-01-01 01:00:00.000000000 +0100
  4596. +++ linux-rpi/arch/arm/lib/arm-mem.h 2015-02-09 04:39:42.000000000 +0100
  4597. @@ -0,0 +1,159 @@
  4598. +/*
  4599. +Copyright (c) 2013, Raspberry Pi Foundation
  4600. +Copyright (c) 2013, RISC OS Open Ltd
  4601. +All rights reserved.
  4602. +
  4603. +Redistribution and use in source and binary forms, with or without
  4604. +modification, are permitted provided that the following conditions are met:
  4605. + * Redistributions of source code must retain the above copyright
  4606. + notice, this list of conditions and the following disclaimer.
  4607. + * Redistributions in binary form must reproduce the above copyright
  4608. + notice, this list of conditions and the following disclaimer in the
  4609. + documentation and/or other materials provided with the distribution.
  4610. + * Neither the name of the copyright holder nor the
  4611. + names of its contributors may be used to endorse or promote products
  4612. + derived from this software without specific prior written permission.
  4613. +
  4614. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  4615. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  4616. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  4617. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  4618. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  4619. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  4620. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  4621. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  4622. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  4623. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4624. +*/
  4625. +
  4626. +.macro myfunc fname
  4627. + .func fname
  4628. + .global fname
  4629. +fname:
  4630. +.endm
  4631. +
  4632. +.macro preload_leading_step1 backwards, ptr, base
  4633. +/* If the destination is already 16-byte aligned, then we need to preload
  4634. + * between 0 and prefetch_distance (inclusive) cache lines ahead so there
  4635. + * are no gaps when the inner loop starts.
  4636. + */
  4637. + .if backwards
  4638. + sub ptr, base, #1
  4639. + bic ptr, ptr, #31
  4640. + .else
  4641. + bic ptr, base, #31
  4642. + .endif
  4643. + .set OFFSET, 0
  4644. + .rept prefetch_distance+1
  4645. + pld [ptr, #OFFSET]
  4646. + .if backwards
  4647. + .set OFFSET, OFFSET-32
  4648. + .else
  4649. + .set OFFSET, OFFSET+32
  4650. + .endif
  4651. + .endr
  4652. +.endm
  4653. +
  4654. +.macro preload_leading_step2 backwards, ptr, base, leading_bytes, tmp
  4655. +/* However, if the destination is not 16-byte aligned, we may need to
  4656. + * preload one more cache line than that. The question we need to ask is:
  4657. + * are the leading bytes more than the amount by which the source
  4658. + * pointer will be rounded down for preloading, and if so, by how many
  4659. + * cache lines?
  4660. + */
  4661. + .if backwards
  4662. +/* Here we compare against how many bytes we are into the
  4663. + * cache line, counting down from the highest such address.
  4664. + * Effectively, we want to calculate
  4665. + * leading_bytes = dst&15
  4666. + * cacheline_offset = 31-((src-leading_bytes-1)&31)
  4667. + * extra_needed = leading_bytes - cacheline_offset
  4668. + * and test if extra_needed is <= 0, or rearranging:
  4669. + * leading_bytes + (src-leading_bytes-1)&31 <= 31
  4670. + */
  4671. + mov tmp, base, lsl #32-5
  4672. + sbc tmp, tmp, leading_bytes, lsl #32-5
  4673. + adds tmp, tmp, leading_bytes, lsl #32-5
  4674. + bcc 61f
  4675. + pld [ptr, #-32*(prefetch_distance+1)]
  4676. + .else
  4677. +/* Effectively, we want to calculate
  4678. + * leading_bytes = (-dst)&15
  4679. + * cacheline_offset = (src+leading_bytes)&31
  4680. + * extra_needed = leading_bytes - cacheline_offset
  4681. + * and test if extra_needed is <= 0.
  4682. + */
  4683. + mov tmp, base, lsl #32-5
  4684. + add tmp, tmp, leading_bytes, lsl #32-5
  4685. + rsbs tmp, tmp, leading_bytes, lsl #32-5
  4686. + bls 61f
  4687. + pld [ptr, #32*(prefetch_distance+1)]
  4688. + .endif
  4689. +61:
  4690. +.endm
  4691. +
  4692. +.macro preload_trailing backwards, base, remain, tmp
  4693. + /* We need either 0, 1 or 2 extra preloads */
  4694. + .if backwards
  4695. + rsb tmp, base, #0
  4696. + mov tmp, tmp, lsl #32-5
  4697. + .else
  4698. + mov tmp, base, lsl #32-5
  4699. + .endif
  4700. + adds tmp, tmp, remain, lsl #32-5
  4701. + adceqs tmp, tmp, #0
  4702. + /* The instruction above has two effects: ensures Z is only
  4703. + * set if C was clear (so Z indicates that both shifted quantities
  4704. + * were 0), and clears C if Z was set (so C indicates that the sum
  4705. + * of the shifted quantities was greater and not equal to 32) */
  4706. + beq 82f
  4707. + .if backwards
  4708. + sub tmp, base, #1
  4709. + bic tmp, tmp, #31
  4710. + .else
  4711. + bic tmp, base, #31
  4712. + .endif
  4713. + bcc 81f
  4714. + .if backwards
  4715. + pld [tmp, #-32*(prefetch_distance+1)]
  4716. +81:
  4717. + pld [tmp, #-32*prefetch_distance]
  4718. + .else
  4719. + pld [tmp, #32*(prefetch_distance+2)]
  4720. +81:
  4721. + pld [tmp, #32*(prefetch_distance+1)]
  4722. + .endif
  4723. +82:
  4724. +.endm
  4725. +
  4726. +.macro preload_all backwards, narrow_case, shift, base, remain, tmp0, tmp1
  4727. + .if backwards
  4728. + sub tmp0, base, #1
  4729. + bic tmp0, tmp0, #31
  4730. + pld [tmp0]
  4731. + sub tmp1, base, remain, lsl #shift
  4732. + .else
  4733. + bic tmp0, base, #31
  4734. + pld [tmp0]
  4735. + add tmp1, base, remain, lsl #shift
  4736. + sub tmp1, tmp1, #1
  4737. + .endif
  4738. + bic tmp1, tmp1, #31
  4739. + cmp tmp1, tmp0
  4740. + beq 92f
  4741. + .if narrow_case
  4742. + /* In this case, all the data fits in either 1 or 2 cache lines */
  4743. + pld [tmp1]
  4744. + .else
  4745. +91:
  4746. + .if backwards
  4747. + sub tmp0, tmp0, #32
  4748. + .else
  4749. + add tmp0, tmp0, #32
  4750. + .endif
  4751. + cmp tmp0, tmp1
  4752. + pld [tmp0]
  4753. + bne 91b
  4754. + .endif
  4755. +92:
  4756. +.endm
  4757. diff -Nur linux-3.18.6/arch/arm/lib/copy_from_user.S linux-rpi/arch/arm/lib/copy_from_user.S
  4758. --- linux-3.18.6/arch/arm/lib/copy_from_user.S 2015-02-06 15:53:48.000000000 +0100
  4759. +++ linux-rpi/arch/arm/lib/copy_from_user.S 2015-02-09 04:39:42.000000000 +0100
  4760. @@ -84,11 +84,13 @@
  4761. .text
  4762. -ENTRY(__copy_from_user)
  4763. +ENTRY(__copy_from_user_std)
  4764. +WEAK(__copy_from_user)
  4765. #include "copy_template.S"
  4766. ENDPROC(__copy_from_user)
  4767. +ENDPROC(__copy_from_user_std)
  4768. .pushsection .fixup,"ax"
  4769. .align 0
  4770. diff -Nur linux-3.18.6/arch/arm/lib/exports_rpi.c linux-rpi/arch/arm/lib/exports_rpi.c
  4771. --- linux-3.18.6/arch/arm/lib/exports_rpi.c 1970-01-01 01:00:00.000000000 +0100
  4772. +++ linux-rpi/arch/arm/lib/exports_rpi.c 2015-02-09 04:39:42.000000000 +0100
  4773. @@ -0,0 +1,37 @@
  4774. +/**
  4775. + * Copyright (c) 2014, Raspberry Pi (Trading) Ltd.
  4776. + *
  4777. + * Redistribution and use in source and binary forms, with or without
  4778. + * modification, are permitted provided that the following conditions
  4779. + * are met:
  4780. + * 1. Redistributions of source code must retain the above copyright
  4781. + * notice, this list of conditions, and the following disclaimer,
  4782. + * without modification.
  4783. + * 2. Redistributions in binary form must reproduce the above copyright
  4784. + * notice, this list of conditions and the following disclaimer in the
  4785. + * documentation and/or other materials provided with the distribution.
  4786. + * 3. The names of the above-listed copyright holders may not be used
  4787. + * to endorse or promote products derived from this software without
  4788. + * specific prior written permission.
  4789. + *
  4790. + * ALTERNATIVELY, this software may be distributed under the terms of the
  4791. + * GNU General Public License ("GPL") version 2, as published by the Free
  4792. + * Software Foundation.
  4793. + *
  4794. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  4795. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  4796. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  4797. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  4798. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  4799. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  4800. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  4801. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4802. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4803. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  4804. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4805. + */
  4806. +
  4807. +#include <linux/kernel.h>
  4808. +#include <linux/module.h>
  4809. +
  4810. +EXPORT_SYMBOL(memcmp);
  4811. diff -Nur linux-3.18.6/arch/arm/lib/Makefile linux-rpi/arch/arm/lib/Makefile
  4812. --- linux-3.18.6/arch/arm/lib/Makefile 2015-02-06 15:53:48.000000000 +0100
  4813. +++ linux-rpi/arch/arm/lib/Makefile 2015-02-09 04:39:42.000000000 +0100
  4814. @@ -6,15 +6,24 @@
  4815. lib-y := backtrace.o changebit.o csumipv6.o csumpartial.o \
  4816. csumpartialcopy.o csumpartialcopyuser.o clearbit.o \
  4817. - delay.o delay-loop.o findbit.o memchr.o memcpy.o \
  4818. - memmove.o memset.o memzero.o setbit.o \
  4819. - strchr.o strrchr.o \
  4820. + delay.o delay-loop.o findbit.o memchr.o memzero.o \
  4821. + setbit.o strchr.o strrchr.o \
  4822. testchangebit.o testclearbit.o testsetbit.o \
  4823. ashldi3.o ashrdi3.o lshrdi3.o muldi3.o \
  4824. ucmpdi2.o lib1funcs.o div64.o \
  4825. io-readsb.o io-writesb.o io-readsl.o io-writesl.o \
  4826. call_with_stack.o bswapsdi2.o
  4827. +# Choose optimised implementations for Raspberry Pi
  4828. +ifeq ($(CONFIG_MACH_BCM2708),y)
  4829. + CFLAGS_uaccess_with_memcpy.o += -DCOPY_FROM_USER_THRESHOLD=1600
  4830. + CFLAGS_uaccess_with_memcpy.o += -DCOPY_TO_USER_THRESHOLD=672
  4831. + obj-$(CONFIG_MODULES) += exports_rpi.o
  4832. + lib-y += memcpy_rpi.o memmove_rpi.o memset_rpi.o memcmp_rpi.o
  4833. +else
  4834. + lib-y += memcpy.o memmove.o memset.o
  4835. +endif
  4836. +
  4837. mmu-y := clear_user.o copy_page.o getuser.o putuser.o
  4838. # the code in uaccess.S is not preemption safe and
  4839. diff -Nur linux-3.18.6/arch/arm/lib/memcmp_rpi.S linux-rpi/arch/arm/lib/memcmp_rpi.S
  4840. --- linux-3.18.6/arch/arm/lib/memcmp_rpi.S 1970-01-01 01:00:00.000000000 +0100
  4841. +++ linux-rpi/arch/arm/lib/memcmp_rpi.S 2015-02-09 04:39:42.000000000 +0100
  4842. @@ -0,0 +1,285 @@
  4843. +/*
  4844. +Copyright (c) 2013, Raspberry Pi Foundation
  4845. +Copyright (c) 2013, RISC OS Open Ltd
  4846. +All rights reserved.
  4847. +
  4848. +Redistribution and use in source and binary forms, with or without
  4849. +modification, are permitted provided that the following conditions are met:
  4850. + * Redistributions of source code must retain the above copyright
  4851. + notice, this list of conditions and the following disclaimer.
  4852. + * Redistributions in binary form must reproduce the above copyright
  4853. + notice, this list of conditions and the following disclaimer in the
  4854. + documentation and/or other materials provided with the distribution.
  4855. + * Neither the name of the copyright holder nor the
  4856. + names of its contributors may be used to endorse or promote products
  4857. + derived from this software without specific prior written permission.
  4858. +
  4859. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  4860. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  4861. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  4862. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  4863. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  4864. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  4865. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  4866. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  4867. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  4868. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4869. +*/
  4870. +
  4871. +#include <linux/linkage.h>
  4872. +#include "arm-mem.h"
  4873. +
  4874. +/* Prevent the stack from becoming executable */
  4875. +#if defined(__linux__) && defined(__ELF__)
  4876. +.section .note.GNU-stack,"",%progbits
  4877. +#endif
  4878. +
  4879. + .text
  4880. + .arch armv6
  4881. + .object_arch armv4
  4882. + .arm
  4883. + .altmacro
  4884. + .p2align 2
  4885. +
  4886. +.macro memcmp_process_head unaligned
  4887. + .if unaligned
  4888. + ldr DAT0, [S_1], #4
  4889. + ldr DAT1, [S_1], #4
  4890. + ldr DAT2, [S_1], #4
  4891. + ldr DAT3, [S_1], #4
  4892. + .else
  4893. + ldmia S_1!, {DAT0, DAT1, DAT2, DAT3}
  4894. + .endif
  4895. + ldmia S_2!, {DAT4, DAT5, DAT6, DAT7}
  4896. +.endm
  4897. +
  4898. +.macro memcmp_process_tail
  4899. + cmp DAT0, DAT4
  4900. + cmpeq DAT1, DAT5
  4901. + cmpeq DAT2, DAT6
  4902. + cmpeq DAT3, DAT7
  4903. + bne 200f
  4904. +.endm
  4905. +
  4906. +.macro memcmp_leading_31bytes
  4907. + movs DAT0, OFF, lsl #31
  4908. + ldrmib DAT0, [S_1], #1
  4909. + ldrcsh DAT1, [S_1], #2
  4910. + ldrmib DAT4, [S_2], #1
  4911. + ldrcsh DAT5, [S_2], #2
  4912. + movpl DAT0, #0
  4913. + movcc DAT1, #0
  4914. + movpl DAT4, #0
  4915. + movcc DAT5, #0
  4916. + submi N, N, #1
  4917. + subcs N, N, #2
  4918. + cmp DAT0, DAT4
  4919. + cmpeq DAT1, DAT5
  4920. + bne 200f
  4921. + movs DAT0, OFF, lsl #29
  4922. + ldrmi DAT0, [S_1], #4
  4923. + ldrcs DAT1, [S_1], #4
  4924. + ldrcs DAT2, [S_1], #4
  4925. + ldrmi DAT4, [S_2], #4
  4926. + ldmcsia S_2!, {DAT5, DAT6}
  4927. + movpl DAT0, #0
  4928. + movcc DAT1, #0
  4929. + movcc DAT2, #0
  4930. + movpl DAT4, #0
  4931. + movcc DAT5, #0
  4932. + movcc DAT6, #0
  4933. + submi N, N, #4
  4934. + subcs N, N, #8
  4935. + cmp DAT0, DAT4
  4936. + cmpeq DAT1, DAT5
  4937. + cmpeq DAT2, DAT6
  4938. + bne 200f
  4939. + tst OFF, #16
  4940. + beq 105f
  4941. + memcmp_process_head 1
  4942. + sub N, N, #16
  4943. + memcmp_process_tail
  4944. +105:
  4945. +.endm
  4946. +
  4947. +.macro memcmp_trailing_15bytes unaligned
  4948. + movs N, N, lsl #29
  4949. + .if unaligned
  4950. + ldrcs DAT0, [S_1], #4
  4951. + ldrcs DAT1, [S_1], #4
  4952. + .else
  4953. + ldmcsia S_1!, {DAT0, DAT1}
  4954. + .endif
  4955. + ldrmi DAT2, [S_1], #4
  4956. + ldmcsia S_2!, {DAT4, DAT5}
  4957. + ldrmi DAT6, [S_2], #4
  4958. + movcc DAT0, #0
  4959. + movcc DAT1, #0
  4960. + movpl DAT2, #0
  4961. + movcc DAT4, #0
  4962. + movcc DAT5, #0
  4963. + movpl DAT6, #0
  4964. + cmp DAT0, DAT4
  4965. + cmpeq DAT1, DAT5
  4966. + cmpeq DAT2, DAT6
  4967. + bne 200f
  4968. + movs N, N, lsl #2
  4969. + ldrcsh DAT0, [S_1], #2
  4970. + ldrmib DAT1, [S_1]
  4971. + ldrcsh DAT4, [S_2], #2
  4972. + ldrmib DAT5, [S_2]
  4973. + movcc DAT0, #0
  4974. + movpl DAT1, #0
  4975. + movcc DAT4, #0
  4976. + movpl DAT5, #0
  4977. + cmp DAT0, DAT4
  4978. + cmpeq DAT1, DAT5
  4979. + bne 200f
  4980. +.endm
  4981. +
  4982. +.macro memcmp_long_inner_loop unaligned
  4983. +110:
  4984. + memcmp_process_head unaligned
  4985. + pld [S_2, #prefetch_distance*32 + 16]
  4986. + memcmp_process_tail
  4987. + memcmp_process_head unaligned
  4988. + pld [S_1, OFF]
  4989. + memcmp_process_tail
  4990. + subs N, N, #32
  4991. + bhs 110b
  4992. + /* Just before the final (prefetch_distance+1) 32-byte blocks,
  4993. + * deal with final preloads */
  4994. + preload_trailing 0, S_1, N, DAT0
  4995. + preload_trailing 0, S_2, N, DAT0
  4996. + add N, N, #(prefetch_distance+2)*32 - 16
  4997. +120:
  4998. + memcmp_process_head unaligned
  4999. + memcmp_process_tail
  5000. + subs N, N, #16
  5001. + bhs 120b
  5002. + /* Trailing words and bytes */
  5003. + tst N, #15
  5004. + beq 199f
  5005. + memcmp_trailing_15bytes unaligned
  5006. +199: /* Reached end without detecting a difference */
  5007. + mov a1, #0
  5008. + setend le
  5009. + pop {DAT1-DAT6, pc}
  5010. +.endm
  5011. +
  5012. +.macro memcmp_short_inner_loop unaligned
  5013. + subs N, N, #16 /* simplifies inner loop termination */
  5014. + blo 122f
  5015. +120:
  5016. + memcmp_process_head unaligned
  5017. + memcmp_process_tail
  5018. + subs N, N, #16
  5019. + bhs 120b
  5020. +122: /* Trailing words and bytes */
  5021. + tst N, #15
  5022. + beq 199f
  5023. + memcmp_trailing_15bytes unaligned
  5024. +199: /* Reached end without detecting a difference */
  5025. + mov a1, #0
  5026. + setend le
  5027. + pop {DAT1-DAT6, pc}
  5028. +.endm
  5029. +
  5030. +/*
  5031. + * int memcmp(const void *s1, const void *s2, size_t n);
  5032. + * On entry:
  5033. + * a1 = pointer to buffer 1
  5034. + * a2 = pointer to buffer 2
  5035. + * a3 = number of bytes to compare (as unsigned chars)
  5036. + * On exit:
  5037. + * a1 = >0/=0/<0 if s1 >/=/< s2
  5038. + */
  5039. +
  5040. +.set prefetch_distance, 2
  5041. +
  5042. +ENTRY(memcmp)
  5043. + S_1 .req a1
  5044. + S_2 .req a2
  5045. + N .req a3
  5046. + DAT0 .req a4
  5047. + DAT1 .req v1
  5048. + DAT2 .req v2
  5049. + DAT3 .req v3
  5050. + DAT4 .req v4
  5051. + DAT5 .req v5
  5052. + DAT6 .req v6
  5053. + DAT7 .req ip
  5054. + OFF .req lr
  5055. +
  5056. + push {DAT1-DAT6, lr}
  5057. + setend be /* lowest-addressed bytes are most significant */
  5058. +
  5059. + /* To preload ahead as we go, we need at least (prefetch_distance+2) 32-byte blocks */
  5060. + cmp N, #(prefetch_distance+3)*32 - 1
  5061. + blo 170f
  5062. +
  5063. + /* Long case */
  5064. + /* Adjust N so that the decrement instruction can also test for
  5065. + * inner loop termination. We want it to stop when there are
  5066. + * (prefetch_distance+1) complete blocks to go. */
  5067. + sub N, N, #(prefetch_distance+2)*32
  5068. + preload_leading_step1 0, DAT0, S_1
  5069. + preload_leading_step1 0, DAT1, S_2
  5070. + tst S_2, #31
  5071. + beq 154f
  5072. + rsb OFF, S_2, #0 /* no need to AND with 15 here */
  5073. + preload_leading_step2 0, DAT0, S_1, OFF, DAT2
  5074. + preload_leading_step2 0, DAT1, S_2, OFF, DAT2
  5075. + memcmp_leading_31bytes
  5076. +154: /* Second source now cacheline (32-byte) aligned; we have at
  5077. + * least one prefetch to go. */
  5078. + /* Prefetch offset is best selected such that it lies in the
  5079. + * first 8 of each 32 bytes - but it's just as easy to aim for
  5080. + * the first one */
  5081. + and OFF, S_1, #31
  5082. + rsb OFF, OFF, #32*prefetch_distance
  5083. + tst S_1, #3
  5084. + bne 140f
  5085. + memcmp_long_inner_loop 0
  5086. +140: memcmp_long_inner_loop 1
  5087. +
  5088. +170: /* Short case */
  5089. + teq N, #0
  5090. + beq 199f
  5091. + preload_all 0, 0, 0, S_1, N, DAT0, DAT1
  5092. + preload_all 0, 0, 0, S_2, N, DAT0, DAT1
  5093. + tst S_2, #3
  5094. + beq 174f
  5095. +172: subs N, N, #1
  5096. + blo 199f
  5097. + ldrb DAT0, [S_1], #1
  5098. + ldrb DAT4, [S_2], #1
  5099. + cmp DAT0, DAT4
  5100. + bne 200f
  5101. + tst S_2, #3
  5102. + bne 172b
  5103. +174: /* Second source now 4-byte aligned; we have 0 or more bytes to go */
  5104. + tst S_1, #3
  5105. + bne 140f
  5106. + memcmp_short_inner_loop 0
  5107. +140: memcmp_short_inner_loop 1
  5108. +
  5109. +200: /* Difference found: determine sign. */
  5110. + movhi a1, #1
  5111. + movlo a1, #-1
  5112. + setend le
  5113. + pop {DAT1-DAT6, pc}
  5114. +
  5115. + .unreq S_1
  5116. + .unreq S_2
  5117. + .unreq N
  5118. + .unreq DAT0
  5119. + .unreq DAT1
  5120. + .unreq DAT2
  5121. + .unreq DAT3
  5122. + .unreq DAT4
  5123. + .unreq DAT5
  5124. + .unreq DAT6
  5125. + .unreq DAT7
  5126. + .unreq OFF
  5127. +ENDPROC(memcmp)
  5128. diff -Nur linux-3.18.6/arch/arm/lib/memcpymove.h linux-rpi/arch/arm/lib/memcpymove.h
  5129. --- linux-3.18.6/arch/arm/lib/memcpymove.h 1970-01-01 01:00:00.000000000 +0100
  5130. +++ linux-rpi/arch/arm/lib/memcpymove.h 2015-02-09 04:39:42.000000000 +0100
  5131. @@ -0,0 +1,506 @@
  5132. +/*
  5133. +Copyright (c) 2013, Raspberry Pi Foundation
  5134. +Copyright (c) 2013, RISC OS Open Ltd
  5135. +All rights reserved.
  5136. +
  5137. +Redistribution and use in source and binary forms, with or without
  5138. +modification, are permitted provided that the following conditions are met:
  5139. + * Redistributions of source code must retain the above copyright
  5140. + notice, this list of conditions and the following disclaimer.
  5141. + * Redistributions in binary form must reproduce the above copyright
  5142. + notice, this list of conditions and the following disclaimer in the
  5143. + documentation and/or other materials provided with the distribution.
  5144. + * Neither the name of the copyright holder nor the
  5145. + names of its contributors may be used to endorse or promote products
  5146. + derived from this software without specific prior written permission.
  5147. +
  5148. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  5149. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  5150. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  5151. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  5152. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  5153. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  5154. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  5155. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  5156. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  5157. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5158. +*/
  5159. +
  5160. +.macro unaligned_words backwards, align, use_pld, words, r0, r1, r2, r3, r4, r5, r6, r7, r8
  5161. + .if words == 1
  5162. + .if backwards
  5163. + mov r1, r0, lsl #32-align*8
  5164. + ldr r0, [S, #-4]!
  5165. + orr r1, r1, r0, lsr #align*8
  5166. + str r1, [D, #-4]!
  5167. + .else
  5168. + mov r0, r1, lsr #align*8
  5169. + ldr r1, [S, #4]!
  5170. + orr r0, r0, r1, lsl #32-align*8
  5171. + str r0, [D], #4
  5172. + .endif
  5173. + .elseif words == 2
  5174. + .if backwards
  5175. + ldr r1, [S, #-4]!
  5176. + mov r2, r0, lsl #32-align*8
  5177. + ldr r0, [S, #-4]!
  5178. + orr r2, r2, r1, lsr #align*8
  5179. + mov r1, r1, lsl #32-align*8
  5180. + orr r1, r1, r0, lsr #align*8
  5181. + stmdb D!, {r1, r2}
  5182. + .else
  5183. + ldr r1, [S, #4]!
  5184. + mov r0, r2, lsr #align*8
  5185. + ldr r2, [S, #4]!
  5186. + orr r0, r0, r1, lsl #32-align*8
  5187. + mov r1, r1, lsr #align*8
  5188. + orr r1, r1, r2, lsl #32-align*8
  5189. + stmia D!, {r0, r1}
  5190. + .endif
  5191. + .elseif words == 4
  5192. + .if backwards
  5193. + ldmdb S!, {r2, r3}
  5194. + mov r4, r0, lsl #32-align*8
  5195. + ldmdb S!, {r0, r1}
  5196. + orr r4, r4, r3, lsr #align*8
  5197. + mov r3, r3, lsl #32-align*8
  5198. + orr r3, r3, r2, lsr #align*8
  5199. + mov r2, r2, lsl #32-align*8
  5200. + orr r2, r2, r1, lsr #align*8
  5201. + mov r1, r1, lsl #32-align*8
  5202. + orr r1, r1, r0, lsr #align*8
  5203. + stmdb D!, {r1, r2, r3, r4}
  5204. + .else
  5205. + ldmib S!, {r1, r2}
  5206. + mov r0, r4, lsr #align*8
  5207. + ldmib S!, {r3, r4}
  5208. + orr r0, r0, r1, lsl #32-align*8
  5209. + mov r1, r1, lsr #align*8
  5210. + orr r1, r1, r2, lsl #32-align*8
  5211. + mov r2, r2, lsr #align*8
  5212. + orr r2, r2, r3, lsl #32-align*8
  5213. + mov r3, r3, lsr #align*8
  5214. + orr r3, r3, r4, lsl #32-align*8
  5215. + stmia D!, {r0, r1, r2, r3}
  5216. + .endif
  5217. + .elseif words == 8
  5218. + .if backwards
  5219. + ldmdb S!, {r4, r5, r6, r7}
  5220. + mov r8, r0, lsl #32-align*8
  5221. + ldmdb S!, {r0, r1, r2, r3}
  5222. + .if use_pld
  5223. + pld [S, OFF]
  5224. + .endif
  5225. + orr r8, r8, r7, lsr #align*8
  5226. + mov r7, r7, lsl #32-align*8
  5227. + orr r7, r7, r6, lsr #align*8
  5228. + mov r6, r6, lsl #32-align*8
  5229. + orr r6, r6, r5, lsr #align*8
  5230. + mov r5, r5, lsl #32-align*8
  5231. + orr r5, r5, r4, lsr #align*8
  5232. + mov r4, r4, lsl #32-align*8
  5233. + orr r4, r4, r3, lsr #align*8
  5234. + mov r3, r3, lsl #32-align*8
  5235. + orr r3, r3, r2, lsr #align*8
  5236. + mov r2, r2, lsl #32-align*8
  5237. + orr r2, r2, r1, lsr #align*8
  5238. + mov r1, r1, lsl #32-align*8
  5239. + orr r1, r1, r0, lsr #align*8
  5240. + stmdb D!, {r5, r6, r7, r8}
  5241. + stmdb D!, {r1, r2, r3, r4}
  5242. + .else
  5243. + ldmib S!, {r1, r2, r3, r4}
  5244. + mov r0, r8, lsr #align*8
  5245. + ldmib S!, {r5, r6, r7, r8}
  5246. + .if use_pld
  5247. + pld [S, OFF]
  5248. + .endif
  5249. + orr r0, r0, r1, lsl #32-align*8
  5250. + mov r1, r1, lsr #align*8
  5251. + orr r1, r1, r2, lsl #32-align*8
  5252. + mov r2, r2, lsr #align*8
  5253. + orr r2, r2, r3, lsl #32-align*8
  5254. + mov r3, r3, lsr #align*8
  5255. + orr r3, r3, r4, lsl #32-align*8
  5256. + mov r4, r4, lsr #align*8
  5257. + orr r4, r4, r5, lsl #32-align*8
  5258. + mov r5, r5, lsr #align*8
  5259. + orr r5, r5, r6, lsl #32-align*8
  5260. + mov r6, r6, lsr #align*8
  5261. + orr r6, r6, r7, lsl #32-align*8
  5262. + mov r7, r7, lsr #align*8
  5263. + orr r7, r7, r8, lsl #32-align*8
  5264. + stmia D!, {r0, r1, r2, r3}
  5265. + stmia D!, {r4, r5, r6, r7}
  5266. + .endif
  5267. + .endif
  5268. +.endm
  5269. +
  5270. +.macro memcpy_leading_15bytes backwards, align
  5271. + movs DAT1, DAT2, lsl #31
  5272. + sub N, N, DAT2
  5273. + .if backwards
  5274. + ldrmib DAT0, [S, #-1]!
  5275. + ldrcsh DAT1, [S, #-2]!
  5276. + strmib DAT0, [D, #-1]!
  5277. + strcsh DAT1, [D, #-2]!
  5278. + .else
  5279. + ldrmib DAT0, [S], #1
  5280. + ldrcsh DAT1, [S], #2
  5281. + strmib DAT0, [D], #1
  5282. + strcsh DAT1, [D], #2
  5283. + .endif
  5284. + movs DAT1, DAT2, lsl #29
  5285. + .if backwards
  5286. + ldrmi DAT0, [S, #-4]!
  5287. + .if align == 0
  5288. + ldmcsdb S!, {DAT1, DAT2}
  5289. + .else
  5290. + ldrcs DAT2, [S, #-4]!
  5291. + ldrcs DAT1, [S, #-4]!
  5292. + .endif
  5293. + strmi DAT0, [D, #-4]!
  5294. + stmcsdb D!, {DAT1, DAT2}
  5295. + .else
  5296. + ldrmi DAT0, [S], #4
  5297. + .if align == 0
  5298. + ldmcsia S!, {DAT1, DAT2}
  5299. + .else
  5300. + ldrcs DAT1, [S], #4
  5301. + ldrcs DAT2, [S], #4
  5302. + .endif
  5303. + strmi DAT0, [D], #4
  5304. + stmcsia D!, {DAT1, DAT2}
  5305. + .endif
  5306. +.endm
  5307. +
  5308. +.macro memcpy_trailing_15bytes backwards, align
  5309. + movs N, N, lsl #29
  5310. + .if backwards
  5311. + .if align == 0
  5312. + ldmcsdb S!, {DAT0, DAT1}
  5313. + .else
  5314. + ldrcs DAT1, [S, #-4]!
  5315. + ldrcs DAT0, [S, #-4]!
  5316. + .endif
  5317. + ldrmi DAT2, [S, #-4]!
  5318. + stmcsdb D!, {DAT0, DAT1}
  5319. + strmi DAT2, [D, #-4]!
  5320. + .else
  5321. + .if align == 0
  5322. + ldmcsia S!, {DAT0, DAT1}
  5323. + .else
  5324. + ldrcs DAT0, [S], #4
  5325. + ldrcs DAT1, [S], #4
  5326. + .endif
  5327. + ldrmi DAT2, [S], #4
  5328. + stmcsia D!, {DAT0, DAT1}
  5329. + strmi DAT2, [D], #4
  5330. + .endif
  5331. + movs N, N, lsl #2
  5332. + .if backwards
  5333. + ldrcsh DAT0, [S, #-2]!
  5334. + ldrmib DAT1, [S, #-1]
  5335. + strcsh DAT0, [D, #-2]!
  5336. + strmib DAT1, [D, #-1]
  5337. + .else
  5338. + ldrcsh DAT0, [S], #2
  5339. + ldrmib DAT1, [S]
  5340. + strcsh DAT0, [D], #2
  5341. + strmib DAT1, [D]
  5342. + .endif
  5343. +.endm
  5344. +
  5345. +.macro memcpy_long_inner_loop backwards, align
  5346. + .if align != 0
  5347. + .if backwards
  5348. + ldr DAT0, [S, #-align]!
  5349. + .else
  5350. + ldr LAST, [S, #-align]!
  5351. + .endif
  5352. + .endif
  5353. +110:
  5354. + .if align == 0
  5355. + .if backwards
  5356. + ldmdb S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
  5357. + pld [S, OFF]
  5358. + stmdb D!, {DAT4, DAT5, DAT6, LAST}
  5359. + stmdb D!, {DAT0, DAT1, DAT2, DAT3}
  5360. + .else
  5361. + ldmia S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
  5362. + pld [S, OFF]
  5363. + stmia D!, {DAT0, DAT1, DAT2, DAT3}
  5364. + stmia D!, {DAT4, DAT5, DAT6, LAST}
  5365. + .endif
  5366. + .else
  5367. + unaligned_words backwards, align, 1, 8, DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, DAT7, LAST
  5368. + .endif
  5369. + subs N, N, #32
  5370. + bhs 110b
  5371. + /* Just before the final (prefetch_distance+1) 32-byte blocks, deal with final preloads */
  5372. + preload_trailing backwards, S, N, OFF
  5373. + add N, N, #(prefetch_distance+2)*32 - 32
  5374. +120:
  5375. + .if align == 0
  5376. + .if backwards
  5377. + ldmdb S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
  5378. + stmdb D!, {DAT4, DAT5, DAT6, LAST}
  5379. + stmdb D!, {DAT0, DAT1, DAT2, DAT3}
  5380. + .else
  5381. + ldmia S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
  5382. + stmia D!, {DAT0, DAT1, DAT2, DAT3}
  5383. + stmia D!, {DAT4, DAT5, DAT6, LAST}
  5384. + .endif
  5385. + .else
  5386. + unaligned_words backwards, align, 0, 8, DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, DAT7, LAST
  5387. + .endif
  5388. + subs N, N, #32
  5389. + bhs 120b
  5390. + tst N, #16
  5391. + .if align == 0
  5392. + .if backwards
  5393. + ldmnedb S!, {DAT0, DAT1, DAT2, LAST}
  5394. + stmnedb D!, {DAT0, DAT1, DAT2, LAST}
  5395. + .else
  5396. + ldmneia S!, {DAT0, DAT1, DAT2, LAST}
  5397. + stmneia D!, {DAT0, DAT1, DAT2, LAST}
  5398. + .endif
  5399. + .else
  5400. + beq 130f
  5401. + unaligned_words backwards, align, 0, 4, DAT0, DAT1, DAT2, DAT3, LAST
  5402. +130:
  5403. + .endif
  5404. + /* Trailing words and bytes */
  5405. + tst N, #15
  5406. + beq 199f
  5407. + .if align != 0
  5408. + add S, S, #align
  5409. + .endif
  5410. + memcpy_trailing_15bytes backwards, align
  5411. +199:
  5412. + pop {DAT3, DAT4, DAT5, DAT6, DAT7}
  5413. + pop {D, DAT1, DAT2, pc}
  5414. +.endm
  5415. +
  5416. +.macro memcpy_medium_inner_loop backwards, align
  5417. +120:
  5418. + .if backwards
  5419. + .if align == 0
  5420. + ldmdb S!, {DAT0, DAT1, DAT2, LAST}
  5421. + .else
  5422. + ldr LAST, [S, #-4]!
  5423. + ldr DAT2, [S, #-4]!
  5424. + ldr DAT1, [S, #-4]!
  5425. + ldr DAT0, [S, #-4]!
  5426. + .endif
  5427. + stmdb D!, {DAT0, DAT1, DAT2, LAST}
  5428. + .else
  5429. + .if align == 0
  5430. + ldmia S!, {DAT0, DAT1, DAT2, LAST}
  5431. + .else
  5432. + ldr DAT0, [S], #4
  5433. + ldr DAT1, [S], #4
  5434. + ldr DAT2, [S], #4
  5435. + ldr LAST, [S], #4
  5436. + .endif
  5437. + stmia D!, {DAT0, DAT1, DAT2, LAST}
  5438. + .endif
  5439. + subs N, N, #16
  5440. + bhs 120b
  5441. + /* Trailing words and bytes */
  5442. + tst N, #15
  5443. + beq 199f
  5444. + memcpy_trailing_15bytes backwards, align
  5445. +199:
  5446. + pop {D, DAT1, DAT2, pc}
  5447. +.endm
  5448. +
  5449. +.macro memcpy_short_inner_loop backwards, align
  5450. + tst N, #16
  5451. + .if backwards
  5452. + .if align == 0
  5453. + ldmnedb S!, {DAT0, DAT1, DAT2, LAST}
  5454. + .else
  5455. + ldrne LAST, [S, #-4]!
  5456. + ldrne DAT2, [S, #-4]!
  5457. + ldrne DAT1, [S, #-4]!
  5458. + ldrne DAT0, [S, #-4]!
  5459. + .endif
  5460. + stmnedb D!, {DAT0, DAT1, DAT2, LAST}
  5461. + .else
  5462. + .if align == 0
  5463. + ldmneia S!, {DAT0, DAT1, DAT2, LAST}
  5464. + .else
  5465. + ldrne DAT0, [S], #4
  5466. + ldrne DAT1, [S], #4
  5467. + ldrne DAT2, [S], #4
  5468. + ldrne LAST, [S], #4
  5469. + .endif
  5470. + stmneia D!, {DAT0, DAT1, DAT2, LAST}
  5471. + .endif
  5472. + memcpy_trailing_15bytes backwards, align
  5473. +199:
  5474. + pop {D, DAT1, DAT2, pc}
  5475. +.endm
  5476. +
  5477. +.macro memcpy backwards
  5478. + D .req a1
  5479. + S .req a2
  5480. + N .req a3
  5481. + DAT0 .req a4
  5482. + DAT1 .req v1
  5483. + DAT2 .req v2
  5484. + DAT3 .req v3
  5485. + DAT4 .req v4
  5486. + DAT5 .req v5
  5487. + DAT6 .req v6
  5488. + DAT7 .req sl
  5489. + LAST .req ip
  5490. + OFF .req lr
  5491. +
  5492. + .cfi_startproc
  5493. +
  5494. + push {D, DAT1, DAT2, lr}
  5495. +
  5496. + .cfi_def_cfa_offset 16
  5497. + .cfi_rel_offset D, 0
  5498. + .cfi_undefined S
  5499. + .cfi_undefined N
  5500. + .cfi_undefined DAT0
  5501. + .cfi_rel_offset DAT1, 4
  5502. + .cfi_rel_offset DAT2, 8
  5503. + .cfi_undefined LAST
  5504. + .cfi_rel_offset lr, 12
  5505. +
  5506. + .if backwards
  5507. + add D, D, N
  5508. + add S, S, N
  5509. + .endif
  5510. +
  5511. + /* See if we're guaranteed to have at least one 16-byte aligned 16-byte write */
  5512. + cmp N, #31
  5513. + blo 170f
  5514. + /* To preload ahead as we go, we need at least (prefetch_distance+2) 32-byte blocks */
  5515. + cmp N, #(prefetch_distance+3)*32 - 1
  5516. + blo 160f
  5517. +
  5518. + /* Long case */
  5519. + push {DAT3, DAT4, DAT5, DAT6, DAT7}
  5520. +
  5521. + .cfi_def_cfa_offset 36
  5522. + .cfi_rel_offset D, 20
  5523. + .cfi_rel_offset DAT1, 24
  5524. + .cfi_rel_offset DAT2, 28
  5525. + .cfi_rel_offset DAT3, 0
  5526. + .cfi_rel_offset DAT4, 4
  5527. + .cfi_rel_offset DAT5, 8
  5528. + .cfi_rel_offset DAT6, 12
  5529. + .cfi_rel_offset DAT7, 16
  5530. + .cfi_rel_offset lr, 32
  5531. +
  5532. + /* Adjust N so that the decrement instruction can also test for
  5533. + * inner loop termination. We want it to stop when there are
  5534. + * (prefetch_distance+1) complete blocks to go. */
  5535. + sub N, N, #(prefetch_distance+2)*32
  5536. + preload_leading_step1 backwards, DAT0, S
  5537. + .if backwards
  5538. + /* Bug in GAS: it accepts, but mis-assembles the instruction
  5539. + * ands DAT2, D, #60, 2
  5540. + * which sets DAT2 to the number of leading bytes until destination is aligned and also clears C (sets borrow)
  5541. + */
  5542. + .word 0xE210513C
  5543. + beq 154f
  5544. + .else
  5545. + ands DAT2, D, #15
  5546. + beq 154f
  5547. + rsb DAT2, DAT2, #16 /* number of leading bytes until destination aligned */
  5548. + .endif
  5549. + preload_leading_step2 backwards, DAT0, S, DAT2, OFF
  5550. + memcpy_leading_15bytes backwards, 1
  5551. +154: /* Destination now 16-byte aligned; we have at least one prefetch as well as at least one 16-byte output block */
  5552. + /* Prefetch offset is best selected such that it lies in the first 8 of each 32 bytes - but it's just as easy to aim for the first one */
  5553. + .if backwards
  5554. + rsb OFF, S, #3
  5555. + and OFF, OFF, #28
  5556. + sub OFF, OFF, #32*(prefetch_distance+1)
  5557. + .else
  5558. + and OFF, S, #28
  5559. + rsb OFF, OFF, #32*prefetch_distance
  5560. + .endif
  5561. + movs DAT0, S, lsl #31
  5562. + bhi 157f
  5563. + bcs 156f
  5564. + bmi 155f
  5565. + memcpy_long_inner_loop backwards, 0
  5566. +155: memcpy_long_inner_loop backwards, 1
  5567. +156: memcpy_long_inner_loop backwards, 2
  5568. +157: memcpy_long_inner_loop backwards, 3
  5569. +
  5570. + .cfi_def_cfa_offset 16
  5571. + .cfi_rel_offset D, 0
  5572. + .cfi_rel_offset DAT1, 4
  5573. + .cfi_rel_offset DAT2, 8
  5574. + .cfi_same_value DAT3
  5575. + .cfi_same_value DAT4
  5576. + .cfi_same_value DAT5
  5577. + .cfi_same_value DAT6
  5578. + .cfi_same_value DAT7
  5579. + .cfi_rel_offset lr, 12
  5580. +
  5581. +160: /* Medium case */
  5582. + preload_all backwards, 0, 0, S, N, DAT2, OFF
  5583. + sub N, N, #16 /* simplifies inner loop termination */
  5584. + .if backwards
  5585. + ands DAT2, D, #15
  5586. + beq 164f
  5587. + .else
  5588. + ands DAT2, D, #15
  5589. + beq 164f
  5590. + rsb DAT2, DAT2, #16
  5591. + .endif
  5592. + memcpy_leading_15bytes backwards, align
  5593. +164: /* Destination now 16-byte aligned; we have at least one 16-byte output block */
  5594. + tst S, #3
  5595. + bne 140f
  5596. + memcpy_medium_inner_loop backwards, 0
  5597. +140: memcpy_medium_inner_loop backwards, 1
  5598. +
  5599. +170: /* Short case, less than 31 bytes, so no guarantee of at least one 16-byte block */
  5600. + teq N, #0
  5601. + beq 199f
  5602. + preload_all backwards, 1, 0, S, N, DAT2, LAST
  5603. + tst D, #3
  5604. + beq 174f
  5605. +172: subs N, N, #1
  5606. + blo 199f
  5607. + .if backwards
  5608. + ldrb DAT0, [S, #-1]!
  5609. + strb DAT0, [D, #-1]!
  5610. + .else
  5611. + ldrb DAT0, [S], #1
  5612. + strb DAT0, [D], #1
  5613. + .endif
  5614. + tst D, #3
  5615. + bne 172b
  5616. +174: /* Destination now 4-byte aligned; we have 0 or more output bytes to go */
  5617. + tst S, #3
  5618. + bne 140f
  5619. + memcpy_short_inner_loop backwards, 0
  5620. +140: memcpy_short_inner_loop backwards, 1
  5621. +
  5622. + .cfi_endproc
  5623. +
  5624. + .unreq D
  5625. + .unreq S
  5626. + .unreq N
  5627. + .unreq DAT0
  5628. + .unreq DAT1
  5629. + .unreq DAT2
  5630. + .unreq DAT3
  5631. + .unreq DAT4
  5632. + .unreq DAT5
  5633. + .unreq DAT6
  5634. + .unreq DAT7
  5635. + .unreq LAST
  5636. + .unreq OFF
  5637. +.endm
  5638. diff -Nur linux-3.18.6/arch/arm/lib/memcpy_rpi.S linux-rpi/arch/arm/lib/memcpy_rpi.S
  5639. --- linux-3.18.6/arch/arm/lib/memcpy_rpi.S 1970-01-01 01:00:00.000000000 +0100
  5640. +++ linux-rpi/arch/arm/lib/memcpy_rpi.S 2015-02-09 04:39:42.000000000 +0100
  5641. @@ -0,0 +1,59 @@
  5642. +/*
  5643. +Copyright (c) 2013, Raspberry Pi Foundation
  5644. +Copyright (c) 2013, RISC OS Open Ltd
  5645. +All rights reserved.
  5646. +
  5647. +Redistribution and use in source and binary forms, with or without
  5648. +modification, are permitted provided that the following conditions are met:
  5649. + * Redistributions of source code must retain the above copyright
  5650. + notice, this list of conditions and the following disclaimer.
  5651. + * Redistributions in binary form must reproduce the above copyright
  5652. + notice, this list of conditions and the following disclaimer in the
  5653. + documentation and/or other materials provided with the distribution.
  5654. + * Neither the name of the copyright holder nor the
  5655. + names of its contributors may be used to endorse or promote products
  5656. + derived from this software without specific prior written permission.
  5657. +
  5658. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  5659. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  5660. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  5661. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  5662. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  5663. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  5664. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  5665. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  5666. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  5667. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5668. +*/
  5669. +
  5670. +#include <linux/linkage.h>
  5671. +#include "arm-mem.h"
  5672. +#include "memcpymove.h"
  5673. +
  5674. +/* Prevent the stack from becoming executable */
  5675. +#if defined(__linux__) && defined(__ELF__)
  5676. +.section .note.GNU-stack,"",%progbits
  5677. +#endif
  5678. +
  5679. + .text
  5680. + .arch armv6
  5681. + .object_arch armv4
  5682. + .arm
  5683. + .altmacro
  5684. + .p2align 2
  5685. +
  5686. +/*
  5687. + * void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
  5688. + * On entry:
  5689. + * a1 = pointer to destination
  5690. + * a2 = pointer to source
  5691. + * a3 = number of bytes to copy
  5692. + * On exit:
  5693. + * a1 preserved
  5694. + */
  5695. +
  5696. +.set prefetch_distance, 3
  5697. +
  5698. +ENTRY(memcpy)
  5699. + memcpy 0
  5700. +ENDPROC(memcpy)
  5701. diff -Nur linux-3.18.6/arch/arm/lib/memmove_rpi.S linux-rpi/arch/arm/lib/memmove_rpi.S
  5702. --- linux-3.18.6/arch/arm/lib/memmove_rpi.S 1970-01-01 01:00:00.000000000 +0100
  5703. +++ linux-rpi/arch/arm/lib/memmove_rpi.S 2015-02-09 04:39:42.000000000 +0100
  5704. @@ -0,0 +1,61 @@
  5705. +/*
  5706. +Copyright (c) 2013, Raspberry Pi Foundation
  5707. +Copyright (c) 2013, RISC OS Open Ltd
  5708. +All rights reserved.
  5709. +
  5710. +Redistribution and use in source and binary forms, with or without
  5711. +modification, are permitted provided that the following conditions are met:
  5712. + * Redistributions of source code must retain the above copyright
  5713. + notice, this list of conditions and the following disclaimer.
  5714. + * Redistributions in binary form must reproduce the above copyright
  5715. + notice, this list of conditions and the following disclaimer in the
  5716. + documentation and/or other materials provided with the distribution.
  5717. + * Neither the name of the copyright holder nor the
  5718. + names of its contributors may be used to endorse or promote products
  5719. + derived from this software without specific prior written permission.
  5720. +
  5721. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  5722. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  5723. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  5724. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  5725. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  5726. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  5727. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  5728. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  5729. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  5730. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5731. +*/
  5732. +
  5733. +#include <linux/linkage.h>
  5734. +#include "arm-mem.h"
  5735. +#include "memcpymove.h"
  5736. +
  5737. +/* Prevent the stack from becoming executable */
  5738. +#if defined(__linux__) && defined(__ELF__)
  5739. +.section .note.GNU-stack,"",%progbits
  5740. +#endif
  5741. +
  5742. + .text
  5743. + .arch armv6
  5744. + .object_arch armv4
  5745. + .arm
  5746. + .altmacro
  5747. + .p2align 2
  5748. +
  5749. +/*
  5750. + * void *memmove(void *s1, const void *s2, size_t n);
  5751. + * On entry:
  5752. + * a1 = pointer to destination
  5753. + * a2 = pointer to source
  5754. + * a3 = number of bytes to copy
  5755. + * On exit:
  5756. + * a1 preserved
  5757. + */
  5758. +
  5759. +.set prefetch_distance, 3
  5760. +
  5761. +ENTRY(memmove)
  5762. + cmp a2, a1
  5763. + bpl memcpy /* pl works even over -1 - 0 and 0x7fffffff - 0x80000000 boundaries */
  5764. + memcpy 1
  5765. +ENDPROC(memmove)
  5766. diff -Nur linux-3.18.6/arch/arm/lib/memset_rpi.S linux-rpi/arch/arm/lib/memset_rpi.S
  5767. --- linux-3.18.6/arch/arm/lib/memset_rpi.S 1970-01-01 01:00:00.000000000 +0100
  5768. +++ linux-rpi/arch/arm/lib/memset_rpi.S 2015-02-09 04:39:42.000000000 +0100
  5769. @@ -0,0 +1,121 @@
  5770. +/*
  5771. +Copyright (c) 2013, Raspberry Pi Foundation
  5772. +Copyright (c) 2013, RISC OS Open Ltd
  5773. +All rights reserved.
  5774. +
  5775. +Redistribution and use in source and binary forms, with or without
  5776. +modification, are permitted provided that the following conditions are met:
  5777. + * Redistributions of source code must retain the above copyright
  5778. + notice, this list of conditions and the following disclaimer.
  5779. + * Redistributions in binary form must reproduce the above copyright
  5780. + notice, this list of conditions and the following disclaimer in the
  5781. + documentation and/or other materials provided with the distribution.
  5782. + * Neither the name of the copyright holder nor the
  5783. + names of its contributors may be used to endorse or promote products
  5784. + derived from this software without specific prior written permission.
  5785. +
  5786. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  5787. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  5788. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  5789. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  5790. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  5791. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  5792. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  5793. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  5794. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  5795. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5796. +*/
  5797. +
  5798. +#include <linux/linkage.h>
  5799. +#include "arm-mem.h"
  5800. +
  5801. +/* Prevent the stack from becoming executable */
  5802. +#if defined(__linux__) && defined(__ELF__)
  5803. +.section .note.GNU-stack,"",%progbits
  5804. +#endif
  5805. +
  5806. + .text
  5807. + .arch armv6
  5808. + .object_arch armv4
  5809. + .arm
  5810. + .altmacro
  5811. + .p2align 2
  5812. +
  5813. +/*
  5814. + * void *memset(void *s, int c, size_t n);
  5815. + * On entry:
  5816. + * a1 = pointer to buffer to fill
  5817. + * a2 = byte pattern to fill with (caller-narrowed)
  5818. + * a3 = number of bytes to fill
  5819. + * On exit:
  5820. + * a1 preserved
  5821. + */
  5822. +ENTRY(memset)
  5823. + S .req a1
  5824. + DAT0 .req a2
  5825. + N .req a3
  5826. + DAT1 .req a4
  5827. + DAT2 .req ip
  5828. + DAT3 .req lr
  5829. +
  5830. + orr DAT0, DAT0, lsl #8
  5831. + push {S, lr}
  5832. + orr DAT0, DAT0, lsl #16
  5833. + mov DAT1, DAT0
  5834. +
  5835. + /* See if we're guaranteed to have at least one 16-byte aligned 16-byte write */
  5836. + cmp N, #31
  5837. + blo 170f
  5838. +
  5839. +161: sub N, N, #16 /* simplifies inner loop termination */
  5840. + /* Leading words and bytes */
  5841. + tst S, #15
  5842. + beq 164f
  5843. + rsb DAT3, S, #0 /* bits 0-3 = number of leading bytes until aligned */
  5844. + movs DAT2, DAT3, lsl #31
  5845. + submi N, N, #1
  5846. + strmib DAT0, [S], #1
  5847. + subcs N, N, #2
  5848. + strcsh DAT0, [S], #2
  5849. + movs DAT2, DAT3, lsl #29
  5850. + submi N, N, #4
  5851. + strmi DAT0, [S], #4
  5852. + subcs N, N, #8
  5853. + stmcsia S!, {DAT0, DAT1}
  5854. +164: /* Delayed set up of DAT2 and DAT3 so we could use them as scratch registers above */
  5855. + mov DAT2, DAT0
  5856. + mov DAT3, DAT0
  5857. + /* Now the inner loop of 16-byte stores */
  5858. +165: stmia S!, {DAT0, DAT1, DAT2, DAT3}
  5859. + subs N, N, #16
  5860. + bhs 165b
  5861. +166: /* Trailing words and bytes */
  5862. + movs N, N, lsl #29
  5863. + stmcsia S!, {DAT0, DAT1}
  5864. + strmi DAT0, [S], #4
  5865. + movs N, N, lsl #2
  5866. + strcsh DAT0, [S], #2
  5867. + strmib DAT0, [S]
  5868. +199: pop {S, pc}
  5869. +
  5870. +170: /* Short case */
  5871. + mov DAT2, DAT0
  5872. + mov DAT3, DAT0
  5873. + tst S, #3
  5874. + beq 174f
  5875. +172: subs N, N, #1
  5876. + blo 199b
  5877. + strb DAT0, [S], #1
  5878. + tst S, #3
  5879. + bne 172b
  5880. +174: tst N, #16
  5881. + stmneia S!, {DAT0, DAT1, DAT2, DAT3}
  5882. + b 166b
  5883. +
  5884. + .unreq S
  5885. + .unreq DAT0
  5886. + .unreq N
  5887. + .unreq DAT1
  5888. + .unreq DAT2
  5889. + .unreq DAT3
  5890. +ENDPROC(memset)
  5891. diff -Nur linux-3.18.6/arch/arm/lib/uaccess_with_memcpy.c linux-rpi/arch/arm/lib/uaccess_with_memcpy.c
  5892. --- linux-3.18.6/arch/arm/lib/uaccess_with_memcpy.c 2015-02-06 15:53:48.000000000 +0100
  5893. +++ linux-rpi/arch/arm/lib/uaccess_with_memcpy.c 2015-02-09 04:39:42.000000000 +0100
  5894. @@ -22,6 +22,14 @@
  5895. #include <asm/current.h>
  5896. #include <asm/page.h>
  5897. +#ifndef COPY_FROM_USER_THRESHOLD
  5898. +#define COPY_FROM_USER_THRESHOLD 64
  5899. +#endif
  5900. +
  5901. +#ifndef COPY_TO_USER_THRESHOLD
  5902. +#define COPY_TO_USER_THRESHOLD 64
  5903. +#endif
  5904. +
  5905. static int
  5906. pin_page_for_write(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp)
  5907. {
  5908. @@ -85,7 +93,44 @@
  5909. return 1;
  5910. }
  5911. -static unsigned long noinline
  5912. +static int
  5913. +pin_page_for_read(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp)
  5914. +{
  5915. + unsigned long addr = (unsigned long)_addr;
  5916. + pgd_t *pgd;
  5917. + pmd_t *pmd;
  5918. + pte_t *pte;
  5919. + pud_t *pud;
  5920. + spinlock_t *ptl;
  5921. +
  5922. + pgd = pgd_offset(current->mm, addr);
  5923. + if (unlikely(pgd_none(*pgd) || pgd_bad(*pgd)))
  5924. + {
  5925. + return 0;
  5926. + }
  5927. + pud = pud_offset(pgd, addr);
  5928. + if (unlikely(pud_none(*pud) || pud_bad(*pud)))
  5929. + {
  5930. + return 0;
  5931. + }
  5932. +
  5933. + pmd = pmd_offset(pud, addr);
  5934. + if (unlikely(pmd_none(*pmd) || pmd_bad(*pmd)))
  5935. + return 0;
  5936. +
  5937. + pte = pte_offset_map_lock(current->mm, pmd, addr, &ptl);
  5938. + if (unlikely(!pte_present(*pte) || !pte_young(*pte))) {
  5939. + pte_unmap_unlock(pte, ptl);
  5940. + return 0;
  5941. + }
  5942. +
  5943. + *ptep = pte;
  5944. + *ptlp = ptl;
  5945. +
  5946. + return 1;
  5947. +}
  5948. +
  5949. +unsigned long noinline
  5950. __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n)
  5951. {
  5952. int atomic;
  5953. @@ -135,6 +180,54 @@
  5954. return n;
  5955. }
  5956. +unsigned long noinline
  5957. +__copy_from_user_memcpy(void *to, const void __user *from, unsigned long n)
  5958. +{
  5959. + int atomic;
  5960. +
  5961. + if (unlikely(segment_eq(get_fs(), KERNEL_DS))) {
  5962. + memcpy(to, (const void *)from, n);
  5963. + return 0;
  5964. + }
  5965. +
  5966. + /* the mmap semaphore is taken only if not in an atomic context */
  5967. + atomic = in_atomic();
  5968. +
  5969. + if (!atomic)
  5970. + down_read(&current->mm->mmap_sem);
  5971. + while (n) {
  5972. + pte_t *pte;
  5973. + spinlock_t *ptl;
  5974. + int tocopy;
  5975. +
  5976. + while (!pin_page_for_read(from, &pte, &ptl)) {
  5977. + char temp;
  5978. + if (!atomic)
  5979. + up_read(&current->mm->mmap_sem);
  5980. + if (__get_user(temp, (char __user *)from))
  5981. + goto out;
  5982. + if (!atomic)
  5983. + down_read(&current->mm->mmap_sem);
  5984. + }
  5985. +
  5986. + tocopy = (~(unsigned long)from & ~PAGE_MASK) + 1;
  5987. + if (tocopy > n)
  5988. + tocopy = n;
  5989. +
  5990. + memcpy(to, (const void *)from, tocopy);
  5991. + to += tocopy;
  5992. + from += tocopy;
  5993. + n -= tocopy;
  5994. +
  5995. + pte_unmap_unlock(pte, ptl);
  5996. + }
  5997. + if (!atomic)
  5998. + up_read(&current->mm->mmap_sem);
  5999. +
  6000. +out:
  6001. + return n;
  6002. +}
  6003. +
  6004. unsigned long
  6005. __copy_to_user(void __user *to, const void *from, unsigned long n)
  6006. {
  6007. @@ -145,10 +238,25 @@
  6008. * With frame pointer disabled, tail call optimization kicks in
  6009. * as well making this test almost invisible.
  6010. */
  6011. - if (n < 64)
  6012. + if (n < COPY_TO_USER_THRESHOLD)
  6013. return __copy_to_user_std(to, from, n);
  6014. return __copy_to_user_memcpy(to, from, n);
  6015. }
  6016. +
  6017. +unsigned long
  6018. +__copy_from_user(void *to, const void __user *from, unsigned long n)
  6019. +{
  6020. + /*
  6021. + * This test is stubbed out of the main function above to keep
  6022. + * the overhead for small copies low by avoiding a large
  6023. + * register dump on the stack just to reload them right away.
  6024. + * With frame pointer disabled, tail call optimization kicks in
  6025. + * as well making this test almost invisible.
  6026. + */
  6027. + if (n < COPY_FROM_USER_THRESHOLD)
  6028. + return __copy_from_user_std(to, from, n);
  6029. + return __copy_from_user_memcpy(to, from, n);
  6030. +}
  6031. static unsigned long noinline
  6032. __clear_user_memset(void __user *addr, unsigned long n)
  6033. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/armctrl.c linux-rpi/arch/arm/mach-bcm2708/armctrl.c
  6034. --- linux-3.18.6/arch/arm/mach-bcm2708/armctrl.c 1970-01-01 01:00:00.000000000 +0100
  6035. +++ linux-rpi/arch/arm/mach-bcm2708/armctrl.c 2015-02-09 04:39:42.000000000 +0100
  6036. @@ -0,0 +1,315 @@
  6037. +/*
  6038. + * linux/arch/arm/mach-bcm2708/armctrl.c
  6039. + *
  6040. + * Copyright (C) 2010 Broadcom
  6041. + *
  6042. + * This program is free software; you can redistribute it and/or modify
  6043. + * it under the terms of the GNU General Public License as published by
  6044. + * the Free Software Foundation; either version 2 of the License, or
  6045. + * (at your option) any later version.
  6046. + *
  6047. + * This program is distributed in the hope that it will be useful,
  6048. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6049. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6050. + * GNU General Public License for more details.
  6051. + *
  6052. + * You should have received a copy of the GNU General Public License
  6053. + * along with this program; if not, write to the Free Software
  6054. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6055. + */
  6056. +#include <linux/init.h>
  6057. +#include <linux/list.h>
  6058. +#include <linux/io.h>
  6059. +#include <linux/version.h>
  6060. +#include <linux/syscore_ops.h>
  6061. +#include <linux/interrupt.h>
  6062. +#include <linux/irqdomain.h>
  6063. +#include <linux/of.h>
  6064. +
  6065. +#include <asm/mach/irq.h>
  6066. +#include <mach/hardware.h>
  6067. +#include "armctrl.h"
  6068. +
  6069. +/* For support of kernels >= 3.0 assume only one VIC for now*/
  6070. +static unsigned int remap_irqs[(INTERRUPT_ARASANSDIO + 1) - INTERRUPT_JPEG] = {
  6071. + INTERRUPT_VC_JPEG,
  6072. + INTERRUPT_VC_USB,
  6073. + INTERRUPT_VC_3D,
  6074. + INTERRUPT_VC_DMA2,
  6075. + INTERRUPT_VC_DMA3,
  6076. + INTERRUPT_VC_I2C,
  6077. + INTERRUPT_VC_SPI,
  6078. + INTERRUPT_VC_I2SPCM,
  6079. + INTERRUPT_VC_SDIO,
  6080. + INTERRUPT_VC_UART,
  6081. + INTERRUPT_VC_ARASANSDIO
  6082. +};
  6083. +
  6084. +static void armctrl_mask_irq(struct irq_data *d)
  6085. +{
  6086. + static const unsigned int disables[4] = {
  6087. + ARM_IRQ_DIBL1,
  6088. + ARM_IRQ_DIBL2,
  6089. + ARM_IRQ_DIBL3,
  6090. + 0
  6091. + };
  6092. +
  6093. + if (d->irq >= FIQ_START) {
  6094. + writel(0, __io_address(ARM_IRQ_FAST));
  6095. + } else {
  6096. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  6097. + writel(1 << (data & 0x1f), __io_address(disables[(data >> 5) & 0x3]));
  6098. + }
  6099. +}
  6100. +
  6101. +static void armctrl_unmask_irq(struct irq_data *d)
  6102. +{
  6103. + static const unsigned int enables[4] = {
  6104. + ARM_IRQ_ENBL1,
  6105. + ARM_IRQ_ENBL2,
  6106. + ARM_IRQ_ENBL3,
  6107. + 0
  6108. + };
  6109. +
  6110. + if (d->irq >= FIQ_START) {
  6111. + unsigned int data =
  6112. + (unsigned int)irq_get_chip_data(d->irq) - FIQ_START;
  6113. + writel(0x80 | data, __io_address(ARM_IRQ_FAST));
  6114. + } else {
  6115. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  6116. + writel(1 << (data & 0x1f), __io_address(enables[(data >> 5) & 0x3]));
  6117. + }
  6118. +}
  6119. +
  6120. +#ifdef CONFIG_OF
  6121. +
  6122. +#define NR_IRQS_BANK0 21
  6123. +#define NR_BANKS 3
  6124. +#define IRQS_PER_BANK 32
  6125. +
  6126. +/* from drivers/irqchip/irq-bcm2835.c */
  6127. +static int armctrl_xlate(struct irq_domain *d, struct device_node *ctrlr,
  6128. + const u32 *intspec, unsigned int intsize,
  6129. + unsigned long *out_hwirq, unsigned int *out_type)
  6130. +{
  6131. + if (WARN_ON(intsize != 2))
  6132. + return -EINVAL;
  6133. +
  6134. + if (WARN_ON(intspec[0] >= NR_BANKS))
  6135. + return -EINVAL;
  6136. +
  6137. + if (WARN_ON(intspec[1] >= IRQS_PER_BANK))
  6138. + return -EINVAL;
  6139. +
  6140. + if (WARN_ON(intspec[0] == 0 && intspec[1] >= NR_IRQS_BANK0))
  6141. + return -EINVAL;
  6142. +
  6143. + if (intspec[0] == 0)
  6144. + *out_hwirq = ARM_IRQ0_BASE + intspec[1];
  6145. + else if (intspec[0] == 1)
  6146. + *out_hwirq = ARM_IRQ1_BASE + intspec[1];
  6147. + else
  6148. + *out_hwirq = ARM_IRQ2_BASE + intspec[1];
  6149. +
  6150. + /* reverse remap_irqs[] */
  6151. + switch (*out_hwirq) {
  6152. + case INTERRUPT_VC_JPEG:
  6153. + *out_hwirq = INTERRUPT_JPEG;
  6154. + break;
  6155. + case INTERRUPT_VC_USB:
  6156. + *out_hwirq = INTERRUPT_USB;
  6157. + break;
  6158. + case INTERRUPT_VC_3D:
  6159. + *out_hwirq = INTERRUPT_3D;
  6160. + break;
  6161. + case INTERRUPT_VC_DMA2:
  6162. + *out_hwirq = INTERRUPT_DMA2;
  6163. + break;
  6164. + case INTERRUPT_VC_DMA3:
  6165. + *out_hwirq = INTERRUPT_DMA3;
  6166. + break;
  6167. + case INTERRUPT_VC_I2C:
  6168. + *out_hwirq = INTERRUPT_I2C;
  6169. + break;
  6170. + case INTERRUPT_VC_SPI:
  6171. + *out_hwirq = INTERRUPT_SPI;
  6172. + break;
  6173. + case INTERRUPT_VC_I2SPCM:
  6174. + *out_hwirq = INTERRUPT_I2SPCM;
  6175. + break;
  6176. + case INTERRUPT_VC_SDIO:
  6177. + *out_hwirq = INTERRUPT_SDIO;
  6178. + break;
  6179. + case INTERRUPT_VC_UART:
  6180. + *out_hwirq = INTERRUPT_UART;
  6181. + break;
  6182. + case INTERRUPT_VC_ARASANSDIO:
  6183. + *out_hwirq = INTERRUPT_ARASANSDIO;
  6184. + break;
  6185. + }
  6186. +
  6187. + *out_type = IRQ_TYPE_NONE;
  6188. + return 0;
  6189. +}
  6190. +
  6191. +static struct irq_domain_ops armctrl_ops = {
  6192. + .xlate = armctrl_xlate
  6193. +};
  6194. +
  6195. +void __init armctrl_dt_init(void)
  6196. +{
  6197. + struct device_node *np;
  6198. + struct irq_domain *domain;
  6199. +
  6200. + np = of_find_compatible_node(NULL, NULL, "brcm,bcm2708-armctrl-ic");
  6201. + if (!np)
  6202. + return;
  6203. +
  6204. + domain = irq_domain_add_legacy(np, BCM2708_ALLOC_IRQS,
  6205. + IRQ_ARMCTRL_START, 0,
  6206. + &armctrl_ops, NULL);
  6207. + WARN_ON(!domain);
  6208. +}
  6209. +#else
  6210. +void __init armctrl_dt_init(void) { }
  6211. +#endif /* CONFIG_OF */
  6212. +
  6213. +#if defined(CONFIG_PM)
  6214. +
  6215. +/* for kernels 3.xx use the new syscore_ops apis but for older kernels use the sys dev class */
  6216. +
  6217. +/* Static defines
  6218. + * struct armctrl_device - VIC PM device (< 3.xx)
  6219. + * @sysdev: The system device which is registered. (< 3.xx)
  6220. + * @irq: The IRQ number for the base of the VIC.
  6221. + * @base: The register base for the VIC.
  6222. + * @resume_sources: A bitmask of interrupts for resume.
  6223. + * @resume_irqs: The IRQs enabled for resume.
  6224. + * @int_select: Save for VIC_INT_SELECT.
  6225. + * @int_enable: Save for VIC_INT_ENABLE.
  6226. + * @soft_int: Save for VIC_INT_SOFT.
  6227. + * @protect: Save for VIC_PROTECT.
  6228. + */
  6229. +struct armctrl_info {
  6230. + void __iomem *base;
  6231. + int irq;
  6232. + u32 resume_sources;
  6233. + u32 resume_irqs;
  6234. + u32 int_select;
  6235. + u32 int_enable;
  6236. + u32 soft_int;
  6237. + u32 protect;
  6238. +} armctrl;
  6239. +
  6240. +static int armctrl_suspend(void)
  6241. +{
  6242. + return 0;
  6243. +}
  6244. +
  6245. +static void armctrl_resume(void)
  6246. +{
  6247. + return;
  6248. +}
  6249. +
  6250. +/**
  6251. + * armctrl_pm_register - Register a VIC for later power management control
  6252. + * @base: The base address of the VIC.
  6253. + * @irq: The base IRQ for the VIC.
  6254. + * @resume_sources: bitmask of interrupts allowed for resume sources.
  6255. + *
  6256. + * For older kernels (< 3.xx) do -
  6257. + * Register the VIC with the system device tree so that it can be notified
  6258. + * of suspend and resume requests and ensure that the correct actions are
  6259. + * taken to re-instate the settings on resume.
  6260. + */
  6261. +static void __init armctrl_pm_register(void __iomem * base, unsigned int irq,
  6262. + u32 resume_sources)
  6263. +{
  6264. + armctrl.base = base;
  6265. + armctrl.resume_sources = resume_sources;
  6266. + armctrl.irq = irq;
  6267. +}
  6268. +
  6269. +static int armctrl_set_wake(struct irq_data *d, unsigned int on)
  6270. +{
  6271. + unsigned int off = d->irq & 31;
  6272. + u32 bit = 1 << off;
  6273. +
  6274. + if (!(bit & armctrl.resume_sources))
  6275. + return -EINVAL;
  6276. +
  6277. + if (on)
  6278. + armctrl.resume_irqs |= bit;
  6279. + else
  6280. + armctrl.resume_irqs &= ~bit;
  6281. +
  6282. + return 0;
  6283. +}
  6284. +
  6285. +#else
  6286. +static inline void armctrl_pm_register(void __iomem * base, unsigned int irq,
  6287. + u32 arg1)
  6288. +{
  6289. +}
  6290. +
  6291. +#define armctrl_suspend NULL
  6292. +#define armctrl_resume NULL
  6293. +#define armctrl_set_wake NULL
  6294. +#endif /* CONFIG_PM */
  6295. +
  6296. +static struct syscore_ops armctrl_syscore_ops = {
  6297. + .suspend = armctrl_suspend,
  6298. + .resume = armctrl_resume,
  6299. +};
  6300. +
  6301. +/**
  6302. + * armctrl_syscore_init - initicall to register VIC pm functions
  6303. + *
  6304. + * This is called via late_initcall() to register
  6305. + * the resources for the VICs due to the early
  6306. + * nature of the VIC's registration.
  6307. +*/
  6308. +static int __init armctrl_syscore_init(void)
  6309. +{
  6310. + register_syscore_ops(&armctrl_syscore_ops);
  6311. + return 0;
  6312. +}
  6313. +
  6314. +late_initcall(armctrl_syscore_init);
  6315. +
  6316. +static struct irq_chip armctrl_chip = {
  6317. + .name = "ARMCTRL",
  6318. + .irq_ack = NULL,
  6319. + .irq_mask = armctrl_mask_irq,
  6320. + .irq_unmask = armctrl_unmask_irq,
  6321. + .irq_set_wake = armctrl_set_wake,
  6322. +};
  6323. +
  6324. +/**
  6325. + * armctrl_init - initialise a vectored interrupt controller
  6326. + * @base: iomem base address
  6327. + * @irq_start: starting interrupt number, must be muliple of 32
  6328. + * @armctrl_sources: bitmask of interrupt sources to allow
  6329. + * @resume_sources: bitmask of interrupt sources to allow for resume
  6330. + */
  6331. +int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  6332. + u32 armctrl_sources, u32 resume_sources)
  6333. +{
  6334. + unsigned int irq;
  6335. +
  6336. + for (irq = 0; irq < BCM2708_ALLOC_IRQS; irq++) {
  6337. + unsigned int data = irq;
  6338. + if (irq >= INTERRUPT_JPEG && irq <= INTERRUPT_ARASANSDIO)
  6339. + data = remap_irqs[irq - INTERRUPT_JPEG];
  6340. +
  6341. + irq_set_chip(irq, &armctrl_chip);
  6342. + irq_set_chip_data(irq, (void *)data);
  6343. + irq_set_handler(irq, handle_level_irq);
  6344. + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_DISABLED);
  6345. + }
  6346. +
  6347. + armctrl_pm_register(base, irq_start, resume_sources);
  6348. + init_FIQ(FIQ_START);
  6349. + armctrl_dt_init();
  6350. + return 0;
  6351. +}
  6352. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/armctrl.h linux-rpi/arch/arm/mach-bcm2708/armctrl.h
  6353. --- linux-3.18.6/arch/arm/mach-bcm2708/armctrl.h 1970-01-01 01:00:00.000000000 +0100
  6354. +++ linux-rpi/arch/arm/mach-bcm2708/armctrl.h 2015-02-09 04:39:42.000000000 +0100
  6355. @@ -0,0 +1,27 @@
  6356. +/*
  6357. + * linux/arch/arm/mach-bcm2708/armctrl.h
  6358. + *
  6359. + * Copyright (C) 2010 Broadcom
  6360. + *
  6361. + * This program is free software; you can redistribute it and/or modify
  6362. + * it under the terms of the GNU General Public License as published by
  6363. + * the Free Software Foundation; either version 2 of the License, or
  6364. + * (at your option) any later version.
  6365. + *
  6366. + * This program is distributed in the hope that it will be useful,
  6367. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6368. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6369. + * GNU General Public License for more details.
  6370. + *
  6371. + * You should have received a copy of the GNU General Public License
  6372. + * along with this program; if not, write to the Free Software
  6373. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6374. + */
  6375. +
  6376. +#ifndef __BCM2708_ARMCTRL_H
  6377. +#define __BCM2708_ARMCTRL_H
  6378. +
  6379. +extern int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  6380. + u32 armctrl_sources, u32 resume_sources);
  6381. +
  6382. +#endif
  6383. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/bcm2708.c linux-rpi/arch/arm/mach-bcm2708/bcm2708.c
  6384. --- linux-3.18.6/arch/arm/mach-bcm2708/bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  6385. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708.c 2015-02-09 04:39:42.000000000 +0100
  6386. @@ -0,0 +1,1132 @@
  6387. +/*
  6388. + * linux/arch/arm/mach-bcm2708/bcm2708.c
  6389. + *
  6390. + * Copyright (C) 2010 Broadcom
  6391. + *
  6392. + * This program is free software; you can redistribute it and/or modify
  6393. + * it under the terms of the GNU General Public License as published by
  6394. + * the Free Software Foundation; either version 2 of the License, or
  6395. + * (at your option) any later version.
  6396. + *
  6397. + * This program is distributed in the hope that it will be useful,
  6398. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6399. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6400. + * GNU General Public License for more details.
  6401. + *
  6402. + * You should have received a copy of the GNU General Public License
  6403. + * along with this program; if not, write to the Free Software
  6404. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6405. + */
  6406. +
  6407. +#include <linux/init.h>
  6408. +#include <linux/device.h>
  6409. +#include <linux/dma-mapping.h>
  6410. +#include <linux/serial_8250.h>
  6411. +#include <linux/platform_device.h>
  6412. +#include <linux/syscore_ops.h>
  6413. +#include <linux/interrupt.h>
  6414. +#include <linux/amba/bus.h>
  6415. +#include <linux/amba/clcd.h>
  6416. +#include <linux/clk-provider.h>
  6417. +#include <linux/clkdev.h>
  6418. +#include <linux/clockchips.h>
  6419. +#include <linux/cnt32_to_63.h>
  6420. +#include <linux/io.h>
  6421. +#include <linux/module.h>
  6422. +#include <linux/of_platform.h>
  6423. +#include <linux/spi/spi.h>
  6424. +#include <linux/gpio/machine.h>
  6425. +#include <linux/w1-gpio.h>
  6426. +#include <linux/pps-gpio.h>
  6427. +
  6428. +#include <linux/version.h>
  6429. +#include <linux/clkdev.h>
  6430. +#include <asm/system_info.h>
  6431. +#include <mach/hardware.h>
  6432. +#include <asm/irq.h>
  6433. +#include <linux/leds.h>
  6434. +#include <asm/mach-types.h>
  6435. +#include <linux/sched_clock.h>
  6436. +
  6437. +#include <asm/mach/arch.h>
  6438. +#include <asm/mach/flash.h>
  6439. +#include <asm/mach/irq.h>
  6440. +#include <asm/mach/time.h>
  6441. +#include <asm/mach/map.h>
  6442. +
  6443. +#include <mach/timex.h>
  6444. +#include <mach/dma.h>
  6445. +#include <mach/vcio.h>
  6446. +#include <mach/system.h>
  6447. +
  6448. +#include <linux/delay.h>
  6449. +
  6450. +#include "bcm2708.h"
  6451. +#include "armctrl.h"
  6452. +
  6453. +#ifdef CONFIG_BCM_VC_CMA
  6454. +#include <linux/broadcom/vc_cma.h>
  6455. +#endif
  6456. +
  6457. +
  6458. +/* Effectively we have an IOMMU (ARM<->VideoCore map) that is set up to
  6459. + * give us IO access only to 64Mbytes of physical memory (26 bits). We could
  6460. + * represent this window by setting our dmamasks to 26 bits but, in fact
  6461. + * we're not going to use addresses outside this range (they're not in real
  6462. + * memory) so we don't bother.
  6463. + *
  6464. + * In the future we might include code to use this IOMMU to remap other
  6465. + * physical addresses onto VideoCore memory then the use of 32-bits would be
  6466. + * more legitimate.
  6467. + */
  6468. +#define DMA_MASK_BITS_COMMON 32
  6469. +
  6470. +// use GPIO 4 for the one-wire GPIO pin, if enabled
  6471. +#define W1_GPIO 4
  6472. +// ensure one-wire GPIO pullup is disabled by default
  6473. +#define W1_PULLUP -1
  6474. +
  6475. +/* command line parameters */
  6476. +static unsigned boardrev, serial;
  6477. +static unsigned uart_clock = UART0_CLOCK;
  6478. +static unsigned disk_led_gpio = 16;
  6479. +static unsigned disk_led_active_low = 1;
  6480. +static unsigned reboot_part = 0;
  6481. +static unsigned w1_gpio_pin = W1_GPIO;
  6482. +static unsigned w1_gpio_pullup = W1_PULLUP;
  6483. +static int pps_gpio_pin = -1;
  6484. +static bool vc_i2c_override = false;
  6485. +
  6486. +static unsigned use_dt = 0;
  6487. +
  6488. +static void __init bcm2708_init_led(void);
  6489. +
  6490. +void __init bcm2708_init_irq(void)
  6491. +{
  6492. + armctrl_init(__io_address(ARMCTRL_IC_BASE), 0, 0, 0);
  6493. +}
  6494. +
  6495. +static struct map_desc bcm2708_io_desc[] __initdata = {
  6496. + {
  6497. + .virtual = IO_ADDRESS(ARMCTRL_BASE),
  6498. + .pfn = __phys_to_pfn(ARMCTRL_BASE),
  6499. + .length = SZ_4K,
  6500. + .type = MT_DEVICE},
  6501. + {
  6502. + .virtual = IO_ADDRESS(UART0_BASE),
  6503. + .pfn = __phys_to_pfn(UART0_BASE),
  6504. + .length = SZ_4K,
  6505. + .type = MT_DEVICE},
  6506. + {
  6507. + .virtual = IO_ADDRESS(UART1_BASE),
  6508. + .pfn = __phys_to_pfn(UART1_BASE),
  6509. + .length = SZ_4K,
  6510. + .type = MT_DEVICE},
  6511. + {
  6512. + .virtual = IO_ADDRESS(DMA_BASE),
  6513. + .pfn = __phys_to_pfn(DMA_BASE),
  6514. + .length = SZ_4K,
  6515. + .type = MT_DEVICE},
  6516. + {
  6517. + .virtual = IO_ADDRESS(MCORE_BASE),
  6518. + .pfn = __phys_to_pfn(MCORE_BASE),
  6519. + .length = SZ_4K,
  6520. + .type = MT_DEVICE},
  6521. + {
  6522. + .virtual = IO_ADDRESS(ST_BASE),
  6523. + .pfn = __phys_to_pfn(ST_BASE),
  6524. + .length = SZ_4K,
  6525. + .type = MT_DEVICE},
  6526. + {
  6527. + .virtual = IO_ADDRESS(USB_BASE),
  6528. + .pfn = __phys_to_pfn(USB_BASE),
  6529. + .length = SZ_128K,
  6530. + .type = MT_DEVICE},
  6531. + {
  6532. + .virtual = IO_ADDRESS(PM_BASE),
  6533. + .pfn = __phys_to_pfn(PM_BASE),
  6534. + .length = SZ_4K,
  6535. + .type = MT_DEVICE},
  6536. + {
  6537. + .virtual = IO_ADDRESS(GPIO_BASE),
  6538. + .pfn = __phys_to_pfn(GPIO_BASE),
  6539. + .length = SZ_4K,
  6540. + .type = MT_DEVICE}
  6541. +};
  6542. +
  6543. +void __init bcm2708_map_io(void)
  6544. +{
  6545. + iotable_init(bcm2708_io_desc, ARRAY_SIZE(bcm2708_io_desc));
  6546. +}
  6547. +
  6548. +/* The STC is a free running counter that increments at the rate of 1MHz */
  6549. +#define STC_FREQ_HZ 1000000
  6550. +
  6551. +static inline uint32_t timer_read(void)
  6552. +{
  6553. + /* STC: a free running counter that increments at the rate of 1MHz */
  6554. + return readl(__io_address(ST_BASE + 0x04));
  6555. +}
  6556. +
  6557. +static unsigned long bcm2708_read_current_timer(void)
  6558. +{
  6559. + return timer_read();
  6560. +}
  6561. +
  6562. +static u64 notrace bcm2708_read_sched_clock(void)
  6563. +{
  6564. + return timer_read();
  6565. +}
  6566. +
  6567. +static cycle_t clksrc_read(struct clocksource *cs)
  6568. +{
  6569. + return timer_read();
  6570. +}
  6571. +
  6572. +static struct clocksource clocksource_stc = {
  6573. + .name = "stc",
  6574. + .rating = 300,
  6575. + .read = clksrc_read,
  6576. + .mask = CLOCKSOURCE_MASK(32),
  6577. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  6578. +};
  6579. +
  6580. +unsigned long frc_clock_ticks32(void)
  6581. +{
  6582. + return timer_read();
  6583. +}
  6584. +
  6585. +static void __init bcm2708_clocksource_init(void)
  6586. +{
  6587. + if (clocksource_register_hz(&clocksource_stc, STC_FREQ_HZ)) {
  6588. + printk(KERN_ERR "timer: failed to initialize clock "
  6589. + "source %s\n", clocksource_stc.name);
  6590. + }
  6591. +}
  6592. +
  6593. +struct clk __init *bcm2708_clk_register(const char *name, unsigned long fixed_rate)
  6594. +{
  6595. + struct clk *clk;
  6596. +
  6597. + clk = clk_register_fixed_rate(NULL, name, NULL, CLK_IS_ROOT,
  6598. + fixed_rate);
  6599. + if (IS_ERR(clk))
  6600. + pr_err("%s not registered\n", name);
  6601. +
  6602. + return clk;
  6603. +}
  6604. +
  6605. +void __init bcm2708_register_clkdev(struct clk *clk, const char *name)
  6606. +{
  6607. + int ret;
  6608. +
  6609. + ret = clk_register_clkdev(clk, NULL, name);
  6610. + if (ret)
  6611. + pr_err("%s alias not registered\n", name);
  6612. +}
  6613. +
  6614. +void __init bcm2708_init_clocks(void)
  6615. +{
  6616. + struct clk *clk;
  6617. +
  6618. + clk = bcm2708_clk_register("uart0_clk", uart_clock);
  6619. + bcm2708_register_clkdev(clk, "dev:f1");
  6620. +
  6621. + clk = bcm2708_clk_register("sdhost_clk", 250000000);
  6622. + bcm2708_register_clkdev(clk, "bcm2708_spi.0");
  6623. + bcm2708_register_clkdev(clk, "bcm2708_i2c.0");
  6624. + bcm2708_register_clkdev(clk, "bcm2708_i2c.1");
  6625. +}
  6626. +
  6627. +#define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
  6628. +#define UART0_DMA { 15, 14 }
  6629. +
  6630. +AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  6631. +
  6632. +static struct amba_device *amba_devs[] __initdata = {
  6633. + &uart0_device,
  6634. +};
  6635. +
  6636. +static struct resource bcm2708_dmaman_resources[] = {
  6637. + {
  6638. + .start = DMA_BASE,
  6639. + .end = DMA_BASE + SZ_4K - 1,
  6640. + .flags = IORESOURCE_MEM,
  6641. + }
  6642. +};
  6643. +
  6644. +static struct platform_device bcm2708_dmaman_device = {
  6645. + .name = BCM_DMAMAN_DRIVER_NAME,
  6646. + .id = 0, /* first bcm2708_dma */
  6647. + .resource = bcm2708_dmaman_resources,
  6648. + .num_resources = ARRAY_SIZE(bcm2708_dmaman_resources),
  6649. +};
  6650. +
  6651. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  6652. +static struct w1_gpio_platform_data w1_gpio_pdata = {
  6653. + .pin = W1_GPIO,
  6654. + .ext_pullup_enable_pin = W1_PULLUP,
  6655. + .is_open_drain = 0,
  6656. +};
  6657. +
  6658. +static struct platform_device w1_device = {
  6659. + .name = "w1-gpio",
  6660. + .id = -1,
  6661. + .dev.platform_data = &w1_gpio_pdata,
  6662. +};
  6663. +#endif
  6664. +
  6665. +static struct pps_gpio_platform_data pps_gpio_info = {
  6666. + .assert_falling_edge = false,
  6667. + .capture_clear = false,
  6668. + .gpio_pin = -1,
  6669. + .gpio_label = "PPS",
  6670. +};
  6671. +
  6672. +static struct platform_device pps_gpio_device = {
  6673. + .name = "pps-gpio",
  6674. + .id = PLATFORM_DEVID_NONE,
  6675. + .dev.platform_data = &pps_gpio_info,
  6676. +};
  6677. +
  6678. +static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  6679. +
  6680. +static struct platform_device bcm2708_fb_device = {
  6681. + .name = "bcm2708_fb",
  6682. + .id = -1, /* only one bcm2708_fb */
  6683. + .resource = NULL,
  6684. + .num_resources = 0,
  6685. + .dev = {
  6686. + .dma_mask = &fb_dmamask,
  6687. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  6688. + },
  6689. +};
  6690. +
  6691. +static struct plat_serial8250_port bcm2708_uart1_platform_data[] = {
  6692. + {
  6693. + .mapbase = UART1_BASE + 0x40,
  6694. + .irq = IRQ_AUX,
  6695. + .uartclk = 125000000,
  6696. + .regshift = 2,
  6697. + .iotype = UPIO_MEM,
  6698. + .flags = UPF_FIXED_TYPE | UPF_IOREMAP | UPF_SKIP_TEST,
  6699. + .type = PORT_8250,
  6700. + },
  6701. + {},
  6702. +};
  6703. +
  6704. +static struct platform_device bcm2708_uart1_device = {
  6705. + .name = "serial8250",
  6706. + .id = PLAT8250_DEV_PLATFORM,
  6707. + .dev = {
  6708. + .platform_data = bcm2708_uart1_platform_data,
  6709. + },
  6710. +};
  6711. +
  6712. +static struct resource bcm2708_usb_resources[] = {
  6713. + [0] = {
  6714. + .start = USB_BASE,
  6715. + .end = USB_BASE + SZ_128K - 1,
  6716. + .flags = IORESOURCE_MEM,
  6717. + },
  6718. + [1] = {
  6719. + .start = MPHI_BASE,
  6720. + .end = MPHI_BASE + SZ_4K - 1,
  6721. + .flags = IORESOURCE_MEM,
  6722. + },
  6723. + [2] = {
  6724. + .start = IRQ_HOSTPORT,
  6725. + .end = IRQ_HOSTPORT,
  6726. + .flags = IORESOURCE_IRQ,
  6727. + },
  6728. + [3] = {
  6729. + .start = IRQ_USB,
  6730. + .end = IRQ_USB,
  6731. + .flags = IORESOURCE_IRQ,
  6732. + },
  6733. +};
  6734. +
  6735. +
  6736. +static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  6737. +
  6738. +static struct platform_device bcm2708_usb_device = {
  6739. + .name = "bcm2708_usb",
  6740. + .id = -1, /* only one bcm2708_usb */
  6741. + .resource = bcm2708_usb_resources,
  6742. + .num_resources = ARRAY_SIZE(bcm2708_usb_resources),
  6743. + .dev = {
  6744. + .dma_mask = &usb_dmamask,
  6745. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  6746. + },
  6747. +};
  6748. +
  6749. +static struct resource bcm2708_vcio_resources[] = {
  6750. + [0] = { /* mailbox/semaphore/doorbell access */
  6751. + .start = MCORE_BASE,
  6752. + .end = MCORE_BASE + SZ_4K - 1,
  6753. + .flags = IORESOURCE_MEM,
  6754. + },
  6755. +};
  6756. +
  6757. +static u64 vcio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  6758. +
  6759. +static struct platform_device bcm2708_vcio_device = {
  6760. + .name = BCM_VCIO_DRIVER_NAME,
  6761. + .id = -1, /* only one VideoCore I/O area */
  6762. + .resource = bcm2708_vcio_resources,
  6763. + .num_resources = ARRAY_SIZE(bcm2708_vcio_resources),
  6764. + .dev = {
  6765. + .dma_mask = &vcio_dmamask,
  6766. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  6767. + },
  6768. +};
  6769. +
  6770. +#ifdef CONFIG_BCM2708_GPIO
  6771. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  6772. +
  6773. +static struct resource bcm2708_gpio_resources[] = {
  6774. + [0] = { /* general purpose I/O */
  6775. + .start = GPIO_BASE,
  6776. + .end = GPIO_BASE + SZ_4K - 1,
  6777. + .flags = IORESOURCE_MEM,
  6778. + },
  6779. +};
  6780. +
  6781. +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  6782. +
  6783. +static struct platform_device bcm2708_gpio_device = {
  6784. + .name = BCM_GPIO_DRIVER_NAME,
  6785. + .id = -1, /* only one VideoCore I/O area */
  6786. + .resource = bcm2708_gpio_resources,
  6787. + .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
  6788. + .dev = {
  6789. + .dma_mask = &gpio_dmamask,
  6790. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  6791. + },
  6792. +};
  6793. +#endif
  6794. +
  6795. +static struct resource bcm2708_systemtimer_resources[] = {
  6796. + [0] = { /* system timer access */
  6797. + .start = ST_BASE,
  6798. + .end = ST_BASE + SZ_4K - 1,
  6799. + .flags = IORESOURCE_MEM,
  6800. + },
  6801. + {
  6802. + .start = IRQ_TIMER3,
  6803. + .end = IRQ_TIMER3,
  6804. + .flags = IORESOURCE_IRQ,
  6805. + }
  6806. +
  6807. +};
  6808. +
  6809. +static u64 systemtimer_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  6810. +
  6811. +static struct platform_device bcm2708_systemtimer_device = {
  6812. + .name = "bcm2708_systemtimer",
  6813. + .id = -1, /* only one VideoCore I/O area */
  6814. + .resource = bcm2708_systemtimer_resources,
  6815. + .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
  6816. + .dev = {
  6817. + .dma_mask = &systemtimer_dmamask,
  6818. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  6819. + },
  6820. +};
  6821. +
  6822. +#ifdef CONFIG_MMC_BCM2835 /* Arasan emmc SD (new) */
  6823. +static struct resource bcm2835_emmc_resources[] = {
  6824. + [0] = {
  6825. + .start = EMMC_BASE,
  6826. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  6827. + /* the memory map actually makes SZ_4K available */
  6828. + .flags = IORESOURCE_MEM,
  6829. + },
  6830. + [1] = {
  6831. + .start = IRQ_ARASANSDIO,
  6832. + .end = IRQ_ARASANSDIO,
  6833. + .flags = IORESOURCE_IRQ,
  6834. + },
  6835. +};
  6836. +
  6837. +static u64 bcm2835_emmc_dmamask = 0xffffffffUL;
  6838. +
  6839. +struct platform_device bcm2835_emmc_device = {
  6840. + .name = "mmc-bcm2835",
  6841. + .id = 0,
  6842. + .num_resources = ARRAY_SIZE(bcm2835_emmc_resources),
  6843. + .resource = bcm2835_emmc_resources,
  6844. + .dev = {
  6845. + .dma_mask = &bcm2835_emmc_dmamask,
  6846. + .coherent_dma_mask = 0xffffffffUL},
  6847. +};
  6848. +#endif /* CONFIG_MMC_BCM2835 */
  6849. +
  6850. +static struct resource bcm2708_powerman_resources[] = {
  6851. + [0] = {
  6852. + .start = PM_BASE,
  6853. + .end = PM_BASE + SZ_256 - 1,
  6854. + .flags = IORESOURCE_MEM,
  6855. + },
  6856. +};
  6857. +
  6858. +static u64 powerman_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  6859. +
  6860. +struct platform_device bcm2708_powerman_device = {
  6861. + .name = "bcm2708_powerman",
  6862. + .id = 0,
  6863. + .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
  6864. + .resource = bcm2708_powerman_resources,
  6865. + .dev = {
  6866. + .dma_mask = &powerman_dmamask,
  6867. + .coherent_dma_mask = 0xffffffffUL},
  6868. +};
  6869. +
  6870. +
  6871. +static struct platform_device bcm2708_alsa_devices[] = {
  6872. + [0] = {
  6873. + .name = "bcm2835_AUD0",
  6874. + .id = 0, /* first audio device */
  6875. + .resource = 0,
  6876. + .num_resources = 0,
  6877. + },
  6878. + [1] = {
  6879. + .name = "bcm2835_AUD1",
  6880. + .id = 1, /* second audio device */
  6881. + .resource = 0,
  6882. + .num_resources = 0,
  6883. + },
  6884. + [2] = {
  6885. + .name = "bcm2835_AUD2",
  6886. + .id = 2, /* third audio device */
  6887. + .resource = 0,
  6888. + .num_resources = 0,
  6889. + },
  6890. + [3] = {
  6891. + .name = "bcm2835_AUD3",
  6892. + .id = 3, /* forth audio device */
  6893. + .resource = 0,
  6894. + .num_resources = 0,
  6895. + },
  6896. + [4] = {
  6897. + .name = "bcm2835_AUD4",
  6898. + .id = 4, /* fifth audio device */
  6899. + .resource = 0,
  6900. + .num_resources = 0,
  6901. + },
  6902. + [5] = {
  6903. + .name = "bcm2835_AUD5",
  6904. + .id = 5, /* sixth audio device */
  6905. + .resource = 0,
  6906. + .num_resources = 0,
  6907. + },
  6908. + [6] = {
  6909. + .name = "bcm2835_AUD6",
  6910. + .id = 6, /* seventh audio device */
  6911. + .resource = 0,
  6912. + .num_resources = 0,
  6913. + },
  6914. + [7] = {
  6915. + .name = "bcm2835_AUD7",
  6916. + .id = 7, /* eighth audio device */
  6917. + .resource = 0,
  6918. + .num_resources = 0,
  6919. + },
  6920. +};
  6921. +
  6922. +static struct resource bcm2708_spi_resources[] = {
  6923. + {
  6924. + .start = SPI0_BASE,
  6925. + .end = SPI0_BASE + SZ_256 - 1,
  6926. + .flags = IORESOURCE_MEM,
  6927. + }, {
  6928. + .start = IRQ_SPI,
  6929. + .end = IRQ_SPI,
  6930. + .flags = IORESOURCE_IRQ,
  6931. + }
  6932. +};
  6933. +
  6934. +
  6935. +static u64 bcm2708_spi_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  6936. +static struct platform_device bcm2708_spi_device = {
  6937. + .name = "bcm2708_spi",
  6938. + .id = 0,
  6939. + .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
  6940. + .resource = bcm2708_spi_resources,
  6941. + .dev = {
  6942. + .dma_mask = &bcm2708_spi_dmamask,
  6943. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
  6944. +};
  6945. +
  6946. +#ifdef CONFIG_BCM2708_SPIDEV
  6947. +static struct spi_board_info bcm2708_spi_devices[] = {
  6948. +#ifdef CONFIG_SPI_SPIDEV
  6949. + {
  6950. + .modalias = "spidev",
  6951. + .max_speed_hz = 500000,
  6952. + .bus_num = 0,
  6953. + .chip_select = 0,
  6954. + .mode = SPI_MODE_0,
  6955. + }, {
  6956. + .modalias = "spidev",
  6957. + .max_speed_hz = 500000,
  6958. + .bus_num = 0,
  6959. + .chip_select = 1,
  6960. + .mode = SPI_MODE_0,
  6961. + }
  6962. +#endif
  6963. +};
  6964. +#endif
  6965. +
  6966. +static struct resource bcm2708_bsc0_resources[] = {
  6967. + {
  6968. + .start = BSC0_BASE,
  6969. + .end = BSC0_BASE + SZ_256 - 1,
  6970. + .flags = IORESOURCE_MEM,
  6971. + }, {
  6972. + .start = INTERRUPT_I2C,
  6973. + .end = INTERRUPT_I2C,
  6974. + .flags = IORESOURCE_IRQ,
  6975. + }
  6976. +};
  6977. +
  6978. +static struct platform_device bcm2708_bsc0_device = {
  6979. + .name = "bcm2708_i2c",
  6980. + .id = 0,
  6981. + .num_resources = ARRAY_SIZE(bcm2708_bsc0_resources),
  6982. + .resource = bcm2708_bsc0_resources,
  6983. +};
  6984. +
  6985. +
  6986. +static struct resource bcm2708_bsc1_resources[] = {
  6987. + {
  6988. + .start = BSC1_BASE,
  6989. + .end = BSC1_BASE + SZ_256 - 1,
  6990. + .flags = IORESOURCE_MEM,
  6991. + }, {
  6992. + .start = INTERRUPT_I2C,
  6993. + .end = INTERRUPT_I2C,
  6994. + .flags = IORESOURCE_IRQ,
  6995. + }
  6996. +};
  6997. +
  6998. +static struct platform_device bcm2708_bsc1_device = {
  6999. + .name = "bcm2708_i2c",
  7000. + .id = 1,
  7001. + .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  7002. + .resource = bcm2708_bsc1_resources,
  7003. +};
  7004. +
  7005. +static struct platform_device bcm2835_hwmon_device = {
  7006. + .name = "bcm2835_hwmon",
  7007. +};
  7008. +
  7009. +static struct platform_device bcm2835_thermal_device = {
  7010. + .name = "bcm2835_thermal",
  7011. +};
  7012. +
  7013. +#if defined(CONFIG_SND_BCM2708_SOC_I2S) || defined(CONFIG_SND_BCM2708_SOC_I2S_MODULE)
  7014. +static struct resource bcm2708_i2s_resources[] = {
  7015. + {
  7016. + .start = I2S_BASE,
  7017. + .end = I2S_BASE + 0x20,
  7018. + .flags = IORESOURCE_MEM,
  7019. + },
  7020. + {
  7021. + .start = PCM_CLOCK_BASE,
  7022. + .end = PCM_CLOCK_BASE + 0x02,
  7023. + .flags = IORESOURCE_MEM,
  7024. + }
  7025. +};
  7026. +
  7027. +static struct platform_device bcm2708_i2s_device = {
  7028. + .name = "bcm2708-i2s",
  7029. + .id = 0,
  7030. + .num_resources = ARRAY_SIZE(bcm2708_i2s_resources),
  7031. + .resource = bcm2708_i2s_resources,
  7032. +};
  7033. +#endif
  7034. +
  7035. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  7036. +static struct platform_device snd_hifiberry_dac_device = {
  7037. + .name = "snd-hifiberry-dac",
  7038. + .id = 0,
  7039. + .num_resources = 0,
  7040. +};
  7041. +
  7042. +static struct platform_device snd_pcm5102a_codec_device = {
  7043. + .name = "pcm5102a-codec",
  7044. + .id = -1,
  7045. + .num_resources = 0,
  7046. +};
  7047. +#endif
  7048. +
  7049. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
  7050. +static struct platform_device snd_rpi_hifiberry_dacplus_device = {
  7051. + .name = "snd-rpi-hifiberry-dacplus",
  7052. + .id = 0,
  7053. + .num_resources = 0,
  7054. +};
  7055. +
  7056. +static struct i2c_board_info __initdata snd_pcm512x_hbdacplus_i2c_devices[] = {
  7057. + {
  7058. + I2C_BOARD_INFO("pcm5122", 0x4d)
  7059. + },
  7060. +};
  7061. +#endif
  7062. +
  7063. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  7064. +static struct platform_device snd_hifiberry_digi_device = {
  7065. + .name = "snd-hifiberry-digi",
  7066. + .id = 0,
  7067. + .num_resources = 0,
  7068. +};
  7069. +
  7070. +static struct i2c_board_info __initdata snd_wm8804_i2c_devices[] = {
  7071. + {
  7072. + I2C_BOARD_INFO("wm8804", 0x3b)
  7073. + },
  7074. +};
  7075. +
  7076. +#endif
  7077. +
  7078. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
  7079. +static struct platform_device snd_hifiberry_amp_device = {
  7080. + .name = "snd-hifiberry-amp",
  7081. + .id = 0,
  7082. + .num_resources = 0,
  7083. +};
  7084. +
  7085. +static struct i2c_board_info __initdata snd_tas5713_i2c_devices[] = {
  7086. + {
  7087. + I2C_BOARD_INFO("tas5713", 0x1b)
  7088. + },
  7089. +};
  7090. +#endif
  7091. +
  7092. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  7093. +static struct platform_device snd_rpi_dac_device = {
  7094. + .name = "snd-rpi-dac",
  7095. + .id = 0,
  7096. + .num_resources = 0,
  7097. +};
  7098. +
  7099. +static struct platform_device snd_pcm1794a_codec_device = {
  7100. + .name = "pcm1794a-codec",
  7101. + .id = -1,
  7102. + .num_resources = 0,
  7103. +};
  7104. +#endif
  7105. +
  7106. +
  7107. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  7108. +static struct platform_device snd_rpi_iqaudio_dac_device = {
  7109. + .name = "snd-rpi-iqaudio-dac",
  7110. + .id = 0,
  7111. + .num_resources = 0,
  7112. +};
  7113. +
  7114. +// Use the actual device name rather than generic driver name
  7115. +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
  7116. + {
  7117. + I2C_BOARD_INFO("pcm5122", 0x4c)
  7118. + },
  7119. +};
  7120. +#endif
  7121. +
  7122. +int __init bcm_register_device(struct platform_device *pdev)
  7123. +{
  7124. + int ret;
  7125. +
  7126. + ret = platform_device_register(pdev);
  7127. + if (ret)
  7128. + pr_debug("Unable to register platform device '%s': %d\n",
  7129. + pdev->name, ret);
  7130. +
  7131. + return ret;
  7132. +}
  7133. +
  7134. +/*
  7135. + * Use these macros for platform and i2c devices that are present in the
  7136. + * Device Tree. This way the devices are only added on non-DT systems.
  7137. + */
  7138. +#define bcm_register_device_dt(pdev) \
  7139. + if (!use_dt) bcm_register_device(pdev)
  7140. +
  7141. +#define i2c_register_board_info_dt(busnum, info, n) \
  7142. + if (!use_dt) i2c_register_board_info(busnum, info, n)
  7143. +
  7144. +int calc_rsts(int partition)
  7145. +{
  7146. + return PM_PASSWORD |
  7147. + ((partition & (1 << 0)) << 0) |
  7148. + ((partition & (1 << 1)) << 1) |
  7149. + ((partition & (1 << 2)) << 2) |
  7150. + ((partition & (1 << 3)) << 3) |
  7151. + ((partition & (1 << 4)) << 4) |
  7152. + ((partition & (1 << 5)) << 5);
  7153. +}
  7154. +
  7155. +static void bcm2708_restart(enum reboot_mode mode, const char *cmd)
  7156. +{
  7157. + extern char bcm2708_reboot_mode;
  7158. + uint32_t pm_rstc, pm_wdog;
  7159. + uint32_t timeout = 10;
  7160. + uint32_t pm_rsts = 0;
  7161. +
  7162. + if(bcm2708_reboot_mode == 'q')
  7163. + {
  7164. + // NOOBS < 1.3 booting with reboot=q
  7165. + pm_rsts = readl(__io_address(PM_RSTS));
  7166. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRQ_SET;
  7167. + }
  7168. + else if(bcm2708_reboot_mode == 'p')
  7169. + {
  7170. + // NOOBS < 1.3 halting
  7171. + pm_rsts = readl(__io_address(PM_RSTS));
  7172. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRH_SET;
  7173. + }
  7174. + else
  7175. + {
  7176. + pm_rsts = calc_rsts(reboot_part);
  7177. + }
  7178. +
  7179. + writel(pm_rsts, __io_address(PM_RSTS));
  7180. +
  7181. + /* Setup watchdog for reset */
  7182. + pm_rstc = readl(__io_address(PM_RSTC));
  7183. +
  7184. + pm_wdog = PM_PASSWORD | (timeout & PM_WDOG_TIME_SET); // watchdog timer = timer clock / 16; need password (31:16) + value (11:0)
  7185. + pm_rstc = PM_PASSWORD | (pm_rstc & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
  7186. +
  7187. + writel(pm_wdog, __io_address(PM_WDOG));
  7188. + writel(pm_rstc, __io_address(PM_RSTC));
  7189. +}
  7190. +
  7191. +/* 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 */
  7192. +static void bcm2708_power_off(void)
  7193. +{
  7194. + extern char bcm2708_reboot_mode;
  7195. + if(bcm2708_reboot_mode == 'q')
  7196. + {
  7197. + // NOOBS < v1.3
  7198. + bcm2708_restart('p', "");
  7199. + }
  7200. + else
  7201. + {
  7202. + /* partition 63 is special code for HALT the bootloader knows not to boot*/
  7203. + reboot_part = 63;
  7204. + /* continue with normal reset mechanism */
  7205. + bcm2708_restart(0, "");
  7206. + }
  7207. +}
  7208. +
  7209. +#ifdef CONFIG_OF
  7210. +static void __init bcm2708_dt_init(void)
  7211. +{
  7212. + int ret;
  7213. +
  7214. + of_clk_init(NULL);
  7215. + ret = of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  7216. + if (ret) {
  7217. + pr_err("of_platform_populate failed: %d\n", ret);
  7218. + /* Proceed as if CONFIG_OF was not defined */
  7219. + } else {
  7220. + use_dt = 1;
  7221. + }
  7222. +}
  7223. +#else
  7224. +static void __init bcm2708_dt_init(void) { }
  7225. +#endif /* CONFIG_OF */
  7226. +
  7227. +void __init bcm2708_init(void)
  7228. +{
  7229. + int i;
  7230. +
  7231. +#if defined(CONFIG_BCM_VC_CMA)
  7232. + vc_cma_early_init();
  7233. +#endif
  7234. + printk("bcm2708.uart_clock = %d\n", uart_clock);
  7235. + pm_power_off = bcm2708_power_off;
  7236. +
  7237. + bcm2708_init_clocks();
  7238. + bcm2708_dt_init();
  7239. +
  7240. + bcm_register_device(&bcm2708_dmaman_device);
  7241. + bcm_register_device(&bcm2708_vcio_device);
  7242. +#ifdef CONFIG_BCM2708_GPIO
  7243. + bcm_register_device_dt(&bcm2708_gpio_device);
  7244. +#endif
  7245. +
  7246. +#if defined(CONFIG_PPS_CLIENT_GPIO) || defined(CONFIG_PPS_CLIENT_GPIO_MODULE)
  7247. + if (!use_dt && (pps_gpio_pin >= 0)) {
  7248. + pr_info("bcm2708: GPIO %d setup as pps-gpio device\n", pps_gpio_pin);
  7249. + pps_gpio_info.gpio_pin = pps_gpio_pin;
  7250. + pps_gpio_device.id = pps_gpio_pin;
  7251. + bcm_register_device(&pps_gpio_device);
  7252. + }
  7253. +#endif
  7254. +
  7255. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  7256. + w1_gpio_pdata.pin = w1_gpio_pin;
  7257. + w1_gpio_pdata.ext_pullup_enable_pin = w1_gpio_pullup;
  7258. + bcm_register_device_dt(&w1_device);
  7259. +#endif
  7260. + bcm_register_device(&bcm2708_systemtimer_device);
  7261. + bcm_register_device(&bcm2708_fb_device);
  7262. + bcm_register_device(&bcm2708_usb_device);
  7263. + bcm_register_device(&bcm2708_uart1_device);
  7264. + bcm_register_device(&bcm2708_powerman_device);
  7265. +
  7266. +#ifdef CONFIG_MMC_BCM2835
  7267. + bcm_register_device(&bcm2835_emmc_device);
  7268. +#endif
  7269. + bcm2708_init_led();
  7270. + for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  7271. + bcm_register_device(&bcm2708_alsa_devices[i]);
  7272. +
  7273. + bcm_register_device(&bcm2835_hwmon_device);
  7274. + bcm_register_device(&bcm2835_thermal_device);
  7275. +
  7276. + bcm_register_device_dt(&bcm2708_spi_device);
  7277. +
  7278. + if (vc_i2c_override) {
  7279. + bcm_register_device_dt(&bcm2708_bsc0_device);
  7280. + bcm_register_device_dt(&bcm2708_bsc1_device);
  7281. + } else if ((boardrev & 0xffffff) == 0x2 || (boardrev & 0xffffff) == 0x3) {
  7282. + bcm_register_device_dt(&bcm2708_bsc0_device);
  7283. + } else {
  7284. + bcm_register_device_dt(&bcm2708_bsc1_device);
  7285. + }
  7286. +
  7287. +#if defined(CONFIG_SND_BCM2708_SOC_I2S) || defined(CONFIG_SND_BCM2708_SOC_I2S_MODULE)
  7288. + bcm_register_device_dt(&bcm2708_i2s_device);
  7289. +#endif
  7290. +
  7291. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  7292. + bcm_register_device_dt(&snd_hifiberry_dac_device);
  7293. + bcm_register_device_dt(&snd_pcm5102a_codec_device);
  7294. +#endif
  7295. +
  7296. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
  7297. + bcm_register_device_dt(&snd_rpi_hifiberry_dacplus_device);
  7298. + i2c_register_board_info_dt(1, snd_pcm512x_hbdacplus_i2c_devices, ARRAY_SIZE(snd_pcm512x_hbdacplus_i2c_devices));
  7299. +#endif
  7300. +
  7301. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  7302. + bcm_register_device_dt(&snd_hifiberry_digi_device);
  7303. + i2c_register_board_info_dt(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
  7304. +#endif
  7305. +
  7306. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
  7307. + bcm_register_device_dt(&snd_hifiberry_amp_device);
  7308. + i2c_register_board_info_dt(1, snd_tas5713_i2c_devices, ARRAY_SIZE(snd_tas5713_i2c_devices));
  7309. +#endif
  7310. +
  7311. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  7312. + bcm_register_device_dt(&snd_rpi_dac_device);
  7313. + bcm_register_device_dt(&snd_pcm1794a_codec_device);
  7314. +#endif
  7315. +
  7316. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  7317. + bcm_register_device_dt(&snd_rpi_iqaudio_dac_device);
  7318. + i2c_register_board_info_dt(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
  7319. +#endif
  7320. +
  7321. +
  7322. + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  7323. + struct amba_device *d = amba_devs[i];
  7324. + amba_device_register(d, &iomem_resource);
  7325. + }
  7326. + system_rev = boardrev;
  7327. + system_serial_low = serial;
  7328. +
  7329. +#ifdef CONFIG_BCM2708_SPIDEV
  7330. + if (!use_dt)
  7331. + spi_register_board_info(bcm2708_spi_devices,
  7332. + ARRAY_SIZE(bcm2708_spi_devices));
  7333. +#endif
  7334. +}
  7335. +
  7336. +static void timer_set_mode(enum clock_event_mode mode,
  7337. + struct clock_event_device *clk)
  7338. +{
  7339. + switch (mode) {
  7340. + case CLOCK_EVT_MODE_ONESHOT: /* Leave the timer disabled, .set_next_event will enable it */
  7341. + case CLOCK_EVT_MODE_SHUTDOWN:
  7342. + break;
  7343. + case CLOCK_EVT_MODE_PERIODIC:
  7344. +
  7345. + case CLOCK_EVT_MODE_UNUSED:
  7346. + case CLOCK_EVT_MODE_RESUME:
  7347. +
  7348. + default:
  7349. + printk(KERN_ERR "timer_set_mode: unhandled mode:%d\n",
  7350. + (int)mode);
  7351. + break;
  7352. + }
  7353. +
  7354. +}
  7355. +
  7356. +static int timer_set_next_event(unsigned long cycles,
  7357. + struct clock_event_device *unused)
  7358. +{
  7359. + unsigned long stc;
  7360. + do {
  7361. + stc = readl(__io_address(ST_BASE + 0x04));
  7362. + /* We could take a FIQ here, which may push ST above STC3 */
  7363. + writel(stc + cycles, __io_address(ST_BASE + 0x18));
  7364. + } while ((signed long) cycles >= 0 &&
  7365. + (signed long) (readl(__io_address(ST_BASE + 0x04)) - stc)
  7366. + >= (signed long) cycles);
  7367. + return 0;
  7368. +}
  7369. +
  7370. +static struct clock_event_device timer0_clockevent = {
  7371. + .name = "timer0",
  7372. + .shift = 32,
  7373. + .features = CLOCK_EVT_FEAT_ONESHOT,
  7374. + .set_mode = timer_set_mode,
  7375. + .set_next_event = timer_set_next_event,
  7376. +};
  7377. +
  7378. +/*
  7379. + * IRQ handler for the timer
  7380. + */
  7381. +static irqreturn_t bcm2708_timer_interrupt(int irq, void *dev_id)
  7382. +{
  7383. + struct clock_event_device *evt = &timer0_clockevent;
  7384. +
  7385. + writel(1 << 3, __io_address(ST_BASE + 0x00)); /* stcs clear timer int */
  7386. +
  7387. + evt->event_handler(evt);
  7388. +
  7389. + return IRQ_HANDLED;
  7390. +}
  7391. +
  7392. +static struct irqaction bcm2708_timer_irq = {
  7393. + .name = "BCM2708 Timer Tick",
  7394. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  7395. + .handler = bcm2708_timer_interrupt,
  7396. +};
  7397. +
  7398. +/*
  7399. + * Set up timer interrupt, and return the current time in seconds.
  7400. + */
  7401. +
  7402. +static struct delay_timer bcm2708_delay_timer = {
  7403. + .read_current_timer = bcm2708_read_current_timer,
  7404. + .freq = STC_FREQ_HZ,
  7405. +};
  7406. +
  7407. +static void __init bcm2708_timer_init(void)
  7408. +{
  7409. + /* init high res timer */
  7410. + bcm2708_clocksource_init();
  7411. +
  7412. + /*
  7413. + * Initialise to a known state (all timers off)
  7414. + */
  7415. + writel(0, __io_address(ARM_T_CONTROL));
  7416. + /*
  7417. + * Make irqs happen for the system timer
  7418. + */
  7419. + setup_irq(IRQ_TIMER3, &bcm2708_timer_irq);
  7420. +
  7421. + sched_clock_register(bcm2708_read_sched_clock, 32, STC_FREQ_HZ);
  7422. +
  7423. + timer0_clockevent.mult =
  7424. + div_sc(STC_FREQ_HZ, NSEC_PER_SEC, timer0_clockevent.shift);
  7425. + timer0_clockevent.max_delta_ns =
  7426. + clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  7427. + timer0_clockevent.min_delta_ns =
  7428. + clockevent_delta2ns(0xf, &timer0_clockevent);
  7429. +
  7430. + timer0_clockevent.cpumask = cpumask_of(0);
  7431. + clockevents_register_device(&timer0_clockevent);
  7432. +
  7433. + register_current_timer_delay(&bcm2708_delay_timer);
  7434. +}
  7435. +
  7436. +#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  7437. +#include <linux/leds.h>
  7438. +
  7439. +static struct gpio_led bcm2708_leds[] = {
  7440. + [0] = {
  7441. + .gpio = 16,
  7442. + .name = "led0",
  7443. + .default_trigger = "mmc0",
  7444. + .active_low = 1,
  7445. + },
  7446. +};
  7447. +
  7448. +static struct gpio_led_platform_data bcm2708_led_pdata = {
  7449. + .num_leds = ARRAY_SIZE(bcm2708_leds),
  7450. + .leds = bcm2708_leds,
  7451. +};
  7452. +
  7453. +static struct platform_device bcm2708_led_device = {
  7454. + .name = "leds-gpio",
  7455. + .id = -1,
  7456. + .dev = {
  7457. + .platform_data = &bcm2708_led_pdata,
  7458. + },
  7459. +};
  7460. +
  7461. +static void __init bcm2708_init_led(void)
  7462. +{
  7463. + bcm2708_leds[0].gpio = disk_led_gpio;
  7464. + bcm2708_leds[0].active_low = disk_led_active_low;
  7465. + bcm_register_device_dt(&bcm2708_led_device);
  7466. +}
  7467. +#else
  7468. +static inline void bcm2708_init_led(void)
  7469. +{
  7470. +}
  7471. +#endif
  7472. +
  7473. +void __init bcm2708_init_early(void)
  7474. +{
  7475. + /*
  7476. + * Some devices allocate their coherent buffers from atomic
  7477. + * context. Increase size of atomic coherent pool to make sure such
  7478. + * the allocations won't fail.
  7479. + */
  7480. + init_dma_coherent_pool_size(SZ_4M);
  7481. +}
  7482. +
  7483. +static void __init board_reserve(void)
  7484. +{
  7485. +#if defined(CONFIG_BCM_VC_CMA)
  7486. + vc_cma_reserve();
  7487. +#endif
  7488. +}
  7489. +
  7490. +static const char * const bcm2708_compat[] = {
  7491. + "brcm,bcm2708",
  7492. + NULL
  7493. +};
  7494. +
  7495. +MACHINE_START(BCM2708, "BCM2708")
  7496. + /* Maintainer: Broadcom Europe Ltd. */
  7497. + .map_io = bcm2708_map_io,
  7498. + .init_irq = bcm2708_init_irq,
  7499. + .init_time = bcm2708_timer_init,
  7500. + .init_machine = bcm2708_init,
  7501. + .init_early = bcm2708_init_early,
  7502. + .reserve = board_reserve,
  7503. + .restart = bcm2708_restart,
  7504. + .dt_compat = bcm2708_compat,
  7505. +MACHINE_END
  7506. +
  7507. +module_param(boardrev, uint, 0644);
  7508. +module_param(serial, uint, 0644);
  7509. +module_param(uart_clock, uint, 0644);
  7510. +module_param(disk_led_gpio, uint, 0644);
  7511. +module_param(disk_led_active_low, uint, 0644);
  7512. +module_param(reboot_part, uint, 0644);
  7513. +module_param(w1_gpio_pin, uint, 0644);
  7514. +module_param(w1_gpio_pullup, uint, 0644);
  7515. +module_param(pps_gpio_pin, int, 0644);
  7516. +MODULE_PARM_DESC(pps_gpio_pin, "Set GPIO pin to reserve for PPS");
  7517. +module_param(vc_i2c_override, bool, 0644);
  7518. +MODULE_PARM_DESC(vc_i2c_override, "Allow the use of VC's I2C peripheral.");
  7519. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/bcm2708_gpio.c linux-rpi/arch/arm/mach-bcm2708/bcm2708_gpio.c
  7520. --- linux-3.18.6/arch/arm/mach-bcm2708/bcm2708_gpio.c 1970-01-01 01:00:00.000000000 +0100
  7521. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708_gpio.c 2015-02-09 04:39:42.000000000 +0100
  7522. @@ -0,0 +1,426 @@
  7523. +/*
  7524. + * linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
  7525. + *
  7526. + * Copyright (C) 2010 Broadcom
  7527. + *
  7528. + * This program is free software; you can redistribute it and/or modify
  7529. + * it under the terms of the GNU General Public License version 2 as
  7530. + * published by the Free Software Foundation.
  7531. + *
  7532. + */
  7533. +
  7534. +#include <linux/spinlock.h>
  7535. +#include <linux/module.h>
  7536. +#include <linux/delay.h>
  7537. +#include <linux/list.h>
  7538. +#include <linux/io.h>
  7539. +#include <linux/irq.h>
  7540. +#include <linux/interrupt.h>
  7541. +#include <linux/slab.h>
  7542. +#include <mach/gpio.h>
  7543. +#include <linux/gpio.h>
  7544. +#include <linux/platform_device.h>
  7545. +#include <mach/platform.h>
  7546. +#include <linux/pinctrl/consumer.h>
  7547. +
  7548. +#include <linux/platform_data/bcm2708.h>
  7549. +
  7550. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  7551. +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
  7552. +#define BCM_GPIO_USE_IRQ 1
  7553. +
  7554. +#define GPIOFSEL(x) (0x00+(x)*4)
  7555. +#define GPIOSET(x) (0x1c+(x)*4)
  7556. +#define GPIOCLR(x) (0x28+(x)*4)
  7557. +#define GPIOLEV(x) (0x34+(x)*4)
  7558. +#define GPIOEDS(x) (0x40+(x)*4)
  7559. +#define GPIOREN(x) (0x4c+(x)*4)
  7560. +#define GPIOFEN(x) (0x58+(x)*4)
  7561. +#define GPIOHEN(x) (0x64+(x)*4)
  7562. +#define GPIOLEN(x) (0x70+(x)*4)
  7563. +#define GPIOAREN(x) (0x7c+(x)*4)
  7564. +#define GPIOAFEN(x) (0x88+(x)*4)
  7565. +#define GPIOUD(x) (0x94+(x)*4)
  7566. +#define GPIOUDCLK(x) (0x98+(x)*4)
  7567. +
  7568. +#define GPIO_BANKS 2
  7569. +
  7570. +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
  7571. + GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
  7572. + GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
  7573. + GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
  7574. +};
  7575. +
  7576. + /* Each of the two spinlocks protects a different set of hardware
  7577. + * regiters and data structurs. This decouples the code of the IRQ from
  7578. + * the GPIO code. This also makes the case of a GPIO routine call from
  7579. + * the IRQ code simpler.
  7580. + */
  7581. +static DEFINE_SPINLOCK(lock); /* GPIO registers */
  7582. +
  7583. +struct bcm2708_gpio {
  7584. + struct list_head list;
  7585. + void __iomem *base;
  7586. + struct gpio_chip gc;
  7587. + unsigned long rising[(BCM2708_NR_GPIOS + 31) / 32];
  7588. + unsigned long falling[(BCM2708_NR_GPIOS + 31) / 32];
  7589. + unsigned long high[(BCM2708_NR_GPIOS + 31) / 32];
  7590. + unsigned long low[(BCM2708_NR_GPIOS + 31) / 32];
  7591. +};
  7592. +
  7593. +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
  7594. + int function)
  7595. +{
  7596. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  7597. + unsigned long flags;
  7598. + unsigned gpiodir;
  7599. + unsigned gpio_bank = offset / 10;
  7600. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  7601. +
  7602. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
  7603. + if (offset >= BCM2708_NR_GPIOS)
  7604. + return -EINVAL;
  7605. +
  7606. + spin_lock_irqsave(&lock, flags);
  7607. +
  7608. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  7609. + gpiodir &= ~(7 << gpio_field_offset);
  7610. + gpiodir |= function << gpio_field_offset;
  7611. + writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
  7612. + spin_unlock_irqrestore(&lock, flags);
  7613. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  7614. +
  7615. + return 0;
  7616. +}
  7617. +
  7618. +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
  7619. +{
  7620. + return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
  7621. +}
  7622. +
  7623. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
  7624. +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
  7625. + int value)
  7626. +{
  7627. + int ret;
  7628. + ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
  7629. + if (ret >= 0)
  7630. + bcm2708_gpio_set(gc, offset, value);
  7631. + return ret;
  7632. +}
  7633. +
  7634. +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
  7635. +{
  7636. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  7637. + unsigned gpio_bank = offset / 32;
  7638. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  7639. + unsigned lev;
  7640. +
  7641. + if (offset >= BCM2708_NR_GPIOS)
  7642. + return 0;
  7643. + lev = readl(gpio->base + GPIOLEV(gpio_bank));
  7644. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
  7645. + return 0x1 & (lev >> gpio_field_offset);
  7646. +}
  7647. +
  7648. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  7649. +{
  7650. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  7651. + unsigned gpio_bank = offset / 32;
  7652. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  7653. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
  7654. + if (offset >= BCM2708_NR_GPIOS)
  7655. + return;
  7656. + if (value)
  7657. + writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
  7658. + else
  7659. + writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
  7660. +}
  7661. +
  7662. +/**********************
  7663. + * extension to configure pullups
  7664. + */
  7665. +int bcm2708_gpio_setpull(struct gpio_chip *gc, unsigned offset,
  7666. + bcm2708_gpio_pull_t value)
  7667. +{
  7668. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  7669. + unsigned gpio_bank = offset / 32;
  7670. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  7671. +
  7672. + if (offset >= BCM2708_NR_GPIOS)
  7673. + return -EINVAL;
  7674. +
  7675. + switch (value) {
  7676. + case BCM2708_PULL_UP:
  7677. + writel(2, gpio->base + GPIOUD(0));
  7678. + break;
  7679. + case BCM2708_PULL_DOWN:
  7680. + writel(1, gpio->base + GPIOUD(0));
  7681. + break;
  7682. + case BCM2708_PULL_OFF:
  7683. + writel(0, gpio->base + GPIOUD(0));
  7684. + break;
  7685. + }
  7686. +
  7687. + udelay(5);
  7688. + writel(1 << gpio_field_offset, gpio->base + GPIOUDCLK(gpio_bank));
  7689. + udelay(5);
  7690. + writel(0, gpio->base + GPIOUD(0));
  7691. + writel(0 << gpio_field_offset, gpio->base + GPIOUDCLK(gpio_bank));
  7692. +
  7693. + return 0;
  7694. +}
  7695. +EXPORT_SYMBOL(bcm2708_gpio_setpull);
  7696. +
  7697. +/*************************************************************************************************************************
  7698. + * bcm2708 GPIO IRQ
  7699. + */
  7700. +
  7701. +#if BCM_GPIO_USE_IRQ
  7702. +
  7703. +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  7704. +{
  7705. + return gpio_to_irq(gpio);
  7706. +}
  7707. +
  7708. +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
  7709. +{
  7710. + unsigned irq = d->irq;
  7711. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  7712. + unsigned gn = irq_to_gpio(irq);
  7713. + unsigned gb = gn / 32;
  7714. + unsigned go = gn % 32;
  7715. +
  7716. + gpio->rising[gb] &= ~(1 << go);
  7717. + gpio->falling[gb] &= ~(1 << go);
  7718. + gpio->high[gb] &= ~(1 << go);
  7719. + gpio->low[gb] &= ~(1 << go);
  7720. +
  7721. + if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  7722. + return -EINVAL;
  7723. +
  7724. + if (type & IRQ_TYPE_EDGE_RISING)
  7725. + gpio->rising[gb] |= (1 << go);
  7726. + if (type & IRQ_TYPE_EDGE_FALLING)
  7727. + gpio->falling[gb] |= (1 << go);
  7728. + if (type & IRQ_TYPE_LEVEL_HIGH)
  7729. + gpio->high[gb] |= (1 << go);
  7730. + if (type & IRQ_TYPE_LEVEL_LOW)
  7731. + gpio->low[gb] |= (1 << go);
  7732. + return 0;
  7733. +}
  7734. +
  7735. +static void bcm2708_gpio_irq_mask(struct irq_data *d)
  7736. +{
  7737. + unsigned irq = d->irq;
  7738. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  7739. + unsigned gn = irq_to_gpio(irq);
  7740. + unsigned gb = gn / 32;
  7741. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  7742. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  7743. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  7744. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  7745. +
  7746. + gn = gn % 32;
  7747. +
  7748. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  7749. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  7750. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  7751. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  7752. +}
  7753. +
  7754. +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
  7755. +{
  7756. + unsigned irq = d->irq;
  7757. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  7758. + unsigned gn = irq_to_gpio(irq);
  7759. + unsigned gb = gn / 32;
  7760. + unsigned go = gn % 32;
  7761. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  7762. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  7763. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  7764. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  7765. +
  7766. + if (gpio->rising[gb] & (1 << go)) {
  7767. + writel(rising | (1 << go), gpio->base + GPIOREN(gb));
  7768. + } else {
  7769. + writel(rising & ~(1 << go), gpio->base + GPIOREN(gb));
  7770. + }
  7771. +
  7772. + if (gpio->falling[gb] & (1 << go)) {
  7773. + writel(falling | (1 << go), gpio->base + GPIOFEN(gb));
  7774. + } else {
  7775. + writel(falling & ~(1 << go), gpio->base + GPIOFEN(gb));
  7776. + }
  7777. +
  7778. + if (gpio->high[gb] & (1 << go)) {
  7779. + writel(high | (1 << go), gpio->base + GPIOHEN(gb));
  7780. + } else {
  7781. + writel(high & ~(1 << go), gpio->base + GPIOHEN(gb));
  7782. + }
  7783. +
  7784. + if (gpio->low[gb] & (1 << go)) {
  7785. + writel(low | (1 << go), gpio->base + GPIOLEN(gb));
  7786. + } else {
  7787. + writel(low & ~(1 << go), gpio->base + GPIOLEN(gb));
  7788. + }
  7789. +}
  7790. +
  7791. +static struct irq_chip bcm2708_irqchip = {
  7792. + .name = "GPIO",
  7793. + .irq_enable = bcm2708_gpio_irq_unmask,
  7794. + .irq_disable = bcm2708_gpio_irq_mask,
  7795. + .irq_unmask = bcm2708_gpio_irq_unmask,
  7796. + .irq_mask = bcm2708_gpio_irq_mask,
  7797. + .irq_set_type = bcm2708_gpio_irq_set_type,
  7798. +};
  7799. +
  7800. +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
  7801. +{
  7802. + unsigned long edsr;
  7803. + unsigned bank;
  7804. + int i;
  7805. + unsigned gpio;
  7806. + unsigned level_bits;
  7807. + struct bcm2708_gpio *gpio_data = dev_id;
  7808. +
  7809. + for (bank = 0; bank < GPIO_BANKS; bank++) {
  7810. + edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
  7811. + level_bits = gpio_data->high[bank] | gpio_data->low[bank];
  7812. +
  7813. + for_each_set_bit(i, &edsr, 32) {
  7814. + gpio = i + bank * 32;
  7815. + /* ack edge triggered IRQs immediately */
  7816. + if (!(level_bits & (1<<i)))
  7817. + writel(1<<i,
  7818. + __io_address(GPIO_BASE) + GPIOEDS(bank));
  7819. + generic_handle_irq(gpio_to_irq(gpio));
  7820. + /* ack level triggered IRQ after handling them */
  7821. + if (level_bits & (1<<i))
  7822. + writel(1<<i,
  7823. + __io_address(GPIO_BASE) + GPIOEDS(bank));
  7824. + }
  7825. + }
  7826. + return IRQ_HANDLED;
  7827. +}
  7828. +
  7829. +static struct irqaction bcm2708_gpio_irq = {
  7830. + .name = "BCM2708 GPIO catchall handler",
  7831. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  7832. + .handler = bcm2708_gpio_interrupt,
  7833. +};
  7834. +
  7835. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  7836. +{
  7837. + unsigned irq;
  7838. +
  7839. + ucb->gc.to_irq = bcm2708_gpio_to_irq;
  7840. +
  7841. + for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
  7842. + irq_set_chip_data(irq, ucb);
  7843. + irq_set_chip_and_handler(irq, &bcm2708_irqchip,
  7844. + handle_simple_irq);
  7845. + set_irq_flags(irq, IRQF_VALID);
  7846. + }
  7847. +
  7848. + bcm2708_gpio_irq.dev_id = ucb;
  7849. + setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
  7850. +}
  7851. +
  7852. +#else
  7853. +
  7854. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  7855. +{
  7856. +}
  7857. +
  7858. +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
  7859. +
  7860. +static int bcm2708_gpio_probe(struct platform_device *dev)
  7861. +{
  7862. + struct bcm2708_gpio *ucb;
  7863. + struct resource *res;
  7864. + int bank;
  7865. + int err = 0;
  7866. +
  7867. + printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
  7868. +
  7869. + ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
  7870. + if (NULL == ucb) {
  7871. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  7872. + "mailbox memory\n");
  7873. + err = -ENOMEM;
  7874. + goto err;
  7875. + }
  7876. +
  7877. + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  7878. +
  7879. + platform_set_drvdata(dev, ucb);
  7880. + ucb->base = __io_address(GPIO_BASE);
  7881. +
  7882. + ucb->gc.label = "bcm2708_gpio";
  7883. + ucb->gc.base = 0;
  7884. + ucb->gc.ngpio = BCM2708_NR_GPIOS;
  7885. + ucb->gc.owner = THIS_MODULE;
  7886. +
  7887. + ucb->gc.direction_input = bcm2708_gpio_dir_in;
  7888. + ucb->gc.direction_output = bcm2708_gpio_dir_out;
  7889. + ucb->gc.get = bcm2708_gpio_get;
  7890. + ucb->gc.set = bcm2708_gpio_set;
  7891. + ucb->gc.can_sleep = 0;
  7892. +
  7893. + for (bank = 0; bank < GPIO_BANKS; bank++) {
  7894. + writel(0, ucb->base + GPIOREN(bank));
  7895. + writel(0, ucb->base + GPIOFEN(bank));
  7896. + writel(0, ucb->base + GPIOHEN(bank));
  7897. + writel(0, ucb->base + GPIOLEN(bank));
  7898. + writel(0, ucb->base + GPIOAREN(bank));
  7899. + writel(0, ucb->base + GPIOAFEN(bank));
  7900. + writel(~0, ucb->base + GPIOEDS(bank));
  7901. + }
  7902. +
  7903. + bcm2708_gpio_irq_init(ucb);
  7904. +
  7905. + err = gpiochip_add(&ucb->gc);
  7906. +
  7907. +err:
  7908. + return err;
  7909. +
  7910. +}
  7911. +
  7912. +static int bcm2708_gpio_remove(struct platform_device *dev)
  7913. +{
  7914. + int err = 0;
  7915. + struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
  7916. +
  7917. + printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
  7918. +
  7919. + gpiochip_remove(&ucb->gc);
  7920. +
  7921. + platform_set_drvdata(dev, NULL);
  7922. + kfree(ucb);
  7923. +
  7924. + return err;
  7925. +}
  7926. +
  7927. +static struct platform_driver bcm2708_gpio_driver = {
  7928. + .probe = bcm2708_gpio_probe,
  7929. + .remove = bcm2708_gpio_remove,
  7930. + .driver = {
  7931. + .name = "bcm2708_gpio"},
  7932. +};
  7933. +
  7934. +static int __init bcm2708_gpio_init(void)
  7935. +{
  7936. + return platform_driver_register(&bcm2708_gpio_driver);
  7937. +}
  7938. +
  7939. +static void __exit bcm2708_gpio_exit(void)
  7940. +{
  7941. + platform_driver_unregister(&bcm2708_gpio_driver);
  7942. +}
  7943. +
  7944. +module_init(bcm2708_gpio_init);
  7945. +module_exit(bcm2708_gpio_exit);
  7946. +
  7947. +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
  7948. +MODULE_LICENSE("GPL");
  7949. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/bcm2708.h linux-rpi/arch/arm/mach-bcm2708/bcm2708.h
  7950. --- linux-3.18.6/arch/arm/mach-bcm2708/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  7951. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708.h 2015-02-09 04:39:42.000000000 +0100
  7952. @@ -0,0 +1,49 @@
  7953. +/*
  7954. + * linux/arch/arm/mach-bcm2708/bcm2708.h
  7955. + *
  7956. + * BCM2708 machine support header
  7957. + *
  7958. + * Copyright (C) 2010 Broadcom
  7959. + *
  7960. + * This program is free software; you can redistribute it and/or modify
  7961. + * it under the terms of the GNU General Public License as published by
  7962. + * the Free Software Foundation; either version 2 of the License, or
  7963. + * (at your option) any later version.
  7964. + *
  7965. + * This program is distributed in the hope that it will be useful,
  7966. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7967. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7968. + * GNU General Public License for more details.
  7969. + *
  7970. + * You should have received a copy of the GNU General Public License
  7971. + * along with this program; if not, write to the Free Software
  7972. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  7973. + */
  7974. +
  7975. +#ifndef __BCM2708_BCM2708_H
  7976. +#define __BCM2708_BCM2708_H
  7977. +
  7978. +#include <linux/amba/bus.h>
  7979. +
  7980. +extern void __init bcm2708_init(void);
  7981. +extern void __init bcm2708_init_irq(void);
  7982. +extern void __init bcm2708_map_io(void);
  7983. +extern struct sys_timer bcm2708_timer;
  7984. +extern unsigned int mmc_status(struct device *dev);
  7985. +
  7986. +#define AMBA_DEVICE(name, busid, base, plat) \
  7987. +static struct amba_device name##_device = { \
  7988. + .dev = { \
  7989. + .coherent_dma_mask = ~0, \
  7990. + .init_name = busid, \
  7991. + .platform_data = plat, \
  7992. + }, \
  7993. + .res = { \
  7994. + .start = base##_BASE, \
  7995. + .end = (base##_BASE) + SZ_4K - 1,\
  7996. + .flags = IORESOURCE_MEM, \
  7997. + }, \
  7998. + .irq = base##_IRQ, \
  7999. +}
  8000. +
  8001. +#endif
  8002. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/dma.c linux-rpi/arch/arm/mach-bcm2708/dma.c
  8003. --- linux-3.18.6/arch/arm/mach-bcm2708/dma.c 1970-01-01 01:00:00.000000000 +0100
  8004. +++ linux-rpi/arch/arm/mach-bcm2708/dma.c 2015-02-09 04:39:42.000000000 +0100
  8005. @@ -0,0 +1,409 @@
  8006. +/*
  8007. + * linux/arch/arm/mach-bcm2708/dma.c
  8008. + *
  8009. + * Copyright (C) 2010 Broadcom
  8010. + *
  8011. + * This program is free software; you can redistribute it and/or modify
  8012. + * it under the terms of the GNU General Public License version 2 as
  8013. + * published by the Free Software Foundation.
  8014. + */
  8015. +
  8016. +#include <linux/slab.h>
  8017. +#include <linux/device.h>
  8018. +#include <linux/platform_device.h>
  8019. +#include <linux/module.h>
  8020. +#include <linux/scatterlist.h>
  8021. +
  8022. +#include <mach/dma.h>
  8023. +#include <mach/irqs.h>
  8024. +
  8025. +/*****************************************************************************\
  8026. + * *
  8027. + * Configuration *
  8028. + * *
  8029. +\*****************************************************************************/
  8030. +
  8031. +#define CACHE_LINE_MASK 31
  8032. +#define DRIVER_NAME BCM_DMAMAN_DRIVER_NAME
  8033. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  8034. +
  8035. +/* valid only for channels 0 - 14, 15 has its own base address */
  8036. +#define BCM2708_DMA_CHAN(n) ((n)<<8) /* base address */
  8037. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  8038. + ((void __iomem *)((char *)(dma_base)+BCM2708_DMA_CHAN(n)))
  8039. +
  8040. +
  8041. +/*****************************************************************************\
  8042. + * *
  8043. + * DMA Auxilliary Functions *
  8044. + * *
  8045. +\*****************************************************************************/
  8046. +
  8047. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  8048. + section inside the DMA buffer and another section outside it.
  8049. + Even if we flush DMA buffers from the cache there is always the chance that
  8050. + during a DMA someone will access the part of a cache line that is outside
  8051. + the DMA buffer - which will then bring in unwelcome data.
  8052. + Without being able to dictate our own buffer pools we must insist that
  8053. + DMA buffers consist of a whole number of cache lines.
  8054. +*/
  8055. +
  8056. +extern int
  8057. +bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  8058. +{
  8059. + int i;
  8060. +
  8061. + for (i = 0; i < sg_len; i++) {
  8062. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  8063. + sg_ptr[i].length & CACHE_LINE_MASK)
  8064. + return 0;
  8065. + }
  8066. +
  8067. + return 1;
  8068. +}
  8069. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  8070. +
  8071. +extern void
  8072. +bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block)
  8073. +{
  8074. + dsb(); /* ARM data synchronization (push) operation */
  8075. +
  8076. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  8077. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  8078. +}
  8079. +
  8080. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  8081. +{
  8082. + dsb();
  8083. +
  8084. + /* ugly busy wait only option for now */
  8085. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  8086. + cpu_relax();
  8087. +}
  8088. +
  8089. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  8090. +
  8091. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  8092. +{
  8093. + dsb();
  8094. +
  8095. + return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
  8096. +}
  8097. +EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
  8098. +
  8099. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  8100. + Does nothing if there is no DMA in progress.
  8101. + This routine waits for the current AXI transfer to complete before
  8102. + terminating the current DMA. If the current transfer is hung on a DREQ used
  8103. + by an uncooperative peripheral the AXI transfer may never complete. In this
  8104. + case the routine times out and return a non-zero error code.
  8105. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  8106. + does not produce an interrupt.
  8107. +*/
  8108. +extern int
  8109. +bcm_dma_abort(void __iomem *dma_chan_base)
  8110. +{
  8111. + unsigned long int cs;
  8112. + int rc = 0;
  8113. +
  8114. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  8115. +
  8116. + if (BCM2708_DMA_ACTIVE & cs) {
  8117. + long int timeout = 10000;
  8118. +
  8119. + /* write 0 to the active bit - pause the DMA */
  8120. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  8121. +
  8122. + /* wait for any current AXI transfer to complete */
  8123. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  8124. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  8125. +
  8126. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  8127. + /* we'll un-pause when we set of our next DMA */
  8128. + rc = -ETIMEDOUT;
  8129. +
  8130. + } else if (BCM2708_DMA_ACTIVE & cs) {
  8131. + /* terminate the control block chain */
  8132. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  8133. +
  8134. + /* abort the whole DMA */
  8135. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  8136. + dma_chan_base + BCM2708_DMA_CS);
  8137. + }
  8138. + }
  8139. +
  8140. + return rc;
  8141. +}
  8142. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  8143. +
  8144. +
  8145. +/***************************************************************************** \
  8146. + * *
  8147. + * DMA Manager Device Methods *
  8148. + * *
  8149. +\*****************************************************************************/
  8150. +
  8151. +struct vc_dmaman {
  8152. + void __iomem *dma_base;
  8153. + u32 chan_available; /* bitmap of available channels */
  8154. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  8155. +};
  8156. +
  8157. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  8158. + u32 chans_available)
  8159. +{
  8160. + dmaman->dma_base = dma_base;
  8161. + dmaman->chan_available = chans_available;
  8162. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* chans 2 & 3 */
  8163. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* chan 0 */
  8164. + dmaman->has_feature[BCM_DMA_FEATURE_NORMAL_ORD] = 0xfe; /* chans 1 to 7 */
  8165. + dmaman->has_feature[BCM_DMA_FEATURE_LITE_ORD] = 0x7f00; /* chans 8 to 14 */
  8166. +}
  8167. +
  8168. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  8169. + unsigned preferred_feature_set)
  8170. +{
  8171. + u32 chans;
  8172. + int feature;
  8173. +
  8174. + chans = dmaman->chan_available;
  8175. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  8176. + /* select the subset of available channels with the desired
  8177. + feature so long as some of the candidate channels have that
  8178. + feature */
  8179. + if ((preferred_feature_set & (1 << feature)) &&
  8180. + (chans & dmaman->has_feature[feature]))
  8181. + chans &= dmaman->has_feature[feature];
  8182. +
  8183. + if (chans) {
  8184. + int chan = 0;
  8185. + /* return the ordinal of the first channel in the bitmap */
  8186. + while (chans != 0 && (chans & 1) == 0) {
  8187. + chans >>= 1;
  8188. + chan++;
  8189. + }
  8190. + /* claim the channel */
  8191. + dmaman->chan_available &= ~(1 << chan);
  8192. + return chan;
  8193. + } else
  8194. + return -ENOMEM;
  8195. +}
  8196. +
  8197. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  8198. +{
  8199. + if (chan < 0)
  8200. + return -EINVAL;
  8201. + else if ((1 << chan) & dmaman->chan_available)
  8202. + return -EIDRM;
  8203. + else {
  8204. + dmaman->chan_available |= (1 << chan);
  8205. + return 0;
  8206. + }
  8207. +}
  8208. +
  8209. +/*****************************************************************************\
  8210. + * *
  8211. + * DMA IRQs *
  8212. + * *
  8213. +\*****************************************************************************/
  8214. +
  8215. +static unsigned char bcm_dma_irqs[] = {
  8216. + IRQ_DMA0,
  8217. + IRQ_DMA1,
  8218. + IRQ_DMA2,
  8219. + IRQ_DMA3,
  8220. + IRQ_DMA4,
  8221. + IRQ_DMA5,
  8222. + IRQ_DMA6,
  8223. + IRQ_DMA7,
  8224. + IRQ_DMA8,
  8225. + IRQ_DMA9,
  8226. + IRQ_DMA10,
  8227. + IRQ_DMA11,
  8228. + IRQ_DMA12
  8229. +};
  8230. +
  8231. +
  8232. +/***************************************************************************** \
  8233. + * *
  8234. + * DMA Manager Monitor *
  8235. + * *
  8236. +\*****************************************************************************/
  8237. +
  8238. +static struct device *dmaman_dev; /* we assume there's only one! */
  8239. +
  8240. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  8241. + void __iomem **out_dma_base, int *out_dma_irq)
  8242. +{
  8243. + if (!dmaman_dev)
  8244. + return -ENODEV;
  8245. + else {
  8246. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  8247. + int rc;
  8248. +
  8249. + device_lock(dmaman_dev);
  8250. + rc = vc_dmaman_chan_alloc(dmaman, preferred_feature_set);
  8251. + if (rc >= 0) {
  8252. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base,
  8253. + rc);
  8254. + *out_dma_irq = bcm_dma_irqs[rc];
  8255. + }
  8256. + device_unlock(dmaman_dev);
  8257. +
  8258. + return rc;
  8259. + }
  8260. +}
  8261. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  8262. +
  8263. +extern int bcm_dma_chan_free(int channel)
  8264. +{
  8265. + if (dmaman_dev) {
  8266. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  8267. + int rc;
  8268. +
  8269. + device_lock(dmaman_dev);
  8270. + rc = vc_dmaman_chan_free(dmaman, channel);
  8271. + device_unlock(dmaman_dev);
  8272. +
  8273. + return rc;
  8274. + } else
  8275. + return -ENODEV;
  8276. +}
  8277. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  8278. +
  8279. +static int dev_dmaman_register(const char *dev_name, struct device *dev)
  8280. +{
  8281. + int rc = dmaman_dev ? -EINVAL : 0;
  8282. + dmaman_dev = dev;
  8283. + return rc;
  8284. +}
  8285. +
  8286. +static void dev_dmaman_deregister(const char *dev_name, struct device *dev)
  8287. +{
  8288. + dmaman_dev = NULL;
  8289. +}
  8290. +
  8291. +/*****************************************************************************\
  8292. + * *
  8293. + * DMA Device *
  8294. + * *
  8295. +\*****************************************************************************/
  8296. +
  8297. +static int dmachans = -1; /* module parameter */
  8298. +
  8299. +static int bcm_dmaman_probe(struct platform_device *pdev)
  8300. +{
  8301. + int ret = 0;
  8302. + struct vc_dmaman *dmaman;
  8303. + struct resource *dma_res = NULL;
  8304. + void __iomem *dma_base = NULL;
  8305. + int have_dma_region = 0;
  8306. +
  8307. + dmaman = kzalloc(sizeof(*dmaman), GFP_KERNEL);
  8308. + if (NULL == dmaman) {
  8309. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  8310. + "DMA management memory\n");
  8311. + ret = -ENOMEM;
  8312. + } else {
  8313. +
  8314. + dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  8315. + if (dma_res == NULL) {
  8316. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  8317. + "resource\n");
  8318. + ret = -ENODEV;
  8319. + } else if (!request_mem_region(dma_res->start,
  8320. + resource_size(dma_res),
  8321. + DRIVER_NAME)) {
  8322. + dev_err(&pdev->dev, "cannot obtain DMA region\n");
  8323. + ret = -EBUSY;
  8324. + } else {
  8325. + have_dma_region = 1;
  8326. + dma_base = ioremap(dma_res->start,
  8327. + resource_size(dma_res));
  8328. + if (!dma_base) {
  8329. + dev_err(&pdev->dev, "cannot map DMA region\n");
  8330. + ret = -ENOMEM;
  8331. + } else {
  8332. + /* use module parameter if one was provided */
  8333. + if (dmachans > 0)
  8334. + vc_dmaman_init(dmaman, dma_base,
  8335. + dmachans);
  8336. + else
  8337. + vc_dmaman_init(dmaman, dma_base,
  8338. + DEFAULT_DMACHAN_BITMAP);
  8339. +
  8340. + platform_set_drvdata(pdev, dmaman);
  8341. + dev_dmaman_register(DRIVER_NAME, &pdev->dev);
  8342. +
  8343. + printk(KERN_INFO DRIVER_NAME ": DMA manager "
  8344. + "at %p\n", dma_base);
  8345. + }
  8346. + }
  8347. + }
  8348. + if (ret != 0) {
  8349. + if (dma_base)
  8350. + iounmap(dma_base);
  8351. + if (dma_res && have_dma_region)
  8352. + release_mem_region(dma_res->start,
  8353. + resource_size(dma_res));
  8354. + if (dmaman)
  8355. + kfree(dmaman);
  8356. + }
  8357. + return ret;
  8358. +}
  8359. +
  8360. +static int bcm_dmaman_remove(struct platform_device *pdev)
  8361. +{
  8362. + struct vc_dmaman *dmaman = platform_get_drvdata(pdev);
  8363. +
  8364. + platform_set_drvdata(pdev, NULL);
  8365. + dev_dmaman_deregister(DRIVER_NAME, &pdev->dev);
  8366. + kfree(dmaman);
  8367. +
  8368. + return 0;
  8369. +}
  8370. +
  8371. +static struct platform_driver bcm_dmaman_driver = {
  8372. + .probe = bcm_dmaman_probe,
  8373. + .remove = bcm_dmaman_remove,
  8374. +
  8375. + .driver = {
  8376. + .name = DRIVER_NAME,
  8377. + .owner = THIS_MODULE,
  8378. + },
  8379. +};
  8380. +
  8381. +/*****************************************************************************\
  8382. + * *
  8383. + * Driver init/exit *
  8384. + * *
  8385. +\*****************************************************************************/
  8386. +
  8387. +static int __init bcm_dmaman_drv_init(void)
  8388. +{
  8389. + int ret;
  8390. +
  8391. + ret = platform_driver_register(&bcm_dmaman_driver);
  8392. + if (ret != 0) {
  8393. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  8394. + "on platform\n");
  8395. + }
  8396. +
  8397. + return ret;
  8398. +}
  8399. +
  8400. +static void __exit bcm_dmaman_drv_exit(void)
  8401. +{
  8402. + platform_driver_unregister(&bcm_dmaman_driver);
  8403. +}
  8404. +
  8405. +module_init(bcm_dmaman_drv_init);
  8406. +module_exit(bcm_dmaman_drv_exit);
  8407. +
  8408. +module_param(dmachans, int, 0644);
  8409. +
  8410. +MODULE_AUTHOR("Gray Girling <grayg@broadcom.com>");
  8411. +MODULE_DESCRIPTION("DMA channel manager driver");
  8412. +MODULE_LICENSE("GPL");
  8413. +
  8414. +MODULE_PARM_DESC(dmachans, "Bitmap of DMA channels available to the ARM");
  8415. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/arm_control.h linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_control.h
  8416. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/arm_control.h 1970-01-01 01:00:00.000000000 +0100
  8417. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_control.h 2015-02-09 04:39:42.000000000 +0100
  8418. @@ -0,0 +1,419 @@
  8419. +/*
  8420. + * linux/arch/arm/mach-bcm2708/arm_control.h
  8421. + *
  8422. + * Copyright (C) 2010 Broadcom
  8423. + *
  8424. + * This program is free software; you can redistribute it and/or modify
  8425. + * it under the terms of the GNU General Public License as published by
  8426. + * the Free Software Foundation; either version 2 of the License, or
  8427. + * (at your option) any later version.
  8428. + *
  8429. + * This program is distributed in the hope that it will be useful,
  8430. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8431. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8432. + * GNU General Public License for more details.
  8433. + *
  8434. + * You should have received a copy of the GNU General Public License
  8435. + * along with this program; if not, write to the Free Software
  8436. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  8437. + */
  8438. +
  8439. +#ifndef __BCM2708_ARM_CONTROL_H
  8440. +#define __BCM2708_ARM_CONTROL_H
  8441. +
  8442. +/*
  8443. + * Definitions and addresses for the ARM CONTROL logic
  8444. + * This file is manually generated.
  8445. + */
  8446. +
  8447. +#define ARM_BASE 0x7E00B000
  8448. +
  8449. +/* Basic configuration */
  8450. +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000)
  8451. +#define ARM_C0_SIZ128M 0x00000000
  8452. +#define ARM_C0_SIZ256M 0x00000001
  8453. +#define ARM_C0_SIZ512M 0x00000002
  8454. +#define ARM_C0_SIZ1G 0x00000003
  8455. +#define ARM_C0_BRESP0 0x00000000
  8456. +#define ARM_C0_BRESP1 0x00000004
  8457. +#define ARM_C0_BRESP2 0x00000008
  8458. +#define ARM_C0_BOOTHI 0x00000010
  8459. +#define ARM_C0_UNUSED05 0x00000020 /* free */
  8460. +#define ARM_C0_FULLPERI 0x00000040
  8461. +#define ARM_C0_UNUSED78 0x00000180 /* free */
  8462. +#define ARM_C0_JTAGMASK 0x00000E00
  8463. +#define ARM_C0_JTAGOFF 0x00000000
  8464. +#define ARM_C0_JTAGBASH 0x00000800 /* Debug on GPIO off */
  8465. +#define ARM_C0_JTAGGPIO 0x00000C00 /* Debug on GPIO on */
  8466. +#define ARM_C0_APROTMSK 0x0000F000
  8467. +#define ARM_C0_DBG0SYNC 0x00010000 /* VPU0 halt sync */
  8468. +#define ARM_C0_DBG1SYNC 0x00020000 /* VPU1 halt sync */
  8469. +#define ARM_C0_SWDBGREQ 0x00040000 /* HW debug request */
  8470. +#define ARM_C0_PASSHALT 0x00080000 /* ARM halt passed to debugger */
  8471. +#define ARM_C0_PRIO_PER 0x00F00000 /* per priority mask */
  8472. +#define ARM_C0_PRIO_L2 0x0F000000
  8473. +#define ARM_C0_PRIO_UC 0xF0000000
  8474. +
  8475. +#define ARM_C0_APROTPASS 0x0000A000 /* Translate 1:1 */
  8476. +#define ARM_C0_APROTUSER 0x00000000 /* Only user mode */
  8477. +#define ARM_C0_APROTSYST 0x0000F000 /* Only system mode */
  8478. +
  8479. +
  8480. +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440)
  8481. +#define ARM_C1_TIMER 0x00000001 /* re-route timer IRQ to VC */
  8482. +#define ARM_C1_MAIL 0x00000002 /* re-route Mail IRQ to VC */
  8483. +#define ARM_C1_BELL0 0x00000004 /* re-route Doorbell 0 to VC */
  8484. +#define ARM_C1_BELL1 0x00000008 /* re-route Doorbell 1 to VC */
  8485. +#define ARM_C1_PERSON 0x00000100 /* peripherals on */
  8486. +#define ARM_C1_REQSTOP 0x00000200 /* ASYNC bridge request stop */
  8487. +
  8488. +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444)
  8489. +#define ARM_S_ACKSTOP 0x80000000 /* Bridge stopped */
  8490. +#define ARM_S_READPEND 0x000003FF /* pending reads counter */
  8491. +#define ARM_S_WRITPEND 0x000FFC00 /* pending writes counter */
  8492. +
  8493. +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448)
  8494. +#define ARM_EH_PERIBURST 0x00000001 /* Burst write seen on peri bus */
  8495. +#define ARM_EH_ILLADDRS1 0x00000002 /* Address bits 25-27 error */
  8496. +#define ARM_EH_ILLADDRS2 0x00000004 /* Address bits 31-28 error */
  8497. +#define ARM_EH_VPU0HALT 0x00000008 /* VPU0 halted & in debug mode */
  8498. +#define ARM_EH_VPU1HALT 0x00000010 /* VPU1 halted & in debug mode */
  8499. +#define ARM_EH_ARMHALT 0x00000020 /* ARM in halted debug mode */
  8500. +
  8501. +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C)
  8502. +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C)
  8503. +#define ARM_IDVAL 0x364D5241
  8504. +
  8505. +/* Translation memory */
  8506. +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100)
  8507. +/* 32 locations: 0x100.. 0x17F */
  8508. +/* 32 spare means we CAN go to 64 pages.... */
  8509. +
  8510. +
  8511. +/* Interrupts */
  8512. +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200) /* Top IRQ bits */
  8513. +#define ARM_I0_TIMER 0x00000001 /* timer IRQ */
  8514. +#define ARM_I0_MAIL 0x00000002 /* Mail IRQ */
  8515. +#define ARM_I0_BELL0 0x00000004 /* Doorbell 0 */
  8516. +#define ARM_I0_BELL1 0x00000008 /* Doorbell 1 */
  8517. +#define ARM_I0_BANK1 0x00000100 /* Bank1 IRQ */
  8518. +#define ARM_I0_BANK2 0x00000200 /* Bank2 IRQ */
  8519. +
  8520. +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204) /* All bank1 IRQ bits */
  8521. +/* todo: all I1_interrupt sources */
  8522. +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208) /* All bank2 IRQ bits */
  8523. +/* todo: all I2_interrupt sources */
  8524. +
  8525. +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C) /* FIQ control */
  8526. +#define ARM_IF_INDEX 0x0000007F /* FIQ select */
  8527. +#define ARM_IF_ENABLE 0x00000080 /* FIQ enable */
  8528. +#define ARM_IF_VCMASK 0x0000003F /* FIQ = (index from VC source) */
  8529. +#define ARM_IF_TIMER 0x00000040 /* FIQ = ARM timer */
  8530. +#define ARM_IF_MAIL 0x00000041 /* FIQ = ARM Mail */
  8531. +#define ARM_IF_BELL0 0x00000042 /* FIQ = ARM Doorbell 0 */
  8532. +#define ARM_IF_BELL1 0x00000043 /* FIQ = ARM Doorbell 1 */
  8533. +#define ARM_IF_VP0HALT 0x00000044 /* FIQ = VPU0 Halt seen */
  8534. +#define ARM_IF_VP1HALT 0x00000045 /* FIQ = VPU1 Halt seen */
  8535. +#define ARM_IF_ILLEGAL 0x00000046 /* FIQ = Illegal access seen */
  8536. +
  8537. +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210) /* Bank1 enable bits */
  8538. +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214) /* Bank2 enable bits */
  8539. +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218) /* ARM irqs enable bits */
  8540. +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C) /* Bank1 disable bits */
  8541. +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220) /* Bank2 disable bits */
  8542. +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224) /* ARM irqs disable bits */
  8543. +#define ARM_IE_TIMER 0x00000001 /* Timer IRQ */
  8544. +#define ARM_IE_MAIL 0x00000002 /* Mail IRQ */
  8545. +#define ARM_IE_BELL0 0x00000004 /* Doorbell 0 */
  8546. +#define ARM_IE_BELL1 0x00000008 /* Doorbell 1 */
  8547. +#define ARM_IE_VP0HALT 0x00000010 /* VPU0 Halt */
  8548. +#define ARM_IE_VP1HALT 0x00000020 /* VPU1 Halt */
  8549. +#define ARM_IE_ILLEGAL 0x00000040 /* Illegal access seen */
  8550. +
  8551. +/* Timer */
  8552. +/* For reg. fields see sp804 spec. */
  8553. +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400)
  8554. +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404)
  8555. +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408)
  8556. +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C)
  8557. +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410)
  8558. +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414)
  8559. +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418)
  8560. +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c)
  8561. +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420)
  8562. +
  8563. +#define TIMER_CTRL_ONESHOT (1 << 0)
  8564. +#define TIMER_CTRL_32BIT (1 << 1)
  8565. +#define TIMER_CTRL_DIV1 (0 << 2)
  8566. +#define TIMER_CTRL_DIV16 (1 << 2)
  8567. +#define TIMER_CTRL_DIV256 (2 << 2)
  8568. +#define TIMER_CTRL_IE (1 << 5)
  8569. +#define TIMER_CTRL_PERIODIC (1 << 6)
  8570. +#define TIMER_CTRL_ENABLE (1 << 7)
  8571. +#define TIMER_CTRL_DBGHALT (1 << 8)
  8572. +#define TIMER_CTRL_ENAFREE (1 << 9)
  8573. +#define TIMER_CTRL_FREEDIV_SHIFT 16)
  8574. +#define TIMER_CTRL_FREEDIV_MASK 0xff
  8575. +
  8576. +/* Semaphores, Doorbells, Mailboxes */
  8577. +#define ARM_SBM_OWN0 (ARM_BASE+0x800)
  8578. +#define ARM_SBM_OWN1 (ARM_BASE+0x900)
  8579. +#define ARM_SBM_OWN2 (ARM_BASE+0xA00)
  8580. +#define ARM_SBM_OWN3 (ARM_BASE+0xB00)
  8581. +
  8582. +/* MAILBOXES
  8583. + * Register flags are common across all
  8584. + * owner registers. See end of this section
  8585. + *
  8586. + * Semaphores, Doorbells, Mailboxes Owner 0
  8587. + *
  8588. + */
  8589. +
  8590. +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  8591. +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  8592. +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04)
  8593. +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08)
  8594. +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C)
  8595. +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10)
  8596. +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14)
  8597. +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18)
  8598. +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
  8599. +#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40)
  8600. +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44)
  8601. +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48)
  8602. +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
  8603. +/* MAILBOX 0 access in Owner 0 area */
  8604. +/* Some addresses should ONLY be used by owner 0 */
  8605. +#define ARM_0_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) */
  8606. +#define ARM_0_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) Normal read */
  8607. +#define ARM_0_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN0+0x90) /* none-pop read */
  8608. +#define ARM_0_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN0+0x94) /* Sender read (only LS 2 bits) */
  8609. +#define ARM_0_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN0+0x98) /* Status read */
  8610. +#define ARM_0_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0x9C) /* Config read/write */
  8611. +/* MAILBOX 1 access in Owner 0 area */
  8612. +/* Owner 0 should only WRITE to this mailbox */
  8613. +#define ARM_0_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) /* .. 0xAC (4 locations) */
  8614. +/*#define ARM_0_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */
  8615. +/*#define ARM_0_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */
  8616. +/*#define ARM_0_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */
  8617. +#define ARM_0_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN0+0xB8) /* Status read */
  8618. +/*#define ARM_0_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */
  8619. +/* General SEM, BELL, MAIL config/status */
  8620. +#define ARM_0_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE0) /* semaphore clear/debug register */
  8621. +#define ARM_0_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE4) /* Doorbells clear/debug register */
  8622. +#define ARM_0_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xF8) /* ALL interrupts */
  8623. +#define ARM_0_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xFC) /* IRQS pending for owner 0 */
  8624. +
  8625. +/* Semaphores, Doorbells, Mailboxes Owner 1 */
  8626. +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  8627. +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  8628. +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
  8629. +#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08)
  8630. +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C)
  8631. +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10)
  8632. +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14)
  8633. +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18)
  8634. +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C)
  8635. +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40)
  8636. +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44)
  8637. +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48)
  8638. +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
  8639. +/* MAILBOX 0 access in Owner 0 area */
  8640. +/* Owner 1 should only WRITE to this mailbox */
  8641. +#define ARM_1_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0x80) /* .. 0x8C (4 locations) */
  8642. +/*#define ARM_1_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */
  8643. +/*#define ARM_1_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */
  8644. +/*#define ARM_1_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */
  8645. +#define ARM_1_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN1+0x98) /* Status read */
  8646. +/*#define ARM_1_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */
  8647. +/* MAILBOX 1 access in Owner 0 area */
  8648. +#define ARM_1_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) */
  8649. +#define ARM_1_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) Normal read */
  8650. +#define ARM_1_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN1+0xB0) /* none-pop read */
  8651. +#define ARM_1_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN1+0xB4) /* Sender read (only LS 2 bits) */
  8652. +#define ARM_1_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN1+0xB8) /* Status read */
  8653. +#define ARM_1_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0xBC)
  8654. +/* General SEM, BELL, MAIL config/status */
  8655. +#define ARM_1_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE0) /* semaphore clear/debug register */
  8656. +#define ARM_1_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE4) /* Doorbells clear/debug register */
  8657. +#define ARM_1_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xFC) /* IRQS pending for owner 1 */
  8658. +#define ARM_1_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xF8) /* ALL interrupts */
  8659. +
  8660. +/* Semaphores, Doorbells, Mailboxes Owner 2 */
  8661. +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  8662. +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  8663. +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04)
  8664. +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08)
  8665. +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C)
  8666. +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10)
  8667. +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14)
  8668. +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18)
  8669. +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C)
  8670. +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40)
  8671. +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44)
  8672. +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48)
  8673. +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C)
  8674. +/* MAILBOX 0 access in Owner 2 area */
  8675. +/* Owner 2 should only WRITE to this mailbox */
  8676. +#define ARM_2_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0x80) /* .. 0x8C (4 locations) */
  8677. +/*#define ARM_2_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */
  8678. +/*#define ARM_2_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */
  8679. +/*#define ARM_2_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */
  8680. +#define ARM_2_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN2+0x98) /* Status read */
  8681. +/*#define ARM_2_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */
  8682. +/* MAILBOX 1 access in Owner 2 area */
  8683. +/* Owner 2 should only WRITE to this mailbox */
  8684. +#define ARM_2_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) /* .. 0xAC (4 locations) */
  8685. +/*#define ARM_2_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */
  8686. +/*#define ARM_2_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */
  8687. +/*#define ARM_2_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */
  8688. +#define ARM_2_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN2+0xB8) /* Status read */
  8689. +/*#define ARM_2_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */
  8690. +/* General SEM, BELL, MAIL config/status */
  8691. +#define ARM_2_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE0) /* semaphore clear/debug register */
  8692. +#define ARM_2_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE4) /* Doorbells clear/debug register */
  8693. +#define ARM_2_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xFC) /* IRQS pending for owner 2 */
  8694. +#define ARM_2_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xF8) /* ALL interrupts */
  8695. +
  8696. +/* Semaphores, Doorbells, Mailboxes Owner 3 */
  8697. +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  8698. +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  8699. +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04)
  8700. +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08)
  8701. +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C)
  8702. +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10)
  8703. +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14)
  8704. +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18)
  8705. +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C)
  8706. +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40)
  8707. +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44)
  8708. +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48)
  8709. +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C)
  8710. +/* MAILBOX 0 access in Owner 3 area */
  8711. +/* Owner 3 should only WRITE to this mailbox */
  8712. +#define ARM_3_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0x80) /* .. 0x8C (4 locations) */
  8713. +/*#define ARM_3_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */
  8714. +/*#define ARM_3_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */
  8715. +/*#define ARM_3_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */
  8716. +#define ARM_3_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN3+0x98) /* Status read */
  8717. +/*#define ARM_3_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */
  8718. +/* MAILBOX 1 access in Owner 3 area */
  8719. +/* Owner 3 should only WRITE to this mailbox */
  8720. +#define ARM_3_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) /* .. 0xAC (4 locations) */
  8721. +/*#define ARM_3_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */
  8722. +/*#define ARM_3_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */
  8723. +/*#define ARM_3_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */
  8724. +#define ARM_3_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN3+0xB8) /* Status read */
  8725. +/*#define ARM_3_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */
  8726. +/* General SEM, BELL, MAIL config/status */
  8727. +#define ARM_3_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE0) /* semaphore clear/debug register */
  8728. +#define ARM_3_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE4) /* Doorbells clear/debug register */
  8729. +#define ARM_3_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xFC) /* IRQS pending for owner 3 */
  8730. +#define ARM_3_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xF8) /* ALL interrupts */
  8731. +
  8732. +
  8733. +
  8734. +/* Mailbox flags. Valid for all owners */
  8735. +
  8736. +/* Mailbox status register (...0x98) */
  8737. +#define ARM_MS_FULL 0x80000000
  8738. +#define ARM_MS_EMPTY 0x40000000
  8739. +#define ARM_MS_LEVEL 0x400000FF /* Max. value depdnds on mailbox depth parameter */
  8740. +
  8741. +/* MAILBOX config/status register (...0x9C) */
  8742. +/* ANY write to this register clears the error bits! */
  8743. +#define ARM_MC_IHAVEDATAIRQEN 0x00000001 /* mailbox irq enable: has data */
  8744. +#define ARM_MC_IHAVESPACEIRQEN 0x00000002 /* mailbox irq enable: has space */
  8745. +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004 /* mailbox irq enable: Opp. is empty */
  8746. +#define ARM_MC_MAIL_CLEAR 0x00000008 /* mailbox clear write 1, then 0 */
  8747. +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010 /* mailbox irq pending: has space */
  8748. +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020 /* mailbox irq pending: Opp. is empty */
  8749. +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040 /* mailbox irq pending */
  8750. +/* Bit 7 is unused */
  8751. +#define ARM_MC_ERRNOOWN 0x00000100 /* error : none owner read from mailbox */
  8752. +#define ARM_MC_ERROVERFLW 0x00000200 /* error : write to fill mailbox */
  8753. +#define ARM_MC_ERRUNDRFLW 0x00000400 /* error : read from empty mailbox */
  8754. +
  8755. +/* Semaphore clear/debug register (...0xE0) */
  8756. +#define ARM_SD_OWN0 0x00000003 /* Owner of sem 0 */
  8757. +#define ARM_SD_OWN1 0x0000000C /* Owner of sem 1 */
  8758. +#define ARM_SD_OWN2 0x00000030 /* Owner of sem 2 */
  8759. +#define ARM_SD_OWN3 0x000000C0 /* Owner of sem 3 */
  8760. +#define ARM_SD_OWN4 0x00000300 /* Owner of sem 4 */
  8761. +#define ARM_SD_OWN5 0x00000C00 /* Owner of sem 5 */
  8762. +#define ARM_SD_OWN6 0x00003000 /* Owner of sem 6 */
  8763. +#define ARM_SD_OWN7 0x0000C000 /* Owner of sem 7 */
  8764. +#define ARM_SD_SEM0 0x00010000 /* Status of sem 0 */
  8765. +#define ARM_SD_SEM1 0x00020000 /* Status of sem 1 */
  8766. +#define ARM_SD_SEM2 0x00040000 /* Status of sem 2 */
  8767. +#define ARM_SD_SEM3 0x00080000 /* Status of sem 3 */
  8768. +#define ARM_SD_SEM4 0x00100000 /* Status of sem 4 */
  8769. +#define ARM_SD_SEM5 0x00200000 /* Status of sem 5 */
  8770. +#define ARM_SD_SEM6 0x00400000 /* Status of sem 6 */
  8771. +#define ARM_SD_SEM7 0x00800000 /* Status of sem 7 */
  8772. +
  8773. +/* Doorbells clear/debug register (...0xE4) */
  8774. +#define ARM_BD_OWN0 0x00000003 /* Owner of doorbell 0 */
  8775. +#define ARM_BD_OWN1 0x0000000C /* Owner of doorbell 1 */
  8776. +#define ARM_BD_OWN2 0x00000030 /* Owner of doorbell 2 */
  8777. +#define ARM_BD_OWN3 0x000000C0 /* Owner of doorbell 3 */
  8778. +#define ARM_BD_BELL0 0x00000100 /* Status of doorbell 0 */
  8779. +#define ARM_BD_BELL1 0x00000200 /* Status of doorbell 1 */
  8780. +#define ARM_BD_BELL2 0x00000400 /* Status of doorbell 2 */
  8781. +#define ARM_BD_BELL3 0x00000800 /* Status of doorbell 3 */
  8782. +
  8783. +/* MY IRQS register (...0xF8) */
  8784. +#define ARM_MYIRQ_BELL 0x00000001 /* This owner has a doorbell IRQ */
  8785. +#define ARM_MYIRQ_MAIL 0x00000002 /* This owner has a mailbox IRQ */
  8786. +
  8787. +/* ALL IRQS register (...0xF8) */
  8788. +#define ARM_AIS_BELL0 0x00000001 /* Doorbell 0 IRQ pending */
  8789. +#define ARM_AIS_BELL1 0x00000002 /* Doorbell 1 IRQ pending */
  8790. +#define ARM_AIS_BELL2 0x00000004 /* Doorbell 2 IRQ pending */
  8791. +#define ARM_AIS_BELL3 0x00000008 /* Doorbell 3 IRQ pending */
  8792. +#define ARM_AIS0_HAVEDATA 0x00000010 /* MAIL 0 has data IRQ pending */
  8793. +#define ARM_AIS0_HAVESPAC 0x00000020 /* MAIL 0 has space IRQ pending */
  8794. +#define ARM_AIS0_OPPEMPTY 0x00000040 /* MAIL 0 opposite is empty IRQ */
  8795. +#define ARM_AIS1_HAVEDATA 0x00000080 /* MAIL 1 has data IRQ pending */
  8796. +#define ARM_AIS1_HAVESPAC 0x00000100 /* MAIL 1 has space IRQ pending */
  8797. +#define ARM_AIS1_OPPEMPTY 0x00000200 /* MAIL 1 opposite is empty IRQ */
  8798. +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */
  8799. +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */
  8800. +/* */
  8801. +/* ARM JTAG BASH */
  8802. +/* */
  8803. +#define AJB_BASE 0x7e2000c0
  8804. +
  8805. +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00)
  8806. +#define AJB_BITS0 0x000000
  8807. +#define AJB_BITS4 0x000004
  8808. +#define AJB_BITS8 0x000008
  8809. +#define AJB_BITS12 0x00000C
  8810. +#define AJB_BITS16 0x000010
  8811. +#define AJB_BITS20 0x000014
  8812. +#define AJB_BITS24 0x000018
  8813. +#define AJB_BITS28 0x00001C
  8814. +#define AJB_BITS32 0x000020
  8815. +#define AJB_BITS34 0x000022
  8816. +#define AJB_OUT_MS 0x000040
  8817. +#define AJB_OUT_LS 0x000000
  8818. +#define AJB_INV_CLK 0x000080
  8819. +#define AJB_D0_RISE 0x000100
  8820. +#define AJB_D0_FALL 0x000000
  8821. +#define AJB_D1_RISE 0x000200
  8822. +#define AJB_D1_FALL 0x000000
  8823. +#define AJB_IN_RISE 0x000400
  8824. +#define AJB_IN_FALL 0x000000
  8825. +#define AJB_ENABLE 0x000800
  8826. +#define AJB_HOLD0 0x000000
  8827. +#define AJB_HOLD1 0x001000
  8828. +#define AJB_HOLD2 0x002000
  8829. +#define AJB_HOLD3 0x003000
  8830. +#define AJB_RESETN 0x004000
  8831. +#define AJB_CLKSHFT 16
  8832. +#define AJB_BUSY 0x80000000
  8833. +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04)
  8834. +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08)
  8835. +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c)
  8836. +
  8837. +#endif
  8838. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/arm_power.h linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_power.h
  8839. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/arm_power.h 1970-01-01 01:00:00.000000000 +0100
  8840. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_power.h 2015-02-09 04:39:42.000000000 +0100
  8841. @@ -0,0 +1,62 @@
  8842. +/*
  8843. + * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h
  8844. + *
  8845. + * Copyright (C) 2010 Broadcom
  8846. + *
  8847. + * This program is free software; you can redistribute it and/or modify
  8848. + * it under the terms of the GNU General Public License as published by
  8849. + * the Free Software Foundation; either version 2 of the License, or
  8850. + * (at your option) any later version.
  8851. + *
  8852. + * This program is distributed in the hope that it will be useful,
  8853. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8854. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8855. + * GNU General Public License for more details.
  8856. + *
  8857. + * You should have received a copy of the GNU General Public License
  8858. + * along with this program; if not, write to the Free Software
  8859. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  8860. + */
  8861. +
  8862. +#ifndef _ARM_POWER_H
  8863. +#define _ARM_POWER_H
  8864. +
  8865. +/* Use meaningful names on each side */
  8866. +#ifdef __VIDEOCORE__
  8867. +#define PREFIX(x) ARM_##x
  8868. +#else
  8869. +#define PREFIX(x) BCM_##x
  8870. +#endif
  8871. +
  8872. +enum {
  8873. + PREFIX(POWER_SDCARD_BIT),
  8874. + PREFIX(POWER_UART_BIT),
  8875. + PREFIX(POWER_MINIUART_BIT),
  8876. + PREFIX(POWER_USB_BIT),
  8877. + PREFIX(POWER_I2C0_BIT),
  8878. + PREFIX(POWER_I2C1_BIT),
  8879. + PREFIX(POWER_I2C2_BIT),
  8880. + PREFIX(POWER_SPI_BIT),
  8881. + PREFIX(POWER_CCP2TX_BIT),
  8882. + PREFIX(POWER_DSI_BIT),
  8883. +
  8884. + PREFIX(POWER_MAX)
  8885. +};
  8886. +
  8887. +enum {
  8888. + PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)),
  8889. + PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)),
  8890. + PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)),
  8891. + PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)),
  8892. + PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)),
  8893. + PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)),
  8894. + PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)),
  8895. + PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)),
  8896. + PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)),
  8897. + PREFIX(POWER_DSI) = (1 << PREFIX(POWER_DSI_BIT)),
  8898. +
  8899. + PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1,
  8900. + PREFIX(POWER_NONE) = 0
  8901. +};
  8902. +
  8903. +#endif
  8904. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/clkdev.h linux-rpi/arch/arm/mach-bcm2708/include/mach/clkdev.h
  8905. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/clkdev.h 1970-01-01 01:00:00.000000000 +0100
  8906. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/clkdev.h 2015-02-09 04:39:42.000000000 +0100
  8907. @@ -0,0 +1,7 @@
  8908. +#ifndef __ASM_MACH_CLKDEV_H
  8909. +#define __ASM_MACH_CLKDEV_H
  8910. +
  8911. +#define __clk_get(clk) ({ 1; })
  8912. +#define __clk_put(clk) do { } while (0)
  8913. +
  8914. +#endif
  8915. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/debug-macro.S linux-rpi/arch/arm/mach-bcm2708/include/mach/debug-macro.S
  8916. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/debug-macro.S 1970-01-01 01:00:00.000000000 +0100
  8917. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/debug-macro.S 2015-02-09 04:39:42.000000000 +0100
  8918. @@ -0,0 +1,22 @@
  8919. +/* arch/arm/mach-bcm2708/include/mach/debug-macro.S
  8920. + *
  8921. + * Debugging macro include header
  8922. + *
  8923. + * Copyright (C) 2010 Broadcom
  8924. + * Copyright (C) 1994-1999 Russell King
  8925. + * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
  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 version 2 as
  8929. + * published by the Free Software Foundation.
  8930. + *
  8931. +*/
  8932. +
  8933. +#include <mach/platform.h>
  8934. +
  8935. + .macro addruart, rp, rv, tmp
  8936. + ldr \rp, =UART0_BASE
  8937. + ldr \rv, =IO_ADDRESS(UART0_BASE)
  8938. + .endm
  8939. +
  8940. +#include <debug/pl01x.S>
  8941. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/dma.h linux-rpi/arch/arm/mach-bcm2708/include/mach/dma.h
  8942. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
  8943. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/dma.h 2015-02-09 04:39:42.000000000 +0100
  8944. @@ -0,0 +1,94 @@
  8945. +/*
  8946. + * linux/arch/arm/mach-bcm2708/include/mach/dma.h
  8947. + *
  8948. + * Copyright (C) 2010 Broadcom
  8949. + *
  8950. + * This program is free software; you can redistribute it and/or modify
  8951. + * it under the terms of the GNU General Public License version 2 as
  8952. + * published by the Free Software Foundation.
  8953. + */
  8954. +
  8955. +
  8956. +#ifndef _MACH_BCM2708_DMA_H
  8957. +#define _MACH_BCM2708_DMA_H
  8958. +
  8959. +#define BCM_DMAMAN_DRIVER_NAME "bcm2708_dma"
  8960. +
  8961. +/* DMA CS Control and Status bits */
  8962. +#define BCM2708_DMA_ACTIVE (1 << 0)
  8963. +#define BCM2708_DMA_INT (1 << 2)
  8964. +#define BCM2708_DMA_ISPAUSED (1 << 4) /* Pause requested or not active */
  8965. +#define BCM2708_DMA_ISHELD (1 << 5) /* Is held by DREQ flow control */
  8966. +#define BCM2708_DMA_ERR (1 << 8)
  8967. +#define BCM2708_DMA_ABORT (1 << 30) /* stop current CB, go to next, WO */
  8968. +#define BCM2708_DMA_RESET (1 << 31) /* WO, self clearing */
  8969. +
  8970. +/* DMA control block "info" field bits */
  8971. +#define BCM2708_DMA_INT_EN (1 << 0)
  8972. +#define BCM2708_DMA_TDMODE (1 << 1)
  8973. +#define BCM2708_DMA_WAIT_RESP (1 << 3)
  8974. +#define BCM2708_DMA_D_INC (1 << 4)
  8975. +#define BCM2708_DMA_D_WIDTH (1 << 5)
  8976. +#define BCM2708_DMA_D_DREQ (1 << 6)
  8977. +#define BCM2708_DMA_S_INC (1 << 8)
  8978. +#define BCM2708_DMA_S_WIDTH (1 << 9)
  8979. +#define BCM2708_DMA_S_DREQ (1 << 10)
  8980. +
  8981. +#define BCM2708_DMA_BURST(x) (((x)&0xf) << 12)
  8982. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  8983. +#define BCM2708_DMA_WAITS(x) (((x)&0x1f) << 21)
  8984. +
  8985. +#define BCM2708_DMA_DREQ_EMMC 11
  8986. +#define BCM2708_DMA_DREQ_SDHOST 13
  8987. +
  8988. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  8989. +#define BCM2708_DMA_ADDR 0x04
  8990. +/* the current control block appears in the following registers - read only */
  8991. +#define BCM2708_DMA_INFO 0x08
  8992. +#define BCM2708_DMA_SOURCE_AD 0x0c
  8993. +#define BCM2708_DMA_DEST_AD 0x10
  8994. +#define BCM2708_DMA_NEXTCB 0x1C
  8995. +#define BCM2708_DMA_DEBUG 0x20
  8996. +
  8997. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4)+BCM2708_DMA_CS)
  8998. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4)+BCM2708_DMA_ADDR)
  8999. +
  9000. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  9001. +
  9002. +struct bcm2708_dma_cb {
  9003. + unsigned long info;
  9004. + unsigned long src;
  9005. + unsigned long dst;
  9006. + unsigned long length;
  9007. + unsigned long stride;
  9008. + unsigned long next;
  9009. + unsigned long pad[2];
  9010. +};
  9011. +struct scatterlist;
  9012. +
  9013. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  9014. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  9015. + dma_addr_t control_block);
  9016. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  9017. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base);
  9018. +extern int /*rc*/ bcm_dma_abort(void __iomem *dma_chan_base);
  9019. +
  9020. +/* When listing features we can ask for when allocating DMA channels give
  9021. + those with higher priority smaller ordinal numbers */
  9022. +#define BCM_DMA_FEATURE_FAST_ORD 0
  9023. +#define BCM_DMA_FEATURE_BULK_ORD 1
  9024. +#define BCM_DMA_FEATURE_NORMAL_ORD 2
  9025. +#define BCM_DMA_FEATURE_LITE_ORD 3
  9026. +#define BCM_DMA_FEATURE_FAST (1<<BCM_DMA_FEATURE_FAST_ORD)
  9027. +#define BCM_DMA_FEATURE_BULK (1<<BCM_DMA_FEATURE_BULK_ORD)
  9028. +#define BCM_DMA_FEATURE_NORMAL (1<<BCM_DMA_FEATURE_NORMAL_ORD)
  9029. +#define BCM_DMA_FEATURE_LITE (1<<BCM_DMA_FEATURE_LITE_ORD)
  9030. +#define BCM_DMA_FEATURE_COUNT 4
  9031. +
  9032. +/* return channel no or -ve error */
  9033. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  9034. + void __iomem **out_dma_base, int *out_dma_irq);
  9035. +extern int bcm_dma_chan_free(int channel);
  9036. +
  9037. +
  9038. +#endif /* _MACH_BCM2708_DMA_H */
  9039. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/entry-macro.S linux-rpi/arch/arm/mach-bcm2708/include/mach/entry-macro.S
  9040. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/entry-macro.S 1970-01-01 01:00:00.000000000 +0100
  9041. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/entry-macro.S 2015-02-09 04:39:42.000000000 +0100
  9042. @@ -0,0 +1,69 @@
  9043. +/*
  9044. + * arch/arm/mach-bcm2708/include/mach/entry-macro.S
  9045. + *
  9046. + * Low-level IRQ helper macros for BCM2708 platforms
  9047. + *
  9048. + * Copyright (C) 2010 Broadcom
  9049. + *
  9050. + * This program is free software; you can redistribute it and/or modify
  9051. + * it under the terms of the GNU General Public License as published by
  9052. + * the Free Software Foundation; either version 2 of the License, or
  9053. + * (at your option) any later version.
  9054. + *
  9055. + * This program is distributed in the hope that it will be useful,
  9056. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9057. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9058. + * GNU General Public License for more details.
  9059. + *
  9060. + * You should have received a copy of the GNU General Public License
  9061. + * along with this program; if not, write to the Free Software
  9062. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9063. + */
  9064. +#include <mach/hardware.h>
  9065. +
  9066. + .macro disable_fiq
  9067. + .endm
  9068. +
  9069. + .macro get_irqnr_preamble, base, tmp
  9070. + ldr \base, =IO_ADDRESS(ARMCTRL_IC_BASE)
  9071. + .endm
  9072. +
  9073. + .macro arch_ret_to_user, tmp1, tmp2
  9074. + .endm
  9075. +
  9076. + .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
  9077. + /* get masked status */
  9078. + ldr \irqstat, [\base, #(ARM_IRQ_PEND0 - ARMCTRL_IC_BASE)]
  9079. + mov \irqnr, #(ARM_IRQ0_BASE + 31)
  9080. + and \tmp, \irqstat, #0x300 @ save bits 8 and 9
  9081. + /* clear bits 8 and 9, and test */
  9082. + bics \irqstat, \irqstat, #0x300
  9083. + bne 1010f
  9084. +
  9085. + tst \tmp, #0x100
  9086. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND1 - ARMCTRL_IC_BASE)]
  9087. + movne \irqnr, #(ARM_IRQ1_BASE + 31)
  9088. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  9089. + bicne \irqstat, #((1<<7) | (1<<9) | (1<<10))
  9090. + bicne \irqstat, #((1<<18) | (1<<19))
  9091. + bne 1010f
  9092. +
  9093. + tst \tmp, #0x200
  9094. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND2 - ARMCTRL_IC_BASE)]
  9095. + movne \irqnr, #(ARM_IRQ2_BASE + 31)
  9096. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  9097. + bicne \irqstat, #((1<<21) | (1<<22) | (1<<23) | (1<<24) | (1<<25))
  9098. + bicne \irqstat, #((1<<30))
  9099. + beq 1020f
  9100. +
  9101. +1010:
  9102. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  9103. + @ N.B. CLZ is an ARM5 instruction.
  9104. + sub \tmp, \irqstat, #1
  9105. + eor \irqstat, \irqstat, \tmp
  9106. + clz \tmp, \irqstat
  9107. + sub \irqnr, \tmp
  9108. +
  9109. +1020: @ EQ will be set if no irqs pending
  9110. +
  9111. + .endm
  9112. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/frc.h linux-rpi/arch/arm/mach-bcm2708/include/mach/frc.h
  9113. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/frc.h 1970-01-01 01:00:00.000000000 +0100
  9114. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/frc.h 2015-02-09 04:39:42.000000000 +0100
  9115. @@ -0,0 +1,38 @@
  9116. +/*
  9117. + * arch/arm/mach-bcm2708/include/mach/timex.h
  9118. + *
  9119. + * BCM2708 free running counter (timer)
  9120. + *
  9121. + * Copyright (C) 2010 Broadcom
  9122. + *
  9123. + * This program is free software; you can redistribute it and/or modify
  9124. + * it under the terms of the GNU General Public License as published by
  9125. + * the Free Software Foundation; either version 2 of the License, or
  9126. + * (at your option) any later version.
  9127. + *
  9128. + * This program is distributed in the hope that it will be useful,
  9129. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9130. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9131. + * GNU General Public License for more details.
  9132. + *
  9133. + * You should have received a copy of the GNU General Public License
  9134. + * along with this program; if not, write to the Free Software
  9135. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9136. + */
  9137. +
  9138. +#ifndef _MACH_FRC_H
  9139. +#define _MACH_FRC_H
  9140. +
  9141. +#define FRC_TICK_RATE (1000000)
  9142. +
  9143. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  9144. + (slightly faster than frc_clock_ticks63()
  9145. + */
  9146. +extern unsigned long frc_clock_ticks32(void);
  9147. +
  9148. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  9149. + * Note - top bit should be ignored (see cnt32_to_63)
  9150. + */
  9151. +extern unsigned long long frc_clock_ticks63(void);
  9152. +
  9153. +#endif
  9154. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/gpio.h linux-rpi/arch/arm/mach-bcm2708/include/mach/gpio.h
  9155. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/gpio.h 1970-01-01 01:00:00.000000000 +0100
  9156. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/gpio.h 2015-02-09 04:39:42.000000000 +0100
  9157. @@ -0,0 +1,17 @@
  9158. +/*
  9159. + * arch/arm/mach-bcm2708/include/mach/gpio.h
  9160. + *
  9161. + * This file is licensed under the terms of the GNU General Public
  9162. + * License version 2. This program is licensed "as is" without any
  9163. + * warranty of any kind, whether express or implied.
  9164. + */
  9165. +
  9166. +#ifndef __ASM_ARCH_GPIO_H
  9167. +#define __ASM_ARCH_GPIO_H
  9168. +
  9169. +#define BCM2708_NR_GPIOS 54 // number of gpio lines
  9170. +
  9171. +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
  9172. +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
  9173. +
  9174. +#endif
  9175. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/hardware.h linux-rpi/arch/arm/mach-bcm2708/include/mach/hardware.h
  9176. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/hardware.h 1970-01-01 01:00:00.000000000 +0100
  9177. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/hardware.h 2015-02-09 04:39:42.000000000 +0100
  9178. @@ -0,0 +1,28 @@
  9179. +/*
  9180. + * arch/arm/mach-bcm2708/include/mach/hardware.h
  9181. + *
  9182. + * This file contains the hardware definitions of the BCM2708 devices.
  9183. + *
  9184. + * Copyright (C) 2010 Broadcom
  9185. + *
  9186. + * This program is free software; you can redistribute it and/or modify
  9187. + * it under the terms of the GNU General Public License as published by
  9188. + * the Free Software Foundation; either version 2 of the License, or
  9189. + * (at your option) any later version.
  9190. + *
  9191. + * This program is distributed in the hope that it will be useful,
  9192. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9193. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9194. + * GNU General Public License for more details.
  9195. + *
  9196. + * You should have received a copy of the GNU General Public License
  9197. + * along with this program; if not, write to the Free Software
  9198. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9199. + */
  9200. +#ifndef __ASM_ARCH_HARDWARE_H
  9201. +#define __ASM_ARCH_HARDWARE_H
  9202. +
  9203. +#include <asm/sizes.h>
  9204. +#include <mach/platform.h>
  9205. +
  9206. +#endif
  9207. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/io.h linux-rpi/arch/arm/mach-bcm2708/include/mach/io.h
  9208. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/io.h 1970-01-01 01:00:00.000000000 +0100
  9209. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/io.h 2015-02-09 04:39:42.000000000 +0100
  9210. @@ -0,0 +1,27 @@
  9211. +/*
  9212. + * arch/arm/mach-bcm2708/include/mach/io.h
  9213. + *
  9214. + * Copyright (C) 2003 ARM Limited
  9215. + *
  9216. + * This program is free software; you can redistribute it and/or modify
  9217. + * it under the terms of the GNU General Public License as published by
  9218. + * the Free Software Foundation; either version 2 of the License, or
  9219. + * (at your option) any later version.
  9220. + *
  9221. + * This program is distributed in the hope that it will be useful,
  9222. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9223. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9224. + * GNU General Public License for more details.
  9225. + *
  9226. + * You should have received a copy of the GNU General Public License
  9227. + * along with this program; if not, write to the Free Software
  9228. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9229. + */
  9230. +#ifndef __ASM_ARM_ARCH_IO_H
  9231. +#define __ASM_ARM_ARCH_IO_H
  9232. +
  9233. +#define IO_SPACE_LIMIT 0xffffffff
  9234. +
  9235. +#define __io(a) __typesafe_io(a)
  9236. +
  9237. +#endif
  9238. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/irqs.h linux-rpi/arch/arm/mach-bcm2708/include/mach/irqs.h
  9239. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/irqs.h 1970-01-01 01:00:00.000000000 +0100
  9240. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/irqs.h 2015-02-09 04:39:42.000000000 +0100
  9241. @@ -0,0 +1,199 @@
  9242. +/*
  9243. + * arch/arm/mach-bcm2708/include/mach/irqs.h
  9244. + *
  9245. + * Copyright (C) 2010 Broadcom
  9246. + * Copyright (C) 2003 ARM Limited
  9247. + * Copyright (C) 2000 Deep Blue Solutions Ltd.
  9248. + *
  9249. + * This program is free software; you can redistribute it and/or modify
  9250. + * it under the terms of the GNU General Public License as published by
  9251. + * the Free Software Foundation; either version 2 of the License, or
  9252. + * (at your option) any later version.
  9253. + *
  9254. + * This program is distributed in the hope that it will be useful,
  9255. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9256. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9257. + * GNU General Public License for more details.
  9258. + *
  9259. + * You should have received a copy of the GNU General Public License
  9260. + * along with this program; if not, write to the Free Software
  9261. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9262. + */
  9263. +
  9264. +#ifndef _BCM2708_IRQS_H_
  9265. +#define _BCM2708_IRQS_H_
  9266. +
  9267. +#include <mach/platform.h>
  9268. +
  9269. +/*
  9270. + * IRQ interrupts definitions are the same as the INT definitions
  9271. + * held within platform.h
  9272. + */
  9273. +#define IRQ_ARMCTRL_START 0
  9274. +#define IRQ_TIMER0 (IRQ_ARMCTRL_START + INTERRUPT_TIMER0)
  9275. +#define IRQ_TIMER1 (IRQ_ARMCTRL_START + INTERRUPT_TIMER1)
  9276. +#define IRQ_TIMER2 (IRQ_ARMCTRL_START + INTERRUPT_TIMER2)
  9277. +#define IRQ_TIMER3 (IRQ_ARMCTRL_START + INTERRUPT_TIMER3)
  9278. +#define IRQ_CODEC0 (IRQ_ARMCTRL_START + INTERRUPT_CODEC0)
  9279. +#define IRQ_CODEC1 (IRQ_ARMCTRL_START + INTERRUPT_CODEC1)
  9280. +#define IRQ_CODEC2 (IRQ_ARMCTRL_START + INTERRUPT_CODEC2)
  9281. +#define IRQ_JPEG (IRQ_ARMCTRL_START + INTERRUPT_JPEG)
  9282. +#define IRQ_ISP (IRQ_ARMCTRL_START + INTERRUPT_ISP)
  9283. +#define IRQ_USB (IRQ_ARMCTRL_START + INTERRUPT_USB)
  9284. +#define IRQ_3D (IRQ_ARMCTRL_START + INTERRUPT_3D)
  9285. +#define IRQ_TRANSPOSER (IRQ_ARMCTRL_START + INTERRUPT_TRANSPOSER)
  9286. +#define IRQ_MULTICORESYNC0 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC0)
  9287. +#define IRQ_MULTICORESYNC1 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC1)
  9288. +#define IRQ_MULTICORESYNC2 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC2)
  9289. +#define IRQ_MULTICORESYNC3 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC3)
  9290. +#define IRQ_DMA0 (IRQ_ARMCTRL_START + INTERRUPT_DMA0)
  9291. +#define IRQ_DMA1 (IRQ_ARMCTRL_START + INTERRUPT_DMA1)
  9292. +#define IRQ_DMA2 (IRQ_ARMCTRL_START + INTERRUPT_DMA2)
  9293. +#define IRQ_DMA3 (IRQ_ARMCTRL_START + INTERRUPT_DMA3)
  9294. +#define IRQ_DMA4 (IRQ_ARMCTRL_START + INTERRUPT_DMA4)
  9295. +#define IRQ_DMA5 (IRQ_ARMCTRL_START + INTERRUPT_DMA5)
  9296. +#define IRQ_DMA6 (IRQ_ARMCTRL_START + INTERRUPT_DMA6)
  9297. +#define IRQ_DMA7 (IRQ_ARMCTRL_START + INTERRUPT_DMA7)
  9298. +#define IRQ_DMA8 (IRQ_ARMCTRL_START + INTERRUPT_DMA8)
  9299. +#define IRQ_DMA9 (IRQ_ARMCTRL_START + INTERRUPT_DMA9)
  9300. +#define IRQ_DMA10 (IRQ_ARMCTRL_START + INTERRUPT_DMA10)
  9301. +#define IRQ_DMA11 (IRQ_ARMCTRL_START + INTERRUPT_DMA11)
  9302. +#define IRQ_DMA12 (IRQ_ARMCTRL_START + INTERRUPT_DMA12)
  9303. +#define IRQ_AUX (IRQ_ARMCTRL_START + INTERRUPT_AUX)
  9304. +#define IRQ_ARM (IRQ_ARMCTRL_START + INTERRUPT_ARM)
  9305. +#define IRQ_VPUDMA (IRQ_ARMCTRL_START + INTERRUPT_VPUDMA)
  9306. +#define IRQ_HOSTPORT (IRQ_ARMCTRL_START + INTERRUPT_HOSTPORT)
  9307. +#define IRQ_VIDEOSCALER (IRQ_ARMCTRL_START + INTERRUPT_VIDEOSCALER)
  9308. +#define IRQ_CCP2TX (IRQ_ARMCTRL_START + INTERRUPT_CCP2TX)
  9309. +#define IRQ_SDC (IRQ_ARMCTRL_START + INTERRUPT_SDC)
  9310. +#define IRQ_DSI0 (IRQ_ARMCTRL_START + INTERRUPT_DSI0)
  9311. +#define IRQ_AVE (IRQ_ARMCTRL_START + INTERRUPT_AVE)
  9312. +#define IRQ_CAM0 (IRQ_ARMCTRL_START + INTERRUPT_CAM0)
  9313. +#define IRQ_CAM1 (IRQ_ARMCTRL_START + INTERRUPT_CAM1)
  9314. +#define IRQ_HDMI0 (IRQ_ARMCTRL_START + INTERRUPT_HDMI0)
  9315. +#define IRQ_HDMI1 (IRQ_ARMCTRL_START + INTERRUPT_HDMI1)
  9316. +#define IRQ_PIXELVALVE1 (IRQ_ARMCTRL_START + INTERRUPT_PIXELVALVE1)
  9317. +#define IRQ_I2CSPISLV (IRQ_ARMCTRL_START + INTERRUPT_I2CSPISLV)
  9318. +#define IRQ_DSI1 (IRQ_ARMCTRL_START + INTERRUPT_DSI1)
  9319. +#define IRQ_PWA0 (IRQ_ARMCTRL_START + INTERRUPT_PWA0)
  9320. +#define IRQ_PWA1 (IRQ_ARMCTRL_START + INTERRUPT_PWA1)
  9321. +#define IRQ_CPR (IRQ_ARMCTRL_START + INTERRUPT_CPR)
  9322. +#define IRQ_SMI (IRQ_ARMCTRL_START + INTERRUPT_SMI)
  9323. +#define IRQ_GPIO0 (IRQ_ARMCTRL_START + INTERRUPT_GPIO0)
  9324. +#define IRQ_GPIO1 (IRQ_ARMCTRL_START + INTERRUPT_GPIO1)
  9325. +#define IRQ_GPIO2 (IRQ_ARMCTRL_START + INTERRUPT_GPIO2)
  9326. +#define IRQ_GPIO3 (IRQ_ARMCTRL_START + INTERRUPT_GPIO3)
  9327. +#define IRQ_I2C (IRQ_ARMCTRL_START + INTERRUPT_I2C)
  9328. +#define IRQ_SPI (IRQ_ARMCTRL_START + INTERRUPT_SPI)
  9329. +#define IRQ_I2SPCM (IRQ_ARMCTRL_START + INTERRUPT_I2SPCM)
  9330. +#define IRQ_SDIO (IRQ_ARMCTRL_START + INTERRUPT_SDIO)
  9331. +#define IRQ_UART (IRQ_ARMCTRL_START + INTERRUPT_UART)
  9332. +#define IRQ_SLIMBUS (IRQ_ARMCTRL_START + INTERRUPT_SLIMBUS)
  9333. +#define IRQ_VEC (IRQ_ARMCTRL_START + INTERRUPT_VEC)
  9334. +#define IRQ_CPG (IRQ_ARMCTRL_START + INTERRUPT_CPG)
  9335. +#define IRQ_RNG (IRQ_ARMCTRL_START + INTERRUPT_RNG)
  9336. +#define IRQ_ARASANSDIO (IRQ_ARMCTRL_START + INTERRUPT_ARASANSDIO)
  9337. +#define IRQ_AVSPMON (IRQ_ARMCTRL_START + INTERRUPT_AVSPMON)
  9338. +
  9339. +#define IRQ_ARM_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_TIMER)
  9340. +#define IRQ_ARM_MAILBOX (IRQ_ARMCTRL_START + INTERRUPT_ARM_MAILBOX)
  9341. +#define IRQ_ARM_DOORBELL_0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_0)
  9342. +#define IRQ_ARM_DOORBELL_1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_1)
  9343. +#define IRQ_VPU0_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU0_HALTED)
  9344. +#define IRQ_VPU1_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU1_HALTED)
  9345. +#define IRQ_ILLEGAL_TYPE0 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE0)
  9346. +#define IRQ_ILLEGAL_TYPE1 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE1)
  9347. +#define IRQ_PENDING1 (IRQ_ARMCTRL_START + INTERRUPT_PENDING1)
  9348. +#define IRQ_PENDING2 (IRQ_ARMCTRL_START + INTERRUPT_PENDING2)
  9349. +
  9350. +#define FIQ_START HARD_IRQS
  9351. +
  9352. +/*
  9353. + * FIQ interrupts definitions are the same as the INT definitions.
  9354. + */
  9355. +#define FIQ_TIMER0 (FIQ_START+INTERRUPT_TIMER0)
  9356. +#define FIQ_TIMER1 (FIQ_START+INTERRUPT_TIMER1)
  9357. +#define FIQ_TIMER2 (FIQ_START+INTERRUPT_TIMER2)
  9358. +#define FIQ_TIMER3 (FIQ_START+INTERRUPT_TIMER3)
  9359. +#define FIQ_CODEC0 (FIQ_START+INTERRUPT_CODEC0)
  9360. +#define FIQ_CODEC1 (FIQ_START+INTERRUPT_CODEC1)
  9361. +#define FIQ_CODEC2 (FIQ_START+INTERRUPT_CODEC2)
  9362. +#define FIQ_JPEG (FIQ_START+INTERRUPT_JPEG)
  9363. +#define FIQ_ISP (FIQ_START+INTERRUPT_ISP)
  9364. +#define FIQ_USB (FIQ_START+INTERRUPT_USB)
  9365. +#define FIQ_3D (FIQ_START+INTERRUPT_3D)
  9366. +#define FIQ_TRANSPOSER (FIQ_START+INTERRUPT_TRANSPOSER)
  9367. +#define FIQ_MULTICORESYNC0 (FIQ_START+INTERRUPT_MULTICORESYNC0)
  9368. +#define FIQ_MULTICORESYNC1 (FIQ_START+INTERRUPT_MULTICORESYNC1)
  9369. +#define FIQ_MULTICORESYNC2 (FIQ_START+INTERRUPT_MULTICORESYNC2)
  9370. +#define FIQ_MULTICORESYNC3 (FIQ_START+INTERRUPT_MULTICORESYNC3)
  9371. +#define FIQ_DMA0 (FIQ_START+INTERRUPT_DMA0)
  9372. +#define FIQ_DMA1 (FIQ_START+INTERRUPT_DMA1)
  9373. +#define FIQ_DMA2 (FIQ_START+INTERRUPT_DMA2)
  9374. +#define FIQ_DMA3 (FIQ_START+INTERRUPT_DMA3)
  9375. +#define FIQ_DMA4 (FIQ_START+INTERRUPT_DMA4)
  9376. +#define FIQ_DMA5 (FIQ_START+INTERRUPT_DMA5)
  9377. +#define FIQ_DMA6 (FIQ_START+INTERRUPT_DMA6)
  9378. +#define FIQ_DMA7 (FIQ_START+INTERRUPT_DMA7)
  9379. +#define FIQ_DMA8 (FIQ_START+INTERRUPT_DMA8)
  9380. +#define FIQ_DMA9 (FIQ_START+INTERRUPT_DMA9)
  9381. +#define FIQ_DMA10 (FIQ_START+INTERRUPT_DMA10)
  9382. +#define FIQ_DMA11 (FIQ_START+INTERRUPT_DMA11)
  9383. +#define FIQ_DMA12 (FIQ_START+INTERRUPT_DMA12)
  9384. +#define FIQ_AUX (FIQ_START+INTERRUPT_AUX)
  9385. +#define FIQ_ARM (FIQ_START+INTERRUPT_ARM)
  9386. +#define FIQ_VPUDMA (FIQ_START+INTERRUPT_VPUDMA)
  9387. +#define FIQ_HOSTPORT (FIQ_START+INTERRUPT_HOSTPORT)
  9388. +#define FIQ_VIDEOSCALER (FIQ_START+INTERRUPT_VIDEOSCALER)
  9389. +#define FIQ_CCP2TX (FIQ_START+INTERRUPT_CCP2TX)
  9390. +#define FIQ_SDC (FIQ_START+INTERRUPT_SDC)
  9391. +#define FIQ_DSI0 (FIQ_START+INTERRUPT_DSI0)
  9392. +#define FIQ_AVE (FIQ_START+INTERRUPT_AVE)
  9393. +#define FIQ_CAM0 (FIQ_START+INTERRUPT_CAM0)
  9394. +#define FIQ_CAM1 (FIQ_START+INTERRUPT_CAM1)
  9395. +#define FIQ_HDMI0 (FIQ_START+INTERRUPT_HDMI0)
  9396. +#define FIQ_HDMI1 (FIQ_START+INTERRUPT_HDMI1)
  9397. +#define FIQ_PIXELVALVE1 (FIQ_START+INTERRUPT_PIXELVALVE1)
  9398. +#define FIQ_I2CSPISLV (FIQ_START+INTERRUPT_I2CSPISLV)
  9399. +#define FIQ_DSI1 (FIQ_START+INTERRUPT_DSI1)
  9400. +#define FIQ_PWA0 (FIQ_START+INTERRUPT_PWA0)
  9401. +#define FIQ_PWA1 (FIQ_START+INTERRUPT_PWA1)
  9402. +#define FIQ_CPR (FIQ_START+INTERRUPT_CPR)
  9403. +#define FIQ_SMI (FIQ_START+INTERRUPT_SMI)
  9404. +#define FIQ_GPIO0 (FIQ_START+INTERRUPT_GPIO0)
  9405. +#define FIQ_GPIO1 (FIQ_START+INTERRUPT_GPIO1)
  9406. +#define FIQ_GPIO2 (FIQ_START+INTERRUPT_GPIO2)
  9407. +#define FIQ_GPIO3 (FIQ_START+INTERRUPT_GPIO3)
  9408. +#define FIQ_I2C (FIQ_START+INTERRUPT_I2C)
  9409. +#define FIQ_SPI (FIQ_START+INTERRUPT_SPI)
  9410. +#define FIQ_I2SPCM (FIQ_START+INTERRUPT_I2SPCM)
  9411. +#define FIQ_SDIO (FIQ_START+INTERRUPT_SDIO)
  9412. +#define FIQ_UART (FIQ_START+INTERRUPT_UART)
  9413. +#define FIQ_SLIMBUS (FIQ_START+INTERRUPT_SLIMBUS)
  9414. +#define FIQ_VEC (FIQ_START+INTERRUPT_VEC)
  9415. +#define FIQ_CPG (FIQ_START+INTERRUPT_CPG)
  9416. +#define FIQ_RNG (FIQ_START+INTERRUPT_RNG)
  9417. +#define FIQ_ARASANSDIO (FIQ_START+INTERRUPT_ARASANSDIO)
  9418. +#define FIQ_AVSPMON (FIQ_START+INTERRUPT_AVSPMON)
  9419. +
  9420. +#define FIQ_ARM_TIMER (FIQ_START+INTERRUPT_ARM_TIMER)
  9421. +#define FIQ_ARM_MAILBOX (FIQ_START+INTERRUPT_ARM_MAILBOX)
  9422. +#define FIQ_ARM_DOORBELL_0 (FIQ_START+INTERRUPT_ARM_DOORBELL_0)
  9423. +#define FIQ_ARM_DOORBELL_1 (FIQ_START+INTERRUPT_ARM_DOORBELL_1)
  9424. +#define FIQ_VPU0_HALTED (FIQ_START+INTERRUPT_VPU0_HALTED)
  9425. +#define FIQ_VPU1_HALTED (FIQ_START+INTERRUPT_VPU1_HALTED)
  9426. +#define FIQ_ILLEGAL_TYPE0 (FIQ_START+INTERRUPT_ILLEGAL_TYPE0)
  9427. +#define FIQ_ILLEGAL_TYPE1 (FIQ_START+INTERRUPT_ILLEGAL_TYPE1)
  9428. +#define FIQ_PENDING1 (FIQ_START+INTERRUPT_PENDING1)
  9429. +#define FIQ_PENDING2 (FIQ_START+INTERRUPT_PENDING2)
  9430. +
  9431. +#define HARD_IRQS (64 + 21)
  9432. +#define FIQ_IRQS (64 + 21)
  9433. +#define GPIO_IRQ_START (HARD_IRQS + FIQ_IRQS)
  9434. +#define GPIO_IRQS (32*5)
  9435. +#define SPARE_ALLOC_IRQS 64
  9436. +#define BCM2708_ALLOC_IRQS (HARD_IRQS+FIQ_IRQS+GPIO_IRQS+SPARE_ALLOC_IRQS)
  9437. +#define FREE_IRQS 128
  9438. +#define NR_IRQS (BCM2708_ALLOC_IRQS+FREE_IRQS)
  9439. +
  9440. +#endif /* _BCM2708_IRQS_H_ */
  9441. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/memory.h linux-rpi/arch/arm/mach-bcm2708/include/mach/memory.h
  9442. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/memory.h 1970-01-01 01:00:00.000000000 +0100
  9443. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/memory.h 2015-02-09 04:39:42.000000000 +0100
  9444. @@ -0,0 +1,57 @@
  9445. +/*
  9446. + * arch/arm/mach-bcm2708/include/mach/memory.h
  9447. + *
  9448. + * Copyright (C) 2010 Broadcom
  9449. + *
  9450. + * This program is free software; you can redistribute it and/or modify
  9451. + * it under the terms of the GNU General Public License as published by
  9452. + * the Free Software Foundation; either version 2 of the License, or
  9453. + * (at your option) any later version.
  9454. + *
  9455. + * This program is distributed in the hope that it will be useful,
  9456. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9457. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9458. + * GNU General Public License for more details.
  9459. + *
  9460. + * You should have received a copy of the GNU General Public License
  9461. + * along with this program; if not, write to the Free Software
  9462. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9463. + */
  9464. +#ifndef __ASM_ARCH_MEMORY_H
  9465. +#define __ASM_ARCH_MEMORY_H
  9466. +
  9467. +/* Memory overview:
  9468. +
  9469. + [ARMcore] <--virtual addr-->
  9470. + [ARMmmu] <--physical addr-->
  9471. + [GERTmap] <--bus add-->
  9472. + [VCperiph]
  9473. +
  9474. +*/
  9475. +
  9476. +/*
  9477. + * Physical DRAM offset.
  9478. + */
  9479. +#define BCM_PLAT_PHYS_OFFSET UL(0x00000000)
  9480. +#define VC_ARMMEM_OFFSET UL(0x00000000) /* offset in VC of ARM memory */
  9481. +
  9482. +#ifdef CONFIG_BCM2708_NOL2CACHE
  9483. + #define _REAL_BUS_OFFSET UL(0xC0000000) /* don't use L1 or L2 caches */
  9484. +#else
  9485. + #define _REAL_BUS_OFFSET UL(0x40000000) /* use L2 cache */
  9486. +#endif
  9487. +
  9488. +/* We're using the memory at 64M in the VideoCore for Linux - this adjustment
  9489. + * will provide the offset into this area as well as setting the bits that
  9490. + * stop the L1 and L2 cache from being used
  9491. + *
  9492. + * WARNING: this only works because the ARM is given memory at a fixed location
  9493. + * (ARMMEM_OFFSET)
  9494. + */
  9495. +#define BUS_OFFSET (VC_ARMMEM_OFFSET + _REAL_BUS_OFFSET)
  9496. +#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
  9497. +#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
  9498. +#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - BCM_PLAT_PHYS_OFFSET))
  9499. +#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - BCM_PLAT_PHYS_OFFSET))
  9500. +
  9501. +#endif
  9502. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/platform.h linux-rpi/arch/arm/mach-bcm2708/include/mach/platform.h
  9503. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/platform.h 1970-01-01 01:00:00.000000000 +0100
  9504. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/platform.h 2015-02-09 04:39:42.000000000 +0100
  9505. @@ -0,0 +1,228 @@
  9506. +/*
  9507. + * arch/arm/mach-bcm2708/include/mach/platform.h
  9508. + *
  9509. + * Copyright (C) 2010 Broadcom
  9510. + *
  9511. + * This program is free software; you can redistribute it and/or modify
  9512. + * it under the terms of the GNU General Public License as published by
  9513. + * the Free Software Foundation; either version 2 of the License, or
  9514. + * (at your option) any later version.
  9515. + *
  9516. + * This program is distributed in the hope that it will be useful,
  9517. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9518. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9519. + * GNU General Public License for more details.
  9520. + *
  9521. + * You should have received a copy of the GNU General Public License
  9522. + * along with this program; if not, write to the Free Software
  9523. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9524. + */
  9525. +
  9526. +#ifndef _BCM2708_PLATFORM_H
  9527. +#define _BCM2708_PLATFORM_H
  9528. +
  9529. +
  9530. +/* macros to get at IO space when running virtually */
  9531. +#define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  9532. +
  9533. +#define __io_address(n) IOMEM(IO_ADDRESS(n))
  9534. +
  9535. +
  9536. +/*
  9537. + * SDRAM
  9538. + */
  9539. +#define BCM2708_SDRAM_BASE 0x00000000
  9540. +
  9541. +/*
  9542. + * Logic expansion modules
  9543. + *
  9544. + */
  9545. +
  9546. +
  9547. +/* ------------------------------------------------------------------------
  9548. + * BCM2708 ARMCTRL Registers
  9549. + * ------------------------------------------------------------------------
  9550. + */
  9551. +
  9552. +#define HW_REGISTER_RW(addr) (addr)
  9553. +#define HW_REGISTER_RO(addr) (addr)
  9554. +
  9555. +#include "arm_control.h"
  9556. +#undef ARM_BASE
  9557. +
  9558. +/*
  9559. + * Definitions and addresses for the ARM CONTROL logic
  9560. + * This file is manually generated.
  9561. + */
  9562. +
  9563. +#define BCM2708_PERI_BASE 0x20000000
  9564. +#define IC0_BASE (BCM2708_PERI_BASE + 0x2000)
  9565. +#define ST_BASE (BCM2708_PERI_BASE + 0x3000) /* System Timer */
  9566. +#define MPHI_BASE (BCM2708_PERI_BASE + 0x6000) /* Message -based Parallel Host Interface */
  9567. +#define DMA_BASE (BCM2708_PERI_BASE + 0x7000) /* DMA controller */
  9568. +#define ARM_BASE (BCM2708_PERI_BASE + 0xB000) /* BCM2708 ARM control block */
  9569. +#define PM_BASE (BCM2708_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */
  9570. +#define PCM_CLOCK_BASE (BCM2708_PERI_BASE + 0x101098) /* PCM Clock */
  9571. +#define RNG_BASE (BCM2708_PERI_BASE + 0x104000) /* Hardware RNG */
  9572. +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO */
  9573. +#define UART0_BASE (BCM2708_PERI_BASE + 0x201000) /* Uart 0 */
  9574. +#define MMCI0_BASE (BCM2708_PERI_BASE + 0x202000) /* MMC interface */
  9575. +#define I2S_BASE (BCM2708_PERI_BASE + 0x203000) /* I2S */
  9576. +#define SPI0_BASE (BCM2708_PERI_BASE + 0x204000) /* SPI0 */
  9577. +#define BSC0_BASE (BCM2708_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */
  9578. +#define UART1_BASE (BCM2708_PERI_BASE + 0x215000) /* Uart 1 */
  9579. +#define EMMC_BASE (BCM2708_PERI_BASE + 0x300000) /* eMMC interface */
  9580. +#define SMI_BASE (BCM2708_PERI_BASE + 0x600000) /* SMI */
  9581. +#define BSC1_BASE (BCM2708_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */
  9582. +#define USB_BASE (BCM2708_PERI_BASE + 0x980000) /* DTC_OTG USB controller */
  9583. +#define MCORE_BASE (BCM2708_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/
  9584. +
  9585. +#define ARMCTRL_BASE (ARM_BASE + 0x000)
  9586. +#define ARMCTRL_IC_BASE (ARM_BASE + 0x200) /* ARM interrupt controller */
  9587. +#define ARMCTRL_TIMER0_1_BASE (ARM_BASE + 0x400) /* Timer 0 and 1 */
  9588. +#define ARMCTRL_0_SBM_BASE (ARM_BASE + 0x800) /* User 0 (ARM)'s Semaphores Doorbells and Mailboxes */
  9589. +
  9590. +
  9591. +/*
  9592. + * Interrupt assignments
  9593. + */
  9594. +
  9595. +#define ARM_IRQ1_BASE 0
  9596. +#define INTERRUPT_TIMER0 (ARM_IRQ1_BASE + 0)
  9597. +#define INTERRUPT_TIMER1 (ARM_IRQ1_BASE + 1)
  9598. +#define INTERRUPT_TIMER2 (ARM_IRQ1_BASE + 2)
  9599. +#define INTERRUPT_TIMER3 (ARM_IRQ1_BASE + 3)
  9600. +#define INTERRUPT_CODEC0 (ARM_IRQ1_BASE + 4)
  9601. +#define INTERRUPT_CODEC1 (ARM_IRQ1_BASE + 5)
  9602. +#define INTERRUPT_CODEC2 (ARM_IRQ1_BASE + 6)
  9603. +#define INTERRUPT_VC_JPEG (ARM_IRQ1_BASE + 7)
  9604. +#define INTERRUPT_ISP (ARM_IRQ1_BASE + 8)
  9605. +#define INTERRUPT_VC_USB (ARM_IRQ1_BASE + 9)
  9606. +#define INTERRUPT_VC_3D (ARM_IRQ1_BASE + 10)
  9607. +#define INTERRUPT_TRANSPOSER (ARM_IRQ1_BASE + 11)
  9608. +#define INTERRUPT_MULTICORESYNC0 (ARM_IRQ1_BASE + 12)
  9609. +#define INTERRUPT_MULTICORESYNC1 (ARM_IRQ1_BASE + 13)
  9610. +#define INTERRUPT_MULTICORESYNC2 (ARM_IRQ1_BASE + 14)
  9611. +#define INTERRUPT_MULTICORESYNC3 (ARM_IRQ1_BASE + 15)
  9612. +#define INTERRUPT_DMA0 (ARM_IRQ1_BASE + 16)
  9613. +#define INTERRUPT_DMA1 (ARM_IRQ1_BASE + 17)
  9614. +#define INTERRUPT_VC_DMA2 (ARM_IRQ1_BASE + 18)
  9615. +#define INTERRUPT_VC_DMA3 (ARM_IRQ1_BASE + 19)
  9616. +#define INTERRUPT_DMA4 (ARM_IRQ1_BASE + 20)
  9617. +#define INTERRUPT_DMA5 (ARM_IRQ1_BASE + 21)
  9618. +#define INTERRUPT_DMA6 (ARM_IRQ1_BASE + 22)
  9619. +#define INTERRUPT_DMA7 (ARM_IRQ1_BASE + 23)
  9620. +#define INTERRUPT_DMA8 (ARM_IRQ1_BASE + 24)
  9621. +#define INTERRUPT_DMA9 (ARM_IRQ1_BASE + 25)
  9622. +#define INTERRUPT_DMA10 (ARM_IRQ1_BASE + 26)
  9623. +#define INTERRUPT_DMA11 (ARM_IRQ1_BASE + 27)
  9624. +#define INTERRUPT_DMA12 (ARM_IRQ1_BASE + 28)
  9625. +#define INTERRUPT_AUX (ARM_IRQ1_BASE + 29)
  9626. +#define INTERRUPT_ARM (ARM_IRQ1_BASE + 30)
  9627. +#define INTERRUPT_VPUDMA (ARM_IRQ1_BASE + 31)
  9628. +
  9629. +#define ARM_IRQ2_BASE 32
  9630. +#define INTERRUPT_HOSTPORT (ARM_IRQ2_BASE + 0)
  9631. +#define INTERRUPT_VIDEOSCALER (ARM_IRQ2_BASE + 1)
  9632. +#define INTERRUPT_CCP2TX (ARM_IRQ2_BASE + 2)
  9633. +#define INTERRUPT_SDC (ARM_IRQ2_BASE + 3)
  9634. +#define INTERRUPT_DSI0 (ARM_IRQ2_BASE + 4)
  9635. +#define INTERRUPT_AVE (ARM_IRQ2_BASE + 5)
  9636. +#define INTERRUPT_CAM0 (ARM_IRQ2_BASE + 6)
  9637. +#define INTERRUPT_CAM1 (ARM_IRQ2_BASE + 7)
  9638. +#define INTERRUPT_HDMI0 (ARM_IRQ2_BASE + 8)
  9639. +#define INTERRUPT_HDMI1 (ARM_IRQ2_BASE + 9)
  9640. +#define INTERRUPT_PIXELVALVE1 (ARM_IRQ2_BASE + 10)
  9641. +#define INTERRUPT_I2CSPISLV (ARM_IRQ2_BASE + 11)
  9642. +#define INTERRUPT_DSI1 (ARM_IRQ2_BASE + 12)
  9643. +#define INTERRUPT_PWA0 (ARM_IRQ2_BASE + 13)
  9644. +#define INTERRUPT_PWA1 (ARM_IRQ2_BASE + 14)
  9645. +#define INTERRUPT_CPR (ARM_IRQ2_BASE + 15)
  9646. +#define INTERRUPT_SMI (ARM_IRQ2_BASE + 16)
  9647. +#define INTERRUPT_GPIO0 (ARM_IRQ2_BASE + 17)
  9648. +#define INTERRUPT_GPIO1 (ARM_IRQ2_BASE + 18)
  9649. +#define INTERRUPT_GPIO2 (ARM_IRQ2_BASE + 19)
  9650. +#define INTERRUPT_GPIO3 (ARM_IRQ2_BASE + 20)
  9651. +#define INTERRUPT_VC_I2C (ARM_IRQ2_BASE + 21)
  9652. +#define INTERRUPT_VC_SPI (ARM_IRQ2_BASE + 22)
  9653. +#define INTERRUPT_VC_I2SPCM (ARM_IRQ2_BASE + 23)
  9654. +#define INTERRUPT_VC_SDIO (ARM_IRQ2_BASE + 24)
  9655. +#define INTERRUPT_VC_UART (ARM_IRQ2_BASE + 25)
  9656. +#define INTERRUPT_SLIMBUS (ARM_IRQ2_BASE + 26)
  9657. +#define INTERRUPT_VEC (ARM_IRQ2_BASE + 27)
  9658. +#define INTERRUPT_CPG (ARM_IRQ2_BASE + 28)
  9659. +#define INTERRUPT_RNG (ARM_IRQ2_BASE + 29)
  9660. +#define INTERRUPT_VC_ARASANSDIO (ARM_IRQ2_BASE + 30)
  9661. +#define INTERRUPT_AVSPMON (ARM_IRQ2_BASE + 31)
  9662. +
  9663. +#define ARM_IRQ0_BASE 64
  9664. +#define INTERRUPT_ARM_TIMER (ARM_IRQ0_BASE + 0)
  9665. +#define INTERRUPT_ARM_MAILBOX (ARM_IRQ0_BASE + 1)
  9666. +#define INTERRUPT_ARM_DOORBELL_0 (ARM_IRQ0_BASE + 2)
  9667. +#define INTERRUPT_ARM_DOORBELL_1 (ARM_IRQ0_BASE + 3)
  9668. +#define INTERRUPT_VPU0_HALTED (ARM_IRQ0_BASE + 4)
  9669. +#define INTERRUPT_VPU1_HALTED (ARM_IRQ0_BASE + 5)
  9670. +#define INTERRUPT_ILLEGAL_TYPE0 (ARM_IRQ0_BASE + 6)
  9671. +#define INTERRUPT_ILLEGAL_TYPE1 (ARM_IRQ0_BASE + 7)
  9672. +#define INTERRUPT_PENDING1 (ARM_IRQ0_BASE + 8)
  9673. +#define INTERRUPT_PENDING2 (ARM_IRQ0_BASE + 9)
  9674. +#define INTERRUPT_JPEG (ARM_IRQ0_BASE + 10)
  9675. +#define INTERRUPT_USB (ARM_IRQ0_BASE + 11)
  9676. +#define INTERRUPT_3D (ARM_IRQ0_BASE + 12)
  9677. +#define INTERRUPT_DMA2 (ARM_IRQ0_BASE + 13)
  9678. +#define INTERRUPT_DMA3 (ARM_IRQ0_BASE + 14)
  9679. +#define INTERRUPT_I2C (ARM_IRQ0_BASE + 15)
  9680. +#define INTERRUPT_SPI (ARM_IRQ0_BASE + 16)
  9681. +#define INTERRUPT_I2SPCM (ARM_IRQ0_BASE + 17)
  9682. +#define INTERRUPT_SDIO (ARM_IRQ0_BASE + 18)
  9683. +#define INTERRUPT_UART (ARM_IRQ0_BASE + 19)
  9684. +#define INTERRUPT_ARASANSDIO (ARM_IRQ0_BASE + 20)
  9685. +
  9686. +#define MAXIRQNUM (32 + 32 + 20)
  9687. +#define MAXFIQNUM (32 + 32 + 20)
  9688. +
  9689. +#define MAX_TIMER 2
  9690. +#define MAX_PERIOD 699050
  9691. +#define TICKS_PER_uSEC 1
  9692. +
  9693. +/*
  9694. + * These are useconds NOT ticks.
  9695. + *
  9696. + */
  9697. +#define mSEC_1 1000
  9698. +#define mSEC_5 (mSEC_1 * 5)
  9699. +#define mSEC_10 (mSEC_1 * 10)
  9700. +#define mSEC_25 (mSEC_1 * 25)
  9701. +#define SEC_1 (mSEC_1 * 1000)
  9702. +
  9703. +/*
  9704. + * Watchdog
  9705. + */
  9706. +#define PM_RSTC (PM_BASE+0x1c)
  9707. +#define PM_RSTS (PM_BASE+0x20)
  9708. +#define PM_WDOG (PM_BASE+0x24)
  9709. +
  9710. +#define PM_WDOG_RESET 0000000000
  9711. +#define PM_PASSWORD 0x5a000000
  9712. +#define PM_WDOG_TIME_SET 0x000fffff
  9713. +#define PM_RSTC_WRCFG_CLR 0xffffffcf
  9714. +#define PM_RSTC_WRCFG_SET 0x00000030
  9715. +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  9716. +#define PM_RSTC_RESET 0x00000102
  9717. +
  9718. +#define PM_RSTS_HADPOR_SET 0x00001000
  9719. +#define PM_RSTS_HADSRH_SET 0x00000400
  9720. +#define PM_RSTS_HADSRF_SET 0x00000200
  9721. +#define PM_RSTS_HADSRQ_SET 0x00000100
  9722. +#define PM_RSTS_HADWRH_SET 0x00000040
  9723. +#define PM_RSTS_HADWRF_SET 0x00000020
  9724. +#define PM_RSTS_HADWRQ_SET 0x00000010
  9725. +#define PM_RSTS_HADDRH_SET 0x00000004
  9726. +#define PM_RSTS_HADDRF_SET 0x00000002
  9727. +#define PM_RSTS_HADDRQ_SET 0x00000001
  9728. +
  9729. +#define UART0_CLOCK 3000000
  9730. +
  9731. +#endif
  9732. +
  9733. +/* END */
  9734. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/power.h linux-rpi/arch/arm/mach-bcm2708/include/mach/power.h
  9735. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/power.h 1970-01-01 01:00:00.000000000 +0100
  9736. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/power.h 2015-02-09 04:39:42.000000000 +0100
  9737. @@ -0,0 +1,26 @@
  9738. +/*
  9739. + * linux/arch/arm/mach-bcm2708/power.h
  9740. + *
  9741. + * Copyright (C) 2010 Broadcom
  9742. + *
  9743. + * This program is free software; you can redistribute it and/or modify
  9744. + * it under the terms of the GNU General Public License version 2 as
  9745. + * published by the Free Software Foundation.
  9746. + *
  9747. + * This device provides a shared mechanism for controlling the power to
  9748. + * VideoCore subsystems.
  9749. + */
  9750. +
  9751. +#ifndef _MACH_BCM2708_POWER_H
  9752. +#define _MACH_BCM2708_POWER_H
  9753. +
  9754. +#include <linux/types.h>
  9755. +#include <mach/arm_power.h>
  9756. +
  9757. +typedef unsigned int BCM_POWER_HANDLE_T;
  9758. +
  9759. +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle);
  9760. +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request);
  9761. +extern int bcm_power_close(BCM_POWER_HANDLE_T handle);
  9762. +
  9763. +#endif
  9764. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/system.h linux-rpi/arch/arm/mach-bcm2708/include/mach/system.h
  9765. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/system.h 1970-01-01 01:00:00.000000000 +0100
  9766. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/system.h 2015-02-09 04:39:42.000000000 +0100
  9767. @@ -0,0 +1,38 @@
  9768. +/*
  9769. + * arch/arm/mach-bcm2708/include/mach/system.h
  9770. + *
  9771. + * Copyright (C) 2010 Broadcom
  9772. + * Copyright (C) 2003 ARM Limited
  9773. + * Copyright (C) 2000 Deep Blue Solutions Ltd
  9774. + *
  9775. + * This program is free software; you can redistribute it and/or modify
  9776. + * it under the terms of the GNU General Public License as published by
  9777. + * the Free Software Foundation; either version 2 of the License, or
  9778. + * (at your option) any later version.
  9779. + *
  9780. + * This program is distributed in the hope that it will be useful,
  9781. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9782. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9783. + * GNU General Public License for more details.
  9784. + *
  9785. + * You should have received a copy of the GNU General Public License
  9786. + * along with this program; if not, write to the Free Software
  9787. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9788. + */
  9789. +#ifndef __ASM_ARCH_SYSTEM_H
  9790. +#define __ASM_ARCH_SYSTEM_H
  9791. +
  9792. +#include <linux/io.h>
  9793. +#include <mach/hardware.h>
  9794. +#include <mach/platform.h>
  9795. +
  9796. +static inline void arch_idle(void)
  9797. +{
  9798. + /*
  9799. + * This should do all the clock switching
  9800. + * and wait for interrupt tricks
  9801. + */
  9802. + cpu_do_idle();
  9803. +}
  9804. +
  9805. +#endif
  9806. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/timex.h linux-rpi/arch/arm/mach-bcm2708/include/mach/timex.h
  9807. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/timex.h 1970-01-01 01:00:00.000000000 +0100
  9808. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/timex.h 2015-02-09 04:39:42.000000000 +0100
  9809. @@ -0,0 +1,23 @@
  9810. +/*
  9811. + * arch/arm/mach-bcm2708/include/mach/timex.h
  9812. + *
  9813. + * BCM2708 sysem clock frequency
  9814. + *
  9815. + * Copyright (C) 2010 Broadcom
  9816. + *
  9817. + * This program is free software; you can redistribute it and/or modify
  9818. + * it under the terms of the GNU General Public License as published by
  9819. + * the Free Software Foundation; either version 2 of the License, or
  9820. + * (at your option) any later version.
  9821. + *
  9822. + * This program is distributed in the hope that it will be useful,
  9823. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9824. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9825. + * GNU General Public License for more details.
  9826. + *
  9827. + * You should have received a copy of the GNU General Public License
  9828. + * along with this program; if not, write to the Free Software
  9829. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9830. + */
  9831. +
  9832. +#define CLOCK_TICK_RATE (1000000)
  9833. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/uncompress.h linux-rpi/arch/arm/mach-bcm2708/include/mach/uncompress.h
  9834. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/uncompress.h 1970-01-01 01:00:00.000000000 +0100
  9835. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/uncompress.h 2015-02-09 04:39:42.000000000 +0100
  9836. @@ -0,0 +1,84 @@
  9837. +/*
  9838. + * arch/arm/mach-bcn2708/include/mach/uncompress.h
  9839. + *
  9840. + * Copyright (C) 2010 Broadcom
  9841. + * Copyright (C) 2003 ARM Limited
  9842. + *
  9843. + * This program is free software; you can redistribute it and/or modify
  9844. + * it under the terms of the GNU General Public License as published by
  9845. + * the Free Software Foundation; either version 2 of the License, or
  9846. + * (at your option) any later version.
  9847. + *
  9848. + * This program is distributed in the hope that it will be useful,
  9849. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9850. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9851. + * GNU General Public License for more details.
  9852. + *
  9853. + * You should have received a copy of the GNU General Public License
  9854. + * along with this program; if not, write to the Free Software
  9855. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9856. + */
  9857. +
  9858. +#include <linux/io.h>
  9859. +#include <linux/amba/serial.h>
  9860. +#include <mach/hardware.h>
  9861. +
  9862. +#define UART_BAUD 115200
  9863. +
  9864. +#define BCM2708_UART_DR __io(UART0_BASE + UART01x_DR)
  9865. +#define BCM2708_UART_FR __io(UART0_BASE + UART01x_FR)
  9866. +#define BCM2708_UART_IBRD __io(UART0_BASE + UART011_IBRD)
  9867. +#define BCM2708_UART_FBRD __io(UART0_BASE + UART011_FBRD)
  9868. +#define BCM2708_UART_LCRH __io(UART0_BASE + UART011_LCRH)
  9869. +#define BCM2708_UART_CR __io(UART0_BASE + UART011_CR)
  9870. +
  9871. +/*
  9872. + * This does not append a newline
  9873. + */
  9874. +static inline void putc(int c)
  9875. +{
  9876. + while (__raw_readl(BCM2708_UART_FR) & UART01x_FR_TXFF)
  9877. + barrier();
  9878. +
  9879. + __raw_writel(c, BCM2708_UART_DR);
  9880. +}
  9881. +
  9882. +static inline void flush(void)
  9883. +{
  9884. + int fr;
  9885. +
  9886. + do {
  9887. + fr = __raw_readl(BCM2708_UART_FR);
  9888. + barrier();
  9889. + } while ((fr & (UART011_FR_TXFE | UART01x_FR_BUSY)) != UART011_FR_TXFE);
  9890. +}
  9891. +
  9892. +static inline void arch_decomp_setup(void)
  9893. +{
  9894. + int temp, div, rem, frac;
  9895. +
  9896. + temp = 16 * UART_BAUD;
  9897. + div = UART0_CLOCK / temp;
  9898. + rem = UART0_CLOCK % temp;
  9899. + temp = (8 * rem) / UART_BAUD;
  9900. + frac = (temp >> 1) + (temp & 1);
  9901. +
  9902. + /* Make sure the UART is disabled before we start */
  9903. + __raw_writel(0, BCM2708_UART_CR);
  9904. +
  9905. + /* Set the baud rate */
  9906. + __raw_writel(div, BCM2708_UART_IBRD);
  9907. + __raw_writel(frac, BCM2708_UART_FBRD);
  9908. +
  9909. + /* Set the UART to 8n1, FIFO enabled */
  9910. + __raw_writel(UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN, BCM2708_UART_LCRH);
  9911. +
  9912. + /* Enable the UART */
  9913. + __raw_writel(UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE,
  9914. + BCM2708_UART_CR);
  9915. +}
  9916. +
  9917. +/*
  9918. + * nothing to do
  9919. + */
  9920. +#define arch_decomp_wdog()
  9921. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/vcio.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vcio.h
  9922. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/vcio.h 1970-01-01 01:00:00.000000000 +0100
  9923. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vcio.h 2015-02-09 04:39:42.000000000 +0100
  9924. @@ -0,0 +1,165 @@
  9925. +/*
  9926. + * arch/arm/mach-bcm2708/include/mach/vcio.h
  9927. + *
  9928. + * Copyright (C) 2010 Broadcom
  9929. + *
  9930. + * This program is free software; you can redistribute it and/or modify
  9931. + * it under the terms of the GNU General Public License as published by
  9932. + * the Free Software Foundation; either version 2 of the License, or
  9933. + * (at your option) any later version.
  9934. + *
  9935. + * This program is distributed in the hope that it will be useful,
  9936. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9937. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9938. + * GNU General Public License for more details.
  9939. + *
  9940. + * You should have received a copy of the GNU General Public License
  9941. + * along with this program; if not, write to the Free Software
  9942. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9943. + */
  9944. +#ifndef _MACH_BCM2708_VCIO_H
  9945. +#define _MACH_BCM2708_VCIO_H
  9946. +
  9947. +/* Routines to handle I/O via the VideoCore "ARM control" registers
  9948. + * (semaphores, doorbells, mailboxes)
  9949. + */
  9950. +
  9951. +#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
  9952. +
  9953. +/* Constants shared with the ARM identifying separate mailbox channels */
  9954. +#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
  9955. +#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
  9956. +#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
  9957. +#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
  9958. +#define MBOX_CHAN_COUNT 9
  9959. +
  9960. +enum {
  9961. + VCMSG_PROCESS_REQUEST = 0x00000000
  9962. +};
  9963. +enum {
  9964. + VCMSG_REQUEST_SUCCESSFUL = 0x80000000,
  9965. + VCMSG_REQUEST_FAILED = 0x80000001
  9966. +};
  9967. +/* Mailbox property tags */
  9968. +enum {
  9969. + VCMSG_PROPERTY_END = 0x00000000,
  9970. + VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
  9971. + VCMSG_GET_BOARD_MODEL = 0x00010001,
  9972. + VCMSG_GET_BOARD_REVISION = 0x00010002,
  9973. + VCMSG_GET_BOARD_MAC_ADDRESS = 0x00010003,
  9974. + VCMSG_GET_BOARD_SERIAL = 0x00010004,
  9975. + VCMSG_GET_ARM_MEMORY = 0x00010005,
  9976. + VCMSG_GET_VC_MEMORY = 0x00010006,
  9977. + VCMSG_GET_CLOCKS = 0x00010007,
  9978. + VCMSG_GET_COMMAND_LINE = 0x00050001,
  9979. + VCMSG_GET_DMA_CHANNELS = 0x00060001,
  9980. + VCMSG_GET_POWER_STATE = 0x00020001,
  9981. + VCMSG_GET_TIMING = 0x00020002,
  9982. + VCMSG_SET_POWER_STATE = 0x00028001,
  9983. + VCMSG_GET_CLOCK_STATE = 0x00030001,
  9984. + VCMSG_SET_CLOCK_STATE = 0x00038001,
  9985. + VCMSG_GET_CLOCK_RATE = 0x00030002,
  9986. + VCMSG_SET_CLOCK_RATE = 0x00038002,
  9987. + VCMSG_GET_VOLTAGE = 0x00030003,
  9988. + VCMSG_SET_VOLTAGE = 0x00038003,
  9989. + VCMSG_GET_MAX_CLOCK = 0x00030004,
  9990. + VCMSG_GET_MAX_VOLTAGE = 0x00030005,
  9991. + VCMSG_GET_TEMPERATURE = 0x00030006,
  9992. + VCMSG_GET_MIN_CLOCK = 0x00030007,
  9993. + VCMSG_GET_MIN_VOLTAGE = 0x00030008,
  9994. + VCMSG_GET_TURBO = 0x00030009,
  9995. + VCMSG_GET_MAX_TEMPERATURE = 0x0003000a,
  9996. + VCMSG_GET_STC = 0x0003000b,
  9997. + VCMSG_SET_TURBO = 0x00038009,
  9998. + VCMSG_SET_ALLOCATE_MEM = 0x0003000c,
  9999. + VCMSG_SET_LOCK_MEM = 0x0003000d,
  10000. + VCMSG_SET_UNLOCK_MEM = 0x0003000e,
  10001. + VCMSG_SET_RELEASE_MEM = 0x0003000f,
  10002. + VCMSG_SET_EXECUTE_CODE = 0x00030010,
  10003. + VCMSG_SET_EXECUTE_QPU = 0x00030011,
  10004. + VCMSG_SET_ENABLE_QPU = 0x00030012,
  10005. + VCMSG_GET_RESOURCE_HANDLE = 0x00030014,
  10006. + VCMSG_GET_EDID_BLOCK = 0x00030020,
  10007. + VCMSG_GET_CUSTOMER_OTP = 0x00030021,
  10008. + VCMSG_SET_CUSTOMER_OTP = 0x00038021,
  10009. + VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
  10010. + VCMSG_SET_RELEASE_BUFFER = 0x00048001,
  10011. + VCMSG_SET_BLANK_SCREEN = 0x00040002,
  10012. + VCMSG_TST_BLANK_SCREEN = 0x00044002,
  10013. + VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
  10014. + VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
  10015. + VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
  10016. + VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
  10017. + VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
  10018. + VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
  10019. + VCMSG_GET_DEPTH = 0x00040005,
  10020. + VCMSG_TST_DEPTH = 0x00044005,
  10021. + VCMSG_SET_DEPTH = 0x00048005,
  10022. + VCMSG_GET_PIXEL_ORDER = 0x00040006,
  10023. + VCMSG_TST_PIXEL_ORDER = 0x00044006,
  10024. + VCMSG_SET_PIXEL_ORDER = 0x00048006,
  10025. + VCMSG_GET_ALPHA_MODE = 0x00040007,
  10026. + VCMSG_TST_ALPHA_MODE = 0x00044007,
  10027. + VCMSG_SET_ALPHA_MODE = 0x00048007,
  10028. + VCMSG_GET_PITCH = 0x00040008,
  10029. + VCMSG_TST_PITCH = 0x00044008,
  10030. + VCMSG_SET_PITCH = 0x00048008,
  10031. + VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
  10032. + VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
  10033. + VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
  10034. + VCMSG_GET_OVERSCAN = 0x0004000a,
  10035. + VCMSG_TST_OVERSCAN = 0x0004400a,
  10036. + VCMSG_SET_OVERSCAN = 0x0004800a,
  10037. + VCMSG_GET_PALETTE = 0x0004000b,
  10038. + VCMSG_TST_PALETTE = 0x0004400b,
  10039. + VCMSG_SET_PALETTE = 0x0004800b,
  10040. + VCMSG_GET_LAYER = 0x0004000c,
  10041. + VCMSG_TST_LAYER = 0x0004400c,
  10042. + VCMSG_SET_LAYER = 0x0004800c,
  10043. + VCMSG_GET_TRANSFORM = 0x0004000d,
  10044. + VCMSG_TST_TRANSFORM = 0x0004400d,
  10045. + VCMSG_SET_TRANSFORM = 0x0004800d,
  10046. + VCMSG_TST_VSYNC = 0x0004400e,
  10047. + VCMSG_SET_VSYNC = 0x0004800e,
  10048. + VCMSG_SET_CURSOR_INFO = 0x00008010,
  10049. + VCMSG_SET_CURSOR_STATE = 0x00008011,
  10050. +};
  10051. +
  10052. +extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
  10053. +extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
  10054. +extern int /*rc*/ bcm_mailbox_property(void *data, int size);
  10055. +
  10056. +#include <linux/ioctl.h>
  10057. +
  10058. +/*
  10059. + * The major device number. We can't rely on dynamic
  10060. + * registration any more, because ioctls need to know
  10061. + * it.
  10062. + */
  10063. +#define MAJOR_NUM 100
  10064. +
  10065. +/*
  10066. + * Set the message of the device driver
  10067. + */
  10068. +#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  10069. +/*
  10070. + * _IOWR means that we're creating an ioctl command
  10071. + * number for passing information from a user process
  10072. + * to the kernel module and from the kernel module to user process
  10073. + *
  10074. + * The first arguments, MAJOR_NUM, is the major device
  10075. + * number we're using.
  10076. + *
  10077. + * The second argument is the number of the command
  10078. + * (there could be several with different meanings).
  10079. + *
  10080. + * The third argument is the type we want to get from
  10081. + * the process to the kernel.
  10082. + */
  10083. +
  10084. +/*
  10085. + * The name of the device file
  10086. + */
  10087. +#define DEVICE_FILE_NAME "vcio"
  10088. +
  10089. +#endif
  10090. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/vc_mem.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_mem.h
  10091. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/vc_mem.h 1970-01-01 01:00:00.000000000 +0100
  10092. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_mem.h 2015-02-09 04:39:42.000000000 +0100
  10093. @@ -0,0 +1,35 @@
  10094. +/*****************************************************************************
  10095. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  10096. +*
  10097. +* Unless you and Broadcom execute a separate written software license
  10098. +* agreement governing use of this software, this software is licensed to you
  10099. +* under the terms of the GNU General Public License version 2, available at
  10100. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10101. +*
  10102. +* Notwithstanding the above, under no circumstances may you combine this
  10103. +* software in any way with any other Broadcom software provided under a
  10104. +* license other than the GPL, without Broadcom's express prior written
  10105. +* consent.
  10106. +*****************************************************************************/
  10107. +
  10108. +#if !defined( VC_MEM_H )
  10109. +#define VC_MEM_H
  10110. +
  10111. +#include <linux/ioctl.h>
  10112. +
  10113. +#define VC_MEM_IOC_MAGIC 'v'
  10114. +
  10115. +#define VC_MEM_IOC_MEM_PHYS_ADDR _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
  10116. +#define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
  10117. +#define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
  10118. +#define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
  10119. +
  10120. +#if defined( __KERNEL__ )
  10121. +#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
  10122. +
  10123. +extern unsigned long mm_vc_mem_phys_addr;
  10124. +extern unsigned int mm_vc_mem_size;
  10125. +extern int vc_mem_get_current_size( void );
  10126. +#endif
  10127. +
  10128. +#endif /* VC_MEM_H */
  10129. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/vc_sm_defs.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_sm_defs.h
  10130. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/vc_sm_defs.h 1970-01-01 01:00:00.000000000 +0100
  10131. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_sm_defs.h 2015-02-09 04:39:42.000000000 +0100
  10132. @@ -0,0 +1,181 @@
  10133. +/*****************************************************************************
  10134. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10135. +*
  10136. +* Unless you and Broadcom execute a separate written software license
  10137. +* agreement governing use of this software, this software is licensed to you
  10138. +* under the terms of the GNU General Public License version 2, available at
  10139. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10140. +*
  10141. +* Notwithstanding the above, under no circumstances may you combine this
  10142. +* software in any way with any other Broadcom software provided under a
  10143. +* license other than the GPL, without Broadcom's express prior written
  10144. +* consent.
  10145. +*****************************************************************************/
  10146. +
  10147. +#ifndef __VC_SM_DEFS_H__INCLUDED__
  10148. +#define __VC_SM_DEFS_H__INCLUDED__
  10149. +
  10150. +/* FourCC code used for VCHI connection */
  10151. +#define VC_SM_SERVER_NAME MAKE_FOURCC("SMEM")
  10152. +
  10153. +/* Maximum message length */
  10154. +#define VC_SM_MAX_MSG_LEN (sizeof(VC_SM_MSG_UNION_T) + \
  10155. + sizeof(VC_SM_MSG_HDR_T))
  10156. +#define VC_SM_MAX_RSP_LEN (sizeof(VC_SM_MSG_UNION_T))
  10157. +
  10158. +/* Resource name maximum size */
  10159. +#define VC_SM_RESOURCE_NAME 32
  10160. +
  10161. +/* All message types supported for HOST->VC direction */
  10162. +typedef enum {
  10163. + /* Allocate shared memory block */
  10164. + VC_SM_MSG_TYPE_ALLOC,
  10165. + /* Lock allocated shared memory block */
  10166. + VC_SM_MSG_TYPE_LOCK,
  10167. + /* Unlock allocated shared memory block */
  10168. + VC_SM_MSG_TYPE_UNLOCK,
  10169. + /* Unlock allocated shared memory block, do not answer command */
  10170. + VC_SM_MSG_TYPE_UNLOCK_NOANS,
  10171. + /* Free shared memory block */
  10172. + VC_SM_MSG_TYPE_FREE,
  10173. + /* Resize a shared memory block */
  10174. + VC_SM_MSG_TYPE_RESIZE,
  10175. + /* Walk the allocated shared memory block(s) */
  10176. + VC_SM_MSG_TYPE_WALK_ALLOC,
  10177. +
  10178. + /* A previously applied action will need to be reverted */
  10179. + VC_SM_MSG_TYPE_ACTION_CLEAN,
  10180. + VC_SM_MSG_TYPE_MAX
  10181. +} VC_SM_MSG_TYPE;
  10182. +
  10183. +/* Type of memory to be allocated */
  10184. +typedef enum {
  10185. + VC_SM_ALLOC_CACHED,
  10186. + VC_SM_ALLOC_NON_CACHED,
  10187. +
  10188. +} VC_SM_ALLOC_TYPE_T;
  10189. +
  10190. +/* Message header for all messages in HOST->VC direction */
  10191. +typedef struct {
  10192. + int32_t type;
  10193. + uint32_t trans_id;
  10194. + uint8_t body[0];
  10195. +
  10196. +} VC_SM_MSG_HDR_T;
  10197. +
  10198. +/* Request to allocate memory (HOST->VC) */
  10199. +typedef struct {
  10200. + /* type of memory to allocate */
  10201. + VC_SM_ALLOC_TYPE_T type;
  10202. + /* byte amount of data to allocate per unit */
  10203. + uint32_t base_unit;
  10204. + /* number of unit to allocate */
  10205. + uint32_t num_unit;
  10206. + /* alignement to be applied on allocation */
  10207. + uint32_t alignement;
  10208. + /* identity of who allocated this block */
  10209. + uint32_t allocator;
  10210. + /* resource name (for easier tracking on vc side) */
  10211. + char name[VC_SM_RESOURCE_NAME];
  10212. +
  10213. +} VC_SM_ALLOC_T;
  10214. +
  10215. +/* Result of a requested memory allocation (VC->HOST) */
  10216. +typedef struct {
  10217. + /* Transaction identifier */
  10218. + uint32_t trans_id;
  10219. +
  10220. + /* Resource handle */
  10221. + uint32_t res_handle;
  10222. + /* Pointer to resource buffer */
  10223. + void *res_mem;
  10224. + /* Resource base size (bytes) */
  10225. + uint32_t res_base_size;
  10226. + /* Resource number */
  10227. + uint32_t res_num;
  10228. +
  10229. +} VC_SM_ALLOC_RESULT_T;
  10230. +
  10231. +/* Request to free a previously allocated memory (HOST->VC) */
  10232. +typedef struct {
  10233. + /* Resource handle (returned from alloc) */
  10234. + uint32_t res_handle;
  10235. + /* Resource buffer (returned from alloc) */
  10236. + void *res_mem;
  10237. +
  10238. +} VC_SM_FREE_T;
  10239. +
  10240. +/* Request to lock a previously allocated memory (HOST->VC) */
  10241. +typedef struct {
  10242. + /* Resource handle (returned from alloc) */
  10243. + uint32_t res_handle;
  10244. + /* Resource buffer (returned from alloc) */
  10245. + void *res_mem;
  10246. +
  10247. +} VC_SM_LOCK_UNLOCK_T;
  10248. +
  10249. +/* Request to resize a previously allocated memory (HOST->VC) */
  10250. +typedef struct {
  10251. + /* Resource handle (returned from alloc) */
  10252. + uint32_t res_handle;
  10253. + /* Resource buffer (returned from alloc) */
  10254. + void *res_mem;
  10255. + /* Resource *new* size requested (bytes) */
  10256. + uint32_t res_new_size;
  10257. +
  10258. +} VC_SM_RESIZE_T;
  10259. +
  10260. +/* Result of a requested memory lock (VC->HOST) */
  10261. +typedef struct {
  10262. + /* Transaction identifier */
  10263. + uint32_t trans_id;
  10264. +
  10265. + /* Resource handle */
  10266. + uint32_t res_handle;
  10267. + /* Pointer to resource buffer */
  10268. + void *res_mem;
  10269. + /* Pointer to former resource buffer if the memory
  10270. + * was reallocated */
  10271. + void *res_old_mem;
  10272. +
  10273. +} VC_SM_LOCK_RESULT_T;
  10274. +
  10275. +/* Generic result for a request (VC->HOST) */
  10276. +typedef struct {
  10277. + /* Transaction identifier */
  10278. + uint32_t trans_id;
  10279. +
  10280. + int32_t success;
  10281. +
  10282. +} VC_SM_RESULT_T;
  10283. +
  10284. +/* Request to revert a previously applied action (HOST->VC) */
  10285. +typedef struct {
  10286. + /* Action of interest */
  10287. + VC_SM_MSG_TYPE res_action;
  10288. + /* Transaction identifier for the action of interest */
  10289. + uint32_t action_trans_id;
  10290. +
  10291. +} VC_SM_ACTION_CLEAN_T;
  10292. +
  10293. +/* Request to remove all data associated with a given allocator (HOST->VC) */
  10294. +typedef struct {
  10295. + /* Allocator identifier */
  10296. + uint32_t allocator;
  10297. +
  10298. +} VC_SM_FREE_ALL_T;
  10299. +
  10300. +/* Union of ALL messages */
  10301. +typedef union {
  10302. + VC_SM_ALLOC_T alloc;
  10303. + VC_SM_ALLOC_RESULT_T alloc_result;
  10304. + VC_SM_FREE_T free;
  10305. + VC_SM_ACTION_CLEAN_T action_clean;
  10306. + VC_SM_RESIZE_T resize;
  10307. + VC_SM_LOCK_RESULT_T lock_result;
  10308. + VC_SM_RESULT_T result;
  10309. + VC_SM_FREE_ALL_T free_all;
  10310. +
  10311. +} VC_SM_MSG_UNION_T;
  10312. +
  10313. +#endif /* __VC_SM_DEFS_H__INCLUDED__ */
  10314. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/vc_sm_knl.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_sm_knl.h
  10315. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/vc_sm_knl.h 1970-01-01 01:00:00.000000000 +0100
  10316. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_sm_knl.h 2015-02-09 04:39:42.000000000 +0100
  10317. @@ -0,0 +1,55 @@
  10318. +/*****************************************************************************
  10319. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10320. +*
  10321. +* Unless you and Broadcom execute a separate written software license
  10322. +* agreement governing use of this software, this software is licensed to you
  10323. +* under the terms of the GNU General Public License version 2, available at
  10324. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10325. +*
  10326. +* Notwithstanding the above, under no circumstances may you combine this
  10327. +* software in any way with any other Broadcom software provided under a
  10328. +* license other than the GPL, without Broadcom's express prior written
  10329. +* consent.
  10330. +*****************************************************************************/
  10331. +
  10332. +#ifndef __VC_SM_KNL_H__INCLUDED__
  10333. +#define __VC_SM_KNL_H__INCLUDED__
  10334. +
  10335. +#if !defined(__KERNEL__)
  10336. +#error "This interface is for kernel use only..."
  10337. +#endif
  10338. +
  10339. +/* Type of memory to be locked (ie mapped) */
  10340. +typedef enum {
  10341. + VC_SM_LOCK_CACHED,
  10342. + VC_SM_LOCK_NON_CACHED,
  10343. +
  10344. +} VC_SM_LOCK_CACHE_MODE_T;
  10345. +
  10346. +/* Allocate a shared memory handle and block.
  10347. +*/
  10348. +int vc_sm_alloc(VC_SM_ALLOC_T *alloc, int *handle);
  10349. +
  10350. +/* Free a previously allocated shared memory handle and block.
  10351. +*/
  10352. +int vc_sm_free(int handle);
  10353. +
  10354. +/* Lock a memory handle for use by kernel.
  10355. +*/
  10356. +int vc_sm_lock(int handle, VC_SM_LOCK_CACHE_MODE_T mode,
  10357. + long unsigned int *data);
  10358. +
  10359. +/* Unlock a memory handle in use by kernel.
  10360. +*/
  10361. +int vc_sm_unlock(int handle, int flush, int no_vc_unlock);
  10362. +
  10363. +/* Get an internal resource handle mapped from the external one.
  10364. +*/
  10365. +int vc_sm_int_handle(int handle);
  10366. +
  10367. +/* Map a shared memory region for use by kernel.
  10368. +*/
  10369. +int vc_sm_map(int handle, unsigned int sm_addr, VC_SM_LOCK_CACHE_MODE_T mode,
  10370. + long unsigned int *data);
  10371. +
  10372. +#endif /* __VC_SM_KNL_H__INCLUDED__ */
  10373. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/vc_vchi_sm.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_vchi_sm.h
  10374. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/vc_vchi_sm.h 1970-01-01 01:00:00.000000000 +0100
  10375. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_vchi_sm.h 2015-02-09 04:39:42.000000000 +0100
  10376. @@ -0,0 +1,82 @@
  10377. +/*****************************************************************************
  10378. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10379. +*
  10380. +* Unless you and Broadcom execute a separate written software license
  10381. +* agreement governing use of this software, this software is licensed to you
  10382. +* under the terms of the GNU General Public License version 2, available at
  10383. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10384. +*
  10385. +* Notwithstanding the above, under no circumstances may you combine this
  10386. +* software in any way with any other Broadcom software provided under a
  10387. +* license other than the GPL, without Broadcom's express prior written
  10388. +* consent.
  10389. +*****************************************************************************/
  10390. +
  10391. +#ifndef __VC_VCHI_SM_H__INCLUDED__
  10392. +#define __VC_VCHI_SM_H__INCLUDED__
  10393. +
  10394. +#include "interface/vchi/vchi.h"
  10395. +
  10396. +#include "vc_sm_defs.h"
  10397. +
  10398. +/* Forward declare.
  10399. +*/
  10400. +typedef struct sm_instance *VC_VCHI_SM_HANDLE_T;
  10401. +
  10402. +/* Initialize the shared memory service, opens up vchi connection to talk to it.
  10403. +*/
  10404. +VC_VCHI_SM_HANDLE_T vc_vchi_sm_init(VCHI_INSTANCE_T vchi_instance,
  10405. + VCHI_CONNECTION_T **vchi_connections,
  10406. + uint32_t num_connections);
  10407. +
  10408. +/* Terminates the shared memory service.
  10409. +*/
  10410. +int vc_vchi_sm_stop(VC_VCHI_SM_HANDLE_T *handle);
  10411. +
  10412. +/* Ask the shared memory service to allocate some memory on videocre and
  10413. +** return the result of this allocation (which upon success will be a pointer
  10414. +** to some memory in videocore space).
  10415. +*/
  10416. +int vc_vchi_sm_alloc(VC_VCHI_SM_HANDLE_T handle,
  10417. + VC_SM_ALLOC_T *alloc,
  10418. + VC_SM_ALLOC_RESULT_T *alloc_result, uint32_t *trans_id);
  10419. +
  10420. +/* Ask the shared memory service to free up some memory that was previously
  10421. +** allocated by the vc_vchi_sm_alloc function call.
  10422. +*/
  10423. +int vc_vchi_sm_free(VC_VCHI_SM_HANDLE_T handle,
  10424. + VC_SM_FREE_T *free, uint32_t *trans_id);
  10425. +
  10426. +/* Ask the shared memory service to lock up some memory that was previously
  10427. +** allocated by the vc_vchi_sm_alloc function call.
  10428. +*/
  10429. +int vc_vchi_sm_lock(VC_VCHI_SM_HANDLE_T handle,
  10430. + VC_SM_LOCK_UNLOCK_T *lock_unlock,
  10431. + VC_SM_LOCK_RESULT_T *lock_result, uint32_t *trans_id);
  10432. +
  10433. +/* Ask the shared memory service to unlock some memory that was previously
  10434. +** allocated by the vc_vchi_sm_alloc function call.
  10435. +*/
  10436. +int vc_vchi_sm_unlock(VC_VCHI_SM_HANDLE_T handle,
  10437. + VC_SM_LOCK_UNLOCK_T *lock_unlock,
  10438. + uint32_t *trans_id, uint8_t wait_reply);
  10439. +
  10440. +/* Ask the shared memory service to resize some memory that was previously
  10441. +** allocated by the vc_vchi_sm_alloc function call.
  10442. +*/
  10443. +int vc_vchi_sm_resize(VC_VCHI_SM_HANDLE_T handle,
  10444. + VC_SM_RESIZE_T *resize, uint32_t *trans_id);
  10445. +
  10446. +/* Walk the allocated resources on the videocore side, the allocation will
  10447. +** show up in the log. This is purely for debug/information and takes no
  10448. +** specific actions.
  10449. +*/
  10450. +int vc_vchi_sm_walk_alloc(VC_VCHI_SM_HANDLE_T handle);
  10451. +
  10452. +/* Clean up following a previously interrupted action which left the system
  10453. +** in a bad state of some sort.
  10454. +*/
  10455. +int vc_vchi_sm_clean_up(VC_VCHI_SM_HANDLE_T handle,
  10456. + VC_SM_ACTION_CLEAN_T *action_clean);
  10457. +
  10458. +#endif /* __VC_VCHI_SM_H__INCLUDED__ */
  10459. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/vmalloc.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vmalloc.h
  10460. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
  10461. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vmalloc.h 2015-02-09 04:39:42.000000000 +0100
  10462. @@ -0,0 +1,20 @@
  10463. +/*
  10464. + * arch/arm/mach-bcm2708/include/mach/vmalloc.h
  10465. + *
  10466. + * Copyright (C) 2010 Broadcom
  10467. + *
  10468. + * This program is free software; you can redistribute it and/or modify
  10469. + * it under the terms of the GNU General Public License as published by
  10470. + * the Free Software Foundation; either version 2 of the License, or
  10471. + * (at your option) any later version.
  10472. + *
  10473. + * This program is distributed in the hope that it will be useful,
  10474. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10475. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10476. + * GNU General Public License for more details.
  10477. + *
  10478. + * You should have received a copy of the GNU General Public License
  10479. + * along with this program; if not, write to the Free Software
  10480. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  10481. + */
  10482. +#define VMALLOC_END (0xe8000000)
  10483. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/include/mach/vmcs_sm_ioctl.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vmcs_sm_ioctl.h
  10484. --- linux-3.18.6/arch/arm/mach-bcm2708/include/mach/vmcs_sm_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  10485. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vmcs_sm_ioctl.h 2015-02-09 04:39:42.000000000 +0100
  10486. @@ -0,0 +1,233 @@
  10487. +/*****************************************************************************
  10488. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10489. +*
  10490. +* Unless you and Broadcom execute a separate written software license
  10491. +* agreement governing use of this software, this software is licensed to you
  10492. +* under the terms of the GNU General Public License version 2, available at
  10493. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10494. +*
  10495. +* Notwithstanding the above, under no circumstances may you combine this
  10496. +* software in any way with any other Broadcom software provided under a
  10497. +* license other than the GPL, without Broadcom's express prior written
  10498. +* consent.
  10499. +*
  10500. +*****************************************************************************/
  10501. +
  10502. +#if !defined(__VMCS_SM_IOCTL_H__INCLUDED__)
  10503. +#define __VMCS_SM_IOCTL_H__INCLUDED__
  10504. +
  10505. +/* ---- Include Files ---------------------------------------------------- */
  10506. +
  10507. +#if defined(__KERNEL__)
  10508. +#include <linux/types.h> /* Needed for standard types */
  10509. +#else
  10510. +#include <stdint.h>
  10511. +#endif
  10512. +
  10513. +#include <linux/ioctl.h>
  10514. +
  10515. +/* ---- Constants and Types ---------------------------------------------- */
  10516. +
  10517. +#define VMCS_SM_RESOURCE_NAME 32
  10518. +#define VMCS_SM_RESOURCE_NAME_DEFAULT "sm-host-resource"
  10519. +
  10520. +/* Type define used to create unique IOCTL number */
  10521. +#define VMCS_SM_MAGIC_TYPE 'I'
  10522. +
  10523. +/* IOCTL commands */
  10524. +enum vmcs_sm_cmd_e {
  10525. + VMCS_SM_CMD_ALLOC = 0x5A, /* Start at 0x5A arbitrarily */
  10526. + VMCS_SM_CMD_ALLOC_SHARE,
  10527. + VMCS_SM_CMD_LOCK,
  10528. + VMCS_SM_CMD_LOCK_CACHE,
  10529. + VMCS_SM_CMD_UNLOCK,
  10530. + VMCS_SM_CMD_RESIZE,
  10531. + VMCS_SM_CMD_UNMAP,
  10532. + VMCS_SM_CMD_FREE,
  10533. + VMCS_SM_CMD_FLUSH,
  10534. + VMCS_SM_CMD_INVALID,
  10535. +
  10536. + VMCS_SM_CMD_SIZE_USR_HANDLE,
  10537. + VMCS_SM_CMD_CHK_USR_HANDLE,
  10538. +
  10539. + VMCS_SM_CMD_MAPPED_USR_HANDLE,
  10540. + VMCS_SM_CMD_MAPPED_USR_ADDRESS,
  10541. + VMCS_SM_CMD_MAPPED_VC_HDL_FROM_ADDR,
  10542. + VMCS_SM_CMD_MAPPED_VC_HDL_FROM_HDL,
  10543. + VMCS_SM_CMD_MAPPED_VC_ADDR_FROM_HDL,
  10544. +
  10545. + VMCS_SM_CMD_VC_WALK_ALLOC,
  10546. + VMCS_SM_CMD_HOST_WALK_MAP,
  10547. + VMCS_SM_CMD_HOST_WALK_PID_ALLOC,
  10548. + VMCS_SM_CMD_HOST_WALK_PID_MAP,
  10549. +
  10550. + VMCS_SM_CMD_LAST /* Do no delete */
  10551. +};
  10552. +
  10553. +/* Cache type supported, conveniently matches the user space definition in
  10554. +** user-vcsm.h.
  10555. +*/
  10556. +enum vmcs_sm_cache_e {
  10557. + VMCS_SM_CACHE_NONE,
  10558. + VMCS_SM_CACHE_HOST,
  10559. + VMCS_SM_CACHE_VC,
  10560. + VMCS_SM_CACHE_BOTH,
  10561. +};
  10562. +
  10563. +/* IOCTL Data structures */
  10564. +struct vmcs_sm_ioctl_alloc {
  10565. + /* user -> kernel */
  10566. + unsigned int size;
  10567. + unsigned int num;
  10568. + enum vmcs_sm_cache_e cached;
  10569. + char name[VMCS_SM_RESOURCE_NAME];
  10570. +
  10571. + /* kernel -> user */
  10572. + unsigned int handle;
  10573. + /* unsigned int base_addr; */
  10574. +};
  10575. +
  10576. +struct vmcs_sm_ioctl_alloc_share {
  10577. + /* user -> kernel */
  10578. + unsigned int handle;
  10579. + unsigned int size;
  10580. +};
  10581. +
  10582. +struct vmcs_sm_ioctl_free {
  10583. + /* user -> kernel */
  10584. + unsigned int handle;
  10585. + /* unsigned int base_addr; */
  10586. +};
  10587. +
  10588. +struct vmcs_sm_ioctl_lock_unlock {
  10589. + /* user -> kernel */
  10590. + unsigned int handle;
  10591. +
  10592. + /* kernel -> user */
  10593. + unsigned int addr;
  10594. +};
  10595. +
  10596. +struct vmcs_sm_ioctl_lock_cache {
  10597. + /* user -> kernel */
  10598. + unsigned int handle;
  10599. + enum vmcs_sm_cache_e cached;
  10600. +};
  10601. +
  10602. +struct vmcs_sm_ioctl_resize {
  10603. + /* user -> kernel */
  10604. + unsigned int handle;
  10605. + unsigned int new_size;
  10606. +
  10607. + /* kernel -> user */
  10608. + unsigned int old_size;
  10609. +};
  10610. +
  10611. +struct vmcs_sm_ioctl_map {
  10612. + /* user -> kernel */
  10613. + /* and kernel -> user */
  10614. + unsigned int pid;
  10615. + unsigned int handle;
  10616. + unsigned int addr;
  10617. +
  10618. + /* kernel -> user */
  10619. + unsigned int size;
  10620. +};
  10621. +
  10622. +struct vmcs_sm_ioctl_walk {
  10623. + /* user -> kernel */
  10624. + unsigned int pid;
  10625. +};
  10626. +
  10627. +struct vmcs_sm_ioctl_chk {
  10628. + /* user -> kernel */
  10629. + unsigned int handle;
  10630. +
  10631. + /* kernel -> user */
  10632. + unsigned int addr;
  10633. + unsigned int size;
  10634. + enum vmcs_sm_cache_e cache;
  10635. +};
  10636. +
  10637. +struct vmcs_sm_ioctl_size {
  10638. + /* user -> kernel */
  10639. + unsigned int handle;
  10640. +
  10641. + /* kernel -> user */
  10642. + unsigned int size;
  10643. +};
  10644. +
  10645. +struct vmcs_sm_ioctl_cache {
  10646. + /* user -> kernel */
  10647. + unsigned int handle;
  10648. + unsigned int addr;
  10649. + unsigned int size;
  10650. +};
  10651. +
  10652. +/* IOCTL numbers */
  10653. +#define VMCS_SM_IOCTL_MEM_ALLOC\
  10654. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_ALLOC,\
  10655. + struct vmcs_sm_ioctl_alloc)
  10656. +#define VMCS_SM_IOCTL_MEM_ALLOC_SHARE\
  10657. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_ALLOC_SHARE,\
  10658. + struct vmcs_sm_ioctl_alloc_share)
  10659. +#define VMCS_SM_IOCTL_MEM_LOCK\
  10660. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_LOCK,\
  10661. + struct vmcs_sm_ioctl_lock_unlock)
  10662. +#define VMCS_SM_IOCTL_MEM_LOCK_CACHE\
  10663. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_LOCK_CACHE,\
  10664. + struct vmcs_sm_ioctl_lock_cache)
  10665. +#define VMCS_SM_IOCTL_MEM_UNLOCK\
  10666. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_UNLOCK,\
  10667. + struct vmcs_sm_ioctl_lock_unlock)
  10668. +#define VMCS_SM_IOCTL_MEM_RESIZE\
  10669. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_RESIZE,\
  10670. + struct vmcs_sm_ioctl_resize)
  10671. +#define VMCS_SM_IOCTL_MEM_FREE\
  10672. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_FREE,\
  10673. + struct vmcs_sm_ioctl_free)
  10674. +#define VMCS_SM_IOCTL_MEM_FLUSH\
  10675. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_FLUSH,\
  10676. + struct vmcs_sm_ioctl_cache)
  10677. +#define VMCS_SM_IOCTL_MEM_INVALID\
  10678. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_INVALID,\
  10679. + struct vmcs_sm_ioctl_cache)
  10680. +
  10681. +#define VMCS_SM_IOCTL_SIZE_USR_HDL\
  10682. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_SIZE_USR_HANDLE,\
  10683. + struct vmcs_sm_ioctl_size)
  10684. +#define VMCS_SM_IOCTL_CHK_USR_HDL\
  10685. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_CHK_USR_HANDLE,\
  10686. + struct vmcs_sm_ioctl_chk)
  10687. +
  10688. +#define VMCS_SM_IOCTL_MAP_USR_HDL\
  10689. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_USR_HANDLE,\
  10690. + struct vmcs_sm_ioctl_map)
  10691. +#define VMCS_SM_IOCTL_MAP_USR_ADDRESS\
  10692. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_USR_ADDRESS,\
  10693. + struct vmcs_sm_ioctl_map)
  10694. +#define VMCS_SM_IOCTL_MAP_VC_HDL_FR_ADDR\
  10695. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_VC_HDL_FROM_ADDR,\
  10696. + struct vmcs_sm_ioctl_map)
  10697. +#define VMCS_SM_IOCTL_MAP_VC_HDL_FR_HDL\
  10698. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_VC_HDL_FROM_HDL,\
  10699. + struct vmcs_sm_ioctl_map)
  10700. +#define VMCS_SM_IOCTL_MAP_VC_ADDR_FR_HDL\
  10701. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_VC_ADDR_FROM_HDL,\
  10702. + struct vmcs_sm_ioctl_map)
  10703. +
  10704. +#define VMCS_SM_IOCTL_VC_WALK_ALLOC\
  10705. + _IO(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_VC_WALK_ALLOC)
  10706. +#define VMCS_SM_IOCTL_HOST_WALK_MAP\
  10707. + _IO(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_HOST_WALK_MAP)
  10708. +#define VMCS_SM_IOCTL_HOST_WALK_PID_ALLOC\
  10709. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_HOST_WALK_PID_ALLOC,\
  10710. + struct vmcs_sm_ioctl_walk)
  10711. +#define VMCS_SM_IOCTL_HOST_WALK_PID_MAP\
  10712. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_HOST_WALK_PID_MAP,\
  10713. + struct vmcs_sm_ioctl_walk)
  10714. +
  10715. +/* ---- Variable Externs ------------------------------------------------- */
  10716. +
  10717. +/* ---- Function Prototypes ---------------------------------------------- */
  10718. +
  10719. +#endif /* __VMCS_SM_IOCTL_H__INCLUDED__ */
  10720. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/Kconfig linux-rpi/arch/arm/mach-bcm2708/Kconfig
  10721. --- linux-3.18.6/arch/arm/mach-bcm2708/Kconfig 1970-01-01 01:00:00.000000000 +0100
  10722. +++ linux-rpi/arch/arm/mach-bcm2708/Kconfig 2015-02-09 04:39:42.000000000 +0100
  10723. @@ -0,0 +1,52 @@
  10724. +menu "Broadcom BCM2708 Implementations"
  10725. + depends on ARCH_BCM2708
  10726. +
  10727. +config MACH_BCM2708
  10728. + bool "Broadcom BCM2708 Development Platform"
  10729. + select NEED_MACH_MEMORY_H
  10730. + select NEED_MACH_IO_H
  10731. + select CPU_V6
  10732. + help
  10733. + Include support for the Broadcom(R) BCM2708 platform.
  10734. +
  10735. +config BCM2708_DT
  10736. + bool "BCM2708 Device Tree support"
  10737. + depends on MACH_BCM2708
  10738. + default n
  10739. + select USE_OF
  10740. + select ARCH_REQUIRE_GPIOLIB
  10741. + select PINCTRL
  10742. + select PINCTRL_BCM2835
  10743. + help
  10744. + Enable Device Tree support for BCM2708
  10745. +
  10746. +config BCM2708_GPIO
  10747. + bool "BCM2708 gpio support"
  10748. + depends on MACH_BCM2708
  10749. + select ARCH_REQUIRE_GPIOLIB
  10750. + default y
  10751. + help
  10752. + Include support for the Broadcom(R) BCM2708 gpio.
  10753. +
  10754. +config BCM2708_VCMEM
  10755. + bool "Videocore Memory"
  10756. + depends on MACH_BCM2708
  10757. + default y
  10758. + help
  10759. + Helper for videocore memory access and total size allocation.
  10760. +
  10761. +config BCM2708_NOL2CACHE
  10762. + bool "Videocore L2 cache disable"
  10763. + depends on MACH_BCM2708
  10764. + default n
  10765. + help
  10766. + Do not allow ARM to use GPU's L2 cache. Requires disable_l2cache in config.txt.
  10767. +
  10768. +config BCM2708_SPIDEV
  10769. + bool "Bind spidev to SPI0 master"
  10770. + depends on MACH_BCM2708
  10771. + depends on SPI
  10772. + default y
  10773. + help
  10774. + Binds spidev driver to the SPI0 master
  10775. +endmenu
  10776. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/Makefile linux-rpi/arch/arm/mach-bcm2708/Makefile
  10777. --- linux-3.18.6/arch/arm/mach-bcm2708/Makefile 1970-01-01 01:00:00.000000000 +0100
  10778. +++ linux-rpi/arch/arm/mach-bcm2708/Makefile 2015-02-09 04:39:42.000000000 +0100
  10779. @@ -0,0 +1,7 @@
  10780. +#
  10781. +# Makefile for the linux kernel.
  10782. +#
  10783. +
  10784. +obj-$(CONFIG_MACH_BCM2708) += bcm2708.o armctrl.o vcio.o power.o dma.o
  10785. +obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
  10786. +obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
  10787. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/Makefile.boot linux-rpi/arch/arm/mach-bcm2708/Makefile.boot
  10788. --- linux-3.18.6/arch/arm/mach-bcm2708/Makefile.boot 1970-01-01 01:00:00.000000000 +0100
  10789. +++ linux-rpi/arch/arm/mach-bcm2708/Makefile.boot 2015-02-09 04:39:42.000000000 +0100
  10790. @@ -0,0 +1,3 @@
  10791. + zreladdr-y := 0x00008000
  10792. +params_phys-y := 0x00000100
  10793. +initrd_phys-y := 0x00800000
  10794. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/power.c linux-rpi/arch/arm/mach-bcm2708/power.c
  10795. --- linux-3.18.6/arch/arm/mach-bcm2708/power.c 1970-01-01 01:00:00.000000000 +0100
  10796. +++ linux-rpi/arch/arm/mach-bcm2708/power.c 2015-02-09 04:39:42.000000000 +0100
  10797. @@ -0,0 +1,197 @@
  10798. +/*
  10799. + * linux/arch/arm/mach-bcm2708/power.c
  10800. + *
  10801. + * Copyright (C) 2010 Broadcom
  10802. + *
  10803. + * This program is free software; you can redistribute it and/or modify
  10804. + * it under the terms of the GNU General Public License version 2 as
  10805. + * published by the Free Software Foundation.
  10806. + *
  10807. + * This device provides a shared mechanism for controlling the power to
  10808. + * VideoCore subsystems.
  10809. + */
  10810. +
  10811. +#include <linux/module.h>
  10812. +#include <linux/semaphore.h>
  10813. +#include <linux/bug.h>
  10814. +#include <mach/power.h>
  10815. +#include <mach/vcio.h>
  10816. +#include <mach/arm_power.h>
  10817. +
  10818. +#define DRIVER_NAME "bcm2708_power"
  10819. +
  10820. +#define BCM_POWER_MAXCLIENTS 4
  10821. +#define BCM_POWER_NOCLIENT (1<<31)
  10822. +
  10823. +/* Some drivers expect there devices to be permanently powered */
  10824. +
  10825. +#ifdef CONFIG_USB
  10826. +#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB)
  10827. +#endif
  10828. +
  10829. +#if 1
  10830. +#define DPRINTK printk
  10831. +#else
  10832. +#define DPRINTK if (0) printk
  10833. +#endif
  10834. +
  10835. +struct state_struct {
  10836. + uint32_t global_request;
  10837. + uint32_t client_request[BCM_POWER_MAXCLIENTS];
  10838. + struct semaphore client_mutex;
  10839. + struct semaphore mutex;
  10840. +} g_state;
  10841. +
  10842. +int bcm_power_open(BCM_POWER_HANDLE_T *handle)
  10843. +{
  10844. + BCM_POWER_HANDLE_T i;
  10845. + int ret = -EBUSY;
  10846. +
  10847. + down(&g_state.client_mutex);
  10848. +
  10849. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  10850. + if (g_state.client_request[i] == BCM_POWER_NOCLIENT) {
  10851. + g_state.client_request[i] = BCM_POWER_NONE;
  10852. + *handle = i;
  10853. + ret = 0;
  10854. + break;
  10855. + }
  10856. + }
  10857. +
  10858. + up(&g_state.client_mutex);
  10859. +
  10860. + DPRINTK("bcm_power_open() -> %d\n", *handle);
  10861. +
  10862. + return ret;
  10863. +}
  10864. +EXPORT_SYMBOL_GPL(bcm_power_open);
  10865. +
  10866. +int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
  10867. +{
  10868. + int rc = 0;
  10869. +
  10870. + DPRINTK("bcm_power_request(%d, %x)\n", handle, request);
  10871. +
  10872. + if ((handle < BCM_POWER_MAXCLIENTS) &&
  10873. + (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) {
  10874. + if (down_interruptible(&g_state.mutex) != 0) {
  10875. + DPRINTK("bcm_power_request -> interrupted\n");
  10876. + return -EINTR;
  10877. + }
  10878. +
  10879. + if (request != g_state.client_request[handle]) {
  10880. + uint32_t others_request = 0;
  10881. + uint32_t global_request;
  10882. + BCM_POWER_HANDLE_T i;
  10883. +
  10884. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  10885. + if (i != handle)
  10886. + others_request |=
  10887. + g_state.client_request[i];
  10888. + }
  10889. + others_request &= ~BCM_POWER_NOCLIENT;
  10890. +
  10891. + global_request = request | others_request;
  10892. + if (global_request != g_state.global_request) {
  10893. + uint32_t actual;
  10894. +
  10895. + /* Send a request to VideoCore */
  10896. + bcm_mailbox_write(MBOX_CHAN_POWER,
  10897. + global_request << 4);
  10898. +
  10899. + /* Wait for a response during power-up */
  10900. + if (global_request & ~g_state.global_request) {
  10901. + rc = bcm_mailbox_read(MBOX_CHAN_POWER,
  10902. + &actual);
  10903. + DPRINTK
  10904. + ("bcm_mailbox_read -> %08x, %d\n",
  10905. + actual, rc);
  10906. + actual >>= 4;
  10907. + } else {
  10908. + rc = 0;
  10909. + actual = global_request;
  10910. + }
  10911. +
  10912. + if (rc == 0) {
  10913. + if (actual != global_request) {
  10914. + printk(KERN_ERR
  10915. + "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n",
  10916. + __func__,
  10917. + g_state.global_request,
  10918. + global_request, actual, request, others_request);
  10919. + /* A failure */
  10920. + BUG_ON((others_request & actual)
  10921. + != others_request);
  10922. + request &= actual;
  10923. + rc = -EIO;
  10924. + }
  10925. +
  10926. + g_state.global_request = actual;
  10927. + g_state.client_request[handle] =
  10928. + request;
  10929. + }
  10930. + }
  10931. + }
  10932. + up(&g_state.mutex);
  10933. + } else {
  10934. + rc = -EINVAL;
  10935. + }
  10936. + DPRINTK("bcm_power_request -> %d\n", rc);
  10937. + return rc;
  10938. +}
  10939. +EXPORT_SYMBOL_GPL(bcm_power_request);
  10940. +
  10941. +int bcm_power_close(BCM_POWER_HANDLE_T handle)
  10942. +{
  10943. + int rc;
  10944. +
  10945. + DPRINTK("bcm_power_close(%d)\n", handle);
  10946. +
  10947. + rc = bcm_power_request(handle, BCM_POWER_NONE);
  10948. + if (rc == 0)
  10949. + g_state.client_request[handle] = BCM_POWER_NOCLIENT;
  10950. +
  10951. + return rc;
  10952. +}
  10953. +EXPORT_SYMBOL_GPL(bcm_power_close);
  10954. +
  10955. +static int __init bcm_power_init(void)
  10956. +{
  10957. +#if defined(BCM_POWER_ALWAYS_ON)
  10958. + BCM_POWER_HANDLE_T always_on_handle;
  10959. +#endif
  10960. + int rc = 0;
  10961. + int i;
  10962. +
  10963. + printk(KERN_INFO "bcm_power: Broadcom power driver\n");
  10964. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  10965. +
  10966. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++)
  10967. + g_state.client_request[i] = BCM_POWER_NOCLIENT;
  10968. +
  10969. + sema_init(&g_state.client_mutex, 1);
  10970. + sema_init(&g_state.mutex, 1);
  10971. +
  10972. + g_state.global_request = 0;
  10973. +
  10974. +#if defined(BCM_POWER_ALWAYS_ON)
  10975. + if (BCM_POWER_ALWAYS_ON) {
  10976. + bcm_power_open(&always_on_handle);
  10977. + bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON);
  10978. + }
  10979. +#endif
  10980. +
  10981. + return rc;
  10982. +}
  10983. +
  10984. +static void __exit bcm_power_exit(void)
  10985. +{
  10986. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  10987. +}
  10988. +
  10989. +arch_initcall(bcm_power_init); /* Initialize early */
  10990. +module_exit(bcm_power_exit);
  10991. +
  10992. +MODULE_AUTHOR("Phil Elwell");
  10993. +MODULE_DESCRIPTION("Interface to BCM2708 power management");
  10994. +MODULE_LICENSE("GPL");
  10995. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/vcio.c linux-rpi/arch/arm/mach-bcm2708/vcio.c
  10996. --- linux-3.18.6/arch/arm/mach-bcm2708/vcio.c 1970-01-01 01:00:00.000000000 +0100
  10997. +++ linux-rpi/arch/arm/mach-bcm2708/vcio.c 2015-02-09 04:39:42.000000000 +0100
  10998. @@ -0,0 +1,484 @@
  10999. +/*
  11000. + * linux/arch/arm/mach-bcm2708/vcio.c
  11001. + *
  11002. + * Copyright (C) 2010 Broadcom
  11003. + *
  11004. + * This program is free software; you can redistribute it and/or modify
  11005. + * it under the terms of the GNU General Public License version 2 as
  11006. + * published by the Free Software Foundation.
  11007. + *
  11008. + * This device provides a shared mechanism for writing to the mailboxes,
  11009. + * semaphores, doorbells etc. that are shared between the ARM and the
  11010. + * VideoCore processor
  11011. + */
  11012. +
  11013. +#if defined(CONFIG_SERIAL_BCM_MBOX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  11014. +#define SUPPORT_SYSRQ
  11015. +#endif
  11016. +
  11017. +#include <linux/module.h>
  11018. +#include <linux/console.h>
  11019. +#include <linux/serial_core.h>
  11020. +#include <linux/serial.h>
  11021. +#include <linux/errno.h>
  11022. +#include <linux/device.h>
  11023. +#include <linux/init.h>
  11024. +#include <linux/mm.h>
  11025. +#include <linux/dma-mapping.h>
  11026. +#include <linux/platform_device.h>
  11027. +#include <linux/sysrq.h>
  11028. +#include <linux/delay.h>
  11029. +#include <linux/slab.h>
  11030. +#include <linux/interrupt.h>
  11031. +#include <linux/irq.h>
  11032. +
  11033. +#include <linux/io.h>
  11034. +
  11035. +#include <mach/vcio.h>
  11036. +#include <mach/platform.h>
  11037. +
  11038. +#include <asm/uaccess.h>
  11039. +
  11040. +
  11041. +#define DRIVER_NAME BCM_VCIO_DRIVER_NAME
  11042. +
  11043. +/* ----------------------------------------------------------------------
  11044. + * Mailbox
  11045. + * -------------------------------------------------------------------- */
  11046. +
  11047. +/* offsets from a mail box base address */
  11048. +#define MAIL_WRT 0x00 /* write - and next 4 words */
  11049. +#define MAIL_RD 0x00 /* read - and next 4 words */
  11050. +#define MAIL_POL 0x10 /* read without popping the fifo */
  11051. +#define MAIL_SND 0x14 /* sender ID (bottom two bits) */
  11052. +#define MAIL_STA 0x18 /* status */
  11053. +#define MAIL_CNF 0x1C /* configuration */
  11054. +
  11055. +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
  11056. +#define MBOX_MSG_LSB(chan, data28) (((data28) << 4) | ((chan) & 0xf))
  11057. +#define MBOX_CHAN(msg) ((msg) & 0xf)
  11058. +#define MBOX_DATA28(msg) ((msg) & ~0xf)
  11059. +#define MBOX_DATA28_LSB(msg) (((uint32_t)msg) >> 4)
  11060. +
  11061. +#define MBOX_MAGIC 0xd0d0c0de
  11062. +static struct class *vcio_class = NULL;
  11063. +struct vc_mailbox {
  11064. + struct device *dev; /* parent device */
  11065. + void __iomem *status;
  11066. + void __iomem *config;
  11067. + void __iomem *read;
  11068. + void __iomem *write;
  11069. + uint32_t msg[MBOX_CHAN_COUNT];
  11070. + struct semaphore sema[MBOX_CHAN_COUNT];
  11071. + uint32_t magic;
  11072. +};
  11073. +
  11074. +static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
  11075. + uint32_t addr_mbox)
  11076. +{
  11077. + int i;
  11078. +
  11079. + mbox_out->dev = dev;
  11080. + mbox_out->status = __io_address(addr_mbox + MAIL_STA);
  11081. + mbox_out->config = __io_address(addr_mbox + MAIL_CNF);
  11082. + mbox_out->read = __io_address(addr_mbox + MAIL_RD);
  11083. + /* Write to the other mailbox */
  11084. + mbox_out->write =
  11085. + __io_address((addr_mbox ^ ARM_0_MAIL0_WRT ^ ARM_0_MAIL1_WRT) +
  11086. + MAIL_WRT);
  11087. +
  11088. + for (i = 0; i < MBOX_CHAN_COUNT; i++) {
  11089. + mbox_out->msg[i] = 0;
  11090. + sema_init(&mbox_out->sema[i], 0);
  11091. + }
  11092. +
  11093. + /* Enable the interrupt on data reception */
  11094. + writel(ARM_MC_IHAVEDATAIRQEN, mbox_out->config);
  11095. +
  11096. + mbox_out->magic = MBOX_MAGIC;
  11097. +}
  11098. +
  11099. +static int mbox_write(struct vc_mailbox *mbox, unsigned chan, uint32_t data28)
  11100. +{
  11101. + int rc;
  11102. +
  11103. + if (mbox->magic != MBOX_MAGIC)
  11104. + rc = -EINVAL;
  11105. + else {
  11106. + /* wait for the mailbox FIFO to have some space in it */
  11107. + while (0 != (readl(mbox->status) & ARM_MS_FULL))
  11108. + cpu_relax();
  11109. +
  11110. + writel(MBOX_MSG(chan, data28), mbox->write);
  11111. + rc = 0;
  11112. + }
  11113. + return rc;
  11114. +}
  11115. +
  11116. +static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
  11117. +{
  11118. + int rc;
  11119. +
  11120. + if (mbox->magic != MBOX_MAGIC)
  11121. + rc = -EINVAL;
  11122. + else {
  11123. + down(&mbox->sema[chan]);
  11124. + *data28 = MBOX_DATA28(mbox->msg[chan]);
  11125. + mbox->msg[chan] = 0;
  11126. + rc = 0;
  11127. + }
  11128. + return rc;
  11129. +}
  11130. +
  11131. +static irqreturn_t mbox_irq(int irq, void *dev_id)
  11132. +{
  11133. + /* wait for the mailbox FIFO to have some data in it */
  11134. + struct vc_mailbox *mbox = (struct vc_mailbox *) dev_id;
  11135. + int status = readl(mbox->status);
  11136. + int ret = IRQ_NONE;
  11137. +
  11138. + while (!(status & ARM_MS_EMPTY)) {
  11139. + uint32_t msg = readl(mbox->read);
  11140. + int chan = MBOX_CHAN(msg);
  11141. + if (chan < MBOX_CHAN_COUNT) {
  11142. + if (mbox->msg[chan]) {
  11143. + /* Overflow */
  11144. + printk(KERN_ERR DRIVER_NAME
  11145. + ": mbox chan %d overflow - drop %08x\n",
  11146. + chan, msg);
  11147. + } else {
  11148. + mbox->msg[chan] = (msg | 0xf);
  11149. + up(&mbox->sema[chan]);
  11150. + }
  11151. + } else {
  11152. + printk(KERN_ERR DRIVER_NAME
  11153. + ": invalid channel selector (msg %08x)\n", msg);
  11154. + }
  11155. + ret = IRQ_HANDLED;
  11156. + status = readl(mbox->status);
  11157. + }
  11158. + return ret;
  11159. +}
  11160. +
  11161. +static struct irqaction mbox_irqaction = {
  11162. + .name = "ARM Mailbox IRQ",
  11163. + .flags = IRQF_DISABLED | IRQF_IRQPOLL,
  11164. + .handler = mbox_irq,
  11165. +};
  11166. +
  11167. +/* ----------------------------------------------------------------------
  11168. + * Mailbox Methods
  11169. + * -------------------------------------------------------------------- */
  11170. +
  11171. +static struct device *mbox_dev; /* we assume there's only one! */
  11172. +
  11173. +static int dev_mbox_write(struct device *dev, unsigned chan, uint32_t data28)
  11174. +{
  11175. + int rc;
  11176. +
  11177. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  11178. + device_lock(dev);
  11179. + rc = mbox_write(mailbox, chan, data28);
  11180. + device_unlock(dev);
  11181. +
  11182. + return rc;
  11183. +}
  11184. +
  11185. +static int dev_mbox_read(struct device *dev, unsigned chan, uint32_t *data28)
  11186. +{
  11187. + int rc;
  11188. +
  11189. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  11190. + device_lock(dev);
  11191. + rc = mbox_read(mailbox, chan, data28);
  11192. + device_unlock(dev);
  11193. +
  11194. + return rc;
  11195. +}
  11196. +
  11197. +extern int bcm_mailbox_write(unsigned chan, uint32_t data28)
  11198. +{
  11199. + if (mbox_dev)
  11200. + return dev_mbox_write(mbox_dev, chan, data28);
  11201. + else
  11202. + return -ENODEV;
  11203. +}
  11204. +EXPORT_SYMBOL_GPL(bcm_mailbox_write);
  11205. +
  11206. +extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
  11207. +{
  11208. + if (mbox_dev)
  11209. + return dev_mbox_read(mbox_dev, chan, data28);
  11210. + else
  11211. + return -ENODEV;
  11212. +}
  11213. +EXPORT_SYMBOL_GPL(bcm_mailbox_read);
  11214. +
  11215. +static void dev_mbox_register(const char *dev_name, struct device *dev)
  11216. +{
  11217. + mbox_dev = dev;
  11218. +}
  11219. +
  11220. +static int mbox_copy_from_user(void *dst, const void *src, int size)
  11221. +{
  11222. + if ( (uint32_t)src < TASK_SIZE)
  11223. + {
  11224. + return copy_from_user(dst, src, size);
  11225. + }
  11226. + else
  11227. + {
  11228. + memcpy( dst, src, size );
  11229. + return 0;
  11230. + }
  11231. +}
  11232. +
  11233. +static int mbox_copy_to_user(void *dst, const void *src, int size)
  11234. +{
  11235. + if ( (uint32_t)dst < TASK_SIZE)
  11236. + {
  11237. + return copy_to_user(dst, src, size);
  11238. + }
  11239. + else
  11240. + {
  11241. + memcpy( dst, src, size );
  11242. + return 0;
  11243. + }
  11244. +}
  11245. +
  11246. +static DEFINE_MUTEX(mailbox_lock);
  11247. +extern int bcm_mailbox_property(void *data, int size)
  11248. +{
  11249. + uint32_t success;
  11250. + dma_addr_t mem_bus; /* the memory address accessed from videocore */
  11251. + void *mem_kern; /* the memory address accessed from driver */
  11252. + int s = 0;
  11253. +
  11254. + mutex_lock(&mailbox_lock);
  11255. + /* allocate some memory for the messages communicating with GPU */
  11256. + mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
  11257. + if (mem_kern) {
  11258. + /* create the message */
  11259. + mbox_copy_from_user(mem_kern, data, size);
  11260. +
  11261. + /* send the message */
  11262. + wmb();
  11263. + s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
  11264. + if (s == 0) {
  11265. + s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
  11266. + }
  11267. + if (s == 0) {
  11268. + /* copy the response */
  11269. + rmb();
  11270. + mbox_copy_to_user(data, mem_kern, size);
  11271. + }
  11272. + dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
  11273. + } else {
  11274. + s = -ENOMEM;
  11275. + }
  11276. + if (s != 0)
  11277. + printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
  11278. +
  11279. + mutex_unlock(&mailbox_lock);
  11280. + return s;
  11281. +}
  11282. +EXPORT_SYMBOL_GPL(bcm_mailbox_property);
  11283. +
  11284. +/* ----------------------------------------------------------------------
  11285. + * Platform Device for Mailbox
  11286. + * -------------------------------------------------------------------- */
  11287. +
  11288. +/*
  11289. + * Is the device open right now? Used to prevent
  11290. + * concurent access into the same device
  11291. + */
  11292. +static int Device_Open = 0;
  11293. +
  11294. +/*
  11295. + * This is called whenever a process attempts to open the device file
  11296. + */
  11297. +static int device_open(struct inode *inode, struct file *file)
  11298. +{
  11299. + /*
  11300. + * We don't want to talk to two processes at the same time
  11301. + */
  11302. + if (Device_Open)
  11303. + return -EBUSY;
  11304. +
  11305. + Device_Open++;
  11306. + /*
  11307. + * Initialize the message
  11308. + */
  11309. + try_module_get(THIS_MODULE);
  11310. + return 0;
  11311. +}
  11312. +
  11313. +static int device_release(struct inode *inode, struct file *file)
  11314. +{
  11315. + /*
  11316. + * We're now ready for our next caller
  11317. + */
  11318. + Device_Open--;
  11319. +
  11320. + module_put(THIS_MODULE);
  11321. + return 0;
  11322. +}
  11323. +
  11324. +/*
  11325. + * This function is called whenever a process tries to do an ioctl on our
  11326. + * device file. We get two extra parameters (additional to the inode and file
  11327. + * structures, which all device functions get): the number of the ioctl called
  11328. + * and the parameter given to the ioctl function.
  11329. + *
  11330. + * If the ioctl is write or read/write (meaning output is returned to the
  11331. + * calling process), the ioctl call returns the output of this function.
  11332. + *
  11333. + */
  11334. +static long device_ioctl(struct file *file, /* see include/linux/fs.h */
  11335. + unsigned int ioctl_num, /* number and param for ioctl */
  11336. + unsigned long ioctl_param)
  11337. +{
  11338. + unsigned size;
  11339. + /*
  11340. + * Switch according to the ioctl called
  11341. + */
  11342. + switch (ioctl_num) {
  11343. + case IOCTL_MBOX_PROPERTY:
  11344. + /*
  11345. + * Receive a pointer to a message (in user space) and set that
  11346. + * to be the device's message. Get the parameter given to
  11347. + * ioctl by the process.
  11348. + */
  11349. + mbox_copy_from_user(&size, (void *)ioctl_param, sizeof size);
  11350. + return bcm_mailbox_property((void *)ioctl_param, size);
  11351. + break;
  11352. + default:
  11353. + printk(KERN_ERR DRIVER_NAME "unknown ioctl: %d\n", ioctl_num);
  11354. + return -EINVAL;
  11355. + }
  11356. +
  11357. + return 0;
  11358. +}
  11359. +
  11360. +/* Module Declarations */
  11361. +
  11362. +/*
  11363. + * This structure will hold the functions to be called
  11364. + * when a process does something to the device we
  11365. + * created. Since a pointer to this structure is kept in
  11366. + * the devices table, it can't be local to
  11367. + * init_module. NULL is for unimplemented functios.
  11368. + */
  11369. +struct file_operations fops = {
  11370. + .unlocked_ioctl = device_ioctl,
  11371. + .open = device_open,
  11372. + .release = device_release, /* a.k.a. close */
  11373. +};
  11374. +
  11375. +static int bcm_vcio_probe(struct platform_device *pdev)
  11376. +{
  11377. + int ret = 0;
  11378. + struct vc_mailbox *mailbox;
  11379. +
  11380. + mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
  11381. + if (NULL == mailbox) {
  11382. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  11383. + "mailbox memory\n");
  11384. + ret = -ENOMEM;
  11385. + } else {
  11386. + struct resource *res;
  11387. +
  11388. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  11389. + if (res == NULL) {
  11390. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  11391. + "resource\n");
  11392. + ret = -ENODEV;
  11393. + kfree(mailbox);
  11394. + } else {
  11395. + /* should be based on the registers from res really */
  11396. + mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
  11397. +
  11398. + platform_set_drvdata(pdev, mailbox);
  11399. + dev_mbox_register(DRIVER_NAME, &pdev->dev);
  11400. +
  11401. + mbox_irqaction.dev_id = mailbox;
  11402. + setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
  11403. + printk(KERN_INFO DRIVER_NAME ": mailbox at %p\n",
  11404. + __io_address(ARM_0_MAIL0_RD));
  11405. + }
  11406. + }
  11407. +
  11408. + if (ret == 0) {
  11409. + /*
  11410. + * Register the character device
  11411. + */
  11412. + ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
  11413. +
  11414. + /*
  11415. + * Negative values signify an error
  11416. + */
  11417. + if (ret < 0) {
  11418. + printk(KERN_ERR DRIVER_NAME
  11419. + "Failed registering the character device %d\n", ret);
  11420. + return ret;
  11421. + }
  11422. + vcio_class = class_create(THIS_MODULE, BCM_VCIO_DRIVER_NAME);
  11423. + if (IS_ERR(vcio_class)) {
  11424. + ret = PTR_ERR(vcio_class);
  11425. + return ret ;
  11426. + }
  11427. + device_create(vcio_class, NULL, MKDEV(MAJOR_NUM, 0), NULL,
  11428. + "vcio");
  11429. + }
  11430. + return ret;
  11431. +}
  11432. +
  11433. +static int bcm_vcio_remove(struct platform_device *pdev)
  11434. +{
  11435. + struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
  11436. +
  11437. + platform_set_drvdata(pdev, NULL);
  11438. + kfree(mailbox);
  11439. +
  11440. + return 0;
  11441. +}
  11442. +
  11443. +static struct platform_driver bcm_mbox_driver = {
  11444. + .probe = bcm_vcio_probe,
  11445. + .remove = bcm_vcio_remove,
  11446. +
  11447. + .driver = {
  11448. + .name = DRIVER_NAME,
  11449. + .owner = THIS_MODULE,
  11450. + },
  11451. +};
  11452. +
  11453. +static int __init bcm_mbox_init(void)
  11454. +{
  11455. + int ret;
  11456. +
  11457. + printk(KERN_INFO "mailbox: Broadcom VideoCore Mailbox driver\n");
  11458. +
  11459. + ret = platform_driver_register(&bcm_mbox_driver);
  11460. + if (ret != 0) {
  11461. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  11462. + "on platform\n");
  11463. + }
  11464. +
  11465. + return ret;
  11466. +}
  11467. +
  11468. +static void __exit bcm_mbox_exit(void)
  11469. +{
  11470. + device_destroy(vcio_class,MKDEV(MAJOR_NUM, 0));
  11471. + class_destroy(vcio_class);
  11472. + unregister_chrdev(MAJOR_NUM, DEVICE_FILE_NAME);
  11473. + platform_driver_unregister(&bcm_mbox_driver);
  11474. +}
  11475. +
  11476. +arch_initcall(bcm_mbox_init); /* Initialize early */
  11477. +module_exit(bcm_mbox_exit);
  11478. +
  11479. +MODULE_AUTHOR("Gray Girling");
  11480. +MODULE_DESCRIPTION("ARM I/O to VideoCore processor");
  11481. +MODULE_LICENSE("GPL");
  11482. +MODULE_ALIAS("platform:bcm-mbox");
  11483. diff -Nur linux-3.18.6/arch/arm/mach-bcm2708/vc_mem.c linux-rpi/arch/arm/mach-bcm2708/vc_mem.c
  11484. --- linux-3.18.6/arch/arm/mach-bcm2708/vc_mem.c 1970-01-01 01:00:00.000000000 +0100
  11485. +++ linux-rpi/arch/arm/mach-bcm2708/vc_mem.c 2015-02-09 04:39:42.000000000 +0100
  11486. @@ -0,0 +1,432 @@
  11487. +/*****************************************************************************
  11488. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  11489. +*
  11490. +* Unless you and Broadcom execute a separate written software license
  11491. +* agreement governing use of this software, this software is licensed to you
  11492. +* under the terms of the GNU General Public License version 2, available at
  11493. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  11494. +*
  11495. +* Notwithstanding the above, under no circumstances may you combine this
  11496. +* software in any way with any other Broadcom software provided under a
  11497. +* license other than the GPL, without Broadcom's express prior written
  11498. +* consent.
  11499. +*****************************************************************************/
  11500. +
  11501. +#include <linux/kernel.h>
  11502. +#include <linux/module.h>
  11503. +#include <linux/fs.h>
  11504. +#include <linux/device.h>
  11505. +#include <linux/cdev.h>
  11506. +#include <linux/mm.h>
  11507. +#include <linux/slab.h>
  11508. +#include <linux/debugfs.h>
  11509. +#include <asm/uaccess.h>
  11510. +#include <linux/dma-mapping.h>
  11511. +
  11512. +#ifdef CONFIG_ARCH_KONA
  11513. +#include <chal/chal_ipc.h>
  11514. +#elif CONFIG_ARCH_BCM2708
  11515. +#else
  11516. +#include <csp/chal_ipc.h>
  11517. +#endif
  11518. +
  11519. +#include "mach/vc_mem.h"
  11520. +#include <mach/vcio.h>
  11521. +
  11522. +#define DRIVER_NAME "vc-mem"
  11523. +
  11524. +// Device (/dev) related variables
  11525. +static dev_t vc_mem_devnum = 0;
  11526. +static struct class *vc_mem_class = NULL;
  11527. +static struct cdev vc_mem_cdev;
  11528. +static int vc_mem_inited = 0;
  11529. +
  11530. +#ifdef CONFIG_DEBUG_FS
  11531. +static struct dentry *vc_mem_debugfs_entry;
  11532. +#endif
  11533. +
  11534. +/*
  11535. + * Videocore memory addresses and size
  11536. + *
  11537. + * Drivers that wish to know the videocore memory addresses and sizes should
  11538. + * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
  11539. + * headers. This allows the other drivers to not be tied down to a a certain
  11540. + * address/size at compile time.
  11541. + *
  11542. + * In the future, the goal is to have the videocore memory virtual address and
  11543. + * size be calculated at boot time rather than at compile time. The decision of
  11544. + * where the videocore memory resides and its size would be in the hands of the
  11545. + * bootloader (and/or kernel). When that happens, the values of these variables
  11546. + * would be calculated and assigned in the init function.
  11547. + */
  11548. +// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
  11549. +unsigned long mm_vc_mem_phys_addr = 0x00000000;
  11550. +unsigned int mm_vc_mem_size = 0;
  11551. +unsigned int mm_vc_mem_base = 0;
  11552. +
  11553. +EXPORT_SYMBOL(mm_vc_mem_phys_addr);
  11554. +EXPORT_SYMBOL(mm_vc_mem_size);
  11555. +EXPORT_SYMBOL(mm_vc_mem_base);
  11556. +
  11557. +static uint phys_addr = 0;
  11558. +static uint mem_size = 0;
  11559. +static uint mem_base = 0;
  11560. +
  11561. +
  11562. +/****************************************************************************
  11563. +*
  11564. +* vc_mem_open
  11565. +*
  11566. +***************************************************************************/
  11567. +
  11568. +static int
  11569. +vc_mem_open(struct inode *inode, struct file *file)
  11570. +{
  11571. + (void) inode;
  11572. + (void) file;
  11573. +
  11574. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  11575. +
  11576. + return 0;
  11577. +}
  11578. +
  11579. +/****************************************************************************
  11580. +*
  11581. +* vc_mem_release
  11582. +*
  11583. +***************************************************************************/
  11584. +
  11585. +static int
  11586. +vc_mem_release(struct inode *inode, struct file *file)
  11587. +{
  11588. + (void) inode;
  11589. + (void) file;
  11590. +
  11591. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  11592. +
  11593. + return 0;
  11594. +}
  11595. +
  11596. +/****************************************************************************
  11597. +*
  11598. +* vc_mem_get_size
  11599. +*
  11600. +***************************************************************************/
  11601. +
  11602. +static void
  11603. +vc_mem_get_size(void)
  11604. +{
  11605. +}
  11606. +
  11607. +/****************************************************************************
  11608. +*
  11609. +* vc_mem_get_base
  11610. +*
  11611. +***************************************************************************/
  11612. +
  11613. +static void
  11614. +vc_mem_get_base(void)
  11615. +{
  11616. +}
  11617. +
  11618. +/****************************************************************************
  11619. +*
  11620. +* vc_mem_get_current_size
  11621. +*
  11622. +***************************************************************************/
  11623. +
  11624. +int
  11625. +vc_mem_get_current_size(void)
  11626. +{
  11627. + return mm_vc_mem_size;
  11628. +}
  11629. +
  11630. +EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
  11631. +
  11632. +/****************************************************************************
  11633. +*
  11634. +* vc_mem_ioctl
  11635. +*
  11636. +***************************************************************************/
  11637. +
  11638. +static long
  11639. +vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  11640. +{
  11641. + int rc = 0;
  11642. +
  11643. + (void) cmd;
  11644. + (void) arg;
  11645. +
  11646. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  11647. +
  11648. + switch (cmd) {
  11649. + case VC_MEM_IOC_MEM_PHYS_ADDR:
  11650. + {
  11651. + pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n",
  11652. + __func__, (void *) mm_vc_mem_phys_addr);
  11653. +
  11654. + if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
  11655. + sizeof (mm_vc_mem_phys_addr)) != 0) {
  11656. + rc = -EFAULT;
  11657. + }
  11658. + break;
  11659. + }
  11660. + case VC_MEM_IOC_MEM_SIZE:
  11661. + {
  11662. + // Get the videocore memory size first
  11663. + vc_mem_get_size();
  11664. +
  11665. + pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
  11666. + mm_vc_mem_size);
  11667. +
  11668. + if (copy_to_user((void *) arg, &mm_vc_mem_size,
  11669. + sizeof (mm_vc_mem_size)) != 0) {
  11670. + rc = -EFAULT;
  11671. + }
  11672. + break;
  11673. + }
  11674. + case VC_MEM_IOC_MEM_BASE:
  11675. + {
  11676. + // Get the videocore memory base
  11677. + vc_mem_get_base();
  11678. +
  11679. + pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
  11680. + mm_vc_mem_base);
  11681. +
  11682. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  11683. + sizeof (mm_vc_mem_base)) != 0) {
  11684. + rc = -EFAULT;
  11685. + }
  11686. + break;
  11687. + }
  11688. + case VC_MEM_IOC_MEM_LOAD:
  11689. + {
  11690. + // Get the videocore memory base
  11691. + vc_mem_get_base();
  11692. +
  11693. + pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
  11694. + mm_vc_mem_base);
  11695. +
  11696. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  11697. + sizeof (mm_vc_mem_base)) != 0) {
  11698. + rc = -EFAULT;
  11699. + }
  11700. + break;
  11701. + }
  11702. + default:
  11703. + {
  11704. + return -ENOTTY;
  11705. + }
  11706. + }
  11707. + pr_debug("%s: file = 0x%p returning %d\n", __func__, file, rc);
  11708. +
  11709. + return rc;
  11710. +}
  11711. +
  11712. +/****************************************************************************
  11713. +*
  11714. +* vc_mem_mmap
  11715. +*
  11716. +***************************************************************************/
  11717. +
  11718. +static int
  11719. +vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
  11720. +{
  11721. + int rc = 0;
  11722. + unsigned long length = vma->vm_end - vma->vm_start;
  11723. + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  11724. +
  11725. + pr_debug("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n",
  11726. + __func__, (long) vma->vm_start, (long) vma->vm_end,
  11727. + (long) vma->vm_pgoff);
  11728. +
  11729. + if (offset + length > mm_vc_mem_size) {
  11730. + pr_err("%s: length %ld is too big\n", __func__, length);
  11731. + return -EINVAL;
  11732. + }
  11733. + // Do not cache the memory map
  11734. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  11735. +
  11736. + rc = remap_pfn_range(vma, vma->vm_start,
  11737. + (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
  11738. + vma->vm_pgoff, length, vma->vm_page_prot);
  11739. + if (rc != 0) {
  11740. + pr_err("%s: remap_pfn_range failed (rc=%d)\n", __func__, rc);
  11741. + }
  11742. +
  11743. + return rc;
  11744. +}
  11745. +
  11746. +/****************************************************************************
  11747. +*
  11748. +* File Operations for the driver.
  11749. +*
  11750. +***************************************************************************/
  11751. +
  11752. +static const struct file_operations vc_mem_fops = {
  11753. + .owner = THIS_MODULE,
  11754. + .open = vc_mem_open,
  11755. + .release = vc_mem_release,
  11756. + .unlocked_ioctl = vc_mem_ioctl,
  11757. + .mmap = vc_mem_mmap,
  11758. +};
  11759. +
  11760. +#ifdef CONFIG_DEBUG_FS
  11761. +static void vc_mem_debugfs_deinit(void)
  11762. +{
  11763. + debugfs_remove_recursive(vc_mem_debugfs_entry);
  11764. + vc_mem_debugfs_entry = NULL;
  11765. +}
  11766. +
  11767. +
  11768. +static int vc_mem_debugfs_init(
  11769. + struct device *dev)
  11770. +{
  11771. + vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
  11772. + if (!vc_mem_debugfs_entry) {
  11773. + dev_warn(dev, "could not create debugfs entry\n");
  11774. + return -EFAULT;
  11775. + }
  11776. +
  11777. + if (!debugfs_create_x32("vc_mem_phys_addr",
  11778. + 0444,
  11779. + vc_mem_debugfs_entry,
  11780. + (u32 *)&mm_vc_mem_phys_addr)) {
  11781. + dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
  11782. + __func__);
  11783. + goto fail;
  11784. + }
  11785. +
  11786. + if (!debugfs_create_x32("vc_mem_size",
  11787. + 0444,
  11788. + vc_mem_debugfs_entry,
  11789. + (u32 *)&mm_vc_mem_size)) {
  11790. + dev_warn(dev, "%s:could not create vc_mem_size entry\n",
  11791. + __func__);
  11792. + goto fail;
  11793. + }
  11794. +
  11795. + if (!debugfs_create_x32("vc_mem_base",
  11796. + 0444,
  11797. + vc_mem_debugfs_entry,
  11798. + (u32 *)&mm_vc_mem_base)) {
  11799. + dev_warn(dev, "%s:could not create vc_mem_base entry\n",
  11800. + __func__);
  11801. + goto fail;
  11802. + }
  11803. +
  11804. + return 0;
  11805. +
  11806. +fail:
  11807. + vc_mem_debugfs_deinit();
  11808. + return -EFAULT;
  11809. +}
  11810. +
  11811. +#endif /* CONFIG_DEBUG_FS */
  11812. +
  11813. +
  11814. +/****************************************************************************
  11815. +*
  11816. +* vc_mem_init
  11817. +*
  11818. +***************************************************************************/
  11819. +
  11820. +static int __init
  11821. +vc_mem_init(void)
  11822. +{
  11823. + int rc = -EFAULT;
  11824. + struct device *dev;
  11825. +
  11826. + pr_debug("%s: called\n", __func__);
  11827. +
  11828. + mm_vc_mem_phys_addr = phys_addr;
  11829. + mm_vc_mem_size = mem_size;
  11830. + mm_vc_mem_base = mem_base;
  11831. +
  11832. + vc_mem_get_size();
  11833. +
  11834. + pr_info("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
  11835. + mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
  11836. +
  11837. + if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
  11838. + pr_err("%s: alloc_chrdev_region failed (rc=%d)\n",
  11839. + __func__, rc);
  11840. + goto out_err;
  11841. + }
  11842. +
  11843. + cdev_init(&vc_mem_cdev, &vc_mem_fops);
  11844. + if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
  11845. + pr_err("%s: cdev_add failed (rc=%d)\n", __func__, rc);
  11846. + goto out_unregister;
  11847. + }
  11848. +
  11849. + vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
  11850. + if (IS_ERR(vc_mem_class)) {
  11851. + rc = PTR_ERR(vc_mem_class);
  11852. + pr_err("%s: class_create failed (rc=%d)\n", __func__, rc);
  11853. + goto out_cdev_del;
  11854. + }
  11855. +
  11856. + dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
  11857. + DRIVER_NAME);
  11858. + if (IS_ERR(dev)) {
  11859. + rc = PTR_ERR(dev);
  11860. + pr_err("%s: device_create failed (rc=%d)\n", __func__, rc);
  11861. + goto out_class_destroy;
  11862. + }
  11863. +
  11864. +#ifdef CONFIG_DEBUG_FS
  11865. + /* don't fail if the debug entries cannot be created */
  11866. + vc_mem_debugfs_init(dev);
  11867. +#endif
  11868. +
  11869. + vc_mem_inited = 1;
  11870. + return 0;
  11871. +
  11872. + device_destroy(vc_mem_class, vc_mem_devnum);
  11873. +
  11874. + out_class_destroy:
  11875. + class_destroy(vc_mem_class);
  11876. + vc_mem_class = NULL;
  11877. +
  11878. + out_cdev_del:
  11879. + cdev_del(&vc_mem_cdev);
  11880. +
  11881. + out_unregister:
  11882. + unregister_chrdev_region(vc_mem_devnum, 1);
  11883. +
  11884. + out_err:
  11885. + return -1;
  11886. +}
  11887. +
  11888. +/****************************************************************************
  11889. +*
  11890. +* vc_mem_exit
  11891. +*
  11892. +***************************************************************************/
  11893. +
  11894. +static void __exit
  11895. +vc_mem_exit(void)
  11896. +{
  11897. + pr_debug("%s: called\n", __func__);
  11898. +
  11899. + if (vc_mem_inited) {
  11900. +#if CONFIG_DEBUG_FS
  11901. + vc_mem_debugfs_deinit();
  11902. +#endif
  11903. + device_destroy(vc_mem_class, vc_mem_devnum);
  11904. + class_destroy(vc_mem_class);
  11905. + cdev_del(&vc_mem_cdev);
  11906. + unregister_chrdev_region(vc_mem_devnum, 1);
  11907. + }
  11908. +}
  11909. +
  11910. +module_init(vc_mem_init);
  11911. +module_exit(vc_mem_exit);
  11912. +MODULE_LICENSE("GPL");
  11913. +MODULE_AUTHOR("Broadcom Corporation");
  11914. +
  11915. +module_param(phys_addr, uint, 0644);
  11916. +module_param(mem_size, uint, 0644);
  11917. +module_param(mem_base, uint, 0644);
  11918. +
  11919. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/armctrl.c linux-rpi/arch/arm/mach-bcm2709/armctrl.c
  11920. --- linux-3.18.6/arch/arm/mach-bcm2709/armctrl.c 1970-01-01 01:00:00.000000000 +0100
  11921. +++ linux-rpi/arch/arm/mach-bcm2709/armctrl.c 2015-02-09 04:39:42.000000000 +0100
  11922. @@ -0,0 +1,365 @@
  11923. +/*
  11924. + * linux/arch/arm/mach-bcm2708/armctrl.c
  11925. + *
  11926. + * Copyright (C) 2010 Broadcom
  11927. + *
  11928. + * This program is free software; you can redistribute it and/or modify
  11929. + * it under the terms of the GNU General Public License as published by
  11930. + * the Free Software Foundation; either version 2 of the License, or
  11931. + * (at your option) any later version.
  11932. + *
  11933. + * This program is distributed in the hope that it will be useful,
  11934. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11935. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11936. + * GNU General Public License for more details.
  11937. + *
  11938. + * You should have received a copy of the GNU General Public License
  11939. + * along with this program; if not, write to the Free Software
  11940. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  11941. + */
  11942. +#include <linux/init.h>
  11943. +#include <linux/list.h>
  11944. +#include <linux/io.h>
  11945. +#include <linux/version.h>
  11946. +#include <linux/syscore_ops.h>
  11947. +#include <linux/interrupt.h>
  11948. +#include <linux/irqdomain.h>
  11949. +#include <linux/of.h>
  11950. +
  11951. +#include <asm/mach/irq.h>
  11952. +#include <mach/hardware.h>
  11953. +#include "armctrl.h"
  11954. +
  11955. +/* For support of kernels >= 3.0 assume only one VIC for now*/
  11956. +static unsigned int remap_irqs[(INTERRUPT_ARASANSDIO + 1) - INTERRUPT_JPEG] = {
  11957. + INTERRUPT_VC_JPEG,
  11958. + INTERRUPT_VC_USB,
  11959. + INTERRUPT_VC_3D,
  11960. + INTERRUPT_VC_DMA2,
  11961. + INTERRUPT_VC_DMA3,
  11962. + INTERRUPT_VC_I2C,
  11963. + INTERRUPT_VC_SPI,
  11964. + INTERRUPT_VC_I2SPCM,
  11965. + INTERRUPT_VC_SDIO,
  11966. + INTERRUPT_VC_UART,
  11967. + INTERRUPT_VC_ARASANSDIO
  11968. +};
  11969. +
  11970. +static void armctrl_mask_irq(struct irq_data *d)
  11971. +{
  11972. + static const unsigned int disables[4] = {
  11973. + ARM_IRQ_DIBL1,
  11974. + ARM_IRQ_DIBL2,
  11975. + ARM_IRQ_DIBL3,
  11976. + 0
  11977. + };
  11978. + int i;
  11979. + if (d->irq >= FIQ_START) {
  11980. + writel(0, __io_address(ARM_IRQ_FAST));
  11981. + } else if (d->irq >= IRQ_ARM_LOCAL_CNTPSIRQ && d->irq < IRQ_ARM_LOCAL_CNTPSIRQ + 4) {
  11982. +#if 1
  11983. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq) - IRQ_ARM_LOCAL_CNTPSIRQ;
  11984. + for (i=0; i<4; i++) // i = raw_smp_processor_id(); //
  11985. + {
  11986. + unsigned int val = readl(__io_address(ARM_LOCAL_TIMER_INT_CONTROL0 + 4*i));
  11987. + writel(val &~ (1 << data), __io_address(ARM_LOCAL_TIMER_INT_CONTROL0 + 4*i));
  11988. + }
  11989. +#endif
  11990. + } else if (d->irq >= IRQ_ARM_LOCAL_MAILBOX0 && d->irq < IRQ_ARM_LOCAL_MAILBOX0 + 4) {
  11991. +#if 0
  11992. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq) - IRQ_ARM_LOCAL_MAILBOX0;
  11993. + for (i=0; i<4; i++) {
  11994. + unsigned int val = readl(__io_address(ARM_LOCAL_MAILBOX_INT_CONTROL0 + 4*i));
  11995. + writel(val &~ (1 << data), __io_address(ARM_LOCAL_MAILBOX_INT_CONTROL0 + 4*i));
  11996. + }
  11997. +#endif
  11998. + } else if (d->irq >= ARM_IRQ1_BASE && d->irq < ARM_IRQ_LOCAL_BASE) {
  11999. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  12000. + writel(1 << (data & 0x1f), __io_address(disables[(data >> 5) & 0x3]));
  12001. + } else { printk("%s: %d\n", __func__, d->irq); BUG(); }
  12002. +}
  12003. +
  12004. +static void armctrl_unmask_irq(struct irq_data *d)
  12005. +{
  12006. + static const unsigned int enables[4] = {
  12007. + ARM_IRQ_ENBL1,
  12008. + ARM_IRQ_ENBL2,
  12009. + ARM_IRQ_ENBL3,
  12010. + 0
  12011. + };
  12012. + int i;
  12013. + if (d->irq >= FIQ_START) {
  12014. + unsigned int data;
  12015. + if (num_online_cpus() > 1) {
  12016. + data = readl(__io_address(ARM_LOCAL_GPU_INT_ROUTING));
  12017. + data &= ~0xc;
  12018. + data |= (1 << 2);
  12019. + writel(data, __io_address(ARM_LOCAL_GPU_INT_ROUTING));
  12020. + }
  12021. + /* Unmask in ARMCTRL block after routing it properly */
  12022. + data = (unsigned int)irq_get_chip_data(d->irq) - FIQ_START;
  12023. + writel(0x80 | data, __io_address(ARM_IRQ_FAST));
  12024. + } else if (d->irq >= IRQ_ARM_LOCAL_CNTPSIRQ && d->irq < IRQ_ARM_LOCAL_CNTPSIRQ + 4) {
  12025. +#if 1
  12026. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq) - IRQ_ARM_LOCAL_CNTPSIRQ;
  12027. + for (i=0; i<4; i++) // i = raw_smp_processor_id();
  12028. + {
  12029. + unsigned int val = readl(__io_address(ARM_LOCAL_TIMER_INT_CONTROL0 + 4*i));
  12030. + writel(val | (1 << data), __io_address(ARM_LOCAL_TIMER_INT_CONTROL0 + 4*i));
  12031. + }
  12032. +#endif
  12033. + } else if (d->irq >= IRQ_ARM_LOCAL_MAILBOX0 && d->irq < IRQ_ARM_LOCAL_MAILBOX0 + 4) {
  12034. +#if 0
  12035. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq) - IRQ_ARM_LOCAL_MAILBOX0;
  12036. + for (i=0; i<4; i++) {
  12037. + unsigned int val = readl(__io_address(ARM_LOCAL_MAILBOX_INT_CONTROL0 + 4*i));
  12038. + writel(val | (1 << data), __io_address(ARM_LOCAL_MAILBOX_INT_CONTROL0 + 4*i));
  12039. + }
  12040. +#endif
  12041. + } else if (d->irq >= ARM_IRQ1_BASE && d->irq < ARM_IRQ_LOCAL_BASE) {
  12042. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  12043. + writel(1 << (data & 0x1f), __io_address(enables[(data >> 5) & 0x3]));
  12044. + } else { printk("%s: %d\n", __func__, d->irq); BUG(); }
  12045. +}
  12046. +
  12047. +#ifdef CONFIG_OF
  12048. +
  12049. +#define NR_IRQS_BANK0 21
  12050. +#define NR_BANKS 4
  12051. +#define IRQS_PER_BANK 32
  12052. +
  12053. +/* from drivers/irqchip/irq-bcm2835.c */
  12054. +static int armctrl_xlate(struct irq_domain *d, struct device_node *ctrlr,
  12055. + const u32 *intspec, unsigned int intsize,
  12056. + unsigned long *out_hwirq, unsigned int *out_type)
  12057. +{
  12058. + if (WARN_ON(intsize != 2))
  12059. + return -EINVAL;
  12060. +
  12061. + if (WARN_ON(intspec[0] >= NR_BANKS))
  12062. + return -EINVAL;
  12063. +
  12064. + if (WARN_ON(intspec[1] >= IRQS_PER_BANK))
  12065. + return -EINVAL;
  12066. +
  12067. + if (WARN_ON(intspec[0] == 0 && intspec[1] >= NR_IRQS_BANK0))
  12068. + return -EINVAL;
  12069. +
  12070. + if (WARN_ON(intspec[0] == 3 && intspec[1] > 3 && intspec[1] != 5))
  12071. + return -EINVAL;
  12072. +
  12073. + if (intspec[0] == 0)
  12074. + *out_hwirq = ARM_IRQ0_BASE + intspec[1];
  12075. + else if (intspec[0] == 1)
  12076. + *out_hwirq = ARM_IRQ1_BASE + intspec[1];
  12077. + else if (intspec[0] == 2)
  12078. + *out_hwirq = ARM_IRQ2_BASE + intspec[1];
  12079. + else
  12080. + *out_hwirq = ARM_IRQ_LOCAL_BASE + intspec[1];
  12081. +
  12082. + /* reverse remap_irqs[] */
  12083. + switch (*out_hwirq) {
  12084. + case INTERRUPT_VC_JPEG:
  12085. + *out_hwirq = INTERRUPT_JPEG;
  12086. + break;
  12087. + case INTERRUPT_VC_USB:
  12088. + *out_hwirq = INTERRUPT_USB;
  12089. + break;
  12090. + case INTERRUPT_VC_3D:
  12091. + *out_hwirq = INTERRUPT_3D;
  12092. + break;
  12093. + case INTERRUPT_VC_DMA2:
  12094. + *out_hwirq = INTERRUPT_DMA2;
  12095. + break;
  12096. + case INTERRUPT_VC_DMA3:
  12097. + *out_hwirq = INTERRUPT_DMA3;
  12098. + break;
  12099. + case INTERRUPT_VC_I2C:
  12100. + *out_hwirq = INTERRUPT_I2C;
  12101. + break;
  12102. + case INTERRUPT_VC_SPI:
  12103. + *out_hwirq = INTERRUPT_SPI;
  12104. + break;
  12105. + case INTERRUPT_VC_I2SPCM:
  12106. + *out_hwirq = INTERRUPT_I2SPCM;
  12107. + break;
  12108. + case INTERRUPT_VC_SDIO:
  12109. + *out_hwirq = INTERRUPT_SDIO;
  12110. + break;
  12111. + case INTERRUPT_VC_UART:
  12112. + *out_hwirq = INTERRUPT_UART;
  12113. + break;
  12114. + case INTERRUPT_VC_ARASANSDIO:
  12115. + *out_hwirq = INTERRUPT_ARASANSDIO;
  12116. + break;
  12117. + }
  12118. +
  12119. + *out_type = IRQ_TYPE_NONE;
  12120. + return 0;
  12121. +}
  12122. +
  12123. +static struct irq_domain_ops armctrl_ops = {
  12124. + .xlate = armctrl_xlate
  12125. +};
  12126. +
  12127. +void __init armctrl_dt_init(void)
  12128. +{
  12129. + struct device_node *np;
  12130. + struct irq_domain *domain;
  12131. +
  12132. + np = of_find_compatible_node(NULL, NULL, "brcm,bcm2708-armctrl-ic");
  12133. + if (!np)
  12134. + return;
  12135. +
  12136. + domain = irq_domain_add_legacy(np, BCM2708_ALLOC_IRQS,
  12137. + IRQ_ARMCTRL_START, 0,
  12138. + &armctrl_ops, NULL);
  12139. + WARN_ON(!domain);
  12140. +}
  12141. +#else
  12142. +void __init armctrl_dt_init(void) { }
  12143. +#endif /* CONFIG_OF */
  12144. +
  12145. +#if defined(CONFIG_PM)
  12146. +
  12147. +/* for kernels 3.xx use the new syscore_ops apis but for older kernels use the sys dev class */
  12148. +
  12149. +/* Static defines
  12150. + * struct armctrl_device - VIC PM device (< 3.xx)
  12151. + * @sysdev: The system device which is registered. (< 3.xx)
  12152. + * @irq: The IRQ number for the base of the VIC.
  12153. + * @base: The register base for the VIC.
  12154. + * @resume_sources: A bitmask of interrupts for resume.
  12155. + * @resume_irqs: The IRQs enabled for resume.
  12156. + * @int_select: Save for VIC_INT_SELECT.
  12157. + * @int_enable: Save for VIC_INT_ENABLE.
  12158. + * @soft_int: Save for VIC_INT_SOFT.
  12159. + * @protect: Save for VIC_PROTECT.
  12160. + */
  12161. +struct armctrl_info {
  12162. + void __iomem *base;
  12163. + int irq;
  12164. + u32 resume_sources;
  12165. + u32 resume_irqs;
  12166. + u32 int_select;
  12167. + u32 int_enable;
  12168. + u32 soft_int;
  12169. + u32 protect;
  12170. +} armctrl;
  12171. +
  12172. +static int armctrl_suspend(void)
  12173. +{
  12174. + return 0;
  12175. +}
  12176. +
  12177. +static void armctrl_resume(void)
  12178. +{
  12179. + return;
  12180. +}
  12181. +
  12182. +/**
  12183. + * armctrl_pm_register - Register a VIC for later power management control
  12184. + * @base: The base address of the VIC.
  12185. + * @irq: The base IRQ for the VIC.
  12186. + * @resume_sources: bitmask of interrupts allowed for resume sources.
  12187. + *
  12188. + * For older kernels (< 3.xx) do -
  12189. + * Register the VIC with the system device tree so that it can be notified
  12190. + * of suspend and resume requests and ensure that the correct actions are
  12191. + * taken to re-instate the settings on resume.
  12192. + */
  12193. +static void __init armctrl_pm_register(void __iomem * base, unsigned int irq,
  12194. + u32 resume_sources)
  12195. +{
  12196. + armctrl.base = base;
  12197. + armctrl.resume_sources = resume_sources;
  12198. + armctrl.irq = irq;
  12199. +}
  12200. +
  12201. +static int armctrl_set_wake(struct irq_data *d, unsigned int on)
  12202. +{
  12203. + unsigned int off = d->irq & 31;
  12204. + u32 bit = 1 << off;
  12205. +
  12206. + if (!(bit & armctrl.resume_sources))
  12207. + return -EINVAL;
  12208. +
  12209. + if (on)
  12210. + armctrl.resume_irqs |= bit;
  12211. + else
  12212. + armctrl.resume_irqs &= ~bit;
  12213. +
  12214. + return 0;
  12215. +}
  12216. +
  12217. +#else
  12218. +static inline void armctrl_pm_register(void __iomem * base, unsigned int irq,
  12219. + u32 arg1)
  12220. +{
  12221. +}
  12222. +
  12223. +#define armctrl_suspend NULL
  12224. +#define armctrl_resume NULL
  12225. +#define armctrl_set_wake NULL
  12226. +#endif /* CONFIG_PM */
  12227. +
  12228. +static struct syscore_ops armctrl_syscore_ops = {
  12229. + .suspend = armctrl_suspend,
  12230. + .resume = armctrl_resume,
  12231. +};
  12232. +
  12233. +/**
  12234. + * armctrl_syscore_init - initicall to register VIC pm functions
  12235. + *
  12236. + * This is called via late_initcall() to register
  12237. + * the resources for the VICs due to the early
  12238. + * nature of the VIC's registration.
  12239. +*/
  12240. +static int __init armctrl_syscore_init(void)
  12241. +{
  12242. + register_syscore_ops(&armctrl_syscore_ops);
  12243. + return 0;
  12244. +}
  12245. +
  12246. +late_initcall(armctrl_syscore_init);
  12247. +
  12248. +static struct irq_chip armctrl_chip = {
  12249. + .name = "ARMCTRL",
  12250. + .irq_ack = NULL,
  12251. + .irq_mask = armctrl_mask_irq,
  12252. + .irq_unmask = armctrl_unmask_irq,
  12253. + .irq_set_wake = armctrl_set_wake,
  12254. +};
  12255. +
  12256. +/**
  12257. + * armctrl_init - initialise a vectored interrupt controller
  12258. + * @base: iomem base address
  12259. + * @irq_start: starting interrupt number, must be muliple of 32
  12260. + * @armctrl_sources: bitmask of interrupt sources to allow
  12261. + * @resume_sources: bitmask of interrupt sources to allow for resume
  12262. + */
  12263. +int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  12264. + u32 armctrl_sources, u32 resume_sources)
  12265. +{
  12266. + unsigned int irq;
  12267. +
  12268. + for (irq = 0; irq < BCM2708_ALLOC_IRQS; irq++) {
  12269. + unsigned int data = irq;
  12270. + if (irq >= INTERRUPT_JPEG && irq <= INTERRUPT_ARASANSDIO)
  12271. + data = remap_irqs[irq - INTERRUPT_JPEG];
  12272. + if (irq >= IRQ_ARM_LOCAL_CNTPSIRQ && irq <= IRQ_ARM_LOCAL_TIMER) {
  12273. + irq_set_percpu_devid(irq);
  12274. + irq_set_chip_and_handler(irq, &armctrl_chip, handle_percpu_devid_irq);
  12275. + set_irq_flags(irq, IRQF_VALID | IRQF_NOAUTOEN);
  12276. + } else {
  12277. + irq_set_chip_and_handler(irq, &armctrl_chip, handle_level_irq);
  12278. + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_DISABLED);
  12279. + }
  12280. + irq_set_chip_data(irq, (void *)data);
  12281. + }
  12282. +
  12283. + armctrl_pm_register(base, irq_start, resume_sources);
  12284. + init_FIQ(FIQ_START);
  12285. + armctrl_dt_init();
  12286. + return 0;
  12287. +}
  12288. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/armctrl.h linux-rpi/arch/arm/mach-bcm2709/armctrl.h
  12289. --- linux-3.18.6/arch/arm/mach-bcm2709/armctrl.h 1970-01-01 01:00:00.000000000 +0100
  12290. +++ linux-rpi/arch/arm/mach-bcm2709/armctrl.h 2015-02-09 04:39:42.000000000 +0100
  12291. @@ -0,0 +1,27 @@
  12292. +/*
  12293. + * linux/arch/arm/mach-bcm2708/armctrl.h
  12294. + *
  12295. + * Copyright (C) 2010 Broadcom
  12296. + *
  12297. + * This program is free software; you can redistribute it and/or modify
  12298. + * it under the terms of the GNU General Public License as published by
  12299. + * the Free Software Foundation; either version 2 of the License, or
  12300. + * (at your option) any later version.
  12301. + *
  12302. + * This program is distributed in the hope that it will be useful,
  12303. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12304. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12305. + * GNU General Public License for more details.
  12306. + *
  12307. + * You should have received a copy of the GNU General Public License
  12308. + * along with this program; if not, write to the Free Software
  12309. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  12310. + */
  12311. +
  12312. +#ifndef __BCM2708_ARMCTRL_H
  12313. +#define __BCM2708_ARMCTRL_H
  12314. +
  12315. +extern int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  12316. + u32 armctrl_sources, u32 resume_sources);
  12317. +
  12318. +#endif
  12319. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/bcm2708_gpio.c linux-rpi/arch/arm/mach-bcm2709/bcm2708_gpio.c
  12320. --- linux-3.18.6/arch/arm/mach-bcm2709/bcm2708_gpio.c 1970-01-01 01:00:00.000000000 +0100
  12321. +++ linux-rpi/arch/arm/mach-bcm2709/bcm2708_gpio.c 2015-02-09 04:39:42.000000000 +0100
  12322. @@ -0,0 +1,426 @@
  12323. +/*
  12324. + * linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
  12325. + *
  12326. + * Copyright (C) 2010 Broadcom
  12327. + *
  12328. + * This program is free software; you can redistribute it and/or modify
  12329. + * it under the terms of the GNU General Public License version 2 as
  12330. + * published by the Free Software Foundation.
  12331. + *
  12332. + */
  12333. +
  12334. +#include <linux/spinlock.h>
  12335. +#include <linux/module.h>
  12336. +#include <linux/delay.h>
  12337. +#include <linux/list.h>
  12338. +#include <linux/io.h>
  12339. +#include <linux/irq.h>
  12340. +#include <linux/interrupt.h>
  12341. +#include <linux/slab.h>
  12342. +#include <mach/gpio.h>
  12343. +#include <linux/gpio.h>
  12344. +#include <linux/platform_device.h>
  12345. +#include <mach/platform.h>
  12346. +#include <linux/pinctrl/consumer.h>
  12347. +
  12348. +#include <linux/platform_data/bcm2708.h>
  12349. +
  12350. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  12351. +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
  12352. +#define BCM_GPIO_USE_IRQ 1
  12353. +
  12354. +#define GPIOFSEL(x) (0x00+(x)*4)
  12355. +#define GPIOSET(x) (0x1c+(x)*4)
  12356. +#define GPIOCLR(x) (0x28+(x)*4)
  12357. +#define GPIOLEV(x) (0x34+(x)*4)
  12358. +#define GPIOEDS(x) (0x40+(x)*4)
  12359. +#define GPIOREN(x) (0x4c+(x)*4)
  12360. +#define GPIOFEN(x) (0x58+(x)*4)
  12361. +#define GPIOHEN(x) (0x64+(x)*4)
  12362. +#define GPIOLEN(x) (0x70+(x)*4)
  12363. +#define GPIOAREN(x) (0x7c+(x)*4)
  12364. +#define GPIOAFEN(x) (0x88+(x)*4)
  12365. +#define GPIOUD(x) (0x94+(x)*4)
  12366. +#define GPIOUDCLK(x) (0x98+(x)*4)
  12367. +
  12368. +#define GPIO_BANKS 2
  12369. +
  12370. +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
  12371. + GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
  12372. + GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
  12373. + GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
  12374. +};
  12375. +
  12376. + /* Each of the two spinlocks protects a different set of hardware
  12377. + * regiters and data structurs. This decouples the code of the IRQ from
  12378. + * the GPIO code. This also makes the case of a GPIO routine call from
  12379. + * the IRQ code simpler.
  12380. + */
  12381. +static DEFINE_SPINLOCK(lock); /* GPIO registers */
  12382. +
  12383. +struct bcm2708_gpio {
  12384. + struct list_head list;
  12385. + void __iomem *base;
  12386. + struct gpio_chip gc;
  12387. + unsigned long rising[(BCM2708_NR_GPIOS + 31) / 32];
  12388. + unsigned long falling[(BCM2708_NR_GPIOS + 31) / 32];
  12389. + unsigned long high[(BCM2708_NR_GPIOS + 31) / 32];
  12390. + unsigned long low[(BCM2708_NR_GPIOS + 31) / 32];
  12391. +};
  12392. +
  12393. +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
  12394. + int function)
  12395. +{
  12396. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  12397. + unsigned long flags;
  12398. + unsigned gpiodir;
  12399. + unsigned gpio_bank = offset / 10;
  12400. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  12401. +
  12402. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
  12403. + if (offset >= BCM2708_NR_GPIOS)
  12404. + return -EINVAL;
  12405. +
  12406. + spin_lock_irqsave(&lock, flags);
  12407. +
  12408. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  12409. + gpiodir &= ~(7 << gpio_field_offset);
  12410. + gpiodir |= function << gpio_field_offset;
  12411. + writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
  12412. + spin_unlock_irqrestore(&lock, flags);
  12413. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  12414. +
  12415. + return 0;
  12416. +}
  12417. +
  12418. +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
  12419. +{
  12420. + return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
  12421. +}
  12422. +
  12423. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
  12424. +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
  12425. + int value)
  12426. +{
  12427. + int ret;
  12428. + ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
  12429. + if (ret >= 0)
  12430. + bcm2708_gpio_set(gc, offset, value);
  12431. + return ret;
  12432. +}
  12433. +
  12434. +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
  12435. +{
  12436. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  12437. + unsigned gpio_bank = offset / 32;
  12438. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  12439. + unsigned lev;
  12440. +
  12441. + if (offset >= BCM2708_NR_GPIOS)
  12442. + return 0;
  12443. + lev = readl(gpio->base + GPIOLEV(gpio_bank));
  12444. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
  12445. + return 0x1 & (lev >> gpio_field_offset);
  12446. +}
  12447. +
  12448. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  12449. +{
  12450. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  12451. + unsigned gpio_bank = offset / 32;
  12452. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  12453. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
  12454. + if (offset >= BCM2708_NR_GPIOS)
  12455. + return;
  12456. + if (value)
  12457. + writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
  12458. + else
  12459. + writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
  12460. +}
  12461. +
  12462. +/**********************
  12463. + * extension to configure pullups
  12464. + */
  12465. +int bcm2708_gpio_setpull(struct gpio_chip *gc, unsigned offset,
  12466. + bcm2708_gpio_pull_t value)
  12467. +{
  12468. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  12469. + unsigned gpio_bank = offset / 32;
  12470. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  12471. +
  12472. + if (offset >= BCM2708_NR_GPIOS)
  12473. + return -EINVAL;
  12474. +
  12475. + switch (value) {
  12476. + case BCM2708_PULL_UP:
  12477. + writel(2, gpio->base + GPIOUD(0));
  12478. + break;
  12479. + case BCM2708_PULL_DOWN:
  12480. + writel(1, gpio->base + GPIOUD(0));
  12481. + break;
  12482. + case BCM2708_PULL_OFF:
  12483. + writel(0, gpio->base + GPIOUD(0));
  12484. + break;
  12485. + }
  12486. +
  12487. + udelay(5);
  12488. + writel(1 << gpio_field_offset, gpio->base + GPIOUDCLK(gpio_bank));
  12489. + udelay(5);
  12490. + writel(0, gpio->base + GPIOUD(0));
  12491. + writel(0 << gpio_field_offset, gpio->base + GPIOUDCLK(gpio_bank));
  12492. +
  12493. + return 0;
  12494. +}
  12495. +EXPORT_SYMBOL(bcm2708_gpio_setpull);
  12496. +
  12497. +/*************************************************************************************************************************
  12498. + * bcm2708 GPIO IRQ
  12499. + */
  12500. +
  12501. +#if BCM_GPIO_USE_IRQ
  12502. +
  12503. +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  12504. +{
  12505. + return gpio_to_irq(gpio);
  12506. +}
  12507. +
  12508. +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
  12509. +{
  12510. + unsigned irq = d->irq;
  12511. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  12512. + unsigned gn = irq_to_gpio(irq);
  12513. + unsigned gb = gn / 32;
  12514. + unsigned go = gn % 32;
  12515. +
  12516. + gpio->rising[gb] &= ~(1 << go);
  12517. + gpio->falling[gb] &= ~(1 << go);
  12518. + gpio->high[gb] &= ~(1 << go);
  12519. + gpio->low[gb] &= ~(1 << go);
  12520. +
  12521. + if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  12522. + return -EINVAL;
  12523. +
  12524. + if (type & IRQ_TYPE_EDGE_RISING)
  12525. + gpio->rising[gb] |= (1 << go);
  12526. + if (type & IRQ_TYPE_EDGE_FALLING)
  12527. + gpio->falling[gb] |= (1 << go);
  12528. + if (type & IRQ_TYPE_LEVEL_HIGH)
  12529. + gpio->high[gb] |= (1 << go);
  12530. + if (type & IRQ_TYPE_LEVEL_LOW)
  12531. + gpio->low[gb] |= (1 << go);
  12532. + return 0;
  12533. +}
  12534. +
  12535. +static void bcm2708_gpio_irq_mask(struct irq_data *d)
  12536. +{
  12537. + unsigned irq = d->irq;
  12538. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  12539. + unsigned gn = irq_to_gpio(irq);
  12540. + unsigned gb = gn / 32;
  12541. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  12542. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  12543. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  12544. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  12545. +
  12546. + gn = gn % 32;
  12547. +
  12548. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  12549. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  12550. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  12551. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  12552. +}
  12553. +
  12554. +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
  12555. +{
  12556. + unsigned irq = d->irq;
  12557. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  12558. + unsigned gn = irq_to_gpio(irq);
  12559. + unsigned gb = gn / 32;
  12560. + unsigned go = gn % 32;
  12561. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  12562. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  12563. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  12564. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  12565. +
  12566. + if (gpio->rising[gb] & (1 << go)) {
  12567. + writel(rising | (1 << go), gpio->base + GPIOREN(gb));
  12568. + } else {
  12569. + writel(rising & ~(1 << go), gpio->base + GPIOREN(gb));
  12570. + }
  12571. +
  12572. + if (gpio->falling[gb] & (1 << go)) {
  12573. + writel(falling | (1 << go), gpio->base + GPIOFEN(gb));
  12574. + } else {
  12575. + writel(falling & ~(1 << go), gpio->base + GPIOFEN(gb));
  12576. + }
  12577. +
  12578. + if (gpio->high[gb] & (1 << go)) {
  12579. + writel(high | (1 << go), gpio->base + GPIOHEN(gb));
  12580. + } else {
  12581. + writel(high & ~(1 << go), gpio->base + GPIOHEN(gb));
  12582. + }
  12583. +
  12584. + if (gpio->low[gb] & (1 << go)) {
  12585. + writel(low | (1 << go), gpio->base + GPIOLEN(gb));
  12586. + } else {
  12587. + writel(low & ~(1 << go), gpio->base + GPIOLEN(gb));
  12588. + }
  12589. +}
  12590. +
  12591. +static struct irq_chip bcm2708_irqchip = {
  12592. + .name = "GPIO",
  12593. + .irq_enable = bcm2708_gpio_irq_unmask,
  12594. + .irq_disable = bcm2708_gpio_irq_mask,
  12595. + .irq_unmask = bcm2708_gpio_irq_unmask,
  12596. + .irq_mask = bcm2708_gpio_irq_mask,
  12597. + .irq_set_type = bcm2708_gpio_irq_set_type,
  12598. +};
  12599. +
  12600. +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
  12601. +{
  12602. + unsigned long edsr;
  12603. + unsigned bank;
  12604. + int i;
  12605. + unsigned gpio;
  12606. + unsigned level_bits;
  12607. + struct bcm2708_gpio *gpio_data = dev_id;
  12608. +
  12609. + for (bank = 0; bank < GPIO_BANKS; bank++) {
  12610. + edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
  12611. + level_bits = gpio_data->high[bank] | gpio_data->low[bank];
  12612. +
  12613. + for_each_set_bit(i, &edsr, 32) {
  12614. + gpio = i + bank * 32;
  12615. + /* ack edge triggered IRQs immediately */
  12616. + if (!(level_bits & (1<<i)))
  12617. + writel(1<<i,
  12618. + __io_address(GPIO_BASE) + GPIOEDS(bank));
  12619. + generic_handle_irq(gpio_to_irq(gpio));
  12620. + /* ack level triggered IRQ after handling them */
  12621. + if (level_bits & (1<<i))
  12622. + writel(1<<i,
  12623. + __io_address(GPIO_BASE) + GPIOEDS(bank));
  12624. + }
  12625. + }
  12626. + return IRQ_HANDLED;
  12627. +}
  12628. +
  12629. +static struct irqaction bcm2708_gpio_irq = {
  12630. + .name = "BCM2708 GPIO catchall handler",
  12631. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  12632. + .handler = bcm2708_gpio_interrupt,
  12633. +};
  12634. +
  12635. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  12636. +{
  12637. + unsigned irq;
  12638. +
  12639. + ucb->gc.to_irq = bcm2708_gpio_to_irq;
  12640. +
  12641. + for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
  12642. + irq_set_chip_data(irq, ucb);
  12643. + irq_set_chip_and_handler(irq, &bcm2708_irqchip,
  12644. + handle_simple_irq);
  12645. + set_irq_flags(irq, IRQF_VALID);
  12646. + }
  12647. +
  12648. + bcm2708_gpio_irq.dev_id = ucb;
  12649. + setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
  12650. +}
  12651. +
  12652. +#else
  12653. +
  12654. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  12655. +{
  12656. +}
  12657. +
  12658. +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
  12659. +
  12660. +static int bcm2708_gpio_probe(struct platform_device *dev)
  12661. +{
  12662. + struct bcm2708_gpio *ucb;
  12663. + struct resource *res;
  12664. + int bank;
  12665. + int err = 0;
  12666. +
  12667. + printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
  12668. +
  12669. + ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
  12670. + if (NULL == ucb) {
  12671. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  12672. + "mailbox memory\n");
  12673. + err = -ENOMEM;
  12674. + goto err;
  12675. + }
  12676. +
  12677. + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  12678. +
  12679. + platform_set_drvdata(dev, ucb);
  12680. + ucb->base = __io_address(GPIO_BASE);
  12681. +
  12682. + ucb->gc.label = "bcm2708_gpio";
  12683. + ucb->gc.base = 0;
  12684. + ucb->gc.ngpio = BCM2708_NR_GPIOS;
  12685. + ucb->gc.owner = THIS_MODULE;
  12686. +
  12687. + ucb->gc.direction_input = bcm2708_gpio_dir_in;
  12688. + ucb->gc.direction_output = bcm2708_gpio_dir_out;
  12689. + ucb->gc.get = bcm2708_gpio_get;
  12690. + ucb->gc.set = bcm2708_gpio_set;
  12691. + ucb->gc.can_sleep = 0;
  12692. +
  12693. + for (bank = 0; bank < GPIO_BANKS; bank++) {
  12694. + writel(0, ucb->base + GPIOREN(bank));
  12695. + writel(0, ucb->base + GPIOFEN(bank));
  12696. + writel(0, ucb->base + GPIOHEN(bank));
  12697. + writel(0, ucb->base + GPIOLEN(bank));
  12698. + writel(0, ucb->base + GPIOAREN(bank));
  12699. + writel(0, ucb->base + GPIOAFEN(bank));
  12700. + writel(~0, ucb->base + GPIOEDS(bank));
  12701. + }
  12702. +
  12703. + bcm2708_gpio_irq_init(ucb);
  12704. +
  12705. + err = gpiochip_add(&ucb->gc);
  12706. +
  12707. +err:
  12708. + return err;
  12709. +
  12710. +}
  12711. +
  12712. +static int bcm2708_gpio_remove(struct platform_device *dev)
  12713. +{
  12714. + int err = 0;
  12715. + struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
  12716. +
  12717. + printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
  12718. +
  12719. + gpiochip_remove(&ucb->gc);
  12720. +
  12721. + platform_set_drvdata(dev, NULL);
  12722. + kfree(ucb);
  12723. +
  12724. + return err;
  12725. +}
  12726. +
  12727. +static struct platform_driver bcm2708_gpio_driver = {
  12728. + .probe = bcm2708_gpio_probe,
  12729. + .remove = bcm2708_gpio_remove,
  12730. + .driver = {
  12731. + .name = "bcm2708_gpio"},
  12732. +};
  12733. +
  12734. +static int __init bcm2708_gpio_init(void)
  12735. +{
  12736. + return platform_driver_register(&bcm2708_gpio_driver);
  12737. +}
  12738. +
  12739. +static void __exit bcm2708_gpio_exit(void)
  12740. +{
  12741. + platform_driver_unregister(&bcm2708_gpio_driver);
  12742. +}
  12743. +
  12744. +module_init(bcm2708_gpio_init);
  12745. +module_exit(bcm2708_gpio_exit);
  12746. +
  12747. +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
  12748. +MODULE_LICENSE("GPL");
  12749. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/bcm2709.c linux-rpi/arch/arm/mach-bcm2709/bcm2709.c
  12750. --- linux-3.18.6/arch/arm/mach-bcm2709/bcm2709.c 1970-01-01 01:00:00.000000000 +0100
  12751. +++ linux-rpi/arch/arm/mach-bcm2709/bcm2709.c 2015-02-09 04:39:42.000000000 +0100
  12752. @@ -0,0 +1,1297 @@
  12753. +/*
  12754. + * linux/arch/arm/mach-bcm2709/bcm2709.c
  12755. + *
  12756. + * Copyright (C) 2010 Broadcom
  12757. + *
  12758. + * This program is free software; you can redistribute it and/or modify
  12759. + * it under the terms of the GNU General Public License as published by
  12760. + * the Free Software Foundation; either version 2 of the License, or
  12761. + * (at your option) any later version.
  12762. + *
  12763. + * This program is distributed in the hope that it will be useful,
  12764. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12765. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12766. + * GNU General Public License for more details.
  12767. + *
  12768. + * You should have received a copy of the GNU General Public License
  12769. + * along with this program; if not, write to the Free Software
  12770. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  12771. + */
  12772. +
  12773. +#include <linux/init.h>
  12774. +#include <linux/device.h>
  12775. +#include <linux/dma-mapping.h>
  12776. +#include <linux/serial_8250.h>
  12777. +#include <linux/platform_device.h>
  12778. +#include <linux/syscore_ops.h>
  12779. +#include <linux/interrupt.h>
  12780. +#include <linux/amba/bus.h>
  12781. +#include <linux/amba/clcd.h>
  12782. +#include <linux/clk-provider.h>
  12783. +#include <linux/clkdev.h>
  12784. +#include <linux/clockchips.h>
  12785. +#include <linux/cnt32_to_63.h>
  12786. +#include <linux/io.h>
  12787. +#include <linux/module.h>
  12788. +#include <linux/of_platform.h>
  12789. +#include <linux/spi/spi.h>
  12790. +#include <linux/gpio/machine.h>
  12791. +#include <linux/w1-gpio.h>
  12792. +#include <linux/pps-gpio.h>
  12793. +
  12794. +#include <linux/version.h>
  12795. +#include <linux/clkdev.h>
  12796. +#include <asm/system_info.h>
  12797. +#include <mach/hardware.h>
  12798. +#include <asm/irq.h>
  12799. +#include <linux/leds.h>
  12800. +#include <asm/mach-types.h>
  12801. +#include <asm/cputype.h>
  12802. +#include <linux/sched_clock.h>
  12803. +
  12804. +#include <asm/mach/arch.h>
  12805. +#include <asm/mach/flash.h>
  12806. +#include <asm/mach/irq.h>
  12807. +#include <asm/mach/time.h>
  12808. +#include <asm/mach/map.h>
  12809. +
  12810. +#include <mach/timex.h>
  12811. +#include <mach/dma.h>
  12812. +#include <mach/vcio.h>
  12813. +#include <mach/system.h>
  12814. +
  12815. +#include <linux/delay.h>
  12816. +
  12817. +#include "bcm2709.h"
  12818. +#include "armctrl.h"
  12819. +
  12820. +#ifdef CONFIG_BCM_VC_CMA
  12821. +#include <linux/broadcom/vc_cma.h>
  12822. +#endif
  12823. +
  12824. +//#define SYSTEM_TIMER
  12825. +
  12826. +/* Effectively we have an IOMMU (ARM<->VideoCore map) that is set up to
  12827. + * give us IO access only to 64Mbytes of physical memory (26 bits). We could
  12828. + * represent this window by setting our dmamasks to 26 bits but, in fact
  12829. + * we're not going to use addresses outside this range (they're not in real
  12830. + * memory) so we don't bother.
  12831. + *
  12832. + * In the future we might include code to use this IOMMU to remap other
  12833. + * physical addresses onto VideoCore memory then the use of 32-bits would be
  12834. + * more legitimate.
  12835. + */
  12836. +#define DMA_MASK_BITS_COMMON 32
  12837. +
  12838. +// use GPIO 4 for the one-wire GPIO pin, if enabled
  12839. +#define W1_GPIO 4
  12840. +// ensure one-wire GPIO pullup is disabled by default
  12841. +#define W1_PULLUP -1
  12842. +
  12843. +/* command line parameters */
  12844. +static unsigned boardrev, serial;
  12845. +static unsigned uart_clock = UART0_CLOCK;
  12846. +static unsigned disk_led_gpio = 16;
  12847. +static unsigned disk_led_active_low = 1;
  12848. +static unsigned reboot_part = 0;
  12849. +static unsigned w1_gpio_pin = W1_GPIO;
  12850. +static unsigned w1_gpio_pullup = W1_PULLUP;
  12851. +static int pps_gpio_pin = -1;
  12852. +static bool vc_i2c_override = false;
  12853. +
  12854. +static unsigned use_dt = 0;
  12855. +
  12856. +static void __init bcm2709_init_led(void);
  12857. +
  12858. +void __init bcm2709_init_irq(void)
  12859. +{
  12860. + armctrl_init(__io_address(ARMCTRL_IC_BASE), 0, 0, 0);
  12861. +}
  12862. +
  12863. +static struct map_desc bcm2709_io_desc[] __initdata = {
  12864. + {
  12865. + .virtual = IO_ADDRESS(ARMCTRL_BASE),
  12866. + .pfn = __phys_to_pfn(ARMCTRL_BASE),
  12867. + .length = SZ_4K,
  12868. + .type = MT_DEVICE},
  12869. + {
  12870. + .virtual = IO_ADDRESS(UART0_BASE),
  12871. + .pfn = __phys_to_pfn(UART0_BASE),
  12872. + .length = SZ_4K,
  12873. + .type = MT_DEVICE},
  12874. + {
  12875. + .virtual = IO_ADDRESS(UART1_BASE),
  12876. + .pfn = __phys_to_pfn(UART1_BASE),
  12877. + .length = SZ_4K,
  12878. + .type = MT_DEVICE},
  12879. + {
  12880. + .virtual = IO_ADDRESS(DMA_BASE),
  12881. + .pfn = __phys_to_pfn(DMA_BASE),
  12882. + .length = SZ_4K,
  12883. + .type = MT_DEVICE},
  12884. + {
  12885. + .virtual = IO_ADDRESS(MCORE_BASE),
  12886. + .pfn = __phys_to_pfn(MCORE_BASE),
  12887. + .length = SZ_4K,
  12888. + .type = MT_DEVICE},
  12889. + {
  12890. + .virtual = IO_ADDRESS(ST_BASE),
  12891. + .pfn = __phys_to_pfn(ST_BASE),
  12892. + .length = SZ_4K,
  12893. + .type = MT_DEVICE},
  12894. + {
  12895. + .virtual = IO_ADDRESS(USB_BASE),
  12896. + .pfn = __phys_to_pfn(USB_BASE),
  12897. + .length = SZ_128K,
  12898. + .type = MT_DEVICE},
  12899. + {
  12900. + .virtual = IO_ADDRESS(PM_BASE),
  12901. + .pfn = __phys_to_pfn(PM_BASE),
  12902. + .length = SZ_4K,
  12903. + .type = MT_DEVICE},
  12904. + {
  12905. + .virtual = IO_ADDRESS(GPIO_BASE),
  12906. + .pfn = __phys_to_pfn(GPIO_BASE),
  12907. + .length = SZ_4K,
  12908. + .type = MT_DEVICE},
  12909. + {
  12910. + .virtual = IO_ADDRESS(ARM_LOCAL_BASE),
  12911. + .pfn = __phys_to_pfn(ARM_LOCAL_BASE),
  12912. + .length = SZ_4K,
  12913. + .type = MT_DEVICE},
  12914. +};
  12915. +
  12916. +void __init bcm2709_map_io(void)
  12917. +{
  12918. + iotable_init(bcm2709_io_desc, ARRAY_SIZE(bcm2709_io_desc));
  12919. +}
  12920. +
  12921. +#ifdef SYSTEM_TIMER
  12922. +
  12923. +/* The STC is a free running counter that increments at the rate of 1MHz */
  12924. +#define STC_FREQ_HZ 1000000
  12925. +
  12926. +static inline uint32_t timer_read(void)
  12927. +{
  12928. + /* STC: a free running counter that increments at the rate of 1MHz */
  12929. + return readl(__io_address(ST_BASE + 0x04));
  12930. +}
  12931. +
  12932. +static unsigned long bcm2709_read_current_timer(void)
  12933. +{
  12934. + return timer_read();
  12935. +}
  12936. +
  12937. +static u64 notrace bcm2709_read_sched_clock(void)
  12938. +{
  12939. + return timer_read();
  12940. +}
  12941. +
  12942. +static cycle_t clksrc_read(struct clocksource *cs)
  12943. +{
  12944. + return timer_read();
  12945. +}
  12946. +
  12947. +static struct clocksource clocksource_stc = {
  12948. + .name = "stc",
  12949. + .rating = 300,
  12950. + .read = clksrc_read,
  12951. + .mask = CLOCKSOURCE_MASK(32),
  12952. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  12953. +};
  12954. +
  12955. +unsigned long frc_clock_ticks32(void)
  12956. +{
  12957. + return timer_read();
  12958. +}
  12959. +
  12960. +static void __init bcm2709_clocksource_init(void)
  12961. +{
  12962. + if (clocksource_register_hz(&clocksource_stc, STC_FREQ_HZ)) {
  12963. + printk(KERN_ERR "timer: failed to initialize clock "
  12964. + "source %s\n", clocksource_stc.name);
  12965. + }
  12966. +}
  12967. +#endif
  12968. +
  12969. +struct clk __init *bcm2709_clk_register(const char *name, unsigned long fixed_rate)
  12970. +{
  12971. + struct clk *clk;
  12972. +
  12973. + clk = clk_register_fixed_rate(NULL, name, NULL, CLK_IS_ROOT,
  12974. + fixed_rate);
  12975. + if (IS_ERR(clk))
  12976. + pr_err("%s not registered\n", name);
  12977. +
  12978. + return clk;
  12979. +}
  12980. +
  12981. +void __init bcm2709_register_clkdev(struct clk *clk, const char *name)
  12982. +{
  12983. + int ret;
  12984. +
  12985. + ret = clk_register_clkdev(clk, NULL, name);
  12986. + if (ret)
  12987. + pr_err("%s alias not registered\n", name);
  12988. +}
  12989. +
  12990. +void __init bcm2709_init_clocks(void)
  12991. +{
  12992. + struct clk *clk;
  12993. +
  12994. + clk = bcm2709_clk_register("uart0_clk", uart_clock);
  12995. + bcm2709_register_clkdev(clk, "dev:f1");
  12996. +
  12997. + clk = bcm2709_clk_register("sdhost_clk", 250000000);
  12998. + bcm2709_register_clkdev(clk, "bcm2708_spi.0");
  12999. + bcm2709_register_clkdev(clk, "bcm2708_i2c.0");
  13000. + bcm2709_register_clkdev(clk, "bcm2708_i2c.1");
  13001. +}
  13002. +
  13003. +#define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
  13004. +#define UART0_DMA { 15, 14 }
  13005. +
  13006. +AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  13007. +
  13008. +static struct amba_device *amba_devs[] __initdata = {
  13009. + &uart0_device,
  13010. +};
  13011. +
  13012. +static struct resource bcm2708_dmaman_resources[] = {
  13013. + {
  13014. + .start = DMA_BASE,
  13015. + .end = DMA_BASE + SZ_4K - 1,
  13016. + .flags = IORESOURCE_MEM,
  13017. + }
  13018. +};
  13019. +
  13020. +static struct platform_device bcm2708_dmaman_device = {
  13021. + .name = BCM_DMAMAN_DRIVER_NAME,
  13022. + .id = 0, /* first bcm2708_dma */
  13023. + .resource = bcm2708_dmaman_resources,
  13024. + .num_resources = ARRAY_SIZE(bcm2708_dmaman_resources),
  13025. +};
  13026. +
  13027. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  13028. +static struct w1_gpio_platform_data w1_gpio_pdata = {
  13029. + .pin = W1_GPIO,
  13030. + .ext_pullup_enable_pin = W1_PULLUP,
  13031. + .is_open_drain = 0,
  13032. +};
  13033. +
  13034. +static struct platform_device w1_device = {
  13035. + .name = "w1-gpio",
  13036. + .id = -1,
  13037. + .dev.platform_data = &w1_gpio_pdata,
  13038. +};
  13039. +#endif
  13040. +
  13041. +static struct pps_gpio_platform_data pps_gpio_info = {
  13042. + .assert_falling_edge = false,
  13043. + .capture_clear = false,
  13044. + .gpio_pin = -1,
  13045. + .gpio_label = "PPS",
  13046. +};
  13047. +
  13048. +static struct platform_device pps_gpio_device = {
  13049. + .name = "pps-gpio",
  13050. + .id = PLATFORM_DEVID_NONE,
  13051. + .dev.platform_data = &pps_gpio_info,
  13052. +};
  13053. +
  13054. +static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  13055. +
  13056. +static struct platform_device bcm2708_fb_device = {
  13057. + .name = "bcm2708_fb",
  13058. + .id = -1, /* only one bcm2708_fb */
  13059. + .resource = NULL,
  13060. + .num_resources = 0,
  13061. + .dev = {
  13062. + .dma_mask = &fb_dmamask,
  13063. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  13064. + },
  13065. +};
  13066. +
  13067. +static struct plat_serial8250_port bcm2708_uart1_platform_data[] = {
  13068. + {
  13069. + .mapbase = UART1_BASE + 0x40,
  13070. + .irq = IRQ_AUX,
  13071. + .uartclk = 125000000,
  13072. + .regshift = 2,
  13073. + .iotype = UPIO_MEM,
  13074. + .flags = UPF_FIXED_TYPE | UPF_IOREMAP | UPF_SKIP_TEST,
  13075. + .type = PORT_8250,
  13076. + },
  13077. + {},
  13078. +};
  13079. +
  13080. +static struct platform_device bcm2708_uart1_device = {
  13081. + .name = "serial8250",
  13082. + .id = PLAT8250_DEV_PLATFORM,
  13083. + .dev = {
  13084. + .platform_data = bcm2708_uart1_platform_data,
  13085. + },
  13086. +};
  13087. +
  13088. +static struct resource bcm2708_usb_resources[] = {
  13089. + [0] = {
  13090. + .start = USB_BASE,
  13091. + .end = USB_BASE + SZ_128K - 1,
  13092. + .flags = IORESOURCE_MEM,
  13093. + },
  13094. + [1] = {
  13095. + .start = MPHI_BASE,
  13096. + .end = MPHI_BASE + SZ_4K - 1,
  13097. + .flags = IORESOURCE_MEM,
  13098. + },
  13099. + [2] = {
  13100. + .start = IRQ_HOSTPORT,
  13101. + .end = IRQ_HOSTPORT,
  13102. + .flags = IORESOURCE_IRQ,
  13103. + },
  13104. + [3] = {
  13105. + .start = IRQ_USB,
  13106. + .end = IRQ_USB,
  13107. + .flags = IORESOURCE_IRQ,
  13108. + },
  13109. + [4] = {
  13110. + .start = ARM_LOCAL_BASE,
  13111. + .end = ARM_LOCAL_BASE + SZ_4K - 1,
  13112. + .flags = IORESOURCE_MEM,
  13113. + },
  13114. + [5] = {
  13115. + .start = IRQ_ARM_LOCAL_MAILBOX1,
  13116. + .end = IRQ_ARM_LOCAL_MAILBOX1,
  13117. + .flags = IORESOURCE_IRQ
  13118. + },
  13119. +};
  13120. +
  13121. +
  13122. +static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  13123. +
  13124. +static struct platform_device bcm2708_usb_device = {
  13125. + .name = "bcm2708_usb",
  13126. + .id = -1, /* only one bcm2708_usb */
  13127. + .resource = bcm2708_usb_resources,
  13128. + .num_resources = ARRAY_SIZE(bcm2708_usb_resources),
  13129. + .dev = {
  13130. + .dma_mask = &usb_dmamask,
  13131. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  13132. + },
  13133. +};
  13134. +
  13135. +static struct resource bcm2708_vcio_resources[] = {
  13136. + [0] = { /* mailbox/semaphore/doorbell access */
  13137. + .start = MCORE_BASE,
  13138. + .end = MCORE_BASE + SZ_4K - 1,
  13139. + .flags = IORESOURCE_MEM,
  13140. + },
  13141. +};
  13142. +
  13143. +static u64 vcio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  13144. +
  13145. +static struct platform_device bcm2708_vcio_device = {
  13146. + .name = BCM_VCIO_DRIVER_NAME,
  13147. + .id = -1, /* only one VideoCore I/O area */
  13148. + .resource = bcm2708_vcio_resources,
  13149. + .num_resources = ARRAY_SIZE(bcm2708_vcio_resources),
  13150. + .dev = {
  13151. + .dma_mask = &vcio_dmamask,
  13152. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  13153. + },
  13154. +};
  13155. +
  13156. +#ifdef CONFIG_BCM2708_GPIO
  13157. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  13158. +
  13159. +static struct resource bcm2708_gpio_resources[] = {
  13160. + [0] = { /* general purpose I/O */
  13161. + .start = GPIO_BASE,
  13162. + .end = GPIO_BASE + SZ_4K - 1,
  13163. + .flags = IORESOURCE_MEM,
  13164. + },
  13165. +};
  13166. +
  13167. +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  13168. +
  13169. +static struct platform_device bcm2708_gpio_device = {
  13170. + .name = BCM_GPIO_DRIVER_NAME,
  13171. + .id = -1, /* only one VideoCore I/O area */
  13172. + .resource = bcm2708_gpio_resources,
  13173. + .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
  13174. + .dev = {
  13175. + .dma_mask = &gpio_dmamask,
  13176. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  13177. + },
  13178. +};
  13179. +#endif
  13180. +
  13181. +#ifdef SYSTEM_TIMER
  13182. +static struct resource bcm2708_systemtimer_resources[] = {
  13183. + [0] = { /* system timer access */
  13184. + .start = ST_BASE,
  13185. + .end = ST_BASE + SZ_4K - 1,
  13186. + .flags = IORESOURCE_MEM,
  13187. + },
  13188. + {
  13189. + .start = IRQ_TIMER3,
  13190. + .end = IRQ_TIMER3,
  13191. + .flags = IORESOURCE_IRQ,
  13192. + }
  13193. +
  13194. +};
  13195. +
  13196. +static u64 systemtimer_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  13197. +
  13198. +static struct platform_device bcm2708_systemtimer_device = {
  13199. + .name = "bcm2708_systemtimer",
  13200. + .id = -1, /* only one VideoCore I/O area */
  13201. + .resource = bcm2708_systemtimer_resources,
  13202. + .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
  13203. + .dev = {
  13204. + .dma_mask = &systemtimer_dmamask,
  13205. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  13206. + },
  13207. +};
  13208. +#endif
  13209. +
  13210. +#ifdef CONFIG_MMC_BCM2835 /* Arasan emmc SD (new) */
  13211. +static struct resource bcm2835_emmc_resources[] = {
  13212. + [0] = {
  13213. + .start = EMMC_BASE,
  13214. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  13215. + /* the memory map actually makes SZ_4K available */
  13216. + .flags = IORESOURCE_MEM,
  13217. + },
  13218. + [1] = {
  13219. + .start = IRQ_ARASANSDIO,
  13220. + .end = IRQ_ARASANSDIO,
  13221. + .flags = IORESOURCE_IRQ,
  13222. + },
  13223. +};
  13224. +
  13225. +static u64 bcm2835_emmc_dmamask = 0xffffffffUL;
  13226. +
  13227. +struct platform_device bcm2835_emmc_device = {
  13228. + .name = "mmc-bcm2835",
  13229. + .id = 0,
  13230. + .num_resources = ARRAY_SIZE(bcm2835_emmc_resources),
  13231. + .resource = bcm2835_emmc_resources,
  13232. + .dev = {
  13233. + .dma_mask = &bcm2835_emmc_dmamask,
  13234. + .coherent_dma_mask = 0xffffffffUL},
  13235. +};
  13236. +#endif /* CONFIG_MMC_BCM2835 */
  13237. +
  13238. +static struct resource bcm2708_powerman_resources[] = {
  13239. + [0] = {
  13240. + .start = PM_BASE,
  13241. + .end = PM_BASE + SZ_256 - 1,
  13242. + .flags = IORESOURCE_MEM,
  13243. + },
  13244. +};
  13245. +
  13246. +static u64 powerman_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  13247. +
  13248. +struct platform_device bcm2708_powerman_device = {
  13249. + .name = "bcm2708_powerman",
  13250. + .id = 0,
  13251. + .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
  13252. + .resource = bcm2708_powerman_resources,
  13253. + .dev = {
  13254. + .dma_mask = &powerman_dmamask,
  13255. + .coherent_dma_mask = 0xffffffffUL},
  13256. +};
  13257. +
  13258. +
  13259. +static struct platform_device bcm2708_alsa_devices[] = {
  13260. + [0] = {
  13261. + .name = "bcm2835_AUD0",
  13262. + .id = 0, /* first audio device */
  13263. + .resource = 0,
  13264. + .num_resources = 0,
  13265. + },
  13266. + [1] = {
  13267. + .name = "bcm2835_AUD1",
  13268. + .id = 1, /* second audio device */
  13269. + .resource = 0,
  13270. + .num_resources = 0,
  13271. + },
  13272. + [2] = {
  13273. + .name = "bcm2835_AUD2",
  13274. + .id = 2, /* third audio device */
  13275. + .resource = 0,
  13276. + .num_resources = 0,
  13277. + },
  13278. + [3] = {
  13279. + .name = "bcm2835_AUD3",
  13280. + .id = 3, /* forth audio device */
  13281. + .resource = 0,
  13282. + .num_resources = 0,
  13283. + },
  13284. + [4] = {
  13285. + .name = "bcm2835_AUD4",
  13286. + .id = 4, /* fifth audio device */
  13287. + .resource = 0,
  13288. + .num_resources = 0,
  13289. + },
  13290. + [5] = {
  13291. + .name = "bcm2835_AUD5",
  13292. + .id = 5, /* sixth audio device */
  13293. + .resource = 0,
  13294. + .num_resources = 0,
  13295. + },
  13296. + [6] = {
  13297. + .name = "bcm2835_AUD6",
  13298. + .id = 6, /* seventh audio device */
  13299. + .resource = 0,
  13300. + .num_resources = 0,
  13301. + },
  13302. + [7] = {
  13303. + .name = "bcm2835_AUD7",
  13304. + .id = 7, /* eighth audio device */
  13305. + .resource = 0,
  13306. + .num_resources = 0,
  13307. + },
  13308. +};
  13309. +
  13310. +static struct resource bcm2708_spi_resources[] = {
  13311. + {
  13312. + .start = SPI0_BASE,
  13313. + .end = SPI0_BASE + SZ_256 - 1,
  13314. + .flags = IORESOURCE_MEM,
  13315. + }, {
  13316. + .start = IRQ_SPI,
  13317. + .end = IRQ_SPI,
  13318. + .flags = IORESOURCE_IRQ,
  13319. + }
  13320. +};
  13321. +
  13322. +
  13323. +static u64 bcm2708_spi_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  13324. +static struct platform_device bcm2708_spi_device = {
  13325. + .name = "bcm2708_spi",
  13326. + .id = 0,
  13327. + .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
  13328. + .resource = bcm2708_spi_resources,
  13329. + .dev = {
  13330. + .dma_mask = &bcm2708_spi_dmamask,
  13331. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
  13332. +};
  13333. +
  13334. +#ifdef CONFIG_BCM2708_SPIDEV
  13335. +static struct spi_board_info bcm2708_spi_devices[] = {
  13336. +#ifdef CONFIG_SPI_SPIDEV
  13337. + {
  13338. + .modalias = "spidev",
  13339. + .max_speed_hz = 500000,
  13340. + .bus_num = 0,
  13341. + .chip_select = 0,
  13342. + .mode = SPI_MODE_0,
  13343. + }, {
  13344. + .modalias = "spidev",
  13345. + .max_speed_hz = 500000,
  13346. + .bus_num = 0,
  13347. + .chip_select = 1,
  13348. + .mode = SPI_MODE_0,
  13349. + }
  13350. +#endif
  13351. +};
  13352. +#endif
  13353. +
  13354. +static struct resource bcm2708_bsc0_resources[] = {
  13355. + {
  13356. + .start = BSC0_BASE,
  13357. + .end = BSC0_BASE + SZ_256 - 1,
  13358. + .flags = IORESOURCE_MEM,
  13359. + }, {
  13360. + .start = INTERRUPT_I2C,
  13361. + .end = INTERRUPT_I2C,
  13362. + .flags = IORESOURCE_IRQ,
  13363. + }
  13364. +};
  13365. +
  13366. +static struct platform_device bcm2708_bsc0_device = {
  13367. + .name = "bcm2708_i2c",
  13368. + .id = 0,
  13369. + .num_resources = ARRAY_SIZE(bcm2708_bsc0_resources),
  13370. + .resource = bcm2708_bsc0_resources,
  13371. +};
  13372. +
  13373. +
  13374. +static struct resource bcm2708_bsc1_resources[] = {
  13375. + {
  13376. + .start = BSC1_BASE,
  13377. + .end = BSC1_BASE + SZ_256 - 1,
  13378. + .flags = IORESOURCE_MEM,
  13379. + }, {
  13380. + .start = INTERRUPT_I2C,
  13381. + .end = INTERRUPT_I2C,
  13382. + .flags = IORESOURCE_IRQ,
  13383. + }
  13384. +};
  13385. +
  13386. +static struct platform_device bcm2708_bsc1_device = {
  13387. + .name = "bcm2708_i2c",
  13388. + .id = 1,
  13389. + .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  13390. + .resource = bcm2708_bsc1_resources,
  13391. +};
  13392. +
  13393. +static struct platform_device bcm2835_hwmon_device = {
  13394. + .name = "bcm2835_hwmon",
  13395. +};
  13396. +
  13397. +static struct platform_device bcm2835_thermal_device = {
  13398. + .name = "bcm2835_thermal",
  13399. +};
  13400. +
  13401. +#if defined(CONFIG_SND_BCM2708_SOC_I2S) || defined(CONFIG_SND_BCM2708_SOC_I2S_MODULE)
  13402. +static struct resource bcm2708_i2s_resources[] = {
  13403. + {
  13404. + .start = I2S_BASE,
  13405. + .end = I2S_BASE + 0x20,
  13406. + .flags = IORESOURCE_MEM,
  13407. + },
  13408. + {
  13409. + .start = PCM_CLOCK_BASE,
  13410. + .end = PCM_CLOCK_BASE + 0x02,
  13411. + .flags = IORESOURCE_MEM,
  13412. + }
  13413. +};
  13414. +
  13415. +static struct platform_device bcm2708_i2s_device = {
  13416. + .name = "bcm2708-i2s",
  13417. + .id = 0,
  13418. + .num_resources = ARRAY_SIZE(bcm2708_i2s_resources),
  13419. + .resource = bcm2708_i2s_resources,
  13420. +};
  13421. +#endif
  13422. +
  13423. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  13424. +static struct platform_device snd_hifiberry_dac_device = {
  13425. + .name = "snd-hifiberry-dac",
  13426. + .id = 0,
  13427. + .num_resources = 0,
  13428. +};
  13429. +
  13430. +static struct platform_device snd_pcm5102a_codec_device = {
  13431. + .name = "pcm5102a-codec",
  13432. + .id = -1,
  13433. + .num_resources = 0,
  13434. +};
  13435. +#endif
  13436. +
  13437. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
  13438. +static struct platform_device snd_rpi_hifiberry_dacplus_device = {
  13439. + .name = "snd-rpi-hifiberry-dacplus",
  13440. + .id = 0,
  13441. + .num_resources = 0,
  13442. +};
  13443. +
  13444. +static struct i2c_board_info __initdata snd_pcm512x_hbdacplus_i2c_devices[] = {
  13445. + {
  13446. + I2C_BOARD_INFO("pcm5122", 0x4d)
  13447. + },
  13448. +};
  13449. +#endif
  13450. +
  13451. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  13452. +static struct platform_device snd_hifiberry_digi_device = {
  13453. + .name = "snd-hifiberry-digi",
  13454. + .id = 0,
  13455. + .num_resources = 0,
  13456. +};
  13457. +
  13458. +static struct i2c_board_info __initdata snd_wm8804_i2c_devices[] = {
  13459. + {
  13460. + I2C_BOARD_INFO("wm8804", 0x3b)
  13461. + },
  13462. +};
  13463. +
  13464. +#endif
  13465. +
  13466. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
  13467. +static struct platform_device snd_hifiberry_amp_device = {
  13468. + .name = "snd-hifiberry-amp",
  13469. + .id = 0,
  13470. + .num_resources = 0,
  13471. +};
  13472. +
  13473. +static struct i2c_board_info __initdata snd_tas5713_i2c_devices[] = {
  13474. + {
  13475. + I2C_BOARD_INFO("tas5713", 0x1b)
  13476. + },
  13477. +};
  13478. +#endif
  13479. +
  13480. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  13481. +static struct platform_device snd_rpi_dac_device = {
  13482. + .name = "snd-rpi-dac",
  13483. + .id = 0,
  13484. + .num_resources = 0,
  13485. +};
  13486. +
  13487. +static struct platform_device snd_pcm1794a_codec_device = {
  13488. + .name = "pcm1794a-codec",
  13489. + .id = -1,
  13490. + .num_resources = 0,
  13491. +};
  13492. +#endif
  13493. +
  13494. +
  13495. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  13496. +static struct platform_device snd_rpi_iqaudio_dac_device = {
  13497. + .name = "snd-rpi-iqaudio-dac",
  13498. + .id = 0,
  13499. + .num_resources = 0,
  13500. +};
  13501. +
  13502. +// Use the actual device name rather than generic driver name
  13503. +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
  13504. + {
  13505. + I2C_BOARD_INFO("pcm5122", 0x4c)
  13506. + },
  13507. +};
  13508. +#endif
  13509. +
  13510. +int __init bcm_register_device(struct platform_device *pdev)
  13511. +{
  13512. + int ret;
  13513. +
  13514. + ret = platform_device_register(pdev);
  13515. + if (ret)
  13516. + pr_debug("Unable to register platform device '%s': %d\n",
  13517. + pdev->name, ret);
  13518. +
  13519. + return ret;
  13520. +}
  13521. +
  13522. +/*
  13523. + * Use these macros for platform and i2c devices that are present in the
  13524. + * Device Tree. This way the devices are only added on non-DT systems.
  13525. + */
  13526. +#define bcm_register_device_dt(pdev) \
  13527. + if (!use_dt) bcm_register_device(pdev)
  13528. +
  13529. +#define i2c_register_board_info_dt(busnum, info, n) \
  13530. + if (!use_dt) i2c_register_board_info(busnum, info, n)
  13531. +
  13532. +int calc_rsts(int partition)
  13533. +{
  13534. + return PM_PASSWORD |
  13535. + ((partition & (1 << 0)) << 0) |
  13536. + ((partition & (1 << 1)) << 1) |
  13537. + ((partition & (1 << 2)) << 2) |
  13538. + ((partition & (1 << 3)) << 3) |
  13539. + ((partition & (1 << 4)) << 4) |
  13540. + ((partition & (1 << 5)) << 5);
  13541. +}
  13542. +
  13543. +static void bcm2709_restart(enum reboot_mode mode, const char *cmd)
  13544. +{
  13545. + extern char bcm2708_reboot_mode;
  13546. + uint32_t pm_rstc, pm_wdog;
  13547. + uint32_t timeout = 10;
  13548. + uint32_t pm_rsts = 0;
  13549. +
  13550. + if(bcm2708_reboot_mode == 'q')
  13551. + {
  13552. + // NOOBS < 1.3 booting with reboot=q
  13553. + pm_rsts = readl(__io_address(PM_RSTS));
  13554. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRQ_SET;
  13555. + }
  13556. + else if(bcm2708_reboot_mode == 'p')
  13557. + {
  13558. + // NOOBS < 1.3 halting
  13559. + pm_rsts = readl(__io_address(PM_RSTS));
  13560. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRH_SET;
  13561. + }
  13562. + else
  13563. + {
  13564. + pm_rsts = calc_rsts(reboot_part);
  13565. + }
  13566. +
  13567. + writel(pm_rsts, __io_address(PM_RSTS));
  13568. +
  13569. + /* Setup watchdog for reset */
  13570. + pm_rstc = readl(__io_address(PM_RSTC));
  13571. +
  13572. + pm_wdog = PM_PASSWORD | (timeout & PM_WDOG_TIME_SET); // watchdog timer = timer clock / 16; need password (31:16) + value (11:0)
  13573. + pm_rstc = PM_PASSWORD | (pm_rstc & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
  13574. +
  13575. + writel(pm_wdog, __io_address(PM_WDOG));
  13576. + writel(pm_rstc, __io_address(PM_RSTC));
  13577. +}
  13578. +
  13579. +/* 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 */
  13580. +static void bcm2709_power_off(void)
  13581. +{
  13582. + extern char bcm2708_reboot_mode;
  13583. + if(bcm2708_reboot_mode == 'q')
  13584. + {
  13585. + // NOOBS < v1.3
  13586. + bcm2709_restart('p', "");
  13587. + }
  13588. + else
  13589. + {
  13590. + /* partition 63 is special code for HALT the bootloader knows not to boot*/
  13591. + reboot_part = 63;
  13592. + /* continue with normal reset mechanism */
  13593. + bcm2709_restart(0, "");
  13594. + }
  13595. +}
  13596. +
  13597. +#ifdef CONFIG_OF
  13598. +static void __init bcm2709_dt_init(void)
  13599. +{
  13600. + int ret;
  13601. +
  13602. + ret = of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  13603. + if (ret) {
  13604. + pr_err("of_platform_populate failed: %d\n", ret);
  13605. + use_dt = 0;
  13606. + }
  13607. +}
  13608. +#else
  13609. +static void __init bcm2709_dt_init(void) { }
  13610. +#endif /* CONFIG_OF */
  13611. +
  13612. +void __init bcm2709_init(void)
  13613. +{
  13614. + int i;
  13615. +
  13616. +#if defined(CONFIG_BCM_VC_CMA)
  13617. + vc_cma_early_init();
  13618. +#endif
  13619. + printk("bcm2709.uart_clock = %d\n", uart_clock);
  13620. + pm_power_off = bcm2709_power_off;
  13621. +
  13622. + bcm2709_init_clocks();
  13623. + if (use_dt)
  13624. + bcm2709_dt_init();
  13625. +
  13626. + bcm_register_device(&bcm2708_dmaman_device);
  13627. + bcm_register_device(&bcm2708_vcio_device);
  13628. +#ifdef CONFIG_BCM2708_GPIO
  13629. + bcm_register_device_dt(&bcm2708_gpio_device);
  13630. +#endif
  13631. +
  13632. +#if defined(CONFIG_PPS_CLIENT_GPIO) || defined(CONFIG_PPS_CLIENT_GPIO_MODULE)
  13633. + if (!use_dt && (pps_gpio_pin >= 0)) {
  13634. + pr_info("bcm2709: GPIO %d setup as pps-gpio device\n", pps_gpio_pin);
  13635. + pps_gpio_info.gpio_pin = pps_gpio_pin;
  13636. + pps_gpio_device.id = pps_gpio_pin;
  13637. + bcm_register_device(&pps_gpio_device);
  13638. + }
  13639. +#endif
  13640. +
  13641. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  13642. + w1_gpio_pdata.pin = w1_gpio_pin;
  13643. + w1_gpio_pdata.ext_pullup_enable_pin = w1_gpio_pullup;
  13644. + bcm_register_device_dt(&w1_device);
  13645. +#endif
  13646. +#ifdef SYSTEM_TIMER
  13647. + bcm_register_device(&bcm2708_systemtimer_device);
  13648. +#endif
  13649. + bcm_register_device(&bcm2708_fb_device);
  13650. + bcm_register_device(&bcm2708_usb_device);
  13651. + bcm_register_device(&bcm2708_uart1_device);
  13652. + bcm_register_device(&bcm2708_powerman_device);
  13653. +
  13654. +#ifdef CONFIG_MMC_BCM2835
  13655. + bcm_register_device(&bcm2835_emmc_device);
  13656. +#endif
  13657. + bcm2709_init_led();
  13658. + for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  13659. + bcm_register_device(&bcm2708_alsa_devices[i]);
  13660. +
  13661. + bcm_register_device(&bcm2835_hwmon_device);
  13662. + bcm_register_device(&bcm2835_thermal_device);
  13663. +
  13664. + bcm_register_device_dt(&bcm2708_spi_device);
  13665. +
  13666. + if (vc_i2c_override) {
  13667. + bcm_register_device_dt(&bcm2708_bsc0_device);
  13668. + bcm_register_device_dt(&bcm2708_bsc1_device);
  13669. + } else if ((boardrev & 0xffffff) == 0x2 || (boardrev & 0xffffff) == 0x3) {
  13670. + bcm_register_device_dt(&bcm2708_bsc0_device);
  13671. + } else {
  13672. + bcm_register_device_dt(&bcm2708_bsc1_device);
  13673. + }
  13674. +
  13675. +#if defined(CONFIG_SND_BCM2708_SOC_I2S) || defined(CONFIG_SND_BCM2708_SOC_I2S_MODULE)
  13676. + bcm_register_device_dt(&bcm2708_i2s_device);
  13677. +#endif
  13678. +
  13679. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  13680. + bcm_register_device_dt(&snd_hifiberry_dac_device);
  13681. + bcm_register_device_dt(&snd_pcm5102a_codec_device);
  13682. +#endif
  13683. +
  13684. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
  13685. + bcm_register_device_dt(&snd_rpi_hifiberry_dacplus_device);
  13686. + i2c_register_board_info_dt(1, snd_pcm512x_hbdacplus_i2c_devices, ARRAY_SIZE(snd_pcm512x_hbdacplus_i2c_devices));
  13687. +#endif
  13688. +
  13689. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  13690. + bcm_register_device_dt(&snd_hifiberry_digi_device);
  13691. + i2c_register_board_info_dt(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
  13692. +#endif
  13693. +
  13694. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
  13695. + bcm_register_device_dt(&snd_hifiberry_amp_device);
  13696. + i2c_register_board_info_dt(1, snd_tas5713_i2c_devices, ARRAY_SIZE(snd_tas5713_i2c_devices));
  13697. +#endif
  13698. +
  13699. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  13700. + bcm_register_device_dt(&snd_rpi_dac_device);
  13701. + bcm_register_device_dt(&snd_pcm1794a_codec_device);
  13702. +#endif
  13703. +
  13704. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  13705. + bcm_register_device_dt(&snd_rpi_iqaudio_dac_device);
  13706. + i2c_register_board_info_dt(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
  13707. +#endif
  13708. +
  13709. +
  13710. + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  13711. + struct amba_device *d = amba_devs[i];
  13712. + amba_device_register(d, &iomem_resource);
  13713. + }
  13714. + system_rev = boardrev;
  13715. + system_serial_low = serial;
  13716. +
  13717. +#ifdef CONFIG_BCM2708_SPIDEV
  13718. + if (!use_dt)
  13719. + spi_register_board_info(bcm2708_spi_devices,
  13720. + ARRAY_SIZE(bcm2708_spi_devices));
  13721. +#endif
  13722. +}
  13723. +
  13724. +#ifdef SYSTEM_TIMER
  13725. +static void timer_set_mode(enum clock_event_mode mode,
  13726. + struct clock_event_device *clk)
  13727. +{
  13728. + switch (mode) {
  13729. + case CLOCK_EVT_MODE_ONESHOT: /* Leave the timer disabled, .set_next_event will enable it */
  13730. + case CLOCK_EVT_MODE_SHUTDOWN:
  13731. + break;
  13732. + case CLOCK_EVT_MODE_PERIODIC:
  13733. +
  13734. + case CLOCK_EVT_MODE_UNUSED:
  13735. + case CLOCK_EVT_MODE_RESUME:
  13736. +
  13737. + default:
  13738. + printk(KERN_ERR "timer_set_mode: unhandled mode:%d\n",
  13739. + (int)mode);
  13740. + break;
  13741. + }
  13742. +
  13743. +}
  13744. +
  13745. +static int timer_set_next_event(unsigned long cycles,
  13746. + struct clock_event_device *unused)
  13747. +{
  13748. + unsigned long stc;
  13749. + do {
  13750. + stc = readl(__io_address(ST_BASE + 0x04));
  13751. + /* We could take a FIQ here, which may push ST above STC3 */
  13752. + writel(stc + cycles, __io_address(ST_BASE + 0x18));
  13753. + } while ((signed long) cycles >= 0 &&
  13754. + (signed long) (readl(__io_address(ST_BASE + 0x04)) - stc)
  13755. + >= (signed long) cycles);
  13756. + return 0;
  13757. +}
  13758. +
  13759. +static struct clock_event_device timer0_clockevent = {
  13760. + .name = "timer0",
  13761. + .shift = 32,
  13762. + .features = CLOCK_EVT_FEAT_ONESHOT,
  13763. + .set_mode = timer_set_mode,
  13764. + .set_next_event = timer_set_next_event,
  13765. +};
  13766. +
  13767. +/*
  13768. + * IRQ handler for the timer
  13769. + */
  13770. +static irqreturn_t bcm2709_timer_interrupt(int irq, void *dev_id)
  13771. +{
  13772. + struct clock_event_device *evt = &timer0_clockevent;
  13773. +
  13774. + writel(1 << 3, __io_address(ST_BASE + 0x00)); /* stcs clear timer int */
  13775. +
  13776. + evt->event_handler(evt);
  13777. +
  13778. + return IRQ_HANDLED;
  13779. +}
  13780. +
  13781. +static struct irqaction bcm2709_timer_irq = {
  13782. + .name = "BCM2709 Timer Tick",
  13783. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  13784. + .handler = bcm2709_timer_interrupt,
  13785. +};
  13786. +
  13787. +/*
  13788. + * Set up timer interrupt, and return the current time in seconds.
  13789. + */
  13790. +
  13791. +static struct delay_timer bcm2709_delay_timer = {
  13792. + .read_current_timer = bcm2709_read_current_timer,
  13793. + .freq = STC_FREQ_HZ,
  13794. +};
  13795. +
  13796. +static void __init bcm2709_timer_init(void)
  13797. +{
  13798. + /* init high res timer */
  13799. + bcm2709_clocksource_init();
  13800. +
  13801. + /*
  13802. + * Make irqs happen for the system timer
  13803. + */
  13804. + setup_irq(IRQ_TIMER3, &bcm2708_timer_irq);
  13805. +
  13806. + sched_clock_register(bcm2709_read_sched_clock, 32, STC_FREQ_HZ);
  13807. +
  13808. + timer0_clockevent.mult =
  13809. + div_sc(STC_FREQ_HZ, NSEC_PER_SEC, timer0_clockevent.shift);
  13810. + timer0_clockevent.max_delta_ns =
  13811. + clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  13812. + timer0_clockevent.min_delta_ns =
  13813. + clockevent_delta2ns(0xf, &timer0_clockevent);
  13814. +
  13815. + timer0_clockevent.cpumask = cpumask_of(0);
  13816. + clockevents_register_device(&timer0_clockevent);
  13817. +
  13818. + register_current_timer_delay(&bcm2708_delay_timer);
  13819. +}
  13820. +
  13821. +#else
  13822. +
  13823. +static void __init bcm2709_timer_init(void)
  13824. +{
  13825. + extern void dc4_arch_timer_init(void);
  13826. + // timer control
  13827. + writel(0, __io_address(ARM_LOCAL_CONTROL));
  13828. + // timer pre_scaler
  13829. + writel(0x80000000, __io_address(ARM_LOCAL_PRESCALER)); // 19.2MHz
  13830. + //writel(0x06AAAAAB, __io_address(ARM_LOCAL_PRESCALER)); // 1MHz
  13831. +
  13832. + if (use_dt)
  13833. + {
  13834. + of_clk_init(NULL);
  13835. + clocksource_of_init();
  13836. + }
  13837. + else
  13838. + dc4_arch_timer_init();
  13839. +}
  13840. +
  13841. +#endif
  13842. +
  13843. +#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  13844. +#include <linux/leds.h>
  13845. +
  13846. +static struct gpio_led bcm2709_leds[] = {
  13847. + [0] = {
  13848. + .gpio = 16,
  13849. + .name = "led0",
  13850. + .default_trigger = "mmc0",
  13851. + .active_low = 1,
  13852. + },
  13853. +};
  13854. +
  13855. +static struct gpio_led_platform_data bcm2709_led_pdata = {
  13856. + .num_leds = ARRAY_SIZE(bcm2709_leds),
  13857. + .leds = bcm2709_leds,
  13858. +};
  13859. +
  13860. +static struct platform_device bcm2709_led_device = {
  13861. + .name = "leds-gpio",
  13862. + .id = -1,
  13863. + .dev = {
  13864. + .platform_data = &bcm2709_led_pdata,
  13865. + },
  13866. +};
  13867. +
  13868. +static void __init bcm2709_init_led(void)
  13869. +{
  13870. + bcm2709_leds[0].gpio = disk_led_gpio;
  13871. + bcm2709_leds[0].active_low = disk_led_active_low;
  13872. + bcm_register_device_dt(&bcm2709_led_device);
  13873. +}
  13874. +#else
  13875. +static inline void bcm2709_init_led(void)
  13876. +{
  13877. +}
  13878. +#endif
  13879. +
  13880. +void __init bcm2709_init_early(void)
  13881. +{
  13882. + /*
  13883. + * Some devices allocate their coherent buffers from atomic
  13884. + * context. Increase size of atomic coherent pool to make sure such
  13885. + * the allocations won't fail.
  13886. + */
  13887. + init_dma_coherent_pool_size(SZ_4M);
  13888. +
  13889. +#ifdef CONFIG_OF
  13890. + if (of_allnodes)
  13891. + use_dt = 1;
  13892. +#endif
  13893. +}
  13894. +
  13895. +static void __init board_reserve(void)
  13896. +{
  13897. +#if defined(CONFIG_BCM_VC_CMA)
  13898. + vc_cma_reserve();
  13899. +#endif
  13900. +}
  13901. +
  13902. +
  13903. +#include <linux/smp.h>
  13904. +
  13905. +#include <mach/hardware.h>
  13906. +#include <asm/cacheflush.h>
  13907. +#include <asm/smp_plat.h>
  13908. +int dc4=0;
  13909. +//void dc4_log(unsigned x) { if (dc4) writel((x), __io_address(ST_BASE+10 + raw_smp_processor_id()*4)); }
  13910. +void dc4_log_dead(unsigned x) { if (dc4) writel((readl(__io_address(ST_BASE+0x10 + raw_smp_processor_id()*4)) & 0xffff) | ((x)<<16), __io_address(ST_BASE+0x10 + raw_smp_processor_id()*4)); }
  13911. +
  13912. +static void bcm2835_send_doorbell(const struct cpumask *mask, unsigned int irq)
  13913. +{
  13914. + int cpu;
  13915. + /*
  13916. + * Ensure that stores to Normal memory are visible to the
  13917. + * other CPUs before issuing the IPI.
  13918. + */
  13919. + dsb();
  13920. +
  13921. + /* Convert our logical CPU mask into a physical one. */
  13922. + for_each_cpu(cpu, mask)
  13923. + {
  13924. + /* submit softirq */
  13925. + writel(1<<irq, __io_address(ARM_LOCAL_MAILBOX0_SET0 + 0x10 * MPIDR_AFFINITY_LEVEL(cpu_logical_map(cpu), 0)));
  13926. + }
  13927. +}
  13928. +
  13929. +void __init bcm2709_smp_init_cpus(void)
  13930. +{
  13931. + void secondary_startup(void);
  13932. + unsigned int i, ncores;
  13933. +
  13934. + ncores = 4; // xxx scu_get_core_count(NULL);
  13935. + printk("[%s] enter (%x->%x)\n", __FUNCTION__, (unsigned)virt_to_phys((void *)secondary_startup), (unsigned)__io_address(ST_BASE + 0x10));
  13936. + printk("[%s] ncores=%d\n", __FUNCTION__, ncores);
  13937. +
  13938. + for (i = 0; i < ncores; i++) {
  13939. + set_cpu_possible(i, true);
  13940. + /* enable IRQ (not FIQ) */
  13941. + writel(0x1, __io_address(ARM_LOCAL_MAILBOX_INT_CONTROL0 + 0x4 * i));
  13942. + //writel(0xf, __io_address(ARM_LOCAL_TIMER_INT_CONTROL0 + 0x4 * i));
  13943. + }
  13944. + set_smp_cross_call(bcm2835_send_doorbell);
  13945. +}
  13946. +
  13947. +/*
  13948. + * for arch/arm/kernel/smp.c:smp_prepare_cpus(unsigned int max_cpus)
  13949. + */
  13950. +void __init bcm2709_smp_prepare_cpus(unsigned int max_cpus)
  13951. +{
  13952. + //void __iomem *scu_base;
  13953. +
  13954. + printk("[%s] enter\n", __FUNCTION__);
  13955. + //scu_base = scu_base_addr();
  13956. + //scu_enable(scu_base);
  13957. +}
  13958. +
  13959. +/*
  13960. + * for linux/arch/arm/kernel/smp.c:secondary_start_kernel(void)
  13961. + */
  13962. +void __cpuinit bcm2709_secondary_init(unsigned int cpu)
  13963. +{
  13964. + printk("[%s] enter cpu:%d\n", __FUNCTION__, cpu);
  13965. + //gic_secondary_init(0);
  13966. +}
  13967. +
  13968. +/*
  13969. + * for linux/arch/arm/kernel/smp.c:__cpu_up(..)
  13970. + */
  13971. +int __cpuinit bcm2709_boot_secondary(unsigned int cpu, struct task_struct *idle)
  13972. +{
  13973. + void secondary_startup(void);
  13974. + void *mbox_set = __io_address(ARM_LOCAL_MAILBOX3_SET0 + 0x10 * MPIDR_AFFINITY_LEVEL(cpu_logical_map(cpu), 0));
  13975. + void *mbox_clr = __io_address(ARM_LOCAL_MAILBOX3_CLR0 + 0x10 * MPIDR_AFFINITY_LEVEL(cpu_logical_map(cpu), 0));
  13976. + unsigned secondary_boot = (unsigned)virt_to_phys((void *)secondary_startup);
  13977. + int timeout=20;
  13978. + unsigned t = -1;
  13979. + //printk("[%s] enter cpu:%d (%x->%p) %x\n", __FUNCTION__, cpu, secondary_boot, wake, readl(wake));
  13980. +
  13981. + dsb();
  13982. + BUG_ON(readl(mbox_clr) != 0);
  13983. + writel(secondary_boot, mbox_set);
  13984. +
  13985. + while (--timeout > 0) {
  13986. + t = readl(mbox_clr);
  13987. + if (t == 0) break;
  13988. + cpu_relax();
  13989. + }
  13990. + if (timeout==0)
  13991. + printk("[%s] cpu:%d failed to start (%x)\n", __FUNCTION__, cpu, t);
  13992. + else
  13993. + printk("[%s] cpu:%d started (%x) %d\n", __FUNCTION__, cpu, t, timeout);
  13994. +
  13995. + return 0;
  13996. +}
  13997. +
  13998. +
  13999. +struct smp_operations bcm2709_smp_ops __initdata = {
  14000. + .smp_init_cpus = bcm2709_smp_init_cpus,
  14001. + .smp_prepare_cpus = bcm2709_smp_prepare_cpus,
  14002. + .smp_secondary_init = bcm2709_secondary_init,
  14003. + .smp_boot_secondary = bcm2709_boot_secondary,
  14004. +};
  14005. +
  14006. +static const char * const bcm2709_compat[] = {
  14007. + "brcm,bcm2709",
  14008. + "brcm,bcm2708", /* Could use bcm2708 in a pinch */
  14009. + NULL
  14010. +};
  14011. +
  14012. +MACHINE_START(BCM2709, "BCM2709")
  14013. + /* Maintainer: Broadcom Europe Ltd. */
  14014. + .smp = smp_ops(bcm2709_smp_ops),
  14015. + .map_io = bcm2709_map_io,
  14016. + .init_irq = bcm2709_init_irq,
  14017. + .init_time = bcm2709_timer_init,
  14018. + .init_machine = bcm2709_init,
  14019. + .init_early = bcm2709_init_early,
  14020. + .reserve = board_reserve,
  14021. + .restart = bcm2709_restart,
  14022. + .dt_compat = bcm2709_compat,
  14023. +MACHINE_END
  14024. +
  14025. +MACHINE_START(BCM2708, "BCM2709")
  14026. + /* Maintainer: Broadcom Europe Ltd. */
  14027. + .smp = smp_ops(bcm2709_smp_ops),
  14028. + .map_io = bcm2709_map_io,
  14029. + .init_irq = bcm2709_init_irq,
  14030. + .init_time = bcm2709_timer_init,
  14031. + .init_machine = bcm2709_init,
  14032. + .init_early = bcm2709_init_early,
  14033. + .reserve = board_reserve,
  14034. + .restart = bcm2709_restart,
  14035. + .dt_compat = bcm2709_compat,
  14036. +MACHINE_END
  14037. +
  14038. +module_param(boardrev, uint, 0644);
  14039. +module_param(serial, uint, 0644);
  14040. +module_param(uart_clock, uint, 0644);
  14041. +module_param(disk_led_gpio, uint, 0644);
  14042. +module_param(disk_led_active_low, uint, 0644);
  14043. +module_param(reboot_part, uint, 0644);
  14044. +module_param(w1_gpio_pin, uint, 0644);
  14045. +module_param(w1_gpio_pullup, uint, 0644);
  14046. +module_param(pps_gpio_pin, int, 0644);
  14047. +MODULE_PARM_DESC(pps_gpio_pin, "Set GPIO pin to reserve for PPS");
  14048. +module_param(vc_i2c_override, bool, 0644);
  14049. +MODULE_PARM_DESC(vc_i2c_override, "Allow the use of VC's I2C peripheral.");
  14050. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/bcm2709.h linux-rpi/arch/arm/mach-bcm2709/bcm2709.h
  14051. --- linux-3.18.6/arch/arm/mach-bcm2709/bcm2709.h 1970-01-01 01:00:00.000000000 +0100
  14052. +++ linux-rpi/arch/arm/mach-bcm2709/bcm2709.h 2015-02-09 04:39:42.000000000 +0100
  14053. @@ -0,0 +1,49 @@
  14054. +/*
  14055. + * linux/arch/arm/mach-bcm2708/bcm2708.h
  14056. + *
  14057. + * BCM2708 machine support header
  14058. + *
  14059. + * Copyright (C) 2010 Broadcom
  14060. + *
  14061. + * This program is free software; you can redistribute it and/or modify
  14062. + * it under the terms of the GNU General Public License as published by
  14063. + * the Free Software Foundation; either version 2 of the License, or
  14064. + * (at your option) any later version.
  14065. + *
  14066. + * This program is distributed in the hope that it will be useful,
  14067. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14068. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14069. + * GNU General Public License for more details.
  14070. + *
  14071. + * You should have received a copy of the GNU General Public License
  14072. + * along with this program; if not, write to the Free Software
  14073. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14074. + */
  14075. +
  14076. +#ifndef __BCM2708_BCM2708_H
  14077. +#define __BCM2708_BCM2708_H
  14078. +
  14079. +#include <linux/amba/bus.h>
  14080. +
  14081. +extern void __init bcm2708_init(void);
  14082. +extern void __init bcm2708_init_irq(void);
  14083. +extern void __init bcm2708_map_io(void);
  14084. +extern struct sys_timer bcm2708_timer;
  14085. +extern unsigned int mmc_status(struct device *dev);
  14086. +
  14087. +#define AMBA_DEVICE(name, busid, base, plat) \
  14088. +static struct amba_device name##_device = { \
  14089. + .dev = { \
  14090. + .coherent_dma_mask = ~0, \
  14091. + .init_name = busid, \
  14092. + .platform_data = plat, \
  14093. + }, \
  14094. + .res = { \
  14095. + .start = base##_BASE, \
  14096. + .end = (base##_BASE) + SZ_4K - 1,\
  14097. + .flags = IORESOURCE_MEM, \
  14098. + }, \
  14099. + .irq = base##_IRQ, \
  14100. +}
  14101. +
  14102. +#endif
  14103. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/clock.c linux-rpi/arch/arm/mach-bcm2709/clock.c
  14104. --- linux-3.18.6/arch/arm/mach-bcm2709/clock.c 1970-01-01 01:00:00.000000000 +0100
  14105. +++ linux-rpi/arch/arm/mach-bcm2709/clock.c 2015-02-09 04:39:42.000000000 +0100
  14106. @@ -0,0 +1,61 @@
  14107. +/*
  14108. + * linux/arch/arm/mach-bcm2708/clock.c
  14109. + *
  14110. + * Copyright (C) 2010 Broadcom
  14111. + *
  14112. + * This program is free software; you can redistribute it and/or modify
  14113. + * it under the terms of the GNU General Public License as published by
  14114. + * the Free Software Foundation; either version 2 of the License, or
  14115. + * (at your option) any later version.
  14116. + *
  14117. + * This program is distributed in the hope that it will be useful,
  14118. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14119. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14120. + * GNU General Public License for more details.
  14121. + *
  14122. + * You should have received a copy of the GNU General Public License
  14123. + * along with this program; if not, write to the Free Software
  14124. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14125. + */
  14126. +#include <linux/module.h>
  14127. +#include <linux/kernel.h>
  14128. +#include <linux/device.h>
  14129. +#include <linux/list.h>
  14130. +#include <linux/errno.h>
  14131. +#include <linux/err.h>
  14132. +#include <linux/string.h>
  14133. +#include <linux/clk.h>
  14134. +#include <linux/mutex.h>
  14135. +
  14136. +#include <asm/clkdev.h>
  14137. +
  14138. +#include "clock.h"
  14139. +
  14140. +int clk_enable(struct clk *clk)
  14141. +{
  14142. + return 0;
  14143. +}
  14144. +EXPORT_SYMBOL(clk_enable);
  14145. +
  14146. +void clk_disable(struct clk *clk)
  14147. +{
  14148. +}
  14149. +EXPORT_SYMBOL(clk_disable);
  14150. +
  14151. +unsigned long clk_get_rate(struct clk *clk)
  14152. +{
  14153. + return clk->rate;
  14154. +}
  14155. +EXPORT_SYMBOL(clk_get_rate);
  14156. +
  14157. +long clk_round_rate(struct clk *clk, unsigned long rate)
  14158. +{
  14159. + return clk->rate;
  14160. +}
  14161. +EXPORT_SYMBOL(clk_round_rate);
  14162. +
  14163. +int clk_set_rate(struct clk *clk, unsigned long rate)
  14164. +{
  14165. + return -EIO;
  14166. +}
  14167. +EXPORT_SYMBOL(clk_set_rate);
  14168. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/clock.h linux-rpi/arch/arm/mach-bcm2709/clock.h
  14169. --- linux-3.18.6/arch/arm/mach-bcm2709/clock.h 1970-01-01 01:00:00.000000000 +0100
  14170. +++ linux-rpi/arch/arm/mach-bcm2709/clock.h 2015-02-09 04:39:42.000000000 +0100
  14171. @@ -0,0 +1,24 @@
  14172. +/*
  14173. + * linux/arch/arm/mach-bcm2708/clock.h
  14174. + *
  14175. + * Copyright (C) 2010 Broadcom
  14176. + *
  14177. + * This program is free software; you can redistribute it and/or modify
  14178. + * it under the terms of the GNU General Public License as published by
  14179. + * the Free Software Foundation; either version 2 of the License, or
  14180. + * (at your option) any later version.
  14181. + *
  14182. + * This program is distributed in the hope that it will be useful,
  14183. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14184. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14185. + * GNU General Public License for more details.
  14186. + *
  14187. + * You should have received a copy of the GNU General Public License
  14188. + * along with this program; if not, write to the Free Software
  14189. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14190. + */
  14191. +struct module;
  14192. +
  14193. +struct clk {
  14194. + unsigned long rate;
  14195. +};
  14196. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/delay.S linux-rpi/arch/arm/mach-bcm2709/delay.S
  14197. --- linux-3.18.6/arch/arm/mach-bcm2709/delay.S 1970-01-01 01:00:00.000000000 +0100
  14198. +++ linux-rpi/arch/arm/mach-bcm2709/delay.S 2015-02-09 04:39:42.000000000 +0100
  14199. @@ -0,0 +1,21 @@
  14200. +/*
  14201. + * linux/arch/arm/lib/delay.S
  14202. + *
  14203. + * Copyright (C) 1995, 1996 Russell King
  14204. + *
  14205. + * This program is free software; you can redistribute it and/or modify
  14206. + * it under the terms of the GNU General Public License version 2 as
  14207. + * published by the Free Software Foundation.
  14208. + */
  14209. +#include <linux/linkage.h>
  14210. +#include <asm/assembler.h>
  14211. +#include <asm/param.h>
  14212. +
  14213. + .text
  14214. +.align 3 @ 8 byte alignment seems to be needed to avoid fetching stalls
  14215. +@ Delay routine
  14216. +ENTRY(bcm2708_delay)
  14217. + subs r0, r0, #1
  14218. + bhi bcm2708_delay
  14219. + mov pc, lr
  14220. +ENDPROC(bcm2708_delay)
  14221. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/dma.c linux-rpi/arch/arm/mach-bcm2709/dma.c
  14222. --- linux-3.18.6/arch/arm/mach-bcm2709/dma.c 1970-01-01 01:00:00.000000000 +0100
  14223. +++ linux-rpi/arch/arm/mach-bcm2709/dma.c 2015-02-09 04:39:42.000000000 +0100
  14224. @@ -0,0 +1,409 @@
  14225. +/*
  14226. + * linux/arch/arm/mach-bcm2708/dma.c
  14227. + *
  14228. + * Copyright (C) 2010 Broadcom
  14229. + *
  14230. + * This program is free software; you can redistribute it and/or modify
  14231. + * it under the terms of the GNU General Public License version 2 as
  14232. + * published by the Free Software Foundation.
  14233. + */
  14234. +
  14235. +#include <linux/slab.h>
  14236. +#include <linux/device.h>
  14237. +#include <linux/platform_device.h>
  14238. +#include <linux/module.h>
  14239. +#include <linux/scatterlist.h>
  14240. +
  14241. +#include <mach/dma.h>
  14242. +#include <mach/irqs.h>
  14243. +
  14244. +/*****************************************************************************\
  14245. + * *
  14246. + * Configuration *
  14247. + * *
  14248. +\*****************************************************************************/
  14249. +
  14250. +#define CACHE_LINE_MASK 31
  14251. +#define DRIVER_NAME BCM_DMAMAN_DRIVER_NAME
  14252. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  14253. +
  14254. +/* valid only for channels 0 - 14, 15 has its own base address */
  14255. +#define BCM2708_DMA_CHAN(n) ((n)<<8) /* base address */
  14256. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  14257. + ((void __iomem *)((char *)(dma_base)+BCM2708_DMA_CHAN(n)))
  14258. +
  14259. +
  14260. +/*****************************************************************************\
  14261. + * *
  14262. + * DMA Auxilliary Functions *
  14263. + * *
  14264. +\*****************************************************************************/
  14265. +
  14266. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  14267. + section inside the DMA buffer and another section outside it.
  14268. + Even if we flush DMA buffers from the cache there is always the chance that
  14269. + during a DMA someone will access the part of a cache line that is outside
  14270. + the DMA buffer - which will then bring in unwelcome data.
  14271. + Without being able to dictate our own buffer pools we must insist that
  14272. + DMA buffers consist of a whole number of cache lines.
  14273. +*/
  14274. +
  14275. +extern int
  14276. +bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  14277. +{
  14278. + int i;
  14279. +
  14280. + for (i = 0; i < sg_len; i++) {
  14281. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  14282. + sg_ptr[i].length & CACHE_LINE_MASK)
  14283. + return 0;
  14284. + }
  14285. +
  14286. + return 1;
  14287. +}
  14288. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  14289. +
  14290. +extern void
  14291. +bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block)
  14292. +{
  14293. + dsb(); /* ARM data synchronization (push) operation */
  14294. +
  14295. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  14296. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  14297. +}
  14298. +
  14299. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  14300. +{
  14301. + dsb();
  14302. +
  14303. + /* ugly busy wait only option for now */
  14304. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  14305. + cpu_relax();
  14306. +}
  14307. +
  14308. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  14309. +
  14310. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  14311. +{
  14312. + dsb();
  14313. +
  14314. + return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
  14315. +}
  14316. +EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
  14317. +
  14318. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  14319. + Does nothing if there is no DMA in progress.
  14320. + This routine waits for the current AXI transfer to complete before
  14321. + terminating the current DMA. If the current transfer is hung on a DREQ used
  14322. + by an uncooperative peripheral the AXI transfer may never complete. In this
  14323. + case the routine times out and return a non-zero error code.
  14324. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  14325. + does not produce an interrupt.
  14326. +*/
  14327. +extern int
  14328. +bcm_dma_abort(void __iomem *dma_chan_base)
  14329. +{
  14330. + unsigned long int cs;
  14331. + int rc = 0;
  14332. +
  14333. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  14334. +
  14335. + if (BCM2708_DMA_ACTIVE & cs) {
  14336. + long int timeout = 10000;
  14337. +
  14338. + /* write 0 to the active bit - pause the DMA */
  14339. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  14340. +
  14341. + /* wait for any current AXI transfer to complete */
  14342. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  14343. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  14344. +
  14345. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  14346. + /* we'll un-pause when we set of our next DMA */
  14347. + rc = -ETIMEDOUT;
  14348. +
  14349. + } else if (BCM2708_DMA_ACTIVE & cs) {
  14350. + /* terminate the control block chain */
  14351. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  14352. +
  14353. + /* abort the whole DMA */
  14354. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  14355. + dma_chan_base + BCM2708_DMA_CS);
  14356. + }
  14357. + }
  14358. +
  14359. + return rc;
  14360. +}
  14361. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  14362. +
  14363. +
  14364. +/***************************************************************************** \
  14365. + * *
  14366. + * DMA Manager Device Methods *
  14367. + * *
  14368. +\*****************************************************************************/
  14369. +
  14370. +struct vc_dmaman {
  14371. + void __iomem *dma_base;
  14372. + u32 chan_available; /* bitmap of available channels */
  14373. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  14374. +};
  14375. +
  14376. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  14377. + u32 chans_available)
  14378. +{
  14379. + dmaman->dma_base = dma_base;
  14380. + dmaman->chan_available = chans_available;
  14381. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* chans 2 & 3 */
  14382. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* chan 0 */
  14383. + dmaman->has_feature[BCM_DMA_FEATURE_NORMAL_ORD] = 0xfe; /* chans 1 to 7 */
  14384. + dmaman->has_feature[BCM_DMA_FEATURE_LITE_ORD] = 0x7f00; /* chans 8 to 14 */
  14385. +}
  14386. +
  14387. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  14388. + unsigned preferred_feature_set)
  14389. +{
  14390. + u32 chans;
  14391. + int feature;
  14392. +
  14393. + chans = dmaman->chan_available;
  14394. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  14395. + /* select the subset of available channels with the desired
  14396. + feature so long as some of the candidate channels have that
  14397. + feature */
  14398. + if ((preferred_feature_set & (1 << feature)) &&
  14399. + (chans & dmaman->has_feature[feature]))
  14400. + chans &= dmaman->has_feature[feature];
  14401. +
  14402. + if (chans) {
  14403. + int chan = 0;
  14404. + /* return the ordinal of the first channel in the bitmap */
  14405. + while (chans != 0 && (chans & 1) == 0) {
  14406. + chans >>= 1;
  14407. + chan++;
  14408. + }
  14409. + /* claim the channel */
  14410. + dmaman->chan_available &= ~(1 << chan);
  14411. + return chan;
  14412. + } else
  14413. + return -ENOMEM;
  14414. +}
  14415. +
  14416. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  14417. +{
  14418. + if (chan < 0)
  14419. + return -EINVAL;
  14420. + else if ((1 << chan) & dmaman->chan_available)
  14421. + return -EIDRM;
  14422. + else {
  14423. + dmaman->chan_available |= (1 << chan);
  14424. + return 0;
  14425. + }
  14426. +}
  14427. +
  14428. +/*****************************************************************************\
  14429. + * *
  14430. + * DMA IRQs *
  14431. + * *
  14432. +\*****************************************************************************/
  14433. +
  14434. +static unsigned char bcm_dma_irqs[] = {
  14435. + IRQ_DMA0,
  14436. + IRQ_DMA1,
  14437. + IRQ_DMA2,
  14438. + IRQ_DMA3,
  14439. + IRQ_DMA4,
  14440. + IRQ_DMA5,
  14441. + IRQ_DMA6,
  14442. + IRQ_DMA7,
  14443. + IRQ_DMA8,
  14444. + IRQ_DMA9,
  14445. + IRQ_DMA10,
  14446. + IRQ_DMA11,
  14447. + IRQ_DMA12
  14448. +};
  14449. +
  14450. +
  14451. +/***************************************************************************** \
  14452. + * *
  14453. + * DMA Manager Monitor *
  14454. + * *
  14455. +\*****************************************************************************/
  14456. +
  14457. +static struct device *dmaman_dev; /* we assume there's only one! */
  14458. +
  14459. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  14460. + void __iomem **out_dma_base, int *out_dma_irq)
  14461. +{
  14462. + if (!dmaman_dev)
  14463. + return -ENODEV;
  14464. + else {
  14465. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  14466. + int rc;
  14467. +
  14468. + device_lock(dmaman_dev);
  14469. + rc = vc_dmaman_chan_alloc(dmaman, preferred_feature_set);
  14470. + if (rc >= 0) {
  14471. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base,
  14472. + rc);
  14473. + *out_dma_irq = bcm_dma_irqs[rc];
  14474. + }
  14475. + device_unlock(dmaman_dev);
  14476. +
  14477. + return rc;
  14478. + }
  14479. +}
  14480. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  14481. +
  14482. +extern int bcm_dma_chan_free(int channel)
  14483. +{
  14484. + if (dmaman_dev) {
  14485. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  14486. + int rc;
  14487. +
  14488. + device_lock(dmaman_dev);
  14489. + rc = vc_dmaman_chan_free(dmaman, channel);
  14490. + device_unlock(dmaman_dev);
  14491. +
  14492. + return rc;
  14493. + } else
  14494. + return -ENODEV;
  14495. +}
  14496. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  14497. +
  14498. +static int dev_dmaman_register(const char *dev_name, struct device *dev)
  14499. +{
  14500. + int rc = dmaman_dev ? -EINVAL : 0;
  14501. + dmaman_dev = dev;
  14502. + return rc;
  14503. +}
  14504. +
  14505. +static void dev_dmaman_deregister(const char *dev_name, struct device *dev)
  14506. +{
  14507. + dmaman_dev = NULL;
  14508. +}
  14509. +
  14510. +/*****************************************************************************\
  14511. + * *
  14512. + * DMA Device *
  14513. + * *
  14514. +\*****************************************************************************/
  14515. +
  14516. +static int dmachans = -1; /* module parameter */
  14517. +
  14518. +static int bcm_dmaman_probe(struct platform_device *pdev)
  14519. +{
  14520. + int ret = 0;
  14521. + struct vc_dmaman *dmaman;
  14522. + struct resource *dma_res = NULL;
  14523. + void __iomem *dma_base = NULL;
  14524. + int have_dma_region = 0;
  14525. +
  14526. + dmaman = kzalloc(sizeof(*dmaman), GFP_KERNEL);
  14527. + if (NULL == dmaman) {
  14528. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  14529. + "DMA management memory\n");
  14530. + ret = -ENOMEM;
  14531. + } else {
  14532. +
  14533. + dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  14534. + if (dma_res == NULL) {
  14535. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  14536. + "resource\n");
  14537. + ret = -ENODEV;
  14538. + } else if (!request_mem_region(dma_res->start,
  14539. + resource_size(dma_res),
  14540. + DRIVER_NAME)) {
  14541. + dev_err(&pdev->dev, "cannot obtain DMA region\n");
  14542. + ret = -EBUSY;
  14543. + } else {
  14544. + have_dma_region = 1;
  14545. + dma_base = ioremap(dma_res->start,
  14546. + resource_size(dma_res));
  14547. + if (!dma_base) {
  14548. + dev_err(&pdev->dev, "cannot map DMA region\n");
  14549. + ret = -ENOMEM;
  14550. + } else {
  14551. + /* use module parameter if one was provided */
  14552. + if (dmachans > 0)
  14553. + vc_dmaman_init(dmaman, dma_base,
  14554. + dmachans);
  14555. + else
  14556. + vc_dmaman_init(dmaman, dma_base,
  14557. + DEFAULT_DMACHAN_BITMAP);
  14558. +
  14559. + platform_set_drvdata(pdev, dmaman);
  14560. + dev_dmaman_register(DRIVER_NAME, &pdev->dev);
  14561. +
  14562. + printk(KERN_INFO DRIVER_NAME ": DMA manager "
  14563. + "at %p\n", dma_base);
  14564. + }
  14565. + }
  14566. + }
  14567. + if (ret != 0) {
  14568. + if (dma_base)
  14569. + iounmap(dma_base);
  14570. + if (dma_res && have_dma_region)
  14571. + release_mem_region(dma_res->start,
  14572. + resource_size(dma_res));
  14573. + if (dmaman)
  14574. + kfree(dmaman);
  14575. + }
  14576. + return ret;
  14577. +}
  14578. +
  14579. +static int bcm_dmaman_remove(struct platform_device *pdev)
  14580. +{
  14581. + struct vc_dmaman *dmaman = platform_get_drvdata(pdev);
  14582. +
  14583. + platform_set_drvdata(pdev, NULL);
  14584. + dev_dmaman_deregister(DRIVER_NAME, &pdev->dev);
  14585. + kfree(dmaman);
  14586. +
  14587. + return 0;
  14588. +}
  14589. +
  14590. +static struct platform_driver bcm_dmaman_driver = {
  14591. + .probe = bcm_dmaman_probe,
  14592. + .remove = bcm_dmaman_remove,
  14593. +
  14594. + .driver = {
  14595. + .name = DRIVER_NAME,
  14596. + .owner = THIS_MODULE,
  14597. + },
  14598. +};
  14599. +
  14600. +/*****************************************************************************\
  14601. + * *
  14602. + * Driver init/exit *
  14603. + * *
  14604. +\*****************************************************************************/
  14605. +
  14606. +static int __init bcm_dmaman_drv_init(void)
  14607. +{
  14608. + int ret;
  14609. +
  14610. + ret = platform_driver_register(&bcm_dmaman_driver);
  14611. + if (ret != 0) {
  14612. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  14613. + "on platform\n");
  14614. + }
  14615. +
  14616. + return ret;
  14617. +}
  14618. +
  14619. +static void __exit bcm_dmaman_drv_exit(void)
  14620. +{
  14621. + platform_driver_unregister(&bcm_dmaman_driver);
  14622. +}
  14623. +
  14624. +module_init(bcm_dmaman_drv_init);
  14625. +module_exit(bcm_dmaman_drv_exit);
  14626. +
  14627. +module_param(dmachans, int, 0644);
  14628. +
  14629. +MODULE_AUTHOR("Gray Girling <grayg@broadcom.com>");
  14630. +MODULE_DESCRIPTION("DMA channel manager driver");
  14631. +MODULE_LICENSE("GPL");
  14632. +
  14633. +MODULE_PARM_DESC(dmachans, "Bitmap of DMA channels available to the ARM");
  14634. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/dmaer.c linux-rpi/arch/arm/mach-bcm2709/dmaer.c
  14635. --- linux-3.18.6/arch/arm/mach-bcm2709/dmaer.c 1970-01-01 01:00:00.000000000 +0100
  14636. +++ linux-rpi/arch/arm/mach-bcm2709/dmaer.c 2015-02-09 04:39:42.000000000 +0100
  14637. @@ -0,0 +1,886 @@
  14638. +#include <linux/init.h>
  14639. +#include <linux/sched.h>
  14640. +#include <linux/module.h>
  14641. +#include <linux/types.h>
  14642. +#include <linux/kdev_t.h>
  14643. +#include <linux/fs.h>
  14644. +#include <linux/cdev.h>
  14645. +#include <linux/mm.h>
  14646. +#include <linux/slab.h>
  14647. +#include <linux/pagemap.h>
  14648. +#include <linux/device.h>
  14649. +#include <linux/jiffies.h>
  14650. +#include <linux/timex.h>
  14651. +#include <linux/dma-mapping.h>
  14652. +
  14653. +#include <asm/uaccess.h>
  14654. +#include <asm/atomic.h>
  14655. +#include <asm/cacheflush.h>
  14656. +#include <asm/io.h>
  14657. +
  14658. +#include <mach/dma.h>
  14659. +#include <mach/vc_support.h>
  14660. +
  14661. +#ifdef ECLIPSE_IGNORE
  14662. +
  14663. +#define __user
  14664. +#define __init
  14665. +#define __exit
  14666. +#define __iomem
  14667. +#define KERN_DEBUG
  14668. +#define KERN_ERR
  14669. +#define KERN_WARNING
  14670. +#define KERN_INFO
  14671. +#define _IOWR(a, b, c) b
  14672. +#define _IOW(a, b, c) b
  14673. +#define _IO(a, b) b
  14674. +
  14675. +#endif
  14676. +
  14677. +//#define inline
  14678. +
  14679. +#define PRINTK(args...) printk(args)
  14680. +//#define PRINTK_VERBOSE(args...) printk(args)
  14681. +//#define PRINTK(args...)
  14682. +#define PRINTK_VERBOSE(args...)
  14683. +
  14684. +/***** TYPES ****/
  14685. +#define PAGES_PER_LIST 500
  14686. +struct PageList
  14687. +{
  14688. + struct page *m_pPages[PAGES_PER_LIST];
  14689. + unsigned int m_used;
  14690. + struct PageList *m_pNext;
  14691. +};
  14692. +
  14693. +struct VmaPageList
  14694. +{
  14695. + //each vma has a linked list of pages associated with it
  14696. + struct PageList *m_pPageHead;
  14697. + struct PageList *m_pPageTail;
  14698. + unsigned int m_refCount;
  14699. +};
  14700. +
  14701. +struct DmaControlBlock
  14702. +{
  14703. + unsigned int m_transferInfo;
  14704. + void __user *m_pSourceAddr;
  14705. + void __user *m_pDestAddr;
  14706. + unsigned int m_xferLen;
  14707. + unsigned int m_tdStride;
  14708. + struct DmaControlBlock *m_pNext;
  14709. + unsigned int m_blank1, m_blank2;
  14710. +};
  14711. +
  14712. +/***** DEFINES ******/
  14713. +//magic number defining the module
  14714. +#define DMA_MAGIC 0xdd
  14715. +
  14716. +//do user virtual to physical translation of the CB chain
  14717. +#define DMA_PREPARE _IOWR(DMA_MAGIC, 0, struct DmaControlBlock *)
  14718. +
  14719. +//kick the pre-prepared CB chain
  14720. +#define DMA_KICK _IOW(DMA_MAGIC, 1, struct DmaControlBlock *)
  14721. +
  14722. +//prepare it, kick it, wait for it
  14723. +#define DMA_PREPARE_KICK_WAIT _IOWR(DMA_MAGIC, 2, struct DmaControlBlock *)
  14724. +
  14725. +//prepare it, kick it, don't wait for it
  14726. +#define DMA_PREPARE_KICK _IOWR(DMA_MAGIC, 3, struct DmaControlBlock *)
  14727. +
  14728. +//not currently implemented
  14729. +#define DMA_WAIT_ONE _IO(DMA_MAGIC, 4, struct DmaControlBlock *)
  14730. +
  14731. +//wait on all kicked CB chains
  14732. +#define DMA_WAIT_ALL _IO(DMA_MAGIC, 5)
  14733. +
  14734. +//in order to discover the largest AXI burst that should be programmed into the transfer params
  14735. +#define DMA_MAX_BURST _IO(DMA_MAGIC, 6)
  14736. +
  14737. +//set the address range through which the user address is assumed to already by a physical address
  14738. +#define DMA_SET_MIN_PHYS _IOW(DMA_MAGIC, 7, unsigned long)
  14739. +#define DMA_SET_MAX_PHYS _IOW(DMA_MAGIC, 8, unsigned long)
  14740. +#define DMA_SET_PHYS_OFFSET _IOW(DMA_MAGIC, 9, unsigned long)
  14741. +
  14742. +//used to define the size for the CMA-based allocation *in pages*, can only be done once once the file is opened
  14743. +#define DMA_CMA_SET_SIZE _IOW(DMA_MAGIC, 10, unsigned long)
  14744. +
  14745. +//used to get the version of the module, to test for a capability
  14746. +#define DMA_GET_VERSION _IO(DMA_MAGIC, 99)
  14747. +
  14748. +#define VERSION_NUMBER 1
  14749. +
  14750. +#define VIRT_TO_BUS_CACHE_SIZE 8
  14751. +
  14752. +/***** FILE OPS *****/
  14753. +static int Open(struct inode *pInode, struct file *pFile);
  14754. +static int Release(struct inode *pInode, struct file *pFile);
  14755. +static long Ioctl(struct file *pFile, unsigned int cmd, unsigned long arg);
  14756. +static ssize_t Read(struct file *pFile, char __user *pUser, size_t count, loff_t *offp);
  14757. +static int Mmap(struct file *pFile, struct vm_area_struct *pVma);
  14758. +
  14759. +/***** VMA OPS ****/
  14760. +static void VmaOpen4k(struct vm_area_struct *pVma);
  14761. +static void VmaClose4k(struct vm_area_struct *pVma);
  14762. +static int VmaFault4k(struct vm_area_struct *pVma, struct vm_fault *pVmf);
  14763. +
  14764. +/**** DMA PROTOTYPES */
  14765. +static struct DmaControlBlock __user *DmaPrepare(struct DmaControlBlock __user *pUserCB, int *pError);
  14766. +static int DmaKick(struct DmaControlBlock __user *pUserCB);
  14767. +static void DmaWaitAll(void);
  14768. +
  14769. +/**** GENERIC ****/
  14770. +static int __init dmaer_init(void);
  14771. +static void __exit dmaer_exit(void);
  14772. +
  14773. +/*** OPS ***/
  14774. +static struct vm_operations_struct g_vmOps4k = {
  14775. + .open = VmaOpen4k,
  14776. + .close = VmaClose4k,
  14777. + .fault = VmaFault4k,
  14778. +};
  14779. +
  14780. +static struct file_operations g_fOps = {
  14781. + .owner = THIS_MODULE,
  14782. + .llseek = 0,
  14783. + .read = Read,
  14784. + .write = 0,
  14785. + .unlocked_ioctl = Ioctl,
  14786. + .open = Open,
  14787. + .release = Release,
  14788. + .mmap = Mmap,
  14789. +};
  14790. +
  14791. +/***** GLOBALS ******/
  14792. +static dev_t g_majorMinor;
  14793. +
  14794. +//tracking usage of the two files
  14795. +static atomic_t g_oneLock4k = ATOMIC_INIT(1);
  14796. +
  14797. +//device operations
  14798. +static struct cdev g_cDev;
  14799. +static int g_trackedPages = 0;
  14800. +
  14801. +//dma control
  14802. +static unsigned int *g_pDmaChanBase;
  14803. +static int g_dmaIrq;
  14804. +static int g_dmaChan;
  14805. +
  14806. +//cma allocation
  14807. +static int g_cmaHandle;
  14808. +
  14809. +//user virtual to bus address translation acceleration
  14810. +static unsigned long g_virtAddr[VIRT_TO_BUS_CACHE_SIZE];
  14811. +static unsigned long g_busAddr[VIRT_TO_BUS_CACHE_SIZE];
  14812. +static unsigned long g_cbVirtAddr;
  14813. +static unsigned long g_cbBusAddr;
  14814. +static int g_cacheInsertAt;
  14815. +static int g_cacheHit, g_cacheMiss;
  14816. +
  14817. +//off by default
  14818. +static void __user *g_pMinPhys;
  14819. +static void __user *g_pMaxPhys;
  14820. +static unsigned long g_physOffset;
  14821. +
  14822. +/****** CACHE OPERATIONS ********/
  14823. +static inline void FlushAddrCache(void)
  14824. +{
  14825. + int count = 0;
  14826. + for (count = 0; count < VIRT_TO_BUS_CACHE_SIZE; count++)
  14827. + g_virtAddr[count] = 0xffffffff; //never going to match as we always chop the bottom bits anyway
  14828. +
  14829. + g_cbVirtAddr = 0xffffffff;
  14830. +
  14831. + g_cacheInsertAt = 0;
  14832. +}
  14833. +
  14834. +//translate from a user virtual address to a bus address by mapping the page
  14835. +//NB this won't lock a page in memory, so to avoid potential paging issues using kernel logical addresses
  14836. +static inline void __iomem *UserVirtualToBus(void __user *pUser)
  14837. +{
  14838. + int mapped;
  14839. + struct page *pPage;
  14840. + void *phys;
  14841. +
  14842. + //map it (requiring that the pointer points to something that does not hang off the page boundary)
  14843. + mapped = get_user_pages(current, current->mm,
  14844. + (unsigned long)pUser, 1,
  14845. + 1, 0,
  14846. + &pPage,
  14847. + 0);
  14848. +
  14849. + if (mapped <= 0) //error
  14850. + return 0;
  14851. +
  14852. + PRINTK_VERBOSE(KERN_DEBUG "user virtual %p arm phys %p bus %p\n",
  14853. + pUser, page_address(pPage), (void __iomem *)__virt_to_bus(page_address(pPage)));
  14854. +
  14855. + //get the arm physical address
  14856. + phys = page_address(pPage) + offset_in_page(pUser);
  14857. + page_cache_release(pPage);
  14858. +
  14859. + //and now the bus address
  14860. + return (void __iomem *)__virt_to_bus(phys);
  14861. +}
  14862. +
  14863. +static inline void __iomem *UserVirtualToBusViaCbCache(void __user *pUser)
  14864. +{
  14865. + unsigned long virtual_page = (unsigned long)pUser & ~4095;
  14866. + unsigned long page_offset = (unsigned long)pUser & 4095;
  14867. + unsigned long bus_addr;
  14868. +
  14869. + if (g_cbVirtAddr == virtual_page)
  14870. + {
  14871. + bus_addr = g_cbBusAddr + page_offset;
  14872. + g_cacheHit++;
  14873. + return (void __iomem *)bus_addr;
  14874. + }
  14875. + else
  14876. + {
  14877. + bus_addr = (unsigned long)UserVirtualToBus(pUser);
  14878. +
  14879. + if (!bus_addr)
  14880. + return 0;
  14881. +
  14882. + g_cbVirtAddr = virtual_page;
  14883. + g_cbBusAddr = bus_addr & ~4095;
  14884. + g_cacheMiss++;
  14885. +
  14886. + return (void __iomem *)bus_addr;
  14887. + }
  14888. +}
  14889. +
  14890. +//do the same as above, by query our virt->bus cache
  14891. +static inline void __iomem *UserVirtualToBusViaCache(void __user *pUser)
  14892. +{
  14893. + int count;
  14894. + //get the page and its offset
  14895. + unsigned long virtual_page = (unsigned long)pUser & ~4095;
  14896. + unsigned long page_offset = (unsigned long)pUser & 4095;
  14897. + unsigned long bus_addr;
  14898. +
  14899. + if (pUser >= g_pMinPhys && pUser < g_pMaxPhys)
  14900. + {
  14901. + PRINTK_VERBOSE(KERN_DEBUG "user->phys passthrough on %p\n", pUser);
  14902. + return (void __iomem *)((unsigned long)pUser + g_physOffset);
  14903. + }
  14904. +
  14905. + //check the cache for our entry
  14906. + for (count = 0; count < VIRT_TO_BUS_CACHE_SIZE; count++)
  14907. + if (g_virtAddr[count] == virtual_page)
  14908. + {
  14909. + bus_addr = g_busAddr[count] + page_offset;
  14910. + g_cacheHit++;
  14911. + return (void __iomem *)bus_addr;
  14912. + }
  14913. +
  14914. + //not found, look up manually and then insert its page address
  14915. + bus_addr = (unsigned long)UserVirtualToBus(pUser);
  14916. +
  14917. + if (!bus_addr)
  14918. + return 0;
  14919. +
  14920. + g_virtAddr[g_cacheInsertAt] = virtual_page;
  14921. + g_busAddr[g_cacheInsertAt] = bus_addr & ~4095;
  14922. +
  14923. + //round robin
  14924. + g_cacheInsertAt++;
  14925. + if (g_cacheInsertAt == VIRT_TO_BUS_CACHE_SIZE)
  14926. + g_cacheInsertAt = 0;
  14927. +
  14928. + g_cacheMiss++;
  14929. +
  14930. + return (void __iomem *)bus_addr;
  14931. +}
  14932. +
  14933. +/***** FILE OPERATIONS ****/
  14934. +static int Open(struct inode *pInode, struct file *pFile)
  14935. +{
  14936. + PRINTK(KERN_DEBUG "file opening: %d/%d\n", imajor(pInode), iminor(pInode));
  14937. +
  14938. + //check which device we are
  14939. + if (iminor(pInode) == 0) //4k
  14940. + {
  14941. + //only one at a time
  14942. + if (!atomic_dec_and_test(&g_oneLock4k))
  14943. + {
  14944. + atomic_inc(&g_oneLock4k);
  14945. + return -EBUSY;
  14946. + }
  14947. + }
  14948. + else
  14949. + return -EINVAL;
  14950. +
  14951. + //todo there will be trouble if two different processes open the files
  14952. +
  14953. + //reset after any file is opened
  14954. + g_pMinPhys = (void __user *)-1;
  14955. + g_pMaxPhys = (void __user *)0;
  14956. + g_physOffset = 0;
  14957. + g_cmaHandle = 0;
  14958. +
  14959. + return 0;
  14960. +}
  14961. +
  14962. +static int Release(struct inode *pInode, struct file *pFile)
  14963. +{
  14964. + PRINTK(KERN_DEBUG "file closing, %d pages tracked\n", g_trackedPages);
  14965. + if (g_trackedPages)
  14966. + PRINTK(KERN_ERR "we\'re leaking memory!\n");
  14967. +
  14968. + //wait for any dmas to finish
  14969. + DmaWaitAll();
  14970. +
  14971. + //free this memory on the application closing the file or it crashing (implicitly closing the file)
  14972. + if (g_cmaHandle)
  14973. + {
  14974. + PRINTK(KERN_DEBUG "unlocking vc memory\n");
  14975. + if (UnlockVcMemory(g_cmaHandle))
  14976. + PRINTK(KERN_ERR "uh-oh, unable to unlock vc memory!\n");
  14977. + PRINTK(KERN_DEBUG "releasing vc memory\n");
  14978. + if (ReleaseVcMemory(g_cmaHandle))
  14979. + PRINTK(KERN_ERR "uh-oh, unable to release vc memory!\n");
  14980. + }
  14981. +
  14982. + if (iminor(pInode) == 0)
  14983. + atomic_inc(&g_oneLock4k);
  14984. + else
  14985. + return -EINVAL;
  14986. +
  14987. + return 0;
  14988. +}
  14989. +
  14990. +static struct DmaControlBlock __user *DmaPrepare(struct DmaControlBlock __user *pUserCB, int *pError)
  14991. +{
  14992. + struct DmaControlBlock kernCB;
  14993. + struct DmaControlBlock __user *pUNext;
  14994. + void __iomem *pSourceBus, __iomem *pDestBus;
  14995. +
  14996. + //get the control block into kernel memory so we can work on it
  14997. + if (copy_from_user(&kernCB, pUserCB, sizeof(struct DmaControlBlock)) != 0)
  14998. + {
  14999. + PRINTK(KERN_ERR "copy_from_user failed for user cb %p\n", pUserCB);
  15000. + *pError = 1;
  15001. + return 0;
  15002. + }
  15003. +
  15004. + if (kernCB.m_pSourceAddr == 0 || kernCB.m_pDestAddr == 0)
  15005. + {
  15006. + PRINTK(KERN_ERR "faulty source (%p) dest (%p) addresses for user cb %p\n",
  15007. + kernCB.m_pSourceAddr, kernCB.m_pDestAddr, pUserCB);
  15008. + *pError = 1;
  15009. + return 0;
  15010. + }
  15011. +
  15012. + pSourceBus = UserVirtualToBusViaCache(kernCB.m_pSourceAddr);
  15013. + pDestBus = UserVirtualToBusViaCache(kernCB.m_pDestAddr);
  15014. +
  15015. + if (!pSourceBus || !pDestBus)
  15016. + {
  15017. + PRINTK(KERN_ERR "virtual to bus translation failure for source/dest %p/%p->%p/%p\n",
  15018. + kernCB.m_pSourceAddr, kernCB.m_pDestAddr,
  15019. + pSourceBus, pDestBus);
  15020. + *pError = 1;
  15021. + return 0;
  15022. + }
  15023. +
  15024. + //update the user structure with the new bus addresses
  15025. + kernCB.m_pSourceAddr = pSourceBus;
  15026. + kernCB.m_pDestAddr = pDestBus;
  15027. +
  15028. + PRINTK_VERBOSE(KERN_DEBUG "final source %p dest %p\n", kernCB.m_pSourceAddr, kernCB.m_pDestAddr);
  15029. +
  15030. + //sort out the bus address for the next block
  15031. + pUNext = kernCB.m_pNext;
  15032. +
  15033. + if (kernCB.m_pNext)
  15034. + {
  15035. + void __iomem *pNextBus;
  15036. + pNextBus = UserVirtualToBusViaCbCache(kernCB.m_pNext);
  15037. +
  15038. + if (!pNextBus)
  15039. + {
  15040. + PRINTK(KERN_ERR "virtual to bus translation failure for m_pNext\n");
  15041. + *pError = 1;
  15042. + return 0;
  15043. + }
  15044. +
  15045. + //update the pointer with the bus address
  15046. + kernCB.m_pNext = pNextBus;
  15047. + }
  15048. +
  15049. + //write it back to user space
  15050. + if (copy_to_user(pUserCB, &kernCB, sizeof(struct DmaControlBlock)) != 0)
  15051. + {
  15052. + PRINTK(KERN_ERR "copy_to_user failed for cb %p\n", pUserCB);
  15053. + *pError = 1;
  15054. + return 0;
  15055. + }
  15056. +
  15057. + __cpuc_flush_dcache_area(pUserCB, 32);
  15058. +
  15059. + *pError = 0;
  15060. + return pUNext;
  15061. +}
  15062. +
  15063. +static int DmaKick(struct DmaControlBlock __user *pUserCB)
  15064. +{
  15065. + void __iomem *pBusCB;
  15066. +
  15067. + pBusCB = UserVirtualToBusViaCbCache(pUserCB);
  15068. + if (!pBusCB)
  15069. + {
  15070. + PRINTK(KERN_ERR "virtual to bus translation failure for cb\n");
  15071. + return 1;
  15072. + }
  15073. +
  15074. + //flush_cache_all();
  15075. +
  15076. + bcm_dma_start(g_pDmaChanBase, (dma_addr_t)pBusCB);
  15077. +
  15078. + return 0;
  15079. +}
  15080. +
  15081. +static void DmaWaitAll(void)
  15082. +{
  15083. + int counter = 0;
  15084. + volatile int inner_count;
  15085. + volatile unsigned int cs;
  15086. + unsigned long time_before, time_after;
  15087. +
  15088. + time_before = jiffies;
  15089. + //bcm_dma_wait_idle(g_pDmaChanBase);
  15090. + dsb();
  15091. +
  15092. + cs = readl(g_pDmaChanBase);
  15093. +
  15094. + while ((cs & 1) == 1)
  15095. + {
  15096. + cs = readl(g_pDmaChanBase);
  15097. + counter++;
  15098. +
  15099. + for (inner_count = 0; inner_count < 32; inner_count++);
  15100. +
  15101. + asm volatile ("MCR p15,0,r0,c7,c0,4 \n");
  15102. + //cpu_do_idle();
  15103. + if (counter >= 1000000)
  15104. + {
  15105. + PRINTK(KERN_WARNING "DMA failed to finish in a timely fashion\n");
  15106. + break;
  15107. + }
  15108. + }
  15109. + time_after = jiffies;
  15110. + PRINTK_VERBOSE(KERN_DEBUG "done, counter %d, cs %08x", counter, cs);
  15111. + PRINTK_VERBOSE(KERN_DEBUG "took %ld jiffies, %d HZ\n", time_after - time_before, HZ);
  15112. +}
  15113. +
  15114. +static long Ioctl(struct file *pFile, unsigned int cmd, unsigned long arg)
  15115. +{
  15116. + int error = 0;
  15117. + PRINTK_VERBOSE(KERN_DEBUG "ioctl cmd %x arg %lx\n", cmd, arg);
  15118. +
  15119. + switch (cmd)
  15120. + {
  15121. + case DMA_PREPARE:
  15122. + case DMA_PREPARE_KICK:
  15123. + case DMA_PREPARE_KICK_WAIT:
  15124. + {
  15125. + struct DmaControlBlock __user *pUCB = (struct DmaControlBlock *)arg;
  15126. + int steps = 0;
  15127. + unsigned long start_time = jiffies;
  15128. + (void)start_time;
  15129. +
  15130. + //flush our address cache
  15131. + FlushAddrCache();
  15132. +
  15133. + PRINTK_VERBOSE(KERN_DEBUG "dma prepare\n");
  15134. +
  15135. + //do virtual to bus translation for each entry
  15136. + do
  15137. + {
  15138. + pUCB = DmaPrepare(pUCB, &error);
  15139. + } while (error == 0 && ++steps && pUCB);
  15140. + PRINTK_VERBOSE(KERN_DEBUG "prepare done in %d steps, %ld\n", steps, jiffies - start_time);
  15141. +
  15142. + //carry straight on if we want to kick too
  15143. + if (cmd == DMA_PREPARE || error)
  15144. + {
  15145. + PRINTK_VERBOSE(KERN_DEBUG "falling out\n");
  15146. + return error ? -EINVAL : 0;
  15147. + }
  15148. + }
  15149. + case DMA_KICK:
  15150. + PRINTK_VERBOSE(KERN_DEBUG "dma begin\n");
  15151. +
  15152. + if (cmd == DMA_KICK)
  15153. + FlushAddrCache();
  15154. +
  15155. + DmaKick((struct DmaControlBlock __user *)arg);
  15156. +
  15157. + if (cmd != DMA_PREPARE_KICK_WAIT)
  15158. + break;
  15159. +/* case DMA_WAIT_ONE:
  15160. + //PRINTK(KERN_DEBUG "dma wait one\n");
  15161. + break;*/
  15162. + case DMA_WAIT_ALL:
  15163. + //PRINTK(KERN_DEBUG "dma wait all\n");
  15164. + DmaWaitAll();
  15165. + break;
  15166. + case DMA_MAX_BURST:
  15167. + if (g_dmaChan == 0)
  15168. + return 10;
  15169. + else
  15170. + return 5;
  15171. + case DMA_SET_MIN_PHYS:
  15172. + g_pMinPhys = (void __user *)arg;
  15173. + PRINTK(KERN_DEBUG "min/max user/phys bypass set to %p %p\n", g_pMinPhys, g_pMaxPhys);
  15174. + break;
  15175. + case DMA_SET_MAX_PHYS:
  15176. + g_pMaxPhys = (void __user *)arg;
  15177. + PRINTK(KERN_DEBUG "min/max user/phys bypass set to %p %p\n", g_pMinPhys, g_pMaxPhys);
  15178. + break;
  15179. + case DMA_SET_PHYS_OFFSET:
  15180. + g_physOffset = arg;
  15181. + PRINTK(KERN_DEBUG "user/phys bypass offset set to %ld\n", g_physOffset);
  15182. + break;
  15183. + case DMA_CMA_SET_SIZE:
  15184. + {
  15185. + unsigned int pBusAddr;
  15186. +
  15187. + if (g_cmaHandle)
  15188. + {
  15189. + PRINTK(KERN_ERR "memory has already been allocated (handle %d)\n", g_cmaHandle);
  15190. + return -EINVAL;
  15191. + }
  15192. +
  15193. + PRINTK(KERN_INFO "allocating %ld bytes of VC memory\n", arg * 4096);
  15194. +
  15195. + //get the memory
  15196. + if (AllocateVcMemory(&g_cmaHandle, arg * 4096, 4096, MEM_FLAG_L1_NONALLOCATING | MEM_FLAG_NO_INIT | MEM_FLAG_HINT_PERMALOCK))
  15197. + {
  15198. + PRINTK(KERN_ERR "failed to allocate %ld bytes of VC memory\n", arg * 4096);
  15199. + g_cmaHandle = 0;
  15200. + return -EINVAL;
  15201. + }
  15202. +
  15203. + //get an address for it
  15204. + PRINTK(KERN_INFO "trying to map VC memory\n");
  15205. +
  15206. + if (LockVcMemory(&pBusAddr, g_cmaHandle))
  15207. + {
  15208. + PRINTK(KERN_ERR "failed to map CMA handle %d, releasing memory\n", g_cmaHandle);
  15209. + ReleaseVcMemory(g_cmaHandle);
  15210. + g_cmaHandle = 0;
  15211. + }
  15212. +
  15213. + PRINTK(KERN_INFO "bus address for CMA memory is %x\n", pBusAddr);
  15214. + return pBusAddr;
  15215. + }
  15216. + case DMA_GET_VERSION:
  15217. + PRINTK(KERN_DEBUG "returning version number, %d\n", VERSION_NUMBER);
  15218. + return VERSION_NUMBER;
  15219. + default:
  15220. + PRINTK(KERN_DEBUG "unknown ioctl: %d\n", cmd);
  15221. + return -EINVAL;
  15222. + }
  15223. +
  15224. + return 0;
  15225. +}
  15226. +
  15227. +static ssize_t Read(struct file *pFile, char __user *pUser, size_t count, loff_t *offp)
  15228. +{
  15229. + return -EIO;
  15230. +}
  15231. +
  15232. +static int Mmap(struct file *pFile, struct vm_area_struct *pVma)
  15233. +{
  15234. + struct PageList *pPages;
  15235. + struct VmaPageList *pVmaList;
  15236. +
  15237. + PRINTK_VERBOSE(KERN_DEBUG "MMAP vma %p, length %ld (%s %d)\n",
  15238. + pVma, pVma->vm_end - pVma->vm_start,
  15239. + current->comm, current->pid);
  15240. + PRINTK_VERBOSE(KERN_DEBUG "MMAP %p %d (tracked %d)\n", pVma, current->pid, g_trackedPages);
  15241. +
  15242. + //make a new page list
  15243. + pPages = (struct PageList *)kmalloc(sizeof(struct PageList), GFP_KERNEL);
  15244. + if (!pPages)
  15245. + {
  15246. + PRINTK(KERN_ERR "couldn\'t allocate a new page list (%s %d)\n",
  15247. + current->comm, current->pid);
  15248. + return -ENOMEM;
  15249. + }
  15250. +
  15251. + //clear the page list
  15252. + pPages->m_used = 0;
  15253. + pPages->m_pNext = 0;
  15254. +
  15255. + //insert our vma and new page list somewhere
  15256. + if (!pVma->vm_private_data)
  15257. + {
  15258. + struct VmaPageList *pList;
  15259. +
  15260. + PRINTK_VERBOSE(KERN_DEBUG "new vma list, making new one (%s %d)\n",
  15261. + current->comm, current->pid);
  15262. +
  15263. + //make a new vma list
  15264. + pList = (struct VmaPageList *)kmalloc(sizeof(struct VmaPageList), GFP_KERNEL);
  15265. + if (!pList)
  15266. + {
  15267. + PRINTK(KERN_ERR "couldn\'t allocate vma page list (%s %d)\n",
  15268. + current->comm, current->pid);
  15269. + kfree(pPages);
  15270. + return -ENOMEM;
  15271. + }
  15272. +
  15273. + //clear this list
  15274. + pVma->vm_private_data = (void *)pList;
  15275. + pList->m_refCount = 0;
  15276. + }
  15277. +
  15278. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  15279. +
  15280. + //add it to the vma list
  15281. + pVmaList->m_pPageHead = pPages;
  15282. + pVmaList->m_pPageTail = pPages;
  15283. +
  15284. + pVma->vm_ops = &g_vmOps4k;
  15285. + pVma->vm_flags |= VM_IO;
  15286. +
  15287. + VmaOpen4k(pVma);
  15288. +
  15289. + return 0;
  15290. +}
  15291. +
  15292. +/****** VMA OPERATIONS ******/
  15293. +
  15294. +static void VmaOpen4k(struct vm_area_struct *pVma)
  15295. +{
  15296. + struct VmaPageList *pVmaList;
  15297. +
  15298. + 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);
  15299. + PRINTK_VERBOSE(KERN_DEBUG "OPEN %p %d %ld pages (tracked pages %d)\n",
  15300. + pVma, current->pid, (pVma->vm_end - pVma->vm_start) >> 12,
  15301. + g_trackedPages);
  15302. +
  15303. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  15304. +
  15305. + if (pVmaList)
  15306. + {
  15307. + pVmaList->m_refCount++;
  15308. + PRINTK_VERBOSE(KERN_DEBUG "ref count is now %d\n", pVmaList->m_refCount);
  15309. + }
  15310. + else
  15311. + {
  15312. + PRINTK_VERBOSE(KERN_DEBUG "err, open but no vma page list\n");
  15313. + }
  15314. +}
  15315. +
  15316. +static void VmaClose4k(struct vm_area_struct *pVma)
  15317. +{
  15318. + struct VmaPageList *pVmaList;
  15319. + int freed = 0;
  15320. +
  15321. + PRINTK_VERBOSE(KERN_DEBUG "vma close %p private %p (%s %d)\n", pVma, pVma->vm_private_data, current->comm, current->pid);
  15322. +
  15323. + //wait for any dmas to finish
  15324. + DmaWaitAll();
  15325. +
  15326. + //find our vma in the list
  15327. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  15328. +
  15329. + //may be a fork
  15330. + if (pVmaList)
  15331. + {
  15332. + struct PageList *pPages;
  15333. +
  15334. + pVmaList->m_refCount--;
  15335. +
  15336. + if (pVmaList->m_refCount == 0)
  15337. + {
  15338. + PRINTK_VERBOSE(KERN_DEBUG "found vma, freeing pages (%s %d)\n",
  15339. + current->comm, current->pid);
  15340. +
  15341. + pPages = pVmaList->m_pPageHead;
  15342. +
  15343. + if (!pPages)
  15344. + {
  15345. + PRINTK(KERN_ERR "no page list (%s %d)!\n",
  15346. + current->comm, current->pid);
  15347. + return;
  15348. + }
  15349. +
  15350. + while (pPages)
  15351. + {
  15352. + struct PageList *next;
  15353. + int count;
  15354. +
  15355. + PRINTK_VERBOSE(KERN_DEBUG "page list (%s %d)\n",
  15356. + current->comm, current->pid);
  15357. +
  15358. + next = pPages->m_pNext;
  15359. + for (count = 0; count < pPages->m_used; count++)
  15360. + {
  15361. + PRINTK_VERBOSE(KERN_DEBUG "freeing page %p (%s %d)\n",
  15362. + pPages->m_pPages[count],
  15363. + current->comm, current->pid);
  15364. + __free_pages(pPages->m_pPages[count], 0);
  15365. + g_trackedPages--;
  15366. + freed++;
  15367. + }
  15368. +
  15369. + PRINTK_VERBOSE(KERN_DEBUG "freeing page list (%s %d)\n",
  15370. + current->comm, current->pid);
  15371. + kfree(pPages);
  15372. + pPages = next;
  15373. + }
  15374. +
  15375. + //remove our vma from the list
  15376. + kfree(pVmaList);
  15377. + pVma->vm_private_data = 0;
  15378. + }
  15379. + else
  15380. + {
  15381. + PRINTK_VERBOSE(KERN_DEBUG "ref count is %d, not closing\n", pVmaList->m_refCount);
  15382. + }
  15383. + }
  15384. + else
  15385. + {
  15386. + PRINTK_VERBOSE(KERN_ERR "uh-oh, vma %p not found (%s %d)!\n", pVma, current->comm, current->pid);
  15387. + PRINTK_VERBOSE(KERN_ERR "CLOSE ERR\n");
  15388. + }
  15389. +
  15390. + PRINTK_VERBOSE(KERN_DEBUG "CLOSE %p %d %d pages (tracked pages %d)",
  15391. + pVma, current->pid, freed, g_trackedPages);
  15392. +
  15393. + PRINTK_VERBOSE(KERN_DEBUG "%d pages open\n", g_trackedPages);
  15394. +}
  15395. +
  15396. +static int VmaFault4k(struct vm_area_struct *pVma, struct vm_fault *pVmf)
  15397. +{
  15398. + PRINTK_VERBOSE(KERN_DEBUG "vma fault for vma %p private %p at offset %ld (%s %d)\n", pVma, pVma->vm_private_data, pVmf->pgoff,
  15399. + current->comm, current->pid);
  15400. + PRINTK_VERBOSE(KERN_DEBUG "FAULT\n");
  15401. + pVmf->page = alloc_page(GFP_KERNEL);
  15402. +
  15403. + if (pVmf->page)
  15404. + {
  15405. + PRINTK_VERBOSE(KERN_DEBUG "alloc page virtual %p\n", page_address(pVmf->page));
  15406. + }
  15407. +
  15408. + if (!pVmf->page)
  15409. + {
  15410. + PRINTK(KERN_ERR "vma fault oom (%s %d)\n", current->comm, current->pid);
  15411. + return VM_FAULT_OOM;
  15412. + }
  15413. + else
  15414. + {
  15415. + struct VmaPageList *pVmaList;
  15416. +
  15417. + get_page(pVmf->page);
  15418. + g_trackedPages++;
  15419. +
  15420. + //find our vma in the list
  15421. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  15422. +
  15423. + if (pVmaList)
  15424. + {
  15425. + PRINTK_VERBOSE(KERN_DEBUG "vma found (%s %d)\n", current->comm, current->pid);
  15426. +
  15427. + if (pVmaList->m_pPageTail->m_used == PAGES_PER_LIST)
  15428. + {
  15429. + PRINTK_VERBOSE(KERN_DEBUG "making new page list (%s %d)\n", current->comm, current->pid);
  15430. + //making a new page list
  15431. + pVmaList->m_pPageTail->m_pNext = (struct PageList *)kmalloc(sizeof(struct PageList), GFP_KERNEL);
  15432. + if (!pVmaList->m_pPageTail->m_pNext)
  15433. + return -ENOMEM;
  15434. +
  15435. + //update the tail pointer
  15436. + pVmaList->m_pPageTail = pVmaList->m_pPageTail->m_pNext;
  15437. + pVmaList->m_pPageTail->m_used = 0;
  15438. + pVmaList->m_pPageTail->m_pNext = 0;
  15439. + }
  15440. +
  15441. + PRINTK_VERBOSE(KERN_DEBUG "adding page to list (%s %d)\n", current->comm, current->pid);
  15442. +
  15443. + pVmaList->m_pPageTail->m_pPages[pVmaList->m_pPageTail->m_used] = pVmf->page;
  15444. + pVmaList->m_pPageTail->m_used++;
  15445. + }
  15446. + else
  15447. + PRINTK(KERN_ERR "returned page for vma we don\'t know %p (%s %d)\n", pVma, current->comm, current->pid);
  15448. +
  15449. + return 0;
  15450. + }
  15451. +}
  15452. +
  15453. +/****** GENERIC FUNCTIONS ******/
  15454. +static int __init dmaer_init(void)
  15455. +{
  15456. + int result = alloc_chrdev_region(&g_majorMinor, 0, 1, "dmaer");
  15457. + if (result < 0)
  15458. + {
  15459. + PRINTK(KERN_ERR "unable to get major device number\n");
  15460. + return result;
  15461. + }
  15462. + else
  15463. + PRINTK(KERN_DEBUG "major device number %d\n", MAJOR(g_majorMinor));
  15464. +
  15465. + PRINTK(KERN_DEBUG "vma list size %d, page list size %d, page size %ld\n",
  15466. + sizeof(struct VmaPageList), sizeof(struct PageList), PAGE_SIZE);
  15467. +
  15468. + //get a dma channel to work with
  15469. + result = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST, (void **)&g_pDmaChanBase, &g_dmaIrq);
  15470. +
  15471. + //uncomment to force to channel 0
  15472. + //result = 0;
  15473. + //g_pDmaChanBase = 0xce808000;
  15474. +
  15475. + if (result < 0)
  15476. + {
  15477. + PRINTK(KERN_ERR "failed to allocate dma channel\n");
  15478. + cdev_del(&g_cDev);
  15479. + unregister_chrdev_region(g_majorMinor, 1);
  15480. + }
  15481. +
  15482. + //reset the channel
  15483. + PRINTK(KERN_DEBUG "allocated dma channel %d (%p), initial state %08x\n", result, g_pDmaChanBase, *g_pDmaChanBase);
  15484. + *g_pDmaChanBase = 1 << 31;
  15485. + PRINTK(KERN_DEBUG "post-reset %08x\n", *g_pDmaChanBase);
  15486. +
  15487. + g_dmaChan = result;
  15488. +
  15489. + //clear the cache stats
  15490. + g_cacheHit = 0;
  15491. + g_cacheMiss = 0;
  15492. +
  15493. + //register our device - after this we are go go go
  15494. + cdev_init(&g_cDev, &g_fOps);
  15495. + g_cDev.owner = THIS_MODULE;
  15496. + g_cDev.ops = &g_fOps;
  15497. +
  15498. + result = cdev_add(&g_cDev, g_majorMinor, 1);
  15499. + if (result < 0)
  15500. + {
  15501. + PRINTK(KERN_ERR "failed to add character device\n");
  15502. + unregister_chrdev_region(g_majorMinor, 1);
  15503. + bcm_dma_chan_free(g_dmaChan);
  15504. + return result;
  15505. + }
  15506. +
  15507. + return 0;
  15508. +}
  15509. +
  15510. +static void __exit dmaer_exit(void)
  15511. +{
  15512. + PRINTK(KERN_INFO "closing dmaer device, cache stats: %d hits %d misses\n", g_cacheHit, g_cacheMiss);
  15513. + //unregister the device
  15514. + cdev_del(&g_cDev);
  15515. + unregister_chrdev_region(g_majorMinor, 1);
  15516. + //free the dma channel
  15517. + bcm_dma_chan_free(g_dmaChan);
  15518. +}
  15519. +
  15520. +MODULE_LICENSE("Dual BSD/GPL");
  15521. +MODULE_AUTHOR("Simon Hall");
  15522. +module_init(dmaer_init);
  15523. +module_exit(dmaer_exit);
  15524. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/arm_control.h linux-rpi/arch/arm/mach-bcm2709/include/mach/arm_control.h
  15525. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/arm_control.h 1970-01-01 01:00:00.000000000 +0100
  15526. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/arm_control.h 2015-02-09 04:39:42.000000000 +0100
  15527. @@ -0,0 +1,493 @@
  15528. +/*
  15529. + * linux/arch/arm/mach-bcm2708/arm_control.h
  15530. + *
  15531. + * Copyright (C) 2010 Broadcom
  15532. + *
  15533. + * This program is free software; you can redistribute it and/or modify
  15534. + * it under the terms of the GNU General Public License as published by
  15535. + * the Free Software Foundation; either version 2 of the License, or
  15536. + * (at your option) any later version.
  15537. + *
  15538. + * This program is distributed in the hope that it will be useful,
  15539. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15540. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15541. + * GNU General Public License for more details.
  15542. + *
  15543. + * You should have received a copy of the GNU General Public License
  15544. + * along with this program; if not, write to the Free Software
  15545. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15546. + */
  15547. +
  15548. +#ifndef __BCM2708_ARM_CONTROL_H
  15549. +#define __BCM2708_ARM_CONTROL_H
  15550. +
  15551. +/*
  15552. + * Definitions and addresses for the ARM CONTROL logic
  15553. + * This file is manually generated.
  15554. + */
  15555. +
  15556. +#define ARM_BASE 0x7E00B000
  15557. +
  15558. +/* Basic configuration */
  15559. +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000)
  15560. +#define ARM_C0_SIZ128M 0x00000000
  15561. +#define ARM_C0_SIZ256M 0x00000001
  15562. +#define ARM_C0_SIZ512M 0x00000002
  15563. +#define ARM_C0_SIZ1G 0x00000003
  15564. +#define ARM_C0_BRESP0 0x00000000
  15565. +#define ARM_C0_BRESP1 0x00000004
  15566. +#define ARM_C0_BRESP2 0x00000008
  15567. +#define ARM_C0_BOOTHI 0x00000010
  15568. +#define ARM_C0_UNUSED05 0x00000020 /* free */
  15569. +#define ARM_C0_FULLPERI 0x00000040
  15570. +#define ARM_C0_UNUSED78 0x00000180 /* free */
  15571. +#define ARM_C0_JTAGMASK 0x00000E00
  15572. +#define ARM_C0_JTAGOFF 0x00000000
  15573. +#define ARM_C0_JTAGBASH 0x00000800 /* Debug on GPIO off */
  15574. +#define ARM_C0_JTAGGPIO 0x00000C00 /* Debug on GPIO on */
  15575. +#define ARM_C0_APROTMSK 0x0000F000
  15576. +#define ARM_C0_DBG0SYNC 0x00010000 /* VPU0 halt sync */
  15577. +#define ARM_C0_DBG1SYNC 0x00020000 /* VPU1 halt sync */
  15578. +#define ARM_C0_SWDBGREQ 0x00040000 /* HW debug request */
  15579. +#define ARM_C0_PASSHALT 0x00080000 /* ARM halt passed to debugger */
  15580. +#define ARM_C0_PRIO_PER 0x00F00000 /* per priority mask */
  15581. +#define ARM_C0_PRIO_L2 0x0F000000
  15582. +#define ARM_C0_PRIO_UC 0xF0000000
  15583. +
  15584. +#define ARM_C0_APROTPASS 0x0000A000 /* Translate 1:1 */
  15585. +#define ARM_C0_APROTUSER 0x00000000 /* Only user mode */
  15586. +#define ARM_C0_APROTSYST 0x0000F000 /* Only system mode */
  15587. +
  15588. +
  15589. +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440)
  15590. +#define ARM_C1_TIMER 0x00000001 /* re-route timer IRQ to VC */
  15591. +#define ARM_C1_MAIL 0x00000002 /* re-route Mail IRQ to VC */
  15592. +#define ARM_C1_BELL0 0x00000004 /* re-route Doorbell 0 to VC */
  15593. +#define ARM_C1_BELL1 0x00000008 /* re-route Doorbell 1 to VC */
  15594. +#define ARM_C1_PERSON 0x00000100 /* peripherals on */
  15595. +#define ARM_C1_REQSTOP 0x00000200 /* ASYNC bridge request stop */
  15596. +
  15597. +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444)
  15598. +#define ARM_S_ACKSTOP 0x80000000 /* Bridge stopped */
  15599. +#define ARM_S_READPEND 0x000003FF /* pending reads counter */
  15600. +#define ARM_S_WRITPEND 0x000FFC00 /* pending writes counter */
  15601. +
  15602. +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448)
  15603. +#define ARM_EH_PERIBURST 0x00000001 /* Burst write seen on peri bus */
  15604. +#define ARM_EH_ILLADDRS1 0x00000002 /* Address bits 25-27 error */
  15605. +#define ARM_EH_ILLADDRS2 0x00000004 /* Address bits 31-28 error */
  15606. +#define ARM_EH_VPU0HALT 0x00000008 /* VPU0 halted & in debug mode */
  15607. +#define ARM_EH_VPU1HALT 0x00000010 /* VPU1 halted & in debug mode */
  15608. +#define ARM_EH_ARMHALT 0x00000020 /* ARM in halted debug mode */
  15609. +
  15610. +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C)
  15611. +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C)
  15612. +#define ARM_IDVAL 0x364D5241
  15613. +
  15614. +/* Translation memory */
  15615. +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100)
  15616. +/* 32 locations: 0x100.. 0x17F */
  15617. +/* 32 spare means we CAN go to 64 pages.... */
  15618. +
  15619. +
  15620. +/* Interrupts */
  15621. +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200) /* Top IRQ bits */
  15622. +#define ARM_I0_TIMER 0x00000001 /* timer IRQ */
  15623. +#define ARM_I0_MAIL 0x00000002 /* Mail IRQ */
  15624. +#define ARM_I0_BELL0 0x00000004 /* Doorbell 0 */
  15625. +#define ARM_I0_BELL1 0x00000008 /* Doorbell 1 */
  15626. +#define ARM_I0_BANK1 0x00000100 /* Bank1 IRQ */
  15627. +#define ARM_I0_BANK2 0x00000200 /* Bank2 IRQ */
  15628. +
  15629. +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204) /* All bank1 IRQ bits */
  15630. +/* todo: all I1_interrupt sources */
  15631. +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208) /* All bank2 IRQ bits */
  15632. +/* todo: all I2_interrupt sources */
  15633. +
  15634. +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C) /* FIQ control */
  15635. +#define ARM_IF_INDEX 0x0000007F /* FIQ select */
  15636. +#define ARM_IF_ENABLE 0x00000080 /* FIQ enable */
  15637. +#define ARM_IF_VCMASK 0x0000003F /* FIQ = (index from VC source) */
  15638. +#define ARM_IF_TIMER 0x00000040 /* FIQ = ARM timer */
  15639. +#define ARM_IF_MAIL 0x00000041 /* FIQ = ARM Mail */
  15640. +#define ARM_IF_BELL0 0x00000042 /* FIQ = ARM Doorbell 0 */
  15641. +#define ARM_IF_BELL1 0x00000043 /* FIQ = ARM Doorbell 1 */
  15642. +#define ARM_IF_VP0HALT 0x00000044 /* FIQ = VPU0 Halt seen */
  15643. +#define ARM_IF_VP1HALT 0x00000045 /* FIQ = VPU1 Halt seen */
  15644. +#define ARM_IF_ILLEGAL 0x00000046 /* FIQ = Illegal access seen */
  15645. +
  15646. +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210) /* Bank1 enable bits */
  15647. +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214) /* Bank2 enable bits */
  15648. +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218) /* ARM irqs enable bits */
  15649. +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C) /* Bank1 disable bits */
  15650. +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220) /* Bank2 disable bits */
  15651. +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224) /* ARM irqs disable bits */
  15652. +#define ARM_IE_TIMER 0x00000001 /* Timer IRQ */
  15653. +#define ARM_IE_MAIL 0x00000002 /* Mail IRQ */
  15654. +#define ARM_IE_BELL0 0x00000004 /* Doorbell 0 */
  15655. +#define ARM_IE_BELL1 0x00000008 /* Doorbell 1 */
  15656. +#define ARM_IE_VP0HALT 0x00000010 /* VPU0 Halt */
  15657. +#define ARM_IE_VP1HALT 0x00000020 /* VPU1 Halt */
  15658. +#define ARM_IE_ILLEGAL 0x00000040 /* Illegal access seen */
  15659. +
  15660. +/* Timer */
  15661. +/* For reg. fields see sp804 spec. */
  15662. +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400)
  15663. +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404)
  15664. +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408)
  15665. +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C)
  15666. +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410)
  15667. +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414)
  15668. +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418)
  15669. +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c)
  15670. +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420)
  15671. +
  15672. +#define TIMER_CTRL_ONESHOT (1 << 0)
  15673. +#define TIMER_CTRL_32BIT (1 << 1)
  15674. +#define TIMER_CTRL_DIV1 (0 << 2)
  15675. +#define TIMER_CTRL_DIV16 (1 << 2)
  15676. +#define TIMER_CTRL_DIV256 (2 << 2)
  15677. +#define TIMER_CTRL_IE (1 << 5)
  15678. +#define TIMER_CTRL_PERIODIC (1 << 6)
  15679. +#define TIMER_CTRL_ENABLE (1 << 7)
  15680. +#define TIMER_CTRL_DBGHALT (1 << 8)
  15681. +#define TIMER_CTRL_ENAFREE (1 << 9)
  15682. +#define TIMER_CTRL_FREEDIV_SHIFT 16)
  15683. +#define TIMER_CTRL_FREEDIV_MASK 0xff
  15684. +
  15685. +/* Semaphores, Doorbells, Mailboxes */
  15686. +#define ARM_SBM_OWN0 (ARM_BASE+0x800)
  15687. +#define ARM_SBM_OWN1 (ARM_BASE+0x900)
  15688. +#define ARM_SBM_OWN2 (ARM_BASE+0xA00)
  15689. +#define ARM_SBM_OWN3 (ARM_BASE+0xB00)
  15690. +
  15691. +/* MAILBOXES
  15692. + * Register flags are common across all
  15693. + * owner registers. See end of this section
  15694. + *
  15695. + * Semaphores, Doorbells, Mailboxes Owner 0
  15696. + *
  15697. + */
  15698. +
  15699. +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  15700. +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  15701. +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04)
  15702. +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08)
  15703. +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C)
  15704. +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10)
  15705. +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14)
  15706. +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18)
  15707. +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
  15708. +#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40)
  15709. +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44)
  15710. +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48)
  15711. +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
  15712. +/* MAILBOX 0 access in Owner 0 area */
  15713. +/* Some addresses should ONLY be used by owner 0 */
  15714. +#define ARM_0_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) */
  15715. +#define ARM_0_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) Normal read */
  15716. +#define ARM_0_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN0+0x90) /* none-pop read */
  15717. +#define ARM_0_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN0+0x94) /* Sender read (only LS 2 bits) */
  15718. +#define ARM_0_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN0+0x98) /* Status read */
  15719. +#define ARM_0_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0x9C) /* Config read/write */
  15720. +/* MAILBOX 1 access in Owner 0 area */
  15721. +/* Owner 0 should only WRITE to this mailbox */
  15722. +#define ARM_0_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) /* .. 0xAC (4 locations) */
  15723. +/*#define ARM_0_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */
  15724. +/*#define ARM_0_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */
  15725. +/*#define ARM_0_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */
  15726. +#define ARM_0_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN0+0xB8) /* Status read */
  15727. +/*#define ARM_0_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */
  15728. +/* General SEM, BELL, MAIL config/status */
  15729. +#define ARM_0_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE0) /* semaphore clear/debug register */
  15730. +#define ARM_0_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE4) /* Doorbells clear/debug register */
  15731. +#define ARM_0_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xF8) /* ALL interrupts */
  15732. +#define ARM_0_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xFC) /* IRQS pending for owner 0 */
  15733. +
  15734. +/* Semaphores, Doorbells, Mailboxes Owner 1 */
  15735. +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  15736. +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  15737. +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
  15738. +#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08)
  15739. +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C)
  15740. +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10)
  15741. +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14)
  15742. +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18)
  15743. +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C)
  15744. +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40)
  15745. +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44)
  15746. +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48)
  15747. +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
  15748. +/* MAILBOX 0 access in Owner 0 area */
  15749. +/* Owner 1 should only WRITE to this mailbox */
  15750. +#define ARM_1_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0x80) /* .. 0x8C (4 locations) */
  15751. +/*#define ARM_1_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */
  15752. +/*#define ARM_1_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */
  15753. +/*#define ARM_1_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */
  15754. +#define ARM_1_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN1+0x98) /* Status read */
  15755. +/*#define ARM_1_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */
  15756. +/* MAILBOX 1 access in Owner 0 area */
  15757. +#define ARM_1_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) */
  15758. +#define ARM_1_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) Normal read */
  15759. +#define ARM_1_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN1+0xB0) /* none-pop read */
  15760. +#define ARM_1_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN1+0xB4) /* Sender read (only LS 2 bits) */
  15761. +#define ARM_1_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN1+0xB8) /* Status read */
  15762. +#define ARM_1_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0xBC)
  15763. +/* General SEM, BELL, MAIL config/status */
  15764. +#define ARM_1_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE0) /* semaphore clear/debug register */
  15765. +#define ARM_1_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE4) /* Doorbells clear/debug register */
  15766. +#define ARM_1_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xFC) /* IRQS pending for owner 1 */
  15767. +#define ARM_1_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xF8) /* ALL interrupts */
  15768. +
  15769. +/* Semaphores, Doorbells, Mailboxes Owner 2 */
  15770. +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  15771. +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  15772. +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04)
  15773. +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08)
  15774. +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C)
  15775. +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10)
  15776. +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14)
  15777. +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18)
  15778. +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C)
  15779. +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40)
  15780. +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44)
  15781. +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48)
  15782. +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C)
  15783. +/* MAILBOX 0 access in Owner 2 area */
  15784. +/* Owner 2 should only WRITE to this mailbox */
  15785. +#define ARM_2_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0x80) /* .. 0x8C (4 locations) */
  15786. +/*#define ARM_2_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */
  15787. +/*#define ARM_2_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */
  15788. +/*#define ARM_2_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */
  15789. +#define ARM_2_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN2+0x98) /* Status read */
  15790. +/*#define ARM_2_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */
  15791. +/* MAILBOX 1 access in Owner 2 area */
  15792. +/* Owner 2 should only WRITE to this mailbox */
  15793. +#define ARM_2_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) /* .. 0xAC (4 locations) */
  15794. +/*#define ARM_2_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */
  15795. +/*#define ARM_2_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */
  15796. +/*#define ARM_2_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */
  15797. +#define ARM_2_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN2+0xB8) /* Status read */
  15798. +/*#define ARM_2_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */
  15799. +/* General SEM, BELL, MAIL config/status */
  15800. +#define ARM_2_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE0) /* semaphore clear/debug register */
  15801. +#define ARM_2_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE4) /* Doorbells clear/debug register */
  15802. +#define ARM_2_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xFC) /* IRQS pending for owner 2 */
  15803. +#define ARM_2_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xF8) /* ALL interrupts */
  15804. +
  15805. +/* Semaphores, Doorbells, Mailboxes Owner 3 */
  15806. +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  15807. +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  15808. +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04)
  15809. +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08)
  15810. +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C)
  15811. +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10)
  15812. +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14)
  15813. +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18)
  15814. +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C)
  15815. +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40)
  15816. +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44)
  15817. +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48)
  15818. +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C)
  15819. +/* MAILBOX 0 access in Owner 3 area */
  15820. +/* Owner 3 should only WRITE to this mailbox */
  15821. +#define ARM_3_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0x80) /* .. 0x8C (4 locations) */
  15822. +/*#define ARM_3_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */
  15823. +/*#define ARM_3_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */
  15824. +/*#define ARM_3_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */
  15825. +#define ARM_3_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN3+0x98) /* Status read */
  15826. +/*#define ARM_3_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */
  15827. +/* MAILBOX 1 access in Owner 3 area */
  15828. +/* Owner 3 should only WRITE to this mailbox */
  15829. +#define ARM_3_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) /* .. 0xAC (4 locations) */
  15830. +/*#define ARM_3_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */
  15831. +/*#define ARM_3_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */
  15832. +/*#define ARM_3_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */
  15833. +#define ARM_3_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN3+0xB8) /* Status read */
  15834. +/*#define ARM_3_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */
  15835. +/* General SEM, BELL, MAIL config/status */
  15836. +#define ARM_3_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE0) /* semaphore clear/debug register */
  15837. +#define ARM_3_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE4) /* Doorbells clear/debug register */
  15838. +#define ARM_3_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xFC) /* IRQS pending for owner 3 */
  15839. +#define ARM_3_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xF8) /* ALL interrupts */
  15840. +
  15841. +
  15842. +
  15843. +/* Mailbox flags. Valid for all owners */
  15844. +
  15845. +/* Mailbox status register (...0x98) */
  15846. +#define ARM_MS_FULL 0x80000000
  15847. +#define ARM_MS_EMPTY 0x40000000
  15848. +#define ARM_MS_LEVEL 0x400000FF /* Max. value depdnds on mailbox depth parameter */
  15849. +
  15850. +/* MAILBOX config/status register (...0x9C) */
  15851. +/* ANY write to this register clears the error bits! */
  15852. +#define ARM_MC_IHAVEDATAIRQEN 0x00000001 /* mailbox irq enable: has data */
  15853. +#define ARM_MC_IHAVESPACEIRQEN 0x00000002 /* mailbox irq enable: has space */
  15854. +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004 /* mailbox irq enable: Opp. is empty */
  15855. +#define ARM_MC_MAIL_CLEAR 0x00000008 /* mailbox clear write 1, then 0 */
  15856. +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010 /* mailbox irq pending: has space */
  15857. +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020 /* mailbox irq pending: Opp. is empty */
  15858. +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040 /* mailbox irq pending */
  15859. +/* Bit 7 is unused */
  15860. +#define ARM_MC_ERRNOOWN 0x00000100 /* error : none owner read from mailbox */
  15861. +#define ARM_MC_ERROVERFLW 0x00000200 /* error : write to fill mailbox */
  15862. +#define ARM_MC_ERRUNDRFLW 0x00000400 /* error : read from empty mailbox */
  15863. +
  15864. +/* Semaphore clear/debug register (...0xE0) */
  15865. +#define ARM_SD_OWN0 0x00000003 /* Owner of sem 0 */
  15866. +#define ARM_SD_OWN1 0x0000000C /* Owner of sem 1 */
  15867. +#define ARM_SD_OWN2 0x00000030 /* Owner of sem 2 */
  15868. +#define ARM_SD_OWN3 0x000000C0 /* Owner of sem 3 */
  15869. +#define ARM_SD_OWN4 0x00000300 /* Owner of sem 4 */
  15870. +#define ARM_SD_OWN5 0x00000C00 /* Owner of sem 5 */
  15871. +#define ARM_SD_OWN6 0x00003000 /* Owner of sem 6 */
  15872. +#define ARM_SD_OWN7 0x0000C000 /* Owner of sem 7 */
  15873. +#define ARM_SD_SEM0 0x00010000 /* Status of sem 0 */
  15874. +#define ARM_SD_SEM1 0x00020000 /* Status of sem 1 */
  15875. +#define ARM_SD_SEM2 0x00040000 /* Status of sem 2 */
  15876. +#define ARM_SD_SEM3 0x00080000 /* Status of sem 3 */
  15877. +#define ARM_SD_SEM4 0x00100000 /* Status of sem 4 */
  15878. +#define ARM_SD_SEM5 0x00200000 /* Status of sem 5 */
  15879. +#define ARM_SD_SEM6 0x00400000 /* Status of sem 6 */
  15880. +#define ARM_SD_SEM7 0x00800000 /* Status of sem 7 */
  15881. +
  15882. +/* Doorbells clear/debug register (...0xE4) */
  15883. +#define ARM_BD_OWN0 0x00000003 /* Owner of doorbell 0 */
  15884. +#define ARM_BD_OWN1 0x0000000C /* Owner of doorbell 1 */
  15885. +#define ARM_BD_OWN2 0x00000030 /* Owner of doorbell 2 */
  15886. +#define ARM_BD_OWN3 0x000000C0 /* Owner of doorbell 3 */
  15887. +#define ARM_BD_BELL0 0x00000100 /* Status of doorbell 0 */
  15888. +#define ARM_BD_BELL1 0x00000200 /* Status of doorbell 1 */
  15889. +#define ARM_BD_BELL2 0x00000400 /* Status of doorbell 2 */
  15890. +#define ARM_BD_BELL3 0x00000800 /* Status of doorbell 3 */
  15891. +
  15892. +/* MY IRQS register (...0xF8) */
  15893. +#define ARM_MYIRQ_BELL 0x00000001 /* This owner has a doorbell IRQ */
  15894. +#define ARM_MYIRQ_MAIL 0x00000002 /* This owner has a mailbox IRQ */
  15895. +
  15896. +/* ALL IRQS register (...0xF8) */
  15897. +#define ARM_AIS_BELL0 0x00000001 /* Doorbell 0 IRQ pending */
  15898. +#define ARM_AIS_BELL1 0x00000002 /* Doorbell 1 IRQ pending */
  15899. +#define ARM_AIS_BELL2 0x00000004 /* Doorbell 2 IRQ pending */
  15900. +#define ARM_AIS_BELL3 0x00000008 /* Doorbell 3 IRQ pending */
  15901. +#define ARM_AIS0_HAVEDATA 0x00000010 /* MAIL 0 has data IRQ pending */
  15902. +#define ARM_AIS0_HAVESPAC 0x00000020 /* MAIL 0 has space IRQ pending */
  15903. +#define ARM_AIS0_OPPEMPTY 0x00000040 /* MAIL 0 opposite is empty IRQ */
  15904. +#define ARM_AIS1_HAVEDATA 0x00000080 /* MAIL 1 has data IRQ pending */
  15905. +#define ARM_AIS1_HAVESPAC 0x00000100 /* MAIL 1 has space IRQ pending */
  15906. +#define ARM_AIS1_OPPEMPTY 0x00000200 /* MAIL 1 opposite is empty IRQ */
  15907. +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */
  15908. +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */
  15909. +/* */
  15910. +/* ARM JTAG BASH */
  15911. +/* */
  15912. +#define AJB_BASE 0x7e2000c0
  15913. +
  15914. +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00)
  15915. +#define AJB_BITS0 0x000000
  15916. +#define AJB_BITS4 0x000004
  15917. +#define AJB_BITS8 0x000008
  15918. +#define AJB_BITS12 0x00000C
  15919. +#define AJB_BITS16 0x000010
  15920. +#define AJB_BITS20 0x000014
  15921. +#define AJB_BITS24 0x000018
  15922. +#define AJB_BITS28 0x00001C
  15923. +#define AJB_BITS32 0x000020
  15924. +#define AJB_BITS34 0x000022
  15925. +#define AJB_OUT_MS 0x000040
  15926. +#define AJB_OUT_LS 0x000000
  15927. +#define AJB_INV_CLK 0x000080
  15928. +#define AJB_D0_RISE 0x000100
  15929. +#define AJB_D0_FALL 0x000000
  15930. +#define AJB_D1_RISE 0x000200
  15931. +#define AJB_D1_FALL 0x000000
  15932. +#define AJB_IN_RISE 0x000400
  15933. +#define AJB_IN_FALL 0x000000
  15934. +#define AJB_ENABLE 0x000800
  15935. +#define AJB_HOLD0 0x000000
  15936. +#define AJB_HOLD1 0x001000
  15937. +#define AJB_HOLD2 0x002000
  15938. +#define AJB_HOLD3 0x003000
  15939. +#define AJB_RESETN 0x004000
  15940. +#define AJB_CLKSHFT 16
  15941. +#define AJB_BUSY 0x80000000
  15942. +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04)
  15943. +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08)
  15944. +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c)
  15945. +
  15946. +#define ARM_LOCAL_BASE 0x40000000
  15947. +#define ARM_LOCAL_CONTROL HW_REGISTER_RW(ARM_LOCAL_BASE+0x000)
  15948. +#define ARM_LOCAL_PRESCALER HW_REGISTER_RW(ARM_LOCAL_BASE+0x008)
  15949. +#define ARM_LOCAL_GPU_INT_ROUTING HW_REGISTER_RW(ARM_LOCAL_BASE+0x00C)
  15950. +#define ARM_LOCAL_PM_ROUTING_SET HW_REGISTER_RW(ARM_LOCAL_BASE+0x010)
  15951. +#define ARM_LOCAL_PM_ROUTING_CLR HW_REGISTER_RW(ARM_LOCAL_BASE+0x014)
  15952. +#define ARM_LOCAL_TIMER_LS HW_REGISTER_RW(ARM_LOCAL_BASE+0x01C)
  15953. +#define ARM_LOCAL_TIMER_MS HW_REGISTER_RW(ARM_LOCAL_BASE+0x020)
  15954. +#define ARM_LOCAL_INT_ROUTING HW_REGISTER_RW(ARM_LOCAL_BASE+0x024)
  15955. +#define ARM_LOCAL_AXI_COUNT HW_REGISTER_RW(ARM_LOCAL_BASE+0x02C)
  15956. +#define ARM_LOCAL_AXI_IRQ HW_REGISTER_RW(ARM_LOCAL_BASE+0x030)
  15957. +#define ARM_LOCAL_TIMER_CONTROL HW_REGISTER_RW(ARM_LOCAL_BASE+0x034)
  15958. +#define ARM_LOCAL_TIMER_WRITE HW_REGISTER_RW(ARM_LOCAL_BASE+0x038)
  15959. +
  15960. +#define ARM_LOCAL_TIMER_INT_CONTROL0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x040)
  15961. +#define ARM_LOCAL_TIMER_INT_CONTROL1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x044)
  15962. +#define ARM_LOCAL_TIMER_INT_CONTROL2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x048)
  15963. +#define ARM_LOCAL_TIMER_INT_CONTROL3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x04C)
  15964. +
  15965. +#define ARM_LOCAL_MAILBOX_INT_CONTROL0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x050)
  15966. +#define ARM_LOCAL_MAILBOX_INT_CONTROL1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x054)
  15967. +#define ARM_LOCAL_MAILBOX_INT_CONTROL2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x058)
  15968. +#define ARM_LOCAL_MAILBOX_INT_CONTROL3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x05C)
  15969. +
  15970. +#define ARM_LOCAL_IRQ_PENDING0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x060)
  15971. +#define ARM_LOCAL_IRQ_PENDING1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x064)
  15972. +#define ARM_LOCAL_IRQ_PENDING2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x068)
  15973. +#define ARM_LOCAL_IRQ_PENDING3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x06C)
  15974. +
  15975. +#define ARM_LOCAL_FIQ_PENDING0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x070)
  15976. +#define ARM_LOCAL_FIQ_PENDING1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x074)
  15977. +#define ARM_LOCAL_FIQ_PENDING2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x078)
  15978. +#define ARM_LOCAL_FIQ_PENDING3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x07C)
  15979. +
  15980. +#define ARM_LOCAL_MAILBOX0_SET0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x080)
  15981. +#define ARM_LOCAL_MAILBOX1_SET0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x084)
  15982. +#define ARM_LOCAL_MAILBOX2_SET0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x088)
  15983. +#define ARM_LOCAL_MAILBOX3_SET0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x08C)
  15984. +
  15985. +#define ARM_LOCAL_MAILBOX0_SET1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x090)
  15986. +#define ARM_LOCAL_MAILBOX1_SET1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x094)
  15987. +#define ARM_LOCAL_MAILBOX2_SET1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x098)
  15988. +#define ARM_LOCAL_MAILBOX3_SET1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x09C)
  15989. +
  15990. +#define ARM_LOCAL_MAILBOX0_SET2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0A0)
  15991. +#define ARM_LOCAL_MAILBOX1_SET2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0A4)
  15992. +#define ARM_LOCAL_MAILBOX2_SET2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0A8)
  15993. +#define ARM_LOCAL_MAILBOX3_SET2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0AC)
  15994. +
  15995. +#define ARM_LOCAL_MAILBOX0_SET3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0B0)
  15996. +#define ARM_LOCAL_MAILBOX1_SET3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0B4)
  15997. +#define ARM_LOCAL_MAILBOX2_SET3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0B8)
  15998. +#define ARM_LOCAL_MAILBOX3_SET3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0BC)
  15999. +
  16000. +#define ARM_LOCAL_MAILBOX0_CLR0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0C0)
  16001. +#define ARM_LOCAL_MAILBOX1_CLR0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0C4)
  16002. +#define ARM_LOCAL_MAILBOX2_CLR0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0C8)
  16003. +#define ARM_LOCAL_MAILBOX3_CLR0 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0CC)
  16004. +
  16005. +#define ARM_LOCAL_MAILBOX0_CLR1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0D0)
  16006. +#define ARM_LOCAL_MAILBOX1_CLR1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0D4)
  16007. +#define ARM_LOCAL_MAILBOX2_CLR1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0D8)
  16008. +#define ARM_LOCAL_MAILBOX3_CLR1 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0DC)
  16009. +
  16010. +#define ARM_LOCAL_MAILBOX0_CLR2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0E0)
  16011. +#define ARM_LOCAL_MAILBOX1_CLR2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0E4)
  16012. +#define ARM_LOCAL_MAILBOX2_CLR2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0E8)
  16013. +#define ARM_LOCAL_MAILBOX3_CLR2 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0EC)
  16014. +
  16015. +#define ARM_LOCAL_MAILBOX0_CLR3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0F0)
  16016. +#define ARM_LOCAL_MAILBOX1_CLR3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0F4)
  16017. +#define ARM_LOCAL_MAILBOX2_CLR3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0F8)
  16018. +#define ARM_LOCAL_MAILBOX3_CLR3 HW_REGISTER_RW(ARM_LOCAL_BASE+0x0FC)
  16019. +
  16020. +#endif
  16021. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/arm_power.h linux-rpi/arch/arm/mach-bcm2709/include/mach/arm_power.h
  16022. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/arm_power.h 1970-01-01 01:00:00.000000000 +0100
  16023. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/arm_power.h 2015-02-09 04:39:42.000000000 +0100
  16024. @@ -0,0 +1,62 @@
  16025. +/*
  16026. + * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h
  16027. + *
  16028. + * Copyright (C) 2010 Broadcom
  16029. + *
  16030. + * This program is free software; you can redistribute it and/or modify
  16031. + * it under the terms of the GNU General Public License as published by
  16032. + * the Free Software Foundation; either version 2 of the License, or
  16033. + * (at your option) any later version.
  16034. + *
  16035. + * This program is distributed in the hope that it will be useful,
  16036. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16037. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16038. + * GNU General Public License for more details.
  16039. + *
  16040. + * You should have received a copy of the GNU General Public License
  16041. + * along with this program; if not, write to the Free Software
  16042. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16043. + */
  16044. +
  16045. +#ifndef _ARM_POWER_H
  16046. +#define _ARM_POWER_H
  16047. +
  16048. +/* Use meaningful names on each side */
  16049. +#ifdef __VIDEOCORE__
  16050. +#define PREFIX(x) ARM_##x
  16051. +#else
  16052. +#define PREFIX(x) BCM_##x
  16053. +#endif
  16054. +
  16055. +enum {
  16056. + PREFIX(POWER_SDCARD_BIT),
  16057. + PREFIX(POWER_UART_BIT),
  16058. + PREFIX(POWER_MINIUART_BIT),
  16059. + PREFIX(POWER_USB_BIT),
  16060. + PREFIX(POWER_I2C0_BIT),
  16061. + PREFIX(POWER_I2C1_BIT),
  16062. + PREFIX(POWER_I2C2_BIT),
  16063. + PREFIX(POWER_SPI_BIT),
  16064. + PREFIX(POWER_CCP2TX_BIT),
  16065. + PREFIX(POWER_DSI_BIT),
  16066. +
  16067. + PREFIX(POWER_MAX)
  16068. +};
  16069. +
  16070. +enum {
  16071. + PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)),
  16072. + PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)),
  16073. + PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)),
  16074. + PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)),
  16075. + PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)),
  16076. + PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)),
  16077. + PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)),
  16078. + PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)),
  16079. + PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)),
  16080. + PREFIX(POWER_DSI) = (1 << PREFIX(POWER_DSI_BIT)),
  16081. +
  16082. + PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1,
  16083. + PREFIX(POWER_NONE) = 0
  16084. +};
  16085. +
  16086. +#endif
  16087. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/barriers.h linux-rpi/arch/arm/mach-bcm2709/include/mach/barriers.h
  16088. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/barriers.h 1970-01-01 01:00:00.000000000 +0100
  16089. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/barriers.h 2015-02-09 04:39:42.000000000 +0100
  16090. @@ -0,0 +1,3 @@
  16091. +#define mb() dsb()
  16092. +#define rmb() dsb()
  16093. +#define wmb() mb()
  16094. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/clkdev.h linux-rpi/arch/arm/mach-bcm2709/include/mach/clkdev.h
  16095. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/clkdev.h 1970-01-01 01:00:00.000000000 +0100
  16096. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/clkdev.h 2015-02-09 04:39:42.000000000 +0100
  16097. @@ -0,0 +1,7 @@
  16098. +#ifndef __ASM_MACH_CLKDEV_H
  16099. +#define __ASM_MACH_CLKDEV_H
  16100. +
  16101. +#define __clk_get(clk) ({ 1; })
  16102. +#define __clk_put(clk) do { } while (0)
  16103. +
  16104. +#endif
  16105. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/debug-macro.S linux-rpi/arch/arm/mach-bcm2709/include/mach/debug-macro.S
  16106. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/debug-macro.S 1970-01-01 01:00:00.000000000 +0100
  16107. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/debug-macro.S 2015-02-09 04:39:42.000000000 +0100
  16108. @@ -0,0 +1,22 @@
  16109. +/* arch/arm/mach-bcm2708/include/mach/debug-macro.S
  16110. + *
  16111. + * Debugging macro include header
  16112. + *
  16113. + * Copyright (C) 2010 Broadcom
  16114. + * Copyright (C) 1994-1999 Russell King
  16115. + * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
  16116. + *
  16117. + * This program is free software; you can redistribute it and/or modify
  16118. + * it under the terms of the GNU General Public License version 2 as
  16119. + * published by the Free Software Foundation.
  16120. + *
  16121. +*/
  16122. +
  16123. +#include <mach/platform.h>
  16124. +
  16125. + .macro addruart, rp, rv, tmp
  16126. + ldr \rp, =UART0_BASE
  16127. + ldr \rv, =IO_ADDRESS(UART0_BASE)
  16128. + .endm
  16129. +
  16130. +#include <debug/pl01x.S>
  16131. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/dma.h linux-rpi/arch/arm/mach-bcm2709/include/mach/dma.h
  16132. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
  16133. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/dma.h 2015-02-09 04:39:42.000000000 +0100
  16134. @@ -0,0 +1,94 @@
  16135. +/*
  16136. + * linux/arch/arm/mach-bcm2708/include/mach/dma.h
  16137. + *
  16138. + * Copyright (C) 2010 Broadcom
  16139. + *
  16140. + * This program is free software; you can redistribute it and/or modify
  16141. + * it under the terms of the GNU General Public License version 2 as
  16142. + * published by the Free Software Foundation.
  16143. + */
  16144. +
  16145. +
  16146. +#ifndef _MACH_BCM2708_DMA_H
  16147. +#define _MACH_BCM2708_DMA_H
  16148. +
  16149. +#define BCM_DMAMAN_DRIVER_NAME "bcm2708_dma"
  16150. +
  16151. +/* DMA CS Control and Status bits */
  16152. +#define BCM2708_DMA_ACTIVE (1 << 0)
  16153. +#define BCM2708_DMA_INT (1 << 2)
  16154. +#define BCM2708_DMA_ISPAUSED (1 << 4) /* Pause requested or not active */
  16155. +#define BCM2708_DMA_ISHELD (1 << 5) /* Is held by DREQ flow control */
  16156. +#define BCM2708_DMA_ERR (1 << 8)
  16157. +#define BCM2708_DMA_ABORT (1 << 30) /* stop current CB, go to next, WO */
  16158. +#define BCM2708_DMA_RESET (1 << 31) /* WO, self clearing */
  16159. +
  16160. +/* DMA control block "info" field bits */
  16161. +#define BCM2708_DMA_INT_EN (1 << 0)
  16162. +#define BCM2708_DMA_TDMODE (1 << 1)
  16163. +#define BCM2708_DMA_WAIT_RESP (1 << 3)
  16164. +#define BCM2708_DMA_D_INC (1 << 4)
  16165. +#define BCM2708_DMA_D_WIDTH (1 << 5)
  16166. +#define BCM2708_DMA_D_DREQ (1 << 6)
  16167. +#define BCM2708_DMA_S_INC (1 << 8)
  16168. +#define BCM2708_DMA_S_WIDTH (1 << 9)
  16169. +#define BCM2708_DMA_S_DREQ (1 << 10)
  16170. +
  16171. +#define BCM2708_DMA_BURST(x) (((x)&0xf) << 12)
  16172. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  16173. +#define BCM2708_DMA_WAITS(x) (((x)&0x1f) << 21)
  16174. +
  16175. +#define BCM2708_DMA_DREQ_EMMC 11
  16176. +#define BCM2708_DMA_DREQ_SDHOST 13
  16177. +
  16178. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  16179. +#define BCM2708_DMA_ADDR 0x04
  16180. +/* the current control block appears in the following registers - read only */
  16181. +#define BCM2708_DMA_INFO 0x08
  16182. +#define BCM2708_DMA_SOURCE_AD 0x0c
  16183. +#define BCM2708_DMA_DEST_AD 0x10
  16184. +#define BCM2708_DMA_NEXTCB 0x1C
  16185. +#define BCM2708_DMA_DEBUG 0x20
  16186. +
  16187. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4)+BCM2708_DMA_CS)
  16188. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4)+BCM2708_DMA_ADDR)
  16189. +
  16190. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  16191. +
  16192. +struct bcm2708_dma_cb {
  16193. + unsigned long info;
  16194. + unsigned long src;
  16195. + unsigned long dst;
  16196. + unsigned long length;
  16197. + unsigned long stride;
  16198. + unsigned long next;
  16199. + unsigned long pad[2];
  16200. +};
  16201. +struct scatterlist;
  16202. +
  16203. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  16204. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  16205. + dma_addr_t control_block);
  16206. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  16207. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base);
  16208. +extern int /*rc*/ bcm_dma_abort(void __iomem *dma_chan_base);
  16209. +
  16210. +/* When listing features we can ask for when allocating DMA channels give
  16211. + those with higher priority smaller ordinal numbers */
  16212. +#define BCM_DMA_FEATURE_FAST_ORD 0
  16213. +#define BCM_DMA_FEATURE_BULK_ORD 1
  16214. +#define BCM_DMA_FEATURE_NORMAL_ORD 2
  16215. +#define BCM_DMA_FEATURE_LITE_ORD 3
  16216. +#define BCM_DMA_FEATURE_FAST (1<<BCM_DMA_FEATURE_FAST_ORD)
  16217. +#define BCM_DMA_FEATURE_BULK (1<<BCM_DMA_FEATURE_BULK_ORD)
  16218. +#define BCM_DMA_FEATURE_NORMAL (1<<BCM_DMA_FEATURE_NORMAL_ORD)
  16219. +#define BCM_DMA_FEATURE_LITE (1<<BCM_DMA_FEATURE_LITE_ORD)
  16220. +#define BCM_DMA_FEATURE_COUNT 4
  16221. +
  16222. +/* return channel no or -ve error */
  16223. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  16224. + void __iomem **out_dma_base, int *out_dma_irq);
  16225. +extern int bcm_dma_chan_free(int channel);
  16226. +
  16227. +
  16228. +#endif /* _MACH_BCM2708_DMA_H */
  16229. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/entry-macro.S linux-rpi/arch/arm/mach-bcm2709/include/mach/entry-macro.S
  16230. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/entry-macro.S 1970-01-01 01:00:00.000000000 +0100
  16231. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/entry-macro.S 2015-02-09 04:39:42.000000000 +0100
  16232. @@ -0,0 +1,120 @@
  16233. +/*
  16234. + * arch/arm/mach-bcm2708/include/mach/entry-macro.S
  16235. + *
  16236. + * Low-level IRQ helper macros for BCM2708 platforms
  16237. + *
  16238. + * Copyright (C) 2010 Broadcom
  16239. + *
  16240. + * This program is free software; you can redistribute it and/or modify
  16241. + * it under the terms of the GNU General Public License as published by
  16242. + * the Free Software Foundation; either version 2 of the License, or
  16243. + * (at your option) any later version.
  16244. + *
  16245. + * This program is distributed in the hope that it will be useful,
  16246. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16247. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16248. + * GNU General Public License for more details.
  16249. + *
  16250. + * You should have received a copy of the GNU General Public License
  16251. + * along with this program; if not, write to the Free Software
  16252. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16253. + */
  16254. +#include <mach/hardware.h>
  16255. +#include <mach/irqs.h>
  16256. +
  16257. + .macro arch_ret_to_user, tmp1, tmp2
  16258. + .endm
  16259. +
  16260. + .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
  16261. +
  16262. + /* get core number */
  16263. + mrc p15, 0, \base, c0, c0, 5
  16264. + ubfx \base, \base, #0, #2
  16265. +
  16266. + /* get core's local interrupt controller */
  16267. + ldr \irqstat, = __io_address(ARM_LOCAL_IRQ_PENDING0) @ local interrupt source
  16268. + add \irqstat, \irqstat, \base, lsl #2
  16269. + ldr \tmp, [\irqstat]
  16270. +
  16271. + /* test for mailbox0 (IPI) interrupt */
  16272. + tst \tmp, #0x10
  16273. + beq 1030f
  16274. +
  16275. + /* get core's mailbox interrupt control */
  16276. + ldr \irqstat, = __io_address(ARM_LOCAL_MAILBOX0_CLR0) @ mbox_clr
  16277. + add \irqstat, \irqstat, \base, lsl #4
  16278. + ldr \tmp, [\irqstat]
  16279. + clz \tmp, \tmp
  16280. + rsb \irqnr, \tmp, #31
  16281. + mov \tmp, #1
  16282. + lsl \tmp, \irqnr
  16283. + str \tmp, [\irqstat] @ clear interrupt source
  16284. + dsb
  16285. + mov r1, sp
  16286. + adr lr, BSYM(1b)
  16287. + b do_IPI
  16288. +
  16289. +1030:
  16290. + /* check gpu interrupt */
  16291. + tst \tmp, #0x100
  16292. + beq 1040f
  16293. +
  16294. + ldr \base, =IO_ADDRESS(ARMCTRL_IC_BASE)
  16295. + /* get masked status */
  16296. + ldr \irqstat, [\base, #(ARM_IRQ_PEND0 - ARMCTRL_IC_BASE)]
  16297. + mov \irqnr, #(ARM_IRQ0_BASE + 31)
  16298. + and \tmp, \irqstat, #0x300 @ save bits 8 and 9
  16299. + /* clear bits 8 and 9, and test */
  16300. + bics \irqstat, \irqstat, #0x300
  16301. + bne 1010f
  16302. +
  16303. + tst \tmp, #0x100
  16304. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND1 - ARMCTRL_IC_BASE)]
  16305. + movne \irqnr, #(ARM_IRQ1_BASE + 31)
  16306. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  16307. + bicne \irqstat, #((1<<7) | (1<<9) | (1<<10))
  16308. + bicne \irqstat, #((1<<18) | (1<<19))
  16309. + bne 1010f
  16310. +
  16311. + tst \tmp, #0x200
  16312. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND2 - ARMCTRL_IC_BASE)]
  16313. + movne \irqnr, #(ARM_IRQ2_BASE + 31)
  16314. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  16315. + bicne \irqstat, #((1<<21) | (1<<22) | (1<<23) | (1<<24) | (1<<25))
  16316. + bicne \irqstat, #((1<<30))
  16317. + beq 1020f
  16318. +1010:
  16319. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  16320. + sub \tmp, \irqstat, #1
  16321. + eor \irqstat, \irqstat, \tmp
  16322. + clz \tmp, \irqstat
  16323. + sub \irqnr, \tmp
  16324. + b 1050f
  16325. +1040:
  16326. + cmp \tmp, #0
  16327. + beq 1020f
  16328. +
  16329. + /* handle local (e.g. timer) interrupts */
  16330. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  16331. + mov \irqnr, #(ARM_IRQ_LOCAL_BASE + 31)
  16332. + sub \irqstat, \tmp, #1
  16333. + eor \irqstat, \irqstat, \tmp
  16334. + clz \tmp, \irqstat
  16335. + sub \irqnr, \tmp
  16336. +1050:
  16337. + mov r1, sp
  16338. + @
  16339. + @ routine called with r0 = irq number, r1 = struct pt_regs *
  16340. + @
  16341. + adr lr, BSYM(1b)
  16342. + b asm_do_IRQ
  16343. +
  16344. +1020: @ EQ will be set if no irqs pending
  16345. + .endm
  16346. +
  16347. +/*
  16348. + * Interrupt handling. Preserves r7, r8, r9
  16349. + */
  16350. + .macro arch_irq_handler_default
  16351. +1: get_irqnr_and_base r0, r2, r6, lr
  16352. + .endm
  16353. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/frc.h linux-rpi/arch/arm/mach-bcm2709/include/mach/frc.h
  16354. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/frc.h 1970-01-01 01:00:00.000000000 +0100
  16355. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/frc.h 2015-02-09 04:39:42.000000000 +0100
  16356. @@ -0,0 +1,38 @@
  16357. +/*
  16358. + * arch/arm/mach-bcm2708/include/mach/timex.h
  16359. + *
  16360. + * BCM2708 free running counter (timer)
  16361. + *
  16362. + * Copyright (C) 2010 Broadcom
  16363. + *
  16364. + * This program is free software; you can redistribute it and/or modify
  16365. + * it under the terms of the GNU General Public License as published by
  16366. + * the Free Software Foundation; either version 2 of the License, or
  16367. + * (at your option) any later version.
  16368. + *
  16369. + * This program is distributed in the hope that it will be useful,
  16370. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16371. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16372. + * GNU General Public License for more details.
  16373. + *
  16374. + * You should have received a copy of the GNU General Public License
  16375. + * along with this program; if not, write to the Free Software
  16376. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16377. + */
  16378. +
  16379. +#ifndef _MACH_FRC_H
  16380. +#define _MACH_FRC_H
  16381. +
  16382. +#define FRC_TICK_RATE (1000000)
  16383. +
  16384. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  16385. + (slightly faster than frc_clock_ticks63()
  16386. + */
  16387. +extern unsigned long frc_clock_ticks32(void);
  16388. +
  16389. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  16390. + * Note - top bit should be ignored (see cnt32_to_63)
  16391. + */
  16392. +extern unsigned long long frc_clock_ticks63(void);
  16393. +
  16394. +#endif
  16395. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/gpio.h linux-rpi/arch/arm/mach-bcm2709/include/mach/gpio.h
  16396. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/gpio.h 1970-01-01 01:00:00.000000000 +0100
  16397. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/gpio.h 2015-02-09 04:39:42.000000000 +0100
  16398. @@ -0,0 +1,17 @@
  16399. +/*
  16400. + * arch/arm/mach-bcm2708/include/mach/gpio.h
  16401. + *
  16402. + * This file is licensed under the terms of the GNU General Public
  16403. + * License version 2. This program is licensed "as is" without any
  16404. + * warranty of any kind, whether express or implied.
  16405. + */
  16406. +
  16407. +#ifndef __ASM_ARCH_GPIO_H
  16408. +#define __ASM_ARCH_GPIO_H
  16409. +
  16410. +#define BCM2708_NR_GPIOS 54 // number of gpio lines
  16411. +
  16412. +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
  16413. +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
  16414. +
  16415. +#endif
  16416. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/hardware.h linux-rpi/arch/arm/mach-bcm2709/include/mach/hardware.h
  16417. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/hardware.h 1970-01-01 01:00:00.000000000 +0100
  16418. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/hardware.h 2015-02-09 04:39:42.000000000 +0100
  16419. @@ -0,0 +1,28 @@
  16420. +/*
  16421. + * arch/arm/mach-bcm2708/include/mach/hardware.h
  16422. + *
  16423. + * This file contains the hardware definitions of the BCM2708 devices.
  16424. + *
  16425. + * Copyright (C) 2010 Broadcom
  16426. + *
  16427. + * This program is free software; you can redistribute it and/or modify
  16428. + * it under the terms of the GNU General Public License as published by
  16429. + * the Free Software Foundation; either version 2 of the License, or
  16430. + * (at your option) any later version.
  16431. + *
  16432. + * This program is distributed in the hope that it will be useful,
  16433. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16434. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16435. + * GNU General Public License for more details.
  16436. + *
  16437. + * You should have received a copy of the GNU General Public License
  16438. + * along with this program; if not, write to the Free Software
  16439. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16440. + */
  16441. +#ifndef __ASM_ARCH_HARDWARE_H
  16442. +#define __ASM_ARCH_HARDWARE_H
  16443. +
  16444. +#include <asm/sizes.h>
  16445. +#include <mach/platform.h>
  16446. +
  16447. +#endif
  16448. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/io.h linux-rpi/arch/arm/mach-bcm2709/include/mach/io.h
  16449. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/io.h 1970-01-01 01:00:00.000000000 +0100
  16450. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/io.h 2015-02-09 04:39:42.000000000 +0100
  16451. @@ -0,0 +1,27 @@
  16452. +/*
  16453. + * arch/arm/mach-bcm2708/include/mach/io.h
  16454. + *
  16455. + * Copyright (C) 2003 ARM Limited
  16456. + *
  16457. + * This program is free software; you can redistribute it and/or modify
  16458. + * it under the terms of the GNU General Public License as published by
  16459. + * the Free Software Foundation; either version 2 of the License, or
  16460. + * (at your option) any later version.
  16461. + *
  16462. + * This program is distributed in the hope that it will be useful,
  16463. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16464. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16465. + * GNU General Public License for more details.
  16466. + *
  16467. + * You should have received a copy of the GNU General Public License
  16468. + * along with this program; if not, write to the Free Software
  16469. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16470. + */
  16471. +#ifndef __ASM_ARM_ARCH_IO_H
  16472. +#define __ASM_ARM_ARCH_IO_H
  16473. +
  16474. +#define IO_SPACE_LIMIT 0xffffffff
  16475. +
  16476. +#define __io(a) __typesafe_io(a)
  16477. +
  16478. +#endif
  16479. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/irqs.h linux-rpi/arch/arm/mach-bcm2709/include/mach/irqs.h
  16480. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/irqs.h 1970-01-01 01:00:00.000000000 +0100
  16481. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/irqs.h 2015-02-09 04:39:42.000000000 +0100
  16482. @@ -0,0 +1,225 @@
  16483. +/*
  16484. + * arch/arm/mach-bcm2708/include/mach/irqs.h
  16485. + *
  16486. + * Copyright (C) 2010 Broadcom
  16487. + * Copyright (C) 2003 ARM Limited
  16488. + * Copyright (C) 2000 Deep Blue Solutions Ltd.
  16489. + *
  16490. + * This program is free software; you can redistribute it and/or modify
  16491. + * it under the terms of the GNU General Public License as published by
  16492. + * the Free Software Foundation; either version 2 of the License, or
  16493. + * (at your option) any later version.
  16494. + *
  16495. + * This program is distributed in the hope that it will be useful,
  16496. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16497. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16498. + * GNU General Public License for more details.
  16499. + *
  16500. + * You should have received a copy of the GNU General Public License
  16501. + * along with this program; if not, write to the Free Software
  16502. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16503. + */
  16504. +
  16505. +#ifndef _BCM2708_IRQS_H_
  16506. +#define _BCM2708_IRQS_H_
  16507. +
  16508. +#include <mach/platform.h>
  16509. +
  16510. +/*
  16511. + * IRQ interrupts definitions are the same as the INT definitions
  16512. + * held within platform.h
  16513. + */
  16514. +#define IRQ_ARMCTRL_START 0
  16515. +#define IRQ_TIMER0 (IRQ_ARMCTRL_START + INTERRUPT_TIMER0)
  16516. +#define IRQ_TIMER1 (IRQ_ARMCTRL_START + INTERRUPT_TIMER1)
  16517. +#define IRQ_TIMER2 (IRQ_ARMCTRL_START + INTERRUPT_TIMER2)
  16518. +#define IRQ_TIMER3 (IRQ_ARMCTRL_START + INTERRUPT_TIMER3)
  16519. +#define IRQ_CODEC0 (IRQ_ARMCTRL_START + INTERRUPT_CODEC0)
  16520. +#define IRQ_CODEC1 (IRQ_ARMCTRL_START + INTERRUPT_CODEC1)
  16521. +#define IRQ_CODEC2 (IRQ_ARMCTRL_START + INTERRUPT_CODEC2)
  16522. +#define IRQ_JPEG (IRQ_ARMCTRL_START + INTERRUPT_JPEG)
  16523. +#define IRQ_ISP (IRQ_ARMCTRL_START + INTERRUPT_ISP)
  16524. +#define IRQ_USB (IRQ_ARMCTRL_START + INTERRUPT_USB)
  16525. +#define IRQ_3D (IRQ_ARMCTRL_START + INTERRUPT_3D)
  16526. +#define IRQ_TRANSPOSER (IRQ_ARMCTRL_START + INTERRUPT_TRANSPOSER)
  16527. +#define IRQ_MULTICORESYNC0 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC0)
  16528. +#define IRQ_MULTICORESYNC1 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC1)
  16529. +#define IRQ_MULTICORESYNC2 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC2)
  16530. +#define IRQ_MULTICORESYNC3 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC3)
  16531. +#define IRQ_DMA0 (IRQ_ARMCTRL_START + INTERRUPT_DMA0)
  16532. +#define IRQ_DMA1 (IRQ_ARMCTRL_START + INTERRUPT_DMA1)
  16533. +#define IRQ_DMA2 (IRQ_ARMCTRL_START + INTERRUPT_DMA2)
  16534. +#define IRQ_DMA3 (IRQ_ARMCTRL_START + INTERRUPT_DMA3)
  16535. +#define IRQ_DMA4 (IRQ_ARMCTRL_START + INTERRUPT_DMA4)
  16536. +#define IRQ_DMA5 (IRQ_ARMCTRL_START + INTERRUPT_DMA5)
  16537. +#define IRQ_DMA6 (IRQ_ARMCTRL_START + INTERRUPT_DMA6)
  16538. +#define IRQ_DMA7 (IRQ_ARMCTRL_START + INTERRUPT_DMA7)
  16539. +#define IRQ_DMA8 (IRQ_ARMCTRL_START + INTERRUPT_DMA8)
  16540. +#define IRQ_DMA9 (IRQ_ARMCTRL_START + INTERRUPT_DMA9)
  16541. +#define IRQ_DMA10 (IRQ_ARMCTRL_START + INTERRUPT_DMA10)
  16542. +#define IRQ_DMA11 (IRQ_ARMCTRL_START + INTERRUPT_DMA11)
  16543. +#define IRQ_DMA12 (IRQ_ARMCTRL_START + INTERRUPT_DMA12)
  16544. +#define IRQ_AUX (IRQ_ARMCTRL_START + INTERRUPT_AUX)
  16545. +#define IRQ_ARM (IRQ_ARMCTRL_START + INTERRUPT_ARM)
  16546. +#define IRQ_VPUDMA (IRQ_ARMCTRL_START + INTERRUPT_VPUDMA)
  16547. +#define IRQ_HOSTPORT (IRQ_ARMCTRL_START + INTERRUPT_HOSTPORT)
  16548. +#define IRQ_VIDEOSCALER (IRQ_ARMCTRL_START + INTERRUPT_VIDEOSCALER)
  16549. +#define IRQ_CCP2TX (IRQ_ARMCTRL_START + INTERRUPT_CCP2TX)
  16550. +#define IRQ_SDC (IRQ_ARMCTRL_START + INTERRUPT_SDC)
  16551. +#define IRQ_DSI0 (IRQ_ARMCTRL_START + INTERRUPT_DSI0)
  16552. +#define IRQ_AVE (IRQ_ARMCTRL_START + INTERRUPT_AVE)
  16553. +#define IRQ_CAM0 (IRQ_ARMCTRL_START + INTERRUPT_CAM0)
  16554. +#define IRQ_CAM1 (IRQ_ARMCTRL_START + INTERRUPT_CAM1)
  16555. +#define IRQ_HDMI0 (IRQ_ARMCTRL_START + INTERRUPT_HDMI0)
  16556. +#define IRQ_HDMI1 (IRQ_ARMCTRL_START + INTERRUPT_HDMI1)
  16557. +#define IRQ_PIXELVALVE1 (IRQ_ARMCTRL_START + INTERRUPT_PIXELVALVE1)
  16558. +#define IRQ_I2CSPISLV (IRQ_ARMCTRL_START + INTERRUPT_I2CSPISLV)
  16559. +#define IRQ_DSI1 (IRQ_ARMCTRL_START + INTERRUPT_DSI1)
  16560. +#define IRQ_PWA0 (IRQ_ARMCTRL_START + INTERRUPT_PWA0)
  16561. +#define IRQ_PWA1 (IRQ_ARMCTRL_START + INTERRUPT_PWA1)
  16562. +#define IRQ_CPR (IRQ_ARMCTRL_START + INTERRUPT_CPR)
  16563. +#define IRQ_SMI (IRQ_ARMCTRL_START + INTERRUPT_SMI)
  16564. +#define IRQ_GPIO0 (IRQ_ARMCTRL_START + INTERRUPT_GPIO0)
  16565. +#define IRQ_GPIO1 (IRQ_ARMCTRL_START + INTERRUPT_GPIO1)
  16566. +#define IRQ_GPIO2 (IRQ_ARMCTRL_START + INTERRUPT_GPIO2)
  16567. +#define IRQ_GPIO3 (IRQ_ARMCTRL_START + INTERRUPT_GPIO3)
  16568. +#define IRQ_I2C (IRQ_ARMCTRL_START + INTERRUPT_I2C)
  16569. +#define IRQ_SPI (IRQ_ARMCTRL_START + INTERRUPT_SPI)
  16570. +#define IRQ_I2SPCM (IRQ_ARMCTRL_START + INTERRUPT_I2SPCM)
  16571. +#define IRQ_SDIO (IRQ_ARMCTRL_START + INTERRUPT_SDIO)
  16572. +#define IRQ_UART (IRQ_ARMCTRL_START + INTERRUPT_UART)
  16573. +#define IRQ_SLIMBUS (IRQ_ARMCTRL_START + INTERRUPT_SLIMBUS)
  16574. +#define IRQ_VEC (IRQ_ARMCTRL_START + INTERRUPT_VEC)
  16575. +#define IRQ_CPG (IRQ_ARMCTRL_START + INTERRUPT_CPG)
  16576. +#define IRQ_RNG (IRQ_ARMCTRL_START + INTERRUPT_RNG)
  16577. +#define IRQ_ARASANSDIO (IRQ_ARMCTRL_START + INTERRUPT_ARASANSDIO)
  16578. +#define IRQ_AVSPMON (IRQ_ARMCTRL_START + INTERRUPT_AVSPMON)
  16579. +
  16580. +#define IRQ_ARM_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_TIMER)
  16581. +#define IRQ_ARM_MAILBOX (IRQ_ARMCTRL_START + INTERRUPT_ARM_MAILBOX)
  16582. +#define IRQ_ARM_DOORBELL_0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_0)
  16583. +#define IRQ_ARM_DOORBELL_1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_1)
  16584. +#define IRQ_VPU0_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU0_HALTED)
  16585. +#define IRQ_VPU1_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU1_HALTED)
  16586. +#define IRQ_ILLEGAL_TYPE0 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE0)
  16587. +#define IRQ_ILLEGAL_TYPE1 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE1)
  16588. +#define IRQ_PENDING1 (IRQ_ARMCTRL_START + INTERRUPT_PENDING1)
  16589. +#define IRQ_PENDING2 (IRQ_ARMCTRL_START + INTERRUPT_PENDING2)
  16590. +
  16591. +#define IRQ_ARM_LOCAL_CNTPSIRQ (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTPSIRQ)
  16592. +#define IRQ_ARM_LOCAL_CNTPNSIRQ (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTPNSIRQ)
  16593. +#define IRQ_ARM_LOCAL_CNTHPIRQ (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTHPIRQ)
  16594. +#define IRQ_ARM_LOCAL_CNTVIRQ (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTVIRQ)
  16595. +#define IRQ_ARM_LOCAL_MAILBOX0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX0)
  16596. +#define IRQ_ARM_LOCAL_MAILBOX1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX1)
  16597. +#define IRQ_ARM_LOCAL_MAILBOX2 (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX2)
  16598. +#define IRQ_ARM_LOCAL_MAILBOX3 (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX3)
  16599. +#define IRQ_ARM_LOCAL_GPU_FAST (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_GPU_FAST)
  16600. +#define IRQ_ARM_LOCAL_PMU_FAST (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_PMU_FAST)
  16601. +#define IRQ_ARM_LOCAL_ZERO (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_ZERO)
  16602. +#define IRQ_ARM_LOCAL_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_TIMER)
  16603. +
  16604. +#define FIQ_START HARD_IRQS
  16605. +
  16606. +/*
  16607. + * FIQ interrupts definitions are the same as the INT definitions.
  16608. + */
  16609. +#define FIQ_TIMER0 (FIQ_START+INTERRUPT_TIMER0)
  16610. +#define FIQ_TIMER1 (FIQ_START+INTERRUPT_TIMER1)
  16611. +#define FIQ_TIMER2 (FIQ_START+INTERRUPT_TIMER2)
  16612. +#define FIQ_TIMER3 (FIQ_START+INTERRUPT_TIMER3)
  16613. +#define FIQ_CODEC0 (FIQ_START+INTERRUPT_CODEC0)
  16614. +#define FIQ_CODEC1 (FIQ_START+INTERRUPT_CODEC1)
  16615. +#define FIQ_CODEC2 (FIQ_START+INTERRUPT_CODEC2)
  16616. +#define FIQ_JPEG (FIQ_START+INTERRUPT_JPEG)
  16617. +#define FIQ_ISP (FIQ_START+INTERRUPT_ISP)
  16618. +#define FIQ_USB (FIQ_START+INTERRUPT_USB)
  16619. +#define FIQ_3D (FIQ_START+INTERRUPT_3D)
  16620. +#define FIQ_TRANSPOSER (FIQ_START+INTERRUPT_TRANSPOSER)
  16621. +#define FIQ_MULTICORESYNC0 (FIQ_START+INTERRUPT_MULTICORESYNC0)
  16622. +#define FIQ_MULTICORESYNC1 (FIQ_START+INTERRUPT_MULTICORESYNC1)
  16623. +#define FIQ_MULTICORESYNC2 (FIQ_START+INTERRUPT_MULTICORESYNC2)
  16624. +#define FIQ_MULTICORESYNC3 (FIQ_START+INTERRUPT_MULTICORESYNC3)
  16625. +#define FIQ_DMA0 (FIQ_START+INTERRUPT_DMA0)
  16626. +#define FIQ_DMA1 (FIQ_START+INTERRUPT_DMA1)
  16627. +#define FIQ_DMA2 (FIQ_START+INTERRUPT_DMA2)
  16628. +#define FIQ_DMA3 (FIQ_START+INTERRUPT_DMA3)
  16629. +#define FIQ_DMA4 (FIQ_START+INTERRUPT_DMA4)
  16630. +#define FIQ_DMA5 (FIQ_START+INTERRUPT_DMA5)
  16631. +#define FIQ_DMA6 (FIQ_START+INTERRUPT_DMA6)
  16632. +#define FIQ_DMA7 (FIQ_START+INTERRUPT_DMA7)
  16633. +#define FIQ_DMA8 (FIQ_START+INTERRUPT_DMA8)
  16634. +#define FIQ_DMA9 (FIQ_START+INTERRUPT_DMA9)
  16635. +#define FIQ_DMA10 (FIQ_START+INTERRUPT_DMA10)
  16636. +#define FIQ_DMA11 (FIQ_START+INTERRUPT_DMA11)
  16637. +#define FIQ_DMA12 (FIQ_START+INTERRUPT_DMA12)
  16638. +#define FIQ_AUX (FIQ_START+INTERRUPT_AUX)
  16639. +#define FIQ_ARM (FIQ_START+INTERRUPT_ARM)
  16640. +#define FIQ_VPUDMA (FIQ_START+INTERRUPT_VPUDMA)
  16641. +#define FIQ_HOSTPORT (FIQ_START+INTERRUPT_HOSTPORT)
  16642. +#define FIQ_VIDEOSCALER (FIQ_START+INTERRUPT_VIDEOSCALER)
  16643. +#define FIQ_CCP2TX (FIQ_START+INTERRUPT_CCP2TX)
  16644. +#define FIQ_SDC (FIQ_START+INTERRUPT_SDC)
  16645. +#define FIQ_DSI0 (FIQ_START+INTERRUPT_DSI0)
  16646. +#define FIQ_AVE (FIQ_START+INTERRUPT_AVE)
  16647. +#define FIQ_CAM0 (FIQ_START+INTERRUPT_CAM0)
  16648. +#define FIQ_CAM1 (FIQ_START+INTERRUPT_CAM1)
  16649. +#define FIQ_HDMI0 (FIQ_START+INTERRUPT_HDMI0)
  16650. +#define FIQ_HDMI1 (FIQ_START+INTERRUPT_HDMI1)
  16651. +#define FIQ_PIXELVALVE1 (FIQ_START+INTERRUPT_PIXELVALVE1)
  16652. +#define FIQ_I2CSPISLV (FIQ_START+INTERRUPT_I2CSPISLV)
  16653. +#define FIQ_DSI1 (FIQ_START+INTERRUPT_DSI1)
  16654. +#define FIQ_PWA0 (FIQ_START+INTERRUPT_PWA0)
  16655. +#define FIQ_PWA1 (FIQ_START+INTERRUPT_PWA1)
  16656. +#define FIQ_CPR (FIQ_START+INTERRUPT_CPR)
  16657. +#define FIQ_SMI (FIQ_START+INTERRUPT_SMI)
  16658. +#define FIQ_GPIO0 (FIQ_START+INTERRUPT_GPIO0)
  16659. +#define FIQ_GPIO1 (FIQ_START+INTERRUPT_GPIO1)
  16660. +#define FIQ_GPIO2 (FIQ_START+INTERRUPT_GPIO2)
  16661. +#define FIQ_GPIO3 (FIQ_START+INTERRUPT_GPIO3)
  16662. +#define FIQ_I2C (FIQ_START+INTERRUPT_I2C)
  16663. +#define FIQ_SPI (FIQ_START+INTERRUPT_SPI)
  16664. +#define FIQ_I2SPCM (FIQ_START+INTERRUPT_I2SPCM)
  16665. +#define FIQ_SDIO (FIQ_START+INTERRUPT_SDIO)
  16666. +#define FIQ_UART (FIQ_START+INTERRUPT_UART)
  16667. +#define FIQ_SLIMBUS (FIQ_START+INTERRUPT_SLIMBUS)
  16668. +#define FIQ_VEC (FIQ_START+INTERRUPT_VEC)
  16669. +#define FIQ_CPG (FIQ_START+INTERRUPT_CPG)
  16670. +#define FIQ_RNG (FIQ_START+INTERRUPT_RNG)
  16671. +#define FIQ_ARASANSDIO (FIQ_START+INTERRUPT_ARASANSDIO)
  16672. +#define FIQ_AVSPMON (FIQ_START+INTERRUPT_AVSPMON)
  16673. +
  16674. +#define FIQ_ARM_TIMER (FIQ_START+INTERRUPT_ARM_TIMER)
  16675. +#define FIQ_ARM_MAILBOX (FIQ_START+INTERRUPT_ARM_MAILBOX)
  16676. +#define FIQ_ARM_DOORBELL_0 (FIQ_START+INTERRUPT_ARM_DOORBELL_0)
  16677. +#define FIQ_ARM_DOORBELL_1 (FIQ_START+INTERRUPT_ARM_DOORBELL_1)
  16678. +#define FIQ_VPU0_HALTED (FIQ_START+INTERRUPT_VPU0_HALTED)
  16679. +#define FIQ_VPU1_HALTED (FIQ_START+INTERRUPT_VPU1_HALTED)
  16680. +#define FIQ_ILLEGAL_TYPE0 (FIQ_START+INTERRUPT_ILLEGAL_TYPE0)
  16681. +#define FIQ_ILLEGAL_TYPE1 (FIQ_START+INTERRUPT_ILLEGAL_TYPE1)
  16682. +#define FIQ_PENDING1 (FIQ_START+INTERRUPT_PENDING1)
  16683. +#define FIQ_PENDING2 (FIQ_START+INTERRUPT_PENDING2)
  16684. +
  16685. +#define FIQ_ARM_LOCAL_CNTPSIRQ (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTPSIRQ)
  16686. +#define FIQ_ARM_LOCAL_CNTPNSIRQ (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTPNSIRQ)
  16687. +#define FIQ_ARM_LOCAL_CNTHPIRQ (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTHPIRQ)
  16688. +#define FIQ_ARM_LOCAL_CNTVIRQ (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_CNTVIRQ)
  16689. +#define FIQ_ARM_LOCAL_MAILBOX0 (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX0)
  16690. +#define FIQ_ARM_LOCAL_MAILBOX1 (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX1)
  16691. +#define FIQ_ARM_LOCAL_MAILBOX2 (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX2)
  16692. +#define FIQ_ARM_LOCAL_MAILBOX3 (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_MAILBOX3)
  16693. +#define FIQ_ARM_LOCAL_GPU_FAST (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_GPU_FAST)
  16694. +#define FIQ_ARM_LOCAL_PMU_FAST (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_PMU_FAST)
  16695. +#define FIQ_ARM_LOCAL_ZERO (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_ZERO)
  16696. +#define FIQ_ARM_LOCAL_TIMER (FIQ_ARMCTRL_START + INTERRUPT_ARM_LOCAL_TIMER)
  16697. +
  16698. +#define HARD_IRQS (128)
  16699. +#define FIQ_IRQS (128)
  16700. +#define GPIO_IRQ_START (HARD_IRQS + FIQ_IRQS)
  16701. +#define GPIO_IRQS (32*5)
  16702. +#define SPARE_ALLOC_IRQS 32
  16703. +#define BCM2708_ALLOC_IRQS (HARD_IRQS+FIQ_IRQS+GPIO_IRQS+SPARE_ALLOC_IRQS)
  16704. +#define FREE_IRQS 32
  16705. +#define NR_IRQS (BCM2708_ALLOC_IRQS+FREE_IRQS)
  16706. +
  16707. +#endif /* _BCM2708_IRQS_H_ */
  16708. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/memory.h linux-rpi/arch/arm/mach-bcm2709/include/mach/memory.h
  16709. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/memory.h 1970-01-01 01:00:00.000000000 +0100
  16710. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/memory.h 2015-02-09 04:39:42.000000000 +0100
  16711. @@ -0,0 +1,57 @@
  16712. +/*
  16713. + * arch/arm/mach-bcm2708/include/mach/memory.h
  16714. + *
  16715. + * Copyright (C) 2010 Broadcom
  16716. + *
  16717. + * This program is free software; you can redistribute it and/or modify
  16718. + * it under the terms of the GNU General Public License as published by
  16719. + * the Free Software Foundation; either version 2 of the License, or
  16720. + * (at your option) any later version.
  16721. + *
  16722. + * This program is distributed in the hope that it will be useful,
  16723. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16724. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16725. + * GNU General Public License for more details.
  16726. + *
  16727. + * You should have received a copy of the GNU General Public License
  16728. + * along with this program; if not, write to the Free Software
  16729. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16730. + */
  16731. +#ifndef __ASM_ARCH_MEMORY_H
  16732. +#define __ASM_ARCH_MEMORY_H
  16733. +
  16734. +/* Memory overview:
  16735. +
  16736. + [ARMcore] <--virtual addr-->
  16737. + [ARMmmu] <--physical addr-->
  16738. + [GERTmap] <--bus add-->
  16739. + [VCperiph]
  16740. +
  16741. +*/
  16742. +
  16743. +/*
  16744. + * Physical DRAM offset.
  16745. + */
  16746. +#define BCM_PLAT_PHYS_OFFSET UL(0x00000000)
  16747. +#define VC_ARMMEM_OFFSET UL(0x00000000) /* offset in VC of ARM memory */
  16748. +
  16749. +#ifdef CONFIG_BCM2708_NOL2CACHE
  16750. + #define _REAL_BUS_OFFSET UL(0xC0000000) /* don't use L1 or L2 caches */
  16751. +#else
  16752. + #define _REAL_BUS_OFFSET UL(0x40000000) /* use L2 cache */
  16753. +#endif
  16754. +
  16755. +/* We're using the memory at 64M in the VideoCore for Linux - this adjustment
  16756. + * will provide the offset into this area as well as setting the bits that
  16757. + * stop the L1 and L2 cache from being used
  16758. + *
  16759. + * WARNING: this only works because the ARM is given memory at a fixed location
  16760. + * (ARMMEM_OFFSET)
  16761. + */
  16762. +#define BUS_OFFSET (VC_ARMMEM_OFFSET + _REAL_BUS_OFFSET)
  16763. +#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
  16764. +#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
  16765. +#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - BCM_PLAT_PHYS_OFFSET))
  16766. +#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - BCM_PLAT_PHYS_OFFSET))
  16767. +
  16768. +#endif
  16769. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/platform.h linux-rpi/arch/arm/mach-bcm2709/include/mach/platform.h
  16770. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/platform.h 1970-01-01 01:00:00.000000000 +0100
  16771. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/platform.h 2015-02-09 04:39:42.000000000 +0100
  16772. @@ -0,0 +1,225 @@
  16773. +/*
  16774. + * arch/arm/mach-bcm2708/include/mach/platform.h
  16775. + *
  16776. + * Copyright (C) 2010 Broadcom
  16777. + *
  16778. + * This program is free software; you can redistribute it and/or modify
  16779. + * it under the terms of the GNU General Public License as published by
  16780. + * the Free Software Foundation; either version 2 of the License, or
  16781. + * (at your option) any later version.
  16782. + *
  16783. + * This program is distributed in the hope that it will be useful,
  16784. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16785. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16786. + * GNU General Public License for more details.
  16787. + *
  16788. + * You should have received a copy of the GNU General Public License
  16789. + * along with this program; if not, write to the Free Software
  16790. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16791. + */
  16792. +
  16793. +#ifndef _BCM2708_PLATFORM_H
  16794. +#define _BCM2708_PLATFORM_H
  16795. +
  16796. +
  16797. +/* macros to get at IO space when running virtually */
  16798. +#define IO_ADDRESS(x) (((x) & 0x00ffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  16799. +
  16800. +#define __io_address(n) IOMEM(IO_ADDRESS(n))
  16801. +
  16802. +
  16803. +/*
  16804. + * SDRAM
  16805. + */
  16806. +#define BCM2708_SDRAM_BASE 0x00000000
  16807. +
  16808. +/*
  16809. + * Logic expansion modules
  16810. + *
  16811. + */
  16812. +
  16813. +
  16814. +/* ------------------------------------------------------------------------
  16815. + * BCM2708 ARMCTRL Registers
  16816. + * ------------------------------------------------------------------------
  16817. + */
  16818. +
  16819. +#define HW_REGISTER_RW(addr) (addr)
  16820. +#define HW_REGISTER_RO(addr) (addr)
  16821. +
  16822. +#include "arm_control.h"
  16823. +#undef ARM_BASE
  16824. +
  16825. +/*
  16826. + * Definitions and addresses for the ARM CONTROL logic
  16827. + * This file is manually generated.
  16828. + */
  16829. +
  16830. +#define BCM2708_PERI_BASE 0x3F000000
  16831. +#define IC0_BASE (BCM2708_PERI_BASE + 0x2000)
  16832. +#define ST_BASE (BCM2708_PERI_BASE + 0x3000) /* System Timer */
  16833. +#define MPHI_BASE (BCM2708_PERI_BASE + 0x6000) /* Message -based Parallel Host Interface */
  16834. +#define DMA_BASE (BCM2708_PERI_BASE + 0x7000) /* DMA controller */
  16835. +#define ARM_BASE (BCM2708_PERI_BASE + 0xB000) /* BCM2708 ARM control block */
  16836. +#define PM_BASE (BCM2708_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */
  16837. +#define PCM_CLOCK_BASE (BCM2708_PERI_BASE + 0x101098) /* PCM Clock */
  16838. +#define RNG_BASE (BCM2708_PERI_BASE + 0x104000) /* Hardware RNG */
  16839. +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO */
  16840. +#define UART0_BASE (BCM2708_PERI_BASE + 0x201000) /* Uart 0 */
  16841. +#define MMCI0_BASE (BCM2708_PERI_BASE + 0x202000) /* MMC interface */
  16842. +#define I2S_BASE (BCM2708_PERI_BASE + 0x203000) /* I2S */
  16843. +#define SPI0_BASE (BCM2708_PERI_BASE + 0x204000) /* SPI0 */
  16844. +#define BSC0_BASE (BCM2708_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */
  16845. +#define UART1_BASE (BCM2708_PERI_BASE + 0x215000) /* Uart 1 */
  16846. +#define EMMC_BASE (BCM2708_PERI_BASE + 0x300000) /* eMMC interface */
  16847. +#define SMI_BASE (BCM2708_PERI_BASE + 0x600000) /* SMI */
  16848. +#define BSC1_BASE (BCM2708_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */
  16849. +#define USB_BASE (BCM2708_PERI_BASE + 0x980000) /* DTC_OTG USB controller */
  16850. +#define MCORE_BASE (BCM2708_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/
  16851. +
  16852. +#define ARMCTRL_BASE (ARM_BASE + 0x000)
  16853. +#define ARMCTRL_IC_BASE (ARM_BASE + 0x200) /* ARM interrupt controller */
  16854. +#define ARMCTRL_TIMER0_1_BASE (ARM_BASE + 0x400) /* Timer 0 and 1 */
  16855. +#define ARMCTRL_0_SBM_BASE (ARM_BASE + 0x800) /* User 0 (ARM)'s Semaphores Doorbells and Mailboxes */
  16856. +
  16857. +
  16858. +/*
  16859. + * Interrupt assignments
  16860. + */
  16861. +
  16862. +#define ARM_IRQ1_BASE 0
  16863. +#define INTERRUPT_TIMER0 (ARM_IRQ1_BASE + 0)
  16864. +#define INTERRUPT_TIMER1 (ARM_IRQ1_BASE + 1)
  16865. +#define INTERRUPT_TIMER2 (ARM_IRQ1_BASE + 2)
  16866. +#define INTERRUPT_TIMER3 (ARM_IRQ1_BASE + 3)
  16867. +#define INTERRUPT_CODEC0 (ARM_IRQ1_BASE + 4)
  16868. +#define INTERRUPT_CODEC1 (ARM_IRQ1_BASE + 5)
  16869. +#define INTERRUPT_CODEC2 (ARM_IRQ1_BASE + 6)
  16870. +#define INTERRUPT_VC_JPEG (ARM_IRQ1_BASE + 7)
  16871. +#define INTERRUPT_ISP (ARM_IRQ1_BASE + 8)
  16872. +#define INTERRUPT_VC_USB (ARM_IRQ1_BASE + 9)
  16873. +#define INTERRUPT_VC_3D (ARM_IRQ1_BASE + 10)
  16874. +#define INTERRUPT_TRANSPOSER (ARM_IRQ1_BASE + 11)
  16875. +#define INTERRUPT_MULTICORESYNC0 (ARM_IRQ1_BASE + 12)
  16876. +#define INTERRUPT_MULTICORESYNC1 (ARM_IRQ1_BASE + 13)
  16877. +#define INTERRUPT_MULTICORESYNC2 (ARM_IRQ1_BASE + 14)
  16878. +#define INTERRUPT_MULTICORESYNC3 (ARM_IRQ1_BASE + 15)
  16879. +#define INTERRUPT_DMA0 (ARM_IRQ1_BASE + 16)
  16880. +#define INTERRUPT_DMA1 (ARM_IRQ1_BASE + 17)
  16881. +#define INTERRUPT_VC_DMA2 (ARM_IRQ1_BASE + 18)
  16882. +#define INTERRUPT_VC_DMA3 (ARM_IRQ1_BASE + 19)
  16883. +#define INTERRUPT_DMA4 (ARM_IRQ1_BASE + 20)
  16884. +#define INTERRUPT_DMA5 (ARM_IRQ1_BASE + 21)
  16885. +#define INTERRUPT_DMA6 (ARM_IRQ1_BASE + 22)
  16886. +#define INTERRUPT_DMA7 (ARM_IRQ1_BASE + 23)
  16887. +#define INTERRUPT_DMA8 (ARM_IRQ1_BASE + 24)
  16888. +#define INTERRUPT_DMA9 (ARM_IRQ1_BASE + 25)
  16889. +#define INTERRUPT_DMA10 (ARM_IRQ1_BASE + 26)
  16890. +#define INTERRUPT_DMA11 (ARM_IRQ1_BASE + 27)
  16891. +#define INTERRUPT_DMA12 (ARM_IRQ1_BASE + 28)
  16892. +#define INTERRUPT_AUX (ARM_IRQ1_BASE + 29)
  16893. +#define INTERRUPT_ARM (ARM_IRQ1_BASE + 30)
  16894. +#define INTERRUPT_VPUDMA (ARM_IRQ1_BASE + 31)
  16895. +
  16896. +#define ARM_IRQ2_BASE 32
  16897. +#define INTERRUPT_HOSTPORT (ARM_IRQ2_BASE + 0)
  16898. +#define INTERRUPT_VIDEOSCALER (ARM_IRQ2_BASE + 1)
  16899. +#define INTERRUPT_CCP2TX (ARM_IRQ2_BASE + 2)
  16900. +#define INTERRUPT_SDC (ARM_IRQ2_BASE + 3)
  16901. +#define INTERRUPT_DSI0 (ARM_IRQ2_BASE + 4)
  16902. +#define INTERRUPT_AVE (ARM_IRQ2_BASE + 5)
  16903. +#define INTERRUPT_CAM0 (ARM_IRQ2_BASE + 6)
  16904. +#define INTERRUPT_CAM1 (ARM_IRQ2_BASE + 7)
  16905. +#define INTERRUPT_HDMI0 (ARM_IRQ2_BASE + 8)
  16906. +#define INTERRUPT_HDMI1 (ARM_IRQ2_BASE + 9)
  16907. +#define INTERRUPT_PIXELVALVE1 (ARM_IRQ2_BASE + 10)
  16908. +#define INTERRUPT_I2CSPISLV (ARM_IRQ2_BASE + 11)
  16909. +#define INTERRUPT_DSI1 (ARM_IRQ2_BASE + 12)
  16910. +#define INTERRUPT_PWA0 (ARM_IRQ2_BASE + 13)
  16911. +#define INTERRUPT_PWA1 (ARM_IRQ2_BASE + 14)
  16912. +#define INTERRUPT_CPR (ARM_IRQ2_BASE + 15)
  16913. +#define INTERRUPT_SMI (ARM_IRQ2_BASE + 16)
  16914. +#define INTERRUPT_GPIO0 (ARM_IRQ2_BASE + 17)
  16915. +#define INTERRUPT_GPIO1 (ARM_IRQ2_BASE + 18)
  16916. +#define INTERRUPT_GPIO2 (ARM_IRQ2_BASE + 19)
  16917. +#define INTERRUPT_GPIO3 (ARM_IRQ2_BASE + 20)
  16918. +#define INTERRUPT_VC_I2C (ARM_IRQ2_BASE + 21)
  16919. +#define INTERRUPT_VC_SPI (ARM_IRQ2_BASE + 22)
  16920. +#define INTERRUPT_VC_I2SPCM (ARM_IRQ2_BASE + 23)
  16921. +#define INTERRUPT_VC_SDIO (ARM_IRQ2_BASE + 24)
  16922. +#define INTERRUPT_VC_UART (ARM_IRQ2_BASE + 25)
  16923. +#define INTERRUPT_SLIMBUS (ARM_IRQ2_BASE + 26)
  16924. +#define INTERRUPT_VEC (ARM_IRQ2_BASE + 27)
  16925. +#define INTERRUPT_CPG (ARM_IRQ2_BASE + 28)
  16926. +#define INTERRUPT_RNG (ARM_IRQ2_BASE + 29)
  16927. +#define INTERRUPT_VC_ARASANSDIO (ARM_IRQ2_BASE + 30)
  16928. +#define INTERRUPT_AVSPMON (ARM_IRQ2_BASE + 31)
  16929. +
  16930. +#define ARM_IRQ0_BASE 64
  16931. +#define INTERRUPT_ARM_TIMER (ARM_IRQ0_BASE + 0)
  16932. +#define INTERRUPT_ARM_MAILBOX (ARM_IRQ0_BASE + 1)
  16933. +#define INTERRUPT_ARM_DOORBELL_0 (ARM_IRQ0_BASE + 2)
  16934. +#define INTERRUPT_ARM_DOORBELL_1 (ARM_IRQ0_BASE + 3)
  16935. +#define INTERRUPT_VPU0_HALTED (ARM_IRQ0_BASE + 4)
  16936. +#define INTERRUPT_VPU1_HALTED (ARM_IRQ0_BASE + 5)
  16937. +#define INTERRUPT_ILLEGAL_TYPE0 (ARM_IRQ0_BASE + 6)
  16938. +#define INTERRUPT_ILLEGAL_TYPE1 (ARM_IRQ0_BASE + 7)
  16939. +#define INTERRUPT_PENDING1 (ARM_IRQ0_BASE + 8)
  16940. +#define INTERRUPT_PENDING2 (ARM_IRQ0_BASE + 9)
  16941. +#define INTERRUPT_JPEG (ARM_IRQ0_BASE + 10)
  16942. +#define INTERRUPT_USB (ARM_IRQ0_BASE + 11)
  16943. +#define INTERRUPT_3D (ARM_IRQ0_BASE + 12)
  16944. +#define INTERRUPT_DMA2 (ARM_IRQ0_BASE + 13)
  16945. +#define INTERRUPT_DMA3 (ARM_IRQ0_BASE + 14)
  16946. +#define INTERRUPT_I2C (ARM_IRQ0_BASE + 15)
  16947. +#define INTERRUPT_SPI (ARM_IRQ0_BASE + 16)
  16948. +#define INTERRUPT_I2SPCM (ARM_IRQ0_BASE + 17)
  16949. +#define INTERRUPT_SDIO (ARM_IRQ0_BASE + 18)
  16950. +#define INTERRUPT_UART (ARM_IRQ0_BASE + 19)
  16951. +#define INTERRUPT_ARASANSDIO (ARM_IRQ0_BASE + 20)
  16952. +
  16953. +#define ARM_IRQ_LOCAL_BASE 96
  16954. +#define INTERRUPT_ARM_LOCAL_CNTPSIRQ (ARM_IRQ_LOCAL_BASE + 0)
  16955. +#define INTERRUPT_ARM_LOCAL_CNTPNSIRQ (ARM_IRQ_LOCAL_BASE + 1)
  16956. +#define INTERRUPT_ARM_LOCAL_CNTHPIRQ (ARM_IRQ_LOCAL_BASE + 2)
  16957. +#define INTERRUPT_ARM_LOCAL_CNTVIRQ (ARM_IRQ_LOCAL_BASE + 3)
  16958. +#define INTERRUPT_ARM_LOCAL_MAILBOX0 (ARM_IRQ_LOCAL_BASE + 4)
  16959. +#define INTERRUPT_ARM_LOCAL_MAILBOX1 (ARM_IRQ_LOCAL_BASE + 5)
  16960. +#define INTERRUPT_ARM_LOCAL_MAILBOX2 (ARM_IRQ_LOCAL_BASE + 6)
  16961. +#define INTERRUPT_ARM_LOCAL_MAILBOX3 (ARM_IRQ_LOCAL_BASE + 7)
  16962. +#define INTERRUPT_ARM_LOCAL_GPU_FAST (ARM_IRQ_LOCAL_BASE + 8)
  16963. +#define INTERRUPT_ARM_LOCAL_PMU_FAST (ARM_IRQ_LOCAL_BASE + 9)
  16964. +#define INTERRUPT_ARM_LOCAL_ZERO (ARM_IRQ_LOCAL_BASE + 10)
  16965. +#define INTERRUPT_ARM_LOCAL_TIMER (ARM_IRQ_LOCAL_BASE + 11)
  16966. +
  16967. +/*
  16968. + * Watchdog
  16969. + */
  16970. +#define PM_RSTC (PM_BASE+0x1c)
  16971. +#define PM_RSTS (PM_BASE+0x20)
  16972. +#define PM_WDOG (PM_BASE+0x24)
  16973. +
  16974. +#define PM_WDOG_RESET 0000000000
  16975. +#define PM_PASSWORD 0x5a000000
  16976. +#define PM_WDOG_TIME_SET 0x000fffff
  16977. +#define PM_RSTC_WRCFG_CLR 0xffffffcf
  16978. +#define PM_RSTC_WRCFG_SET 0x00000030
  16979. +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  16980. +#define PM_RSTC_RESET 0x00000102
  16981. +
  16982. +#define PM_RSTS_HADPOR_SET 0x00001000
  16983. +#define PM_RSTS_HADSRH_SET 0x00000400
  16984. +#define PM_RSTS_HADSRF_SET 0x00000200
  16985. +#define PM_RSTS_HADSRQ_SET 0x00000100
  16986. +#define PM_RSTS_HADWRH_SET 0x00000040
  16987. +#define PM_RSTS_HADWRF_SET 0x00000020
  16988. +#define PM_RSTS_HADWRQ_SET 0x00000010
  16989. +#define PM_RSTS_HADDRH_SET 0x00000004
  16990. +#define PM_RSTS_HADDRF_SET 0x00000002
  16991. +#define PM_RSTS_HADDRQ_SET 0x00000001
  16992. +
  16993. +#define UART0_CLOCK 3000000
  16994. +
  16995. +#endif
  16996. +
  16997. +/* END */
  16998. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/power.h linux-rpi/arch/arm/mach-bcm2709/include/mach/power.h
  16999. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/power.h 1970-01-01 01:00:00.000000000 +0100
  17000. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/power.h 2015-02-09 04:39:42.000000000 +0100
  17001. @@ -0,0 +1,26 @@
  17002. +/*
  17003. + * linux/arch/arm/mach-bcm2708/power.h
  17004. + *
  17005. + * Copyright (C) 2010 Broadcom
  17006. + *
  17007. + * This program is free software; you can redistribute it and/or modify
  17008. + * it under the terms of the GNU General Public License version 2 as
  17009. + * published by the Free Software Foundation.
  17010. + *
  17011. + * This device provides a shared mechanism for controlling the power to
  17012. + * VideoCore subsystems.
  17013. + */
  17014. +
  17015. +#ifndef _MACH_BCM2708_POWER_H
  17016. +#define _MACH_BCM2708_POWER_H
  17017. +
  17018. +#include <linux/types.h>
  17019. +#include <mach/arm_power.h>
  17020. +
  17021. +typedef unsigned int BCM_POWER_HANDLE_T;
  17022. +
  17023. +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle);
  17024. +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request);
  17025. +extern int bcm_power_close(BCM_POWER_HANDLE_T handle);
  17026. +
  17027. +#endif
  17028. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/system.h linux-rpi/arch/arm/mach-bcm2709/include/mach/system.h
  17029. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/system.h 1970-01-01 01:00:00.000000000 +0100
  17030. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/system.h 2015-02-09 04:39:42.000000000 +0100
  17031. @@ -0,0 +1,38 @@
  17032. +/*
  17033. + * arch/arm/mach-bcm2708/include/mach/system.h
  17034. + *
  17035. + * Copyright (C) 2010 Broadcom
  17036. + * Copyright (C) 2003 ARM Limited
  17037. + * Copyright (C) 2000 Deep Blue Solutions Ltd
  17038. + *
  17039. + * This program is free software; you can redistribute it and/or modify
  17040. + * it under the terms of the GNU General Public License as published by
  17041. + * the Free Software Foundation; either version 2 of the License, or
  17042. + * (at your option) any later version.
  17043. + *
  17044. + * This program is distributed in the hope that it will be useful,
  17045. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17046. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17047. + * GNU General Public License for more details.
  17048. + *
  17049. + * You should have received a copy of the GNU General Public License
  17050. + * along with this program; if not, write to the Free Software
  17051. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17052. + */
  17053. +#ifndef __ASM_ARCH_SYSTEM_H
  17054. +#define __ASM_ARCH_SYSTEM_H
  17055. +
  17056. +#include <linux/io.h>
  17057. +#include <mach/hardware.h>
  17058. +#include <mach/platform.h>
  17059. +
  17060. +static inline void arch_idle(void)
  17061. +{
  17062. + /*
  17063. + * This should do all the clock switching
  17064. + * and wait for interrupt tricks
  17065. + */
  17066. + cpu_do_idle();
  17067. +}
  17068. +
  17069. +#endif
  17070. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/timex.h linux-rpi/arch/arm/mach-bcm2709/include/mach/timex.h
  17071. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/timex.h 1970-01-01 01:00:00.000000000 +0100
  17072. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/timex.h 2015-02-09 04:39:42.000000000 +0100
  17073. @@ -0,0 +1,23 @@
  17074. +/*
  17075. + * arch/arm/mach-bcm2708/include/mach/timex.h
  17076. + *
  17077. + * BCM2708 sysem clock frequency
  17078. + *
  17079. + * Copyright (C) 2010 Broadcom
  17080. + *
  17081. + * This program is free software; you can redistribute it and/or modify
  17082. + * it under the terms of the GNU General Public License as published by
  17083. + * the Free Software Foundation; either version 2 of the License, or
  17084. + * (at your option) any later version.
  17085. + *
  17086. + * This program is distributed in the hope that it will be useful,
  17087. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17088. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17089. + * GNU General Public License for more details.
  17090. + *
  17091. + * You should have received a copy of the GNU General Public License
  17092. + * along with this program; if not, write to the Free Software
  17093. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17094. + */
  17095. +
  17096. +#define CLOCK_TICK_RATE (1000000)
  17097. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/uncompress.h linux-rpi/arch/arm/mach-bcm2709/include/mach/uncompress.h
  17098. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/uncompress.h 1970-01-01 01:00:00.000000000 +0100
  17099. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/uncompress.h 2015-02-09 04:39:42.000000000 +0100
  17100. @@ -0,0 +1,84 @@
  17101. +/*
  17102. + * arch/arm/mach-bcn2708/include/mach/uncompress.h
  17103. + *
  17104. + * Copyright (C) 2010 Broadcom
  17105. + * Copyright (C) 2003 ARM Limited
  17106. + *
  17107. + * This program is free software; you can redistribute it and/or modify
  17108. + * it under the terms of the GNU General Public License as published by
  17109. + * the Free Software Foundation; either version 2 of the License, or
  17110. + * (at your option) any later version.
  17111. + *
  17112. + * This program is distributed in the hope that it will be useful,
  17113. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17114. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17115. + * GNU General Public License for more details.
  17116. + *
  17117. + * You should have received a copy of the GNU General Public License
  17118. + * along with this program; if not, write to the Free Software
  17119. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17120. + */
  17121. +
  17122. +#include <linux/io.h>
  17123. +#include <linux/amba/serial.h>
  17124. +#include <mach/hardware.h>
  17125. +
  17126. +#define UART_BAUD 115200
  17127. +
  17128. +#define BCM2708_UART_DR __io(UART0_BASE + UART01x_DR)
  17129. +#define BCM2708_UART_FR __io(UART0_BASE + UART01x_FR)
  17130. +#define BCM2708_UART_IBRD __io(UART0_BASE + UART011_IBRD)
  17131. +#define BCM2708_UART_FBRD __io(UART0_BASE + UART011_FBRD)
  17132. +#define BCM2708_UART_LCRH __io(UART0_BASE + UART011_LCRH)
  17133. +#define BCM2708_UART_CR __io(UART0_BASE + UART011_CR)
  17134. +
  17135. +/*
  17136. + * This does not append a newline
  17137. + */
  17138. +static inline void putc(int c)
  17139. +{
  17140. + while (__raw_readl(BCM2708_UART_FR) & UART01x_FR_TXFF)
  17141. + barrier();
  17142. +
  17143. + __raw_writel(c, BCM2708_UART_DR);
  17144. +}
  17145. +
  17146. +static inline void flush(void)
  17147. +{
  17148. + int fr;
  17149. +
  17150. + do {
  17151. + fr = __raw_readl(BCM2708_UART_FR);
  17152. + barrier();
  17153. + } while ((fr & (UART011_FR_TXFE | UART01x_FR_BUSY)) != UART011_FR_TXFE);
  17154. +}
  17155. +
  17156. +static inline void arch_decomp_setup(void)
  17157. +{
  17158. + int temp, div, rem, frac;
  17159. +
  17160. + temp = 16 * UART_BAUD;
  17161. + div = UART0_CLOCK / temp;
  17162. + rem = UART0_CLOCK % temp;
  17163. + temp = (8 * rem) / UART_BAUD;
  17164. + frac = (temp >> 1) + (temp & 1);
  17165. +
  17166. + /* Make sure the UART is disabled before we start */
  17167. + __raw_writel(0, BCM2708_UART_CR);
  17168. +
  17169. + /* Set the baud rate */
  17170. + __raw_writel(div, BCM2708_UART_IBRD);
  17171. + __raw_writel(frac, BCM2708_UART_FBRD);
  17172. +
  17173. + /* Set the UART to 8n1, FIFO enabled */
  17174. + __raw_writel(UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN, BCM2708_UART_LCRH);
  17175. +
  17176. + /* Enable the UART */
  17177. + __raw_writel(UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE,
  17178. + BCM2708_UART_CR);
  17179. +}
  17180. +
  17181. +/*
  17182. + * nothing to do
  17183. + */
  17184. +#define arch_decomp_wdog()
  17185. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/vcio.h linux-rpi/arch/arm/mach-bcm2709/include/mach/vcio.h
  17186. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/vcio.h 1970-01-01 01:00:00.000000000 +0100
  17187. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/vcio.h 2015-02-09 04:39:42.000000000 +0100
  17188. @@ -0,0 +1,165 @@
  17189. +/*
  17190. + * arch/arm/mach-bcm2708/include/mach/vcio.h
  17191. + *
  17192. + * Copyright (C) 2010 Broadcom
  17193. + *
  17194. + * This program is free software; you can redistribute it and/or modify
  17195. + * it under the terms of the GNU General Public License as published by
  17196. + * the Free Software Foundation; either version 2 of the License, or
  17197. + * (at your option) any later version.
  17198. + *
  17199. + * This program is distributed in the hope that it will be useful,
  17200. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17201. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17202. + * GNU General Public License for more details.
  17203. + *
  17204. + * You should have received a copy of the GNU General Public License
  17205. + * along with this program; if not, write to the Free Software
  17206. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17207. + */
  17208. +#ifndef _MACH_BCM2708_VCIO_H
  17209. +#define _MACH_BCM2708_VCIO_H
  17210. +
  17211. +/* Routines to handle I/O via the VideoCore "ARM control" registers
  17212. + * (semaphores, doorbells, mailboxes)
  17213. + */
  17214. +
  17215. +#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
  17216. +
  17217. +/* Constants shared with the ARM identifying separate mailbox channels */
  17218. +#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
  17219. +#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
  17220. +#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
  17221. +#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
  17222. +#define MBOX_CHAN_COUNT 9
  17223. +
  17224. +enum {
  17225. + VCMSG_PROCESS_REQUEST = 0x00000000
  17226. +};
  17227. +enum {
  17228. + VCMSG_REQUEST_SUCCESSFUL = 0x80000000,
  17229. + VCMSG_REQUEST_FAILED = 0x80000001
  17230. +};
  17231. +/* Mailbox property tags */
  17232. +enum {
  17233. + VCMSG_PROPERTY_END = 0x00000000,
  17234. + VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
  17235. + VCMSG_GET_BOARD_MODEL = 0x00010001,
  17236. + VCMSG_GET_BOARD_REVISION = 0x00010002,
  17237. + VCMSG_GET_BOARD_MAC_ADDRESS = 0x00010003,
  17238. + VCMSG_GET_BOARD_SERIAL = 0x00010004,
  17239. + VCMSG_GET_ARM_MEMORY = 0x00010005,
  17240. + VCMSG_GET_VC_MEMORY = 0x00010006,
  17241. + VCMSG_GET_CLOCKS = 0x00010007,
  17242. + VCMSG_GET_COMMAND_LINE = 0x00050001,
  17243. + VCMSG_GET_DMA_CHANNELS = 0x00060001,
  17244. + VCMSG_GET_POWER_STATE = 0x00020001,
  17245. + VCMSG_GET_TIMING = 0x00020002,
  17246. + VCMSG_SET_POWER_STATE = 0x00028001,
  17247. + VCMSG_GET_CLOCK_STATE = 0x00030001,
  17248. + VCMSG_SET_CLOCK_STATE = 0x00038001,
  17249. + VCMSG_GET_CLOCK_RATE = 0x00030002,
  17250. + VCMSG_SET_CLOCK_RATE = 0x00038002,
  17251. + VCMSG_GET_VOLTAGE = 0x00030003,
  17252. + VCMSG_SET_VOLTAGE = 0x00038003,
  17253. + VCMSG_GET_MAX_CLOCK = 0x00030004,
  17254. + VCMSG_GET_MAX_VOLTAGE = 0x00030005,
  17255. + VCMSG_GET_TEMPERATURE = 0x00030006,
  17256. + VCMSG_GET_MIN_CLOCK = 0x00030007,
  17257. + VCMSG_GET_MIN_VOLTAGE = 0x00030008,
  17258. + VCMSG_GET_TURBO = 0x00030009,
  17259. + VCMSG_GET_MAX_TEMPERATURE = 0x0003000a,
  17260. + VCMSG_GET_STC = 0x0003000b,
  17261. + VCMSG_SET_TURBO = 0x00038009,
  17262. + VCMSG_SET_ALLOCATE_MEM = 0x0003000c,
  17263. + VCMSG_SET_LOCK_MEM = 0x0003000d,
  17264. + VCMSG_SET_UNLOCK_MEM = 0x0003000e,
  17265. + VCMSG_SET_RELEASE_MEM = 0x0003000f,
  17266. + VCMSG_SET_EXECUTE_CODE = 0x00030010,
  17267. + VCMSG_SET_EXECUTE_QPU = 0x00030011,
  17268. + VCMSG_SET_ENABLE_QPU = 0x00030012,
  17269. + VCMSG_GET_RESOURCE_HANDLE = 0x00030014,
  17270. + VCMSG_GET_EDID_BLOCK = 0x00030020,
  17271. + VCMSG_GET_CUSTOMER_OTP = 0x00030021,
  17272. + VCMSG_SET_CUSTOMER_OTP = 0x00038021,
  17273. + VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
  17274. + VCMSG_SET_RELEASE_BUFFER = 0x00048001,
  17275. + VCMSG_SET_BLANK_SCREEN = 0x00040002,
  17276. + VCMSG_TST_BLANK_SCREEN = 0x00044002,
  17277. + VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
  17278. + VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
  17279. + VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
  17280. + VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
  17281. + VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
  17282. + VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
  17283. + VCMSG_GET_DEPTH = 0x00040005,
  17284. + VCMSG_TST_DEPTH = 0x00044005,
  17285. + VCMSG_SET_DEPTH = 0x00048005,
  17286. + VCMSG_GET_PIXEL_ORDER = 0x00040006,
  17287. + VCMSG_TST_PIXEL_ORDER = 0x00044006,
  17288. + VCMSG_SET_PIXEL_ORDER = 0x00048006,
  17289. + VCMSG_GET_ALPHA_MODE = 0x00040007,
  17290. + VCMSG_TST_ALPHA_MODE = 0x00044007,
  17291. + VCMSG_SET_ALPHA_MODE = 0x00048007,
  17292. + VCMSG_GET_PITCH = 0x00040008,
  17293. + VCMSG_TST_PITCH = 0x00044008,
  17294. + VCMSG_SET_PITCH = 0x00048008,
  17295. + VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
  17296. + VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
  17297. + VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
  17298. + VCMSG_GET_OVERSCAN = 0x0004000a,
  17299. + VCMSG_TST_OVERSCAN = 0x0004400a,
  17300. + VCMSG_SET_OVERSCAN = 0x0004800a,
  17301. + VCMSG_GET_PALETTE = 0x0004000b,
  17302. + VCMSG_TST_PALETTE = 0x0004400b,
  17303. + VCMSG_SET_PALETTE = 0x0004800b,
  17304. + VCMSG_GET_LAYER = 0x0004000c,
  17305. + VCMSG_TST_LAYER = 0x0004400c,
  17306. + VCMSG_SET_LAYER = 0x0004800c,
  17307. + VCMSG_GET_TRANSFORM = 0x0004000d,
  17308. + VCMSG_TST_TRANSFORM = 0x0004400d,
  17309. + VCMSG_SET_TRANSFORM = 0x0004800d,
  17310. + VCMSG_TST_VSYNC = 0x0004400e,
  17311. + VCMSG_SET_VSYNC = 0x0004800e,
  17312. + VCMSG_SET_CURSOR_INFO = 0x00008010,
  17313. + VCMSG_SET_CURSOR_STATE = 0x00008011,
  17314. +};
  17315. +
  17316. +extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
  17317. +extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
  17318. +extern int /*rc*/ bcm_mailbox_property(void *data, int size);
  17319. +
  17320. +#include <linux/ioctl.h>
  17321. +
  17322. +/*
  17323. + * The major device number. We can't rely on dynamic
  17324. + * registration any more, because ioctls need to know
  17325. + * it.
  17326. + */
  17327. +#define MAJOR_NUM 100
  17328. +
  17329. +/*
  17330. + * Set the message of the device driver
  17331. + */
  17332. +#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  17333. +/*
  17334. + * _IOWR means that we're creating an ioctl command
  17335. + * number for passing information from a user process
  17336. + * to the kernel module and from the kernel module to user process
  17337. + *
  17338. + * The first arguments, MAJOR_NUM, is the major device
  17339. + * number we're using.
  17340. + *
  17341. + * The second argument is the number of the command
  17342. + * (there could be several with different meanings).
  17343. + *
  17344. + * The third argument is the type we want to get from
  17345. + * the process to the kernel.
  17346. + */
  17347. +
  17348. +/*
  17349. + * The name of the device file
  17350. + */
  17351. +#define DEVICE_FILE_NAME "vcio"
  17352. +
  17353. +#endif
  17354. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/vc_mem.h linux-rpi/arch/arm/mach-bcm2709/include/mach/vc_mem.h
  17355. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/vc_mem.h 1970-01-01 01:00:00.000000000 +0100
  17356. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/vc_mem.h 2015-02-09 04:39:42.000000000 +0100
  17357. @@ -0,0 +1,35 @@
  17358. +/*****************************************************************************
  17359. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  17360. +*
  17361. +* Unless you and Broadcom execute a separate written software license
  17362. +* agreement governing use of this software, this software is licensed to you
  17363. +* under the terms of the GNU General Public License version 2, available at
  17364. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  17365. +*
  17366. +* Notwithstanding the above, under no circumstances may you combine this
  17367. +* software in any way with any other Broadcom software provided under a
  17368. +* license other than the GPL, without Broadcom's express prior written
  17369. +* consent.
  17370. +*****************************************************************************/
  17371. +
  17372. +#if !defined( VC_MEM_H )
  17373. +#define VC_MEM_H
  17374. +
  17375. +#include <linux/ioctl.h>
  17376. +
  17377. +#define VC_MEM_IOC_MAGIC 'v'
  17378. +
  17379. +#define VC_MEM_IOC_MEM_PHYS_ADDR _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
  17380. +#define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
  17381. +#define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
  17382. +#define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
  17383. +
  17384. +#if defined( __KERNEL__ )
  17385. +#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
  17386. +
  17387. +extern unsigned long mm_vc_mem_phys_addr;
  17388. +extern unsigned int mm_vc_mem_size;
  17389. +extern int vc_mem_get_current_size( void );
  17390. +#endif
  17391. +
  17392. +#endif /* VC_MEM_H */
  17393. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/vc_support.h linux-rpi/arch/arm/mach-bcm2709/include/mach/vc_support.h
  17394. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/vc_support.h 1970-01-01 01:00:00.000000000 +0100
  17395. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/vc_support.h 2015-02-09 04:39:42.000000000 +0100
  17396. @@ -0,0 +1,69 @@
  17397. +#ifndef _VC_SUPPORT_H_
  17398. +#define _VC_SUPPORT_H_
  17399. +
  17400. +/*
  17401. + * vc_support.h
  17402. + *
  17403. + * Created on: 25 Nov 2012
  17404. + * Author: Simon
  17405. + */
  17406. +
  17407. +enum {
  17408. +/*
  17409. + If a MEM_HANDLE_T is discardable, the memory manager may resize it to size
  17410. + 0 at any time when it is not locked or retained.
  17411. + */
  17412. + MEM_FLAG_DISCARDABLE = 1 << 0,
  17413. +
  17414. + /*
  17415. + If a MEM_HANDLE_T is allocating (or normal), its block of memory will be
  17416. + accessed in an allocating fashion through the cache.
  17417. + */
  17418. + MEM_FLAG_NORMAL = 0 << 2,
  17419. + MEM_FLAG_ALLOCATING = MEM_FLAG_NORMAL,
  17420. +
  17421. + /*
  17422. + If a MEM_HANDLE_T is direct, its block of memory will be accessed
  17423. + directly, bypassing the cache.
  17424. + */
  17425. + MEM_FLAG_DIRECT = 1 << 2,
  17426. +
  17427. + /*
  17428. + If a MEM_HANDLE_T is coherent, its block of memory will be accessed in a
  17429. + non-allocating fashion through the cache.
  17430. + */
  17431. + MEM_FLAG_COHERENT = 2 << 2,
  17432. +
  17433. + /*
  17434. + If a MEM_HANDLE_T is L1-nonallocating, its block of memory will be accessed by
  17435. + the VPU in a fashion which is allocating in L2, but only coherent in L1.
  17436. + */
  17437. + MEM_FLAG_L1_NONALLOCATING = (MEM_FLAG_DIRECT | MEM_FLAG_COHERENT),
  17438. +
  17439. + /*
  17440. + If a MEM_HANDLE_T is zero'd, its contents are set to 0 rather than
  17441. + MEM_HANDLE_INVALID on allocation and resize up.
  17442. + */
  17443. + MEM_FLAG_ZERO = 1 << 4,
  17444. +
  17445. + /*
  17446. + If a MEM_HANDLE_T is uninitialised, it will not be reset to a defined value
  17447. + (either zero, or all 1's) on allocation.
  17448. + */
  17449. + MEM_FLAG_NO_INIT = 1 << 5,
  17450. +
  17451. + /*
  17452. + Hints.
  17453. + */
  17454. + MEM_FLAG_HINT_PERMALOCK = 1 << 6, /* Likely to be locked for long periods of time. */
  17455. +};
  17456. +
  17457. +unsigned int AllocateVcMemory(unsigned int *pHandle, unsigned int size, unsigned int alignment, unsigned int flags);
  17458. +unsigned int ReleaseVcMemory(unsigned int handle);
  17459. +unsigned int LockVcMemory(unsigned int *pBusAddress, unsigned int handle);
  17460. +unsigned int UnlockVcMemory(unsigned int handle);
  17461. +
  17462. +unsigned int ExecuteVcCode(unsigned int code,
  17463. + unsigned int r0, unsigned int r1, unsigned int r2, unsigned int r3, unsigned int r4, unsigned int r5);
  17464. +
  17465. +#endif
  17466. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/include/mach/vmalloc.h linux-rpi/arch/arm/mach-bcm2709/include/mach/vmalloc.h
  17467. --- linux-3.18.6/arch/arm/mach-bcm2709/include/mach/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
  17468. +++ linux-rpi/arch/arm/mach-bcm2709/include/mach/vmalloc.h 2015-02-09 04:39:42.000000000 +0100
  17469. @@ -0,0 +1,20 @@
  17470. +/*
  17471. + * arch/arm/mach-bcm2708/include/mach/vmalloc.h
  17472. + *
  17473. + * Copyright (C) 2010 Broadcom
  17474. + *
  17475. + * This program is free software; you can redistribute it and/or modify
  17476. + * it under the terms of the GNU General Public License as published by
  17477. + * the Free Software Foundation; either version 2 of the License, or
  17478. + * (at your option) any later version.
  17479. + *
  17480. + * This program is distributed in the hope that it will be useful,
  17481. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17482. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17483. + * GNU General Public License for more details.
  17484. + *
  17485. + * You should have received a copy of the GNU General Public License
  17486. + * along with this program; if not, write to the Free Software
  17487. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17488. + */
  17489. +#define VMALLOC_END (0xff000000)
  17490. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/Kconfig linux-rpi/arch/arm/mach-bcm2709/Kconfig
  17491. --- linux-3.18.6/arch/arm/mach-bcm2709/Kconfig 1970-01-01 01:00:00.000000000 +0100
  17492. +++ linux-rpi/arch/arm/mach-bcm2709/Kconfig 2015-02-09 04:39:42.000000000 +0100
  17493. @@ -0,0 +1,49 @@
  17494. +menu "Broadcom BCM2709 Implementations"
  17495. + depends on ARCH_BCM2709
  17496. +
  17497. +config MACH_BCM2709
  17498. + bool "Broadcom BCM2709 Development Platform"
  17499. + help
  17500. + Include support for the Broadcom(R) BCM2709 platform.
  17501. +
  17502. +config BCM2709_DT
  17503. + bool "BCM2709 Device Tree support"
  17504. + depends on MACH_BCM2709
  17505. + default n
  17506. + select USE_OF
  17507. + select ARCH_REQUIRE_GPIOLIB
  17508. + select PINCTRL
  17509. + select PINCTRL_BCM2835
  17510. + help
  17511. + Enable Device Tree support for BCM2709
  17512. +
  17513. +config BCM2708_GPIO
  17514. + bool "BCM2709 gpio support"
  17515. + depends on MACH_BCM2709
  17516. + select ARCH_REQUIRE_GPIOLIB
  17517. + default y
  17518. + help
  17519. + Include support for the Broadcom(R) BCM2709 gpio.
  17520. +
  17521. +config BCM2708_VCMEM
  17522. + bool "Videocore Memory"
  17523. + depends on MACH_BCM2709
  17524. + default y
  17525. + help
  17526. + Helper for videocore memory access and total size allocation.
  17527. +
  17528. +config BCM2708_NOL2CACHE
  17529. + bool "Videocore L2 cache disable"
  17530. + depends on MACH_BCM2709
  17531. + default y
  17532. + help
  17533. + Do not allow ARM to use GPU's L2 cache. Requires disable_l2cache in config.txt.
  17534. +
  17535. +config BCM2708_SPIDEV
  17536. + bool "Bind spidev to SPI0 master"
  17537. + depends on MACH_BCM2709
  17538. + depends on SPI
  17539. + default y
  17540. + help
  17541. + Binds spidev driver to the SPI0 master
  17542. +endmenu
  17543. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/Makefile linux-rpi/arch/arm/mach-bcm2709/Makefile
  17544. --- linux-3.18.6/arch/arm/mach-bcm2709/Makefile 1970-01-01 01:00:00.000000000 +0100
  17545. +++ linux-rpi/arch/arm/mach-bcm2709/Makefile 2015-02-09 04:39:42.000000000 +0100
  17546. @@ -0,0 +1,7 @@
  17547. +#
  17548. +# Makefile for the linux kernel.
  17549. +#
  17550. +
  17551. +obj-$(CONFIG_MACH_BCM2709) += bcm2709.o armctrl.o vcio.o power.o dma.o
  17552. +obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
  17553. +obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
  17554. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/Makefile.boot linux-rpi/arch/arm/mach-bcm2709/Makefile.boot
  17555. --- linux-3.18.6/arch/arm/mach-bcm2709/Makefile.boot 1970-01-01 01:00:00.000000000 +0100
  17556. +++ linux-rpi/arch/arm/mach-bcm2709/Makefile.boot 2015-02-09 04:39:42.000000000 +0100
  17557. @@ -0,0 +1,3 @@
  17558. + zreladdr-y := 0x00008000
  17559. +params_phys-y := 0x00000100
  17560. +initrd_phys-y := 0x00800000
  17561. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/power.c linux-rpi/arch/arm/mach-bcm2709/power.c
  17562. --- linux-3.18.6/arch/arm/mach-bcm2709/power.c 1970-01-01 01:00:00.000000000 +0100
  17563. +++ linux-rpi/arch/arm/mach-bcm2709/power.c 2015-02-09 04:39:42.000000000 +0100
  17564. @@ -0,0 +1,195 @@
  17565. +/*
  17566. + * linux/arch/arm/mach-bcm2708/power.c
  17567. + *
  17568. + * Copyright (C) 2010 Broadcom
  17569. + *
  17570. + * This program is free software; you can redistribute it and/or modify
  17571. + * it under the terms of the GNU General Public License version 2 as
  17572. + * published by the Free Software Foundation.
  17573. + *
  17574. + * This device provides a shared mechanism for controlling the power to
  17575. + * VideoCore subsystems.
  17576. + */
  17577. +
  17578. +#include <linux/module.h>
  17579. +#include <linux/semaphore.h>
  17580. +#include <linux/bug.h>
  17581. +#include <mach/power.h>
  17582. +#include <mach/vcio.h>
  17583. +#include <mach/arm_power.h>
  17584. +
  17585. +#define DRIVER_NAME "bcm2708_power"
  17586. +
  17587. +#define BCM_POWER_MAXCLIENTS 4
  17588. +#define BCM_POWER_NOCLIENT (1<<31)
  17589. +
  17590. +/* Some drivers expect there devices to be permanently powered */
  17591. +#ifdef CONFIG_USB
  17592. +#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB)
  17593. +#endif
  17594. +
  17595. +#if 1
  17596. +#define DPRINTK printk
  17597. +#else
  17598. +#define DPRINTK if (0) printk
  17599. +#endif
  17600. +
  17601. +struct state_struct {
  17602. + uint32_t global_request;
  17603. + uint32_t client_request[BCM_POWER_MAXCLIENTS];
  17604. + struct semaphore client_mutex;
  17605. + struct semaphore mutex;
  17606. +} g_state;
  17607. +
  17608. +int bcm_power_open(BCM_POWER_HANDLE_T *handle)
  17609. +{
  17610. + BCM_POWER_HANDLE_T i;
  17611. + int ret = -EBUSY;
  17612. +
  17613. + down(&g_state.client_mutex);
  17614. +
  17615. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  17616. + if (g_state.client_request[i] == BCM_POWER_NOCLIENT) {
  17617. + g_state.client_request[i] = BCM_POWER_NONE;
  17618. + *handle = i;
  17619. + ret = 0;
  17620. + break;
  17621. + }
  17622. + }
  17623. +
  17624. + up(&g_state.client_mutex);
  17625. +
  17626. + DPRINTK("bcm_power_open() -> %d\n", *handle);
  17627. +
  17628. + return ret;
  17629. +}
  17630. +EXPORT_SYMBOL_GPL(bcm_power_open);
  17631. +
  17632. +int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
  17633. +{
  17634. + int rc = 0;
  17635. +
  17636. + DPRINTK("bcm_power_request(%d, %x)\n", handle, request);
  17637. +
  17638. + if ((handle < BCM_POWER_MAXCLIENTS) &&
  17639. + (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) {
  17640. + if (down_interruptible(&g_state.mutex) != 0) {
  17641. + DPRINTK("bcm_power_request -> interrupted\n");
  17642. + return -EINTR;
  17643. + }
  17644. +
  17645. + if (request != g_state.client_request[handle]) {
  17646. + uint32_t others_request = 0;
  17647. + uint32_t global_request;
  17648. + BCM_POWER_HANDLE_T i;
  17649. +
  17650. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  17651. + if (i != handle)
  17652. + others_request |=
  17653. + g_state.client_request[i];
  17654. + }
  17655. + others_request &= ~BCM_POWER_NOCLIENT;
  17656. +
  17657. + global_request = request | others_request;
  17658. + if (global_request != g_state.global_request) {
  17659. + uint32_t actual;
  17660. +
  17661. + /* Send a request to VideoCore */
  17662. + bcm_mailbox_write(MBOX_CHAN_POWER,
  17663. + global_request << 4);
  17664. +
  17665. + /* Wait for a response during power-up */
  17666. + if (global_request & ~g_state.global_request) {
  17667. + rc = bcm_mailbox_read(MBOX_CHAN_POWER,
  17668. + &actual);
  17669. + DPRINTK
  17670. + ("bcm_mailbox_read -> %08x, %d\n",
  17671. + actual, rc);
  17672. + actual >>= 4;
  17673. + } else {
  17674. + rc = 0;
  17675. + actual = global_request;
  17676. + }
  17677. +
  17678. + if (rc == 0) {
  17679. + if (actual != global_request) {
  17680. + printk(KERN_ERR
  17681. + "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n",
  17682. + __func__,
  17683. + g_state.global_request,
  17684. + global_request, actual, request, others_request);
  17685. + /* A failure */
  17686. + BUG_ON((others_request & actual)
  17687. + != others_request);
  17688. + request &= actual;
  17689. + rc = -EIO;
  17690. + }
  17691. +
  17692. + g_state.global_request = actual;
  17693. + g_state.client_request[handle] =
  17694. + request;
  17695. + }
  17696. + }
  17697. + }
  17698. + up(&g_state.mutex);
  17699. + } else {
  17700. + rc = -EINVAL;
  17701. + }
  17702. + DPRINTK("bcm_power_request -> %d\n", rc);
  17703. + return rc;
  17704. +}
  17705. +EXPORT_SYMBOL_GPL(bcm_power_request);
  17706. +
  17707. +int bcm_power_close(BCM_POWER_HANDLE_T handle)
  17708. +{
  17709. + int rc;
  17710. +
  17711. + DPRINTK("bcm_power_close(%d)\n", handle);
  17712. +
  17713. + rc = bcm_power_request(handle, BCM_POWER_NONE);
  17714. + if (rc == 0)
  17715. + g_state.client_request[handle] = BCM_POWER_NOCLIENT;
  17716. +
  17717. + return rc;
  17718. +}
  17719. +EXPORT_SYMBOL_GPL(bcm_power_close);
  17720. +
  17721. +static int __init bcm_power_init(void)
  17722. +{
  17723. +#if defined(BCM_POWER_ALWAYS_ON)
  17724. + BCM_POWER_HANDLE_T always_on_handle;
  17725. +#endif
  17726. + int rc = 0;
  17727. + int i;
  17728. +
  17729. + printk(KERN_INFO "bcm_power: Broadcom power driver\n");
  17730. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  17731. +
  17732. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++)
  17733. + g_state.client_request[i] = BCM_POWER_NOCLIENT;
  17734. +
  17735. + sema_init(&g_state.client_mutex, 1);
  17736. + sema_init(&g_state.mutex, 1);
  17737. +
  17738. + g_state.global_request = 0;
  17739. +#if defined(BCM_POWER_ALWAYS_ON)
  17740. + if (BCM_POWER_ALWAYS_ON) {
  17741. + bcm_power_open(&always_on_handle);
  17742. + bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON);
  17743. + }
  17744. +#endif
  17745. +
  17746. + return rc;
  17747. +}
  17748. +
  17749. +static void __exit bcm_power_exit(void)
  17750. +{
  17751. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  17752. +}
  17753. +
  17754. +arch_initcall(bcm_power_init); /* Initialize early */
  17755. +module_exit(bcm_power_exit);
  17756. +
  17757. +MODULE_AUTHOR("Phil Elwell");
  17758. +MODULE_DESCRIPTION("Interface to BCM2708 power management");
  17759. +MODULE_LICENSE("GPL");
  17760. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/vcio.c linux-rpi/arch/arm/mach-bcm2709/vcio.c
  17761. --- linux-3.18.6/arch/arm/mach-bcm2709/vcio.c 1970-01-01 01:00:00.000000000 +0100
  17762. +++ linux-rpi/arch/arm/mach-bcm2709/vcio.c 2015-02-09 04:39:42.000000000 +0100
  17763. @@ -0,0 +1,484 @@
  17764. +/*
  17765. + * linux/arch/arm/mach-bcm2708/vcio.c
  17766. + *
  17767. + * Copyright (C) 2010 Broadcom
  17768. + *
  17769. + * This program is free software; you can redistribute it and/or modify
  17770. + * it under the terms of the GNU General Public License version 2 as
  17771. + * published by the Free Software Foundation.
  17772. + *
  17773. + * This device provides a shared mechanism for writing to the mailboxes,
  17774. + * semaphores, doorbells etc. that are shared between the ARM and the
  17775. + * VideoCore processor
  17776. + */
  17777. +
  17778. +#if defined(CONFIG_SERIAL_BCM_MBOX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  17779. +#define SUPPORT_SYSRQ
  17780. +#endif
  17781. +
  17782. +#include <linux/module.h>
  17783. +#include <linux/console.h>
  17784. +#include <linux/serial_core.h>
  17785. +#include <linux/serial.h>
  17786. +#include <linux/errno.h>
  17787. +#include <linux/device.h>
  17788. +#include <linux/init.h>
  17789. +#include <linux/mm.h>
  17790. +#include <linux/dma-mapping.h>
  17791. +#include <linux/platform_device.h>
  17792. +#include <linux/sysrq.h>
  17793. +#include <linux/delay.h>
  17794. +#include <linux/slab.h>
  17795. +#include <linux/interrupt.h>
  17796. +#include <linux/irq.h>
  17797. +
  17798. +#include <linux/io.h>
  17799. +
  17800. +#include <mach/vcio.h>
  17801. +#include <mach/platform.h>
  17802. +
  17803. +#include <asm/uaccess.h>
  17804. +
  17805. +
  17806. +#define DRIVER_NAME BCM_VCIO_DRIVER_NAME
  17807. +
  17808. +/* ----------------------------------------------------------------------
  17809. + * Mailbox
  17810. + * -------------------------------------------------------------------- */
  17811. +
  17812. +/* offsets from a mail box base address */
  17813. +#define MAIL_WRT 0x00 /* write - and next 4 words */
  17814. +#define MAIL_RD 0x00 /* read - and next 4 words */
  17815. +#define MAIL_POL 0x10 /* read without popping the fifo */
  17816. +#define MAIL_SND 0x14 /* sender ID (bottom two bits) */
  17817. +#define MAIL_STA 0x18 /* status */
  17818. +#define MAIL_CNF 0x1C /* configuration */
  17819. +
  17820. +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
  17821. +#define MBOX_MSG_LSB(chan, data28) (((data28) << 4) | ((chan) & 0xf))
  17822. +#define MBOX_CHAN(msg) ((msg) & 0xf)
  17823. +#define MBOX_DATA28(msg) ((msg) & ~0xf)
  17824. +#define MBOX_DATA28_LSB(msg) (((uint32_t)msg) >> 4)
  17825. +
  17826. +#define MBOX_MAGIC 0xd0d0c0de
  17827. +static struct class *vcio_class = NULL;
  17828. +struct vc_mailbox {
  17829. + struct device *dev; /* parent device */
  17830. + void __iomem *status;
  17831. + void __iomem *config;
  17832. + void __iomem *read;
  17833. + void __iomem *write;
  17834. + uint32_t msg[MBOX_CHAN_COUNT];
  17835. + struct semaphore sema[MBOX_CHAN_COUNT];
  17836. + uint32_t magic;
  17837. +};
  17838. +
  17839. +static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
  17840. + uint32_t addr_mbox)
  17841. +{
  17842. + int i;
  17843. +
  17844. + mbox_out->dev = dev;
  17845. + mbox_out->status = __io_address(addr_mbox + MAIL_STA);
  17846. + mbox_out->config = __io_address(addr_mbox + MAIL_CNF);
  17847. + mbox_out->read = __io_address(addr_mbox + MAIL_RD);
  17848. + /* Write to the other mailbox */
  17849. + mbox_out->write =
  17850. + __io_address((addr_mbox ^ ARM_0_MAIL0_WRT ^ ARM_0_MAIL1_WRT) +
  17851. + MAIL_WRT);
  17852. +
  17853. + for (i = 0; i < MBOX_CHAN_COUNT; i++) {
  17854. + mbox_out->msg[i] = 0;
  17855. + sema_init(&mbox_out->sema[i], 0);
  17856. + }
  17857. +
  17858. + /* Enable the interrupt on data reception */
  17859. + writel(ARM_MC_IHAVEDATAIRQEN, mbox_out->config);
  17860. +
  17861. + mbox_out->magic = MBOX_MAGIC;
  17862. +}
  17863. +
  17864. +static int mbox_write(struct vc_mailbox *mbox, unsigned chan, uint32_t data28)
  17865. +{
  17866. + int rc;
  17867. +
  17868. + if (mbox->magic != MBOX_MAGIC)
  17869. + rc = -EINVAL;
  17870. + else {
  17871. + /* wait for the mailbox FIFO to have some space in it */
  17872. + while (0 != (readl(mbox->status) & ARM_MS_FULL))
  17873. + cpu_relax();
  17874. +
  17875. + writel(MBOX_MSG(chan, data28), mbox->write);
  17876. + rc = 0;
  17877. + }
  17878. + return rc;
  17879. +}
  17880. +
  17881. +static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
  17882. +{
  17883. + int rc;
  17884. +
  17885. + if (mbox->magic != MBOX_MAGIC)
  17886. + rc = -EINVAL;
  17887. + else {
  17888. + down(&mbox->sema[chan]);
  17889. + *data28 = MBOX_DATA28(mbox->msg[chan]);
  17890. + mbox->msg[chan] = 0;
  17891. + rc = 0;
  17892. + }
  17893. + return rc;
  17894. +}
  17895. +
  17896. +static irqreturn_t mbox_irq(int irq, void *dev_id)
  17897. +{
  17898. + /* wait for the mailbox FIFO to have some data in it */
  17899. + struct vc_mailbox *mbox = (struct vc_mailbox *) dev_id;
  17900. + int status = readl(mbox->status);
  17901. + int ret = IRQ_NONE;
  17902. +
  17903. + while (!(status & ARM_MS_EMPTY)) {
  17904. + uint32_t msg = readl(mbox->read);
  17905. + int chan = MBOX_CHAN(msg);
  17906. + if (chan < MBOX_CHAN_COUNT) {
  17907. + if (mbox->msg[chan]) {
  17908. + /* Overflow */
  17909. + printk(KERN_ERR DRIVER_NAME
  17910. + ": mbox chan %d overflow - drop %08x\n",
  17911. + chan, msg);
  17912. + } else {
  17913. + mbox->msg[chan] = (msg | 0xf);
  17914. + up(&mbox->sema[chan]);
  17915. + }
  17916. + } else {
  17917. + printk(KERN_ERR DRIVER_NAME
  17918. + ": invalid channel selector (msg %08x)\n", msg);
  17919. + }
  17920. + ret = IRQ_HANDLED;
  17921. + status = readl(mbox->status);
  17922. + }
  17923. + return ret;
  17924. +}
  17925. +
  17926. +static struct irqaction mbox_irqaction = {
  17927. + .name = "ARM Mailbox IRQ",
  17928. + .flags = IRQF_DISABLED | IRQF_IRQPOLL,
  17929. + .handler = mbox_irq,
  17930. +};
  17931. +
  17932. +/* ----------------------------------------------------------------------
  17933. + * Mailbox Methods
  17934. + * -------------------------------------------------------------------- */
  17935. +
  17936. +static struct device *mbox_dev; /* we assume there's only one! */
  17937. +
  17938. +static int dev_mbox_write(struct device *dev, unsigned chan, uint32_t data28)
  17939. +{
  17940. + int rc;
  17941. +
  17942. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  17943. + device_lock(dev);
  17944. + rc = mbox_write(mailbox, chan, data28);
  17945. + device_unlock(dev);
  17946. +
  17947. + return rc;
  17948. +}
  17949. +
  17950. +static int dev_mbox_read(struct device *dev, unsigned chan, uint32_t *data28)
  17951. +{
  17952. + int rc;
  17953. +
  17954. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  17955. + device_lock(dev);
  17956. + rc = mbox_read(mailbox, chan, data28);
  17957. + device_unlock(dev);
  17958. +
  17959. + return rc;
  17960. +}
  17961. +
  17962. +extern int bcm_mailbox_write(unsigned chan, uint32_t data28)
  17963. +{
  17964. + if (mbox_dev)
  17965. + return dev_mbox_write(mbox_dev, chan, data28);
  17966. + else
  17967. + return -ENODEV;
  17968. +}
  17969. +EXPORT_SYMBOL_GPL(bcm_mailbox_write);
  17970. +
  17971. +extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
  17972. +{
  17973. + if (mbox_dev)
  17974. + return dev_mbox_read(mbox_dev, chan, data28);
  17975. + else
  17976. + return -ENODEV;
  17977. +}
  17978. +EXPORT_SYMBOL_GPL(bcm_mailbox_read);
  17979. +
  17980. +static void dev_mbox_register(const char *dev_name, struct device *dev)
  17981. +{
  17982. + mbox_dev = dev;
  17983. +}
  17984. +
  17985. +static int mbox_copy_from_user(void *dst, const void *src, int size)
  17986. +{
  17987. + if ( (uint32_t)src < TASK_SIZE)
  17988. + {
  17989. + return copy_from_user(dst, src, size);
  17990. + }
  17991. + else
  17992. + {
  17993. + memcpy( dst, src, size );
  17994. + return 0;
  17995. + }
  17996. +}
  17997. +
  17998. +static int mbox_copy_to_user(void *dst, const void *src, int size)
  17999. +{
  18000. + if ( (uint32_t)dst < TASK_SIZE)
  18001. + {
  18002. + return copy_to_user(dst, src, size);
  18003. + }
  18004. + else
  18005. + {
  18006. + memcpy( dst, src, size );
  18007. + return 0;
  18008. + }
  18009. +}
  18010. +
  18011. +static DEFINE_MUTEX(mailbox_lock);
  18012. +extern int bcm_mailbox_property(void *data, int size)
  18013. +{
  18014. + uint32_t success;
  18015. + dma_addr_t mem_bus; /* the memory address accessed from videocore */
  18016. + void *mem_kern; /* the memory address accessed from driver */
  18017. + int s = 0;
  18018. +
  18019. + mutex_lock(&mailbox_lock);
  18020. + /* allocate some memory for the messages communicating with GPU */
  18021. + mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
  18022. + if (mem_kern) {
  18023. + /* create the message */
  18024. + mbox_copy_from_user(mem_kern, data, size);
  18025. +
  18026. + /* send the message */
  18027. + wmb();
  18028. + s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
  18029. + if (s == 0) {
  18030. + s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
  18031. + }
  18032. + if (s == 0) {
  18033. + /* copy the response */
  18034. + rmb();
  18035. + mbox_copy_to_user(data, mem_kern, size);
  18036. + }
  18037. + dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
  18038. + } else {
  18039. + s = -ENOMEM;
  18040. + }
  18041. + if (s != 0)
  18042. + printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
  18043. +
  18044. + mutex_unlock(&mailbox_lock);
  18045. + return s;
  18046. +}
  18047. +EXPORT_SYMBOL_GPL(bcm_mailbox_property);
  18048. +
  18049. +/* ----------------------------------------------------------------------
  18050. + * Platform Device for Mailbox
  18051. + * -------------------------------------------------------------------- */
  18052. +
  18053. +/*
  18054. + * Is the device open right now? Used to prevent
  18055. + * concurent access into the same device
  18056. + */
  18057. +static int Device_Open = 0;
  18058. +
  18059. +/*
  18060. + * This is called whenever a process attempts to open the device file
  18061. + */
  18062. +static int device_open(struct inode *inode, struct file *file)
  18063. +{
  18064. + /*
  18065. + * We don't want to talk to two processes at the same time
  18066. + */
  18067. + if (Device_Open)
  18068. + return -EBUSY;
  18069. +
  18070. + Device_Open++;
  18071. + /*
  18072. + * Initialize the message
  18073. + */
  18074. + try_module_get(THIS_MODULE);
  18075. + return 0;
  18076. +}
  18077. +
  18078. +static int device_release(struct inode *inode, struct file *file)
  18079. +{
  18080. + /*
  18081. + * We're now ready for our next caller
  18082. + */
  18083. + Device_Open--;
  18084. +
  18085. + module_put(THIS_MODULE);
  18086. + return 0;
  18087. +}
  18088. +
  18089. +/*
  18090. + * This function is called whenever a process tries to do an ioctl on our
  18091. + * device file. We get two extra parameters (additional to the inode and file
  18092. + * structures, which all device functions get): the number of the ioctl called
  18093. + * and the parameter given to the ioctl function.
  18094. + *
  18095. + * If the ioctl is write or read/write (meaning output is returned to the
  18096. + * calling process), the ioctl call returns the output of this function.
  18097. + *
  18098. + */
  18099. +static long device_ioctl(struct file *file, /* see include/linux/fs.h */
  18100. + unsigned int ioctl_num, /* number and param for ioctl */
  18101. + unsigned long ioctl_param)
  18102. +{
  18103. + unsigned size;
  18104. + /*
  18105. + * Switch according to the ioctl called
  18106. + */
  18107. + switch (ioctl_num) {
  18108. + case IOCTL_MBOX_PROPERTY:
  18109. + /*
  18110. + * Receive a pointer to a message (in user space) and set that
  18111. + * to be the device's message. Get the parameter given to
  18112. + * ioctl by the process.
  18113. + */
  18114. + mbox_copy_from_user(&size, (void *)ioctl_param, sizeof size);
  18115. + return bcm_mailbox_property((void *)ioctl_param, size);
  18116. + break;
  18117. + default:
  18118. + printk(KERN_ERR DRIVER_NAME "unknown ioctl: %d\n", ioctl_num);
  18119. + return -EINVAL;
  18120. + }
  18121. +
  18122. + return 0;
  18123. +}
  18124. +
  18125. +/* Module Declarations */
  18126. +
  18127. +/*
  18128. + * This structure will hold the functions to be called
  18129. + * when a process does something to the device we
  18130. + * created. Since a pointer to this structure is kept in
  18131. + * the devices table, it can't be local to
  18132. + * init_module. NULL is for unimplemented functios.
  18133. + */
  18134. +struct file_operations fops = {
  18135. + .unlocked_ioctl = device_ioctl,
  18136. + .open = device_open,
  18137. + .release = device_release, /* a.k.a. close */
  18138. +};
  18139. +
  18140. +static int bcm_vcio_probe(struct platform_device *pdev)
  18141. +{
  18142. + int ret = 0;
  18143. + struct vc_mailbox *mailbox;
  18144. +
  18145. + mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
  18146. + if (NULL == mailbox) {
  18147. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  18148. + "mailbox memory\n");
  18149. + ret = -ENOMEM;
  18150. + } else {
  18151. + struct resource *res;
  18152. +
  18153. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  18154. + if (res == NULL) {
  18155. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  18156. + "resource\n");
  18157. + ret = -ENODEV;
  18158. + kfree(mailbox);
  18159. + } else {
  18160. + /* should be based on the registers from res really */
  18161. + mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
  18162. +
  18163. + platform_set_drvdata(pdev, mailbox);
  18164. + dev_mbox_register(DRIVER_NAME, &pdev->dev);
  18165. +
  18166. + mbox_irqaction.dev_id = mailbox;
  18167. + setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
  18168. + printk(KERN_INFO DRIVER_NAME ": mailbox at %p\n",
  18169. + __io_address(ARM_0_MAIL0_RD));
  18170. + }
  18171. + }
  18172. +
  18173. + if (ret == 0) {
  18174. + /*
  18175. + * Register the character device
  18176. + */
  18177. + ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
  18178. +
  18179. + /*
  18180. + * Negative values signify an error
  18181. + */
  18182. + if (ret < 0) {
  18183. + printk(KERN_ERR DRIVER_NAME
  18184. + "Failed registering the character device %d\n", ret);
  18185. + return ret;
  18186. + }
  18187. + vcio_class = class_create(THIS_MODULE, BCM_VCIO_DRIVER_NAME);
  18188. + if (IS_ERR(vcio_class)) {
  18189. + ret = PTR_ERR(vcio_class);
  18190. + return ret ;
  18191. + }
  18192. + device_create(vcio_class, NULL, MKDEV(MAJOR_NUM, 0), NULL,
  18193. + "vcio");
  18194. + }
  18195. + return ret;
  18196. +}
  18197. +
  18198. +static int bcm_vcio_remove(struct platform_device *pdev)
  18199. +{
  18200. + struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
  18201. +
  18202. + platform_set_drvdata(pdev, NULL);
  18203. + kfree(mailbox);
  18204. +
  18205. + return 0;
  18206. +}
  18207. +
  18208. +static struct platform_driver bcm_mbox_driver = {
  18209. + .probe = bcm_vcio_probe,
  18210. + .remove = bcm_vcio_remove,
  18211. +
  18212. + .driver = {
  18213. + .name = DRIVER_NAME,
  18214. + .owner = THIS_MODULE,
  18215. + },
  18216. +};
  18217. +
  18218. +static int __init bcm_mbox_init(void)
  18219. +{
  18220. + int ret;
  18221. +
  18222. + printk(KERN_INFO "mailbox: Broadcom VideoCore Mailbox driver\n");
  18223. +
  18224. + ret = platform_driver_register(&bcm_mbox_driver);
  18225. + if (ret != 0) {
  18226. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  18227. + "on platform\n");
  18228. + }
  18229. +
  18230. + return ret;
  18231. +}
  18232. +
  18233. +static void __exit bcm_mbox_exit(void)
  18234. +{
  18235. + device_destroy(vcio_class,MKDEV(MAJOR_NUM, 0));
  18236. + class_destroy(vcio_class);
  18237. + unregister_chrdev(MAJOR_NUM, DEVICE_FILE_NAME);
  18238. + platform_driver_unregister(&bcm_mbox_driver);
  18239. +}
  18240. +
  18241. +arch_initcall(bcm_mbox_init); /* Initialize early */
  18242. +module_exit(bcm_mbox_exit);
  18243. +
  18244. +MODULE_AUTHOR("Gray Girling");
  18245. +MODULE_DESCRIPTION("ARM I/O to VideoCore processor");
  18246. +MODULE_LICENSE("GPL");
  18247. +MODULE_ALIAS("platform:bcm-mbox");
  18248. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/vc_mem.c linux-rpi/arch/arm/mach-bcm2709/vc_mem.c
  18249. --- linux-3.18.6/arch/arm/mach-bcm2709/vc_mem.c 1970-01-01 01:00:00.000000000 +0100
  18250. +++ linux-rpi/arch/arm/mach-bcm2709/vc_mem.c 2015-02-09 04:39:42.000000000 +0100
  18251. @@ -0,0 +1,431 @@
  18252. +/*****************************************************************************
  18253. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  18254. +*
  18255. +* Unless you and Broadcom execute a separate written software license
  18256. +* agreement governing use of this software, this software is licensed to you
  18257. +* under the terms of the GNU General Public License version 2, available at
  18258. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  18259. +*
  18260. +* Notwithstanding the above, under no circumstances may you combine this
  18261. +* software in any way with any other Broadcom software provided under a
  18262. +* license other than the GPL, without Broadcom's express prior written
  18263. +* consent.
  18264. +*****************************************************************************/
  18265. +
  18266. +#include <linux/kernel.h>
  18267. +#include <linux/module.h>
  18268. +#include <linux/fs.h>
  18269. +#include <linux/device.h>
  18270. +#include <linux/cdev.h>
  18271. +#include <linux/mm.h>
  18272. +#include <linux/slab.h>
  18273. +#include <linux/debugfs.h>
  18274. +#include <asm/uaccess.h>
  18275. +#include <linux/dma-mapping.h>
  18276. +
  18277. +#ifdef CONFIG_ARCH_KONA
  18278. +#include <chal/chal_ipc.h>
  18279. +#elif defined(CONFIG_ARCH_BCM2708) || defined(CONFIG_ARCH_BCM2709)
  18280. +#else
  18281. +#include <csp/chal_ipc.h>
  18282. +#endif
  18283. +
  18284. +#include "mach/vc_mem.h"
  18285. +#include <mach/vcio.h>
  18286. +
  18287. +#define DRIVER_NAME "vc-mem"
  18288. +
  18289. +// Device (/dev) related variables
  18290. +static dev_t vc_mem_devnum = 0;
  18291. +static struct class *vc_mem_class = NULL;
  18292. +static struct cdev vc_mem_cdev;
  18293. +static int vc_mem_inited = 0;
  18294. +
  18295. +#ifdef CONFIG_DEBUG_FS
  18296. +static struct dentry *vc_mem_debugfs_entry;
  18297. +#endif
  18298. +
  18299. +/*
  18300. + * Videocore memory addresses and size
  18301. + *
  18302. + * Drivers that wish to know the videocore memory addresses and sizes should
  18303. + * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
  18304. + * headers. This allows the other drivers to not be tied down to a a certain
  18305. + * address/size at compile time.
  18306. + *
  18307. + * In the future, the goal is to have the videocore memory virtual address and
  18308. + * size be calculated at boot time rather than at compile time. The decision of
  18309. + * where the videocore memory resides and its size would be in the hands of the
  18310. + * bootloader (and/or kernel). When that happens, the values of these variables
  18311. + * would be calculated and assigned in the init function.
  18312. + */
  18313. +// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
  18314. +unsigned long mm_vc_mem_phys_addr = 0x00000000;
  18315. +unsigned int mm_vc_mem_size = 0;
  18316. +unsigned int mm_vc_mem_base = 0;
  18317. +
  18318. +EXPORT_SYMBOL(mm_vc_mem_phys_addr);
  18319. +EXPORT_SYMBOL(mm_vc_mem_size);
  18320. +EXPORT_SYMBOL(mm_vc_mem_base);
  18321. +
  18322. +static uint phys_addr = 0;
  18323. +static uint mem_size = 0;
  18324. +static uint mem_base = 0;
  18325. +
  18326. +
  18327. +/****************************************************************************
  18328. +*
  18329. +* vc_mem_open
  18330. +*
  18331. +***************************************************************************/
  18332. +
  18333. +static int
  18334. +vc_mem_open(struct inode *inode, struct file *file)
  18335. +{
  18336. + (void) inode;
  18337. + (void) file;
  18338. +
  18339. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  18340. +
  18341. + return 0;
  18342. +}
  18343. +
  18344. +/****************************************************************************
  18345. +*
  18346. +* vc_mem_release
  18347. +*
  18348. +***************************************************************************/
  18349. +
  18350. +static int
  18351. +vc_mem_release(struct inode *inode, struct file *file)
  18352. +{
  18353. + (void) inode;
  18354. + (void) file;
  18355. +
  18356. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  18357. +
  18358. + return 0;
  18359. +}
  18360. +
  18361. +/****************************************************************************
  18362. +*
  18363. +* vc_mem_get_size
  18364. +*
  18365. +***************************************************************************/
  18366. +
  18367. +static void
  18368. +vc_mem_get_size(void)
  18369. +{
  18370. +}
  18371. +
  18372. +/****************************************************************************
  18373. +*
  18374. +* vc_mem_get_base
  18375. +*
  18376. +***************************************************************************/
  18377. +
  18378. +static void
  18379. +vc_mem_get_base(void)
  18380. +{
  18381. +}
  18382. +
  18383. +/****************************************************************************
  18384. +*
  18385. +* vc_mem_get_current_size
  18386. +*
  18387. +***************************************************************************/
  18388. +
  18389. +int
  18390. +vc_mem_get_current_size(void)
  18391. +{
  18392. + return mm_vc_mem_size;
  18393. +}
  18394. +
  18395. +EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
  18396. +
  18397. +/****************************************************************************
  18398. +*
  18399. +* vc_mem_ioctl
  18400. +*
  18401. +***************************************************************************/
  18402. +
  18403. +static long
  18404. +vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  18405. +{
  18406. + int rc = 0;
  18407. +
  18408. + (void) cmd;
  18409. + (void) arg;
  18410. +
  18411. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  18412. +
  18413. + switch (cmd) {
  18414. + case VC_MEM_IOC_MEM_PHYS_ADDR:
  18415. + {
  18416. + pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n",
  18417. + __func__, (void *) mm_vc_mem_phys_addr);
  18418. +
  18419. + if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
  18420. + sizeof (mm_vc_mem_phys_addr)) != 0) {
  18421. + rc = -EFAULT;
  18422. + }
  18423. + break;
  18424. + }
  18425. + case VC_MEM_IOC_MEM_SIZE:
  18426. + {
  18427. + // Get the videocore memory size first
  18428. + vc_mem_get_size();
  18429. +
  18430. + pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
  18431. + mm_vc_mem_size);
  18432. +
  18433. + if (copy_to_user((void *) arg, &mm_vc_mem_size,
  18434. + sizeof (mm_vc_mem_size)) != 0) {
  18435. + rc = -EFAULT;
  18436. + }
  18437. + break;
  18438. + }
  18439. + case VC_MEM_IOC_MEM_BASE:
  18440. + {
  18441. + // Get the videocore memory base
  18442. + vc_mem_get_base();
  18443. +
  18444. + pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
  18445. + mm_vc_mem_base);
  18446. +
  18447. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  18448. + sizeof (mm_vc_mem_base)) != 0) {
  18449. + rc = -EFAULT;
  18450. + }
  18451. + break;
  18452. + }
  18453. + case VC_MEM_IOC_MEM_LOAD:
  18454. + {
  18455. + // Get the videocore memory base
  18456. + vc_mem_get_base();
  18457. +
  18458. + pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
  18459. + mm_vc_mem_base);
  18460. +
  18461. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  18462. + sizeof (mm_vc_mem_base)) != 0) {
  18463. + rc = -EFAULT;
  18464. + }
  18465. + break;
  18466. + }
  18467. + default:
  18468. + {
  18469. + return -ENOTTY;
  18470. + }
  18471. + }
  18472. + pr_debug("%s: file = 0x%p returning %d\n", __func__, file, rc);
  18473. +
  18474. + return rc;
  18475. +}
  18476. +
  18477. +/****************************************************************************
  18478. +*
  18479. +* vc_mem_mmap
  18480. +*
  18481. +***************************************************************************/
  18482. +
  18483. +static int
  18484. +vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
  18485. +{
  18486. + int rc = 0;
  18487. + unsigned long length = vma->vm_end - vma->vm_start;
  18488. + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  18489. +
  18490. + pr_debug("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n",
  18491. + __func__, (long) vma->vm_start, (long) vma->vm_end,
  18492. + (long) vma->vm_pgoff);
  18493. +
  18494. + if (offset + length > mm_vc_mem_size) {
  18495. + pr_err("%s: length %ld is too big\n", __func__, length);
  18496. + return -EINVAL;
  18497. + }
  18498. + // Do not cache the memory map
  18499. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  18500. +
  18501. + rc = remap_pfn_range(vma, vma->vm_start,
  18502. + (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
  18503. + vma->vm_pgoff, length, vma->vm_page_prot);
  18504. + if (rc != 0) {
  18505. + pr_err("%s: remap_pfn_range failed (rc=%d)\n", __func__, rc);
  18506. + }
  18507. +
  18508. + return rc;
  18509. +}
  18510. +
  18511. +/****************************************************************************
  18512. +*
  18513. +* File Operations for the driver.
  18514. +*
  18515. +***************************************************************************/
  18516. +
  18517. +static const struct file_operations vc_mem_fops = {
  18518. + .owner = THIS_MODULE,
  18519. + .open = vc_mem_open,
  18520. + .release = vc_mem_release,
  18521. + .unlocked_ioctl = vc_mem_ioctl,
  18522. + .mmap = vc_mem_mmap,
  18523. +};
  18524. +
  18525. +#ifdef CONFIG_DEBUG_FS
  18526. +static void vc_mem_debugfs_deinit(void)
  18527. +{
  18528. + debugfs_remove_recursive(vc_mem_debugfs_entry);
  18529. + vc_mem_debugfs_entry = NULL;
  18530. +}
  18531. +
  18532. +
  18533. +static int vc_mem_debugfs_init(
  18534. + struct device *dev)
  18535. +{
  18536. + vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
  18537. + if (!vc_mem_debugfs_entry) {
  18538. + dev_warn(dev, "could not create debugfs entry\n");
  18539. + return -EFAULT;
  18540. + }
  18541. +
  18542. + if (!debugfs_create_x32("vc_mem_phys_addr",
  18543. + 0444,
  18544. + vc_mem_debugfs_entry,
  18545. + (u32 *)&mm_vc_mem_phys_addr)) {
  18546. + dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
  18547. + __func__);
  18548. + goto fail;
  18549. + }
  18550. +
  18551. + if (!debugfs_create_x32("vc_mem_size",
  18552. + 0444,
  18553. + vc_mem_debugfs_entry,
  18554. + (u32 *)&mm_vc_mem_size)) {
  18555. + dev_warn(dev, "%s:could not create vc_mem_size entry\n",
  18556. + __func__);
  18557. + goto fail;
  18558. + }
  18559. +
  18560. + if (!debugfs_create_x32("vc_mem_base",
  18561. + 0444,
  18562. + vc_mem_debugfs_entry,
  18563. + (u32 *)&mm_vc_mem_base)) {
  18564. + dev_warn(dev, "%s:could not create vc_mem_base entry\n",
  18565. + __func__);
  18566. + goto fail;
  18567. + }
  18568. +
  18569. + return 0;
  18570. +
  18571. +fail:
  18572. + vc_mem_debugfs_deinit();
  18573. + return -EFAULT;
  18574. +}
  18575. +
  18576. +#endif /* CONFIG_DEBUG_FS */
  18577. +
  18578. +
  18579. +/****************************************************************************
  18580. +*
  18581. +* vc_mem_init
  18582. +*
  18583. +***************************************************************************/
  18584. +
  18585. +static int __init
  18586. +vc_mem_init(void)
  18587. +{
  18588. + int rc = -EFAULT;
  18589. + struct device *dev;
  18590. +
  18591. + pr_debug("%s: called\n", __func__);
  18592. +
  18593. + mm_vc_mem_phys_addr = phys_addr;
  18594. + mm_vc_mem_size = mem_size;
  18595. + mm_vc_mem_base = mem_base;
  18596. +
  18597. + vc_mem_get_size();
  18598. +
  18599. + pr_info("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
  18600. + mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
  18601. +
  18602. + if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
  18603. + pr_err("%s: alloc_chrdev_region failed (rc=%d)\n",
  18604. + __func__, rc);
  18605. + goto out_err;
  18606. + }
  18607. +
  18608. + cdev_init(&vc_mem_cdev, &vc_mem_fops);
  18609. + if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
  18610. + pr_err("%s: cdev_add failed (rc=%d)\n", __func__, rc);
  18611. + goto out_unregister;
  18612. + }
  18613. +
  18614. + vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
  18615. + if (IS_ERR(vc_mem_class)) {
  18616. + rc = PTR_ERR(vc_mem_class);
  18617. + pr_err("%s: class_create failed (rc=%d)\n", __func__, rc);
  18618. + goto out_cdev_del;
  18619. + }
  18620. +
  18621. + dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
  18622. + DRIVER_NAME);
  18623. + if (IS_ERR(dev)) {
  18624. + rc = PTR_ERR(dev);
  18625. + pr_err("%s: device_create failed (rc=%d)\n", __func__, rc);
  18626. + goto out_class_destroy;
  18627. + }
  18628. +
  18629. +#ifdef CONFIG_DEBUG_FS
  18630. + /* don't fail if the debug entries cannot be created */
  18631. + vc_mem_debugfs_init(dev);
  18632. +#endif
  18633. +
  18634. + vc_mem_inited = 1;
  18635. + return 0;
  18636. +
  18637. + device_destroy(vc_mem_class, vc_mem_devnum);
  18638. +
  18639. + out_class_destroy:
  18640. + class_destroy(vc_mem_class);
  18641. + vc_mem_class = NULL;
  18642. +
  18643. + out_cdev_del:
  18644. + cdev_del(&vc_mem_cdev);
  18645. +
  18646. + out_unregister:
  18647. + unregister_chrdev_region(vc_mem_devnum, 1);
  18648. +
  18649. + out_err:
  18650. + return -1;
  18651. +}
  18652. +
  18653. +/****************************************************************************
  18654. +*
  18655. +* vc_mem_exit
  18656. +*
  18657. +***************************************************************************/
  18658. +
  18659. +static void __exit
  18660. +vc_mem_exit(void)
  18661. +{
  18662. + pr_debug("%s: called\n", __func__);
  18663. +
  18664. + if (vc_mem_inited) {
  18665. +#if CONFIG_DEBUG_FS
  18666. + vc_mem_debugfs_deinit();
  18667. +#endif
  18668. + device_destroy(vc_mem_class, vc_mem_devnum);
  18669. + class_destroy(vc_mem_class);
  18670. + cdev_del(&vc_mem_cdev);
  18671. + unregister_chrdev_region(vc_mem_devnum, 1);
  18672. + }
  18673. +}
  18674. +
  18675. +module_init(vc_mem_init);
  18676. +module_exit(vc_mem_exit);
  18677. +MODULE_LICENSE("GPL");
  18678. +MODULE_AUTHOR("Broadcom Corporation");
  18679. +
  18680. +module_param(phys_addr, uint, 0644);
  18681. +module_param(mem_size, uint, 0644);
  18682. +module_param(mem_base, uint, 0644);
  18683. diff -Nur linux-3.18.6/arch/arm/mach-bcm2709/vc_support.c linux-rpi/arch/arm/mach-bcm2709/vc_support.c
  18684. --- linux-3.18.6/arch/arm/mach-bcm2709/vc_support.c 1970-01-01 01:00:00.000000000 +0100
  18685. +++ linux-rpi/arch/arm/mach-bcm2709/vc_support.c 2015-02-09 04:39:42.000000000 +0100
  18686. @@ -0,0 +1,318 @@
  18687. +/*
  18688. + * vc_support.c
  18689. + *
  18690. + * Created on: 25 Nov 2012
  18691. + * Author: Simon
  18692. + */
  18693. +
  18694. +#include <linux/module.h>
  18695. +#include <mach/vcio.h>
  18696. +
  18697. +#ifdef ECLIPSE_IGNORE
  18698. +
  18699. +#define __user
  18700. +#define __init
  18701. +#define __exit
  18702. +#define __iomem
  18703. +#define KERN_DEBUG
  18704. +#define KERN_ERR
  18705. +#define KERN_WARNING
  18706. +#define KERN_INFO
  18707. +#define _IOWR(a, b, c) b
  18708. +#define _IOW(a, b, c) b
  18709. +#define _IO(a, b) b
  18710. +
  18711. +#endif
  18712. +
  18713. +/****** VC MAILBOX FUNCTIONALITY ******/
  18714. +unsigned int AllocateVcMemory(unsigned int *pHandle, unsigned int size, unsigned int alignment, unsigned int flags)
  18715. +{
  18716. + struct vc_msg
  18717. + {
  18718. + unsigned int m_msgSize;
  18719. + unsigned int m_response;
  18720. +
  18721. + struct vc_tag
  18722. + {
  18723. + unsigned int m_tagId;
  18724. + unsigned int m_sendBufferSize;
  18725. + union {
  18726. + unsigned int m_sendDataSize;
  18727. + unsigned int m_recvDataSize;
  18728. + };
  18729. +
  18730. + struct args
  18731. + {
  18732. + union {
  18733. + unsigned int m_size;
  18734. + unsigned int m_handle;
  18735. + };
  18736. + unsigned int m_alignment;
  18737. + unsigned int m_flags;
  18738. + } m_args;
  18739. + } m_tag;
  18740. +
  18741. + unsigned int m_endTag;
  18742. + } msg;
  18743. + int s;
  18744. +
  18745. + msg.m_msgSize = sizeof(msg);
  18746. + msg.m_response = 0;
  18747. + msg.m_endTag = 0;
  18748. +
  18749. + //fill in the tag for the allocation command
  18750. + msg.m_tag.m_tagId = 0x3000c;
  18751. + msg.m_tag.m_sendBufferSize = 12;
  18752. + msg.m_tag.m_sendDataSize = 12;
  18753. +
  18754. + //fill in our args
  18755. + msg.m_tag.m_args.m_size = size;
  18756. + msg.m_tag.m_args.m_alignment = alignment;
  18757. + msg.m_tag.m_args.m_flags = flags;
  18758. +
  18759. + //run the command
  18760. + s = bcm_mailbox_property(&msg, sizeof(msg));
  18761. +
  18762. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  18763. + {
  18764. + *pHandle = msg.m_tag.m_args.m_handle;
  18765. + return 0;
  18766. + }
  18767. + else
  18768. + {
  18769. + printk(KERN_ERR "failed to allocate vc memory: s=%d response=%08x recv data size=%08x\n",
  18770. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  18771. + return 1;
  18772. + }
  18773. +}
  18774. +
  18775. +unsigned int ReleaseVcMemory(unsigned int handle)
  18776. +{
  18777. + struct vc_msg
  18778. + {
  18779. + unsigned int m_msgSize;
  18780. + unsigned int m_response;
  18781. +
  18782. + struct vc_tag
  18783. + {
  18784. + unsigned int m_tagId;
  18785. + unsigned int m_sendBufferSize;
  18786. + union {
  18787. + unsigned int m_sendDataSize;
  18788. + unsigned int m_recvDataSize;
  18789. + };
  18790. +
  18791. + struct args
  18792. + {
  18793. + union {
  18794. + unsigned int m_handle;
  18795. + unsigned int m_error;
  18796. + };
  18797. + } m_args;
  18798. + } m_tag;
  18799. +
  18800. + unsigned int m_endTag;
  18801. + } msg;
  18802. + int s;
  18803. +
  18804. + msg.m_msgSize = sizeof(msg);
  18805. + msg.m_response = 0;
  18806. + msg.m_endTag = 0;
  18807. +
  18808. + //fill in the tag for the release command
  18809. + msg.m_tag.m_tagId = 0x3000f;
  18810. + msg.m_tag.m_sendBufferSize = 4;
  18811. + msg.m_tag.m_sendDataSize = 4;
  18812. +
  18813. + //pass across the handle
  18814. + msg.m_tag.m_args.m_handle = handle;
  18815. +
  18816. + s = bcm_mailbox_property(&msg, sizeof(msg));
  18817. +
  18818. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004 && msg.m_tag.m_args.m_error == 0)
  18819. + return 0;
  18820. + else
  18821. + {
  18822. + printk(KERN_ERR "failed to release vc memory: s=%d response=%08x recv data size=%08x error=%08x\n",
  18823. + s, msg.m_response, msg.m_tag.m_recvDataSize, msg.m_tag.m_args.m_error);
  18824. + return 1;
  18825. + }
  18826. +}
  18827. +
  18828. +unsigned int LockVcMemory(unsigned int *pBusAddress, unsigned int handle)
  18829. +{
  18830. + struct vc_msg
  18831. + {
  18832. + unsigned int m_msgSize;
  18833. + unsigned int m_response;
  18834. +
  18835. + struct vc_tag
  18836. + {
  18837. + unsigned int m_tagId;
  18838. + unsigned int m_sendBufferSize;
  18839. + union {
  18840. + unsigned int m_sendDataSize;
  18841. + unsigned int m_recvDataSize;
  18842. + };
  18843. +
  18844. + struct args
  18845. + {
  18846. + union {
  18847. + unsigned int m_handle;
  18848. + unsigned int m_busAddress;
  18849. + };
  18850. + } m_args;
  18851. + } m_tag;
  18852. +
  18853. + unsigned int m_endTag;
  18854. + } msg;
  18855. + int s;
  18856. +
  18857. + msg.m_msgSize = sizeof(msg);
  18858. + msg.m_response = 0;
  18859. + msg.m_endTag = 0;
  18860. +
  18861. + //fill in the tag for the lock command
  18862. + msg.m_tag.m_tagId = 0x3000d;
  18863. + msg.m_tag.m_sendBufferSize = 4;
  18864. + msg.m_tag.m_sendDataSize = 4;
  18865. +
  18866. + //pass across the handle
  18867. + msg.m_tag.m_args.m_handle = handle;
  18868. +
  18869. + s = bcm_mailbox_property(&msg, sizeof(msg));
  18870. +
  18871. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  18872. + {
  18873. + //pick out the bus address
  18874. + *pBusAddress = msg.m_tag.m_args.m_busAddress;
  18875. + return 0;
  18876. + }
  18877. + else
  18878. + {
  18879. + printk(KERN_ERR "failed to lock vc memory: s=%d response=%08x recv data size=%08x\n",
  18880. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  18881. + return 1;
  18882. + }
  18883. +}
  18884. +
  18885. +unsigned int UnlockVcMemory(unsigned int handle)
  18886. +{
  18887. + struct vc_msg
  18888. + {
  18889. + unsigned int m_msgSize;
  18890. + unsigned int m_response;
  18891. +
  18892. + struct vc_tag
  18893. + {
  18894. + unsigned int m_tagId;
  18895. + unsigned int m_sendBufferSize;
  18896. + union {
  18897. + unsigned int m_sendDataSize;
  18898. + unsigned int m_recvDataSize;
  18899. + };
  18900. +
  18901. + struct args
  18902. + {
  18903. + union {
  18904. + unsigned int m_handle;
  18905. + unsigned int m_error;
  18906. + };
  18907. + } m_args;
  18908. + } m_tag;
  18909. +
  18910. + unsigned int m_endTag;
  18911. + } msg;
  18912. + int s;
  18913. +
  18914. + msg.m_msgSize = sizeof(msg);
  18915. + msg.m_response = 0;
  18916. + msg.m_endTag = 0;
  18917. +
  18918. + //fill in the tag for the unlock command
  18919. + msg.m_tag.m_tagId = 0x3000e;
  18920. + msg.m_tag.m_sendBufferSize = 4;
  18921. + msg.m_tag.m_sendDataSize = 4;
  18922. +
  18923. + //pass across the handle
  18924. + msg.m_tag.m_args.m_handle = handle;
  18925. +
  18926. + s = bcm_mailbox_property(&msg, sizeof(msg));
  18927. +
  18928. + //check the error code too
  18929. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004 && msg.m_tag.m_args.m_error == 0)
  18930. + return 0;
  18931. + else
  18932. + {
  18933. + printk(KERN_ERR "failed to unlock vc memory: s=%d response=%08x recv data size=%08x error%08x\n",
  18934. + s, msg.m_response, msg.m_tag.m_recvDataSize, msg.m_tag.m_args.m_error);
  18935. + return 1;
  18936. + }
  18937. +}
  18938. +
  18939. +unsigned int ExecuteVcCode(unsigned int code,
  18940. + unsigned int r0, unsigned int r1, unsigned int r2, unsigned int r3, unsigned int r4, unsigned int r5)
  18941. +{
  18942. + struct vc_msg
  18943. + {
  18944. + unsigned int m_msgSize;
  18945. + unsigned int m_response;
  18946. +
  18947. + struct vc_tag
  18948. + {
  18949. + unsigned int m_tagId;
  18950. + unsigned int m_sendBufferSize;
  18951. + union {
  18952. + unsigned int m_sendDataSize;
  18953. + unsigned int m_recvDataSize;
  18954. + };
  18955. +
  18956. + struct args
  18957. + {
  18958. + union {
  18959. + unsigned int m_pCode;
  18960. + unsigned int m_return;
  18961. + };
  18962. + unsigned int m_r0;
  18963. + unsigned int m_r1;
  18964. + unsigned int m_r2;
  18965. + unsigned int m_r3;
  18966. + unsigned int m_r4;
  18967. + unsigned int m_r5;
  18968. + } m_args;
  18969. + } m_tag;
  18970. +
  18971. + unsigned int m_endTag;
  18972. + } msg;
  18973. + int s;
  18974. +
  18975. + msg.m_msgSize = sizeof(msg);
  18976. + msg.m_response = 0;
  18977. + msg.m_endTag = 0;
  18978. +
  18979. + //fill in the tag for the unlock command
  18980. + msg.m_tag.m_tagId = 0x30010;
  18981. + msg.m_tag.m_sendBufferSize = 28;
  18982. + msg.m_tag.m_sendDataSize = 28;
  18983. +
  18984. + //pass across the handle
  18985. + msg.m_tag.m_args.m_pCode = code;
  18986. + msg.m_tag.m_args.m_r0 = r0;
  18987. + msg.m_tag.m_args.m_r1 = r1;
  18988. + msg.m_tag.m_args.m_r2 = r2;
  18989. + msg.m_tag.m_args.m_r3 = r3;
  18990. + msg.m_tag.m_args.m_r4 = r4;
  18991. + msg.m_tag.m_args.m_r5 = r5;
  18992. +
  18993. + s = bcm_mailbox_property(&msg, sizeof(msg));
  18994. +
  18995. + //check the error code too
  18996. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  18997. + return msg.m_tag.m_args.m_return;
  18998. + else
  18999. + {
  19000. + printk(KERN_ERR "failed to execute: s=%d response=%08x recv data size=%08x\n",
  19001. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  19002. + return 1;
  19003. + }
  19004. +}
  19005. diff -Nur linux-3.18.6/arch/arm/Makefile linux-rpi/arch/arm/Makefile
  19006. --- linux-3.18.6/arch/arm/Makefile 2015-02-06 15:53:48.000000000 +0100
  19007. +++ linux-rpi/arch/arm/Makefile 2015-02-09 04:39:42.000000000 +0100
  19008. @@ -146,6 +146,8 @@
  19009. machine-$(CONFIG_ARCH_AT91) += at91
  19010. machine-$(CONFIG_ARCH_AXXIA) += axxia
  19011. machine-$(CONFIG_ARCH_BCM) += bcm
  19012. +machine-$(CONFIG_ARCH_BCM2708) += bcm2708
  19013. +machine-$(CONFIG_ARCH_BCM2709) += bcm2709
  19014. machine-$(CONFIG_ARCH_BERLIN) += berlin
  19015. machine-$(CONFIG_ARCH_CLPS711X) += clps711x
  19016. machine-$(CONFIG_ARCH_CNS3XXX) += cns3xxx
  19017. diff -Nur linux-3.18.6/arch/arm/mm/Kconfig linux-rpi/arch/arm/mm/Kconfig
  19018. --- linux-3.18.6/arch/arm/mm/Kconfig 2015-02-06 15:53:48.000000000 +0100
  19019. +++ linux-rpi/arch/arm/mm/Kconfig 2015-02-09 04:39:43.000000000 +0100
  19020. @@ -358,7 +358,7 @@
  19021. # ARMv6
  19022. config CPU_V6
  19023. - bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX
  19024. + bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX || MACH_BCM2708
  19025. select CPU_32v6
  19026. select CPU_ABRT_EV6
  19027. select CPU_CACHE_V6
  19028. diff -Nur linux-3.18.6/arch/arm/mm/proc-v6.S linux-rpi/arch/arm/mm/proc-v6.S
  19029. --- linux-3.18.6/arch/arm/mm/proc-v6.S 2015-02-06 15:53:48.000000000 +0100
  19030. +++ linux-rpi/arch/arm/mm/proc-v6.S 2015-02-09 04:39:43.000000000 +0100
  19031. @@ -73,10 +73,19 @@
  19032. *
  19033. * IRQs are already disabled.
  19034. */
  19035. +
  19036. +/* See jira SW-5991 for details of this workaround */
  19037. ENTRY(cpu_v6_do_idle)
  19038. - mov r1, #0
  19039. - mcr p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  19040. - mcr p15, 0, r1, c7, c0, 4 @ wait for interrupt
  19041. + .align 5
  19042. + mov r1, #2
  19043. +1: subs r1, #1
  19044. + nop
  19045. + mcreq p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  19046. + mcreq p15, 0, r1, c7, c0, 4 @ wait for interrupt
  19047. + nop
  19048. + nop
  19049. + nop
  19050. + bne 1b
  19051. ret lr
  19052. ENTRY(cpu_v6_dcache_clean_area)
  19053. diff -Nur linux-3.18.6/arch/arm/mm/proc-v7.S linux-rpi/arch/arm/mm/proc-v7.S
  19054. --- linux-3.18.6/arch/arm/mm/proc-v7.S 2015-02-06 15:53:48.000000000 +0100
  19055. +++ linux-rpi/arch/arm/mm/proc-v7.S 2015-02-09 04:39:43.000000000 +0100
  19056. @@ -441,6 +441,7 @@
  19057. orr r0, r0, r6 @ set them
  19058. THUMB( orr r0, r0, #1 << 30 ) @ Thumb exceptions
  19059. ret lr @ return to head.S:__ret
  19060. + .space 256
  19061. ENDPROC(__v7_setup)
  19062. .align 2
  19063. diff -Nur linux-3.18.6/arch/arm/tools/mach-types linux-rpi/arch/arm/tools/mach-types
  19064. --- linux-3.18.6/arch/arm/tools/mach-types 2015-02-06 15:53:48.000000000 +0100
  19065. +++ linux-rpi/arch/arm/tools/mach-types 2015-02-09 04:39:43.000000000 +0100
  19066. @@ -522,6 +522,8 @@
  19067. prima2_evb MACH_PRIMA2_EVB PRIMA2_EVB 3103
  19068. paz00 MACH_PAZ00 PAZ00 3128
  19069. acmenetusfoxg20 MACH_ACMENETUSFOXG20 ACMENETUSFOXG20 3129
  19070. +bcm2708 MACH_BCM2708 BCM2708 3138
  19071. +bcm2709 MACH_BCM2709 BCM2709 3139
  19072. ag5evm MACH_AG5EVM AG5EVM 3189
  19073. ics_if_voip MACH_ICS_IF_VOIP ICS_IF_VOIP 3206
  19074. wlf_cragg_6410 MACH_WLF_CRAGG_6410 WLF_CRAGG_6410 3207
  19075. diff -Nur linux-3.18.6/Documentation/video4linux/bcm2835-v4l2.txt linux-rpi/Documentation/video4linux/bcm2835-v4l2.txt
  19076. --- linux-3.18.6/Documentation/video4linux/bcm2835-v4l2.txt 1970-01-01 01:00:00.000000000 +0100
  19077. +++ linux-rpi/Documentation/video4linux/bcm2835-v4l2.txt 2015-02-09 04:39:42.000000000 +0100
  19078. @@ -0,0 +1,60 @@
  19079. +
  19080. +BCM2835 (aka Raspberry Pi) V4L2 driver
  19081. +======================================
  19082. +
  19083. +1. Copyright
  19084. +============
  19085. +
  19086. +Copyright © 2013 Raspberry Pi (Trading) Ltd.
  19087. +
  19088. +2. License
  19089. +==========
  19090. +
  19091. +This program is free software; you can redistribute it and/or modify
  19092. +it under the terms of the GNU General Public License as published by
  19093. +the Free Software Foundation; either version 2 of the License, or
  19094. +(at your option) any later version.
  19095. +
  19096. +This program is distributed in the hope that it will be useful,
  19097. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  19098. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19099. +GNU General Public License for more details.
  19100. +
  19101. +You should have received a copy of the GNU General Public License
  19102. +along with this program; if not, write to the Free Software
  19103. +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19104. +
  19105. +3. Quick Start
  19106. +==============
  19107. +
  19108. +You need a version 1.0 or later of v4l2-ctl, available from:
  19109. + git://git.linuxtv.org/v4l-utils.git
  19110. +
  19111. +$ sudo modprobe bcm2835-v4l2
  19112. +
  19113. +Turn on the overlay:
  19114. +
  19115. +$ v4l2-ctl --overlay=1
  19116. +
  19117. +Turn off the overlay:
  19118. +
  19119. +$ v4l2-ctl --overlay=0
  19120. +
  19121. +Set the capture format for video:
  19122. +
  19123. +$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
  19124. +
  19125. +(Note: 1088 not 1080).
  19126. +
  19127. +Capture:
  19128. +
  19129. +$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.h264
  19130. +
  19131. +Stills capture:
  19132. +
  19133. +$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
  19134. +$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
  19135. +
  19136. +List of available formats:
  19137. +
  19138. +$ v4l2-ctl --list-formats
  19139. diff -Nur linux-3.18.6/drivers/char/broadcom/Kconfig linux-rpi/drivers/char/broadcom/Kconfig
  19140. --- linux-3.18.6/drivers/char/broadcom/Kconfig 1970-01-01 01:00:00.000000000 +0100
  19141. +++ linux-rpi/drivers/char/broadcom/Kconfig 2015-02-09 04:39:53.000000000 +0100
  19142. @@ -0,0 +1,22 @@
  19143. +#
  19144. +# Broadcom char driver config
  19145. +#
  19146. +
  19147. +menuconfig BRCM_CHAR_DRIVERS
  19148. + bool "Broadcom Char Drivers"
  19149. + help
  19150. + Broadcom's char drivers
  19151. +
  19152. +config BCM_VC_CMA
  19153. + bool "Videocore CMA"
  19154. + depends on CMA && BRCM_CHAR_DRIVERS && BCM2708_VCHIQ
  19155. + default n
  19156. + help
  19157. + Helper for videocore CMA access.
  19158. +
  19159. +config BCM_VC_SM
  19160. + tristate "VMCS Shared Memory"
  19161. + default n
  19162. + help
  19163. + Support for the VC shared memory on the Broadcom reference
  19164. + design. Uses the VCHIQ stack.
  19165. diff -Nur linux-3.18.6/drivers/char/broadcom/Makefile linux-rpi/drivers/char/broadcom/Makefile
  19166. --- linux-3.18.6/drivers/char/broadcom/Makefile 1970-01-01 01:00:00.000000000 +0100
  19167. +++ linux-rpi/drivers/char/broadcom/Makefile 2015-02-09 04:39:53.000000000 +0100
  19168. @@ -0,0 +1,2 @@
  19169. +obj-$(CONFIG_BCM_VC_CMA) += vc_cma/
  19170. +obj-$(CONFIG_BCM_VC_SM) += vc_sm/
  19171. diff -Nur linux-3.18.6/drivers/char/broadcom/vc_cma/Makefile linux-rpi/drivers/char/broadcom/vc_cma/Makefile
  19172. --- linux-3.18.6/drivers/char/broadcom/vc_cma/Makefile 1970-01-01 01:00:00.000000000 +0100
  19173. +++ linux-rpi/drivers/char/broadcom/vc_cma/Makefile 2015-02-09 04:39:53.000000000 +0100
  19174. @@ -0,0 +1,14 @@
  19175. +ccflags-y += -Wall -Wstrict-prototypes -Wno-trigraphs
  19176. +ccflags-y += -Werror
  19177. +ccflags-y += -Iinclude/linux/broadcom
  19178. +ccflags-y += -Idrivers/misc/vc04_services
  19179. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchi
  19180. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchiq_arm
  19181. +
  19182. +ccflags-y += -D__KERNEL__
  19183. +ccflags-y += -D__linux__
  19184. +ccflags-y += -Werror
  19185. +
  19186. +obj-$(CONFIG_BCM_VC_CMA) += vc-cma.o
  19187. +
  19188. +vc-cma-objs := vc_cma.o
  19189. diff -Nur linux-3.18.6/drivers/char/broadcom/vc_cma/vc_cma.c linux-rpi/drivers/char/broadcom/vc_cma/vc_cma.c
  19190. --- linux-3.18.6/drivers/char/broadcom/vc_cma/vc_cma.c 1970-01-01 01:00:00.000000000 +0100
  19191. +++ linux-rpi/drivers/char/broadcom/vc_cma/vc_cma.c 2015-02-09 04:39:53.000000000 +0100
  19192. @@ -0,0 +1,1143 @@
  19193. +/**
  19194. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19195. + *
  19196. + * Redistribution and use in source and binary forms, with or without
  19197. + * modification, are permitted provided that the following conditions
  19198. + * are met:
  19199. + * 1. Redistributions of source code must retain the above copyright
  19200. + * notice, this list of conditions, and the following disclaimer,
  19201. + * without modification.
  19202. + * 2. Redistributions in binary form must reproduce the above copyright
  19203. + * notice, this list of conditions and the following disclaimer in the
  19204. + * documentation and/or other materials provided with the distribution.
  19205. + * 3. The names of the above-listed copyright holders may not be used
  19206. + * to endorse or promote products derived from this software without
  19207. + * specific prior written permission.
  19208. + *
  19209. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19210. + * GNU General Public License ("GPL") version 2, as published by the Free
  19211. + * Software Foundation.
  19212. + *
  19213. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19214. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19215. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19216. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19217. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19218. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19219. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19220. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19221. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19222. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19223. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19224. + */
  19225. +
  19226. +#include <linux/kernel.h>
  19227. +#include <linux/module.h>
  19228. +#include <linux/kthread.h>
  19229. +#include <linux/fs.h>
  19230. +#include <linux/device.h>
  19231. +#include <linux/cdev.h>
  19232. +#include <linux/mm.h>
  19233. +#include <linux/proc_fs.h>
  19234. +#include <linux/seq_file.h>
  19235. +#include <linux/dma-mapping.h>
  19236. +#include <linux/dma-contiguous.h>
  19237. +#include <linux/platform_device.h>
  19238. +#include <linux/uaccess.h>
  19239. +#include <asm/cacheflush.h>
  19240. +
  19241. +#include "vc_cma.h"
  19242. +
  19243. +#include "vchiq_util.h"
  19244. +#include "vchiq_connected.h"
  19245. +//#include "debug_sym.h"
  19246. +//#include "vc_mem.h"
  19247. +
  19248. +#define DRIVER_NAME "vc-cma"
  19249. +
  19250. +#define LOG_DBG(fmt, ...) \
  19251. + if (vc_cma_debug) \
  19252. + printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
  19253. +#define LOG_ERR(fmt, ...) \
  19254. + printk(KERN_ERR fmt "\n", ##__VA_ARGS__)
  19255. +
  19256. +#define VC_CMA_FOURCC VCHIQ_MAKE_FOURCC('C', 'M', 'A', ' ')
  19257. +#define VC_CMA_VERSION 2
  19258. +
  19259. +#define VC_CMA_CHUNK_ORDER 6 /* 256K */
  19260. +#define VC_CMA_CHUNK_SIZE (4096 << VC_CMA_CHUNK_ORDER)
  19261. +#define VC_CMA_MAX_PARAMS_PER_MSG \
  19262. + ((VCHIQ_MAX_MSG_SIZE - sizeof(unsigned short))/sizeof(unsigned short))
  19263. +#define VC_CMA_RESERVE_COUNT_MAX 16
  19264. +
  19265. +#define PAGES_PER_CHUNK (VC_CMA_CHUNK_SIZE / PAGE_SIZE)
  19266. +
  19267. +#define VCADDR_TO_PHYSADDR(vcaddr) (mm_vc_mem_phys_addr + vcaddr)
  19268. +
  19269. +#define loud_error(...) \
  19270. + LOG_ERR("===== " __VA_ARGS__)
  19271. +
  19272. +enum {
  19273. + VC_CMA_MSG_QUIT,
  19274. + VC_CMA_MSG_OPEN,
  19275. + VC_CMA_MSG_TICK,
  19276. + VC_CMA_MSG_ALLOC, /* chunk count */
  19277. + VC_CMA_MSG_FREE, /* chunk, chunk, ... */
  19278. + VC_CMA_MSG_ALLOCATED, /* chunk, chunk, ... */
  19279. + VC_CMA_MSG_REQUEST_ALLOC, /* chunk count */
  19280. + VC_CMA_MSG_REQUEST_FREE, /* chunk count */
  19281. + VC_CMA_MSG_RESERVE, /* bytes lo, bytes hi */
  19282. + VC_CMA_MSG_UPDATE_RESERVE,
  19283. + VC_CMA_MSG_MAX
  19284. +};
  19285. +
  19286. +struct cma_msg {
  19287. + unsigned short type;
  19288. + unsigned short params[VC_CMA_MAX_PARAMS_PER_MSG];
  19289. +};
  19290. +
  19291. +struct vc_cma_reserve_user {
  19292. + unsigned int pid;
  19293. + unsigned int reserve;
  19294. +};
  19295. +
  19296. +/* Device (/dev) related variables */
  19297. +static dev_t vc_cma_devnum;
  19298. +static struct class *vc_cma_class;
  19299. +static struct cdev vc_cma_cdev;
  19300. +static int vc_cma_inited;
  19301. +static int vc_cma_debug;
  19302. +
  19303. +/* Proc entry */
  19304. +static struct proc_dir_entry *vc_cma_proc_entry;
  19305. +
  19306. +phys_addr_t vc_cma_base;
  19307. +struct page *vc_cma_base_page;
  19308. +unsigned int vc_cma_size;
  19309. +EXPORT_SYMBOL(vc_cma_size);
  19310. +unsigned int vc_cma_initial;
  19311. +unsigned int vc_cma_chunks;
  19312. +unsigned int vc_cma_chunks_used;
  19313. +unsigned int vc_cma_chunks_reserved;
  19314. +
  19315. +static int in_loud_error;
  19316. +
  19317. +unsigned int vc_cma_reserve_total;
  19318. +unsigned int vc_cma_reserve_count;
  19319. +struct vc_cma_reserve_user vc_cma_reserve_users[VC_CMA_RESERVE_COUNT_MAX];
  19320. +static DEFINE_SEMAPHORE(vc_cma_reserve_mutex);
  19321. +static DEFINE_SEMAPHORE(vc_cma_worker_queue_push_mutex);
  19322. +
  19323. +static u64 vc_cma_dma_mask = DMA_BIT_MASK(32);
  19324. +static struct platform_device vc_cma_device = {
  19325. + .name = "vc-cma",
  19326. + .id = 0,
  19327. + .dev = {
  19328. + .dma_mask = &vc_cma_dma_mask,
  19329. + .coherent_dma_mask = DMA_BIT_MASK(32),
  19330. + },
  19331. +};
  19332. +
  19333. +static VCHIQ_INSTANCE_T cma_instance;
  19334. +static VCHIQ_SERVICE_HANDLE_T cma_service;
  19335. +static VCHIU_QUEUE_T cma_msg_queue;
  19336. +static struct task_struct *cma_worker;
  19337. +
  19338. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid);
  19339. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply);
  19340. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  19341. + VCHIQ_HEADER_T * header,
  19342. + VCHIQ_SERVICE_HANDLE_T service,
  19343. + void *bulk_userdata);
  19344. +static void send_vc_msg(unsigned short type,
  19345. + unsigned short param1, unsigned short param2);
  19346. +static bool send_worker_msg(VCHIQ_HEADER_T * msg);
  19347. +
  19348. +static int early_vc_cma_mem(char *p)
  19349. +{
  19350. + unsigned int new_size;
  19351. + printk(KERN_NOTICE "early_vc_cma_mem(%s)", p);
  19352. + vc_cma_size = memparse(p, &p);
  19353. + vc_cma_initial = vc_cma_size;
  19354. + if (*p == '/')
  19355. + vc_cma_size = memparse(p + 1, &p);
  19356. + if (*p == '@')
  19357. + vc_cma_base = memparse(p + 1, &p);
  19358. +
  19359. + new_size = (vc_cma_size - ((-vc_cma_base) & (VC_CMA_CHUNK_SIZE - 1)))
  19360. + & ~(VC_CMA_CHUNK_SIZE - 1);
  19361. + if (new_size > vc_cma_size)
  19362. + vc_cma_size = 0;
  19363. + vc_cma_initial = (vc_cma_initial + VC_CMA_CHUNK_SIZE - 1)
  19364. + & ~(VC_CMA_CHUNK_SIZE - 1);
  19365. + if (vc_cma_initial > vc_cma_size)
  19366. + vc_cma_initial = vc_cma_size;
  19367. + vc_cma_base = (vc_cma_base + VC_CMA_CHUNK_SIZE - 1)
  19368. + & ~(VC_CMA_CHUNK_SIZE - 1);
  19369. +
  19370. + printk(KERN_NOTICE " -> initial %x, size %x, base %x", vc_cma_initial,
  19371. + vc_cma_size, (unsigned int)vc_cma_base);
  19372. +
  19373. + return 0;
  19374. +}
  19375. +
  19376. +early_param("vc-cma-mem", early_vc_cma_mem);
  19377. +
  19378. +void vc_cma_early_init(void)
  19379. +{
  19380. + LOG_DBG("vc_cma_early_init - vc_cma_chunks = %d", vc_cma_chunks);
  19381. + if (vc_cma_size) {
  19382. + int rc = platform_device_register(&vc_cma_device);
  19383. + LOG_DBG("platform_device_register -> %d", rc);
  19384. + }
  19385. +}
  19386. +
  19387. +void vc_cma_reserve(void)
  19388. +{
  19389. + /* if vc_cma_size is set, then declare vc CMA area of the same
  19390. + * size from the end of memory
  19391. + */
  19392. + if (vc_cma_size) {
  19393. + if (dma_declare_contiguous(NULL /*&vc_cma_device.dev*/, vc_cma_size,
  19394. + vc_cma_base, 0) == 0) {
  19395. + } else {
  19396. + LOG_ERR("vc_cma: dma_declare_contiguous(%x,%x) failed",
  19397. + vc_cma_size, (unsigned int)vc_cma_base);
  19398. + vc_cma_size = 0;
  19399. + }
  19400. + }
  19401. + vc_cma_chunks = vc_cma_size / VC_CMA_CHUNK_SIZE;
  19402. +}
  19403. +
  19404. +/****************************************************************************
  19405. +*
  19406. +* vc_cma_open
  19407. +*
  19408. +***************************************************************************/
  19409. +
  19410. +static int vc_cma_open(struct inode *inode, struct file *file)
  19411. +{
  19412. + (void)inode;
  19413. + (void)file;
  19414. +
  19415. + return 0;
  19416. +}
  19417. +
  19418. +/****************************************************************************
  19419. +*
  19420. +* vc_cma_release
  19421. +*
  19422. +***************************************************************************/
  19423. +
  19424. +static int vc_cma_release(struct inode *inode, struct file *file)
  19425. +{
  19426. + (void)inode;
  19427. + (void)file;
  19428. +
  19429. + vc_cma_set_reserve(0, current->tgid);
  19430. +
  19431. + return 0;
  19432. +}
  19433. +
  19434. +/****************************************************************************
  19435. +*
  19436. +* vc_cma_ioctl
  19437. +*
  19438. +***************************************************************************/
  19439. +
  19440. +static long vc_cma_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  19441. +{
  19442. + int rc = 0;
  19443. +
  19444. + (void)cmd;
  19445. + (void)arg;
  19446. +
  19447. + switch (cmd) {
  19448. + case VC_CMA_IOC_RESERVE:
  19449. + rc = vc_cma_set_reserve((unsigned int)arg, current->tgid);
  19450. + if (rc >= 0)
  19451. + rc = 0;
  19452. + break;
  19453. + default:
  19454. + LOG_ERR("vc-cma: Unknown ioctl %x", cmd);
  19455. + return -ENOTTY;
  19456. + }
  19457. +
  19458. + return rc;
  19459. +}
  19460. +
  19461. +/****************************************************************************
  19462. +*
  19463. +* File Operations for the driver.
  19464. +*
  19465. +***************************************************************************/
  19466. +
  19467. +static const struct file_operations vc_cma_fops = {
  19468. + .owner = THIS_MODULE,
  19469. + .open = vc_cma_open,
  19470. + .release = vc_cma_release,
  19471. + .unlocked_ioctl = vc_cma_ioctl,
  19472. +};
  19473. +
  19474. +/****************************************************************************
  19475. +*
  19476. +* vc_cma_proc_open
  19477. +*
  19478. +***************************************************************************/
  19479. +
  19480. +static int vc_cma_show_info(struct seq_file *m, void *v)
  19481. +{
  19482. + int i;
  19483. +
  19484. + seq_printf(m, "Videocore CMA:\n");
  19485. + seq_printf(m, " Base : %08x\n", (unsigned int)vc_cma_base);
  19486. + seq_printf(m, " Length : %08x\n", vc_cma_size);
  19487. + seq_printf(m, " Initial : %08x\n", vc_cma_initial);
  19488. + seq_printf(m, " Chunk size : %08x\n", VC_CMA_CHUNK_SIZE);
  19489. + seq_printf(m, " Chunks : %4d (%d bytes)\n",
  19490. + (int)vc_cma_chunks,
  19491. + (int)(vc_cma_chunks * VC_CMA_CHUNK_SIZE));
  19492. + seq_printf(m, " Used : %4d (%d bytes)\n",
  19493. + (int)vc_cma_chunks_used,
  19494. + (int)(vc_cma_chunks_used * VC_CMA_CHUNK_SIZE));
  19495. + seq_printf(m, " Reserved : %4d (%d bytes)\n",
  19496. + (unsigned int)vc_cma_chunks_reserved,
  19497. + (int)(vc_cma_chunks_reserved * VC_CMA_CHUNK_SIZE));
  19498. +
  19499. + for (i = 0; i < vc_cma_reserve_count; i++) {
  19500. + struct vc_cma_reserve_user *user = &vc_cma_reserve_users[i];
  19501. + seq_printf(m, " PID %5d: %d bytes\n", user->pid,
  19502. + user->reserve);
  19503. + }
  19504. +
  19505. + seq_printf(m, "\n");
  19506. +
  19507. + return 0;
  19508. +}
  19509. +
  19510. +static int vc_cma_proc_open(struct inode *inode, struct file *file)
  19511. +{
  19512. + return single_open(file, vc_cma_show_info, NULL);
  19513. +}
  19514. +
  19515. +/****************************************************************************
  19516. +*
  19517. +* vc_cma_proc_write
  19518. +*
  19519. +***************************************************************************/
  19520. +
  19521. +static int vc_cma_proc_write(struct file *file,
  19522. + const char __user *buffer,
  19523. + size_t size, loff_t *ppos)
  19524. +{
  19525. + int rc = -EFAULT;
  19526. + char input_str[20];
  19527. +
  19528. + memset(input_str, 0, sizeof(input_str));
  19529. +
  19530. + if (size > sizeof(input_str)) {
  19531. + LOG_ERR("%s: input string length too long", __func__);
  19532. + goto out;
  19533. + }
  19534. +
  19535. + if (copy_from_user(input_str, buffer, size - 1)) {
  19536. + LOG_ERR("%s: failed to get input string", __func__);
  19537. + goto out;
  19538. + }
  19539. +#define ALLOC_STR "alloc"
  19540. +#define FREE_STR "free"
  19541. +#define DEBUG_STR "debug"
  19542. +#define RESERVE_STR "reserve"
  19543. + if (strncmp(input_str, ALLOC_STR, strlen(ALLOC_STR)) == 0) {
  19544. + int size;
  19545. + char *p = input_str + strlen(ALLOC_STR);
  19546. +
  19547. + while (*p == ' ')
  19548. + p++;
  19549. + size = memparse(p, NULL);
  19550. + LOG_ERR("/proc/vc-cma: alloc %d", size);
  19551. + if (size)
  19552. + send_vc_msg(VC_CMA_MSG_REQUEST_FREE,
  19553. + size / VC_CMA_CHUNK_SIZE, 0);
  19554. + else
  19555. + LOG_ERR("invalid size '%s'", p);
  19556. + rc = size;
  19557. + } else if (strncmp(input_str, FREE_STR, strlen(FREE_STR)) == 0) {
  19558. + int size;
  19559. + char *p = input_str + strlen(FREE_STR);
  19560. +
  19561. + while (*p == ' ')
  19562. + p++;
  19563. + size = memparse(p, NULL);
  19564. + LOG_ERR("/proc/vc-cma: free %d", size);
  19565. + if (size)
  19566. + send_vc_msg(VC_CMA_MSG_REQUEST_ALLOC,
  19567. + size / VC_CMA_CHUNK_SIZE, 0);
  19568. + else
  19569. + LOG_ERR("invalid size '%s'", p);
  19570. + rc = size;
  19571. + } else if (strncmp(input_str, DEBUG_STR, strlen(DEBUG_STR)) == 0) {
  19572. + char *p = input_str + strlen(DEBUG_STR);
  19573. + while (*p == ' ')
  19574. + p++;
  19575. + if ((strcmp(p, "on") == 0) || (strcmp(p, "1") == 0))
  19576. + vc_cma_debug = 1;
  19577. + else if ((strcmp(p, "off") == 0) || (strcmp(p, "0") == 0))
  19578. + vc_cma_debug = 0;
  19579. + LOG_ERR("/proc/vc-cma: debug %s", vc_cma_debug ? "on" : "off");
  19580. + rc = size;
  19581. + } else if (strncmp(input_str, RESERVE_STR, strlen(RESERVE_STR)) == 0) {
  19582. + int size;
  19583. + int reserved;
  19584. + char *p = input_str + strlen(RESERVE_STR);
  19585. + while (*p == ' ')
  19586. + p++;
  19587. + size = memparse(p, NULL);
  19588. +
  19589. + reserved = vc_cma_set_reserve(size, current->tgid);
  19590. + rc = (reserved >= 0) ? size : reserved;
  19591. + }
  19592. +
  19593. +out:
  19594. + return rc;
  19595. +}
  19596. +
  19597. +/****************************************************************************
  19598. +*
  19599. +* File Operations for /proc interface.
  19600. +*
  19601. +***************************************************************************/
  19602. +
  19603. +static const struct file_operations vc_cma_proc_fops = {
  19604. + .open = vc_cma_proc_open,
  19605. + .read = seq_read,
  19606. + .write = vc_cma_proc_write,
  19607. + .llseek = seq_lseek,
  19608. + .release = single_release
  19609. +};
  19610. +
  19611. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid)
  19612. +{
  19613. + struct vc_cma_reserve_user *user = NULL;
  19614. + int delta = 0;
  19615. + int i;
  19616. +
  19617. + if (down_interruptible(&vc_cma_reserve_mutex))
  19618. + return -ERESTARTSYS;
  19619. +
  19620. + for (i = 0; i < vc_cma_reserve_count; i++) {
  19621. + if (pid == vc_cma_reserve_users[i].pid) {
  19622. + user = &vc_cma_reserve_users[i];
  19623. + delta = reserve - user->reserve;
  19624. + if (reserve)
  19625. + user->reserve = reserve;
  19626. + else {
  19627. + /* Remove this entry by copying downwards */
  19628. + while ((i + 1) < vc_cma_reserve_count) {
  19629. + user[0].pid = user[1].pid;
  19630. + user[0].reserve = user[1].reserve;
  19631. + user++;
  19632. + i++;
  19633. + }
  19634. + vc_cma_reserve_count--;
  19635. + user = NULL;
  19636. + }
  19637. + break;
  19638. + }
  19639. + }
  19640. +
  19641. + if (reserve && !user) {
  19642. + if (vc_cma_reserve_count == VC_CMA_RESERVE_COUNT_MAX) {
  19643. + LOG_ERR("vc-cma: Too many reservations - "
  19644. + "increase CMA_RESERVE_COUNT_MAX");
  19645. + up(&vc_cma_reserve_mutex);
  19646. + return -EBUSY;
  19647. + }
  19648. + user = &vc_cma_reserve_users[vc_cma_reserve_count];
  19649. + user->pid = pid;
  19650. + user->reserve = reserve;
  19651. + delta = reserve;
  19652. + vc_cma_reserve_count++;
  19653. + }
  19654. +
  19655. + vc_cma_reserve_total += delta;
  19656. +
  19657. + send_vc_msg(VC_CMA_MSG_RESERVE,
  19658. + vc_cma_reserve_total & 0xffff, vc_cma_reserve_total >> 16);
  19659. +
  19660. + send_worker_msg((VCHIQ_HEADER_T *) VC_CMA_MSG_UPDATE_RESERVE);
  19661. +
  19662. + LOG_DBG("/proc/vc-cma: reserve %d (PID %d) - total %u",
  19663. + reserve, pid, vc_cma_reserve_total);
  19664. +
  19665. + up(&vc_cma_reserve_mutex);
  19666. +
  19667. + return vc_cma_reserve_total;
  19668. +}
  19669. +
  19670. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  19671. + VCHIQ_HEADER_T * header,
  19672. + VCHIQ_SERVICE_HANDLE_T service,
  19673. + void *bulk_userdata)
  19674. +{
  19675. + switch (reason) {
  19676. + case VCHIQ_MESSAGE_AVAILABLE:
  19677. + if (!send_worker_msg(header))
  19678. + return VCHIQ_RETRY;
  19679. + break;
  19680. + case VCHIQ_SERVICE_CLOSED:
  19681. + LOG_DBG("CMA service closed");
  19682. + break;
  19683. + default:
  19684. + LOG_ERR("Unexpected CMA callback reason %d", reason);
  19685. + break;
  19686. + }
  19687. + return VCHIQ_SUCCESS;
  19688. +}
  19689. +
  19690. +static void send_vc_msg(unsigned short type,
  19691. + unsigned short param1, unsigned short param2)
  19692. +{
  19693. + unsigned short msg[] = { type, param1, param2 };
  19694. + VCHIQ_ELEMENT_T elem = { &msg, sizeof(msg) };
  19695. + VCHIQ_STATUS_T ret;
  19696. + vchiq_use_service(cma_service);
  19697. + ret = vchiq_queue_message(cma_service, &elem, 1);
  19698. + vchiq_release_service(cma_service);
  19699. + if (ret != VCHIQ_SUCCESS)
  19700. + LOG_ERR("vchiq_queue_message returned %x", ret);
  19701. +}
  19702. +
  19703. +static bool send_worker_msg(VCHIQ_HEADER_T * msg)
  19704. +{
  19705. + if (down_interruptible(&vc_cma_worker_queue_push_mutex))
  19706. + return false;
  19707. + vchiu_queue_push(&cma_msg_queue, msg);
  19708. + up(&vc_cma_worker_queue_push_mutex);
  19709. + return true;
  19710. +}
  19711. +
  19712. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply)
  19713. +{
  19714. + int i;
  19715. + for (i = 0; i < num_chunks; i++) {
  19716. + struct page *chunk;
  19717. + unsigned int chunk_num;
  19718. + uint8_t *chunk_addr;
  19719. + size_t chunk_size = PAGES_PER_CHUNK << PAGE_SHIFT;
  19720. +
  19721. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  19722. + PAGES_PER_CHUNK,
  19723. + VC_CMA_CHUNK_ORDER);
  19724. + if (!chunk)
  19725. + break;
  19726. +
  19727. + chunk_addr = page_address(chunk);
  19728. + dmac_flush_range(chunk_addr, chunk_addr + chunk_size);
  19729. + outer_inv_range(__pa(chunk_addr), __pa(chunk_addr) +
  19730. + chunk_size);
  19731. +
  19732. + chunk_num =
  19733. + (page_to_phys(chunk) - vc_cma_base) / VC_CMA_CHUNK_SIZE;
  19734. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  19735. + VC_CMA_CHUNK_SIZE) != 0);
  19736. + if (chunk_num >= vc_cma_chunks) {
  19737. + LOG_ERR("%s: ===============================",
  19738. + __func__);
  19739. + LOG_ERR("%s: chunk phys %x, vc_cma %x-%x - "
  19740. + "bad SPARSEMEM configuration?",
  19741. + __func__, (unsigned int)page_to_phys(chunk),
  19742. + vc_cma_base, vc_cma_base + vc_cma_size - 1);
  19743. + LOG_ERR("%s: dev->cma_area = %p\n", __func__,
  19744. + (void*)0/*vc_cma_device.dev.cma_area*/);
  19745. + LOG_ERR("%s: ===============================",
  19746. + __func__);
  19747. + break;
  19748. + }
  19749. + reply->params[i] = chunk_num;
  19750. + vc_cma_chunks_used++;
  19751. + }
  19752. +
  19753. + if (i < num_chunks) {
  19754. + LOG_ERR("%s: dma_alloc_from_contiguous failed "
  19755. + "for %x bytes (alloc %d of %d, %d free)",
  19756. + __func__, VC_CMA_CHUNK_SIZE, i,
  19757. + num_chunks, vc_cma_chunks - vc_cma_chunks_used);
  19758. + num_chunks = i;
  19759. + }
  19760. +
  19761. + LOG_DBG("CMA allocated %d chunks -> %d used",
  19762. + num_chunks, vc_cma_chunks_used);
  19763. + reply->type = VC_CMA_MSG_ALLOCATED;
  19764. +
  19765. + {
  19766. + VCHIQ_ELEMENT_T elem = {
  19767. + reply,
  19768. + offsetof(struct cma_msg, params[0]) +
  19769. + num_chunks * sizeof(reply->params[0])
  19770. + };
  19771. + VCHIQ_STATUS_T ret;
  19772. + vchiq_use_service(cma_service);
  19773. + ret = vchiq_queue_message(cma_service, &elem, 1);
  19774. + vchiq_release_service(cma_service);
  19775. + if (ret != VCHIQ_SUCCESS)
  19776. + LOG_ERR("vchiq_queue_message return " "%x", ret);
  19777. + }
  19778. +
  19779. + return num_chunks;
  19780. +}
  19781. +
  19782. +static int cma_worker_proc(void *param)
  19783. +{
  19784. + static struct cma_msg reply;
  19785. + (void)param;
  19786. +
  19787. + while (1) {
  19788. + VCHIQ_HEADER_T *msg;
  19789. + static struct cma_msg msg_copy;
  19790. + struct cma_msg *cma_msg = &msg_copy;
  19791. + int type, msg_size;
  19792. +
  19793. + msg = vchiu_queue_pop(&cma_msg_queue);
  19794. + if ((unsigned int)msg >= VC_CMA_MSG_MAX) {
  19795. + msg_size = msg->size;
  19796. + memcpy(&msg_copy, msg->data, msg_size);
  19797. + type = cma_msg->type;
  19798. + vchiq_release_message(cma_service, msg);
  19799. + } else {
  19800. + msg_size = 0;
  19801. + type = (int)msg;
  19802. + if (type == VC_CMA_MSG_QUIT)
  19803. + break;
  19804. + else if (type == VC_CMA_MSG_UPDATE_RESERVE) {
  19805. + msg = NULL;
  19806. + cma_msg = NULL;
  19807. + } else {
  19808. + BUG();
  19809. + continue;
  19810. + }
  19811. + }
  19812. +
  19813. + switch (type) {
  19814. + case VC_CMA_MSG_ALLOC:{
  19815. + int num_chunks, free_chunks;
  19816. + num_chunks = cma_msg->params[0];
  19817. + free_chunks =
  19818. + vc_cma_chunks - vc_cma_chunks_used;
  19819. + LOG_DBG("CMA_MSG_ALLOC(%d chunks)", num_chunks);
  19820. + if (num_chunks > VC_CMA_MAX_PARAMS_PER_MSG) {
  19821. + LOG_ERR
  19822. + ("CMA_MSG_ALLOC - chunk count (%d) "
  19823. + "exceeds VC_CMA_MAX_PARAMS_PER_MSG (%d)",
  19824. + num_chunks,
  19825. + VC_CMA_MAX_PARAMS_PER_MSG);
  19826. + num_chunks = VC_CMA_MAX_PARAMS_PER_MSG;
  19827. + }
  19828. +
  19829. + if (num_chunks > free_chunks) {
  19830. + LOG_ERR
  19831. + ("CMA_MSG_ALLOC - chunk count (%d) "
  19832. + "exceeds free chunks (%d)",
  19833. + num_chunks, free_chunks);
  19834. + num_chunks = free_chunks;
  19835. + }
  19836. +
  19837. + vc_cma_alloc_chunks(num_chunks, &reply);
  19838. + }
  19839. + break;
  19840. +
  19841. + case VC_CMA_MSG_FREE:{
  19842. + int chunk_count =
  19843. + (msg_size -
  19844. + offsetof(struct cma_msg,
  19845. + params)) /
  19846. + sizeof(cma_msg->params[0]);
  19847. + int i;
  19848. + BUG_ON(chunk_count <= 0);
  19849. +
  19850. + LOG_DBG("CMA_MSG_FREE(%d chunks - %x, ...)",
  19851. + chunk_count, cma_msg->params[0]);
  19852. + for (i = 0; i < chunk_count; i++) {
  19853. + int chunk_num = cma_msg->params[i];
  19854. + struct page *page = vc_cma_base_page +
  19855. + chunk_num * PAGES_PER_CHUNK;
  19856. + if (chunk_num >= vc_cma_chunks) {
  19857. + LOG_ERR
  19858. + ("CMA_MSG_FREE - chunk %d of %d"
  19859. + " (value %x) exceeds maximum "
  19860. + "(%x)", i, chunk_count,
  19861. + chunk_num,
  19862. + vc_cma_chunks - 1);
  19863. + break;
  19864. + }
  19865. +
  19866. + if (!dma_release_from_contiguous
  19867. + (NULL /*&vc_cma_device.dev*/, page,
  19868. + PAGES_PER_CHUNK)) {
  19869. + LOG_ERR
  19870. + ("CMA_MSG_FREE - failed to "
  19871. + "release chunk %d (phys %x, "
  19872. + "page %x)", chunk_num,
  19873. + page_to_phys(page),
  19874. + (unsigned int)page);
  19875. + }
  19876. + vc_cma_chunks_used--;
  19877. + }
  19878. + LOG_DBG("CMA released %d chunks -> %d used",
  19879. + i, vc_cma_chunks_used);
  19880. + }
  19881. + break;
  19882. +
  19883. + case VC_CMA_MSG_UPDATE_RESERVE:{
  19884. + int chunks_needed =
  19885. + ((vc_cma_reserve_total + VC_CMA_CHUNK_SIZE -
  19886. + 1)
  19887. + / VC_CMA_CHUNK_SIZE) -
  19888. + vc_cma_chunks_reserved;
  19889. +
  19890. + LOG_DBG
  19891. + ("CMA_MSG_UPDATE_RESERVE(%d chunks needed)",
  19892. + chunks_needed);
  19893. +
  19894. + /* Cap the reservations to what is available */
  19895. + if (chunks_needed > 0) {
  19896. + if (chunks_needed >
  19897. + (vc_cma_chunks -
  19898. + vc_cma_chunks_used))
  19899. + chunks_needed =
  19900. + (vc_cma_chunks -
  19901. + vc_cma_chunks_used);
  19902. +
  19903. + chunks_needed =
  19904. + vc_cma_alloc_chunks(chunks_needed,
  19905. + &reply);
  19906. + }
  19907. +
  19908. + LOG_DBG
  19909. + ("CMA_MSG_UPDATE_RESERVE(%d chunks allocated)",
  19910. + chunks_needed);
  19911. + vc_cma_chunks_reserved += chunks_needed;
  19912. + }
  19913. + break;
  19914. +
  19915. + default:
  19916. + LOG_ERR("unexpected msg type %d", type);
  19917. + break;
  19918. + }
  19919. + }
  19920. +
  19921. + LOG_DBG("quitting...");
  19922. + return 0;
  19923. +}
  19924. +
  19925. +/****************************************************************************
  19926. +*
  19927. +* vc_cma_connected_init
  19928. +*
  19929. +* This function is called once the videocore has been connected.
  19930. +*
  19931. +***************************************************************************/
  19932. +
  19933. +static void vc_cma_connected_init(void)
  19934. +{
  19935. + VCHIQ_SERVICE_PARAMS_T service_params;
  19936. +
  19937. + LOG_DBG("vc_cma_connected_init");
  19938. +
  19939. + if (!vchiu_queue_init(&cma_msg_queue, 16)) {
  19940. + LOG_ERR("could not create CMA msg queue");
  19941. + goto fail_queue;
  19942. + }
  19943. +
  19944. + if (vchiq_initialise(&cma_instance) != VCHIQ_SUCCESS)
  19945. + goto fail_vchiq_init;
  19946. +
  19947. + vchiq_connect(cma_instance);
  19948. +
  19949. + service_params.fourcc = VC_CMA_FOURCC;
  19950. + service_params.callback = cma_service_callback;
  19951. + service_params.userdata = NULL;
  19952. + service_params.version = VC_CMA_VERSION;
  19953. + service_params.version_min = VC_CMA_VERSION;
  19954. +
  19955. + if (vchiq_open_service(cma_instance, &service_params,
  19956. + &cma_service) != VCHIQ_SUCCESS) {
  19957. + LOG_ERR("failed to open service - already in use?");
  19958. + goto fail_vchiq_open;
  19959. + }
  19960. +
  19961. + vchiq_release_service(cma_service);
  19962. +
  19963. + cma_worker = kthread_create(cma_worker_proc, NULL, "cma_worker");
  19964. + if (!cma_worker) {
  19965. + LOG_ERR("could not create CMA worker thread");
  19966. + goto fail_worker;
  19967. + }
  19968. + set_user_nice(cma_worker, -20);
  19969. + wake_up_process(cma_worker);
  19970. +
  19971. + return;
  19972. +
  19973. +fail_worker:
  19974. + vchiq_close_service(cma_service);
  19975. +fail_vchiq_open:
  19976. + vchiq_shutdown(cma_instance);
  19977. +fail_vchiq_init:
  19978. + vchiu_queue_delete(&cma_msg_queue);
  19979. +fail_queue:
  19980. + return;
  19981. +}
  19982. +
  19983. +void
  19984. +loud_error_header(void)
  19985. +{
  19986. + if (in_loud_error)
  19987. + return;
  19988. +
  19989. + LOG_ERR("============================================================"
  19990. + "================");
  19991. + LOG_ERR("============================================================"
  19992. + "================");
  19993. + LOG_ERR("=====");
  19994. +
  19995. + in_loud_error = 1;
  19996. +}
  19997. +
  19998. +void
  19999. +loud_error_footer(void)
  20000. +{
  20001. + if (!in_loud_error)
  20002. + return;
  20003. +
  20004. + LOG_ERR("=====");
  20005. + LOG_ERR("============================================================"
  20006. + "================");
  20007. + LOG_ERR("============================================================"
  20008. + "================");
  20009. +
  20010. + in_loud_error = 0;
  20011. +}
  20012. +
  20013. +#if 1
  20014. +static int check_cma_config(void) { return 1; }
  20015. +#else
  20016. +static int
  20017. +read_vc_debug_var(VC_MEM_ACCESS_HANDLE_T handle,
  20018. + const char *symbol,
  20019. + void *buf, size_t bufsize)
  20020. +{
  20021. + VC_MEM_ADDR_T vcMemAddr;
  20022. + size_t vcMemSize;
  20023. + uint8_t *mapAddr;
  20024. + off_t vcMapAddr;
  20025. +
  20026. + if (!LookupVideoCoreSymbol(handle, symbol,
  20027. + &vcMemAddr,
  20028. + &vcMemSize)) {
  20029. + loud_error_header();
  20030. + loud_error(
  20031. + "failed to find VC symbol \"%s\".",
  20032. + symbol);
  20033. + loud_error_footer();
  20034. + return 0;
  20035. + }
  20036. +
  20037. + if (vcMemSize != bufsize) {
  20038. + loud_error_header();
  20039. + loud_error(
  20040. + "VC symbol \"%s\" is the wrong size.",
  20041. + symbol);
  20042. + loud_error_footer();
  20043. + return 0;
  20044. + }
  20045. +
  20046. + vcMapAddr = (off_t)vcMemAddr & VC_MEM_TO_ARM_ADDR_MASK;
  20047. + vcMapAddr += mm_vc_mem_phys_addr;
  20048. + mapAddr = ioremap_nocache(vcMapAddr, vcMemSize);
  20049. + if (mapAddr == 0) {
  20050. + loud_error_header();
  20051. + loud_error(
  20052. + "failed to ioremap \"%s\" @ 0x%x "
  20053. + "(phys: 0x%x, size: %u).",
  20054. + symbol,
  20055. + (unsigned int)vcMapAddr,
  20056. + (unsigned int)vcMemAddr,
  20057. + (unsigned int)vcMemSize);
  20058. + loud_error_footer();
  20059. + return 0;
  20060. + }
  20061. +
  20062. + memcpy(buf, mapAddr, bufsize);
  20063. + iounmap(mapAddr);
  20064. +
  20065. + return 1;
  20066. +}
  20067. +
  20068. +
  20069. +static int
  20070. +check_cma_config(void)
  20071. +{
  20072. + VC_MEM_ACCESS_HANDLE_T mem_hndl;
  20073. + VC_MEM_ADDR_T mempool_start;
  20074. + VC_MEM_ADDR_T mempool_end;
  20075. + VC_MEM_ADDR_T mempool_offline_start;
  20076. + VC_MEM_ADDR_T mempool_offline_end;
  20077. + VC_MEM_ADDR_T cam_alloc_base;
  20078. + VC_MEM_ADDR_T cam_alloc_size;
  20079. + VC_MEM_ADDR_T cam_alloc_end;
  20080. + int success = 0;
  20081. +
  20082. + if (OpenVideoCoreMemory(&mem_hndl) != 0)
  20083. + goto out;
  20084. +
  20085. + /* Read the relevant VideoCore variables */
  20086. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_START",
  20087. + &mempool_start,
  20088. + sizeof(mempool_start)))
  20089. + goto close;
  20090. +
  20091. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_END",
  20092. + &mempool_end,
  20093. + sizeof(mempool_end)))
  20094. + goto close;
  20095. +
  20096. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_START",
  20097. + &mempool_offline_start,
  20098. + sizeof(mempool_offline_start)))
  20099. + goto close;
  20100. +
  20101. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_END",
  20102. + &mempool_offline_end,
  20103. + sizeof(mempool_offline_end)))
  20104. + goto close;
  20105. +
  20106. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_base",
  20107. + &cam_alloc_base,
  20108. + sizeof(cam_alloc_base)))
  20109. + goto close;
  20110. +
  20111. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_size",
  20112. + &cam_alloc_size,
  20113. + sizeof(cam_alloc_size)))
  20114. + goto close;
  20115. +
  20116. + cam_alloc_end = cam_alloc_base + cam_alloc_size;
  20117. +
  20118. + success = 1;
  20119. +
  20120. + /* Now the sanity checks */
  20121. + if (!mempool_offline_start)
  20122. + mempool_offline_start = mempool_start;
  20123. + if (!mempool_offline_end)
  20124. + mempool_offline_end = mempool_end;
  20125. +
  20126. + if (VCADDR_TO_PHYSADDR(mempool_offline_start) != vc_cma_base) {
  20127. + loud_error_header();
  20128. + loud_error(
  20129. + "__MEMPOOL_OFFLINE_START(%x -> %lx) doesn't match "
  20130. + "vc_cma_base(%x)",
  20131. + mempool_offline_start,
  20132. + VCADDR_TO_PHYSADDR(mempool_offline_start),
  20133. + vc_cma_base);
  20134. + success = 0;
  20135. + }
  20136. +
  20137. + if (VCADDR_TO_PHYSADDR(mempool_offline_end) !=
  20138. + (vc_cma_base + vc_cma_size)) {
  20139. + loud_error_header();
  20140. + loud_error(
  20141. + "__MEMPOOL_OFFLINE_END(%x -> %lx) doesn't match "
  20142. + "vc_cma_base(%x) + vc_cma_size(%x) = %x",
  20143. + mempool_offline_start,
  20144. + VCADDR_TO_PHYSADDR(mempool_offline_end),
  20145. + vc_cma_base, vc_cma_size, vc_cma_base + vc_cma_size);
  20146. + success = 0;
  20147. + }
  20148. +
  20149. + if (mempool_end < mempool_start) {
  20150. + loud_error_header();
  20151. + loud_error(
  20152. + "__MEMPOOL_END(%x) must not be before "
  20153. + "__MEMPOOL_START(%x)",
  20154. + mempool_end,
  20155. + mempool_start);
  20156. + success = 0;
  20157. + }
  20158. +
  20159. + if (mempool_offline_end < mempool_offline_start) {
  20160. + loud_error_header();
  20161. + loud_error(
  20162. + "__MEMPOOL_OFFLINE_END(%x) must not be before "
  20163. + "__MEMPOOL_OFFLINE_START(%x)",
  20164. + mempool_offline_end,
  20165. + mempool_offline_start);
  20166. + success = 0;
  20167. + }
  20168. +
  20169. + if (mempool_offline_start < mempool_start) {
  20170. + loud_error_header();
  20171. + loud_error(
  20172. + "__MEMPOOL_OFFLINE_START(%x) must not be before "
  20173. + "__MEMPOOL_START(%x)",
  20174. + mempool_offline_start,
  20175. + mempool_start);
  20176. + success = 0;
  20177. + }
  20178. +
  20179. + if (mempool_offline_end > mempool_end) {
  20180. + loud_error_header();
  20181. + loud_error(
  20182. + "__MEMPOOL_OFFLINE_END(%x) must not be after "
  20183. + "__MEMPOOL_END(%x)",
  20184. + mempool_offline_end,
  20185. + mempool_end);
  20186. + success = 0;
  20187. + }
  20188. +
  20189. + if ((cam_alloc_base < mempool_end) &&
  20190. + (cam_alloc_end > mempool_start)) {
  20191. + loud_error_header();
  20192. + loud_error(
  20193. + "cam_alloc pool(%x-%x) overlaps "
  20194. + "mempool(%x-%x)",
  20195. + cam_alloc_base, cam_alloc_end,
  20196. + mempool_start, mempool_end);
  20197. + success = 0;
  20198. + }
  20199. +
  20200. + loud_error_footer();
  20201. +
  20202. +close:
  20203. + CloseVideoCoreMemory(mem_hndl);
  20204. +
  20205. +out:
  20206. + return success;
  20207. +}
  20208. +#endif
  20209. +
  20210. +static int vc_cma_init(void)
  20211. +{
  20212. + int rc = -EFAULT;
  20213. + struct device *dev;
  20214. +
  20215. + if (!check_cma_config())
  20216. + goto out_release;
  20217. +
  20218. + printk(KERN_INFO "vc-cma: Videocore CMA driver\n");
  20219. + printk(KERN_INFO "vc-cma: vc_cma_base = 0x%08x\n", vc_cma_base);
  20220. + printk(KERN_INFO "vc-cma: vc_cma_size = 0x%08x (%u MiB)\n",
  20221. + vc_cma_size, vc_cma_size / (1024 * 1024));
  20222. + printk(KERN_INFO "vc-cma: vc_cma_initial = 0x%08x (%u MiB)\n",
  20223. + vc_cma_initial, vc_cma_initial / (1024 * 1024));
  20224. +
  20225. + vc_cma_base_page = phys_to_page(vc_cma_base);
  20226. +
  20227. + if (vc_cma_chunks) {
  20228. + int chunks_needed = vc_cma_initial / VC_CMA_CHUNK_SIZE;
  20229. +
  20230. + for (vc_cma_chunks_used = 0;
  20231. + vc_cma_chunks_used < chunks_needed; vc_cma_chunks_used++) {
  20232. + struct page *chunk;
  20233. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  20234. + PAGES_PER_CHUNK,
  20235. + VC_CMA_CHUNK_ORDER);
  20236. + if (!chunk)
  20237. + break;
  20238. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  20239. + VC_CMA_CHUNK_SIZE) != 0);
  20240. + }
  20241. + if (vc_cma_chunks_used != chunks_needed) {
  20242. + LOG_ERR("%s: dma_alloc_from_contiguous failed (%d "
  20243. + "bytes, allocation %d of %d)",
  20244. + __func__, VC_CMA_CHUNK_SIZE,
  20245. + vc_cma_chunks_used, chunks_needed);
  20246. + goto out_release;
  20247. + }
  20248. +
  20249. + vchiq_add_connected_callback(vc_cma_connected_init);
  20250. + }
  20251. +
  20252. + rc = alloc_chrdev_region(&vc_cma_devnum, 0, 1, DRIVER_NAME);
  20253. + if (rc < 0) {
  20254. + LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
  20255. + goto out_release;
  20256. + }
  20257. +
  20258. + cdev_init(&vc_cma_cdev, &vc_cma_fops);
  20259. + rc = cdev_add(&vc_cma_cdev, vc_cma_devnum, 1);
  20260. + if (rc != 0) {
  20261. + LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
  20262. + goto out_unregister;
  20263. + }
  20264. +
  20265. + vc_cma_class = class_create(THIS_MODULE, DRIVER_NAME);
  20266. + if (IS_ERR(vc_cma_class)) {
  20267. + rc = PTR_ERR(vc_cma_class);
  20268. + LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
  20269. + goto out_cdev_del;
  20270. + }
  20271. +
  20272. + dev = device_create(vc_cma_class, NULL, vc_cma_devnum, NULL,
  20273. + DRIVER_NAME);
  20274. + if (IS_ERR(dev)) {
  20275. + rc = PTR_ERR(dev);
  20276. + LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
  20277. + goto out_class_destroy;
  20278. + }
  20279. +
  20280. + vc_cma_proc_entry = proc_create(DRIVER_NAME, 0444, NULL, &vc_cma_proc_fops);
  20281. + if (vc_cma_proc_entry == NULL) {
  20282. + rc = -EFAULT;
  20283. + LOG_ERR("%s: proc_create failed", __func__);
  20284. + goto out_device_destroy;
  20285. + }
  20286. +
  20287. + vc_cma_inited = 1;
  20288. + return 0;
  20289. +
  20290. +out_device_destroy:
  20291. + device_destroy(vc_cma_class, vc_cma_devnum);
  20292. +
  20293. +out_class_destroy:
  20294. + class_destroy(vc_cma_class);
  20295. + vc_cma_class = NULL;
  20296. +
  20297. +out_cdev_del:
  20298. + cdev_del(&vc_cma_cdev);
  20299. +
  20300. +out_unregister:
  20301. + unregister_chrdev_region(vc_cma_devnum, 1);
  20302. +
  20303. +out_release:
  20304. + /* It is tempting to try to clean up by calling
  20305. + dma_release_from_contiguous for all allocated chunks, but it isn't
  20306. + a very safe thing to do. If vc_cma_initial is non-zero it is because
  20307. + VideoCore is already using that memory, so giving it back to Linux
  20308. + is likely to be fatal.
  20309. + */
  20310. + return -1;
  20311. +}
  20312. +
  20313. +/****************************************************************************
  20314. +*
  20315. +* vc_cma_exit
  20316. +*
  20317. +***************************************************************************/
  20318. +
  20319. +static void __exit vc_cma_exit(void)
  20320. +{
  20321. + LOG_DBG("%s: called", __func__);
  20322. +
  20323. + if (vc_cma_inited) {
  20324. + remove_proc_entry(DRIVER_NAME, NULL);
  20325. + device_destroy(vc_cma_class, vc_cma_devnum);
  20326. + class_destroy(vc_cma_class);
  20327. + cdev_del(&vc_cma_cdev);
  20328. + unregister_chrdev_region(vc_cma_devnum, 1);
  20329. + }
  20330. +}
  20331. +
  20332. +module_init(vc_cma_init);
  20333. +module_exit(vc_cma_exit);
  20334. +MODULE_LICENSE("GPL");
  20335. +MODULE_AUTHOR("Broadcom Corporation");
  20336. diff -Nur linux-3.18.6/drivers/char/broadcom/vc_sm/Makefile linux-rpi/drivers/char/broadcom/vc_sm/Makefile
  20337. --- linux-3.18.6/drivers/char/broadcom/vc_sm/Makefile 1970-01-01 01:00:00.000000000 +0100
  20338. +++ linux-rpi/drivers/char/broadcom/vc_sm/Makefile 2015-02-09 04:39:53.000000000 +0100
  20339. @@ -0,0 +1,21 @@
  20340. +EXTRA_CFLAGS += -Wall -Wstrict-prototypes -Wno-trigraphs -O2
  20341. +
  20342. +EXTRA_CFLAGS += -I"./arch/arm/mach-bcm2708/include/mach"
  20343. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services"
  20344. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services/interface/vchi"
  20345. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services/interface/vchiq_arm"
  20346. +EXTRA_CFLAGS += -I"$(srctree)/fs/"
  20347. +
  20348. +EXTRA_CFLAGS += -DOS_ASSERT_FAILURE
  20349. +EXTRA_CFLAGS += -D__STDC_VERSION=199901L
  20350. +EXTRA_CFLAGS += -D__STDC_VERSION__=199901L
  20351. +EXTRA_CFLAGS += -D__VCCOREVER__=0
  20352. +EXTRA_CFLAGS += -D__KERNEL__
  20353. +EXTRA_CFLAGS += -D__linux__
  20354. +EXTRA_CFLAGS += -Werror
  20355. +
  20356. +obj-$(CONFIG_BCM_VC_SM) := vc-sm.o
  20357. +
  20358. +vc-sm-objs := \
  20359. + vmcs_sm.o \
  20360. + vc_vchi_sm.o
  20361. diff -Nur linux-3.18.6/drivers/char/broadcom/vc_sm/vc_vchi_sm.c linux-rpi/drivers/char/broadcom/vc_sm/vc_vchi_sm.c
  20362. --- linux-3.18.6/drivers/char/broadcom/vc_sm/vc_vchi_sm.c 1970-01-01 01:00:00.000000000 +0100
  20363. +++ linux-rpi/drivers/char/broadcom/vc_sm/vc_vchi_sm.c 2015-02-09 04:39:53.000000000 +0100
  20364. @@ -0,0 +1,492 @@
  20365. +/*****************************************************************************
  20366. +* Copyright 2011-2012 Broadcom Corporation. All rights reserved.
  20367. +*
  20368. +* Unless you and Broadcom execute a separate written software license
  20369. +* agreement governing use of this software, this software is licensed to you
  20370. +* under the terms of the GNU General Public License version 2, available at
  20371. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  20372. +*
  20373. +* Notwithstanding the above, under no circumstances may you combine this
  20374. +* software in any way with any other Broadcom software provided under a
  20375. +* license other than the GPL, without Broadcom's express prior written
  20376. +* consent.
  20377. +*****************************************************************************/
  20378. +
  20379. +/* ---- Include Files ----------------------------------------------------- */
  20380. +#include <linux/types.h>
  20381. +#include <linux/kernel.h>
  20382. +#include <linux/list.h>
  20383. +#include <linux/semaphore.h>
  20384. +#include <linux/mutex.h>
  20385. +#include <linux/slab.h>
  20386. +#include <linux/kthread.h>
  20387. +
  20388. +#include "vc_vchi_sm.h"
  20389. +
  20390. +#define VC_SM_VER 1
  20391. +#define VC_SM_MIN_VER 0
  20392. +
  20393. +/* ---- Private Constants and Types -------------------------------------- */
  20394. +
  20395. +/* Command blocks come from a pool */
  20396. +#define SM_MAX_NUM_CMD_RSP_BLKS 32
  20397. +
  20398. +struct sm_cmd_rsp_blk {
  20399. + struct list_head head; /* To create lists */
  20400. + struct semaphore sema; /* To be signaled when the response is there */
  20401. +
  20402. + uint16_t id;
  20403. + uint16_t length;
  20404. +
  20405. + uint8_t msg[VC_SM_MAX_MSG_LEN];
  20406. +
  20407. + uint32_t wait:1;
  20408. + uint32_t sent:1;
  20409. + uint32_t alloc:1;
  20410. +
  20411. +};
  20412. +
  20413. +struct sm_instance {
  20414. + uint32_t num_connections;
  20415. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  20416. + struct task_struct *io_thread;
  20417. + struct semaphore io_sema;
  20418. +
  20419. + uint32_t trans_id;
  20420. +
  20421. + struct mutex lock;
  20422. + struct list_head cmd_list;
  20423. + struct list_head rsp_list;
  20424. + struct list_head dead_list;
  20425. +
  20426. + struct sm_cmd_rsp_blk free_blk[SM_MAX_NUM_CMD_RSP_BLKS];
  20427. + struct list_head free_list;
  20428. + struct mutex free_lock;
  20429. + struct semaphore free_sema;
  20430. +
  20431. +};
  20432. +
  20433. +/* ---- Private Variables ------------------------------------------------ */
  20434. +
  20435. +/* ---- Private Function Prototypes -------------------------------------- */
  20436. +
  20437. +/* ---- Private Functions ------------------------------------------------ */
  20438. +static struct
  20439. +sm_cmd_rsp_blk *vc_vchi_cmd_create(struct sm_instance *instance,
  20440. + VC_SM_MSG_TYPE id, void *msg,
  20441. + uint32_t size, int wait)
  20442. +{
  20443. + struct sm_cmd_rsp_blk *blk;
  20444. + VC_SM_MSG_HDR_T *hdr;
  20445. +
  20446. + if (down_interruptible(&instance->free_sema)) {
  20447. + blk = kmalloc(sizeof(*blk), GFP_KERNEL);
  20448. + if (!blk)
  20449. + return NULL;
  20450. +
  20451. + blk->alloc = 1;
  20452. + sema_init(&blk->sema, 0);
  20453. + } else {
  20454. + mutex_lock(&instance->free_lock);
  20455. + blk =
  20456. + list_first_entry(&instance->free_list,
  20457. + struct sm_cmd_rsp_blk, head);
  20458. + list_del(&blk->head);
  20459. + mutex_unlock(&instance->free_lock);
  20460. + }
  20461. +
  20462. + blk->sent = 0;
  20463. + blk->wait = wait;
  20464. + blk->length = sizeof(*hdr) + size;
  20465. +
  20466. + hdr = (VC_SM_MSG_HDR_T *) blk->msg;
  20467. + hdr->type = id;
  20468. + mutex_lock(&instance->lock);
  20469. + hdr->trans_id = blk->id = ++instance->trans_id;
  20470. + mutex_unlock(&instance->lock);
  20471. +
  20472. + if (size)
  20473. + memcpy(hdr->body, msg, size);
  20474. +
  20475. + return blk;
  20476. +}
  20477. +
  20478. +static void
  20479. +vc_vchi_cmd_delete(struct sm_instance *instance, struct sm_cmd_rsp_blk *blk)
  20480. +{
  20481. + if (blk->alloc) {
  20482. + kfree(blk);
  20483. + return;
  20484. + }
  20485. +
  20486. + mutex_lock(&instance->free_lock);
  20487. + list_add(&blk->head, &instance->free_list);
  20488. + mutex_unlock(&instance->free_lock);
  20489. + up(&instance->free_sema);
  20490. +}
  20491. +
  20492. +static int vc_vchi_sm_videocore_io(void *arg)
  20493. +{
  20494. + struct sm_instance *instance = arg;
  20495. + struct sm_cmd_rsp_blk *cmd = NULL, *cmd_tmp;
  20496. + VC_SM_RESULT_T *reply;
  20497. + uint32_t reply_len;
  20498. + int32_t status;
  20499. + int svc_use = 1;
  20500. +
  20501. + while (1) {
  20502. + if (svc_use)
  20503. + vchi_service_release(instance->vchi_handle[0]);
  20504. + svc_use = 0;
  20505. + if (!down_interruptible(&instance->io_sema)) {
  20506. + vchi_service_use(instance->vchi_handle[0]);
  20507. + svc_use = 1;
  20508. +
  20509. + do {
  20510. + unsigned int flags;
  20511. + /*
  20512. + * Get new command and move it to response list
  20513. + */
  20514. + mutex_lock(&instance->lock);
  20515. + if (list_empty(&instance->cmd_list)) {
  20516. + /* no more commands to process */
  20517. + mutex_unlock(&instance->lock);
  20518. + break;
  20519. + }
  20520. + cmd =
  20521. + list_first_entry(&instance->cmd_list,
  20522. + struct sm_cmd_rsp_blk,
  20523. + head);
  20524. + list_move(&cmd->head, &instance->rsp_list);
  20525. + cmd->sent = 1;
  20526. + mutex_unlock(&instance->lock);
  20527. +
  20528. + /* Send the command */
  20529. + flags = VCHI_FLAGS_BLOCK_UNTIL_QUEUED;
  20530. + status = vchi_msg_queue(
  20531. + instance->vchi_handle[0],
  20532. + cmd->msg, cmd->length,
  20533. + flags, NULL);
  20534. + if (status) {
  20535. + pr_err("%s: failed to queue message (%d)",
  20536. + __func__, status);
  20537. + }
  20538. +
  20539. + /* If no reply is needed then we're done */
  20540. + if (!cmd->wait) {
  20541. + mutex_lock(&instance->lock);
  20542. + list_del(&cmd->head);
  20543. + mutex_unlock(&instance->lock);
  20544. + vc_vchi_cmd_delete(instance, cmd);
  20545. + continue;
  20546. + }
  20547. +
  20548. + if (status) {
  20549. + up(&cmd->sema);
  20550. + continue;
  20551. + }
  20552. +
  20553. + } while (1);
  20554. +
  20555. + while (!vchi_msg_peek
  20556. + (instance->vchi_handle[0], (void **)&reply,
  20557. + &reply_len, VCHI_FLAGS_NONE)) {
  20558. + mutex_lock(&instance->lock);
  20559. + list_for_each_entry(cmd, &instance->rsp_list,
  20560. + head) {
  20561. + if (cmd->id == reply->trans_id)
  20562. + break;
  20563. + }
  20564. + mutex_unlock(&instance->lock);
  20565. +
  20566. + if (&cmd->head == &instance->rsp_list) {
  20567. + pr_debug("%s: received response %u, throw away...",
  20568. + __func__, reply->trans_id);
  20569. + } else if (reply_len > sizeof(cmd->msg)) {
  20570. + pr_err("%s: reply too big (%u) %u, throw away...",
  20571. + __func__, reply_len,
  20572. + reply->trans_id);
  20573. + } else {
  20574. + memcpy(cmd->msg, reply, reply_len);
  20575. + up(&cmd->sema);
  20576. + }
  20577. +
  20578. + vchi_msg_remove(instance->vchi_handle[0]);
  20579. + }
  20580. +
  20581. + /* Go through the dead list and free them */
  20582. + mutex_lock(&instance->lock);
  20583. + list_for_each_entry_safe(cmd, cmd_tmp,
  20584. + &instance->dead_list, head) {
  20585. + list_del(&cmd->head);
  20586. + vc_vchi_cmd_delete(instance, cmd);
  20587. + }
  20588. + mutex_unlock(&instance->lock);
  20589. + }
  20590. + }
  20591. +
  20592. + return 0;
  20593. +}
  20594. +
  20595. +static void vc_sm_vchi_callback(void *param,
  20596. + const VCHI_CALLBACK_REASON_T reason,
  20597. + void *msg_handle)
  20598. +{
  20599. + struct sm_instance *instance = param;
  20600. +
  20601. + (void)msg_handle;
  20602. +
  20603. + switch (reason) {
  20604. + case VCHI_CALLBACK_MSG_AVAILABLE:
  20605. + up(&instance->io_sema);
  20606. + break;
  20607. +
  20608. + case VCHI_CALLBACK_SERVICE_CLOSED:
  20609. + pr_info("%s: service CLOSED!!", __func__);
  20610. + default:
  20611. + break;
  20612. + }
  20613. +}
  20614. +
  20615. +VC_VCHI_SM_HANDLE_T vc_vchi_sm_init(VCHI_INSTANCE_T vchi_instance,
  20616. + VCHI_CONNECTION_T **vchi_connections,
  20617. + uint32_t num_connections)
  20618. +{
  20619. + uint32_t i;
  20620. + struct sm_instance *instance;
  20621. + int status;
  20622. +
  20623. + pr_debug("%s: start", __func__);
  20624. +
  20625. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  20626. + pr_err("%s: unsupported number of connections %u (max=%u)",
  20627. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  20628. +
  20629. + goto err_null;
  20630. + }
  20631. + /* Allocate memory for this instance */
  20632. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  20633. +
  20634. + /* Misc initialisations */
  20635. + mutex_init(&instance->lock);
  20636. + sema_init(&instance->io_sema, 0);
  20637. + INIT_LIST_HEAD(&instance->cmd_list);
  20638. + INIT_LIST_HEAD(&instance->rsp_list);
  20639. + INIT_LIST_HEAD(&instance->dead_list);
  20640. + INIT_LIST_HEAD(&instance->free_list);
  20641. + sema_init(&instance->free_sema, SM_MAX_NUM_CMD_RSP_BLKS);
  20642. + mutex_init(&instance->free_lock);
  20643. + for (i = 0; i < SM_MAX_NUM_CMD_RSP_BLKS; i++) {
  20644. + sema_init(&instance->free_blk[i].sema, 0);
  20645. + list_add(&instance->free_blk[i].head, &instance->free_list);
  20646. + }
  20647. +
  20648. + /* Open the VCHI service connections */
  20649. + instance->num_connections = num_connections;
  20650. + for (i = 0; i < num_connections; i++) {
  20651. + SERVICE_CREATION_T params = {
  20652. + VCHI_VERSION_EX(VC_SM_VER, VC_SM_MIN_VER),
  20653. + VC_SM_SERVER_NAME,
  20654. + vchi_connections[i],
  20655. + 0,
  20656. + 0,
  20657. + vc_sm_vchi_callback,
  20658. + instance,
  20659. + 0,
  20660. + 0,
  20661. + 0,
  20662. + };
  20663. +
  20664. + status = vchi_service_open(vchi_instance,
  20665. + &params, &instance->vchi_handle[i]);
  20666. + if (status) {
  20667. + pr_err("%s: failed to open VCHI service (%d)",
  20668. + __func__, status);
  20669. +
  20670. + goto err_close_services;
  20671. + }
  20672. + }
  20673. +
  20674. + /* Create the thread which takes care of all io to/from videoocore. */
  20675. + instance->io_thread = kthread_create(&vc_vchi_sm_videocore_io,
  20676. + (void *)instance, "SMIO");
  20677. + if (instance->io_thread == NULL) {
  20678. + pr_err("%s: failed to create SMIO thread", __func__);
  20679. +
  20680. + goto err_close_services;
  20681. + }
  20682. + set_user_nice(instance->io_thread, -10);
  20683. + wake_up_process(instance->io_thread);
  20684. +
  20685. + pr_debug("%s: success - instance 0x%x", __func__, (unsigned)instance);
  20686. + return instance;
  20687. +
  20688. +err_close_services:
  20689. + for (i = 0; i < instance->num_connections; i++) {
  20690. + if (instance->vchi_handle[i] != NULL)
  20691. + vchi_service_close(instance->vchi_handle[i]);
  20692. + }
  20693. + kfree(instance);
  20694. +err_null:
  20695. + pr_debug("%s: FAILED", __func__);
  20696. + return NULL;
  20697. +}
  20698. +
  20699. +int vc_vchi_sm_stop(VC_VCHI_SM_HANDLE_T *handle)
  20700. +{
  20701. + struct sm_instance *instance;
  20702. + uint32_t i;
  20703. +
  20704. + if (handle == NULL) {
  20705. + pr_err("%s: invalid pointer to handle %p", __func__, handle);
  20706. + goto lock;
  20707. + }
  20708. +
  20709. + if (*handle == NULL) {
  20710. + pr_err("%s: invalid handle %p", __func__, *handle);
  20711. + goto lock;
  20712. + }
  20713. +
  20714. + instance = *handle;
  20715. +
  20716. + /* Close all VCHI service connections */
  20717. + for (i = 0; i < instance->num_connections; i++) {
  20718. + int32_t success;
  20719. + vchi_service_use(instance->vchi_handle[i]);
  20720. +
  20721. + success = vchi_service_close(instance->vchi_handle[i]);
  20722. + }
  20723. +
  20724. + kfree(instance);
  20725. +
  20726. + *handle = NULL;
  20727. + return 0;
  20728. +
  20729. +lock:
  20730. + return -EINVAL;
  20731. +}
  20732. +
  20733. +int vc_vchi_sm_send_msg(VC_VCHI_SM_HANDLE_T handle,
  20734. + VC_SM_MSG_TYPE msg_id,
  20735. + void *msg, uint32_t msg_size,
  20736. + void *result, uint32_t result_size,
  20737. + uint32_t *cur_trans_id, uint8_t wait_reply)
  20738. +{
  20739. + int status = 0;
  20740. + struct sm_instance *instance = handle;
  20741. + struct sm_cmd_rsp_blk *cmd_blk;
  20742. +
  20743. + if (handle == NULL) {
  20744. + pr_err("%s: invalid handle", __func__);
  20745. + return -EINVAL;
  20746. + }
  20747. + if (msg == NULL) {
  20748. + pr_err("%s: invalid msg pointer", __func__);
  20749. + return -EINVAL;
  20750. + }
  20751. +
  20752. + cmd_blk =
  20753. + vc_vchi_cmd_create(instance, msg_id, msg, msg_size, wait_reply);
  20754. + if (cmd_blk == NULL) {
  20755. + pr_err("[%s]: failed to allocate global tracking resource",
  20756. + __func__);
  20757. + return -ENOMEM;
  20758. + }
  20759. +
  20760. + if (cur_trans_id != NULL)
  20761. + *cur_trans_id = cmd_blk->id;
  20762. +
  20763. + mutex_lock(&instance->lock);
  20764. + list_add_tail(&cmd_blk->head, &instance->cmd_list);
  20765. + mutex_unlock(&instance->lock);
  20766. + up(&instance->io_sema);
  20767. +
  20768. + if (!wait_reply)
  20769. + /* We're done */
  20770. + return 0;
  20771. +
  20772. + /* Wait for the response */
  20773. + if (down_interruptible(&cmd_blk->sema)) {
  20774. + mutex_lock(&instance->lock);
  20775. + if (!cmd_blk->sent) {
  20776. + list_del(&cmd_blk->head);
  20777. + mutex_unlock(&instance->lock);
  20778. + vc_vchi_cmd_delete(instance, cmd_blk);
  20779. + return -ENXIO;
  20780. + }
  20781. + mutex_unlock(&instance->lock);
  20782. +
  20783. + mutex_lock(&instance->lock);
  20784. + list_move(&cmd_blk->head, &instance->dead_list);
  20785. + mutex_unlock(&instance->lock);
  20786. + up(&instance->io_sema);
  20787. + return -EINTR; /* We're done */
  20788. + }
  20789. +
  20790. + if (result && result_size) {
  20791. + memcpy(result, cmd_blk->msg, result_size);
  20792. + } else {
  20793. + VC_SM_RESULT_T *res = (VC_SM_RESULT_T *) cmd_blk->msg;
  20794. + status = (res->success == 0) ? 0 : -ENXIO;
  20795. + }
  20796. +
  20797. + mutex_lock(&instance->lock);
  20798. + list_del(&cmd_blk->head);
  20799. + mutex_unlock(&instance->lock);
  20800. + vc_vchi_cmd_delete(instance, cmd_blk);
  20801. + return status;
  20802. +}
  20803. +
  20804. +int vc_vchi_sm_alloc(VC_VCHI_SM_HANDLE_T handle, VC_SM_ALLOC_T *msg,
  20805. + VC_SM_ALLOC_RESULT_T *result, uint32_t *cur_trans_id)
  20806. +{
  20807. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_ALLOC,
  20808. + msg, sizeof(*msg), result, sizeof(*result),
  20809. + cur_trans_id, 1);
  20810. +}
  20811. +
  20812. +int vc_vchi_sm_free(VC_VCHI_SM_HANDLE_T handle,
  20813. + VC_SM_FREE_T *msg, uint32_t *cur_trans_id)
  20814. +{
  20815. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_FREE,
  20816. + msg, sizeof(*msg), 0, 0, cur_trans_id, 0);
  20817. +}
  20818. +
  20819. +int vc_vchi_sm_lock(VC_VCHI_SM_HANDLE_T handle,
  20820. + VC_SM_LOCK_UNLOCK_T *msg,
  20821. + VC_SM_LOCK_RESULT_T *result, uint32_t *cur_trans_id)
  20822. +{
  20823. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_LOCK,
  20824. + msg, sizeof(*msg), result, sizeof(*result),
  20825. + cur_trans_id, 1);
  20826. +}
  20827. +
  20828. +int vc_vchi_sm_unlock(VC_VCHI_SM_HANDLE_T handle,
  20829. + VC_SM_LOCK_UNLOCK_T *msg,
  20830. + uint32_t *cur_trans_id, uint8_t wait_reply)
  20831. +{
  20832. + return vc_vchi_sm_send_msg(handle, wait_reply ?
  20833. + VC_SM_MSG_TYPE_UNLOCK :
  20834. + VC_SM_MSG_TYPE_UNLOCK_NOANS, msg,
  20835. + sizeof(*msg), 0, 0, cur_trans_id,
  20836. + wait_reply);
  20837. +}
  20838. +
  20839. +int vc_vchi_sm_resize(VC_VCHI_SM_HANDLE_T handle, VC_SM_RESIZE_T *msg,
  20840. + uint32_t *cur_trans_id)
  20841. +{
  20842. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_RESIZE,
  20843. + msg, sizeof(*msg), 0, 0, cur_trans_id, 1);
  20844. +}
  20845. +
  20846. +int vc_vchi_sm_walk_alloc(VC_VCHI_SM_HANDLE_T handle)
  20847. +{
  20848. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_WALK_ALLOC,
  20849. + 0, 0, 0, 0, 0, 0);
  20850. +}
  20851. +
  20852. +int vc_vchi_sm_clean_up(VC_VCHI_SM_HANDLE_T handle, VC_SM_ACTION_CLEAN_T *msg)
  20853. +{
  20854. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_ACTION_CLEAN,
  20855. + msg, sizeof(*msg), 0, 0, 0, 0);
  20856. +}
  20857. diff -Nur linux-3.18.6/drivers/char/broadcom/vc_sm/vmcs_sm.c linux-rpi/drivers/char/broadcom/vc_sm/vmcs_sm.c
  20858. --- linux-3.18.6/drivers/char/broadcom/vc_sm/vmcs_sm.c 1970-01-01 01:00:00.000000000 +0100
  20859. +++ linux-rpi/drivers/char/broadcom/vc_sm/vmcs_sm.c 2015-02-09 04:39:53.000000000 +0100
  20860. @@ -0,0 +1,3163 @@
  20861. +/*****************************************************************************
  20862. +* Copyright 2011-2012 Broadcom Corporation. All rights reserved.
  20863. +*
  20864. +* Unless you and Broadcom execute a separate written software license
  20865. +* agreement governing use of this software, this software is licensed to you
  20866. +* under the terms of the GNU General Public License version 2, available at
  20867. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  20868. +*
  20869. +* Notwithstanding the above, under no circumstances may you combine this
  20870. +* software in any way with any other Broadcom software provided under a
  20871. +* license other than the GPL, without Broadcom's express prior written
  20872. +* consent.
  20873. +*****************************************************************************/
  20874. +
  20875. +/* ---- Include Files ----------------------------------------------------- */
  20876. +
  20877. +#include <linux/cdev.h>
  20878. +#include <linux/device.h>
  20879. +#include <linux/debugfs.h>
  20880. +#include <linux/dma-mapping.h>
  20881. +#include <linux/errno.h>
  20882. +#include <linux/fs.h>
  20883. +#include <linux/hugetlb.h>
  20884. +#include <linux/ioctl.h>
  20885. +#include <linux/kernel.h>
  20886. +#include <linux/list.h>
  20887. +#include <linux/module.h>
  20888. +#include <linux/mm.h>
  20889. +#include <linux/pfn.h>
  20890. +#include <linux/proc_fs.h>
  20891. +#include <linux/pagemap.h>
  20892. +#include <linux/semaphore.h>
  20893. +#include <linux/slab.h>
  20894. +#include <linux/seq_file.h>
  20895. +#include <linux/types.h>
  20896. +#include <asm/cacheflush.h>
  20897. +
  20898. +#include <vc_mem.h>
  20899. +
  20900. +#include "vchiq_connected.h"
  20901. +#include "vc_vchi_sm.h"
  20902. +
  20903. +#include <vmcs_sm_ioctl.h>
  20904. +#include "vc_sm_knl.h"
  20905. +
  20906. +/* ---- Private Constants and Types --------------------------------------- */
  20907. +
  20908. +#define DEVICE_NAME "vcsm"
  20909. +#define DEVICE_MINOR 0
  20910. +
  20911. +#define VC_SM_DIR_ROOT_NAME "vc-smem"
  20912. +#define VC_SM_DIR_ALLOC_NAME "alloc"
  20913. +#define VC_SM_STATE "state"
  20914. +#define VC_SM_STATS "statistics"
  20915. +#define VC_SM_RESOURCES "resources"
  20916. +#define VC_SM_DEBUG "debug"
  20917. +#define VC_SM_WRITE_BUF_SIZE 128
  20918. +
  20919. +/* Statistics tracked per resource and globally.
  20920. +*/
  20921. +enum SM_STATS_T {
  20922. + /* Attempt. */
  20923. + ALLOC,
  20924. + FREE,
  20925. + LOCK,
  20926. + UNLOCK,
  20927. + MAP,
  20928. + FLUSH,
  20929. + INVALID,
  20930. +
  20931. + END_ATTEMPT,
  20932. +
  20933. + /* Failure. */
  20934. + ALLOC_FAIL,
  20935. + FREE_FAIL,
  20936. + LOCK_FAIL,
  20937. + UNLOCK_FAIL,
  20938. + MAP_FAIL,
  20939. + FLUSH_FAIL,
  20940. + INVALID_FAIL,
  20941. +
  20942. + END_ALL,
  20943. +
  20944. +};
  20945. +
  20946. +static const char *const sm_stats_human_read[] = {
  20947. + "Alloc",
  20948. + "Free",
  20949. + "Lock",
  20950. + "Unlock",
  20951. + "Map",
  20952. + "Cache Flush",
  20953. + "Cache Invalidate",
  20954. +};
  20955. +
  20956. +typedef int (*VC_SM_SHOW) (struct seq_file *s, void *v);
  20957. +struct SM_PDE_T {
  20958. + VC_SM_SHOW show; /* Debug fs function hookup. */
  20959. + struct dentry *dir_entry; /* Debug fs directory entry. */
  20960. + void *priv_data; /* Private data */
  20961. +
  20962. +};
  20963. +
  20964. +/* Single resource allocation tracked for all devices.
  20965. +*/
  20966. +struct sm_mmap {
  20967. + struct list_head map_list; /* Linked list of maps. */
  20968. +
  20969. + struct SM_RESOURCE_T *resource; /* Pointer to the resource. */
  20970. +
  20971. + pid_t res_pid; /* PID owning that resource. */
  20972. + unsigned int res_vc_hdl; /* Resource handle (videocore). */
  20973. + unsigned int res_usr_hdl; /* Resource handle (user). */
  20974. +
  20975. + long unsigned int res_addr; /* Mapped virtual address. */
  20976. + struct vm_area_struct *vma; /* VM area for this mapping. */
  20977. + unsigned int ref_count; /* Reference count to this vma. */
  20978. +
  20979. + /* Used to link maps associated with a resource. */
  20980. + struct list_head resource_map_list;
  20981. +};
  20982. +
  20983. +/* Single resource allocation tracked for each opened device.
  20984. +*/
  20985. +struct SM_RESOURCE_T {
  20986. + struct list_head resource_list; /* List of resources. */
  20987. + struct list_head global_resource_list; /* Global list of resources. */
  20988. +
  20989. + pid_t pid; /* PID owning that resource. */
  20990. + uint32_t res_guid; /* Unique identifier. */
  20991. + uint32_t lock_count; /* Lock count for this resource. */
  20992. + uint32_t ref_count; /* Ref count for this resource. */
  20993. +
  20994. + uint32_t res_handle; /* Resource allocation handle. */
  20995. + void *res_base_mem; /* Resource base memory address. */
  20996. + uint32_t res_size; /* Resource size allocated. */
  20997. + enum vmcs_sm_cache_e res_cached; /* Resource cache type. */
  20998. + struct SM_RESOURCE_T *res_shared; /* Shared resource */
  20999. +
  21000. + enum SM_STATS_T res_stats[END_ALL]; /* Resource statistics. */
  21001. +
  21002. + uint8_t map_count; /* Counter of mappings for this resource. */
  21003. + struct list_head map_list; /* Maps associated with a resource. */
  21004. +
  21005. + struct SM_PRIV_DATA_T *private;
  21006. +};
  21007. +
  21008. +/* Private file data associated with each opened device.
  21009. +*/
  21010. +struct SM_PRIV_DATA_T {
  21011. + struct list_head resource_list; /* List of resources. */
  21012. +
  21013. + pid_t pid; /* PID of creator. */
  21014. +
  21015. + struct dentry *dir_pid; /* Debug fs entries root. */
  21016. + struct SM_PDE_T dir_stats; /* Debug fs entries statistics sub-tree. */
  21017. + struct SM_PDE_T dir_res; /* Debug fs resource sub-tree. */
  21018. +
  21019. + int restart_sys; /* Tracks restart on interrupt. */
  21020. + VC_SM_MSG_TYPE int_action; /* Interrupted action. */
  21021. + uint32_t int_trans_id; /* Interrupted transaction. */
  21022. +
  21023. +};
  21024. +
  21025. +/* Global state information.
  21026. +*/
  21027. +struct SM_STATE_T {
  21028. + VC_VCHI_SM_HANDLE_T sm_handle; /* Handle for videocore service. */
  21029. + struct dentry *dir_root; /* Debug fs entries root. */
  21030. + struct dentry *dir_alloc; /* Debug fs entries allocations. */
  21031. + struct SM_PDE_T dir_stats; /* Debug fs entries statistics sub-tree. */
  21032. + struct SM_PDE_T dir_state; /* Debug fs entries state sub-tree. */
  21033. + struct dentry *debug; /* Debug fs entries debug. */
  21034. +
  21035. + struct mutex map_lock; /* Global map lock. */
  21036. + struct list_head map_list; /* List of maps. */
  21037. + struct list_head resource_list; /* List of resources. */
  21038. +
  21039. + enum SM_STATS_T deceased[END_ALL]; /* Natural termination stats. */
  21040. + enum SM_STATS_T terminated[END_ALL]; /* Forced termination stats. */
  21041. + uint32_t res_deceased_cnt; /* Natural termination counter. */
  21042. + uint32_t res_terminated_cnt; /* Forced termination counter. */
  21043. +
  21044. + struct cdev sm_cdev; /* Device. */
  21045. + dev_t sm_devid; /* Device identifier. */
  21046. + struct class *sm_class; /* Class. */
  21047. + struct device *sm_dev; /* Device. */
  21048. +
  21049. + struct SM_PRIV_DATA_T *data_knl; /* Kernel internal data tracking. */
  21050. +
  21051. + struct mutex lock; /* Global lock. */
  21052. + uint32_t guid; /* GUID (next) tracker. */
  21053. +
  21054. +};
  21055. +
  21056. +/* ---- Private Variables ----------------------------------------------- */
  21057. +
  21058. +static struct SM_STATE_T *sm_state;
  21059. +static int sm_inited;
  21060. +
  21061. +static const char *const sm_cache_map_vector[] = {
  21062. + "(null)",
  21063. + "host",
  21064. + "videocore",
  21065. + "host+videocore",
  21066. +};
  21067. +
  21068. +/* ---- Private Function Prototypes -------------------------------------- */
  21069. +
  21070. +/* ---- Private Functions ------------------------------------------------ */
  21071. +
  21072. +static inline unsigned vcaddr_to_pfn(unsigned long vc_addr)
  21073. +{
  21074. + unsigned long pfn = vc_addr & 0x3FFFFFFF;
  21075. + pfn += mm_vc_mem_phys_addr;
  21076. + pfn >>= PAGE_SHIFT;
  21077. + return pfn;
  21078. +}
  21079. +
  21080. +/* Carries over to the state statistics the statistics once owned by a deceased
  21081. +** resource.
  21082. +*/
  21083. +static void vc_sm_resource_deceased(struct SM_RESOURCE_T *p_res, int terminated)
  21084. +{
  21085. + if (sm_state != NULL) {
  21086. + if (p_res != NULL) {
  21087. + int ix;
  21088. +
  21089. + if (terminated)
  21090. + sm_state->res_terminated_cnt++;
  21091. + else
  21092. + sm_state->res_deceased_cnt++;
  21093. +
  21094. + for (ix = 0; ix < END_ALL; ix++) {
  21095. + if (terminated)
  21096. + sm_state->terminated[ix] +=
  21097. + p_res->res_stats[ix];
  21098. + else
  21099. + sm_state->deceased[ix] +=
  21100. + p_res->res_stats[ix];
  21101. + }
  21102. + }
  21103. + }
  21104. +}
  21105. +
  21106. +/* Fetch a videocore handle corresponding to a mapping of the pid+address
  21107. +** returns 0 (ie NULL) if no such handle exists in the global map.
  21108. +*/
  21109. +static unsigned int vmcs_sm_vc_handle_from_pid_and_address(unsigned int pid,
  21110. + unsigned int addr)
  21111. +{
  21112. + struct sm_mmap *map = NULL;
  21113. + unsigned int handle = 0;
  21114. +
  21115. + if (!sm_state || addr == 0)
  21116. + goto out;
  21117. +
  21118. + mutex_lock(&(sm_state->map_lock));
  21119. +
  21120. + /* Lookup the resource.
  21121. + */
  21122. + if (!list_empty(&sm_state->map_list)) {
  21123. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  21124. + if (map->res_pid != pid || map->res_addr != addr)
  21125. + continue;
  21126. +
  21127. + pr_debug("[%s]: global map %p (pid %u, addr %lx) -> vc-hdl %x (usr-hdl %x)\n",
  21128. + __func__, map, map->res_pid, map->res_addr,
  21129. + map->res_vc_hdl, map->res_usr_hdl);
  21130. +
  21131. + handle = map->res_vc_hdl;
  21132. + break;
  21133. + }
  21134. + }
  21135. +
  21136. + mutex_unlock(&(sm_state->map_lock));
  21137. +
  21138. +out:
  21139. + /* Use a debug log here as it may be a valid situation that we query
  21140. + ** for something that is not mapped, we do not want a kernel log each
  21141. + ** time around.
  21142. + **
  21143. + ** There are other error log that would pop up accordingly if someone
  21144. + ** subsequently tries to use something invalid after being told not to
  21145. + ** use it...
  21146. + */
  21147. + if (handle == 0) {
  21148. + pr_debug("[%s]: not a valid map (pid %u, addr %x)\n",
  21149. + __func__, pid, addr);
  21150. + }
  21151. +
  21152. + return handle;
  21153. +}
  21154. +
  21155. +/* Fetch a user handle corresponding to a mapping of the pid+address
  21156. +** returns 0 (ie NULL) if no such handle exists in the global map.
  21157. +*/
  21158. +static unsigned int vmcs_sm_usr_handle_from_pid_and_address(unsigned int pid,
  21159. + unsigned int addr)
  21160. +{
  21161. + struct sm_mmap *map = NULL;
  21162. + unsigned int handle = 0;
  21163. +
  21164. + if (!sm_state || addr == 0)
  21165. + goto out;
  21166. +
  21167. + mutex_lock(&(sm_state->map_lock));
  21168. +
  21169. + /* Lookup the resource.
  21170. + */
  21171. + if (!list_empty(&sm_state->map_list)) {
  21172. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  21173. + if (map->res_pid != pid || map->res_addr != addr)
  21174. + continue;
  21175. +
  21176. + pr_debug("[%s]: global map %p (pid %u, addr %lx) -> usr-hdl %x (vc-hdl %x)\n",
  21177. + __func__, map, map->res_pid, map->res_addr,
  21178. + map->res_usr_hdl, map->res_vc_hdl);
  21179. +
  21180. + handle = map->res_usr_hdl;
  21181. + break;
  21182. + }
  21183. + }
  21184. +
  21185. + mutex_unlock(&(sm_state->map_lock));
  21186. +
  21187. +out:
  21188. + /* Use a debug log here as it may be a valid situation that we query
  21189. + * for something that is not mapped yet.
  21190. + *
  21191. + * There are other error log that would pop up accordingly if someone
  21192. + * subsequently tries to use something invalid after being told not to
  21193. + * use it...
  21194. + */
  21195. + if (handle == 0)
  21196. + pr_debug("[%s]: not a valid map (pid %u, addr %x)\n",
  21197. + __func__, pid, addr);
  21198. +
  21199. + return handle;
  21200. +}
  21201. +
  21202. +#if defined(DO_NOT_USE)
  21203. +/* Fetch an address corresponding to a mapping of the pid+handle
  21204. +** returns 0 (ie NULL) if no such address exists in the global map.
  21205. +*/
  21206. +static unsigned int vmcs_sm_usr_address_from_pid_and_vc_handle(unsigned int pid,
  21207. + unsigned int hdl)
  21208. +{
  21209. + struct sm_mmap *map = NULL;
  21210. + unsigned int addr = 0;
  21211. +
  21212. + if (sm_state == NULL || hdl == 0)
  21213. + goto out;
  21214. +
  21215. + mutex_lock(&(sm_state->map_lock));
  21216. +
  21217. + /* Lookup the resource.
  21218. + */
  21219. + if (!list_empty(&sm_state->map_list)) {
  21220. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  21221. + if (map->res_pid != pid || map->res_vc_hdl != hdl)
  21222. + continue;
  21223. +
  21224. + pr_debug("[%s]: global map %p (pid %u, vc-hdl %x, usr-hdl %x) -> addr %lx\n",
  21225. + __func__, map, map->res_pid, map->res_vc_hdl,
  21226. + map->res_usr_hdl, map->res_addr);
  21227. +
  21228. + addr = map->res_addr;
  21229. + break;
  21230. + }
  21231. + }
  21232. +
  21233. + mutex_unlock(&(sm_state->map_lock));
  21234. +
  21235. +out:
  21236. + /* Use a debug log here as it may be a valid situation that we query
  21237. + ** for something that is not mapped, we do not want a kernel log each
  21238. + ** time around.
  21239. + **
  21240. + ** There are other error log that would pop up accordingly if someone
  21241. + ** subsequently tries to use something invalid after being told not to
  21242. + ** use it...
  21243. + */
  21244. + if (addr == 0)
  21245. + pr_debug("[%s]: not a valid map (pid %u, hdl %x)\n",
  21246. + __func__, pid, hdl);
  21247. +
  21248. + return addr;
  21249. +}
  21250. +#endif
  21251. +
  21252. +/* Fetch an address corresponding to a mapping of the pid+handle
  21253. +** returns 0 (ie NULL) if no such address exists in the global map.
  21254. +*/
  21255. +static unsigned int vmcs_sm_usr_address_from_pid_and_usr_handle(unsigned int
  21256. + pid,
  21257. + unsigned int
  21258. + hdl)
  21259. +{
  21260. + struct sm_mmap *map = NULL;
  21261. + unsigned int addr = 0;
  21262. +
  21263. + if (sm_state == NULL || hdl == 0)
  21264. + goto out;
  21265. +
  21266. + mutex_lock(&(sm_state->map_lock));
  21267. +
  21268. + /* Lookup the resource.
  21269. + */
  21270. + if (!list_empty(&sm_state->map_list)) {
  21271. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  21272. + if (map->res_pid != pid || map->res_usr_hdl != hdl)
  21273. + continue;
  21274. +
  21275. + pr_debug("[%s]: global map %p (pid %u, vc-hdl %x, usr-hdl %x) -> addr %lx\n",
  21276. + __func__, map, map->res_pid, map->res_vc_hdl,
  21277. + map->res_usr_hdl, map->res_addr);
  21278. +
  21279. + addr = map->res_addr;
  21280. + break;
  21281. + }
  21282. + }
  21283. +
  21284. + mutex_unlock(&(sm_state->map_lock));
  21285. +
  21286. +out:
  21287. + /* Use a debug log here as it may be a valid situation that we query
  21288. + * for something that is not mapped, we do not want a kernel log each
  21289. + * time around.
  21290. + *
  21291. + * There are other error log that would pop up accordingly if someone
  21292. + * subsequently tries to use something invalid after being told not to
  21293. + * use it...
  21294. + */
  21295. + if (addr == 0)
  21296. + pr_debug("[%s]: not a valid map (pid %u, hdl %x)\n", __func__,
  21297. + pid, hdl);
  21298. +
  21299. + return addr;
  21300. +}
  21301. +
  21302. +/* Adds a resource mapping to the global data list.
  21303. +*/
  21304. +static void vmcs_sm_add_map(struct SM_STATE_T *state,
  21305. + struct SM_RESOURCE_T *resource, struct sm_mmap *map)
  21306. +{
  21307. + mutex_lock(&(state->map_lock));
  21308. +
  21309. + /* Add to the global list of mappings
  21310. + */
  21311. + list_add(&map->map_list, &state->map_list);
  21312. +
  21313. + /* Add to the list of mappings for this resource
  21314. + */
  21315. + list_add(&map->resource_map_list, &resource->map_list);
  21316. + resource->map_count++;
  21317. +
  21318. + mutex_unlock(&(state->map_lock));
  21319. +
  21320. + pr_debug("[%s]: added map %p (pid %u, vc-hdl %x, usr-hdl %x, addr %lx)\n",
  21321. + __func__, map, map->res_pid, map->res_vc_hdl,
  21322. + map->res_usr_hdl, map->res_addr);
  21323. +}
  21324. +
  21325. +/* Removes a resource mapping from the global data list.
  21326. +*/
  21327. +static void vmcs_sm_remove_map(struct SM_STATE_T *state,
  21328. + struct SM_RESOURCE_T *resource,
  21329. + struct sm_mmap *map)
  21330. +{
  21331. + mutex_lock(&(state->map_lock));
  21332. +
  21333. + /* Remove from the global list of mappings
  21334. + */
  21335. + list_del(&map->map_list);
  21336. +
  21337. + /* Remove from the list of mapping for this resource
  21338. + */
  21339. + list_del(&map->resource_map_list);
  21340. + if (resource->map_count > 0)
  21341. + resource->map_count--;
  21342. +
  21343. + mutex_unlock(&(state->map_lock));
  21344. +
  21345. + pr_debug("[%s]: removed map %p (pid %d, vc-hdl %x, usr-hdl %x, addr %lx)\n",
  21346. + __func__, map, map->res_pid, map->res_vc_hdl, map->res_usr_hdl,
  21347. + map->res_addr);
  21348. +
  21349. + kfree(map);
  21350. +}
  21351. +
  21352. +/* Read callback for the global state proc entry.
  21353. +*/
  21354. +static int vc_sm_global_state_show(struct seq_file *s, void *v)
  21355. +{
  21356. + struct sm_mmap *map = NULL;
  21357. + int map_count = 0;
  21358. +
  21359. + if (sm_state == NULL)
  21360. + return 0;
  21361. +
  21362. + seq_printf(s, "\nVC-ServiceHandle 0x%x\n",
  21363. + (unsigned int)sm_state->sm_handle);
  21364. +
  21365. + /* Log all applicable mapping(s).
  21366. + */
  21367. +
  21368. + mutex_lock(&(sm_state->map_lock));
  21369. +
  21370. + if (!list_empty(&sm_state->map_list)) {
  21371. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  21372. + map_count++;
  21373. +
  21374. + seq_printf(s, "\nMapping 0x%x\n",
  21375. + (unsigned int)map);
  21376. + seq_printf(s, " TGID %u\n",
  21377. + map->res_pid);
  21378. + seq_printf(s, " VC-HDL 0x%x\n",
  21379. + map->res_vc_hdl);
  21380. + seq_printf(s, " USR-HDL 0x%x\n",
  21381. + map->res_usr_hdl);
  21382. + seq_printf(s, " USR-ADDR 0x%lx\n",
  21383. + map->res_addr);
  21384. + }
  21385. + }
  21386. +
  21387. + mutex_unlock(&(sm_state->map_lock));
  21388. + seq_printf(s, "\n\nTotal map count: %d\n\n", map_count);
  21389. +
  21390. + return 0;
  21391. +}
  21392. +
  21393. +static int vc_sm_global_statistics_show(struct seq_file *s, void *v)
  21394. +{
  21395. + int ix;
  21396. +
  21397. + /* Global state tracked statistics.
  21398. + */
  21399. + if (sm_state != NULL) {
  21400. + seq_puts(s, "\nDeceased Resources Statistics\n");
  21401. +
  21402. + seq_printf(s, "\nNatural Cause (%u occurences)\n",
  21403. + sm_state->res_deceased_cnt);
  21404. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  21405. + if (sm_state->deceased[ix] > 0) {
  21406. + seq_printf(s, " %u\t%s\n",
  21407. + sm_state->deceased[ix],
  21408. + sm_stats_human_read[ix]);
  21409. + }
  21410. + }
  21411. + seq_puts(s, "\n");
  21412. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  21413. + if (sm_state->deceased[ix + END_ATTEMPT] > 0) {
  21414. + seq_printf(s, " %u\tFAILED %s\n",
  21415. + sm_state->deceased[ix + END_ATTEMPT],
  21416. + sm_stats_human_read[ix]);
  21417. + }
  21418. + }
  21419. +
  21420. + seq_printf(s, "\nForcefull (%u occurences)\n",
  21421. + sm_state->res_terminated_cnt);
  21422. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  21423. + if (sm_state->terminated[ix] > 0) {
  21424. + seq_printf(s, " %u\t%s\n",
  21425. + sm_state->terminated[ix],
  21426. + sm_stats_human_read[ix]);
  21427. + }
  21428. + }
  21429. + seq_puts(s, "\n");
  21430. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  21431. + if (sm_state->terminated[ix + END_ATTEMPT] > 0) {
  21432. + seq_printf(s, " %u\tFAILED %s\n",
  21433. + sm_state->terminated[ix +
  21434. + END_ATTEMPT],
  21435. + sm_stats_human_read[ix]);
  21436. + }
  21437. + }
  21438. + }
  21439. +
  21440. + return 0;
  21441. +}
  21442. +
  21443. +#if 0
  21444. +/* Read callback for the statistics proc entry.
  21445. +*/
  21446. +static int vc_sm_statistics_show(struct seq_file *s, void *v)
  21447. +{
  21448. + int ix;
  21449. + struct SM_PRIV_DATA_T *file_data;
  21450. + struct SM_RESOURCE_T *resource;
  21451. + int res_count = 0;
  21452. + struct SM_PDE_T *p_pde;
  21453. +
  21454. + p_pde = (struct SM_PDE_T *)(s->private);
  21455. + file_data = (struct SM_PRIV_DATA_T *)(p_pde->priv_data);
  21456. +
  21457. + if (file_data == NULL)
  21458. + return 0;
  21459. +
  21460. + /* Per process statistics.
  21461. + */
  21462. +
  21463. + seq_printf(s, "\nStatistics for TGID %d\n", file_data->pid);
  21464. +
  21465. + mutex_lock(&(sm_state->map_lock));
  21466. +
  21467. + if (!list_empty(&file_data->resource_list)) {
  21468. + list_for_each_entry(resource, &file_data->resource_list,
  21469. + resource_list) {
  21470. + res_count++;
  21471. +
  21472. + seq_printf(s, "\nGUID: 0x%x\n\n",
  21473. + resource->res_guid);
  21474. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  21475. + if (resource->res_stats[ix] > 0) {
  21476. + seq_printf(s,
  21477. + " %u\t%s\n",
  21478. + resource->res_stats[ix],
  21479. + sm_stats_human_read[ix]);
  21480. + }
  21481. + }
  21482. + seq_puts(s, "\n");
  21483. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  21484. + if (resource->res_stats[ix + END_ATTEMPT] > 0) {
  21485. + seq_printf(s,
  21486. + " %u\tFAILED %s\n",
  21487. + resource->res_stats[
  21488. + ix + END_ATTEMPT],
  21489. + sm_stats_human_read[ix]);
  21490. + }
  21491. + }
  21492. + }
  21493. + }
  21494. +
  21495. + mutex_unlock(&(sm_state->map_lock));
  21496. +
  21497. + seq_printf(s, "\nResources Count %d\n", res_count);
  21498. +
  21499. + return 0;
  21500. +}
  21501. +#endif
  21502. +
  21503. +#if 0
  21504. +/* Read callback for the allocation proc entry. */
  21505. +static int vc_sm_alloc_show(struct seq_file *s, void *v)
  21506. +{
  21507. + struct SM_PRIV_DATA_T *file_data;
  21508. + struct SM_RESOURCE_T *resource;
  21509. + int alloc_count = 0;
  21510. + struct SM_PDE_T *p_pde;
  21511. +
  21512. + p_pde = (struct SM_PDE_T *)(s->private);
  21513. + file_data = (struct SM_PRIV_DATA_T *)(p_pde->priv_data);
  21514. +
  21515. + if (!file_data)
  21516. + return 0;
  21517. +
  21518. + /* Per process statistics. */
  21519. + seq_printf(s, "\nAllocation for TGID %d\n", file_data->pid);
  21520. +
  21521. + mutex_lock(&(sm_state->map_lock));
  21522. +
  21523. + if (!list_empty(&file_data->resource_list)) {
  21524. + list_for_each_entry(resource, &file_data->resource_list,
  21525. + resource_list) {
  21526. + alloc_count++;
  21527. +
  21528. + seq_printf(s, "\nGUID: 0x%x\n",
  21529. + resource->res_guid);
  21530. + seq_printf(s, "Lock Count: %u\n",
  21531. + resource->lock_count);
  21532. + seq_printf(s, "Mapped: %s\n",
  21533. + (resource->map_count ? "yes" : "no"));
  21534. + seq_printf(s, "VC-handle: 0x%x\n",
  21535. + resource->res_handle);
  21536. + seq_printf(s, "VC-address: 0x%p\n",
  21537. + resource->res_base_mem);
  21538. + seq_printf(s, "VC-size (bytes): %u\n",
  21539. + resource->res_size);
  21540. + seq_printf(s, "Cache: %s\n",
  21541. + sm_cache_map_vector[resource->res_cached]);
  21542. + }
  21543. + }
  21544. +
  21545. + mutex_unlock(&(sm_state->map_lock));
  21546. +
  21547. + seq_printf(s, "\n\nTotal allocation count: %d\n\n", alloc_count);
  21548. +
  21549. + return 0;
  21550. +}
  21551. +#endif
  21552. +
  21553. +static int vc_sm_seq_file_show(struct seq_file *s, void *v)
  21554. +{
  21555. + struct SM_PDE_T *sm_pde;
  21556. +
  21557. + sm_pde = (struct SM_PDE_T *)(s->private);
  21558. +
  21559. + if (sm_pde && sm_pde->show)
  21560. + sm_pde->show(s, v);
  21561. +
  21562. + return 0;
  21563. +}
  21564. +
  21565. +static int vc_sm_single_open(struct inode *inode, struct file *file)
  21566. +{
  21567. + return single_open(file, vc_sm_seq_file_show, inode->i_private);
  21568. +}
  21569. +
  21570. +static const struct file_operations vc_sm_debug_fs_fops = {
  21571. + .open = vc_sm_single_open,
  21572. + .read = seq_read,
  21573. + .llseek = seq_lseek,
  21574. + .release = single_release,
  21575. +};
  21576. +
  21577. +/* Adds a resource to the private data list which tracks all the allocated
  21578. +** data.
  21579. +*/
  21580. +static void vmcs_sm_add_resource(struct SM_PRIV_DATA_T *privdata,
  21581. + struct SM_RESOURCE_T *resource)
  21582. +{
  21583. + mutex_lock(&(sm_state->map_lock));
  21584. + list_add(&resource->resource_list, &privdata->resource_list);
  21585. + list_add(&resource->global_resource_list, &sm_state->resource_list);
  21586. + mutex_unlock(&(sm_state->map_lock));
  21587. +
  21588. + pr_debug("[%s]: added resource %p (base addr %p, hdl %x, size %u, cache %u)\n",
  21589. + __func__, resource, resource->res_base_mem,
  21590. + resource->res_handle, resource->res_size, resource->res_cached);
  21591. +}
  21592. +
  21593. +/* Locates a resource and acquire a reference on it.
  21594. +** The resource won't be deleted while there is a reference on it.
  21595. +*/
  21596. +static struct SM_RESOURCE_T *vmcs_sm_acquire_resource(struct SM_PRIV_DATA_T
  21597. + *private,
  21598. + unsigned int res_guid)
  21599. +{
  21600. + struct SM_RESOURCE_T *resource, *ret = NULL;
  21601. +
  21602. + mutex_lock(&(sm_state->map_lock));
  21603. +
  21604. + list_for_each_entry(resource, &private->resource_list, resource_list) {
  21605. + if (resource->res_guid != res_guid)
  21606. + continue;
  21607. +
  21608. + pr_debug("[%s]: located resource %p (guid: %x, base addr %p, hdl %x, size %u, cache %u)\n",
  21609. + __func__, resource, resource->res_guid,
  21610. + resource->res_base_mem, resource->res_handle,
  21611. + resource->res_size, resource->res_cached);
  21612. + resource->ref_count++;
  21613. + ret = resource;
  21614. + break;
  21615. + }
  21616. +
  21617. + mutex_unlock(&(sm_state->map_lock));
  21618. +
  21619. + return ret;
  21620. +}
  21621. +
  21622. +/* Locates a resource and acquire a reference on it.
  21623. +** The resource won't be deleted while there is a reference on it.
  21624. +*/
  21625. +static struct SM_RESOURCE_T *vmcs_sm_acquire_first_resource(
  21626. + struct SM_PRIV_DATA_T *private)
  21627. +{
  21628. + struct SM_RESOURCE_T *resource, *ret = NULL;
  21629. +
  21630. + mutex_lock(&(sm_state->map_lock));
  21631. +
  21632. + list_for_each_entry(resource, &private->resource_list, resource_list) {
  21633. + pr_debug("[%s]: located resource %p (guid: %x, base addr %p, hdl %x, size %u, cache %u)\n",
  21634. + __func__, resource, resource->res_guid,
  21635. + resource->res_base_mem, resource->res_handle,
  21636. + resource->res_size, resource->res_cached);
  21637. + resource->ref_count++;
  21638. + ret = resource;
  21639. + break;
  21640. + }
  21641. +
  21642. + mutex_unlock(&(sm_state->map_lock));
  21643. +
  21644. + return ret;
  21645. +}
  21646. +
  21647. +/* Locates a resource and acquire a reference on it.
  21648. +** The resource won't be deleted while there is a reference on it.
  21649. +*/
  21650. +static struct SM_RESOURCE_T *vmcs_sm_acquire_global_resource(unsigned int
  21651. + res_guid)
  21652. +{
  21653. + struct SM_RESOURCE_T *resource, *ret = NULL;
  21654. +
  21655. + mutex_lock(&(sm_state->map_lock));
  21656. +
  21657. + list_for_each_entry(resource, &sm_state->resource_list,
  21658. + global_resource_list) {
  21659. + if (resource->res_guid != res_guid)
  21660. + continue;
  21661. +
  21662. + pr_debug("[%s]: located resource %p (guid: %x, base addr %p, hdl %x, size %u, cache %u)\n",
  21663. + __func__, resource, resource->res_guid,
  21664. + resource->res_base_mem, resource->res_handle,
  21665. + resource->res_size, resource->res_cached);
  21666. + resource->ref_count++;
  21667. + ret = resource;
  21668. + break;
  21669. + }
  21670. +
  21671. + mutex_unlock(&(sm_state->map_lock));
  21672. +
  21673. + return ret;
  21674. +}
  21675. +
  21676. +/* Release a previously acquired resource.
  21677. +** The resource will be deleted when its refcount reaches 0.
  21678. +*/
  21679. +static void vmcs_sm_release_resource(struct SM_RESOURCE_T *resource, int force)
  21680. +{
  21681. + struct SM_PRIV_DATA_T *private = resource->private;
  21682. + struct sm_mmap *map, *map_tmp;
  21683. + struct SM_RESOURCE_T *res_tmp;
  21684. + int ret;
  21685. +
  21686. + mutex_lock(&(sm_state->map_lock));
  21687. +
  21688. + if (--resource->ref_count) {
  21689. + if (force)
  21690. + pr_err("[%s]: resource %p in use\n", __func__, resource);
  21691. +
  21692. + mutex_unlock(&(sm_state->map_lock));
  21693. + return;
  21694. + }
  21695. +
  21696. + /* Time to free the resource. Start by removing it from the list */
  21697. + list_del(&resource->resource_list);
  21698. + list_del(&resource->global_resource_list);
  21699. +
  21700. + /* Walk the global resource list, find out if the resource is used
  21701. + * somewhere else. In which case we don't want to delete it.
  21702. + */
  21703. + list_for_each_entry(res_tmp, &sm_state->resource_list,
  21704. + global_resource_list) {
  21705. + if (res_tmp->res_handle == resource->res_handle) {
  21706. + resource->res_handle = 0;
  21707. + break;
  21708. + }
  21709. + }
  21710. +
  21711. + mutex_unlock(&(sm_state->map_lock));
  21712. +
  21713. + pr_debug("[%s]: freeing data - guid %x, hdl %x, base address %p\n",
  21714. + __func__, resource->res_guid, resource->res_handle,
  21715. + resource->res_base_mem);
  21716. + resource->res_stats[FREE]++;
  21717. +
  21718. + /* Make sure the resource we're removing is unmapped first */
  21719. + if (resource->map_count && !list_empty(&resource->map_list)) {
  21720. + down_write(&current->mm->mmap_sem);
  21721. + list_for_each_entry_safe(map, map_tmp, &resource->map_list,
  21722. + resource_map_list) {
  21723. + ret =
  21724. + do_munmap(current->mm, map->res_addr,
  21725. + resource->res_size);
  21726. + if (ret) {
  21727. + pr_err("[%s]: could not unmap resource %p\n",
  21728. + __func__, resource);
  21729. + }
  21730. + }
  21731. + up_write(&current->mm->mmap_sem);
  21732. + }
  21733. +
  21734. + /* Free up the videocore allocated resource.
  21735. + */
  21736. + if (resource->res_handle) {
  21737. + VC_SM_FREE_T free = {
  21738. + resource->res_handle, resource->res_base_mem
  21739. + };
  21740. + int status = vc_vchi_sm_free(sm_state->sm_handle, &free,
  21741. + &private->int_trans_id);
  21742. + if (status != 0 && status != -EINTR) {
  21743. + pr_err("[%s]: failed to free memory on videocore (status: %u, trans_id: %u)\n",
  21744. + __func__, status, private->int_trans_id);
  21745. + resource->res_stats[FREE_FAIL]++;
  21746. + ret = -EPERM;
  21747. + }
  21748. + }
  21749. +
  21750. + /* Free up the shared resource.
  21751. + */
  21752. + if (resource->res_shared)
  21753. + vmcs_sm_release_resource(resource->res_shared, 0);
  21754. +
  21755. + /* Free up the local resource tracking this allocation.
  21756. + */
  21757. + vc_sm_resource_deceased(resource, force);
  21758. + kfree(resource);
  21759. +}
  21760. +
  21761. +/* Dump the map table for the driver. If process is -1, dumps the whole table,
  21762. +** if process is a valid pid (non -1) dump only the entries associated with the
  21763. +** pid of interest.
  21764. +*/
  21765. +static void vmcs_sm_host_walk_map_per_pid(int pid)
  21766. +{
  21767. + struct sm_mmap *map = NULL;
  21768. +
  21769. + /* Make sure the device was started properly.
  21770. + */
  21771. + if (sm_state == NULL) {
  21772. + pr_err("[%s]: invalid device\n", __func__);
  21773. + return;
  21774. + }
  21775. +
  21776. + mutex_lock(&(sm_state->map_lock));
  21777. +
  21778. + /* Log all applicable mapping(s).
  21779. + */
  21780. + if (!list_empty(&sm_state->map_list)) {
  21781. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  21782. + if (pid == -1 || map->res_pid == pid) {
  21783. + pr_info("[%s]: tgid: %u - vc-hdl: %x, usr-hdl: %x, usr-addr: %lx\n",
  21784. + __func__, map->res_pid, map->res_vc_hdl,
  21785. + map->res_usr_hdl, map->res_addr);
  21786. + }
  21787. + }
  21788. + }
  21789. +
  21790. + mutex_unlock(&(sm_state->map_lock));
  21791. +
  21792. + return;
  21793. +}
  21794. +
  21795. +/* Dump the allocation table from host side point of view. This only dumps the
  21796. +** data allocated for this process/device referenced by the file_data.
  21797. +*/
  21798. +static void vmcs_sm_host_walk_alloc(struct SM_PRIV_DATA_T *file_data)
  21799. +{
  21800. + struct SM_RESOURCE_T *resource = NULL;
  21801. +
  21802. + /* Make sure the device was started properly.
  21803. + */
  21804. + if ((sm_state == NULL) || (file_data == NULL)) {
  21805. + pr_err("[%s]: invalid device\n", __func__);
  21806. + return;
  21807. + }
  21808. +
  21809. + mutex_lock(&(sm_state->map_lock));
  21810. +
  21811. + if (!list_empty(&file_data->resource_list)) {
  21812. + list_for_each_entry(resource, &file_data->resource_list,
  21813. + resource_list) {
  21814. + pr_info("[%s]: guid: %x - hdl: %x, vc-mem: %p, size: %u, cache: %u\n",
  21815. + __func__, resource->res_guid, resource->res_handle,
  21816. + resource->res_base_mem, resource->res_size,
  21817. + resource->res_cached);
  21818. + }
  21819. + }
  21820. +
  21821. + mutex_unlock(&(sm_state->map_lock));
  21822. +
  21823. + return;
  21824. +}
  21825. +
  21826. +/* Create support for private data tracking.
  21827. +*/
  21828. +static struct SM_PRIV_DATA_T *vc_sm_create_priv_data(pid_t id)
  21829. +{
  21830. + char alloc_name[32];
  21831. + struct SM_PRIV_DATA_T *file_data = NULL;
  21832. +
  21833. + /* Allocate private structure. */
  21834. + file_data = kzalloc(sizeof(*file_data), GFP_KERNEL);
  21835. +
  21836. + if (!file_data) {
  21837. + pr_err("[%s]: cannot allocate file data\n", __func__);
  21838. + goto out;
  21839. + }
  21840. +
  21841. + snprintf(alloc_name, sizeof(alloc_name), "%d", id);
  21842. +
  21843. + INIT_LIST_HEAD(&file_data->resource_list);
  21844. + file_data->pid = id;
  21845. + file_data->dir_pid = debugfs_create_dir(alloc_name,
  21846. + sm_state->dir_alloc);
  21847. +#if 0
  21848. + /* TODO: fix this to support querying statistics per pid */
  21849. +
  21850. + if (IS_ERR_OR_NULL(file_data->dir_pid)) {
  21851. + file_data->dir_pid = NULL;
  21852. + } else {
  21853. + struct dentry *dir_entry;
  21854. +
  21855. + dir_entry = debugfs_create_file(VC_SM_RESOURCES, S_IRUGO,
  21856. + file_data->dir_pid, file_data,
  21857. + vc_sm_debug_fs_fops);
  21858. +
  21859. + file_data->dir_res.dir_entry = dir_entry;
  21860. + file_data->dir_res.priv_data = file_data;
  21861. + file_data->dir_res.show = &vc_sm_alloc_show;
  21862. +
  21863. + dir_entry = debugfs_create_file(VC_SM_STATS, S_IRUGO,
  21864. + file_data->dir_pid, file_data,
  21865. + vc_sm_debug_fs_fops);
  21866. +
  21867. + file_data->dir_res.dir_entry = dir_entry;
  21868. + file_data->dir_res.priv_data = file_data;
  21869. + file_data->dir_res.show = &vc_sm_statistics_show;
  21870. + }
  21871. + pr_debug("[%s]: private data allocated %p\n", __func__, file_data);
  21872. +
  21873. +#endif
  21874. +out:
  21875. + return file_data;
  21876. +}
  21877. +
  21878. +/* Open the device. Creates a private state to help track all allocation
  21879. +** associated with this device.
  21880. +*/
  21881. +static int vc_sm_open(struct inode *inode, struct file *file)
  21882. +{
  21883. + int ret = 0;
  21884. +
  21885. + /* Make sure the device was started properly.
  21886. + */
  21887. + if (!sm_state) {
  21888. + pr_err("[%s]: invalid device\n", __func__);
  21889. + ret = -EPERM;
  21890. + goto out;
  21891. + }
  21892. +
  21893. + file->private_data = vc_sm_create_priv_data(current->tgid);
  21894. + if (file->private_data == NULL) {
  21895. + pr_err("[%s]: failed to create data tracker\n", __func__);
  21896. +
  21897. + ret = -ENOMEM;
  21898. + goto out;
  21899. + }
  21900. +
  21901. +out:
  21902. + return ret;
  21903. +}
  21904. +
  21905. +/* Close the device. Free up all resources still associated with this device
  21906. +** at the time.
  21907. +*/
  21908. +static int vc_sm_release(struct inode *inode, struct file *file)
  21909. +{
  21910. + struct SM_PRIV_DATA_T *file_data =
  21911. + (struct SM_PRIV_DATA_T *)file->private_data;
  21912. + struct SM_RESOURCE_T *resource;
  21913. + int ret = 0;
  21914. +
  21915. + /* Make sure the device was started properly.
  21916. + */
  21917. + if (sm_state == NULL || file_data == NULL) {
  21918. + pr_err("[%s]: invalid device\n", __func__);
  21919. + ret = -EPERM;
  21920. + goto out;
  21921. + }
  21922. +
  21923. + pr_debug("[%s]: using private data %p\n", __func__, file_data);
  21924. +
  21925. + if (file_data->restart_sys == -EINTR) {
  21926. + VC_SM_ACTION_CLEAN_T action_clean;
  21927. +
  21928. + pr_debug("[%s]: releasing following EINTR on %u (trans_id: %u) (likely due to signal)...\n",
  21929. + __func__, file_data->int_action,
  21930. + file_data->int_trans_id);
  21931. +
  21932. + action_clean.res_action = file_data->int_action;
  21933. + action_clean.action_trans_id = file_data->int_trans_id;
  21934. +
  21935. + vc_vchi_sm_clean_up(sm_state->sm_handle, &action_clean);
  21936. + }
  21937. +
  21938. + while ((resource = vmcs_sm_acquire_first_resource(file_data)) != NULL) {
  21939. + vmcs_sm_release_resource(resource, 0);
  21940. + vmcs_sm_release_resource(resource, 1);
  21941. + }
  21942. +
  21943. + /* Remove the corresponding proc entry. */
  21944. + debugfs_remove_recursive(file_data->dir_pid);
  21945. +
  21946. + /* Terminate the private data.
  21947. + */
  21948. + kfree(file_data);
  21949. +
  21950. +out:
  21951. + return ret;
  21952. +}
  21953. +
  21954. +static void vcsm_vma_open(struct vm_area_struct *vma)
  21955. +{
  21956. + struct sm_mmap *map = (struct sm_mmap *)vma->vm_private_data;
  21957. +
  21958. + pr_debug("[%s]: virt %lx-%lx, pid %i, pfn %i\n",
  21959. + __func__, vma->vm_start, vma->vm_end, (int)current->tgid,
  21960. + (int)vma->vm_pgoff);
  21961. +
  21962. + map->ref_count++;
  21963. +}
  21964. +
  21965. +static void vcsm_vma_close(struct vm_area_struct *vma)
  21966. +{
  21967. + struct sm_mmap *map = (struct sm_mmap *)vma->vm_private_data;
  21968. +
  21969. + pr_debug("[%s]: virt %lx-%lx, pid %i, pfn %i\n",
  21970. + __func__, vma->vm_start, vma->vm_end, (int)current->tgid,
  21971. + (int)vma->vm_pgoff);
  21972. +
  21973. + map->ref_count--;
  21974. +
  21975. + /* Remove from the map table.
  21976. + */
  21977. + if (map->ref_count == 0)
  21978. + vmcs_sm_remove_map(sm_state, map->resource, map);
  21979. +}
  21980. +
  21981. +static int vcsm_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
  21982. +{
  21983. + struct sm_mmap *map = (struct sm_mmap *)vma->vm_private_data;
  21984. + struct SM_RESOURCE_T *resource = map->resource;
  21985. + pgoff_t page_offset;
  21986. + unsigned long pfn;
  21987. + int ret = 0;
  21988. +
  21989. + /* Lock the resource if necessary.
  21990. + */
  21991. + if (!resource->lock_count) {
  21992. + VC_SM_LOCK_UNLOCK_T lock_unlock;
  21993. + VC_SM_LOCK_RESULT_T lock_result;
  21994. + int status;
  21995. +
  21996. + lock_unlock.res_handle = resource->res_handle;
  21997. + lock_unlock.res_mem = resource->res_base_mem;
  21998. +
  21999. + pr_debug("[%s]: attempt to lock data - hdl %x, base address %p\n",
  22000. + __func__, lock_unlock.res_handle, lock_unlock.res_mem);
  22001. +
  22002. + /* Lock the videocore allocated resource.
  22003. + */
  22004. + status = vc_vchi_sm_lock(sm_state->sm_handle,
  22005. + &lock_unlock, &lock_result, 0);
  22006. + if ((status != 0) ||
  22007. + ((status == 0) && (lock_result.res_mem == NULL))) {
  22008. + pr_err("[%s]: failed to lock memory on videocore (status: %u)\n",
  22009. + __func__, status);
  22010. + resource->res_stats[LOCK_FAIL]++;
  22011. + return VM_FAULT_SIGBUS;
  22012. + }
  22013. +
  22014. + pfn = vcaddr_to_pfn((unsigned long)resource->res_base_mem);
  22015. + outer_inv_range(__pfn_to_phys(pfn),
  22016. + __pfn_to_phys(pfn) + resource->res_size);
  22017. +
  22018. + resource->res_stats[LOCK]++;
  22019. + resource->lock_count++;
  22020. +
  22021. + /* Keep track of the new base memory.
  22022. + */
  22023. + if ((lock_result.res_mem != NULL) &&
  22024. + (lock_result.res_old_mem != NULL) &&
  22025. + (lock_result.res_mem != lock_result.res_old_mem)) {
  22026. + resource->res_base_mem = lock_result.res_mem;
  22027. + }
  22028. + }
  22029. +
  22030. + /* We don't use vmf->pgoff since that has the fake offset */
  22031. + page_offset = ((unsigned long)vmf->virtual_address - vma->vm_start);
  22032. + pfn = (uint32_t)resource->res_base_mem & 0x3FFFFFFF;
  22033. + pfn += mm_vc_mem_phys_addr;
  22034. + pfn += page_offset;
  22035. + pfn >>= PAGE_SHIFT;
  22036. +
  22037. + /* Finally, remap it */
  22038. + ret = vm_insert_pfn(vma, (unsigned long)vmf->virtual_address, pfn);
  22039. +
  22040. + switch (ret) {
  22041. + case 0:
  22042. + case -ERESTARTSYS:
  22043. + return VM_FAULT_NOPAGE;
  22044. + case -ENOMEM:
  22045. + case -EAGAIN:
  22046. + return VM_FAULT_OOM;
  22047. + default:
  22048. + return VM_FAULT_SIGBUS;
  22049. + }
  22050. +}
  22051. +
  22052. +static struct vm_operations_struct vcsm_vm_ops = {
  22053. + .open = vcsm_vma_open,
  22054. + .close = vcsm_vma_close,
  22055. + .fault = vcsm_vma_fault,
  22056. +};
  22057. +
  22058. +/* Walks a VMA and clean each valid page from the cache */
  22059. +static void vcsm_vma_cache_clean_page_range(unsigned long addr,
  22060. + unsigned long end)
  22061. +{
  22062. + pgd_t *pgd;
  22063. + pud_t *pud;
  22064. + pmd_t *pmd;
  22065. + pte_t *pte;
  22066. + unsigned long pgd_next, pud_next, pmd_next;
  22067. +
  22068. + if (addr >= end)
  22069. + return;
  22070. +
  22071. + /* Walk PGD */
  22072. + pgd = pgd_offset(current->mm, addr);
  22073. + do {
  22074. + pgd_next = pgd_addr_end(addr, end);
  22075. +
  22076. + if (pgd_none(*pgd) || pgd_bad(*pgd))
  22077. + continue;
  22078. +
  22079. + /* Walk PUD */
  22080. + pud = pud_offset(pgd, addr);
  22081. + do {
  22082. + pud_next = pud_addr_end(addr, pgd_next);
  22083. + if (pud_none(*pud) || pud_bad(*pud))
  22084. + continue;
  22085. +
  22086. + /* Walk PMD */
  22087. + pmd = pmd_offset(pud, addr);
  22088. + do {
  22089. + pmd_next = pmd_addr_end(addr, pud_next);
  22090. + if (pmd_none(*pmd) || pmd_bad(*pmd))
  22091. + continue;
  22092. +
  22093. + /* Walk PTE */
  22094. + pte = pte_offset_map(pmd, addr);
  22095. + do {
  22096. + if (pte_none(*pte)
  22097. + || !pte_present(*pte))
  22098. + continue;
  22099. +
  22100. + /* Clean + invalidate */
  22101. + dmac_flush_range((const void *) addr,
  22102. + (const void *)
  22103. + (addr + PAGE_SIZE));
  22104. +
  22105. + } while (pte++, addr +=
  22106. + PAGE_SIZE, addr != pmd_next);
  22107. + pte_unmap(pte);
  22108. +
  22109. + } while (pmd++, addr = pmd_next, addr != pud_next);
  22110. +
  22111. + } while (pud++, addr = pud_next, addr != pgd_next);
  22112. + } while (pgd++, addr = pgd_next, addr != end);
  22113. +}
  22114. +
  22115. +/* Map an allocated data into something that the user space.
  22116. +*/
  22117. +static int vc_sm_mmap(struct file *file, struct vm_area_struct *vma)
  22118. +{
  22119. + int ret = 0;
  22120. + struct SM_PRIV_DATA_T *file_data =
  22121. + (struct SM_PRIV_DATA_T *)file->private_data;
  22122. + struct SM_RESOURCE_T *resource = NULL;
  22123. + struct sm_mmap *map = NULL;
  22124. +
  22125. + /* Make sure the device was started properly.
  22126. + */
  22127. + if ((sm_state == NULL) || (file_data == NULL)) {
  22128. + pr_err("[%s]: invalid device\n", __func__);
  22129. + return -EPERM;
  22130. + }
  22131. +
  22132. + pr_debug("[%s]: private data %p, guid %x\n", __func__, file_data,
  22133. + ((unsigned int)vma->vm_pgoff << PAGE_SHIFT));
  22134. +
  22135. + /* We lookup to make sure that the data we are being asked to mmap is
  22136. + ** something that we allocated.
  22137. + **
  22138. + ** We use the offset information as the key to tell us which resource
  22139. + ** we are mapping.
  22140. + */
  22141. + resource = vmcs_sm_acquire_resource(file_data,
  22142. + ((unsigned int)vma->vm_pgoff <<
  22143. + PAGE_SHIFT));
  22144. + if (resource == NULL) {
  22145. + pr_err("[%s]: failed to locate resource for guid %x\n", __func__,
  22146. + ((unsigned int)vma->vm_pgoff << PAGE_SHIFT));
  22147. + return -ENOMEM;
  22148. + }
  22149. +
  22150. + pr_debug("[%s]: guid %x, tgid %u, %u, %u\n",
  22151. + __func__, resource->res_guid, current->tgid, resource->pid,
  22152. + file_data->pid);
  22153. +
  22154. + /* Check permissions.
  22155. + */
  22156. + if (resource->pid && (resource->pid != current->tgid)) {
  22157. + pr_err("[%s]: current tgid %u != %u owner\n",
  22158. + __func__, current->tgid, resource->pid);
  22159. + ret = -EPERM;
  22160. + goto error;
  22161. + }
  22162. +
  22163. + /* Verify that what we are asked to mmap is proper.
  22164. + */
  22165. + if (resource->res_size != (unsigned int)(vma->vm_end - vma->vm_start)) {
  22166. + pr_err("[%s]: size inconsistency (resource: %u - mmap: %u)\n",
  22167. + __func__,
  22168. + resource->res_size,
  22169. + (unsigned int)(vma->vm_end - vma->vm_start));
  22170. +
  22171. + ret = -EINVAL;
  22172. + goto error;
  22173. + }
  22174. +
  22175. + /* Keep track of the tuple in the global resource list such that one
  22176. + * can do a mapping lookup for address/memory handle.
  22177. + */
  22178. + map = kzalloc(sizeof(*map), GFP_KERNEL);
  22179. + if (map == NULL) {
  22180. + pr_err("[%s]: failed to allocate global tracking resource\n",
  22181. + __func__);
  22182. + ret = -ENOMEM;
  22183. + goto error;
  22184. + }
  22185. +
  22186. + map->res_pid = current->tgid;
  22187. + map->res_vc_hdl = resource->res_handle;
  22188. + map->res_usr_hdl = resource->res_guid;
  22189. + map->res_addr = (long unsigned int)vma->vm_start;
  22190. + map->resource = resource;
  22191. + map->vma = vma;
  22192. + vmcs_sm_add_map(sm_state, resource, map);
  22193. +
  22194. + /* We are not actually mapping the pages, we just provide a fault
  22195. + ** handler to allow pages to be mapped when accessed
  22196. + */
  22197. + vma->vm_flags |=
  22198. + VM_IO | VM_PFNMAP | VM_DONTCOPY | VM_DONTEXPAND;
  22199. + vma->vm_ops = &vcsm_vm_ops;
  22200. + vma->vm_private_data = map;
  22201. +
  22202. + /* vm_pgoff is the first PFN of the mapped memory */
  22203. + vma->vm_pgoff = (unsigned long)resource->res_base_mem & 0x3FFFFFFF;
  22204. + vma->vm_pgoff += mm_vc_mem_phys_addr;
  22205. + vma->vm_pgoff >>= PAGE_SHIFT;
  22206. +
  22207. + if ((resource->res_cached == VMCS_SM_CACHE_NONE) ||
  22208. + (resource->res_cached == VMCS_SM_CACHE_VC)) {
  22209. + /* Allocated non host cached memory, honour it.
  22210. + */
  22211. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  22212. + }
  22213. +
  22214. + pr_debug("[%s]: resource %p (guid %x) - cnt %u, base address %p, handle %x, size %u (%u), cache %u\n",
  22215. + __func__,
  22216. + resource, resource->res_guid, resource->lock_count,
  22217. + resource->res_base_mem, resource->res_handle,
  22218. + resource->res_size, (unsigned int)(vma->vm_end - vma->vm_start),
  22219. + resource->res_cached);
  22220. +
  22221. + pr_debug("[%s]: resource %p (base address %p, handle %x) - map-count %d, usr-addr %x\n",
  22222. + __func__, resource, resource->res_base_mem,
  22223. + resource->res_handle, resource->map_count,
  22224. + (unsigned int)vma->vm_start);
  22225. +
  22226. + vcsm_vma_open(vma);
  22227. + resource->res_stats[MAP]++;
  22228. + vmcs_sm_release_resource(resource, 0);
  22229. + return 0;
  22230. +
  22231. +error:
  22232. + vmcs_sm_release_resource(resource, 0);
  22233. + resource->res_stats[MAP_FAIL]++;
  22234. + return ret;
  22235. +}
  22236. +
  22237. +/* Allocate a shared memory handle and block.
  22238. +*/
  22239. +int vc_sm_ioctl_alloc(struct SM_PRIV_DATA_T *private,
  22240. + struct vmcs_sm_ioctl_alloc *ioparam)
  22241. +{
  22242. + int ret = 0;
  22243. + int status;
  22244. + struct SM_RESOURCE_T *resource;
  22245. + VC_SM_ALLOC_T alloc = { 0 };
  22246. + VC_SM_ALLOC_RESULT_T result = { 0 };
  22247. +
  22248. + /* Setup our allocation parameters */
  22249. + alloc.type = ((ioparam->cached == VMCS_SM_CACHE_VC)
  22250. + || (ioparam->cached ==
  22251. + VMCS_SM_CACHE_BOTH)) ? VC_SM_ALLOC_CACHED :
  22252. + VC_SM_ALLOC_NON_CACHED;
  22253. + alloc.base_unit = ioparam->size;
  22254. + alloc.num_unit = ioparam->num;
  22255. + alloc.allocator = current->tgid;
  22256. + /* Align to kernel page size */
  22257. + alloc.alignement = 4096;
  22258. + /* Align the size to the kernel page size */
  22259. + alloc.base_unit =
  22260. + (alloc.base_unit + alloc.alignement - 1) & ~(alloc.alignement - 1);
  22261. + if (*ioparam->name) {
  22262. + memcpy(alloc.name, ioparam->name, sizeof(alloc.name) - 1);
  22263. + } else {
  22264. + memcpy(alloc.name, VMCS_SM_RESOURCE_NAME_DEFAULT,
  22265. + sizeof(VMCS_SM_RESOURCE_NAME_DEFAULT));
  22266. + }
  22267. +
  22268. + pr_debug("[%s]: attempt to allocate \"%s\" data - type %u, base %u (%u), num %u, alignement %u\n",
  22269. + __func__, alloc.name, alloc.type, ioparam->size,
  22270. + alloc.base_unit, alloc.num_unit, alloc.alignement);
  22271. +
  22272. + /* Allocate local resource to track this allocation.
  22273. + */
  22274. + resource = kzalloc(sizeof(*resource), GFP_KERNEL);
  22275. + if (!resource) {
  22276. + ret = -ENOMEM;
  22277. + goto error;
  22278. + }
  22279. + INIT_LIST_HEAD(&resource->map_list);
  22280. + resource->ref_count++;
  22281. + resource->pid = current->tgid;
  22282. +
  22283. + /* Allocate the videocore resource.
  22284. + */
  22285. + status = vc_vchi_sm_alloc(sm_state->sm_handle, &alloc, &result,
  22286. + &private->int_trans_id);
  22287. + if (status == -EINTR) {
  22288. + pr_debug("[%s]: requesting allocate memory action restart (trans_id: %u)\n",
  22289. + __func__, private->int_trans_id);
  22290. + ret = -ERESTARTSYS;
  22291. + private->restart_sys = -EINTR;
  22292. + private->int_action = VC_SM_MSG_TYPE_ALLOC;
  22293. + goto error;
  22294. + } else if (status != 0 || (status == 0 && result.res_mem == NULL)) {
  22295. + pr_err("[%s]: failed to allocate memory on videocore (status: %u, trans_id: %u)\n",
  22296. + __func__, status, private->int_trans_id);
  22297. + ret = -ENOMEM;
  22298. + resource->res_stats[ALLOC_FAIL]++;
  22299. + goto error;
  22300. + }
  22301. +
  22302. + /* Keep track of the resource we created.
  22303. + */
  22304. + resource->private = private;
  22305. + resource->res_handle = result.res_handle;
  22306. + resource->res_base_mem = result.res_mem;
  22307. + resource->res_size = alloc.base_unit * alloc.num_unit;
  22308. + resource->res_cached = ioparam->cached;
  22309. +
  22310. + /* Kernel/user GUID. This global identifier is used for mmap'ing the
  22311. + * allocated region from user space, it is passed as the mmap'ing
  22312. + * offset, we use it to 'hide' the videocore handle/address.
  22313. + */
  22314. + mutex_lock(&sm_state->lock);
  22315. + resource->res_guid = ++sm_state->guid;
  22316. + mutex_unlock(&sm_state->lock);
  22317. + resource->res_guid <<= PAGE_SHIFT;
  22318. +
  22319. + vmcs_sm_add_resource(private, resource);
  22320. +
  22321. + pr_debug("[%s]: allocated data - guid %x, hdl %x, base address %p, size %d, cache %d\n",
  22322. + __func__, resource->res_guid, resource->res_handle,
  22323. + resource->res_base_mem, resource->res_size,
  22324. + resource->res_cached);
  22325. +
  22326. + /* We're done */
  22327. + resource->res_stats[ALLOC]++;
  22328. + ioparam->handle = resource->res_guid;
  22329. + return 0;
  22330. +
  22331. +error:
  22332. + pr_err("[%s]: failed to allocate \"%s\" data (%i) - type %u, base %u (%u), num %u, alignment %u\n",
  22333. + __func__, alloc.name, ret, alloc.type, ioparam->size,
  22334. + alloc.base_unit, alloc.num_unit, alloc.alignement);
  22335. + if (resource != NULL) {
  22336. + vc_sm_resource_deceased(resource, 1);
  22337. + kfree(resource);
  22338. + }
  22339. + return ret;
  22340. +}
  22341. +
  22342. +/* Share an allocate memory handle and block.
  22343. +*/
  22344. +int vc_sm_ioctl_alloc_share(struct SM_PRIV_DATA_T *private,
  22345. + struct vmcs_sm_ioctl_alloc_share *ioparam)
  22346. +{
  22347. + struct SM_RESOURCE_T *resource, *shared_resource;
  22348. + int ret = 0;
  22349. +
  22350. + pr_debug("[%s]: attempt to share resource %u\n", __func__,
  22351. + ioparam->handle);
  22352. +
  22353. + shared_resource = vmcs_sm_acquire_global_resource(ioparam->handle);
  22354. + if (shared_resource == NULL) {
  22355. + ret = -ENOMEM;
  22356. + goto error;
  22357. + }
  22358. +
  22359. + /* Allocate local resource to track this allocation.
  22360. + */
  22361. + resource = kzalloc(sizeof(*resource), GFP_KERNEL);
  22362. + if (resource == NULL) {
  22363. + pr_err("[%s]: failed to allocate local tracking resource\n",
  22364. + __func__);
  22365. + ret = -ENOMEM;
  22366. + goto error;
  22367. + }
  22368. + INIT_LIST_HEAD(&resource->map_list);
  22369. + resource->ref_count++;
  22370. + resource->pid = current->tgid;
  22371. +
  22372. + /* Keep track of the resource we created.
  22373. + */
  22374. + resource->private = private;
  22375. + resource->res_handle = shared_resource->res_handle;
  22376. + resource->res_base_mem = shared_resource->res_base_mem;
  22377. + resource->res_size = shared_resource->res_size;
  22378. + resource->res_cached = shared_resource->res_cached;
  22379. + resource->res_shared = shared_resource;
  22380. +
  22381. + mutex_lock(&sm_state->lock);
  22382. + resource->res_guid = ++sm_state->guid;
  22383. + mutex_unlock(&sm_state->lock);
  22384. + resource->res_guid <<= PAGE_SHIFT;
  22385. +
  22386. + vmcs_sm_add_resource(private, resource);
  22387. +
  22388. + pr_debug("[%s]: allocated data - guid %x, hdl %x, base address %p, size %d, cache %d\n",
  22389. + __func__, resource->res_guid, resource->res_handle,
  22390. + resource->res_base_mem, resource->res_size,
  22391. + resource->res_cached);
  22392. +
  22393. + /* We're done */
  22394. + resource->res_stats[ALLOC]++;
  22395. + ioparam->handle = resource->res_guid;
  22396. + ioparam->size = resource->res_size;
  22397. + return 0;
  22398. +
  22399. +error:
  22400. + pr_err("[%s]: failed to share %u\n", __func__, ioparam->handle);
  22401. + if (shared_resource != NULL)
  22402. + vmcs_sm_release_resource(shared_resource, 0);
  22403. +
  22404. + return ret;
  22405. +}
  22406. +
  22407. +/* Free a previously allocated shared memory handle and block.
  22408. +*/
  22409. +static int vc_sm_ioctl_free(struct SM_PRIV_DATA_T *private,
  22410. + struct vmcs_sm_ioctl_free *ioparam)
  22411. +{
  22412. + struct SM_RESOURCE_T *resource =
  22413. + vmcs_sm_acquire_resource(private, ioparam->handle);
  22414. +
  22415. + if (resource == NULL) {
  22416. + pr_err("[%s]: resource for guid %u does not exist\n", __func__,
  22417. + ioparam->handle);
  22418. + return -EINVAL;
  22419. + }
  22420. +
  22421. + /* Check permissions.
  22422. + */
  22423. + if (resource->pid && (resource->pid != current->tgid)) {
  22424. + pr_err("[%s]: current tgid %u != %u owner\n",
  22425. + __func__, current->tgid, resource->pid);
  22426. + vmcs_sm_release_resource(resource, 0);
  22427. + return -EPERM;
  22428. + }
  22429. +
  22430. + vmcs_sm_release_resource(resource, 0);
  22431. + vmcs_sm_release_resource(resource, 0);
  22432. + return 0;
  22433. +}
  22434. +
  22435. +/* Resize a previously allocated shared memory handle and block.
  22436. +*/
  22437. +static int vc_sm_ioctl_resize(struct SM_PRIV_DATA_T *private,
  22438. + struct vmcs_sm_ioctl_resize *ioparam)
  22439. +{
  22440. + int ret = 0;
  22441. + int status;
  22442. + VC_SM_RESIZE_T resize;
  22443. + struct SM_RESOURCE_T *resource;
  22444. +
  22445. + /* Locate resource from GUID.
  22446. + */
  22447. + resource = vmcs_sm_acquire_resource(private, ioparam->handle);
  22448. + if (!resource) {
  22449. + pr_err("[%s]: failed resource - guid %x\n",
  22450. + __func__, ioparam->handle);
  22451. + ret = -EFAULT;
  22452. + goto error;
  22453. + }
  22454. +
  22455. + /* If the resource is locked, its reference count will be not NULL,
  22456. + ** in which case we will not be allowed to resize it anyways, so
  22457. + ** reject the attempt here.
  22458. + */
  22459. + if (resource->lock_count != 0) {
  22460. + pr_err("[%s]: cannot resize - guid %x, ref-cnt %d\n",
  22461. + __func__, ioparam->handle, resource->lock_count);
  22462. + ret = -EFAULT;
  22463. + goto error;
  22464. + }
  22465. +
  22466. + /* Check permissions.
  22467. + */
  22468. + if (resource->pid && (resource->pid != current->tgid)) {
  22469. + pr_err("[%s]: current tgid %u != %u owner\n", __func__,
  22470. + current->tgid, resource->pid);
  22471. + ret = -EPERM;
  22472. + goto error;
  22473. + }
  22474. +
  22475. + if (resource->map_count != 0) {
  22476. + pr_err("[%s]: cannot resize - guid %x, ref-cnt %d\n",
  22477. + __func__, ioparam->handle, resource->map_count);
  22478. + ret = -EFAULT;
  22479. + goto error;
  22480. + }
  22481. +
  22482. + resize.res_handle = resource->res_handle;
  22483. + resize.res_mem = resource->res_base_mem;
  22484. + resize.res_new_size = ioparam->new_size;
  22485. +
  22486. + pr_debug("[%s]: attempt to resize data - guid %x, hdl %x, base address %p\n",
  22487. + __func__, ioparam->handle, resize.res_handle, resize.res_mem);
  22488. +
  22489. + /* Resize the videocore allocated resource.
  22490. + */
  22491. + status = vc_vchi_sm_resize(sm_state->sm_handle, &resize,
  22492. + &private->int_trans_id);
  22493. + if (status == -EINTR) {
  22494. + pr_debug("[%s]: requesting resize memory action restart (trans_id: %u)\n",
  22495. + __func__, private->int_trans_id);
  22496. + ret = -ERESTARTSYS;
  22497. + private->restart_sys = -EINTR;
  22498. + private->int_action = VC_SM_MSG_TYPE_RESIZE;
  22499. + goto error;
  22500. + } else if (status != 0) {
  22501. + pr_err("[%s]: failed to resize memory on videocore (status: %u, trans_id: %u)\n",
  22502. + __func__, status, private->int_trans_id);
  22503. + ret = -EPERM;
  22504. + goto error;
  22505. + }
  22506. +
  22507. + pr_debug("[%s]: success to resize data - hdl %x, size %d -> %d\n",
  22508. + __func__, resize.res_handle, resource->res_size,
  22509. + resize.res_new_size);
  22510. +
  22511. + /* Successfully resized, save the information and inform the user.
  22512. + */
  22513. + ioparam->old_size = resource->res_size;
  22514. + resource->res_size = resize.res_new_size;
  22515. +
  22516. +error:
  22517. + if (resource)
  22518. + vmcs_sm_release_resource(resource, 0);
  22519. +
  22520. + return ret;
  22521. +}
  22522. +
  22523. +/* Lock a previously allocated shared memory handle and block.
  22524. +*/
  22525. +static int vc_sm_ioctl_lock(struct SM_PRIV_DATA_T *private,
  22526. + struct vmcs_sm_ioctl_lock_unlock *ioparam,
  22527. + int change_cache, enum vmcs_sm_cache_e cache_type,
  22528. + unsigned int vc_addr)
  22529. +{
  22530. + int status;
  22531. + VC_SM_LOCK_UNLOCK_T lock;
  22532. + VC_SM_LOCK_RESULT_T result;
  22533. + struct SM_RESOURCE_T *resource;
  22534. + int ret = 0;
  22535. + struct sm_mmap *map, *map_tmp;
  22536. + long unsigned int phys_addr;
  22537. +
  22538. + map = NULL;
  22539. +
  22540. + /* Locate resource from GUID.
  22541. + */
  22542. + resource = vmcs_sm_acquire_resource(private, ioparam->handle);
  22543. + if (resource == NULL) {
  22544. + ret = -EINVAL;
  22545. + goto error;
  22546. + }
  22547. +
  22548. + /* Check permissions.
  22549. + */
  22550. + if (resource->pid && (resource->pid != current->tgid)) {
  22551. + pr_err("[%s]: current tgid %u != %u owner\n", __func__,
  22552. + current->tgid, resource->pid);
  22553. + ret = -EPERM;
  22554. + goto error;
  22555. + }
  22556. +
  22557. + lock.res_handle = resource->res_handle;
  22558. + lock.res_mem = resource->res_base_mem;
  22559. +
  22560. + /* Take the lock and get the address to be mapped.
  22561. + */
  22562. + if (vc_addr == 0) {
  22563. + pr_debug("[%s]: attempt to lock data - guid %x, hdl %x, base address %p\n",
  22564. + __func__, ioparam->handle, lock.res_handle,
  22565. + lock.res_mem);
  22566. +
  22567. + /* Lock the videocore allocated resource.
  22568. + */
  22569. + status = vc_vchi_sm_lock(sm_state->sm_handle, &lock, &result,
  22570. + &private->int_trans_id);
  22571. + if (status == -EINTR) {
  22572. + pr_debug("[%s]: requesting lock memory action restart (trans_id: %u)\n",
  22573. + __func__, private->int_trans_id);
  22574. + ret = -ERESTARTSYS;
  22575. + private->restart_sys = -EINTR;
  22576. + private->int_action = VC_SM_MSG_TYPE_LOCK;
  22577. + goto error;
  22578. + } else if (status != 0 ||
  22579. + (status == 0 && result.res_mem == NULL)) {
  22580. + pr_err("[%s]: failed to lock memory on videocore (status: %u, trans_id: %u)\n",
  22581. + __func__, status, private->int_trans_id);
  22582. + ret = -EPERM;
  22583. + resource->res_stats[LOCK_FAIL]++;
  22584. + goto error;
  22585. + }
  22586. +
  22587. + pr_debug("[%s]: succeed to lock data - hdl %x, base address %p (%p), ref-cnt %d\n",
  22588. + __func__, lock.res_handle, result.res_mem,
  22589. + lock.res_mem, resource->lock_count);
  22590. + }
  22591. + /* Lock assumed taken already, address to be mapped is known.
  22592. + */
  22593. + else
  22594. + resource->res_base_mem = (void *)vc_addr;
  22595. +
  22596. + resource->res_stats[LOCK]++;
  22597. + resource->lock_count++;
  22598. +
  22599. + /* Keep track of the new base memory allocation if it has changed.
  22600. + */
  22601. + if ((vc_addr == 0) &&
  22602. + (result.res_mem != NULL) &&
  22603. + (result.res_old_mem != NULL) &&
  22604. + (result.res_mem != result.res_old_mem)) {
  22605. + resource->res_base_mem = result.res_mem;
  22606. +
  22607. + /* Kernel allocated resources.
  22608. + */
  22609. + if (resource->pid == 0) {
  22610. + if (!list_empty(&resource->map_list)) {
  22611. + list_for_each_entry_safe(map, map_tmp,
  22612. + &resource->map_list,
  22613. + resource_map_list) {
  22614. + if (map->res_addr) {
  22615. + iounmap((void *)map->res_addr);
  22616. + map->res_addr = 0;
  22617. +
  22618. + vmcs_sm_remove_map(sm_state,
  22619. + map->resource,
  22620. + map);
  22621. + break;
  22622. + }
  22623. + }
  22624. + }
  22625. + }
  22626. + }
  22627. +
  22628. + if (change_cache)
  22629. + resource->res_cached = cache_type;
  22630. +
  22631. + if (resource->map_count) {
  22632. + ioparam->addr =
  22633. + vmcs_sm_usr_address_from_pid_and_usr_handle(
  22634. + current->tgid, ioparam->handle);
  22635. +
  22636. + pr_debug("[%s] map_count %d private->pid %d current->tgid %d hnd %x addr %u\n",
  22637. + __func__, resource->map_count, private->pid,
  22638. + current->tgid, ioparam->handle, ioparam->addr);
  22639. + } else {
  22640. + /* Kernel allocated resources.
  22641. + */
  22642. + if (resource->pid == 0) {
  22643. + pr_debug("[%s]: attempt mapping kernel resource - guid %x, hdl %x\n",
  22644. + __func__, ioparam->handle, lock.res_handle);
  22645. +
  22646. + ioparam->addr = 0;
  22647. +
  22648. + map = kzalloc(sizeof(*map), GFP_KERNEL);
  22649. + if (map == NULL) {
  22650. + pr_err("[%s]: failed allocating tracker\n",
  22651. + __func__);
  22652. + ret = -ENOMEM;
  22653. + goto error;
  22654. + } else {
  22655. + phys_addr = (uint32_t)resource->res_base_mem &
  22656. + 0x3FFFFFFF;
  22657. + phys_addr += mm_vc_mem_phys_addr;
  22658. + if (resource->res_cached
  22659. + == VMCS_SM_CACHE_HOST) {
  22660. + ioparam->addr = (long unsigned int)
  22661. + /* TODO - make cached work */
  22662. + ioremap_nocache(phys_addr,
  22663. + resource->res_size);
  22664. +
  22665. + pr_debug("[%s]: mapping kernel - guid %x, hdl %x - cached mapping %u\n",
  22666. + __func__, ioparam->handle,
  22667. + lock.res_handle, ioparam->addr);
  22668. + } else {
  22669. + ioparam->addr = (long unsigned int)
  22670. + ioremap_nocache(phys_addr,
  22671. + resource->res_size);
  22672. +
  22673. + pr_debug("[%s]: mapping kernel- guid %x, hdl %x - non cached mapping %u\n",
  22674. + __func__, ioparam->handle,
  22675. + lock.res_handle, ioparam->addr);
  22676. + }
  22677. +
  22678. + map->res_pid = 0;
  22679. + map->res_vc_hdl = resource->res_handle;
  22680. + map->res_usr_hdl = resource->res_guid;
  22681. + map->res_addr = ioparam->addr;
  22682. + map->resource = resource;
  22683. + map->vma = NULL;
  22684. +
  22685. + vmcs_sm_add_map(sm_state, resource, map);
  22686. + }
  22687. + } else
  22688. + ioparam->addr = 0;
  22689. + }
  22690. +
  22691. +error:
  22692. + if (resource)
  22693. + vmcs_sm_release_resource(resource, 0);
  22694. +
  22695. + return ret;
  22696. +}
  22697. +
  22698. +/* Unlock a previously allocated shared memory handle and block.
  22699. +*/
  22700. +static int vc_sm_ioctl_unlock(struct SM_PRIV_DATA_T *private,
  22701. + struct vmcs_sm_ioctl_lock_unlock *ioparam,
  22702. + int flush, int wait_reply, int no_vc_unlock)
  22703. +{
  22704. + int status;
  22705. + VC_SM_LOCK_UNLOCK_T unlock;
  22706. + struct sm_mmap *map, *map_tmp;
  22707. + struct SM_RESOURCE_T *resource;
  22708. + int ret = 0;
  22709. +
  22710. + map = NULL;
  22711. +
  22712. + /* Locate resource from GUID.
  22713. + */
  22714. + resource = vmcs_sm_acquire_resource(private, ioparam->handle);
  22715. + if (resource == NULL) {
  22716. + ret = -EINVAL;
  22717. + goto error;
  22718. + }
  22719. +
  22720. + /* Check permissions.
  22721. + */
  22722. + if (resource->pid && (resource->pid != current->tgid)) {
  22723. + pr_err("[%s]: current tgid %u != %u owner\n",
  22724. + __func__, current->tgid, resource->pid);
  22725. + ret = -EPERM;
  22726. + goto error;
  22727. + }
  22728. +
  22729. + unlock.res_handle = resource->res_handle;
  22730. + unlock.res_mem = resource->res_base_mem;
  22731. +
  22732. + pr_debug("[%s]: attempt to unlock data - guid %x, hdl %x, base address %p\n",
  22733. + __func__, ioparam->handle, unlock.res_handle, unlock.res_mem);
  22734. +
  22735. + /* User space allocated resources.
  22736. + */
  22737. + if (resource->pid) {
  22738. + /* Flush if requested */
  22739. + if (resource->res_cached && flush) {
  22740. + dma_addr_t phys_addr = 0;
  22741. + resource->res_stats[FLUSH]++;
  22742. +
  22743. + phys_addr =
  22744. + (dma_addr_t)((uint32_t)resource->res_base_mem &
  22745. + 0x3FFFFFFF);
  22746. + phys_addr += (dma_addr_t)mm_vc_mem_phys_addr;
  22747. +
  22748. + /* L1 cache flush */
  22749. + down_read(&current->mm->mmap_sem);
  22750. + list_for_each_entry(map, &resource->map_list,
  22751. + resource_map_list) {
  22752. + if (map->vma) {
  22753. + unsigned long start;
  22754. + unsigned long end;
  22755. + start = map->vma->vm_start;
  22756. + end = map->vma->vm_end;
  22757. +
  22758. + vcsm_vma_cache_clean_page_range(
  22759. + start, end);
  22760. + }
  22761. + }
  22762. + up_read(&current->mm->mmap_sem);
  22763. +
  22764. + /* L2 cache flush */
  22765. + outer_clean_range(phys_addr,
  22766. + phys_addr +
  22767. + (size_t) resource->res_size);
  22768. + }
  22769. +
  22770. + /* We need to zap all the vmas associated with this resource */
  22771. + if (resource->lock_count == 1) {
  22772. + down_read(&current->mm->mmap_sem);
  22773. + list_for_each_entry(map, &resource->map_list,
  22774. + resource_map_list) {
  22775. + if (map->vma) {
  22776. + zap_vma_ptes(map->vma,
  22777. + map->vma->vm_start,
  22778. + map->vma->vm_end -
  22779. + map->vma->vm_start);
  22780. + }
  22781. + }
  22782. + up_read(&current->mm->mmap_sem);
  22783. + }
  22784. + }
  22785. + /* Kernel allocated resources. */
  22786. + else {
  22787. + /* Global + Taken in this context */
  22788. + if (resource->ref_count == 2) {
  22789. + if (!list_empty(&resource->map_list)) {
  22790. + list_for_each_entry_safe(map, map_tmp,
  22791. + &resource->map_list,
  22792. + resource_map_list) {
  22793. + if (map->res_addr) {
  22794. + if (flush &&
  22795. + (resource->res_cached ==
  22796. + VMCS_SM_CACHE_HOST)) {
  22797. + long unsigned int
  22798. + phys_addr;
  22799. + phys_addr = (uint32_t)
  22800. + resource->res_base_mem & 0x3FFFFFFF;
  22801. + phys_addr +=
  22802. + mm_vc_mem_phys_addr;
  22803. +
  22804. + /* L1 cache flush */
  22805. + dmac_flush_range((const
  22806. + void
  22807. + *)
  22808. + map->res_addr, (const void *)
  22809. + (map->res_addr + resource->res_size));
  22810. +
  22811. + /* L2 cache flush */
  22812. + outer_clean_range
  22813. + (phys_addr,
  22814. + phys_addr +
  22815. + (size_t)
  22816. + resource->res_size);
  22817. + }
  22818. +
  22819. + iounmap((void *)map->res_addr);
  22820. + map->res_addr = 0;
  22821. +
  22822. + vmcs_sm_remove_map(sm_state,
  22823. + map->resource,
  22824. + map);
  22825. + break;
  22826. + }
  22827. + }
  22828. + }
  22829. + }
  22830. + }
  22831. +
  22832. + if (resource->lock_count) {
  22833. + /* Bypass the videocore unlock.
  22834. + */
  22835. + if (no_vc_unlock)
  22836. + status = 0;
  22837. + /* Unlock the videocore allocated resource.
  22838. + */
  22839. + else {
  22840. + status =
  22841. + vc_vchi_sm_unlock(sm_state->sm_handle, &unlock,
  22842. + &private->int_trans_id,
  22843. + wait_reply);
  22844. + if (status == -EINTR) {
  22845. + pr_debug("[%s]: requesting unlock memory action restart (trans_id: %u)\n",
  22846. + __func__, private->int_trans_id);
  22847. +
  22848. + ret = -ERESTARTSYS;
  22849. + resource->res_stats[UNLOCK]--;
  22850. + private->restart_sys = -EINTR;
  22851. + private->int_action = VC_SM_MSG_TYPE_UNLOCK;
  22852. + goto error;
  22853. + } else if (status != 0) {
  22854. + pr_err("[%s]: failed to unlock vc mem (status: %u, trans_id: %u)\n",
  22855. + __func__, status, private->int_trans_id);
  22856. +
  22857. + ret = -EPERM;
  22858. + resource->res_stats[UNLOCK_FAIL]++;
  22859. + goto error;
  22860. + }
  22861. + }
  22862. +
  22863. + resource->res_stats[UNLOCK]++;
  22864. + resource->lock_count--;
  22865. + }
  22866. +
  22867. + pr_debug("[%s]: success to unlock data - hdl %x, base address %p, ref-cnt %d\n",
  22868. + __func__, unlock.res_handle, unlock.res_mem,
  22869. + resource->lock_count);
  22870. +
  22871. +error:
  22872. + if (resource)
  22873. + vmcs_sm_release_resource(resource, 0);
  22874. +
  22875. + return ret;
  22876. +}
  22877. +
  22878. +/* Handle control from host. */
  22879. +static long vc_sm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  22880. +{
  22881. + int ret = 0;
  22882. + unsigned int cmdnr = _IOC_NR(cmd);
  22883. + struct SM_PRIV_DATA_T *file_data =
  22884. + (struct SM_PRIV_DATA_T *)file->private_data;
  22885. + struct SM_RESOURCE_T *resource = NULL;
  22886. +
  22887. + /* Validate we can work with this device. */
  22888. + if ((sm_state == NULL) || (file_data == NULL)) {
  22889. + pr_err("[%s]: invalid device\n", __func__);
  22890. + ret = -EPERM;
  22891. + goto out;
  22892. + }
  22893. +
  22894. + pr_debug("[%s]: cmd %x tgid %u, owner %u\n", __func__, cmdnr,
  22895. + current->tgid, file_data->pid);
  22896. +
  22897. + /* Action is a re-post of a previously interrupted action? */
  22898. + if (file_data->restart_sys == -EINTR) {
  22899. + VC_SM_ACTION_CLEAN_T action_clean;
  22900. +
  22901. + pr_debug("[%s]: clean up of action %u (trans_id: %u) following EINTR\n",
  22902. + __func__, file_data->int_action,
  22903. + file_data->int_trans_id);
  22904. +
  22905. + action_clean.res_action = file_data->int_action;
  22906. + action_clean.action_trans_id = file_data->int_trans_id;
  22907. +
  22908. + vc_vchi_sm_clean_up(sm_state->sm_handle, &action_clean);
  22909. +
  22910. + file_data->restart_sys = 0;
  22911. + }
  22912. +
  22913. + /* Now process the command.
  22914. + */
  22915. + switch (cmdnr) {
  22916. + /* New memory allocation.
  22917. + */
  22918. + case VMCS_SM_CMD_ALLOC:
  22919. + {
  22920. + struct vmcs_sm_ioctl_alloc ioparam;
  22921. +
  22922. + /* Get the parameter data.
  22923. + */
  22924. + if (copy_from_user
  22925. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  22926. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  22927. + __func__, cmdnr);
  22928. + ret = -EFAULT;
  22929. + goto out;
  22930. + }
  22931. +
  22932. + ret = vc_sm_ioctl_alloc(file_data, &ioparam);
  22933. + if (!ret &&
  22934. + (copy_to_user((void *)arg,
  22935. + &ioparam, sizeof(ioparam)) != 0)) {
  22936. + struct vmcs_sm_ioctl_free freeparam = {
  22937. + ioparam.handle
  22938. + };
  22939. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  22940. + __func__, cmdnr);
  22941. + vc_sm_ioctl_free(file_data, &freeparam);
  22942. + ret = -EFAULT;
  22943. + }
  22944. +
  22945. + /* Done.
  22946. + */
  22947. + goto out;
  22948. + }
  22949. + break;
  22950. +
  22951. + /* Share existing memory allocation.
  22952. + */
  22953. + case VMCS_SM_CMD_ALLOC_SHARE:
  22954. + {
  22955. + struct vmcs_sm_ioctl_alloc_share ioparam;
  22956. +
  22957. + /* Get the parameter data.
  22958. + */
  22959. + if (copy_from_user
  22960. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  22961. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  22962. + __func__, cmdnr);
  22963. + ret = -EFAULT;
  22964. + goto out;
  22965. + }
  22966. +
  22967. + ret = vc_sm_ioctl_alloc_share(file_data, &ioparam);
  22968. +
  22969. + /* Copy result back to user.
  22970. + */
  22971. + if (!ret
  22972. + && copy_to_user((void *)arg, &ioparam,
  22973. + sizeof(ioparam)) != 0) {
  22974. + struct vmcs_sm_ioctl_free freeparam = {
  22975. + ioparam.handle
  22976. + };
  22977. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  22978. + __func__, cmdnr);
  22979. + vc_sm_ioctl_free(file_data, &freeparam);
  22980. + ret = -EFAULT;
  22981. + }
  22982. +
  22983. + /* Done.
  22984. + */
  22985. + goto out;
  22986. + }
  22987. + break;
  22988. +
  22989. + /* Lock (attempt to) *and* register a cache behavior change.
  22990. + */
  22991. + case VMCS_SM_CMD_LOCK_CACHE:
  22992. + {
  22993. + struct vmcs_sm_ioctl_lock_cache ioparam;
  22994. + struct vmcs_sm_ioctl_lock_unlock lock;
  22995. +
  22996. + /* Get parameter data.
  22997. + */
  22998. + if (copy_from_user
  22999. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  23000. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23001. + __func__, cmdnr);
  23002. + ret = -EFAULT;
  23003. + goto out;
  23004. + }
  23005. +
  23006. + lock.handle = ioparam.handle;
  23007. + ret =
  23008. + vc_sm_ioctl_lock(file_data, &lock, 1,
  23009. + ioparam.cached, 0);
  23010. +
  23011. + /* Done.
  23012. + */
  23013. + goto out;
  23014. + }
  23015. + break;
  23016. +
  23017. + /* Lock (attempt to) existing memory allocation.
  23018. + */
  23019. + case VMCS_SM_CMD_LOCK:
  23020. + {
  23021. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  23022. +
  23023. + /* Get parameter data.
  23024. + */
  23025. + if (copy_from_user
  23026. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  23027. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23028. + __func__, cmdnr);
  23029. + ret = -EFAULT;
  23030. + goto out;
  23031. + }
  23032. +
  23033. + ret = vc_sm_ioctl_lock(file_data, &ioparam, 0, 0, 0);
  23034. +
  23035. + /* Copy result back to user.
  23036. + */
  23037. + if (copy_to_user((void *)arg, &ioparam, sizeof(ioparam))
  23038. + != 0) {
  23039. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23040. + __func__, cmdnr);
  23041. + ret = -EFAULT;
  23042. + }
  23043. +
  23044. + /* Done.
  23045. + */
  23046. + goto out;
  23047. + }
  23048. + break;
  23049. +
  23050. + /* Unlock (attempt to) existing memory allocation.
  23051. + */
  23052. + case VMCS_SM_CMD_UNLOCK:
  23053. + {
  23054. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  23055. +
  23056. + /* Get parameter data.
  23057. + */
  23058. + if (copy_from_user
  23059. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  23060. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23061. + __func__, cmdnr);
  23062. + ret = -EFAULT;
  23063. + goto out;
  23064. + }
  23065. +
  23066. + ret = vc_sm_ioctl_unlock(file_data, &ioparam, 0, 1, 0);
  23067. +
  23068. + /* Done.
  23069. + */
  23070. + goto out;
  23071. + }
  23072. + break;
  23073. +
  23074. + /* Resize (attempt to) existing memory allocation.
  23075. + */
  23076. + case VMCS_SM_CMD_RESIZE:
  23077. + {
  23078. + struct vmcs_sm_ioctl_resize ioparam;
  23079. +
  23080. + /* Get parameter data.
  23081. + */
  23082. + if (copy_from_user
  23083. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  23084. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23085. + __func__, cmdnr);
  23086. + ret = -EFAULT;
  23087. + goto out;
  23088. + }
  23089. +
  23090. + ret = vc_sm_ioctl_resize(file_data, &ioparam);
  23091. +
  23092. + /* Copy result back to user.
  23093. + */
  23094. + if (copy_to_user((void *)arg, &ioparam, sizeof(ioparam))
  23095. + != 0) {
  23096. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23097. + __func__, cmdnr);
  23098. + ret = -EFAULT;
  23099. + }
  23100. +
  23101. + /* Done.
  23102. + */
  23103. + goto out;
  23104. + }
  23105. + break;
  23106. +
  23107. + /* Terminate existing memory allocation.
  23108. + */
  23109. + case VMCS_SM_CMD_FREE:
  23110. + {
  23111. + struct vmcs_sm_ioctl_free ioparam;
  23112. +
  23113. + /* Get parameter data.
  23114. + */
  23115. + if (copy_from_user
  23116. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  23117. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23118. + __func__, cmdnr);
  23119. + ret = -EFAULT;
  23120. + goto out;
  23121. + }
  23122. +
  23123. + ret = vc_sm_ioctl_free(file_data, &ioparam);
  23124. +
  23125. + /* Done.
  23126. + */
  23127. + goto out;
  23128. + }
  23129. + break;
  23130. +
  23131. + /* Walk allocation on videocore, information shows up in the
  23132. + ** videocore log.
  23133. + */
  23134. + case VMCS_SM_CMD_VC_WALK_ALLOC:
  23135. + {
  23136. + pr_debug("[%s]: invoking walk alloc\n", __func__);
  23137. +
  23138. + if (vc_vchi_sm_walk_alloc(sm_state->sm_handle) != 0)
  23139. + pr_err("[%s]: failed to walk-alloc on videocore\n",
  23140. + __func__);
  23141. +
  23142. + /* Done.
  23143. + */
  23144. + goto out;
  23145. + }
  23146. + break;
  23147. +/* Walk mapping table on host, information shows up in the
  23148. + ** kernel log.
  23149. + */
  23150. + case VMCS_SM_CMD_HOST_WALK_MAP:
  23151. + {
  23152. + /* Use pid of -1 to tell to walk the whole map. */
  23153. + vmcs_sm_host_walk_map_per_pid(-1);
  23154. +
  23155. + /* Done. */
  23156. + goto out;
  23157. + }
  23158. + break;
  23159. +
  23160. + /* Walk mapping table per process on host. */
  23161. + case VMCS_SM_CMD_HOST_WALK_PID_ALLOC:
  23162. + {
  23163. + struct vmcs_sm_ioctl_walk ioparam;
  23164. +
  23165. + /* Get parameter data. */
  23166. + if (copy_from_user(&ioparam,
  23167. + (void *)arg, sizeof(ioparam)) != 0) {
  23168. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23169. + __func__, cmdnr);
  23170. + ret = -EFAULT;
  23171. + goto out;
  23172. + }
  23173. +
  23174. + vmcs_sm_host_walk_alloc(file_data);
  23175. +
  23176. + /* Done. */
  23177. + goto out;
  23178. + }
  23179. + break;
  23180. +
  23181. + /* Walk allocation per process on host. */
  23182. + case VMCS_SM_CMD_HOST_WALK_PID_MAP:
  23183. + {
  23184. + struct vmcs_sm_ioctl_walk ioparam;
  23185. +
  23186. + /* Get parameter data. */
  23187. + if (copy_from_user(&ioparam,
  23188. + (void *)arg, sizeof(ioparam)) != 0) {
  23189. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23190. + __func__, cmdnr);
  23191. + ret = -EFAULT;
  23192. + goto out;
  23193. + }
  23194. +
  23195. + vmcs_sm_host_walk_map_per_pid(ioparam.pid);
  23196. +
  23197. + /* Done. */
  23198. + goto out;
  23199. + }
  23200. + break;
  23201. +
  23202. + /* Gets the size of the memory associated with a user handle. */
  23203. + case VMCS_SM_CMD_SIZE_USR_HANDLE:
  23204. + {
  23205. + struct vmcs_sm_ioctl_size ioparam;
  23206. +
  23207. + /* Get parameter data. */
  23208. + if (copy_from_user(&ioparam,
  23209. + (void *)arg, sizeof(ioparam)) != 0) {
  23210. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23211. + __func__, cmdnr);
  23212. + ret = -EFAULT;
  23213. + goto out;
  23214. + }
  23215. +
  23216. + /* Locate resource from GUID. */
  23217. + resource =
  23218. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  23219. + if (resource != NULL) {
  23220. + ioparam.size = resource->res_size;
  23221. + vmcs_sm_release_resource(resource, 0);
  23222. + } else {
  23223. + ioparam.size = 0;
  23224. + }
  23225. +
  23226. + if (copy_to_user((void *)arg,
  23227. + &ioparam, sizeof(ioparam)) != 0) {
  23228. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23229. + __func__, cmdnr);
  23230. + ret = -EFAULT;
  23231. + }
  23232. +
  23233. + /* Done. */
  23234. + goto out;
  23235. + }
  23236. + break;
  23237. +
  23238. + /* Verify we are dealing with a valid resource. */
  23239. + case VMCS_SM_CMD_CHK_USR_HANDLE:
  23240. + {
  23241. + struct vmcs_sm_ioctl_chk ioparam;
  23242. +
  23243. + /* Get parameter data.
  23244. + */
  23245. + if (copy_from_user(&ioparam,
  23246. + (void *)arg, sizeof(ioparam)) != 0) {
  23247. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23248. + __func__, cmdnr);
  23249. +
  23250. + ret = -EFAULT;
  23251. + goto out;
  23252. + }
  23253. +
  23254. + /* Locate resource from GUID. */
  23255. + resource =
  23256. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  23257. + if (resource == NULL)
  23258. + ret = -EINVAL;
  23259. + /* If the resource is cacheable, return additional
  23260. + * information that may be needed to flush the cache.
  23261. + */
  23262. + else if ((resource->res_cached == VMCS_SM_CACHE_HOST) ||
  23263. + (resource->res_cached == VMCS_SM_CACHE_BOTH)) {
  23264. + ioparam.addr =
  23265. + vmcs_sm_usr_address_from_pid_and_usr_handle
  23266. + (current->tgid, ioparam.handle);
  23267. + ioparam.size = resource->res_size;
  23268. + ioparam.cache = resource->res_cached;
  23269. + } else {
  23270. + ioparam.addr = 0;
  23271. + ioparam.size = 0;
  23272. + ioparam.cache = resource->res_cached;
  23273. + }
  23274. +
  23275. + if (resource)
  23276. + vmcs_sm_release_resource(resource, 0);
  23277. +
  23278. + if (copy_to_user((void *)arg,
  23279. + &ioparam, sizeof(ioparam)) != 0) {
  23280. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23281. + __func__, cmdnr);
  23282. + ret = -EFAULT;
  23283. + }
  23284. +
  23285. + /* Done.
  23286. + */
  23287. + goto out;
  23288. + }
  23289. + break;
  23290. +
  23291. + /*
  23292. + * Maps a user handle given the process and the virtual address.
  23293. + */
  23294. + case VMCS_SM_CMD_MAPPED_USR_HANDLE:
  23295. + {
  23296. + struct vmcs_sm_ioctl_map ioparam;
  23297. +
  23298. + /* Get parameter data. */
  23299. + if (copy_from_user(&ioparam,
  23300. + (void *)arg, sizeof(ioparam)) != 0) {
  23301. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23302. + __func__, cmdnr);
  23303. +
  23304. + ret = -EFAULT;
  23305. + goto out;
  23306. + }
  23307. +
  23308. + ioparam.handle =
  23309. + vmcs_sm_usr_handle_from_pid_and_address(
  23310. + ioparam.pid, ioparam.addr);
  23311. +
  23312. + resource =
  23313. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  23314. + if ((resource != NULL)
  23315. + && ((resource->res_cached == VMCS_SM_CACHE_HOST)
  23316. + || (resource->res_cached ==
  23317. + VMCS_SM_CACHE_BOTH))) {
  23318. + ioparam.size = resource->res_size;
  23319. + } else {
  23320. + ioparam.size = 0;
  23321. + }
  23322. +
  23323. + if (resource)
  23324. + vmcs_sm_release_resource(resource, 0);
  23325. +
  23326. + if (copy_to_user((void *)arg,
  23327. + &ioparam, sizeof(ioparam)) != 0) {
  23328. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23329. + __func__, cmdnr);
  23330. + ret = -EFAULT;
  23331. + }
  23332. +
  23333. + /* Done. */
  23334. + goto out;
  23335. + }
  23336. + break;
  23337. +
  23338. + /*
  23339. + * Maps a videocore handle given process and virtual address.
  23340. + */
  23341. + case VMCS_SM_CMD_MAPPED_VC_HDL_FROM_ADDR:
  23342. + {
  23343. + struct vmcs_sm_ioctl_map ioparam;
  23344. +
  23345. + /* Get parameter data. */
  23346. + if (copy_from_user(&ioparam,
  23347. + (void *)arg, sizeof(ioparam)) != 0) {
  23348. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23349. + __func__, cmdnr);
  23350. + ret = -EFAULT;
  23351. + goto out;
  23352. + }
  23353. +
  23354. + ioparam.handle = vmcs_sm_vc_handle_from_pid_and_address(
  23355. + ioparam.pid, ioparam.addr);
  23356. +
  23357. + if (copy_to_user((void *)arg,
  23358. + &ioparam, sizeof(ioparam)) != 0) {
  23359. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23360. + __func__, cmdnr);
  23361. +
  23362. + ret = -EFAULT;
  23363. + }
  23364. +
  23365. + /* Done.
  23366. + */
  23367. + goto out;
  23368. + }
  23369. + break;
  23370. +
  23371. + /* Maps a videocore handle given process and user handle. */
  23372. + case VMCS_SM_CMD_MAPPED_VC_HDL_FROM_HDL:
  23373. + {
  23374. + struct vmcs_sm_ioctl_map ioparam;
  23375. +
  23376. + /* Get parameter data. */
  23377. + if (copy_from_user(&ioparam,
  23378. + (void *)arg, sizeof(ioparam)) != 0) {
  23379. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23380. + __func__, cmdnr);
  23381. + ret = -EFAULT;
  23382. + goto out;
  23383. + }
  23384. +
  23385. + /* Locate resource from GUID. */
  23386. + resource =
  23387. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  23388. + if (resource != NULL) {
  23389. + ioparam.handle = resource->res_handle;
  23390. + vmcs_sm_release_resource(resource, 0);
  23391. + } else {
  23392. + ioparam.handle = 0;
  23393. + }
  23394. +
  23395. + if (copy_to_user((void *)arg,
  23396. + &ioparam, sizeof(ioparam)) != 0) {
  23397. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23398. + __func__, cmdnr);
  23399. +
  23400. + ret = -EFAULT;
  23401. + }
  23402. +
  23403. + /* Done. */
  23404. + goto out;
  23405. + }
  23406. + break;
  23407. +
  23408. + /*
  23409. + * Maps a videocore address given process and videocore handle.
  23410. + */
  23411. + case VMCS_SM_CMD_MAPPED_VC_ADDR_FROM_HDL:
  23412. + {
  23413. + struct vmcs_sm_ioctl_map ioparam;
  23414. +
  23415. + /* Get parameter data. */
  23416. + if (copy_from_user(&ioparam,
  23417. + (void *)arg, sizeof(ioparam)) != 0) {
  23418. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23419. + __func__, cmdnr);
  23420. +
  23421. + ret = -EFAULT;
  23422. + goto out;
  23423. + }
  23424. +
  23425. + /* Locate resource from GUID. */
  23426. + resource =
  23427. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  23428. + if (resource != NULL) {
  23429. + ioparam.addr =
  23430. + (unsigned int)resource->res_base_mem;
  23431. + vmcs_sm_release_resource(resource, 0);
  23432. + } else {
  23433. + ioparam.addr = 0;
  23434. + }
  23435. +
  23436. + if (copy_to_user((void *)arg,
  23437. + &ioparam, sizeof(ioparam)) != 0) {
  23438. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23439. + __func__, cmdnr);
  23440. + ret = -EFAULT;
  23441. + }
  23442. +
  23443. + /* Done. */
  23444. + goto out;
  23445. + }
  23446. + break;
  23447. +
  23448. + /* Maps a user address given process and vc handle.
  23449. + */
  23450. + case VMCS_SM_CMD_MAPPED_USR_ADDRESS:
  23451. + {
  23452. + struct vmcs_sm_ioctl_map ioparam;
  23453. +
  23454. + /* Get parameter data. */
  23455. + if (copy_from_user(&ioparam,
  23456. + (void *)arg, sizeof(ioparam)) != 0) {
  23457. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23458. + __func__, cmdnr);
  23459. + ret = -EFAULT;
  23460. + goto out;
  23461. + }
  23462. +
  23463. + /*
  23464. + * Return the address information from the mapping,
  23465. + * 0 (ie NULL) if it cannot locate the actual mapping.
  23466. + */
  23467. + ioparam.addr =
  23468. + vmcs_sm_usr_address_from_pid_and_usr_handle
  23469. + (ioparam.pid, ioparam.handle);
  23470. +
  23471. + if (copy_to_user((void *)arg,
  23472. + &ioparam, sizeof(ioparam)) != 0) {
  23473. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  23474. + __func__, cmdnr);
  23475. + ret = -EFAULT;
  23476. + }
  23477. +
  23478. + /* Done. */
  23479. + goto out;
  23480. + }
  23481. + break;
  23482. +
  23483. + /* Flush the cache for a given mapping. */
  23484. + case VMCS_SM_CMD_FLUSH:
  23485. + {
  23486. + struct vmcs_sm_ioctl_cache ioparam;
  23487. +
  23488. + /* Get parameter data. */
  23489. + if (copy_from_user(&ioparam,
  23490. + (void *)arg, sizeof(ioparam)) != 0) {
  23491. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23492. + __func__, cmdnr);
  23493. + ret = -EFAULT;
  23494. + goto out;
  23495. + }
  23496. +
  23497. + /* Locate resource from GUID. */
  23498. + resource =
  23499. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  23500. +
  23501. + if ((resource != NULL) && resource->res_cached) {
  23502. + dma_addr_t phys_addr = 0;
  23503. +
  23504. + resource->res_stats[FLUSH]++;
  23505. +
  23506. + phys_addr =
  23507. + (dma_addr_t)((uint32_t)
  23508. + resource->res_base_mem &
  23509. + 0x3FFFFFFF);
  23510. + phys_addr += (dma_addr_t)mm_vc_mem_phys_addr;
  23511. +
  23512. + /* L1 cache flush */
  23513. + down_read(&current->mm->mmap_sem);
  23514. + vcsm_vma_cache_clean_page_range((unsigned long)
  23515. + ioparam.addr,
  23516. + (unsigned long)
  23517. + ioparam.addr +
  23518. + ioparam.size);
  23519. + up_read(&current->mm->mmap_sem);
  23520. +
  23521. + /* L2 cache flush */
  23522. + outer_clean_range(phys_addr,
  23523. + phys_addr +
  23524. + (size_t) ioparam.size);
  23525. + } else if (resource == NULL) {
  23526. + ret = -EINVAL;
  23527. + goto out;
  23528. + }
  23529. +
  23530. + if (resource)
  23531. + vmcs_sm_release_resource(resource, 0);
  23532. +
  23533. + /* Done. */
  23534. + goto out;
  23535. + }
  23536. + break;
  23537. +
  23538. + /* Invalidate the cache for a given mapping. */
  23539. + case VMCS_SM_CMD_INVALID:
  23540. + {
  23541. + struct vmcs_sm_ioctl_cache ioparam;
  23542. +
  23543. + /* Get parameter data. */
  23544. + if (copy_from_user(&ioparam,
  23545. + (void *)arg, sizeof(ioparam)) != 0) {
  23546. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  23547. + __func__, cmdnr);
  23548. + ret = -EFAULT;
  23549. + goto out;
  23550. + }
  23551. +
  23552. + /* Locate resource from GUID.
  23553. + */
  23554. + resource =
  23555. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  23556. +
  23557. + if ((resource != NULL) && resource->res_cached) {
  23558. + dma_addr_t phys_addr = 0;
  23559. +
  23560. + resource->res_stats[INVALID]++;
  23561. +
  23562. + phys_addr =
  23563. + (dma_addr_t)((uint32_t)
  23564. + resource->res_base_mem &
  23565. + 0x3FFFFFFF);
  23566. + phys_addr += (dma_addr_t)mm_vc_mem_phys_addr;
  23567. +
  23568. + /* L2 cache invalidate */
  23569. + outer_inv_range(phys_addr,
  23570. + phys_addr +
  23571. + (size_t) ioparam.size);
  23572. +
  23573. + /* L1 cache invalidate */
  23574. + down_read(&current->mm->mmap_sem);
  23575. + vcsm_vma_cache_clean_page_range((unsigned long)
  23576. + ioparam.addr,
  23577. + (unsigned long)
  23578. + ioparam.addr +
  23579. + ioparam.size);
  23580. + up_read(&current->mm->mmap_sem);
  23581. + } else if (resource == NULL) {
  23582. + ret = -EINVAL;
  23583. + goto out;
  23584. + }
  23585. +
  23586. + if (resource)
  23587. + vmcs_sm_release_resource(resource, 0);
  23588. +
  23589. + /* Done.
  23590. + */
  23591. + goto out;
  23592. + }
  23593. + break;
  23594. +
  23595. + default:
  23596. + {
  23597. + ret = -EINVAL;
  23598. + goto out;
  23599. + }
  23600. + break;
  23601. + }
  23602. +
  23603. +out:
  23604. + return ret;
  23605. +}
  23606. +
  23607. +/* Device operations that we managed in this driver.
  23608. +*/
  23609. +static const struct file_operations vmcs_sm_ops = {
  23610. + .owner = THIS_MODULE,
  23611. + .unlocked_ioctl = vc_sm_ioctl,
  23612. + .open = vc_sm_open,
  23613. + .release = vc_sm_release,
  23614. + .mmap = vc_sm_mmap,
  23615. +};
  23616. +
  23617. +/* Creation of device.
  23618. +*/
  23619. +static int vc_sm_create_sharedmemory(void)
  23620. +{
  23621. + int ret;
  23622. +
  23623. + if (sm_state == NULL) {
  23624. + ret = -ENOMEM;
  23625. + goto out;
  23626. + }
  23627. +
  23628. + /* Create a device class for creating dev nodes.
  23629. + */
  23630. + sm_state->sm_class = class_create(THIS_MODULE, "vc-sm");
  23631. + if (IS_ERR(sm_state->sm_class)) {
  23632. + pr_err("[%s]: unable to create device class\n", __func__);
  23633. + ret = PTR_ERR(sm_state->sm_class);
  23634. + goto out;
  23635. + }
  23636. +
  23637. + /* Create a character driver.
  23638. + */
  23639. + ret = alloc_chrdev_region(&sm_state->sm_devid,
  23640. + DEVICE_MINOR, 1, DEVICE_NAME);
  23641. + if (ret != 0) {
  23642. + pr_err("[%s]: unable to allocate device number\n", __func__);
  23643. + goto out_dev_class_destroy;
  23644. + }
  23645. +
  23646. + cdev_init(&sm_state->sm_cdev, &vmcs_sm_ops);
  23647. + ret = cdev_add(&sm_state->sm_cdev, sm_state->sm_devid, 1);
  23648. + if (ret != 0) {
  23649. + pr_err("[%s]: unable to register device\n", __func__);
  23650. + goto out_chrdev_unreg;
  23651. + }
  23652. +
  23653. + /* Create a device node.
  23654. + */
  23655. + sm_state->sm_dev = device_create(sm_state->sm_class,
  23656. + NULL,
  23657. + MKDEV(MAJOR(sm_state->sm_devid),
  23658. + DEVICE_MINOR), NULL,
  23659. + DEVICE_NAME);
  23660. + if (IS_ERR(sm_state->sm_dev)) {
  23661. + pr_err("[%s]: unable to create device node\n", __func__);
  23662. + ret = PTR_ERR(sm_state->sm_dev);
  23663. + goto out_chrdev_del;
  23664. + }
  23665. +
  23666. + goto out;
  23667. +
  23668. +out_chrdev_del:
  23669. + cdev_del(&sm_state->sm_cdev);
  23670. +out_chrdev_unreg:
  23671. + unregister_chrdev_region(sm_state->sm_devid, 1);
  23672. +out_dev_class_destroy:
  23673. + class_destroy(sm_state->sm_class);
  23674. + sm_state->sm_class = NULL;
  23675. +out:
  23676. + return ret;
  23677. +}
  23678. +
  23679. +/* Termination of the device.
  23680. +*/
  23681. +static int vc_sm_remove_sharedmemory(void)
  23682. +{
  23683. + int ret;
  23684. +
  23685. + if (sm_state == NULL) {
  23686. + /* Nothing to do.
  23687. + */
  23688. + ret = 0;
  23689. + goto out;
  23690. + }
  23691. +
  23692. + /* Remove the sharedmemory character driver.
  23693. + */
  23694. + cdev_del(&sm_state->sm_cdev);
  23695. +
  23696. + /* Unregister region.
  23697. + */
  23698. + unregister_chrdev_region(sm_state->sm_devid, 1);
  23699. +
  23700. + ret = 0;
  23701. + goto out;
  23702. +
  23703. +out:
  23704. + return ret;
  23705. +}
  23706. +
  23707. +/* Videocore connected. */
  23708. +static void vc_sm_connected_init(void)
  23709. +{
  23710. + int ret;
  23711. + VCHI_INSTANCE_T vchi_instance;
  23712. + VCHI_CONNECTION_T *vchi_connection = NULL;
  23713. +
  23714. + pr_info("[%s]: start\n", __func__);
  23715. +
  23716. + /* Allocate memory for the state structure.
  23717. + */
  23718. + sm_state = kzalloc(sizeof(struct SM_STATE_T), GFP_KERNEL);
  23719. + if (sm_state == NULL) {
  23720. + pr_err("[%s]: failed to allocate memory\n", __func__);
  23721. + ret = -ENOMEM;
  23722. + goto out;
  23723. + }
  23724. +
  23725. + mutex_init(&sm_state->lock);
  23726. + mutex_init(&sm_state->map_lock);
  23727. +
  23728. + /* Initialize and create a VCHI connection for the shared memory service
  23729. + ** running on videocore.
  23730. + */
  23731. + ret = vchi_initialise(&vchi_instance);
  23732. + if (ret != 0) {
  23733. + pr_err("[%s]: failed to initialise VCHI instance (ret=%d)\n",
  23734. + __func__, ret);
  23735. +
  23736. + ret = -EIO;
  23737. + goto err_free_mem;
  23738. + }
  23739. +
  23740. + ret = vchi_connect(NULL, 0, vchi_instance);
  23741. + if (ret != 0) {
  23742. + pr_err("[%s]: failed to connect VCHI instance (ret=%d)\n",
  23743. + __func__, ret);
  23744. +
  23745. + ret = -EIO;
  23746. + goto err_free_mem;
  23747. + }
  23748. +
  23749. + /* Initialize an instance of the shared memory service. */
  23750. + sm_state->sm_handle =
  23751. + vc_vchi_sm_init(vchi_instance, &vchi_connection, 1);
  23752. + if (sm_state->sm_handle == NULL) {
  23753. + pr_err("[%s]: failed to initialize shared memory service\n",
  23754. + __func__);
  23755. +
  23756. + ret = -EPERM;
  23757. + goto err_free_mem;
  23758. + }
  23759. +
  23760. + /* Create a debug fs directory entry (root). */
  23761. + sm_state->dir_root = debugfs_create_dir(VC_SM_DIR_ROOT_NAME, NULL);
  23762. + if (!sm_state->dir_root) {
  23763. + pr_err("[%s]: failed to create \'%s\' directory entry\n",
  23764. + __func__, VC_SM_DIR_ROOT_NAME);
  23765. +
  23766. + ret = -EPERM;
  23767. + goto err_stop_sm_service;
  23768. + }
  23769. +
  23770. + sm_state->dir_state.show = &vc_sm_global_state_show;
  23771. + sm_state->dir_state.dir_entry = debugfs_create_file(VC_SM_STATE,
  23772. + S_IRUGO, sm_state->dir_root, &sm_state->dir_state,
  23773. + &vc_sm_debug_fs_fops);
  23774. +
  23775. + sm_state->dir_stats.show = &vc_sm_global_statistics_show;
  23776. + sm_state->dir_stats.dir_entry = debugfs_create_file(VC_SM_STATS,
  23777. + S_IRUGO, sm_state->dir_root, &sm_state->dir_stats,
  23778. + &vc_sm_debug_fs_fops);
  23779. +
  23780. + /* Create the proc entry children. */
  23781. + sm_state->dir_alloc = debugfs_create_dir(VC_SM_DIR_ALLOC_NAME,
  23782. + sm_state->dir_root);
  23783. +
  23784. + /* Create a shared memory device. */
  23785. + ret = vc_sm_create_sharedmemory();
  23786. + if (ret != 0) {
  23787. + pr_err("[%s]: failed to create shared memory device\n",
  23788. + __func__);
  23789. + goto err_remove_debugfs;
  23790. + }
  23791. +
  23792. + INIT_LIST_HEAD(&sm_state->map_list);
  23793. + INIT_LIST_HEAD(&sm_state->resource_list);
  23794. +
  23795. + sm_state->data_knl = vc_sm_create_priv_data(0);
  23796. + if (sm_state->data_knl == NULL) {
  23797. + pr_err("[%s]: failed to create kernel private data tracker\n",
  23798. + __func__);
  23799. + goto err_remove_shared_memory;
  23800. + }
  23801. +
  23802. + /* Done!
  23803. + */
  23804. + sm_inited = 1;
  23805. + goto out;
  23806. +
  23807. +err_remove_shared_memory:
  23808. + vc_sm_remove_sharedmemory();
  23809. +err_remove_debugfs:
  23810. + debugfs_remove_recursive(sm_state->dir_root);
  23811. +err_stop_sm_service:
  23812. + vc_vchi_sm_stop(&sm_state->sm_handle);
  23813. +err_free_mem:
  23814. + kfree(sm_state);
  23815. +out:
  23816. + pr_info("[%s]: end - returning %d\n", __func__, ret);
  23817. +}
  23818. +
  23819. +/* Driver loading. */
  23820. +static int __init vc_sm_init(void)
  23821. +{
  23822. + pr_info("vc-sm: Videocore shared memory driver\n");
  23823. + vchiq_add_connected_callback(vc_sm_connected_init);
  23824. + return 0;
  23825. +}
  23826. +
  23827. +/* Driver unloading. */
  23828. +static void __exit vc_sm_exit(void)
  23829. +{
  23830. + pr_debug("[%s]: start\n", __func__);
  23831. + if (sm_inited) {
  23832. + /* Remove shared memory device.
  23833. + */
  23834. + vc_sm_remove_sharedmemory();
  23835. +
  23836. + /* Remove all proc entries.
  23837. + */
  23838. + debugfs_remove_recursive(sm_state->dir_root);
  23839. +
  23840. + /* Stop the videocore shared memory service.
  23841. + */
  23842. + vc_vchi_sm_stop(&sm_state->sm_handle);
  23843. +
  23844. + /* Free the memory for the state structure.
  23845. + */
  23846. + mutex_destroy(&(sm_state->map_lock));
  23847. + kfree(sm_state);
  23848. + }
  23849. +
  23850. + pr_debug("[%s]: end\n", __func__);
  23851. +}
  23852. +
  23853. +#if defined(__KERNEL__)
  23854. +/* Allocate a shared memory handle and block. */
  23855. +int vc_sm_alloc(VC_SM_ALLOC_T *alloc, int *handle)
  23856. +{
  23857. + struct vmcs_sm_ioctl_alloc ioparam = { 0 };
  23858. + int ret;
  23859. + struct SM_RESOURCE_T *resource;
  23860. +
  23861. + /* Validate we can work with this device.
  23862. + */
  23863. + if (sm_state == NULL || alloc == NULL || handle == NULL) {
  23864. + pr_err("[%s]: invalid input\n", __func__);
  23865. + return -EPERM;
  23866. + }
  23867. +
  23868. + ioparam.size = alloc->base_unit;
  23869. + ioparam.num = alloc->num_unit;
  23870. + ioparam.cached =
  23871. + alloc->type == VC_SM_ALLOC_CACHED ? VMCS_SM_CACHE_VC : 0;
  23872. +
  23873. + ret = vc_sm_ioctl_alloc(sm_state->data_knl, &ioparam);
  23874. +
  23875. + if (ret == 0) {
  23876. + resource =
  23877. + vmcs_sm_acquire_resource(sm_state->data_knl,
  23878. + ioparam.handle);
  23879. + if (resource) {
  23880. + resource->pid = 0;
  23881. + vmcs_sm_release_resource(resource, 0);
  23882. +
  23883. + /* Assign valid handle at this time.
  23884. + */
  23885. + *handle = ioparam.handle;
  23886. + } else {
  23887. + ret = -ENOMEM;
  23888. + }
  23889. + }
  23890. +
  23891. + return ret;
  23892. +}
  23893. +EXPORT_SYMBOL_GPL(vc_sm_alloc);
  23894. +
  23895. +/* Get an internal resource handle mapped from the external one.
  23896. +*/
  23897. +int vc_sm_int_handle(int handle)
  23898. +{
  23899. + struct SM_RESOURCE_T *resource;
  23900. + int ret = 0;
  23901. +
  23902. + /* Validate we can work with this device.
  23903. + */
  23904. + if (sm_state == NULL || handle == 0) {
  23905. + pr_err("[%s]: invalid input\n", __func__);
  23906. + return 0;
  23907. + }
  23908. +
  23909. + /* Locate resource from GUID.
  23910. + */
  23911. + resource = vmcs_sm_acquire_resource(sm_state->data_knl, handle);
  23912. + if (resource) {
  23913. + ret = resource->res_handle;
  23914. + vmcs_sm_release_resource(resource, 0);
  23915. + }
  23916. +
  23917. + return ret;
  23918. +}
  23919. +EXPORT_SYMBOL_GPL(vc_sm_int_handle);
  23920. +
  23921. +/* Free a previously allocated shared memory handle and block.
  23922. +*/
  23923. +int vc_sm_free(int handle)
  23924. +{
  23925. + struct vmcs_sm_ioctl_free ioparam = { handle };
  23926. +
  23927. + /* Validate we can work with this device.
  23928. + */
  23929. + if (sm_state == NULL || handle == 0) {
  23930. + pr_err("[%s]: invalid input\n", __func__);
  23931. + return -EPERM;
  23932. + }
  23933. +
  23934. + return vc_sm_ioctl_free(sm_state->data_knl, &ioparam);
  23935. +}
  23936. +EXPORT_SYMBOL_GPL(vc_sm_free);
  23937. +
  23938. +/* Lock a memory handle for use by kernel.
  23939. +*/
  23940. +int vc_sm_lock(int handle, VC_SM_LOCK_CACHE_MODE_T mode,
  23941. + long unsigned int *data)
  23942. +{
  23943. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  23944. + int ret;
  23945. +
  23946. + /* Validate we can work with this device.
  23947. + */
  23948. + if (sm_state == NULL || handle == 0 || data == NULL) {
  23949. + pr_err("[%s]: invalid input\n", __func__);
  23950. + return -EPERM;
  23951. + }
  23952. +
  23953. + *data = 0;
  23954. +
  23955. + ioparam.handle = handle;
  23956. + ret = vc_sm_ioctl_lock(sm_state->data_knl,
  23957. + &ioparam,
  23958. + 1,
  23959. + ((mode ==
  23960. + VC_SM_LOCK_CACHED) ? VMCS_SM_CACHE_HOST :
  23961. + VMCS_SM_CACHE_NONE), 0);
  23962. +
  23963. + *data = ioparam.addr;
  23964. + return ret;
  23965. +}
  23966. +EXPORT_SYMBOL_GPL(vc_sm_lock);
  23967. +
  23968. +/* Unlock a memory handle in use by kernel.
  23969. +*/
  23970. +int vc_sm_unlock(int handle, int flush, int no_vc_unlock)
  23971. +{
  23972. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  23973. +
  23974. + /* Validate we can work with this device.
  23975. + */
  23976. + if (sm_state == NULL || handle == 0) {
  23977. + pr_err("[%s]: invalid input\n", __func__);
  23978. + return -EPERM;
  23979. + }
  23980. +
  23981. + ioparam.handle = handle;
  23982. + return vc_sm_ioctl_unlock(sm_state->data_knl,
  23983. + &ioparam, flush, 0, no_vc_unlock);
  23984. +}
  23985. +EXPORT_SYMBOL_GPL(vc_sm_unlock);
  23986. +
  23987. +/* Map a shared memory region for use by kernel.
  23988. +*/
  23989. +int vc_sm_map(int handle, unsigned int sm_addr, VC_SM_LOCK_CACHE_MODE_T mode,
  23990. + long unsigned int *data)
  23991. +{
  23992. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  23993. + int ret;
  23994. +
  23995. + /* Validate we can work with this device.
  23996. + */
  23997. + if (sm_state == NULL || handle == 0 || data == NULL || sm_addr == 0) {
  23998. + pr_err("[%s]: invalid input\n", __func__);
  23999. + return -EPERM;
  24000. + }
  24001. +
  24002. + *data = 0;
  24003. +
  24004. + ioparam.handle = handle;
  24005. + ret = vc_sm_ioctl_lock(sm_state->data_knl,
  24006. + &ioparam,
  24007. + 1,
  24008. + ((mode ==
  24009. + VC_SM_LOCK_CACHED) ? VMCS_SM_CACHE_HOST :
  24010. + VMCS_SM_CACHE_NONE), sm_addr);
  24011. +
  24012. + *data = ioparam.addr;
  24013. + return ret;
  24014. +}
  24015. +EXPORT_SYMBOL_GPL(vc_sm_map);
  24016. +#endif
  24017. +
  24018. +late_initcall(vc_sm_init);
  24019. +module_exit(vc_sm_exit);
  24020. +
  24021. +MODULE_AUTHOR("Broadcom");
  24022. +MODULE_DESCRIPTION("VideoCore SharedMemory Driver");
  24023. +MODULE_LICENSE("GPL v2");
  24024. diff -Nur linux-3.18.6/drivers/char/hw_random/bcm2708-rng.c linux-rpi/drivers/char/hw_random/bcm2708-rng.c
  24025. --- linux-3.18.6/drivers/char/hw_random/bcm2708-rng.c 1970-01-01 01:00:00.000000000 +0100
  24026. +++ linux-rpi/drivers/char/hw_random/bcm2708-rng.c 2015-02-09 04:39:53.000000000 +0100
  24027. @@ -0,0 +1,118 @@
  24028. +/**
  24029. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  24030. + *
  24031. + * Redistribution and use in source and binary forms, with or without
  24032. + * modification, are permitted provided that the following conditions
  24033. + * are met:
  24034. + * 1. Redistributions of source code must retain the above copyright
  24035. + * notice, this list of conditions, and the following disclaimer,
  24036. + * without modification.
  24037. + * 2. Redistributions in binary form must reproduce the above copyright
  24038. + * notice, this list of conditions and the following disclaimer in the
  24039. + * documentation and/or other materials provided with the distribution.
  24040. + * 3. The names of the above-listed copyright holders may not be used
  24041. + * to endorse or promote products derived from this software without
  24042. + * specific prior written permission.
  24043. + *
  24044. + * ALTERNATIVELY, this software may be distributed under the terms of the
  24045. + * GNU General Public License ("GPL") version 2, as published by the Free
  24046. + * Software Foundation.
  24047. + *
  24048. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  24049. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  24050. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24051. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24052. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24053. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24054. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24055. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24056. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24057. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24058. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24059. + */
  24060. +
  24061. +#include <linux/kernel.h>
  24062. +#include <linux/module.h>
  24063. +#include <linux/init.h>
  24064. +#include <linux/hw_random.h>
  24065. +#include <linux/printk.h>
  24066. +
  24067. +#include <asm/io.h>
  24068. +#include <mach/hardware.h>
  24069. +#include <mach/platform.h>
  24070. +
  24071. +#define RNG_CTRL (0x0)
  24072. +#define RNG_STATUS (0x4)
  24073. +#define RNG_DATA (0x8)
  24074. +#define RNG_FF_THRESHOLD (0xc)
  24075. +
  24076. +/* enable rng */
  24077. +#define RNG_RBGEN 0x1
  24078. +/* double speed, less random mode */
  24079. +#define RNG_RBG2X 0x2
  24080. +
  24081. +/* the initial numbers generated are "less random" so will be discarded */
  24082. +#define RNG_WARMUP_COUNT 0x40000
  24083. +
  24084. +static int bcm2708_rng_data_read(struct hwrng *rng, u32 *buffer)
  24085. +{
  24086. + void __iomem *rng_base = (void __iomem *)rng->priv;
  24087. + unsigned words;
  24088. + /* wait for a random number to be in fifo */
  24089. + do {
  24090. + words = __raw_readl(rng_base + RNG_STATUS)>>24;
  24091. + }
  24092. + while (words == 0);
  24093. + /* read the random number */
  24094. + *buffer = __raw_readl(rng_base + RNG_DATA);
  24095. + return 4;
  24096. +}
  24097. +
  24098. +static struct hwrng bcm2708_rng_ops = {
  24099. + .name = "bcm2708",
  24100. + .data_read = bcm2708_rng_data_read,
  24101. +};
  24102. +
  24103. +static int __init bcm2708_rng_init(void)
  24104. +{
  24105. + void __iomem *rng_base;
  24106. + int err;
  24107. +
  24108. + /* map peripheral */
  24109. + rng_base = ioremap(RNG_BASE, 0x10);
  24110. + pr_info("bcm2708_rng_init=%p\n", rng_base);
  24111. + if (!rng_base) {
  24112. + pr_err("bcm2708_rng_init failed to ioremap\n");
  24113. + return -ENOMEM;
  24114. + }
  24115. + bcm2708_rng_ops.priv = (unsigned long)rng_base;
  24116. +
  24117. + /* set warm-up count & enable */
  24118. + __raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS);
  24119. + __raw_writel(RNG_RBGEN, rng_base + RNG_CTRL);
  24120. +
  24121. + /* register driver */
  24122. + err = hwrng_register(&bcm2708_rng_ops);
  24123. + if (err) {
  24124. + pr_err("bcm2708_rng_init hwrng_register()=%d\n", err);
  24125. + iounmap(rng_base);
  24126. + }
  24127. + return err;
  24128. +}
  24129. +
  24130. +static void __exit bcm2708_rng_exit(void)
  24131. +{
  24132. + void __iomem *rng_base = (void __iomem *)bcm2708_rng_ops.priv;
  24133. + pr_info("bcm2708_rng_exit\n");
  24134. + /* disable rng hardware */
  24135. + __raw_writel(0, rng_base + RNG_CTRL);
  24136. + /* unregister driver */
  24137. + hwrng_unregister(&bcm2708_rng_ops);
  24138. + iounmap(rng_base);
  24139. +}
  24140. +
  24141. +module_init(bcm2708_rng_init);
  24142. +module_exit(bcm2708_rng_exit);
  24143. +
  24144. +MODULE_DESCRIPTION("BCM2708 H/W Random Number Generator (RNG) driver");
  24145. +MODULE_LICENSE("GPL and additional rights");
  24146. diff -Nur linux-3.18.6/drivers/char/hw_random/Kconfig linux-rpi/drivers/char/hw_random/Kconfig
  24147. --- linux-3.18.6/drivers/char/hw_random/Kconfig 2015-02-06 15:53:48.000000000 +0100
  24148. +++ linux-rpi/drivers/char/hw_random/Kconfig 2015-02-09 04:39:53.000000000 +0100
  24149. @@ -320,6 +320,17 @@
  24150. If unsure, say Y.
  24151. +config HW_RANDOM_BCM2708
  24152. + tristate "BCM2708 generic true random number generator support"
  24153. + depends on HW_RANDOM && (ARCH_BCM2708 || ARCH_BCM2709)
  24154. + ---help---
  24155. + This driver provides the kernel-side support for the BCM2708 hardware.
  24156. +
  24157. + To compile this driver as a module, choose M here: the
  24158. + module will be called bcm2708-rng.
  24159. +
  24160. + If unsure, say N.
  24161. +
  24162. config HW_RANDOM_MSM
  24163. tristate "Qualcomm SoCs Random Number Generator support"
  24164. depends on HW_RANDOM && ARCH_QCOM
  24165. diff -Nur linux-3.18.6/drivers/char/hw_random/Makefile linux-rpi/drivers/char/hw_random/Makefile
  24166. --- linux-3.18.6/drivers/char/hw_random/Makefile 2015-02-06 15:53:48.000000000 +0100
  24167. +++ linux-rpi/drivers/char/hw_random/Makefile 2015-02-09 04:39:53.000000000 +0100
  24168. @@ -28,5 +28,6 @@
  24169. obj-$(CONFIG_HW_RANDOM_EXYNOS) += exynos-rng.o
  24170. obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o
  24171. obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
  24172. +obj-$(CONFIG_HW_RANDOM_BCM2708) += bcm2708-rng.o
  24173. obj-$(CONFIG_HW_RANDOM_MSM) += msm-rng.o
  24174. obj-$(CONFIG_HW_RANDOM_XGENE) += xgene-rng.o
  24175. diff -Nur linux-3.18.6/drivers/char/Kconfig linux-rpi/drivers/char/Kconfig
  24176. --- linux-3.18.6/drivers/char/Kconfig 2015-02-06 15:53:48.000000000 +0100
  24177. +++ linux-rpi/drivers/char/Kconfig 2015-02-09 04:39:53.000000000 +0100
  24178. @@ -581,6 +581,8 @@
  24179. source "drivers/s390/char/Kconfig"
  24180. +source "drivers/char/broadcom/Kconfig"
  24181. +
  24182. config MSM_SMD_PKT
  24183. bool "Enable device interface for some SMD packet ports"
  24184. default n
  24185. diff -Nur linux-3.18.6/drivers/char/Makefile linux-rpi/drivers/char/Makefile
  24186. --- linux-3.18.6/drivers/char/Makefile 2015-02-06 15:53:48.000000000 +0100
  24187. +++ linux-rpi/drivers/char/Makefile 2015-02-09 04:39:53.000000000 +0100
  24188. @@ -62,3 +62,4 @@
  24189. obj-$(CONFIG_TILE_SROM) += tile-srom.o
  24190. obj-$(CONFIG_XILLYBUS) += xillybus/
  24191. +obj-$(CONFIG_BRCM_CHAR_DRIVERS) += broadcom/
  24192. diff -Nur linux-3.18.6/drivers/clocksource/arm_arch_timer.c linux-rpi/drivers/clocksource/arm_arch_timer.c
  24193. --- linux-3.18.6/drivers/clocksource/arm_arch_timer.c 2015-02-06 15:53:48.000000000 +0100
  24194. +++ linux-rpi/drivers/clocksource/arm_arch_timer.c 2015-02-09 04:39:53.000000000 +0100
  24195. @@ -795,3 +795,39 @@
  24196. }
  24197. CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem",
  24198. arch_timer_mem_init);
  24199. +
  24200. +int __init dc4_arch_timer_init(void)
  24201. +{
  24202. + if (arch_timers_present & ARCH_CP15_TIMER) {
  24203. + pr_warn("arch_timer: multiple nodes in dt, skipping\n");
  24204. + return -1;
  24205. + }
  24206. +
  24207. + arch_timers_present |= ARCH_CP15_TIMER;
  24208. +
  24209. + /* Try to determine the frequency from the device tree or CNTFRQ */
  24210. + arch_timer_rate = 19200000;
  24211. +
  24212. + arch_timer_ppi[PHYS_SECURE_PPI] = IRQ_ARM_LOCAL_CNTPSIRQ;
  24213. + arch_timer_ppi[PHYS_NONSECURE_PPI] = IRQ_ARM_LOCAL_CNTPNSIRQ;
  24214. + arch_timer_ppi[VIRT_PPI] = IRQ_ARM_LOCAL_CNTVIRQ;
  24215. + arch_timer_ppi[HYP_PPI] = IRQ_ARM_LOCAL_CNTHPIRQ;
  24216. +
  24217. + /*
  24218. + * If HYP mode is available, we know that the physical timer
  24219. + * has been configured to be accessible from PL1. Use it, so
  24220. + * that a guest can use the virtual timer instead.
  24221. + *
  24222. + * If no interrupt provided for virtual timer, we'll have to
  24223. + * stick to the physical timer. It'd better be accessible...
  24224. + */
  24225. + if (is_hyp_mode_available() || !arch_timer_ppi[VIRT_PPI]) {
  24226. + arch_timer_use_virtual = false;
  24227. + }
  24228. +
  24229. + arch_timer_c3stop = 0;
  24230. +
  24231. + arch_timer_register();
  24232. + arch_timer_common_init();
  24233. + return 0;
  24234. +}
  24235. diff -Nur linux-3.18.6/drivers/cpufreq/bcm2835-cpufreq.c linux-rpi/drivers/cpufreq/bcm2835-cpufreq.c
  24236. --- linux-3.18.6/drivers/cpufreq/bcm2835-cpufreq.c 1970-01-01 01:00:00.000000000 +0100
  24237. +++ linux-rpi/drivers/cpufreq/bcm2835-cpufreq.c 2015-02-09 04:39:53.000000000 +0100
  24238. @@ -0,0 +1,224 @@
  24239. +/*****************************************************************************
  24240. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  24241. +*
  24242. +* Unless you and Broadcom execute a separate written software license
  24243. +* agreement governing use of this software, this software is licensed to you
  24244. +* under the terms of the GNU General Public License version 2, available at
  24245. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  24246. +*
  24247. +* Notwithstanding the above, under no circumstances may you combine this
  24248. +* software in any way with any other Broadcom software provided under a
  24249. +* license other than the GPL, without Broadcom's express prior written
  24250. +* consent.
  24251. +*****************************************************************************/
  24252. +
  24253. +/*****************************************************************************
  24254. +* FILENAME: bcm2835-cpufreq.h
  24255. +* DESCRIPTION: This driver dynamically manages the CPU Frequency of the ARM
  24256. +* processor. Messages are sent to Videocore either setting or requesting the
  24257. +* frequency of the ARM in order to match an appropiate frequency to the current
  24258. +* usage of the processor. The policy which selects the frequency to use is
  24259. +* defined in the kernel .config file, but can be changed during runtime.
  24260. +*****************************************************************************/
  24261. +
  24262. +/* ---------- INCLUDES ---------- */
  24263. +#include <linux/kernel.h>
  24264. +#include <linux/init.h>
  24265. +#include <linux/module.h>
  24266. +#include <linux/cpufreq.h>
  24267. +#include <mach/vcio.h>
  24268. +
  24269. +/* ---------- DEFINES ---------- */
  24270. +/*#define CPUFREQ_DEBUG_ENABLE*/ /* enable debugging */
  24271. +#define MODULE_NAME "bcm2835-cpufreq"
  24272. +
  24273. +#define VCMSG_ID_ARM_CLOCK 0x000000003 /* Clock/Voltage ID's */
  24274. +
  24275. +/* debug printk macros */
  24276. +#ifdef CPUFREQ_DEBUG_ENABLE
  24277. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  24278. +#else
  24279. +#define print_debug(fmt,...)
  24280. +#endif
  24281. +#define print_err(fmt,...) pr_err("%s:%s:%d: "fmt, MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  24282. +#define print_info(fmt,...) pr_info("%s: "fmt, MODULE_NAME, ##__VA_ARGS__)
  24283. +
  24284. +/* tag part of the message */
  24285. +struct vc_msg_tag {
  24286. + uint32_t tag_id; /* the message id */
  24287. + uint32_t buffer_size; /* size of the buffer (which in this case is always 8 bytes) */
  24288. + uint32_t data_size; /* amount of data being sent or received */
  24289. + uint32_t dev_id; /* the ID of the clock/voltage to get or set */
  24290. + uint32_t val; /* the value (e.g. rate (in Hz)) to set */
  24291. +};
  24292. +
  24293. +/* message structure to be sent to videocore */
  24294. +struct vc_msg {
  24295. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  24296. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  24297. + struct vc_msg_tag tag; /* the tag structure above to make */
  24298. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  24299. +};
  24300. +
  24301. +/* ---------- GLOBALS ---------- */
  24302. +static struct cpufreq_driver bcm2835_cpufreq_driver; /* the cpufreq driver global */
  24303. +
  24304. +static struct cpufreq_frequency_table bcm2835_freq_table[] = {
  24305. + {0, 0, 0},
  24306. + {0, 0, 0},
  24307. + {0, 0, CPUFREQ_TABLE_END},
  24308. +};
  24309. +
  24310. +/*
  24311. + ===============================================
  24312. + clk_rate either gets or sets the clock rates.
  24313. + ===============================================
  24314. +*/
  24315. +static uint32_t bcm2835_cpufreq_set_clock(int cur_rate, int arm_rate)
  24316. +{
  24317. + int s, actual_rate=0;
  24318. + struct vc_msg msg;
  24319. +
  24320. + /* wipe all previous message data */
  24321. + memset(&msg, 0, sizeof msg);
  24322. +
  24323. + msg.msg_size = sizeof msg;
  24324. +
  24325. + msg.tag.tag_id = VCMSG_SET_CLOCK_RATE;
  24326. + msg.tag.buffer_size = 8;
  24327. + msg.tag.data_size = 8; /* we're sending the clock ID and the new rates which is a total of 2 words */
  24328. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  24329. + msg.tag.val = arm_rate * 1000;
  24330. +
  24331. + /* send the message */
  24332. + s = bcm_mailbox_property(&msg, sizeof msg);
  24333. +
  24334. + /* check if it was all ok and return the rate in KHz */
  24335. + if (s == 0 && (msg.request_code & 0x80000000))
  24336. + actual_rate = msg.tag.val/1000;
  24337. +
  24338. + print_debug("Setting new frequency = %d -> %d (actual %d)\n", cur_rate, arm_rate, actual_rate);
  24339. + return actual_rate;
  24340. +}
  24341. +
  24342. +static uint32_t bcm2835_cpufreq_get_clock(int tag)
  24343. +{
  24344. + int s;
  24345. + int arm_rate = 0;
  24346. + struct vc_msg msg;
  24347. +
  24348. + /* wipe all previous message data */
  24349. + memset(&msg, 0, sizeof msg);
  24350. +
  24351. + msg.msg_size = sizeof msg;
  24352. + msg.tag.tag_id = tag;
  24353. + msg.tag.buffer_size = 8;
  24354. + msg.tag.data_size = 4; /* we're just sending the clock ID which is one word long */
  24355. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  24356. +
  24357. + /* send the message */
  24358. + s = bcm_mailbox_property(&msg, sizeof msg);
  24359. +
  24360. + /* check if it was all ok and return the rate in KHz */
  24361. + if (s == 0 && (msg.request_code & 0x80000000))
  24362. + arm_rate = msg.tag.val/1000;
  24363. +
  24364. + print_debug("%s frequency = %d\n",
  24365. + tag == VCMSG_GET_CLOCK_RATE ? "Current":
  24366. + tag == VCMSG_GET_MIN_CLOCK ? "Min":
  24367. + tag == VCMSG_GET_MAX_CLOCK ? "Max":
  24368. + "Unexpected", arm_rate);
  24369. +
  24370. + return arm_rate;
  24371. +}
  24372. +
  24373. +/*
  24374. + ====================================================
  24375. + Module Initialisation registers the cpufreq driver
  24376. + ====================================================
  24377. +*/
  24378. +static int __init bcm2835_cpufreq_module_init(void)
  24379. +{
  24380. + print_debug("IN\n");
  24381. + return cpufreq_register_driver(&bcm2835_cpufreq_driver);
  24382. +}
  24383. +
  24384. +/*
  24385. + =============
  24386. + Module exit
  24387. + =============
  24388. +*/
  24389. +static void __exit bcm2835_cpufreq_module_exit(void)
  24390. +{
  24391. + print_debug("IN\n");
  24392. + cpufreq_unregister_driver(&bcm2835_cpufreq_driver);
  24393. + return;
  24394. +}
  24395. +
  24396. +/*
  24397. + ==============================================================
  24398. + Initialisation function sets up the CPU policy for first use
  24399. + ==============================================================
  24400. +*/
  24401. +static int bcm2835_cpufreq_driver_init(struct cpufreq_policy *policy)
  24402. +{
  24403. + /* measured value of how long it takes to change frequency */
  24404. + const unsigned int transition_latency = 355000; /* ns */
  24405. +
  24406. + /* now find out what the maximum and minimum frequencies are */
  24407. + bcm2835_freq_table[0].frequency = bcm2835_cpufreq_get_clock(VCMSG_GET_MIN_CLOCK);
  24408. + bcm2835_freq_table[1].frequency = bcm2835_cpufreq_get_clock(VCMSG_GET_MAX_CLOCK);
  24409. +
  24410. + print_info("min=%d max=%d\n", bcm2835_freq_table[0].frequency, bcm2835_freq_table[1].frequency);
  24411. + return cpufreq_generic_init(policy, bcm2835_freq_table, transition_latency);
  24412. +}
  24413. +
  24414. +/*
  24415. + =====================================================================
  24416. + Target index function chooses the requested frequency from the table
  24417. + =====================================================================
  24418. +*/
  24419. +
  24420. +static int bcm2835_cpufreq_driver_target_index(struct cpufreq_policy *policy, unsigned int state)
  24421. +{
  24422. + unsigned int target_freq = bcm2835_freq_table[state].frequency;
  24423. + unsigned int cur = bcm2835_cpufreq_set_clock(policy->cur, target_freq);
  24424. +
  24425. + if (!cur)
  24426. + {
  24427. + print_err("Error occurred setting a new frequency (%d)\n", target_freq);
  24428. + return -EINVAL;
  24429. + }
  24430. + print_debug("%s: %i: freq %d->%d\n", policy->governor->name, state, policy->cur, cur);
  24431. + return 0;
  24432. +}
  24433. +
  24434. +/*
  24435. + ======================================================
  24436. + Get function returns the current frequency from table
  24437. + ======================================================
  24438. +*/
  24439. +
  24440. +static unsigned int bcm2835_cpufreq_driver_get(unsigned int cpu)
  24441. +{
  24442. + unsigned int actual_rate = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  24443. + print_debug("%d: freq=%d\n", cpu, actual_rate);
  24444. + return actual_rate <= bcm2835_freq_table[0].frequency ? bcm2835_freq_table[0].frequency : bcm2835_freq_table[1].frequency;
  24445. +}
  24446. +
  24447. +/* the CPUFreq driver */
  24448. +static struct cpufreq_driver bcm2835_cpufreq_driver = {
  24449. + .name = "BCM2835 CPUFreq",
  24450. + .init = bcm2835_cpufreq_driver_init,
  24451. + .verify = cpufreq_generic_frequency_table_verify,
  24452. + .target_index = bcm2835_cpufreq_driver_target_index,
  24453. + .get = bcm2835_cpufreq_driver_get,
  24454. + .attr = cpufreq_generic_attr,
  24455. +};
  24456. +
  24457. +MODULE_AUTHOR("Dorian Peake and Dom Cobley");
  24458. +MODULE_DESCRIPTION("CPU frequency driver for BCM2835 chip");
  24459. +MODULE_LICENSE("GPL");
  24460. +
  24461. +module_init(bcm2835_cpufreq_module_init);
  24462. +module_exit(bcm2835_cpufreq_module_exit);
  24463. diff -Nur linux-3.18.6/drivers/cpufreq/Kconfig.arm linux-rpi/drivers/cpufreq/Kconfig.arm
  24464. --- linux-3.18.6/drivers/cpufreq/Kconfig.arm 2015-02-06 15:53:48.000000000 +0100
  24465. +++ linux-rpi/drivers/cpufreq/Kconfig.arm 2015-02-09 04:39:53.000000000 +0100
  24466. @@ -241,6 +241,14 @@
  24467. help
  24468. This adds the CPUFreq driver support for SPEAr SOCs.
  24469. +config ARM_BCM2835_CPUFREQ
  24470. + bool "BCM2835 Driver"
  24471. + default y
  24472. + help
  24473. + This adds the CPUFreq driver for BCM2835
  24474. +
  24475. + If in doubt, say N.
  24476. +
  24477. config ARM_TEGRA_CPUFREQ
  24478. bool "TEGRA CPUFreq support"
  24479. depends on ARCH_TEGRA
  24480. diff -Nur linux-3.18.6/drivers/cpufreq/Makefile linux-rpi/drivers/cpufreq/Makefile
  24481. --- linux-3.18.6/drivers/cpufreq/Makefile 2015-02-06 15:53:48.000000000 +0100
  24482. +++ linux-rpi/drivers/cpufreq/Makefile 2015-02-09 04:39:53.000000000 +0100
  24483. @@ -75,6 +75,7 @@
  24484. obj-$(CONFIG_ARM_SA1100_CPUFREQ) += sa1100-cpufreq.o
  24485. obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o
  24486. obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
  24487. +obj-$(CONFIG_ARM_BCM2835_CPUFREQ) += bcm2835-cpufreq.o
  24488. obj-$(CONFIG_ARM_TEGRA_CPUFREQ) += tegra-cpufreq.o
  24489. obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ) += vexpress-spc-cpufreq.o
  24490. diff -Nur linux-3.18.6/drivers/dma/bcm2708-dmaengine.c linux-rpi/drivers/dma/bcm2708-dmaengine.c
  24491. --- linux-3.18.6/drivers/dma/bcm2708-dmaengine.c 1970-01-01 01:00:00.000000000 +0100
  24492. +++ linux-rpi/drivers/dma/bcm2708-dmaengine.c 2015-02-09 04:39:53.000000000 +0100
  24493. @@ -0,0 +1,1052 @@
  24494. +/*
  24495. + * BCM2835 DMA engine support
  24496. + *
  24497. + * This driver supports cyclic and scatter/gather DMA transfers.
  24498. + *
  24499. + * Author: Florian Meier <florian.meier@koalo.de>
  24500. + * Gellert Weisz <gellert@raspberrypi.org>
  24501. + * Copyright 2013-2014
  24502. + *
  24503. + * Based on
  24504. + * OMAP DMAengine support by Russell King
  24505. + *
  24506. + * BCM2708 DMA Driver
  24507. + * Copyright (C) 2010 Broadcom
  24508. + *
  24509. + * Raspberry Pi PCM I2S ALSA Driver
  24510. + * Copyright (c) by Phil Poole 2013
  24511. + *
  24512. + * MARVELL MMP Peripheral DMA Driver
  24513. + * Copyright 2012 Marvell International Ltd.
  24514. + *
  24515. + * This program is free software; you can redistribute it and/or modify
  24516. + * it under the terms of the GNU General Public License as published by
  24517. + * the Free Software Foundation; either version 2 of the License, or
  24518. + * (at your option) any later version.
  24519. + *
  24520. + * This program is distributed in the hope that it will be useful,
  24521. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24522. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24523. + * GNU General Public License for more details.
  24524. + */
  24525. +
  24526. +#include <linux/dmaengine.h>
  24527. +#include <linux/dma-mapping.h>
  24528. +#include <linux/err.h>
  24529. +#include <linux/init.h>
  24530. +#include <linux/interrupt.h>
  24531. +#include <linux/list.h>
  24532. +#include <linux/module.h>
  24533. +#include <linux/platform_device.h>
  24534. +#include <linux/slab.h>
  24535. +#include <linux/io.h>
  24536. +#include <linux/spinlock.h>
  24537. +
  24538. +#ifndef CONFIG_ARCH_BCM2835
  24539. +
  24540. +/* dma manager */
  24541. +#include <mach/dma.h>
  24542. +
  24543. +//#define DMA_COMPLETE DMA_SUCCESS
  24544. +
  24545. +#endif
  24546. +
  24547. +#include <linux/of.h>
  24548. +#include <linux/of_dma.h>
  24549. +
  24550. +#include "virt-dma.h"
  24551. +
  24552. +
  24553. +struct bcm2835_dmadev {
  24554. + struct dma_device ddev;
  24555. + spinlock_t lock;
  24556. + void __iomem *base;
  24557. + struct device_dma_parameters dma_parms;
  24558. +};
  24559. +
  24560. +struct bcm2835_dma_cb {
  24561. + uint32_t info;
  24562. + uint32_t src;
  24563. + uint32_t dst;
  24564. + uint32_t length;
  24565. + uint32_t stride;
  24566. + uint32_t next;
  24567. + uint32_t pad[2];
  24568. +};
  24569. +
  24570. +struct bcm2835_chan {
  24571. + struct virt_dma_chan vc;
  24572. + struct list_head node;
  24573. +
  24574. + struct dma_slave_config cfg;
  24575. + bool cyclic;
  24576. +
  24577. + int ch;
  24578. + struct bcm2835_desc *desc;
  24579. +
  24580. + void __iomem *chan_base;
  24581. + int irq_number;
  24582. +
  24583. + unsigned int dreq;
  24584. +};
  24585. +
  24586. +struct bcm2835_desc {
  24587. + struct virt_dma_desc vd;
  24588. + enum dma_transfer_direction dir;
  24589. +
  24590. + unsigned int control_block_size;
  24591. + struct bcm2835_dma_cb *control_block_base;
  24592. + dma_addr_t control_block_base_phys;
  24593. +
  24594. + unsigned int frames;
  24595. + size_t size;
  24596. +};
  24597. +
  24598. +#define BCM2835_DMA_CS 0x00
  24599. +#define BCM2835_DMA_ADDR 0x04
  24600. +#define BCM2835_DMA_SOURCE_AD 0x0c
  24601. +#define BCM2835_DMA_DEST_AD 0x10
  24602. +#define BCM2835_DMA_NEXTCB 0x1C
  24603. +
  24604. +/* DMA CS Control and Status bits */
  24605. +#define BCM2835_DMA_ACTIVE BIT(0)
  24606. +#define BCM2835_DMA_INT BIT(2)
  24607. +#define BCM2835_DMA_ISPAUSED BIT(4) /* Pause requested or not active */
  24608. +#define BCM2835_DMA_ISHELD BIT(5) /* Is held by DREQ flow control */
  24609. +#define BCM2835_DMA_ERR BIT(8)
  24610. +#define BCM2835_DMA_ABORT BIT(30) /* Stop current CB, go to next, WO */
  24611. +#define BCM2835_DMA_RESET BIT(31) /* WO, self clearing */
  24612. +
  24613. +#define BCM2835_DMA_INT_EN BIT(0)
  24614. +#define BCM2835_DMA_WAIT_RESP BIT(3)
  24615. +#define BCM2835_DMA_D_INC BIT(4)
  24616. +#define BCM2835_DMA_D_WIDTH BIT(5)
  24617. +#define BCM2835_DMA_D_DREQ BIT(6)
  24618. +#define BCM2835_DMA_S_INC BIT(8)
  24619. +#define BCM2835_DMA_S_WIDTH BIT(9)
  24620. +#define BCM2835_DMA_S_DREQ BIT(10)
  24621. +
  24622. +#define BCM2835_DMA_PER_MAP(x) ((x) << 16)
  24623. +#define BCM2835_DMA_WAITS(x) (((x)&0x1f) << 21)
  24624. +
  24625. +#define SDHCI_BCM_DMA_WAITS 0 /* delays slowing DMA transfers: 0-31 */
  24626. +
  24627. +#define BCM2835_DMA_DATA_TYPE_S8 1
  24628. +#define BCM2835_DMA_DATA_TYPE_S16 2
  24629. +#define BCM2835_DMA_DATA_TYPE_S32 4
  24630. +#define BCM2835_DMA_DATA_TYPE_S128 16
  24631. +
  24632. +#define BCM2835_DMA_BULK_MASK BIT(0)
  24633. +#define BCM2835_DMA_FIQ_MASK (BIT(2) | BIT(3))
  24634. +
  24635. +
  24636. +/* Valid only for channels 0 - 14, 15 has its own base address */
  24637. +#define BCM2835_DMA_CHAN(n) ((n) << 8) /* Base address */
  24638. +#define BCM2835_DMA_CHANIO(base, n) ((base) + BCM2835_DMA_CHAN(n))
  24639. +
  24640. +#define MAX_LITE_TRANSFER 32768
  24641. +#define MAX_NORMAL_TRANSFER 1073741824
  24642. +
  24643. +static inline struct bcm2835_dmadev *to_bcm2835_dma_dev(struct dma_device *d)
  24644. +{
  24645. + return container_of(d, struct bcm2835_dmadev, ddev);
  24646. +}
  24647. +
  24648. +static inline struct bcm2835_chan *to_bcm2835_dma_chan(struct dma_chan *c)
  24649. +{
  24650. + return container_of(c, struct bcm2835_chan, vc.chan);
  24651. +}
  24652. +
  24653. +static inline struct bcm2835_desc *to_bcm2835_dma_desc(
  24654. + struct dma_async_tx_descriptor *t)
  24655. +{
  24656. + return container_of(t, struct bcm2835_desc, vd.tx);
  24657. +}
  24658. +
  24659. +static void dma_dumpregs(struct bcm2835_chan *c)
  24660. +{
  24661. + pr_debug("-------------DMA DUMPREGS-------------\n");
  24662. + pr_debug("CS= %u\n",
  24663. + readl(c->chan_base + BCM2835_DMA_CS));
  24664. + pr_debug("ADDR= %u\n",
  24665. + readl(c->chan_base + BCM2835_DMA_ADDR));
  24666. + pr_debug("SOURCE_ADDR= %u\n",
  24667. + readl(c->chan_base + BCM2835_DMA_SOURCE_AD));
  24668. + pr_debug("DEST_AD= %u\n",
  24669. + readl(c->chan_base + BCM2835_DMA_DEST_AD));
  24670. + pr_debug("NEXTCB= %u\n",
  24671. + readl(c->chan_base + BCM2835_DMA_NEXTCB));
  24672. + pr_debug("--------------------------------------\n");
  24673. +}
  24674. +
  24675. +static void bcm2835_dma_desc_free(struct virt_dma_desc *vd)
  24676. +{
  24677. + struct bcm2835_desc *desc = container_of(vd, struct bcm2835_desc, vd);
  24678. + dma_free_coherent(desc->vd.tx.chan->device->dev,
  24679. + desc->control_block_size,
  24680. + desc->control_block_base,
  24681. + desc->control_block_base_phys);
  24682. + kfree(desc);
  24683. +}
  24684. +
  24685. +static int bcm2835_dma_abort(void __iomem *chan_base)
  24686. +{
  24687. + unsigned long cs;
  24688. + long int timeout = 10000;
  24689. +
  24690. + cs = readl(chan_base + BCM2835_DMA_CS);
  24691. + if (!(cs & BCM2835_DMA_ACTIVE))
  24692. + return 0;
  24693. +
  24694. + /* Write 0 to the active bit - Pause the DMA */
  24695. + writel(0, chan_base + BCM2835_DMA_CS);
  24696. +
  24697. + /* Wait for any current AXI transfer to complete */
  24698. + while ((cs & BCM2835_DMA_ISPAUSED) && --timeout) {
  24699. + cpu_relax();
  24700. + cs = readl(chan_base + BCM2835_DMA_CS);
  24701. + }
  24702. +
  24703. + /* We'll un-pause when we set of our next DMA */
  24704. + if (!timeout)
  24705. + return -ETIMEDOUT;
  24706. +
  24707. + if (!(cs & BCM2835_DMA_ACTIVE))
  24708. + return 0;
  24709. +
  24710. + /* Terminate the control block chain */
  24711. + writel(0, chan_base + BCM2835_DMA_NEXTCB);
  24712. +
  24713. + /* Abort the whole DMA */
  24714. + writel(BCM2835_DMA_ABORT | BCM2835_DMA_ACTIVE,
  24715. + chan_base + BCM2835_DMA_CS);
  24716. +
  24717. + return 0;
  24718. +}
  24719. +
  24720. +
  24721. +static void bcm2835_dma_start_desc(struct bcm2835_chan *c)
  24722. +{
  24723. + struct virt_dma_desc *vd = vchan_next_desc(&c->vc);
  24724. + struct bcm2835_desc *d;
  24725. +
  24726. + if (!vd) {
  24727. + c->desc = NULL;
  24728. + return;
  24729. + }
  24730. +
  24731. + list_del(&vd->node);
  24732. +
  24733. + c->desc = d = to_bcm2835_dma_desc(&vd->tx);
  24734. +
  24735. + writel(d->control_block_base_phys, c->chan_base + BCM2835_DMA_ADDR);
  24736. + writel(BCM2835_DMA_ACTIVE, c->chan_base + BCM2835_DMA_CS);
  24737. +
  24738. +}
  24739. +
  24740. +static irqreturn_t bcm2835_dma_callback(int irq, void *data)
  24741. +{
  24742. + struct bcm2835_chan *c = data;
  24743. + struct bcm2835_desc *d;
  24744. + unsigned long flags;
  24745. +
  24746. + spin_lock_irqsave(&c->vc.lock, flags);
  24747. +
  24748. + /* Acknowledge interrupt */
  24749. + writel(BCM2835_DMA_INT, c->chan_base + BCM2835_DMA_CS);
  24750. +
  24751. + d = c->desc;
  24752. +
  24753. + if (d) {
  24754. + if (c->cyclic) {
  24755. + vchan_cyclic_callback(&d->vd);
  24756. +
  24757. + /* Keep the DMA engine running */
  24758. + writel(BCM2835_DMA_ACTIVE,
  24759. + c->chan_base + BCM2835_DMA_CS);
  24760. +
  24761. + } else {
  24762. + vchan_cookie_complete(&c->desc->vd);
  24763. + bcm2835_dma_start_desc(c);
  24764. + }
  24765. + }
  24766. +
  24767. + spin_unlock_irqrestore(&c->vc.lock, flags);
  24768. +
  24769. + return IRQ_HANDLED;
  24770. +}
  24771. +
  24772. +static int bcm2835_dma_alloc_chan_resources(struct dma_chan *chan)
  24773. +{
  24774. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  24775. + int ret;
  24776. +
  24777. + dev_dbg(c->vc.chan.device->dev,
  24778. + "Allocating DMA channel %d\n", c->ch);
  24779. +
  24780. + ret = request_irq(c->irq_number,
  24781. + bcm2835_dma_callback, 0, "DMA IRQ", c);
  24782. +
  24783. + return ret;
  24784. +}
  24785. +
  24786. +static void bcm2835_dma_free_chan_resources(struct dma_chan *chan)
  24787. +{
  24788. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  24789. +
  24790. + vchan_free_chan_resources(&c->vc);
  24791. + free_irq(c->irq_number, c);
  24792. +
  24793. + dev_dbg(c->vc.chan.device->dev, "Freeing DMA channel %u\n", c->ch);
  24794. +}
  24795. +
  24796. +static size_t bcm2835_dma_desc_size(struct bcm2835_desc *d)
  24797. +{
  24798. + return d->size;
  24799. +}
  24800. +
  24801. +static size_t bcm2835_dma_desc_size_pos(struct bcm2835_desc *d, dma_addr_t addr)
  24802. +{
  24803. + unsigned int i;
  24804. + size_t size;
  24805. +
  24806. + for (size = i = 0; i < d->frames; i++) {
  24807. + struct bcm2835_dma_cb *control_block =
  24808. + &d->control_block_base[i];
  24809. + size_t this_size = control_block->length;
  24810. + dma_addr_t dma;
  24811. +
  24812. + if (d->dir == DMA_DEV_TO_MEM)
  24813. + dma = control_block->dst;
  24814. + else
  24815. + dma = control_block->src;
  24816. +
  24817. + if (size)
  24818. + size += this_size;
  24819. + else if (addr >= dma && addr < dma + this_size)
  24820. + size += dma + this_size - addr;
  24821. + }
  24822. +
  24823. + return size;
  24824. +}
  24825. +
  24826. +static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan,
  24827. + dma_cookie_t cookie, struct dma_tx_state *txstate)
  24828. +{
  24829. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  24830. + struct bcm2835_desc *d;
  24831. + struct virt_dma_desc *vd;
  24832. + enum dma_status ret;
  24833. + unsigned long flags;
  24834. + dma_addr_t pos;
  24835. +
  24836. + ret = dma_cookie_status(chan, cookie, txstate);
  24837. + if (ret == DMA_COMPLETE || !txstate)
  24838. + return ret;
  24839. +
  24840. + spin_lock_irqsave(&c->vc.lock, flags);
  24841. + vd = vchan_find_desc(&c->vc, cookie);
  24842. + if (vd) {
  24843. + txstate->residue =
  24844. + bcm2835_dma_desc_size(to_bcm2835_dma_desc(&vd->tx));
  24845. + } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
  24846. + d = c->desc;
  24847. +
  24848. + if (d->dir == DMA_MEM_TO_DEV)
  24849. + pos = readl(c->chan_base + BCM2835_DMA_SOURCE_AD);
  24850. + else if (d->dir == DMA_DEV_TO_MEM)
  24851. + pos = readl(c->chan_base + BCM2835_DMA_DEST_AD);
  24852. + else
  24853. + pos = 0;
  24854. +
  24855. + txstate->residue = bcm2835_dma_desc_size_pos(d, pos);
  24856. + } else {
  24857. + txstate->residue = 0;
  24858. + }
  24859. +
  24860. + spin_unlock_irqrestore(&c->vc.lock, flags);
  24861. +
  24862. + return ret;
  24863. +}
  24864. +
  24865. +static void bcm2835_dma_issue_pending(struct dma_chan *chan)
  24866. +{
  24867. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  24868. + unsigned long flags;
  24869. +
  24870. + spin_lock_irqsave(&c->vc.lock, flags);
  24871. + if (vchan_issue_pending(&c->vc) && !c->desc)
  24872. + bcm2835_dma_start_desc(c);
  24873. +
  24874. + spin_unlock_irqrestore(&c->vc.lock, flags);
  24875. +}
  24876. +
  24877. +static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic(
  24878. + struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  24879. + size_t period_len, enum dma_transfer_direction direction,
  24880. + unsigned long flags)
  24881. +{
  24882. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  24883. + enum dma_slave_buswidth dev_width;
  24884. + struct bcm2835_desc *d;
  24885. + dma_addr_t dev_addr;
  24886. + unsigned int es, sync_type;
  24887. + unsigned int frame, max_size;
  24888. +
  24889. + /* Grab configuration */
  24890. + if (!is_slave_direction(direction)) {
  24891. + dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  24892. + return NULL;
  24893. + }
  24894. +
  24895. + if (direction == DMA_DEV_TO_MEM) {
  24896. + dev_addr = c->cfg.src_addr;
  24897. + dev_width = c->cfg.src_addr_width;
  24898. + sync_type = BCM2835_DMA_S_DREQ;
  24899. + } else {
  24900. + dev_addr = c->cfg.dst_addr;
  24901. + dev_width = c->cfg.dst_addr_width;
  24902. + sync_type = BCM2835_DMA_D_DREQ;
  24903. + }
  24904. +
  24905. + /* Bus width translates to the element size (ES) */
  24906. + switch (dev_width) {
  24907. + case DMA_SLAVE_BUSWIDTH_4_BYTES:
  24908. + es = BCM2835_DMA_DATA_TYPE_S32;
  24909. + break;
  24910. + default:
  24911. + return NULL;
  24912. + }
  24913. +
  24914. + /* Now allocate and setup the descriptor. */
  24915. + d = kzalloc(sizeof(*d), GFP_NOWAIT);
  24916. + if (!d)
  24917. + return NULL;
  24918. +
  24919. + d->dir = direction;
  24920. +
  24921. + if (c->ch >= 8) /* we have a LITE channel */
  24922. + max_size = MAX_LITE_TRANSFER;
  24923. + else
  24924. + max_size = MAX_NORMAL_TRANSFER;
  24925. + period_len = min(period_len, max_size);
  24926. +
  24927. + d->frames = (buf_len-1) / period_len + 1;
  24928. +
  24929. + /* Allocate memory for control blocks */
  24930. + d->control_block_size = d->frames * sizeof(struct bcm2835_dma_cb);
  24931. + d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  24932. + d->control_block_size, &d->control_block_base_phys,
  24933. + GFP_NOWAIT);
  24934. +
  24935. + if (!d->control_block_base) {
  24936. + kfree(d);
  24937. + return NULL;
  24938. + }
  24939. +
  24940. + /*
  24941. + * Iterate over all frames, create a control block
  24942. + * for each frame and link them together.
  24943. + */
  24944. + for (frame = 0; frame < d->frames; frame++) {
  24945. + struct bcm2835_dma_cb *control_block =
  24946. + &d->control_block_base[frame];
  24947. +
  24948. + /* Setup adresses */
  24949. + if (d->dir == DMA_DEV_TO_MEM) {
  24950. + control_block->info = BCM2835_DMA_D_INC;
  24951. + control_block->src = dev_addr;
  24952. + control_block->dst = buf_addr + frame * period_len;
  24953. + } else {
  24954. + control_block->info = BCM2835_DMA_S_INC;
  24955. + control_block->src = buf_addr + frame * period_len;
  24956. + control_block->dst = dev_addr;
  24957. + }
  24958. +
  24959. + /* Enable interrupt */
  24960. + control_block->info |= BCM2835_DMA_INT_EN;
  24961. +
  24962. + /* Setup synchronization */
  24963. + if (sync_type != 0)
  24964. + control_block->info |= sync_type;
  24965. +
  24966. + /* Setup DREQ channel */
  24967. + if (c->cfg.slave_id != 0)
  24968. + control_block->info |=
  24969. + BCM2835_DMA_PER_MAP(c->cfg.slave_id);
  24970. +
  24971. + /* Length of a frame */
  24972. + if (frame != d->frames-1)
  24973. + control_block->length = period_len;
  24974. + else
  24975. + control_block->length = buf_len - (d->frames - 1) * period_len;
  24976. +
  24977. + d->size += control_block->length;
  24978. +
  24979. + /*
  24980. + * Next block is the next frame.
  24981. + * This function is called on cyclic DMA transfers.
  24982. + * Therefore, wrap around at number of frames.
  24983. + */
  24984. + control_block->next = d->control_block_base_phys +
  24985. + sizeof(struct bcm2835_dma_cb)
  24986. + * ((frame + 1) % d->frames);
  24987. + }
  24988. +
  24989. + c->cyclic = true;
  24990. +
  24991. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  24992. +}
  24993. +
  24994. +
  24995. +static struct dma_async_tx_descriptor *bcm2835_dma_prep_slave_sg(
  24996. + struct dma_chan *chan, struct scatterlist *sgl,
  24997. + unsigned int sg_len, enum dma_transfer_direction direction,
  24998. + unsigned long flags, void *context)
  24999. +{
  25000. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  25001. + enum dma_slave_buswidth dev_width;
  25002. + struct bcm2835_desc *d;
  25003. + dma_addr_t dev_addr;
  25004. + struct scatterlist *sgent;
  25005. + unsigned int es, sync_type;
  25006. + unsigned int i, j, splitct, max_size;
  25007. +
  25008. + if (!is_slave_direction(direction)) {
  25009. + dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  25010. + return NULL;
  25011. + }
  25012. +
  25013. + if (direction == DMA_DEV_TO_MEM) {
  25014. + dev_addr = c->cfg.src_addr;
  25015. + dev_width = c->cfg.src_addr_width;
  25016. + sync_type = BCM2835_DMA_S_DREQ;
  25017. + } else {
  25018. + dev_addr = c->cfg.dst_addr;
  25019. + dev_width = c->cfg.dst_addr_width;
  25020. + sync_type = BCM2835_DMA_D_DREQ;
  25021. + }
  25022. +
  25023. + /* Bus width translates to the element size (ES) */
  25024. + switch (dev_width) {
  25025. + case DMA_SLAVE_BUSWIDTH_4_BYTES:
  25026. + es = BCM2835_DMA_DATA_TYPE_S32;
  25027. + break;
  25028. + default:
  25029. + return NULL;
  25030. + }
  25031. +
  25032. + /* Now allocate and setup the descriptor. */
  25033. + d = kzalloc(sizeof(*d), GFP_NOWAIT);
  25034. + if (!d)
  25035. + return NULL;
  25036. +
  25037. + d->dir = direction;
  25038. +
  25039. + if (c->ch >= 8) /* we have a LITE channel */
  25040. + max_size = MAX_LITE_TRANSFER;
  25041. + else
  25042. + max_size = MAX_NORMAL_TRANSFER;
  25043. +
  25044. + /* We store the length of the SG list in d->frames
  25045. + taking care to account for splitting up transfers
  25046. + too large for a LITE channel */
  25047. +
  25048. + d->frames = 0;
  25049. + for_each_sg(sgl, sgent, sg_len, i) {
  25050. + uint32_t len = sg_dma_len(sgent);
  25051. + d->frames += 1 + len / max_size;
  25052. + }
  25053. +
  25054. + /* Allocate memory for control blocks */
  25055. + d->control_block_size = d->frames * sizeof(struct bcm2835_dma_cb);
  25056. + d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  25057. + d->control_block_size, &d->control_block_base_phys,
  25058. + GFP_NOWAIT);
  25059. +
  25060. + if (!d->control_block_base) {
  25061. + kfree(d);
  25062. + return NULL;
  25063. + }
  25064. +
  25065. + /*
  25066. + * Iterate over all SG entries, create a control block
  25067. + * for each frame and link them together.
  25068. + */
  25069. +
  25070. + /* we count the number of times an SG entry had to be splitct
  25071. + as a result of using a LITE channel */
  25072. + splitct = 0;
  25073. +
  25074. + for_each_sg(sgl, sgent, sg_len, i) {
  25075. + dma_addr_t addr = sg_dma_address(sgent);
  25076. + uint32_t len = sg_dma_len(sgent);
  25077. +
  25078. + for (j = 0; j < len; j += max_size) {
  25079. + struct bcm2835_dma_cb *control_block =
  25080. + &d->control_block_base[i+splitct];
  25081. +
  25082. + /* Setup adresses */
  25083. + if (d->dir == DMA_DEV_TO_MEM) {
  25084. + control_block->info = BCM2835_DMA_D_INC |
  25085. + BCM2835_DMA_D_WIDTH | BCM2835_DMA_S_DREQ;
  25086. + control_block->src = dev_addr;
  25087. + control_block->dst = addr + (dma_addr_t)j;
  25088. + } else {
  25089. + control_block->info = BCM2835_DMA_S_INC |
  25090. + BCM2835_DMA_S_WIDTH | BCM2835_DMA_D_DREQ;
  25091. + control_block->src = addr + (dma_addr_t)j;
  25092. + control_block->dst = dev_addr;
  25093. + }
  25094. +
  25095. + /* Common part */
  25096. + control_block->info |= BCM2835_DMA_WAITS(SDHCI_BCM_DMA_WAITS);
  25097. + control_block->info |= BCM2835_DMA_WAIT_RESP;
  25098. +
  25099. + /* Enable */
  25100. + if (i == sg_len-1 && len-j <= max_size)
  25101. + control_block->info |= BCM2835_DMA_INT_EN;
  25102. +
  25103. + /* Setup synchronization */
  25104. + if (sync_type != 0)
  25105. + control_block->info |= sync_type;
  25106. +
  25107. + /* Setup DREQ channel */
  25108. + c->dreq = c->cfg.slave_id; /* DREQ loaded from config */
  25109. +
  25110. + if (c->dreq != 0)
  25111. + control_block->info |=
  25112. + BCM2835_DMA_PER_MAP(c->dreq);
  25113. +
  25114. + /* Length of a frame */
  25115. + control_block->length = min(len-j, max_size);
  25116. + d->size += control_block->length;
  25117. +
  25118. + /*
  25119. + * Next block is the next frame.
  25120. + */
  25121. + if (i < sg_len-1 || len-j > max_size) {
  25122. + /* next block is the next frame. */
  25123. + control_block->next = d->control_block_base_phys +
  25124. + sizeof(struct bcm2835_dma_cb) * (i + splitct + 1);
  25125. + } else {
  25126. + /* next block is empty. */
  25127. + control_block->next = 0;
  25128. + }
  25129. +
  25130. + if (len-j > max_size)
  25131. + splitct++;
  25132. + }
  25133. + }
  25134. +
  25135. + c->cyclic = false;
  25136. +
  25137. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  25138. +}
  25139. +
  25140. +static int bcm2835_dma_slave_config(struct bcm2835_chan *c,
  25141. + struct dma_slave_config *cfg)
  25142. +{
  25143. + if ((cfg->direction == DMA_DEV_TO_MEM &&
  25144. + cfg->src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  25145. + (cfg->direction == DMA_MEM_TO_DEV &&
  25146. + cfg->dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  25147. + !is_slave_direction(cfg->direction)) {
  25148. + return -EINVAL;
  25149. + }
  25150. +
  25151. + c->cfg = *cfg;
  25152. +
  25153. + return 0;
  25154. +}
  25155. +
  25156. +static int bcm2835_dma_terminate_all(struct bcm2835_chan *c)
  25157. +{
  25158. + struct bcm2835_dmadev *d = to_bcm2835_dma_dev(c->vc.chan.device);
  25159. + unsigned long flags;
  25160. + int timeout = 10000;
  25161. + LIST_HEAD(head);
  25162. +
  25163. + spin_lock_irqsave(&c->vc.lock, flags);
  25164. +
  25165. + /* Prevent this channel being scheduled */
  25166. + spin_lock(&d->lock);
  25167. + list_del_init(&c->node);
  25168. + spin_unlock(&d->lock);
  25169. +
  25170. + /*
  25171. + * Stop DMA activity: we assume the callback will not be called
  25172. + * after bcm_dma_abort() returns (even if it does, it will see
  25173. + * c->desc is NULL and exit.)
  25174. + */
  25175. + if (c->desc) {
  25176. + c->desc = NULL;
  25177. + bcm2835_dma_abort(c->chan_base);
  25178. +
  25179. + /* Wait for stopping */
  25180. + while (--timeout) {
  25181. + if (!(readl(c->chan_base + BCM2835_DMA_CS) &
  25182. + BCM2835_DMA_ACTIVE))
  25183. + break;
  25184. +
  25185. + cpu_relax();
  25186. + }
  25187. +
  25188. + if (!timeout)
  25189. + dev_err(d->ddev.dev, "DMA transfer could not be terminated\n");
  25190. + }
  25191. +
  25192. + vchan_get_all_descriptors(&c->vc, &head);
  25193. + spin_unlock_irqrestore(&c->vc.lock, flags);
  25194. + vchan_dma_desc_free_list(&c->vc, &head);
  25195. +
  25196. + return 0;
  25197. +}
  25198. +
  25199. +static int bcm2835_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  25200. + unsigned long arg)
  25201. +{
  25202. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  25203. +
  25204. + switch (cmd) {
  25205. + case DMA_SLAVE_CONFIG:
  25206. + return bcm2835_dma_slave_config(c,
  25207. + (struct dma_slave_config *)arg);
  25208. +
  25209. + case DMA_TERMINATE_ALL:
  25210. + return bcm2835_dma_terminate_all(c);
  25211. +
  25212. + default:
  25213. + return -ENXIO;
  25214. + }
  25215. +}
  25216. +
  25217. +#ifdef CONFIG_ARCH_BCM2835
  25218. +static int bcm2835_dma_chan_init(struct bcm2835_dmadev *d, int chan_id, int irq)
  25219. +{
  25220. + struct bcm2835_chan *c;
  25221. +
  25222. + c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL);
  25223. + if (!c)
  25224. + return -ENOMEM;
  25225. +
  25226. + c->vc.desc_free = bcm2835_dma_desc_free;
  25227. + vchan_init(&c->vc, &d->ddev);
  25228. + INIT_LIST_HEAD(&c->node);
  25229. +
  25230. + d->ddev.chancnt++;
  25231. +
  25232. + c->chan_base = BCM2835_DMA_CHANIO(d->base, chan_id);
  25233. + c->ch = chan_id;
  25234. + c->irq_number = irq;
  25235. +
  25236. + return 0;
  25237. +}
  25238. +#endif
  25239. +
  25240. +static int bcm2708_dma_chan_init(struct bcm2835_dmadev *d,
  25241. + void __iomem *chan_base, int chan_id, int irq)
  25242. +{
  25243. + struct bcm2835_chan *c;
  25244. +
  25245. + c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL);
  25246. + if (!c)
  25247. + return -ENOMEM;
  25248. +
  25249. + c->vc.desc_free = bcm2835_dma_desc_free;
  25250. + vchan_init(&c->vc, &d->ddev);
  25251. + INIT_LIST_HEAD(&c->node);
  25252. +
  25253. + d->ddev.chancnt++;
  25254. +
  25255. + c->chan_base = chan_base;
  25256. + c->ch = chan_id;
  25257. + c->irq_number = irq;
  25258. +
  25259. + return 0;
  25260. +}
  25261. +
  25262. +
  25263. +static void bcm2835_dma_free(struct bcm2835_dmadev *od)
  25264. +{
  25265. + struct bcm2835_chan *c, *next;
  25266. +
  25267. + list_for_each_entry_safe(c, next, &od->ddev.channels,
  25268. + vc.chan.device_node) {
  25269. + list_del(&c->vc.chan.device_node);
  25270. + tasklet_kill(&c->vc.task);
  25271. + }
  25272. +}
  25273. +
  25274. +static const struct of_device_id bcm2835_dma_of_match[] = {
  25275. + { .compatible = "brcm,bcm2835-dma", },
  25276. + {},
  25277. +};
  25278. +MODULE_DEVICE_TABLE(of, bcm2835_dma_of_match);
  25279. +
  25280. +#ifdef CONFIG_ARCH_BCM2835
  25281. +static struct dma_chan *bcm2835_dma_xlate(struct of_phandle_args *spec,
  25282. + struct of_dma *ofdma)
  25283. +{
  25284. + struct bcm2835_dmadev *d = ofdma->of_dma_data;
  25285. + struct dma_chan *chan;
  25286. +
  25287. + chan = dma_get_any_slave_channel(&d->ddev);
  25288. + if (!chan)
  25289. + return NULL;
  25290. +
  25291. + /* Set DREQ from param */
  25292. + to_bcm2835_dma_chan(chan)->dreq = spec->args[0];
  25293. +
  25294. + return chan;
  25295. +}
  25296. +#endif
  25297. +
  25298. +static int bcm2835_dma_device_slave_caps(struct dma_chan *dchan,
  25299. + struct dma_slave_caps *caps)
  25300. +{
  25301. + caps->src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
  25302. + caps->dstn_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
  25303. + caps->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
  25304. + caps->cmd_pause = false;
  25305. + caps->cmd_terminate = true;
  25306. +
  25307. + return 0;
  25308. +}
  25309. +
  25310. +static int bcm2835_dma_probe(struct platform_device *pdev)
  25311. +{
  25312. + struct bcm2835_dmadev *od;
  25313. +#ifdef CONFIG_ARCH_BCM2835
  25314. + struct resource *res;
  25315. + void __iomem *base;
  25316. + uint32_t chans_available;
  25317. +#endif
  25318. + int rc;
  25319. + int i;
  25320. + int irq;
  25321. +
  25322. +
  25323. + if (!pdev->dev.dma_mask)
  25324. + pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  25325. +
  25326. + /* If CONFIG_ARCH_BCM2835 is selected, device tree is used */
  25327. + /* hence the difference between probing */
  25328. +
  25329. +#ifndef CONFIG_ARCH_BCM2835
  25330. +
  25331. + rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  25332. + if (rc)
  25333. + return rc;
  25334. + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  25335. +
  25336. +
  25337. + od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  25338. + if (!od)
  25339. + return -ENOMEM;
  25340. +
  25341. + pdev->dev.dma_parms = &od->dma_parms;
  25342. + dma_set_max_seg_size(&pdev->dev, 0x3FFFFFFF);
  25343. +
  25344. +
  25345. + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  25346. + dma_cap_set(DMA_PRIVATE, od->ddev.cap_mask);
  25347. + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  25348. + od->ddev.device_alloc_chan_resources = bcm2835_dma_alloc_chan_resources;
  25349. + od->ddev.device_free_chan_resources = bcm2835_dma_free_chan_resources;
  25350. + od->ddev.device_tx_status = bcm2835_dma_tx_status;
  25351. + od->ddev.device_issue_pending = bcm2835_dma_issue_pending;
  25352. + od->ddev.device_slave_caps = bcm2835_dma_device_slave_caps;
  25353. + od->ddev.device_prep_dma_cyclic = bcm2835_dma_prep_dma_cyclic;
  25354. + od->ddev.device_prep_slave_sg = bcm2835_dma_prep_slave_sg;
  25355. + od->ddev.device_control = bcm2835_dma_control;
  25356. + od->ddev.dev = &pdev->dev;
  25357. + INIT_LIST_HEAD(&od->ddev.channels);
  25358. + spin_lock_init(&od->lock);
  25359. +
  25360. + platform_set_drvdata(pdev, od);
  25361. +
  25362. + for (i = 0; i < 5; i++) {
  25363. + void __iomem *chan_base;
  25364. + int chan_id;
  25365. +
  25366. + chan_id = bcm_dma_chan_alloc(BCM_DMA_FEATURE_LITE,
  25367. + &chan_base,
  25368. + &irq);
  25369. +
  25370. + if (chan_id < 0)
  25371. + break;
  25372. +
  25373. + rc = bcm2708_dma_chan_init(od, chan_base, chan_id, irq);
  25374. + if (rc)
  25375. + goto err_no_dma;
  25376. + }
  25377. +#else
  25378. + rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  25379. + if (rc)
  25380. + return rc;
  25381. +
  25382. +
  25383. + od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  25384. + if (!od)
  25385. + return -ENOMEM;
  25386. +
  25387. + pdev->dev.dma_parms = &od->dma_parms;
  25388. + dma_set_max_seg_size(&pdev->dev, 0x3FFFFFFF);
  25389. +
  25390. +
  25391. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  25392. + base = devm_ioremap_resource(&pdev->dev, res);
  25393. + if (IS_ERR(base))
  25394. + return PTR_ERR(base);
  25395. +
  25396. + od->base = base;
  25397. +
  25398. +
  25399. + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  25400. + dma_cap_set(DMA_PRIVATE, od->ddev.cap_mask);
  25401. + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  25402. + od->ddev.device_alloc_chan_resources = bcm2835_dma_alloc_chan_resources;
  25403. + od->ddev.device_free_chan_resources = bcm2835_dma_free_chan_resources;
  25404. + od->ddev.device_tx_status = bcm2835_dma_tx_status;
  25405. + od->ddev.device_issue_pending = bcm2835_dma_issue_pending;
  25406. + od->ddev.device_slave_caps = bcm2835_dma_device_slave_caps;
  25407. + od->ddev.device_prep_dma_cyclic = bcm2835_dma_prep_dma_cyclic;
  25408. + od->ddev.device_prep_slave_sg = bcm2835_dma_prep_slave_sg;
  25409. + od->ddev.device_control = bcm2835_dma_control;
  25410. + od->ddev.dev = &pdev->dev;
  25411. + INIT_LIST_HEAD(&od->ddev.channels);
  25412. + spin_lock_init(&od->lock);
  25413. +
  25414. + platform_set_drvdata(pdev, od);
  25415. +
  25416. +
  25417. + /* Request DMA channel mask from device tree */
  25418. + if (of_property_read_u32(pdev->dev.of_node,
  25419. + "brcm,dma-channel-mask",
  25420. + &chans_available)) {
  25421. + dev_err(&pdev->dev, "Failed to get channel mask\n");
  25422. + rc = -EINVAL;
  25423. + goto err_no_dma;
  25424. + }
  25425. +
  25426. +
  25427. + /*
  25428. + * Do not use the FIQ and BULK channels,
  25429. + * because they are used by the GPU.
  25430. + */
  25431. + chans_available &= ~(BCM2835_DMA_FIQ_MASK | BCM2835_DMA_BULK_MASK);
  25432. +
  25433. +
  25434. + for (i = 0; i < pdev->num_resources; i++) {
  25435. + irq = platform_get_irq(pdev, i);
  25436. + if (irq < 0)
  25437. + break;
  25438. +
  25439. + if (chans_available & (1 << i)) {
  25440. + rc = bcm2835_dma_chan_init(od, i, irq);
  25441. + if (rc)
  25442. + goto err_no_dma;
  25443. + }
  25444. + }
  25445. +
  25446. + dev_dbg(&pdev->dev, "Initialized %i DMA channels\n", i);
  25447. +
  25448. + /* Device-tree DMA controller registration */
  25449. + rc = of_dma_controller_register(pdev->dev.of_node,
  25450. + bcm2835_dma_xlate, od);
  25451. + if (rc) {
  25452. + dev_err(&pdev->dev, "Failed to register DMA controller\n");
  25453. + goto err_no_dma;
  25454. + }
  25455. +#endif
  25456. +
  25457. + rc = dma_async_device_register(&od->ddev);
  25458. + if (rc) {
  25459. + dev_err(&pdev->dev,
  25460. + "Failed to register slave DMA engine device: %d\n", rc);
  25461. + goto err_no_dma;
  25462. + }
  25463. +
  25464. + dev_info(&pdev->dev, "Load BCM2835 DMA engine driver\n");
  25465. +
  25466. + return 0;
  25467. +
  25468. +err_no_dma:
  25469. + bcm2835_dma_free(od);
  25470. + return rc;
  25471. +}
  25472. +
  25473. +static int bcm2835_dma_remove(struct platform_device *pdev)
  25474. +{
  25475. + struct bcm2835_dmadev *od = platform_get_drvdata(pdev);
  25476. +
  25477. + dma_async_device_unregister(&od->ddev);
  25478. + bcm2835_dma_free(od);
  25479. +
  25480. + return 0;
  25481. +}
  25482. +
  25483. +#ifndef CONFIG_ARCH_BCM2835
  25484. +
  25485. +
  25486. +static struct platform_driver bcm2835_dma_driver = {
  25487. + .probe = bcm2835_dma_probe,
  25488. + .remove = bcm2835_dma_remove,
  25489. + .driver = {
  25490. + .name = "bcm2708-dmaengine",
  25491. + .owner = THIS_MODULE,
  25492. + },
  25493. +};
  25494. +
  25495. +static struct platform_device *pdev;
  25496. +
  25497. +static const struct platform_device_info bcm2835_dma_dev_info = {
  25498. + .name = "bcm2708-dmaengine",
  25499. + .id = -1,
  25500. +};
  25501. +
  25502. +static int bcm2835_dma_init(void)
  25503. +{
  25504. + int rc = platform_driver_register(&bcm2835_dma_driver);
  25505. +
  25506. + if (rc == 0) {
  25507. + pdev = platform_device_register_full(&bcm2835_dma_dev_info);
  25508. + if (IS_ERR(pdev)) {
  25509. + platform_driver_unregister(&bcm2835_dma_driver);
  25510. + rc = PTR_ERR(pdev);
  25511. + }
  25512. + }
  25513. +
  25514. + return rc;
  25515. +}
  25516. +module_init(bcm2835_dma_init); /* preferable to subsys_initcall */
  25517. +
  25518. +static void __exit bcm2835_dma_exit(void)
  25519. +{
  25520. + platform_device_unregister(pdev);
  25521. + platform_driver_unregister(&bcm2835_dma_driver);
  25522. +}
  25523. +module_exit(bcm2835_dma_exit);
  25524. +
  25525. +#else
  25526. +
  25527. +static struct platform_driver bcm2835_dma_driver = {
  25528. + .probe = bcm2835_dma_probe,
  25529. + .remove = bcm2835_dma_remove,
  25530. + .driver = {
  25531. + .name = "bcm2835-dma",
  25532. + .owner = THIS_MODULE,
  25533. + .of_match_table = of_match_ptr(bcm2835_dma_of_match),
  25534. + },
  25535. +};
  25536. +
  25537. +module_platform_driver(bcm2835_dma_driver);
  25538. +
  25539. +#endif
  25540. +
  25541. +MODULE_ALIAS("platform:bcm2835-dma");
  25542. +MODULE_DESCRIPTION("BCM2835 DMA engine driver");
  25543. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  25544. +MODULE_AUTHOR("Gellert Weisz <gellert@raspberrypi.org>");
  25545. +MODULE_LICENSE("GPL v2");
  25546. diff -Nur linux-3.18.6/drivers/dma/Kconfig linux-rpi/drivers/dma/Kconfig
  25547. --- linux-3.18.6/drivers/dma/Kconfig 2015-02-06 15:53:48.000000000 +0100
  25548. +++ linux-rpi/drivers/dma/Kconfig 2015-02-09 04:39:53.000000000 +0100
  25549. @@ -330,6 +330,12 @@
  25550. select DMA_ENGINE
  25551. select DMA_VIRTUAL_CHANNELS
  25552. +config DMA_BCM2708
  25553. + tristate "BCM2708 DMA engine support"
  25554. + depends on MACH_BCM2708 || MACH_BCM2709
  25555. + select DMA_ENGINE
  25556. + select DMA_VIRTUAL_CHANNELS
  25557. +
  25558. config TI_CPPI41
  25559. tristate "AM33xx CPPI41 DMA support"
  25560. depends on ARCH_OMAP
  25561. diff -Nur linux-3.18.6/drivers/dma/Makefile linux-rpi/drivers/dma/Makefile
  25562. --- linux-3.18.6/drivers/dma/Makefile 2015-02-06 15:53:48.000000000 +0100
  25563. +++ linux-rpi/drivers/dma/Makefile 2015-02-09 04:39:53.000000000 +0100
  25564. @@ -38,6 +38,7 @@
  25565. obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o
  25566. obj-$(CONFIG_DMA_OMAP) += omap-dma.o
  25567. obj-$(CONFIG_DMA_BCM2835) += bcm2835-dma.o
  25568. +obj-$(CONFIG_DMA_BCM2708) += bcm2708-dmaengine.o
  25569. obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
  25570. obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o
  25571. obj-$(CONFIG_TI_CPPI41) += cppi41.o
  25572. diff -Nur linux-3.18.6/drivers/hid/usbhid/hid-core.c linux-rpi/drivers/hid/usbhid/hid-core.c
  25573. --- linux-3.18.6/drivers/hid/usbhid/hid-core.c 2015-02-06 15:53:48.000000000 +0100
  25574. +++ linux-rpi/drivers/hid/usbhid/hid-core.c 2015-02-09 04:39:54.000000000 +0100
  25575. @@ -49,7 +49,7 @@
  25576. * Module parameters.
  25577. */
  25578. -static unsigned int hid_mousepoll_interval;
  25579. +static unsigned int hid_mousepoll_interval = ~0;
  25580. module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644);
  25581. MODULE_PARM_DESC(mousepoll, "Polling interval of mice");
  25582. @@ -1079,8 +1079,12 @@
  25583. }
  25584. /* Change the polling interval of mice. */
  25585. - if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
  25586. - interval = hid_mousepoll_interval;
  25587. + if (hid->collection->usage == HID_GD_MOUSE) {
  25588. + if (hid_mousepoll_interval == ~0 && interval < 16)
  25589. + interval = 16;
  25590. + else if (hid_mousepoll_interval != ~0 && hid_mousepoll_interval != 0)
  25591. + interval = hid_mousepoll_interval;
  25592. + }
  25593. ret = -ENOMEM;
  25594. if (usb_endpoint_dir_in(endpoint)) {
  25595. diff -Nur linux-3.18.6/drivers/hwmon/bcm2835-hwmon.c linux-rpi/drivers/hwmon/bcm2835-hwmon.c
  25596. --- linux-3.18.6/drivers/hwmon/bcm2835-hwmon.c 1970-01-01 01:00:00.000000000 +0100
  25597. +++ linux-rpi/drivers/hwmon/bcm2835-hwmon.c 2015-02-09 04:39:54.000000000 +0100
  25598. @@ -0,0 +1,219 @@
  25599. +/*****************************************************************************
  25600. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  25601. +*
  25602. +* Unless you and Broadcom execute a separate written software license
  25603. +* agreement governing use of this software, this software is licensed to you
  25604. +* under the terms of the GNU General Public License version 2, available at
  25605. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  25606. +*
  25607. +* Notwithstanding the above, under no circumstances may you combine this
  25608. +* software in any way with any other Broadcom software provided under a
  25609. +* license other than the GPL, without Broadcom's express prior written
  25610. +* consent.
  25611. +*****************************************************************************/
  25612. +
  25613. +#include <linux/kernel.h>
  25614. +#include <linux/module.h>
  25615. +#include <linux/init.h>
  25616. +#include <linux/hwmon.h>
  25617. +#include <linux/hwmon-sysfs.h>
  25618. +#include <linux/platform_device.h>
  25619. +#include <linux/sysfs.h>
  25620. +#include <mach/vcio.h>
  25621. +#include <linux/slab.h>
  25622. +#include <linux/err.h>
  25623. +
  25624. +#define MODULE_NAME "bcm2835_hwmon"
  25625. +
  25626. +/*#define HWMON_DEBUG_ENABLE*/
  25627. +
  25628. +#ifdef HWMON_DEBUG_ENABLE
  25629. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  25630. +#else
  25631. +#define print_debug(fmt,...)
  25632. +#endif
  25633. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  25634. +#define print_info(fmt,...) printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ##__VA_ARGS__)
  25635. +
  25636. +#define VC_TAG_GET_TEMP 0x00030006
  25637. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  25638. +
  25639. +/* --- STRUCTS --- */
  25640. +struct bcm2835_hwmon_data {
  25641. + struct device *hwmon_dev;
  25642. +};
  25643. +
  25644. +/* tag part of the message */
  25645. +struct vc_msg_tag {
  25646. + uint32_t tag_id; /* the tag ID for the temperature */
  25647. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  25648. + uint32_t request_code; /* identifies message as a request (should be 0) */
  25649. + uint32_t id; /* extra ID field (should be 0) */
  25650. + uint32_t val; /* returned value of the temperature */
  25651. +};
  25652. +
  25653. +/* message structure to be sent to videocore */
  25654. +struct vc_msg {
  25655. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  25656. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  25657. + struct vc_msg_tag tag; /* the tag structure above to make */
  25658. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  25659. +};
  25660. +
  25661. +typedef enum {
  25662. + TEMP,
  25663. + MAX_TEMP,
  25664. +} temp_type;
  25665. +
  25666. +/* --- PROTOTYPES --- */
  25667. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf);
  25668. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf);
  25669. +
  25670. +/* --- GLOBALS --- */
  25671. +
  25672. +static struct bcm2835_hwmon_data *bcm2835_data;
  25673. +static struct platform_driver bcm2835_hwmon_driver;
  25674. +
  25675. +static SENSOR_DEVICE_ATTR(name, S_IRUGO,bcm2835_get_name,NULL,0);
  25676. +static SENSOR_DEVICE_ATTR(temp1_input,S_IRUGO,bcm2835_get_temp,NULL,TEMP);
  25677. +static SENSOR_DEVICE_ATTR(temp1_max,S_IRUGO,bcm2835_get_temp,NULL,MAX_TEMP);
  25678. +
  25679. +static struct attribute* bcm2835_attributes[] = {
  25680. + &sensor_dev_attr_name.dev_attr.attr,
  25681. + &sensor_dev_attr_temp1_input.dev_attr.attr,
  25682. + &sensor_dev_attr_temp1_max.dev_attr.attr,
  25683. + NULL,
  25684. +};
  25685. +
  25686. +static struct attribute_group bcm2835_attr_group = {
  25687. + .attrs = bcm2835_attributes,
  25688. +};
  25689. +
  25690. +/* --- FUNCTIONS --- */
  25691. +
  25692. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf)
  25693. +{
  25694. + return sprintf(buf,"bcm2835_hwmon\n");
  25695. +}
  25696. +
  25697. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf)
  25698. +{
  25699. + struct vc_msg msg;
  25700. + int result;
  25701. + uint temp = 0;
  25702. + int index = ((struct sensor_device_attribute*)to_sensor_dev_attr(attr))->index;
  25703. +
  25704. + print_debug("IN");
  25705. +
  25706. + /* wipe all previous message data */
  25707. + memset(&msg, 0, sizeof msg);
  25708. +
  25709. + /* determine the message type */
  25710. + if(index == TEMP)
  25711. + msg.tag.tag_id = VC_TAG_GET_TEMP;
  25712. + else if (index == MAX_TEMP)
  25713. + msg.tag.tag_id = VC_TAG_GET_MAX_TEMP;
  25714. + else
  25715. + {
  25716. + print_debug("Unknown temperature message!");
  25717. + return -EINVAL;
  25718. + }
  25719. +
  25720. + msg.msg_size = sizeof msg;
  25721. + msg.tag.buffer_size = 8;
  25722. +
  25723. + /* send the message */
  25724. + result = bcm_mailbox_property(&msg, sizeof msg);
  25725. +
  25726. + /* check if it was all ok and return the rate in milli degrees C */
  25727. + if (result == 0 && (msg.request_code & 0x80000000))
  25728. + temp = (uint)msg.tag.val;
  25729. + #ifdef HWMON_DEBUG_ENABLE
  25730. + else
  25731. + print_debug("Failed to get temperature!");
  25732. + #endif
  25733. + print_debug("Got temperature as %u",temp);
  25734. + print_debug("OUT");
  25735. + return sprintf(buf, "%u\n", temp);
  25736. +}
  25737. +
  25738. +
  25739. +static int bcm2835_hwmon_probe(struct platform_device *pdev)
  25740. +{
  25741. + int err;
  25742. +
  25743. + print_debug("IN");
  25744. + print_debug("HWMON Driver has been probed!");
  25745. +
  25746. + /* check that the device isn't null!*/
  25747. + if(pdev == NULL)
  25748. + {
  25749. + print_debug("Platform device is empty!");
  25750. + return -ENODEV;
  25751. + }
  25752. +
  25753. + /* allocate memory for neccessary data */
  25754. + bcm2835_data = kzalloc(sizeof(struct bcm2835_hwmon_data),GFP_KERNEL);
  25755. + if(!bcm2835_data)
  25756. + {
  25757. + print_debug("Unable to allocate memory for hwmon data!");
  25758. + err = -ENOMEM;
  25759. + goto kzalloc_error;
  25760. + }
  25761. +
  25762. + /* create the sysfs files */
  25763. + if(sysfs_create_group(&pdev->dev.kobj, &bcm2835_attr_group))
  25764. + {
  25765. + print_debug("Unable to create sysfs files!");
  25766. + err = -EFAULT;
  25767. + goto sysfs_error;
  25768. + }
  25769. +
  25770. + /* register the hwmon device */
  25771. + bcm2835_data->hwmon_dev = hwmon_device_register(&pdev->dev);
  25772. + if (IS_ERR(bcm2835_data->hwmon_dev))
  25773. + {
  25774. + err = PTR_ERR(bcm2835_data->hwmon_dev);
  25775. + goto hwmon_error;
  25776. + }
  25777. + print_debug("OUT");
  25778. + return 0;
  25779. +
  25780. + /* error goto's */
  25781. + hwmon_error:
  25782. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  25783. +
  25784. + sysfs_error:
  25785. + kfree(bcm2835_data);
  25786. +
  25787. + kzalloc_error:
  25788. +
  25789. + return err;
  25790. +
  25791. +}
  25792. +
  25793. +static int bcm2835_hwmon_remove(struct platform_device *pdev)
  25794. +{
  25795. + print_debug("IN");
  25796. + hwmon_device_unregister(bcm2835_data->hwmon_dev);
  25797. +
  25798. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  25799. + print_debug("OUT");
  25800. + return 0;
  25801. +}
  25802. +
  25803. +/* Hwmon Driver */
  25804. +static struct platform_driver bcm2835_hwmon_driver = {
  25805. + .probe = bcm2835_hwmon_probe,
  25806. + .remove = bcm2835_hwmon_remove,
  25807. + .driver = {
  25808. + .name = "bcm2835_hwmon",
  25809. + .owner = THIS_MODULE,
  25810. + },
  25811. +};
  25812. +
  25813. +MODULE_LICENSE("GPL");
  25814. +MODULE_AUTHOR("Dorian Peake");
  25815. +MODULE_DESCRIPTION("HW Monitor driver for bcm2835 chip");
  25816. +
  25817. +module_platform_driver(bcm2835_hwmon_driver);
  25818. diff -Nur linux-3.18.6/drivers/hwmon/Kconfig linux-rpi/drivers/hwmon/Kconfig
  25819. --- linux-3.18.6/drivers/hwmon/Kconfig 2015-02-06 15:53:48.000000000 +0100
  25820. +++ linux-rpi/drivers/hwmon/Kconfig 2015-02-09 04:39:54.000000000 +0100
  25821. @@ -1680,6 +1680,16 @@
  25822. This driver provides support for the Ultra45 workstation environmental
  25823. sensors.
  25824. +config SENSORS_BCM2835
  25825. + depends on THERMAL_BCM2835=n
  25826. + tristate "Broadcom BCM2835 HWMON Driver"
  25827. + help
  25828. + If you say yes here you get support for the hardware
  25829. + monitoring features of the BCM2835 Chip
  25830. +
  25831. + This driver can also be built as a module. If so, the module
  25832. + will be called bcm2835-hwmon.
  25833. +
  25834. if ACPI
  25835. comment "ACPI drivers"
  25836. diff -Nur linux-3.18.6/drivers/hwmon/Makefile linux-rpi/drivers/hwmon/Makefile
  25837. --- linux-3.18.6/drivers/hwmon/Makefile 2015-02-06 15:53:48.000000000 +0100
  25838. +++ linux-rpi/drivers/hwmon/Makefile 2015-02-09 04:39:54.000000000 +0100
  25839. @@ -153,6 +153,7 @@
  25840. obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o
  25841. obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
  25842. obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
  25843. +obj-$(CONFIG_SENSORS_BCM2835) += bcm2835-hwmon.o
  25844. obj-$(CONFIG_PMBUS) += pmbus/
  25845. diff -Nur linux-3.18.6/drivers/i2c/busses/i2c-bcm2708.c linux-rpi/drivers/i2c/busses/i2c-bcm2708.c
  25846. --- linux-3.18.6/drivers/i2c/busses/i2c-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  25847. +++ linux-rpi/drivers/i2c/busses/i2c-bcm2708.c 2015-02-09 04:39:54.000000000 +0100
  25848. @@ -0,0 +1,521 @@
  25849. +/*
  25850. + * Driver for Broadcom BCM2708 BSC Controllers
  25851. + *
  25852. + * Copyright (C) 2012 Chris Boot & Frank Buss
  25853. + *
  25854. + * This driver is inspired by:
  25855. + * i2c-ocores.c, by Peter Korsgaard <jacmet@sunsite.dk>
  25856. + *
  25857. + * This program is free software; you can redistribute it and/or modify
  25858. + * it under the terms of the GNU General Public License as published by
  25859. + * the Free Software Foundation; either version 2 of the License, or
  25860. + * (at your option) any later version.
  25861. + *
  25862. + * This program is distributed in the hope that it will be useful,
  25863. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25864. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25865. + * GNU General Public License for more details.
  25866. + *
  25867. + * You should have received a copy of the GNU General Public License
  25868. + * along with this program; if not, write to the Free Software
  25869. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  25870. + */
  25871. +
  25872. +#include <linux/kernel.h>
  25873. +#include <linux/module.h>
  25874. +#include <linux/spinlock.h>
  25875. +#include <linux/clk.h>
  25876. +#include <linux/err.h>
  25877. +#include <linux/of.h>
  25878. +#include <linux/platform_device.h>
  25879. +#include <linux/io.h>
  25880. +#include <linux/slab.h>
  25881. +#include <linux/i2c.h>
  25882. +#include <linux/interrupt.h>
  25883. +#include <linux/sched.h>
  25884. +#include <linux/wait.h>
  25885. +
  25886. +/* BSC register offsets */
  25887. +#define BSC_C 0x00
  25888. +#define BSC_S 0x04
  25889. +#define BSC_DLEN 0x08
  25890. +#define BSC_A 0x0c
  25891. +#define BSC_FIFO 0x10
  25892. +#define BSC_DIV 0x14
  25893. +#define BSC_DEL 0x18
  25894. +#define BSC_CLKT 0x1c
  25895. +
  25896. +/* Bitfields in BSC_C */
  25897. +#define BSC_C_I2CEN 0x00008000
  25898. +#define BSC_C_INTR 0x00000400
  25899. +#define BSC_C_INTT 0x00000200
  25900. +#define BSC_C_INTD 0x00000100
  25901. +#define BSC_C_ST 0x00000080
  25902. +#define BSC_C_CLEAR_1 0x00000020
  25903. +#define BSC_C_CLEAR_2 0x00000010
  25904. +#define BSC_C_READ 0x00000001
  25905. +
  25906. +/* Bitfields in BSC_S */
  25907. +#define BSC_S_CLKT 0x00000200
  25908. +#define BSC_S_ERR 0x00000100
  25909. +#define BSC_S_RXF 0x00000080
  25910. +#define BSC_S_TXE 0x00000040
  25911. +#define BSC_S_RXD 0x00000020
  25912. +#define BSC_S_TXD 0x00000010
  25913. +#define BSC_S_RXR 0x00000008
  25914. +#define BSC_S_TXW 0x00000004
  25915. +#define BSC_S_DONE 0x00000002
  25916. +#define BSC_S_TA 0x00000001
  25917. +
  25918. +#define I2C_TIMEOUT_MS 150
  25919. +#define I2C_WAIT_LOOP_COUNT 40
  25920. +
  25921. +#define DRV_NAME "bcm2708_i2c"
  25922. +
  25923. +static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
  25924. +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  25925. +MODULE_PARM_DESC(baudrate, "The I2C baudrate");
  25926. +
  25927. +static bool combined = false;
  25928. +module_param(combined, bool, 0644);
  25929. +MODULE_PARM_DESC(combined, "Use combined transactions");
  25930. +
  25931. +struct bcm2708_i2c {
  25932. + struct i2c_adapter adapter;
  25933. +
  25934. + spinlock_t lock;
  25935. + void __iomem *base;
  25936. + int irq;
  25937. + struct clk *clk;
  25938. + u32 cdiv;
  25939. +
  25940. + struct completion done;
  25941. +
  25942. + struct i2c_msg *msg;
  25943. + int pos;
  25944. + int nmsgs;
  25945. + bool error;
  25946. +};
  25947. +
  25948. +/*
  25949. + * This function sets the ALT mode on the I2C pins so that we can use them with
  25950. + * the BSC hardware.
  25951. + *
  25952. + * FIXME: This is a hack. Use pinmux / pinctrl.
  25953. + */
  25954. +static void bcm2708_i2c_init_pinmode(int id)
  25955. +{
  25956. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  25957. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  25958. +
  25959. + int pin;
  25960. + u32 *gpio = ioremap(GPIO_BASE, SZ_16K);
  25961. +
  25962. + BUG_ON(id != 0 && id != 1);
  25963. + /* BSC0 is on GPIO 0 & 1, BSC1 is on GPIO 2 & 3 */
  25964. + for (pin = id*2+0; pin <= id*2+1; pin++) {
  25965. + printk("bcm2708_i2c_init_pinmode(%d,%d)\n", id, pin);
  25966. + INP_GPIO(pin); /* set mode to GPIO input first */
  25967. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  25968. + }
  25969. +
  25970. + iounmap(gpio);
  25971. +
  25972. +#undef INP_GPIO
  25973. +#undef SET_GPIO_ALT
  25974. +}
  25975. +
  25976. +static inline u32 bcm2708_rd(struct bcm2708_i2c *bi, unsigned reg)
  25977. +{
  25978. + return readl(bi->base + reg);
  25979. +}
  25980. +
  25981. +static inline void bcm2708_wr(struct bcm2708_i2c *bi, unsigned reg, u32 val)
  25982. +{
  25983. + writel(val, bi->base + reg);
  25984. +}
  25985. +
  25986. +static inline void bcm2708_bsc_reset(struct bcm2708_i2c *bi)
  25987. +{
  25988. + bcm2708_wr(bi, BSC_C, 0);
  25989. + bcm2708_wr(bi, BSC_S, BSC_S_CLKT | BSC_S_ERR | BSC_S_DONE);
  25990. +}
  25991. +
  25992. +static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
  25993. +{
  25994. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
  25995. + bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
  25996. +}
  25997. +
  25998. +static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
  25999. +{
  26000. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
  26001. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  26002. +}
  26003. +
  26004. +static inline int bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  26005. +{
  26006. + u32 cdiv, s;
  26007. + u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
  26008. + int wait_loops = I2C_WAIT_LOOP_COUNT;
  26009. +
  26010. + /* Can't call clk_get_rate as it locks a mutex and here we are spinlocked.
  26011. + * Use the value that we cached in the probe.
  26012. + */
  26013. + cdiv = bi->cdiv;
  26014. +
  26015. + if (bi->msg->flags & I2C_M_RD)
  26016. + c |= BSC_C_INTR | BSC_C_READ;
  26017. + else
  26018. + c |= BSC_C_INTT;
  26019. +
  26020. + bcm2708_wr(bi, BSC_DIV, cdiv);
  26021. + bcm2708_wr(bi, BSC_A, bi->msg->addr);
  26022. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  26023. + if (combined)
  26024. + {
  26025. + /* Do the next two messages meet combined transaction criteria?
  26026. + - Current message is a write, next message is a read
  26027. + - Both messages to same slave address
  26028. + - Write message can fit inside FIFO (16 bytes or less) */
  26029. + if ( (bi->nmsgs > 1) &&
  26030. + !(bi->msg[0].flags & I2C_M_RD) && (bi->msg[1].flags & I2C_M_RD) &&
  26031. + (bi->msg[0].addr == bi->msg[1].addr) && (bi->msg[0].len <= 16)) {
  26032. + /* Fill FIFO with entire write message (16 byte FIFO) */
  26033. + while (bi->pos < bi->msg->len) {
  26034. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  26035. + }
  26036. + /* Start write transfer (no interrupts, don't clear FIFO) */
  26037. + bcm2708_wr(bi, BSC_C, BSC_C_I2CEN | BSC_C_ST);
  26038. +
  26039. + /* poll for transfer start bit (should only take 1-20 polls) */
  26040. + do {
  26041. + s = bcm2708_rd(bi, BSC_S);
  26042. + } while (!(s & (BSC_S_TA | BSC_S_ERR | BSC_S_CLKT | BSC_S_DONE)) && --wait_loops >= 0);
  26043. +
  26044. + /* did we time out or some error occured? */
  26045. + if (wait_loops < 0 || (s & (BSC_S_ERR | BSC_S_CLKT))) {
  26046. + return -1;
  26047. + }
  26048. +
  26049. + /* Send next read message before the write transfer finishes. */
  26050. + bi->nmsgs--;
  26051. + bi->msg++;
  26052. + bi->pos = 0;
  26053. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  26054. + c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_INTR | BSC_C_ST | BSC_C_READ;
  26055. + }
  26056. + }
  26057. + bcm2708_wr(bi, BSC_C, c);
  26058. +
  26059. + return 0;
  26060. +}
  26061. +
  26062. +static irqreturn_t bcm2708_i2c_interrupt(int irq, void *dev_id)
  26063. +{
  26064. + struct bcm2708_i2c *bi = dev_id;
  26065. + bool handled = true;
  26066. + u32 s;
  26067. + int ret;
  26068. +
  26069. + spin_lock(&bi->lock);
  26070. +
  26071. + /* we may see camera interrupts on the "other" I2C channel
  26072. + Just return if we've not sent anything */
  26073. + if (!bi->nmsgs || !bi->msg) {
  26074. + goto early_exit;
  26075. + }
  26076. +
  26077. + s = bcm2708_rd(bi, BSC_S);
  26078. +
  26079. + if (s & (BSC_S_CLKT | BSC_S_ERR)) {
  26080. + bcm2708_bsc_reset(bi);
  26081. + bi->error = true;
  26082. +
  26083. + bi->msg = 0; /* to inform the that all work is done */
  26084. + bi->nmsgs = 0;
  26085. + /* wake up our bh */
  26086. + complete(&bi->done);
  26087. + } else if (s & BSC_S_DONE) {
  26088. + bi->nmsgs--;
  26089. +
  26090. + if (bi->msg->flags & I2C_M_RD) {
  26091. + bcm2708_bsc_fifo_drain(bi);
  26092. + }
  26093. +
  26094. + bcm2708_bsc_reset(bi);
  26095. +
  26096. + if (bi->nmsgs) {
  26097. + /* advance to next message */
  26098. + bi->msg++;
  26099. + bi->pos = 0;
  26100. + ret = bcm2708_bsc_setup(bi);
  26101. + if (ret < 0) {
  26102. + bcm2708_bsc_reset(bi);
  26103. + bi->error = true;
  26104. + bi->msg = 0; /* to inform the that all work is done */
  26105. + bi->nmsgs = 0;
  26106. + /* wake up our bh */
  26107. + complete(&bi->done);
  26108. + goto early_exit;
  26109. + }
  26110. + } else {
  26111. + bi->msg = 0; /* to inform the that all work is done */
  26112. + bi->nmsgs = 0;
  26113. + /* wake up our bh */
  26114. + complete(&bi->done);
  26115. + }
  26116. + } else if (s & BSC_S_TXW) {
  26117. + bcm2708_bsc_fifo_fill(bi);
  26118. + } else if (s & BSC_S_RXR) {
  26119. + bcm2708_bsc_fifo_drain(bi);
  26120. + } else {
  26121. + handled = false;
  26122. + }
  26123. +
  26124. +early_exit:
  26125. + spin_unlock(&bi->lock);
  26126. +
  26127. + return handled ? IRQ_HANDLED : IRQ_NONE;
  26128. +}
  26129. +
  26130. +static int bcm2708_i2c_master_xfer(struct i2c_adapter *adap,
  26131. + struct i2c_msg *msgs, int num)
  26132. +{
  26133. + struct bcm2708_i2c *bi = adap->algo_data;
  26134. + unsigned long flags;
  26135. + int ret;
  26136. +
  26137. + spin_lock_irqsave(&bi->lock, flags);
  26138. +
  26139. + reinit_completion(&bi->done);
  26140. + bi->msg = msgs;
  26141. + bi->pos = 0;
  26142. + bi->nmsgs = num;
  26143. + bi->error = false;
  26144. +
  26145. + ret = bcm2708_bsc_setup(bi);
  26146. +
  26147. + spin_unlock_irqrestore(&bi->lock, flags);
  26148. +
  26149. + /* check the result of the setup */
  26150. + if (ret < 0)
  26151. + {
  26152. + dev_err(&adap->dev, "transfer setup timed out\n");
  26153. + goto error_timeout;
  26154. + }
  26155. +
  26156. + ret = wait_for_completion_timeout(&bi->done, msecs_to_jiffies(I2C_TIMEOUT_MS));
  26157. + if (ret == 0) {
  26158. + dev_err(&adap->dev, "transfer timed out\n");
  26159. + goto error_timeout;
  26160. + }
  26161. +
  26162. + ret = bi->error ? -EIO : num;
  26163. + return ret;
  26164. +
  26165. +error_timeout:
  26166. + spin_lock_irqsave(&bi->lock, flags);
  26167. + bcm2708_bsc_reset(bi);
  26168. + bi->msg = 0; /* to inform the interrupt handler that there's nothing else to be done */
  26169. + bi->nmsgs = 0;
  26170. + spin_unlock_irqrestore(&bi->lock, flags);
  26171. + return -ETIMEDOUT;
  26172. +}
  26173. +
  26174. +static u32 bcm2708_i2c_functionality(struct i2c_adapter *adap)
  26175. +{
  26176. + return I2C_FUNC_I2C | /*I2C_FUNC_10BIT_ADDR |*/ I2C_FUNC_SMBUS_EMUL;
  26177. +}
  26178. +
  26179. +static struct i2c_algorithm bcm2708_i2c_algorithm = {
  26180. + .master_xfer = bcm2708_i2c_master_xfer,
  26181. + .functionality = bcm2708_i2c_functionality,
  26182. +};
  26183. +
  26184. +static int bcm2708_i2c_probe(struct platform_device *pdev)
  26185. +{
  26186. + struct resource *regs;
  26187. + int irq, err = -ENOMEM;
  26188. + struct clk *clk;
  26189. + struct bcm2708_i2c *bi;
  26190. + struct i2c_adapter *adap;
  26191. + unsigned long bus_hz;
  26192. + u32 cdiv;
  26193. +
  26194. + if (pdev->dev.of_node) {
  26195. + u32 bus_clk_rate;
  26196. + pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
  26197. + if (pdev->id < 0) {
  26198. + dev_err(&pdev->dev, "alias is missing\n");
  26199. + return -EINVAL;
  26200. + }
  26201. + if (!of_property_read_u32(pdev->dev.of_node,
  26202. + "clock-frequency", &bus_clk_rate))
  26203. + baudrate = bus_clk_rate;
  26204. + else
  26205. + dev_warn(&pdev->dev,
  26206. + "Could not read clock-frequency property\n");
  26207. + }
  26208. +
  26209. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  26210. + if (!regs) {
  26211. + dev_err(&pdev->dev, "could not get IO memory\n");
  26212. + return -ENXIO;
  26213. + }
  26214. +
  26215. + irq = platform_get_irq(pdev, 0);
  26216. + if (irq < 0) {
  26217. + dev_err(&pdev->dev, "could not get IRQ\n");
  26218. + return irq;
  26219. + }
  26220. +
  26221. + clk = clk_get(&pdev->dev, NULL);
  26222. + if (IS_ERR(clk)) {
  26223. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  26224. + return PTR_ERR(clk);
  26225. + }
  26226. +
  26227. + err = clk_prepare_enable(clk);
  26228. + if (err) {
  26229. + dev_err(&pdev->dev, "could not enable clk: %d\n", err);
  26230. + goto out_clk_put;
  26231. + }
  26232. +
  26233. + bcm2708_i2c_init_pinmode(pdev->id);
  26234. +
  26235. + bi = kzalloc(sizeof(*bi), GFP_KERNEL);
  26236. + if (!bi)
  26237. + goto out_clk_disable;
  26238. +
  26239. + platform_set_drvdata(pdev, bi);
  26240. +
  26241. + adap = &bi->adapter;
  26242. + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DDC;
  26243. + adap->algo = &bcm2708_i2c_algorithm;
  26244. + adap->algo_data = bi;
  26245. + adap->dev.parent = &pdev->dev;
  26246. + adap->nr = pdev->id;
  26247. + strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
  26248. + adap->dev.of_node = pdev->dev.of_node;
  26249. +
  26250. + switch (pdev->id) {
  26251. + case 0:
  26252. + adap->class = I2C_CLASS_HWMON;
  26253. + break;
  26254. + case 1:
  26255. + adap->class = I2C_CLASS_DDC;
  26256. + break;
  26257. + default:
  26258. + dev_err(&pdev->dev, "can only bind to BSC 0 or 1\n");
  26259. + err = -ENXIO;
  26260. + goto out_free_bi;
  26261. + }
  26262. +
  26263. + spin_lock_init(&bi->lock);
  26264. + init_completion(&bi->done);
  26265. +
  26266. + bi->base = ioremap(regs->start, resource_size(regs));
  26267. + if (!bi->base) {
  26268. + dev_err(&pdev->dev, "could not remap memory\n");
  26269. + goto out_free_bi;
  26270. + }
  26271. +
  26272. + bi->irq = irq;
  26273. + bi->clk = clk;
  26274. +
  26275. + err = request_irq(irq, bcm2708_i2c_interrupt, IRQF_SHARED,
  26276. + dev_name(&pdev->dev), bi);
  26277. + if (err) {
  26278. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  26279. + goto out_iounmap;
  26280. + }
  26281. +
  26282. + bcm2708_bsc_reset(bi);
  26283. +
  26284. + err = i2c_add_numbered_adapter(adap);
  26285. + if (err < 0) {
  26286. + dev_err(&pdev->dev, "could not add I2C adapter: %d\n", err);
  26287. + goto out_free_irq;
  26288. + }
  26289. +
  26290. + bus_hz = clk_get_rate(bi->clk);
  26291. + cdiv = bus_hz / baudrate;
  26292. + if (cdiv > 0xffff) {
  26293. + cdiv = 0xffff;
  26294. + baudrate = bus_hz / cdiv;
  26295. + }
  26296. + bi->cdiv = cdiv;
  26297. +
  26298. + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
  26299. + pdev->id, (unsigned long)regs->start, irq, baudrate);
  26300. +
  26301. + return 0;
  26302. +
  26303. +out_free_irq:
  26304. + free_irq(bi->irq, bi);
  26305. +out_iounmap:
  26306. + iounmap(bi->base);
  26307. +out_free_bi:
  26308. + kfree(bi);
  26309. +out_clk_disable:
  26310. + clk_disable_unprepare(clk);
  26311. +out_clk_put:
  26312. + clk_put(clk);
  26313. + return err;
  26314. +}
  26315. +
  26316. +static int bcm2708_i2c_remove(struct platform_device *pdev)
  26317. +{
  26318. + struct bcm2708_i2c *bi = platform_get_drvdata(pdev);
  26319. +
  26320. + platform_set_drvdata(pdev, NULL);
  26321. +
  26322. + i2c_del_adapter(&bi->adapter);
  26323. + free_irq(bi->irq, bi);
  26324. + iounmap(bi->base);
  26325. + clk_disable_unprepare(bi->clk);
  26326. + clk_put(bi->clk);
  26327. + kfree(bi);
  26328. +
  26329. + return 0;
  26330. +}
  26331. +
  26332. +static const struct of_device_id bcm2708_i2c_of_match[] = {
  26333. + { .compatible = "brcm,bcm2708-i2c" },
  26334. + {},
  26335. +};
  26336. +MODULE_DEVICE_TABLE(of, bcm2708_i2c_of_match);
  26337. +
  26338. +static struct platform_driver bcm2708_i2c_driver = {
  26339. + .driver = {
  26340. + .name = DRV_NAME,
  26341. + .owner = THIS_MODULE,
  26342. + .of_match_table = bcm2708_i2c_of_match,
  26343. + },
  26344. + .probe = bcm2708_i2c_probe,
  26345. + .remove = bcm2708_i2c_remove,
  26346. +};
  26347. +
  26348. +// module_platform_driver(bcm2708_i2c_driver);
  26349. +
  26350. +
  26351. +static int __init bcm2708_i2c_init(void)
  26352. +{
  26353. + return platform_driver_register(&bcm2708_i2c_driver);
  26354. +}
  26355. +
  26356. +static void __exit bcm2708_i2c_exit(void)
  26357. +{
  26358. + platform_driver_unregister(&bcm2708_i2c_driver);
  26359. +}
  26360. +
  26361. +module_init(bcm2708_i2c_init);
  26362. +module_exit(bcm2708_i2c_exit);
  26363. +
  26364. +
  26365. +
  26366. +MODULE_DESCRIPTION("BSC controller driver for Broadcom BCM2708");
  26367. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  26368. +MODULE_LICENSE("GPL v2");
  26369. +MODULE_ALIAS("platform:" DRV_NAME);
  26370. diff -Nur linux-3.18.6/drivers/i2c/busses/Kconfig linux-rpi/drivers/i2c/busses/Kconfig
  26371. --- linux-3.18.6/drivers/i2c/busses/Kconfig 2015-02-06 15:53:48.000000000 +0100
  26372. +++ linux-rpi/drivers/i2c/busses/Kconfig 2015-02-09 04:39:54.000000000 +0100
  26373. @@ -361,7 +361,7 @@
  26374. config I2C_BCM2835
  26375. tristate "Broadcom BCM2835 I2C controller"
  26376. - depends on ARCH_BCM2835
  26377. + depends on ARCH_BCM2835 || ARCH_BCM2708 || ARCH_BCM2709
  26378. help
  26379. If you say yes to this option, support will be included for the
  26380. BCM2835 I2C controller.
  26381. @@ -371,6 +371,25 @@
  26382. This support is also available as a module. If so, the module
  26383. will be called i2c-bcm2835.
  26384. +config I2C_BCM2708
  26385. + tristate "BCM2708 BSC"
  26386. + depends on MACH_BCM2708 || MACH_BCM2709
  26387. + help
  26388. + Enabling this option will add BSC (Broadcom Serial Controller)
  26389. + support for the BCM2708. BSC is a Broadcom proprietary bus compatible
  26390. + with I2C/TWI/SMBus.
  26391. +
  26392. +config I2C_BCM2708_BAUDRATE
  26393. + prompt "BCM2708 I2C baudrate"
  26394. + depends on I2C_BCM2708
  26395. + int
  26396. + default 100000
  26397. + help
  26398. + Set the I2C baudrate. This will alter the default value. A
  26399. + different baudrate can be set by using a module parameter as well. If
  26400. + no parameter is provided when loading, this is the value that will be
  26401. + used.
  26402. +
  26403. config I2C_BCM_KONA
  26404. tristate "BCM Kona I2C adapter"
  26405. depends on ARCH_BCM_MOBILE
  26406. diff -Nur linux-3.18.6/drivers/i2c/busses/Makefile linux-rpi/drivers/i2c/busses/Makefile
  26407. --- linux-3.18.6/drivers/i2c/busses/Makefile 2015-02-06 15:53:48.000000000 +0100
  26408. +++ linux-rpi/drivers/i2c/busses/Makefile 2015-02-09 04:39:54.000000000 +0100
  26409. @@ -33,6 +33,7 @@
  26410. obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
  26411. obj-$(CONFIG_I2C_AXXIA) += i2c-axxia.o
  26412. obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o
  26413. +obj-$(CONFIG_I2C_BCM2708) += i2c-bcm2708.o
  26414. obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
  26415. obj-$(CONFIG_I2C_CADENCE) += i2c-cadence.o
  26416. obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o
  26417. diff -Nur linux-3.18.6/drivers/leds/trigger/Kconfig linux-rpi/drivers/leds/trigger/Kconfig
  26418. --- linux-3.18.6/drivers/leds/trigger/Kconfig 2015-02-06 15:53:48.000000000 +0100
  26419. +++ linux-rpi/drivers/leds/trigger/Kconfig 2015-02-09 04:40:01.000000000 +0100
  26420. @@ -108,4 +108,11 @@
  26421. This enables direct flash/torch on/off by the driver, kernel space.
  26422. If unsure, say Y.
  26423. +config LEDS_TRIGGER_INPUT
  26424. + tristate "LED Input Trigger"
  26425. + depends on LEDS_TRIGGERS
  26426. + help
  26427. + This allows the GPIOs assigned to be LEDs to be initialised to inputs.
  26428. + If unsure, say Y.
  26429. +
  26430. endif # LEDS_TRIGGERS
  26431. diff -Nur linux-3.18.6/drivers/leds/trigger/ledtrig-input.c linux-rpi/drivers/leds/trigger/ledtrig-input.c
  26432. --- linux-3.18.6/drivers/leds/trigger/ledtrig-input.c 1970-01-01 01:00:00.000000000 +0100
  26433. +++ linux-rpi/drivers/leds/trigger/ledtrig-input.c 2015-02-09 04:40:01.000000000 +0100
  26434. @@ -0,0 +1,65 @@
  26435. +/*
  26436. + * Set LED GPIO to Input "Trigger"
  26437. + *
  26438. + * Copyright 2015 Phil Elwell <phil@raspberrypi.org>
  26439. + *
  26440. + * Based on Nick Forbes's ledtrig-default-on.c.
  26441. + *
  26442. + * This program is free software; you can redistribute it and/or modify
  26443. + * it under the terms of the GNU General Public License version 2 as
  26444. + * published by the Free Software Foundation.
  26445. + *
  26446. + */
  26447. +
  26448. +#include <linux/module.h>
  26449. +#include <linux/kernel.h>
  26450. +#include <linux/init.h>
  26451. +#include <linux/leds.h>
  26452. +#include <linux/gpio.h>
  26453. +#include "../leds.h"
  26454. +
  26455. +/* This is a hack to get at the private 'gpio' member */
  26456. +
  26457. +struct gpio_led_data {
  26458. + struct led_classdev cdev;
  26459. + unsigned gpio;
  26460. +};
  26461. +
  26462. +static void input_trig_activate(struct led_classdev *led_cdev)
  26463. +{
  26464. + struct gpio_led_data *led_dat =
  26465. + container_of(led_cdev, struct gpio_led_data, cdev);
  26466. + if (gpio_is_valid(led_dat->gpio))
  26467. + gpio_direction_input(led_dat->gpio);
  26468. +}
  26469. +
  26470. +static void input_trig_deactivate(struct led_classdev *led_cdev)
  26471. +{
  26472. + struct gpio_led_data *led_dat =
  26473. + container_of(led_cdev, struct gpio_led_data, cdev);
  26474. + if (gpio_is_valid(led_dat->gpio))
  26475. + gpio_direction_output(led_dat->gpio, 0);
  26476. +}
  26477. +
  26478. +static struct led_trigger input_led_trigger = {
  26479. + .name = "input",
  26480. + .activate = input_trig_activate,
  26481. + .deactivate = input_trig_deactivate,
  26482. +};
  26483. +
  26484. +static int __init input_trig_init(void)
  26485. +{
  26486. + return led_trigger_register(&input_led_trigger);
  26487. +}
  26488. +
  26489. +static void __exit input_trig_exit(void)
  26490. +{
  26491. + led_trigger_unregister(&input_led_trigger);
  26492. +}
  26493. +
  26494. +module_init(input_trig_init);
  26495. +module_exit(input_trig_exit);
  26496. +
  26497. +MODULE_AUTHOR("Phil Elwell <phil@raspberrypi.org>");
  26498. +MODULE_DESCRIPTION("Set LED GPIO to Input \"trigger\"");
  26499. +MODULE_LICENSE("GPL");
  26500. diff -Nur linux-3.18.6/drivers/leds/trigger/Makefile linux-rpi/drivers/leds/trigger/Makefile
  26501. --- linux-3.18.6/drivers/leds/trigger/Makefile 2015-02-06 15:53:48.000000000 +0100
  26502. +++ linux-rpi/drivers/leds/trigger/Makefile 2015-02-09 04:40:01.000000000 +0100
  26503. @@ -8,3 +8,4 @@
  26504. obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o
  26505. obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT) += ledtrig-transient.o
  26506. obj-$(CONFIG_LEDS_TRIGGER_CAMERA) += ledtrig-camera.o
  26507. +obj-$(CONFIG_LEDS_TRIGGER_INPUT) += ledtrig-input.o
  26508. diff -Nur linux-3.18.6/drivers/media/platform/bcm2835/bcm2835-camera.c linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.c
  26509. --- linux-3.18.6/drivers/media/platform/bcm2835/bcm2835-camera.c 1970-01-01 01:00:00.000000000 +0100
  26510. +++ linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.c 2015-02-09 04:40:03.000000000 +0100
  26511. @@ -0,0 +1,1824 @@
  26512. +/*
  26513. + * Broadcom BM2835 V4L2 driver
  26514. + *
  26515. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  26516. + *
  26517. + * This file is subject to the terms and conditions of the GNU General Public
  26518. + * License. See the file COPYING in the main directory of this archive
  26519. + * for more details.
  26520. + *
  26521. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  26522. + * Dave Stevenson <dsteve@broadcom.com>
  26523. + * Simon Mellor <simellor@broadcom.com>
  26524. + * Luke Diamand <luked@broadcom.com>
  26525. + */
  26526. +
  26527. +#include <linux/errno.h>
  26528. +#include <linux/kernel.h>
  26529. +#include <linux/module.h>
  26530. +#include <linux/slab.h>
  26531. +#include <media/videobuf2-vmalloc.h>
  26532. +#include <media/videobuf2-dma-contig.h>
  26533. +#include <media/v4l2-device.h>
  26534. +#include <media/v4l2-ioctl.h>
  26535. +#include <media/v4l2-ctrls.h>
  26536. +#include <media/v4l2-fh.h>
  26537. +#include <media/v4l2-event.h>
  26538. +#include <media/v4l2-common.h>
  26539. +#include <linux/delay.h>
  26540. +
  26541. +#include "mmal-common.h"
  26542. +#include "mmal-encodings.h"
  26543. +#include "mmal-vchiq.h"
  26544. +#include "mmal-msg.h"
  26545. +#include "mmal-parameters.h"
  26546. +#include "bcm2835-camera.h"
  26547. +
  26548. +#define BM2835_MMAL_VERSION "0.0.2"
  26549. +#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
  26550. +#define MIN_WIDTH 16
  26551. +#define MIN_HEIGHT 16
  26552. +#define MAX_WIDTH 2592
  26553. +#define MAX_HEIGHT 1944
  26554. +#define MIN_BUFFER_SIZE (80*1024)
  26555. +
  26556. +#define MAX_VIDEO_MODE_WIDTH 1280
  26557. +#define MAX_VIDEO_MODE_HEIGHT 720
  26558. +
  26559. +MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
  26560. +MODULE_AUTHOR("Vincent Sanders");
  26561. +MODULE_LICENSE("GPL");
  26562. +MODULE_VERSION(BM2835_MMAL_VERSION);
  26563. +
  26564. +int bcm2835_v4l2_debug;
  26565. +module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
  26566. +MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
  26567. +
  26568. +int max_video_width = MAX_VIDEO_MODE_WIDTH;
  26569. +int max_video_height = MAX_VIDEO_MODE_HEIGHT;
  26570. +module_param(max_video_width, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  26571. +MODULE_PARM_DESC(max_video_width, "Threshold for video mode");
  26572. +module_param(max_video_height, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  26573. +MODULE_PARM_DESC(max_video_height, "Threshold for video mode");
  26574. +
  26575. +/* Gstreamer bug https://bugzilla.gnome.org/show_bug.cgi?id=726521
  26576. + * v4l2src does bad (and actually wrong) things when the vidioc_enum_framesizes
  26577. + * function says type V4L2_FRMSIZE_TYPE_STEPWISE, which we do by default.
  26578. + * It's happier if we just don't say anything at all, when it then
  26579. + * sets up a load of defaults that it thinks might work.
  26580. + * If gst_v4l2src_is_broken is non-zero, then we remove the function from
  26581. + * our function table list (actually switch to an alternate set, but same
  26582. + * result).
  26583. + */
  26584. +int gst_v4l2src_is_broken = 0;
  26585. +module_param(gst_v4l2src_is_broken, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  26586. +MODULE_PARM_DESC(gst_v4l2src_is_broken, "If non-zero, enable workaround for Gstreamer");
  26587. +
  26588. +static struct bm2835_mmal_dev *gdev; /* global device data */
  26589. +
  26590. +#define FPS_MIN 1
  26591. +#define FPS_MAX 90
  26592. +
  26593. +/* timeperframe: min/max and default */
  26594. +static const struct v4l2_fract
  26595. + tpf_min = {.numerator = 1, .denominator = FPS_MAX},
  26596. + tpf_max = {.numerator = 1, .denominator = FPS_MIN},
  26597. + tpf_default = {.numerator = 1000, .denominator = 30000};
  26598. +
  26599. +/* video formats */
  26600. +static struct mmal_fmt formats[] = {
  26601. + {
  26602. + .name = "4:2:0, packed YUV",
  26603. + .fourcc = V4L2_PIX_FMT_YUV420,
  26604. + .flags = 0,
  26605. + .mmal = MMAL_ENCODING_I420,
  26606. + .depth = 12,
  26607. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26608. + },
  26609. + {
  26610. + .name = "4:2:2, packed, YUYV",
  26611. + .fourcc = V4L2_PIX_FMT_YUYV,
  26612. + .flags = 0,
  26613. + .mmal = MMAL_ENCODING_YUYV,
  26614. + .depth = 16,
  26615. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26616. + },
  26617. + {
  26618. + .name = "RGB24 (LE)",
  26619. + .fourcc = V4L2_PIX_FMT_RGB24,
  26620. + .flags = 0,
  26621. + .mmal = MMAL_ENCODING_BGR24,
  26622. + .depth = 24,
  26623. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26624. + },
  26625. + {
  26626. + .name = "JPEG",
  26627. + .fourcc = V4L2_PIX_FMT_JPEG,
  26628. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  26629. + .mmal = MMAL_ENCODING_JPEG,
  26630. + .depth = 8,
  26631. + .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
  26632. + },
  26633. + {
  26634. + .name = "H264",
  26635. + .fourcc = V4L2_PIX_FMT_H264,
  26636. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  26637. + .mmal = MMAL_ENCODING_H264,
  26638. + .depth = 8,
  26639. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  26640. + },
  26641. + {
  26642. + .name = "MJPEG",
  26643. + .fourcc = V4L2_PIX_FMT_MJPEG,
  26644. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  26645. + .mmal = MMAL_ENCODING_MJPEG,
  26646. + .depth = 8,
  26647. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  26648. + },
  26649. + {
  26650. + .name = "4:2:2, packed, YVYU",
  26651. + .fourcc = V4L2_PIX_FMT_YVYU,
  26652. + .flags = 0,
  26653. + .mmal = MMAL_ENCODING_YVYU,
  26654. + .depth = 16,
  26655. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26656. + },
  26657. + {
  26658. + .name = "4:2:2, packed, VYUY",
  26659. + .fourcc = V4L2_PIX_FMT_VYUY,
  26660. + .flags = 0,
  26661. + .mmal = MMAL_ENCODING_VYUY,
  26662. + .depth = 16,
  26663. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26664. + },
  26665. + {
  26666. + .name = "4:2:2, packed, UYVY",
  26667. + .fourcc = V4L2_PIX_FMT_UYVY,
  26668. + .flags = 0,
  26669. + .mmal = MMAL_ENCODING_UYVY,
  26670. + .depth = 16,
  26671. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26672. + },
  26673. + {
  26674. + .name = "4:2:0, packed, NV12",
  26675. + .fourcc = V4L2_PIX_FMT_NV12,
  26676. + .flags = 0,
  26677. + .mmal = MMAL_ENCODING_NV12,
  26678. + .depth = 12,
  26679. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26680. + },
  26681. + {
  26682. + .name = "RGB24 (BE)",
  26683. + .fourcc = V4L2_PIX_FMT_BGR24,
  26684. + .flags = 0,
  26685. + .mmal = MMAL_ENCODING_RGB24,
  26686. + .depth = 24,
  26687. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26688. + },
  26689. + {
  26690. + .name = "4:2:0, packed YVU",
  26691. + .fourcc = V4L2_PIX_FMT_YVU420,
  26692. + .flags = 0,
  26693. + .mmal = MMAL_ENCODING_YV12,
  26694. + .depth = 12,
  26695. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26696. + },
  26697. + {
  26698. + .name = "4:2:0, packed, NV21",
  26699. + .fourcc = V4L2_PIX_FMT_NV21,
  26700. + .flags = 0,
  26701. + .mmal = MMAL_ENCODING_NV21,
  26702. + .depth = 12,
  26703. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26704. + },
  26705. + {
  26706. + .name = "RGB32 (BE)",
  26707. + .fourcc = V4L2_PIX_FMT_BGR32,
  26708. + .flags = 0,
  26709. + .mmal = MMAL_ENCODING_BGRA,
  26710. + .depth = 32,
  26711. + .mmal_component = MMAL_COMPONENT_CAMERA,
  26712. + },
  26713. +};
  26714. +
  26715. +static struct mmal_fmt *get_format(struct v4l2_format *f)
  26716. +{
  26717. + struct mmal_fmt *fmt;
  26718. + unsigned int k;
  26719. +
  26720. + for (k = 0; k < ARRAY_SIZE(formats); k++) {
  26721. + fmt = &formats[k];
  26722. + if (fmt->fourcc == f->fmt.pix.pixelformat)
  26723. + break;
  26724. + }
  26725. +
  26726. + if (k == ARRAY_SIZE(formats))
  26727. + return NULL;
  26728. +
  26729. + return &formats[k];
  26730. +}
  26731. +
  26732. +/* ------------------------------------------------------------------
  26733. + Videobuf queue operations
  26734. + ------------------------------------------------------------------*/
  26735. +
  26736. +static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  26737. + unsigned int *nbuffers, unsigned int *nplanes,
  26738. + unsigned int sizes[], void *alloc_ctxs[])
  26739. +{
  26740. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  26741. + unsigned long size;
  26742. +
  26743. + /* refuse queue setup if port is not configured */
  26744. + if (dev->capture.port == NULL) {
  26745. + v4l2_err(&dev->v4l2_dev,
  26746. + "%s: capture port not configured\n", __func__);
  26747. + return -EINVAL;
  26748. + }
  26749. +
  26750. + size = dev->capture.port->current_buffer.size;
  26751. + if (size == 0) {
  26752. + v4l2_err(&dev->v4l2_dev,
  26753. + "%s: capture port buffer size is zero\n", __func__);
  26754. + return -EINVAL;
  26755. + }
  26756. +
  26757. + if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
  26758. + *nbuffers = (dev->capture.port->current_buffer.num + 2);
  26759. +
  26760. + *nplanes = 1;
  26761. +
  26762. + sizes[0] = size;
  26763. +
  26764. + /*
  26765. + * videobuf2-vmalloc allocator is context-less so no need to set
  26766. + * alloc_ctxs array.
  26767. + */
  26768. +
  26769. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  26770. + __func__, dev);
  26771. +
  26772. + return 0;
  26773. +}
  26774. +
  26775. +static int buffer_prepare(struct vb2_buffer *vb)
  26776. +{
  26777. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  26778. + unsigned long size;
  26779. +
  26780. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  26781. + __func__, dev);
  26782. +
  26783. + BUG_ON(dev->capture.port == NULL);
  26784. + BUG_ON(dev->capture.fmt == NULL);
  26785. +
  26786. + size = dev->capture.stride * dev->capture.height;
  26787. + if (vb2_plane_size(vb, 0) < size) {
  26788. + v4l2_err(&dev->v4l2_dev,
  26789. + "%s data will not fit into plane (%lu < %lu)\n",
  26790. + __func__, vb2_plane_size(vb, 0), size);
  26791. + return -EINVAL;
  26792. + }
  26793. +
  26794. + return 0;
  26795. +}
  26796. +
  26797. +static inline bool is_capturing(struct bm2835_mmal_dev *dev)
  26798. +{
  26799. + return dev->capture.camera_port ==
  26800. + &dev->
  26801. + component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
  26802. +}
  26803. +
  26804. +static void buffer_cb(struct vchiq_mmal_instance *instance,
  26805. + struct vchiq_mmal_port *port,
  26806. + int status,
  26807. + struct mmal_buffer *buf,
  26808. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
  26809. +{
  26810. + struct bm2835_mmal_dev *dev = port->cb_ctx;
  26811. +
  26812. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  26813. + "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
  26814. + __func__, status, buf, length, mmal_flags, pts);
  26815. +
  26816. + if (status != 0) {
  26817. + /* error in transfer */
  26818. + if (buf != NULL) {
  26819. + /* there was a buffer with the error so return it */
  26820. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  26821. + }
  26822. + return;
  26823. + } else if (length == 0) {
  26824. + /* stream ended */
  26825. + if (buf != NULL) {
  26826. + /* this should only ever happen if the port is
  26827. + * disabled and there are buffers still queued
  26828. + */
  26829. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  26830. + pr_debug("Empty buffer");
  26831. + } else if (dev->capture.frame_count) {
  26832. + /* grab another frame */
  26833. + if (is_capturing(dev)) {
  26834. + pr_debug("Grab another frame");
  26835. + vchiq_mmal_port_parameter_set(
  26836. + instance,
  26837. + dev->capture.
  26838. + camera_port,
  26839. + MMAL_PARAMETER_CAPTURE,
  26840. + &dev->capture.
  26841. + frame_count,
  26842. + sizeof(dev->capture.frame_count));
  26843. + }
  26844. + } else {
  26845. + /* signal frame completion */
  26846. + complete(&dev->capture.frame_cmplt);
  26847. + }
  26848. + } else {
  26849. + if (dev->capture.frame_count) {
  26850. + if (dev->capture.vc_start_timestamp != -1 &&
  26851. + pts != 0) {
  26852. + s64 runtime_us = pts -
  26853. + dev->capture.vc_start_timestamp;
  26854. + u32 div = 0;
  26855. + u32 rem = 0;
  26856. +
  26857. + div =
  26858. + div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
  26859. + buf->vb.v4l2_buf.timestamp.tv_sec =
  26860. + dev->capture.kernel_start_ts.tv_sec - 1 +
  26861. + div;
  26862. + buf->vb.v4l2_buf.timestamp.tv_usec =
  26863. + dev->capture.kernel_start_ts.tv_usec + rem;
  26864. +
  26865. + if (buf->vb.v4l2_buf.timestamp.tv_usec >=
  26866. + USEC_PER_SEC) {
  26867. + buf->vb.v4l2_buf.timestamp.tv_sec++;
  26868. + buf->vb.v4l2_buf.timestamp.tv_usec -=
  26869. + USEC_PER_SEC;
  26870. + }
  26871. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  26872. + "Convert start time %d.%06d and %llu "
  26873. + "with offset %llu to %d.%06d\n",
  26874. + (int)dev->capture.kernel_start_ts.
  26875. + tv_sec,
  26876. + (int)dev->capture.kernel_start_ts.
  26877. + tv_usec,
  26878. + dev->capture.vc_start_timestamp, pts,
  26879. + (int)buf->vb.v4l2_buf.timestamp.tv_sec,
  26880. + (int)buf->vb.v4l2_buf.timestamp.
  26881. + tv_usec);
  26882. + } else {
  26883. + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
  26884. + }
  26885. +
  26886. + vb2_set_plane_payload(&buf->vb, 0, length);
  26887. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
  26888. +
  26889. + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
  26890. + is_capturing(dev)) {
  26891. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  26892. + "Grab another frame as buffer has EOS");
  26893. + vchiq_mmal_port_parameter_set(
  26894. + instance,
  26895. + dev->capture.
  26896. + camera_port,
  26897. + MMAL_PARAMETER_CAPTURE,
  26898. + &dev->capture.
  26899. + frame_count,
  26900. + sizeof(dev->capture.frame_count));
  26901. + }
  26902. + } else {
  26903. + /* signal frame completion */
  26904. + complete(&dev->capture.frame_cmplt);
  26905. + }
  26906. + }
  26907. +}
  26908. +
  26909. +static int enable_camera(struct bm2835_mmal_dev *dev)
  26910. +{
  26911. + int ret;
  26912. + if (!dev->camera_use_count) {
  26913. + ret = vchiq_mmal_component_enable(
  26914. + dev->instance,
  26915. + dev->component[MMAL_COMPONENT_CAMERA]);
  26916. + if (ret < 0) {
  26917. + v4l2_err(&dev->v4l2_dev,
  26918. + "Failed enabling camera, ret %d\n", ret);
  26919. + return -EINVAL;
  26920. + }
  26921. + }
  26922. + dev->camera_use_count++;
  26923. + v4l2_dbg(1, bcm2835_v4l2_debug,
  26924. + &dev->v4l2_dev, "enabled camera (refcount %d)\n",
  26925. + dev->camera_use_count);
  26926. + return 0;
  26927. +}
  26928. +
  26929. +static int disable_camera(struct bm2835_mmal_dev *dev)
  26930. +{
  26931. + int ret;
  26932. + if (!dev->camera_use_count) {
  26933. + v4l2_err(&dev->v4l2_dev,
  26934. + "Disabled the camera when already disabled\n");
  26935. + return -EINVAL;
  26936. + }
  26937. + dev->camera_use_count--;
  26938. + if (!dev->camera_use_count) {
  26939. + unsigned int i = 0xFFFFFFFF;
  26940. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  26941. + "Disabling camera\n");
  26942. + ret =
  26943. + vchiq_mmal_component_disable(
  26944. + dev->instance,
  26945. + dev->component[MMAL_COMPONENT_CAMERA]);
  26946. + if (ret < 0) {
  26947. + v4l2_err(&dev->v4l2_dev,
  26948. + "Failed disabling camera, ret %d\n", ret);
  26949. + return -EINVAL;
  26950. + }
  26951. + vchiq_mmal_port_parameter_set(
  26952. + dev->instance,
  26953. + &dev->component[MMAL_COMPONENT_CAMERA]->control,
  26954. + MMAL_PARAMETER_CAMERA_NUM, &i,
  26955. + sizeof(i));
  26956. + }
  26957. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  26958. + "Camera refcount now %d\n", dev->camera_use_count);
  26959. + return 0;
  26960. +}
  26961. +
  26962. +static void buffer_queue(struct vb2_buffer *vb)
  26963. +{
  26964. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  26965. + struct mmal_buffer *buf = container_of(vb, struct mmal_buffer, vb);
  26966. + int ret;
  26967. +
  26968. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  26969. + "%s: dev:%p buf:%p\n", __func__, dev, buf);
  26970. +
  26971. + buf->buffer = vb2_plane_vaddr(&buf->vb, 0);
  26972. + buf->buffer_size = vb2_plane_size(&buf->vb, 0);
  26973. +
  26974. + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
  26975. + if (ret < 0)
  26976. + v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
  26977. + __func__);
  26978. +}
  26979. +
  26980. +static int start_streaming(struct vb2_queue *vq, unsigned int count)
  26981. +{
  26982. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  26983. + int ret;
  26984. + int parameter_size;
  26985. +
  26986. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  26987. + __func__, dev);
  26988. +
  26989. + /* ensure a format has actually been set */
  26990. + if (dev->capture.port == NULL)
  26991. + return -EINVAL;
  26992. +
  26993. + if (enable_camera(dev) < 0) {
  26994. + v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
  26995. + return -EINVAL;
  26996. + }
  26997. +
  26998. + /*init_completion(&dev->capture.frame_cmplt); */
  26999. +
  27000. + /* enable frame capture */
  27001. + dev->capture.frame_count = 1;
  27002. +
  27003. + /* if the preview is not already running, wait for a few frames for AGC
  27004. + * to settle down.
  27005. + */
  27006. + if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
  27007. + msleep(300);
  27008. +
  27009. + /* enable the connection from camera to encoder (if applicable) */
  27010. + if (dev->capture.camera_port != dev->capture.port
  27011. + && dev->capture.camera_port) {
  27012. + ret = vchiq_mmal_port_enable(dev->instance,
  27013. + dev->capture.camera_port, NULL);
  27014. + if (ret) {
  27015. + v4l2_err(&dev->v4l2_dev,
  27016. + "Failed to enable encode tunnel - error %d\n",
  27017. + ret);
  27018. + return -1;
  27019. + }
  27020. + }
  27021. +
  27022. + /* Get VC timestamp at this point in time */
  27023. + parameter_size = sizeof(dev->capture.vc_start_timestamp);
  27024. + if (vchiq_mmal_port_parameter_get(dev->instance,
  27025. + dev->capture.camera_port,
  27026. + MMAL_PARAMETER_SYSTEM_TIME,
  27027. + &dev->capture.vc_start_timestamp,
  27028. + &parameter_size)) {
  27029. + v4l2_err(&dev->v4l2_dev,
  27030. + "Failed to get VC start time - update your VC f/w\n");
  27031. +
  27032. + /* Flag to indicate just to rely on kernel timestamps */
  27033. + dev->capture.vc_start_timestamp = -1;
  27034. + } else
  27035. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27036. + "Start time %lld size %d\n",
  27037. + dev->capture.vc_start_timestamp, parameter_size);
  27038. +
  27039. + v4l2_get_timestamp(&dev->capture.kernel_start_ts);
  27040. +
  27041. + /* enable the camera port */
  27042. + dev->capture.port->cb_ctx = dev;
  27043. + ret =
  27044. + vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
  27045. + if (ret) {
  27046. + v4l2_err(&dev->v4l2_dev,
  27047. + "Failed to enable capture port - error %d. "
  27048. + "Disabling camera port again\n", ret);
  27049. +
  27050. + vchiq_mmal_port_disable(dev->instance,
  27051. + dev->capture.camera_port);
  27052. + if (disable_camera(dev) < 0) {
  27053. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
  27054. + return -EINVAL;
  27055. + }
  27056. + return -1;
  27057. + }
  27058. +
  27059. + /* capture the first frame */
  27060. + vchiq_mmal_port_parameter_set(dev->instance,
  27061. + dev->capture.camera_port,
  27062. + MMAL_PARAMETER_CAPTURE,
  27063. + &dev->capture.frame_count,
  27064. + sizeof(dev->capture.frame_count));
  27065. + return 0;
  27066. +}
  27067. +
  27068. +/* abort streaming and wait for last buffer */
  27069. +static void stop_streaming(struct vb2_queue *vq)
  27070. +{
  27071. + int ret;
  27072. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  27073. +
  27074. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  27075. + __func__, dev);
  27076. +
  27077. + init_completion(&dev->capture.frame_cmplt);
  27078. + dev->capture.frame_count = 0;
  27079. +
  27080. + /* ensure a format has actually been set */
  27081. + if (dev->capture.port == NULL) {
  27082. + v4l2_err(&dev->v4l2_dev,
  27083. + "no capture port - stream not started?\n");
  27084. + return;
  27085. + }
  27086. +
  27087. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
  27088. +
  27089. + /* stop capturing frames */
  27090. + vchiq_mmal_port_parameter_set(dev->instance,
  27091. + dev->capture.camera_port,
  27092. + MMAL_PARAMETER_CAPTURE,
  27093. + &dev->capture.frame_count,
  27094. + sizeof(dev->capture.frame_count));
  27095. +
  27096. + /* wait for last frame to complete */
  27097. + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
  27098. + if (ret <= 0)
  27099. + v4l2_err(&dev->v4l2_dev,
  27100. + "error %d waiting for frame completion\n", ret);
  27101. +
  27102. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27103. + "disabling connection\n");
  27104. +
  27105. + /* disable the connection from camera to encoder */
  27106. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
  27107. + if (!ret && dev->capture.camera_port != dev->capture.port) {
  27108. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27109. + "disabling port\n");
  27110. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
  27111. + } else if (dev->capture.camera_port != dev->capture.port) {
  27112. + v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
  27113. + ret);
  27114. + }
  27115. +
  27116. + if (disable_camera(dev) < 0)
  27117. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
  27118. +}
  27119. +
  27120. +static void bm2835_mmal_lock(struct vb2_queue *vq)
  27121. +{
  27122. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  27123. + mutex_lock(&dev->mutex);
  27124. +}
  27125. +
  27126. +static void bm2835_mmal_unlock(struct vb2_queue *vq)
  27127. +{
  27128. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  27129. + mutex_unlock(&dev->mutex);
  27130. +}
  27131. +
  27132. +static struct vb2_ops bm2835_mmal_video_qops = {
  27133. + .queue_setup = queue_setup,
  27134. + .buf_prepare = buffer_prepare,
  27135. + .buf_queue = buffer_queue,
  27136. + .start_streaming = start_streaming,
  27137. + .stop_streaming = stop_streaming,
  27138. + .wait_prepare = bm2835_mmal_unlock,
  27139. + .wait_finish = bm2835_mmal_lock,
  27140. +};
  27141. +
  27142. +/* ------------------------------------------------------------------
  27143. + IOCTL operations
  27144. + ------------------------------------------------------------------*/
  27145. +
  27146. +/* overlay ioctl */
  27147. +static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
  27148. + struct v4l2_fmtdesc *f)
  27149. +{
  27150. + struct mmal_fmt *fmt;
  27151. +
  27152. + if (f->index >= ARRAY_SIZE(formats))
  27153. + return -EINVAL;
  27154. +
  27155. + fmt = &formats[f->index];
  27156. +
  27157. + strlcpy(f->description, fmt->name, sizeof(f->description));
  27158. + f->pixelformat = fmt->fourcc;
  27159. + f->flags = fmt->flags;
  27160. +
  27161. + return 0;
  27162. +}
  27163. +
  27164. +static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
  27165. + struct v4l2_format *f)
  27166. +{
  27167. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27168. +
  27169. + f->fmt.win = dev->overlay;
  27170. +
  27171. + return 0;
  27172. +}
  27173. +
  27174. +static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
  27175. + struct v4l2_format *f)
  27176. +{
  27177. + /* Only support one format so get the current one. */
  27178. + vidioc_g_fmt_vid_overlay(file, priv, f);
  27179. +
  27180. + /* todo: allow the size and/or offset to be changed. */
  27181. + return 0;
  27182. +}
  27183. +
  27184. +static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
  27185. + struct v4l2_format *f)
  27186. +{
  27187. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27188. +
  27189. + vidioc_try_fmt_vid_overlay(file, priv, f);
  27190. +
  27191. + dev->overlay = f->fmt.win;
  27192. +
  27193. + /* todo: program the preview port parameters */
  27194. + return 0;
  27195. +}
  27196. +
  27197. +static int vidioc_overlay(struct file *file, void *f, unsigned int on)
  27198. +{
  27199. + int ret;
  27200. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27201. + struct vchiq_mmal_port *src;
  27202. + struct vchiq_mmal_port *dst;
  27203. + struct mmal_parameter_displayregion prev_config = {
  27204. + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
  27205. + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
  27206. + .layer = PREVIEW_LAYER,
  27207. + .alpha = 255,
  27208. + .fullscreen = 0,
  27209. + .dest_rect = {
  27210. + .x = dev->overlay.w.left,
  27211. + .y = dev->overlay.w.top,
  27212. + .width = dev->overlay.w.width,
  27213. + .height = dev->overlay.w.height,
  27214. + },
  27215. + };
  27216. +
  27217. + if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
  27218. + (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
  27219. + return 0; /* already in requested state */
  27220. +
  27221. + src =
  27222. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27223. + output[MMAL_CAMERA_PORT_PREVIEW];
  27224. +
  27225. + if (!on) {
  27226. + /* disconnect preview ports and disable component */
  27227. + ret = vchiq_mmal_port_disable(dev->instance, src);
  27228. + if (!ret)
  27229. + ret =
  27230. + vchiq_mmal_port_connect_tunnel(dev->instance, src,
  27231. + NULL);
  27232. + if (ret >= 0)
  27233. + ret = vchiq_mmal_component_disable(
  27234. + dev->instance,
  27235. + dev->component[MMAL_COMPONENT_PREVIEW]);
  27236. +
  27237. + disable_camera(dev);
  27238. + return ret;
  27239. + }
  27240. +
  27241. + /* set preview port format and connect it to output */
  27242. + dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
  27243. +
  27244. + ret = vchiq_mmal_port_set_format(dev->instance, src);
  27245. + if (ret < 0)
  27246. + goto error;
  27247. +
  27248. + ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
  27249. + MMAL_PARAMETER_DISPLAYREGION,
  27250. + &prev_config, sizeof(prev_config));
  27251. + if (ret < 0)
  27252. + goto error;
  27253. +
  27254. + if (enable_camera(dev) < 0)
  27255. + goto error;
  27256. +
  27257. + ret = vchiq_mmal_component_enable(
  27258. + dev->instance,
  27259. + dev->component[MMAL_COMPONENT_PREVIEW]);
  27260. + if (ret < 0)
  27261. + goto error;
  27262. +
  27263. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
  27264. + src, dst);
  27265. + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
  27266. + if (!ret)
  27267. + ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
  27268. +error:
  27269. + return ret;
  27270. +}
  27271. +
  27272. +static int vidioc_g_fbuf(struct file *file, void *fh,
  27273. + struct v4l2_framebuffer *a)
  27274. +{
  27275. + /* The video overlay must stay within the framebuffer and can't be
  27276. + positioned independently. */
  27277. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27278. + struct vchiq_mmal_port *preview_port =
  27279. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27280. + output[MMAL_CAMERA_PORT_PREVIEW];
  27281. + a->flags = V4L2_FBUF_FLAG_OVERLAY;
  27282. + a->fmt.width = preview_port->es.video.width;
  27283. + a->fmt.height = preview_port->es.video.height;
  27284. + a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
  27285. + a->fmt.bytesperline = (preview_port->es.video.width * 3)>>1;
  27286. + a->fmt.sizeimage = (preview_port->es.video.width *
  27287. + preview_port->es.video.height * 3)>>1;
  27288. + a->fmt.colorspace = V4L2_COLORSPACE_JPEG;
  27289. +
  27290. + return 0;
  27291. +}
  27292. +
  27293. +/* input ioctls */
  27294. +static int vidioc_enum_input(struct file *file, void *priv,
  27295. + struct v4l2_input *inp)
  27296. +{
  27297. + /* only a single camera input */
  27298. + if (inp->index != 0)
  27299. + return -EINVAL;
  27300. +
  27301. + inp->type = V4L2_INPUT_TYPE_CAMERA;
  27302. + sprintf(inp->name, "Camera %u", inp->index);
  27303. + return 0;
  27304. +}
  27305. +
  27306. +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  27307. +{
  27308. + *i = 0;
  27309. + return 0;
  27310. +}
  27311. +
  27312. +static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  27313. +{
  27314. + if (i != 0)
  27315. + return -EINVAL;
  27316. +
  27317. + return 0;
  27318. +}
  27319. +
  27320. +/* capture ioctls */
  27321. +static int vidioc_querycap(struct file *file, void *priv,
  27322. + struct v4l2_capability *cap)
  27323. +{
  27324. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27325. + u32 major;
  27326. + u32 minor;
  27327. +
  27328. + vchiq_mmal_version(dev->instance, &major, &minor);
  27329. +
  27330. + strcpy(cap->driver, "bm2835 mmal");
  27331. + snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
  27332. + major, minor);
  27333. +
  27334. + snprintf(cap->bus_info, sizeof(cap->bus_info),
  27335. + "platform:%s", dev->v4l2_dev.name);
  27336. + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
  27337. + V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
  27338. + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  27339. +
  27340. + return 0;
  27341. +}
  27342. +
  27343. +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  27344. + struct v4l2_fmtdesc *f)
  27345. +{
  27346. + struct mmal_fmt *fmt;
  27347. +
  27348. + if (f->index >= ARRAY_SIZE(formats))
  27349. + return -EINVAL;
  27350. +
  27351. + fmt = &formats[f->index];
  27352. +
  27353. + strlcpy(f->description, fmt->name, sizeof(f->description));
  27354. + f->pixelformat = fmt->fourcc;
  27355. + f->flags = fmt->flags;
  27356. +
  27357. + return 0;
  27358. +}
  27359. +
  27360. +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  27361. + struct v4l2_format *f)
  27362. +{
  27363. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27364. +
  27365. + f->fmt.pix.width = dev->capture.width;
  27366. + f->fmt.pix.height = dev->capture.height;
  27367. + f->fmt.pix.field = V4L2_FIELD_NONE;
  27368. + f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
  27369. + f->fmt.pix.bytesperline = dev->capture.stride;
  27370. + f->fmt.pix.sizeimage = dev->capture.buffersize;
  27371. +
  27372. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_RGB24)
  27373. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  27374. + else
  27375. + f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  27376. + f->fmt.pix.priv = 0;
  27377. +
  27378. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  27379. + __func__);
  27380. + return 0;
  27381. +}
  27382. +
  27383. +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  27384. + struct v4l2_format *f)
  27385. +{
  27386. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27387. + struct mmal_fmt *mfmt;
  27388. +
  27389. + mfmt = get_format(f);
  27390. + if (!mfmt) {
  27391. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27392. + "Fourcc format (0x%08x) unknown.\n",
  27393. + f->fmt.pix.pixelformat);
  27394. + f->fmt.pix.pixelformat = formats[0].fourcc;
  27395. + mfmt = get_format(f);
  27396. + }
  27397. +
  27398. + f->fmt.pix.field = V4L2_FIELD_NONE;
  27399. +
  27400. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27401. + "Clipping/aligning %dx%d format %08X\n",
  27402. + f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  27403. +
  27404. + v4l_bound_align_image(&f->fmt.pix.width, MIN_WIDTH, MAX_WIDTH, 1,
  27405. + &f->fmt.pix.height, MIN_HEIGHT, MAX_HEIGHT, 1, 0);
  27406. + f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth)>>3;
  27407. +
  27408. + /* Image buffer has to be padded to allow for alignment, even though
  27409. + * we then remove that padding before delivering the buffer.
  27410. + */
  27411. + f->fmt.pix.sizeimage = ((f->fmt.pix.height+15)&~15) *
  27412. + (((f->fmt.pix.width+31)&~31) * mfmt->depth) >> 3;
  27413. +
  27414. + if ((mfmt->flags & V4L2_FMT_FLAG_COMPRESSED) &&
  27415. + f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
  27416. + f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
  27417. +
  27418. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_RGB24)
  27419. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  27420. + else
  27421. + f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  27422. + f->fmt.pix.priv = 0;
  27423. +
  27424. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27425. + "Now %dx%d format %08X\n",
  27426. + f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  27427. +
  27428. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  27429. + __func__);
  27430. + return 0;
  27431. +}
  27432. +
  27433. +static int mmal_setup_components(struct bm2835_mmal_dev *dev,
  27434. + struct v4l2_format *f)
  27435. +{
  27436. + int ret;
  27437. + struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
  27438. + struct vchiq_mmal_component *encode_component = NULL;
  27439. + struct mmal_fmt *mfmt = get_format(f);
  27440. +
  27441. + BUG_ON(!mfmt);
  27442. +
  27443. + if (dev->capture.encode_component) {
  27444. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27445. + "vid_cap - disconnect previous tunnel\n");
  27446. +
  27447. + /* Disconnect any previous connection */
  27448. + vchiq_mmal_port_connect_tunnel(dev->instance,
  27449. + dev->capture.camera_port, NULL);
  27450. + dev->capture.camera_port = NULL;
  27451. + ret = vchiq_mmal_component_disable(dev->instance,
  27452. + dev->capture.
  27453. + encode_component);
  27454. + if (ret)
  27455. + v4l2_err(&dev->v4l2_dev,
  27456. + "Failed to disable encode component %d\n",
  27457. + ret);
  27458. +
  27459. + dev->capture.encode_component = NULL;
  27460. + }
  27461. + /* format dependant port setup */
  27462. + switch (mfmt->mmal_component) {
  27463. + case MMAL_COMPONENT_CAMERA:
  27464. + /* Make a further decision on port based on resolution */
  27465. + if (f->fmt.pix.width <= max_video_width
  27466. + && f->fmt.pix.height <= max_video_height)
  27467. + camera_port = port =
  27468. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27469. + output[MMAL_CAMERA_PORT_VIDEO];
  27470. + else
  27471. + camera_port = port =
  27472. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27473. + output[MMAL_CAMERA_PORT_CAPTURE];
  27474. + break;
  27475. + case MMAL_COMPONENT_IMAGE_ENCODE:
  27476. + encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
  27477. + port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  27478. + camera_port =
  27479. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27480. + output[MMAL_CAMERA_PORT_CAPTURE];
  27481. + break;
  27482. + case MMAL_COMPONENT_VIDEO_ENCODE:
  27483. + encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
  27484. + port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  27485. + camera_port =
  27486. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27487. + output[MMAL_CAMERA_PORT_VIDEO];
  27488. + break;
  27489. + default:
  27490. + break;
  27491. + }
  27492. +
  27493. + if (!port)
  27494. + return -EINVAL;
  27495. +
  27496. + if (encode_component)
  27497. + camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
  27498. + else
  27499. + camera_port->format.encoding = mfmt->mmal;
  27500. +
  27501. + camera_port->format.encoding_variant = 0;
  27502. + camera_port->es.video.width = f->fmt.pix.width;
  27503. + camera_port->es.video.height = f->fmt.pix.height;
  27504. + camera_port->es.video.crop.x = 0;
  27505. + camera_port->es.video.crop.y = 0;
  27506. + camera_port->es.video.crop.width = f->fmt.pix.width;
  27507. + camera_port->es.video.crop.height = f->fmt.pix.height;
  27508. + camera_port->es.video.frame_rate.num = 0;
  27509. + camera_port->es.video.frame_rate.den = 1;
  27510. + camera_port->es.video.color_space = MMAL_COLOR_SPACE_JPEG_JFIF;
  27511. +
  27512. + ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
  27513. +
  27514. + if (!ret
  27515. + && camera_port ==
  27516. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27517. + output[MMAL_CAMERA_PORT_VIDEO]) {
  27518. + bool overlay_enabled =
  27519. + !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
  27520. + struct vchiq_mmal_port *preview_port =
  27521. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27522. + output[MMAL_CAMERA_PORT_PREVIEW];
  27523. + /* Preview and encode ports need to match on resolution */
  27524. + if (overlay_enabled) {
  27525. + /* Need to disable the overlay before we can update
  27526. + * the resolution
  27527. + */
  27528. + ret =
  27529. + vchiq_mmal_port_disable(dev->instance,
  27530. + preview_port);
  27531. + if (!ret)
  27532. + ret =
  27533. + vchiq_mmal_port_connect_tunnel(
  27534. + dev->instance,
  27535. + preview_port,
  27536. + NULL);
  27537. + }
  27538. + preview_port->es.video.width = f->fmt.pix.width;
  27539. + preview_port->es.video.height = f->fmt.pix.height;
  27540. + preview_port->es.video.crop.x = 0;
  27541. + preview_port->es.video.crop.y = 0;
  27542. + preview_port->es.video.crop.width = f->fmt.pix.width;
  27543. + preview_port->es.video.crop.height = f->fmt.pix.height;
  27544. + preview_port->es.video.frame_rate.num =
  27545. + dev->capture.timeperframe.denominator;
  27546. + preview_port->es.video.frame_rate.den =
  27547. + dev->capture.timeperframe.numerator;
  27548. + ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
  27549. + if (overlay_enabled) {
  27550. + ret = vchiq_mmal_port_connect_tunnel(
  27551. + dev->instance,
  27552. + preview_port,
  27553. + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
  27554. + if (!ret)
  27555. + ret = vchiq_mmal_port_enable(dev->instance,
  27556. + preview_port,
  27557. + NULL);
  27558. + }
  27559. + }
  27560. +
  27561. + if (ret) {
  27562. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27563. + "%s failed to set format %dx%d %08X\n", __func__,
  27564. + f->fmt.pix.width, f->fmt.pix.height,
  27565. + f->fmt.pix.pixelformat);
  27566. + /* ensure capture is not going to be tried */
  27567. + dev->capture.port = NULL;
  27568. + } else {
  27569. + if (encode_component) {
  27570. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27571. + "vid_cap - set up encode comp\n");
  27572. +
  27573. + /* configure buffering */
  27574. + camera_port->current_buffer.size =
  27575. + camera_port->recommended_buffer.size;
  27576. + camera_port->current_buffer.num =
  27577. + camera_port->recommended_buffer.num;
  27578. +
  27579. + ret =
  27580. + vchiq_mmal_port_connect_tunnel(
  27581. + dev->instance,
  27582. + camera_port,
  27583. + &encode_component->input[0]);
  27584. + if (ret) {
  27585. + v4l2_dbg(1, bcm2835_v4l2_debug,
  27586. + &dev->v4l2_dev,
  27587. + "%s failed to create connection\n",
  27588. + __func__);
  27589. + /* ensure capture is not going to be tried */
  27590. + dev->capture.port = NULL;
  27591. + } else {
  27592. + port->es.video.width = f->fmt.pix.width;
  27593. + port->es.video.height = f->fmt.pix.height;
  27594. + port->es.video.crop.x = 0;
  27595. + port->es.video.crop.y = 0;
  27596. + port->es.video.crop.width = f->fmt.pix.width;
  27597. + port->es.video.crop.height = f->fmt.pix.height;
  27598. + port->es.video.frame_rate.num =
  27599. + dev->capture.timeperframe.denominator;
  27600. + port->es.video.frame_rate.den =
  27601. + dev->capture.timeperframe.numerator;
  27602. +
  27603. + port->format.encoding = mfmt->mmal;
  27604. + port->format.encoding_variant = 0;
  27605. + /* Set any encoding specific parameters */
  27606. + switch (mfmt->mmal_component) {
  27607. + case MMAL_COMPONENT_VIDEO_ENCODE:
  27608. + port->format.bitrate =
  27609. + dev->capture.encode_bitrate;
  27610. + break;
  27611. + case MMAL_COMPONENT_IMAGE_ENCODE:
  27612. + /* Could set EXIF parameters here */
  27613. + break;
  27614. + default:
  27615. + break;
  27616. + }
  27617. + ret = vchiq_mmal_port_set_format(dev->instance,
  27618. + port);
  27619. + if (ret)
  27620. + v4l2_dbg(1, bcm2835_v4l2_debug,
  27621. + &dev->v4l2_dev,
  27622. + "%s failed to set format %dx%d fmt %08X\n",
  27623. + __func__,
  27624. + f->fmt.pix.width,
  27625. + f->fmt.pix.height,
  27626. + f->fmt.pix.pixelformat
  27627. + );
  27628. + }
  27629. +
  27630. + if (!ret) {
  27631. + ret = vchiq_mmal_component_enable(
  27632. + dev->instance,
  27633. + encode_component);
  27634. + if (ret) {
  27635. + v4l2_dbg(1, bcm2835_v4l2_debug,
  27636. + &dev->v4l2_dev,
  27637. + "%s Failed to enable encode components\n",
  27638. + __func__);
  27639. + }
  27640. + }
  27641. + if (!ret) {
  27642. + /* configure buffering */
  27643. + port->current_buffer.num = 1;
  27644. + port->current_buffer.size =
  27645. + f->fmt.pix.sizeimage;
  27646. + if (port->format.encoding ==
  27647. + MMAL_ENCODING_JPEG) {
  27648. + v4l2_dbg(1, bcm2835_v4l2_debug,
  27649. + &dev->v4l2_dev,
  27650. + "JPG - buf size now %d was %d\n",
  27651. + f->fmt.pix.sizeimage,
  27652. + port->current_buffer.size);
  27653. + port->current_buffer.size =
  27654. + (f->fmt.pix.sizeimage <
  27655. + (100 << 10))
  27656. + ? (100 << 10) : f->fmt.pix.
  27657. + sizeimage;
  27658. + }
  27659. + v4l2_dbg(1, bcm2835_v4l2_debug,
  27660. + &dev->v4l2_dev,
  27661. + "vid_cap - cur_buf.size set to %d\n",
  27662. + f->fmt.pix.sizeimage);
  27663. + port->current_buffer.alignment = 0;
  27664. + }
  27665. + } else {
  27666. + /* configure buffering */
  27667. + camera_port->current_buffer.num = 1;
  27668. + camera_port->current_buffer.size = f->fmt.pix.sizeimage;
  27669. + camera_port->current_buffer.alignment = 0;
  27670. + }
  27671. +
  27672. + if (!ret) {
  27673. + dev->capture.fmt = mfmt;
  27674. + dev->capture.stride = f->fmt.pix.bytesperline;
  27675. + dev->capture.width = camera_port->es.video.crop.width;
  27676. + dev->capture.height = camera_port->es.video.crop.height;
  27677. + dev->capture.buffersize = port->current_buffer.size;
  27678. +
  27679. + /* select port for capture */
  27680. + dev->capture.port = port;
  27681. + dev->capture.camera_port = camera_port;
  27682. + dev->capture.encode_component = encode_component;
  27683. + v4l2_dbg(1, bcm2835_v4l2_debug,
  27684. + &dev->v4l2_dev,
  27685. + "Set dev->capture.fmt %08X, %dx%d, stride %d, size %d",
  27686. + port->format.encoding,
  27687. + dev->capture.width, dev->capture.height,
  27688. + dev->capture.stride, dev->capture.buffersize);
  27689. + }
  27690. + }
  27691. +
  27692. + /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
  27693. + return ret;
  27694. +}
  27695. +
  27696. +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  27697. + struct v4l2_format *f)
  27698. +{
  27699. + int ret;
  27700. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27701. + struct mmal_fmt *mfmt;
  27702. +
  27703. + /* try the format to set valid parameters */
  27704. + ret = vidioc_try_fmt_vid_cap(file, priv, f);
  27705. + if (ret) {
  27706. + v4l2_err(&dev->v4l2_dev,
  27707. + "vid_cap - vidioc_try_fmt_vid_cap failed\n");
  27708. + return ret;
  27709. + }
  27710. +
  27711. + /* if a capture is running refuse to set format */
  27712. + if (vb2_is_busy(&dev->capture.vb_vidq)) {
  27713. + v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
  27714. + return -EBUSY;
  27715. + }
  27716. +
  27717. + /* If the format is unsupported v4l2 says we should switch to
  27718. + * a supported one and not return an error. */
  27719. + mfmt = get_format(f);
  27720. + if (!mfmt) {
  27721. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  27722. + "Fourcc format (0x%08x) unknown.\n",
  27723. + f->fmt.pix.pixelformat);
  27724. + f->fmt.pix.pixelformat = formats[0].fourcc;
  27725. + mfmt = get_format(f);
  27726. + }
  27727. +
  27728. + ret = mmal_setup_components(dev, f);
  27729. + if (ret != 0) {
  27730. + v4l2_err(&dev->v4l2_dev,
  27731. + "%s: failed to setup mmal components: %d\n",
  27732. + __func__, ret);
  27733. + ret = -EINVAL;
  27734. + }
  27735. +
  27736. + return ret;
  27737. +}
  27738. +
  27739. +int vidioc_enum_framesizes(struct file *file, void *fh,
  27740. + struct v4l2_frmsizeenum *fsize)
  27741. +{
  27742. + static const struct v4l2_frmsize_stepwise sizes = {
  27743. + MIN_WIDTH, MAX_WIDTH, 2,
  27744. + MIN_HEIGHT, MAX_HEIGHT, 2
  27745. + };
  27746. + int i;
  27747. +
  27748. + if (fsize->index)
  27749. + return -EINVAL;
  27750. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  27751. + if (formats[i].fourcc == fsize->pixel_format)
  27752. + break;
  27753. + if (i == ARRAY_SIZE(formats))
  27754. + return -EINVAL;
  27755. + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
  27756. + fsize->stepwise = sizes;
  27757. + return 0;
  27758. +}
  27759. +
  27760. +/* timeperframe is arbitrary and continous */
  27761. +static int vidioc_enum_frameintervals(struct file *file, void *priv,
  27762. + struct v4l2_frmivalenum *fival)
  27763. +{
  27764. + int i;
  27765. +
  27766. + if (fival->index)
  27767. + return -EINVAL;
  27768. +
  27769. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  27770. + if (formats[i].fourcc == fival->pixel_format)
  27771. + break;
  27772. + if (i == ARRAY_SIZE(formats))
  27773. + return -EINVAL;
  27774. +
  27775. + /* regarding width & height - we support any within range */
  27776. + if (fival->width < MIN_WIDTH || fival->width > MAX_WIDTH ||
  27777. + fival->height < MIN_HEIGHT || fival->height > MAX_HEIGHT)
  27778. + return -EINVAL;
  27779. +
  27780. + fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
  27781. +
  27782. + /* fill in stepwise (step=1.0 is requred by V4L2 spec) */
  27783. + fival->stepwise.min = tpf_min;
  27784. + fival->stepwise.max = tpf_max;
  27785. + fival->stepwise.step = (struct v4l2_fract) {1, 1};
  27786. +
  27787. + return 0;
  27788. +}
  27789. +
  27790. +static int vidioc_g_parm(struct file *file, void *priv,
  27791. + struct v4l2_streamparm *parm)
  27792. +{
  27793. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27794. +
  27795. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  27796. + return -EINVAL;
  27797. +
  27798. + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  27799. + parm->parm.capture.timeperframe = dev->capture.timeperframe;
  27800. + parm->parm.capture.readbuffers = 1;
  27801. + return 0;
  27802. +}
  27803. +
  27804. +#define FRACT_CMP(a, OP, b) \
  27805. + ((u64)(a).numerator * (b).denominator OP \
  27806. + (u64)(b).numerator * (a).denominator)
  27807. +
  27808. +static int vidioc_s_parm(struct file *file, void *priv,
  27809. + struct v4l2_streamparm *parm)
  27810. +{
  27811. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  27812. + struct v4l2_fract tpf;
  27813. + struct mmal_parameter_rational fps_param;
  27814. +
  27815. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  27816. + return -EINVAL;
  27817. +
  27818. + tpf = parm->parm.capture.timeperframe;
  27819. +
  27820. + /* tpf: {*, 0} resets timing; clip to [min, max]*/
  27821. + tpf = tpf.denominator ? tpf : tpf_default;
  27822. + tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
  27823. + tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
  27824. +
  27825. + dev->capture.timeperframe = tpf;
  27826. + parm->parm.capture.timeperframe = tpf;
  27827. + parm->parm.capture.readbuffers = 1;
  27828. +
  27829. + fps_param.num = 0; /* Select variable fps, and then use
  27830. + * FPS_RANGE to select the actual limits.
  27831. + */
  27832. + fps_param.den = 1;
  27833. + set_framerate_params(dev);
  27834. +
  27835. + return 0;
  27836. +}
  27837. +
  27838. +static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
  27839. + /* overlay */
  27840. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  27841. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  27842. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  27843. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  27844. + .vidioc_overlay = vidioc_overlay,
  27845. + .vidioc_g_fbuf = vidioc_g_fbuf,
  27846. +
  27847. + /* inputs */
  27848. + .vidioc_enum_input = vidioc_enum_input,
  27849. + .vidioc_g_input = vidioc_g_input,
  27850. + .vidioc_s_input = vidioc_s_input,
  27851. +
  27852. + /* capture */
  27853. + .vidioc_querycap = vidioc_querycap,
  27854. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  27855. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  27856. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  27857. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  27858. +
  27859. + /* buffer management */
  27860. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  27861. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  27862. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  27863. + .vidioc_querybuf = vb2_ioctl_querybuf,
  27864. + .vidioc_qbuf = vb2_ioctl_qbuf,
  27865. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  27866. + .vidioc_enum_framesizes = vidioc_enum_framesizes,
  27867. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  27868. + .vidioc_g_parm = vidioc_g_parm,
  27869. + .vidioc_s_parm = vidioc_s_parm,
  27870. + .vidioc_streamon = vb2_ioctl_streamon,
  27871. + .vidioc_streamoff = vb2_ioctl_streamoff,
  27872. +
  27873. + .vidioc_log_status = v4l2_ctrl_log_status,
  27874. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  27875. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  27876. +};
  27877. +
  27878. +static const struct v4l2_ioctl_ops camera0_ioctl_ops_gstreamer = {
  27879. + /* overlay */
  27880. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  27881. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  27882. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  27883. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  27884. + .vidioc_overlay = vidioc_overlay,
  27885. + .vidioc_g_fbuf = vidioc_g_fbuf,
  27886. +
  27887. + /* inputs */
  27888. + .vidioc_enum_input = vidioc_enum_input,
  27889. + .vidioc_g_input = vidioc_g_input,
  27890. + .vidioc_s_input = vidioc_s_input,
  27891. +
  27892. + /* capture */
  27893. + .vidioc_querycap = vidioc_querycap,
  27894. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  27895. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  27896. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  27897. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  27898. +
  27899. + /* buffer management */
  27900. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  27901. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  27902. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  27903. + .vidioc_querybuf = vb2_ioctl_querybuf,
  27904. + .vidioc_qbuf = vb2_ioctl_qbuf,
  27905. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  27906. + /* Remove this function ptr to fix gstreamer bug
  27907. + .vidioc_enum_framesizes = vidioc_enum_framesizes, */
  27908. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  27909. + .vidioc_g_parm = vidioc_g_parm,
  27910. + .vidioc_s_parm = vidioc_s_parm,
  27911. + .vidioc_streamon = vb2_ioctl_streamon,
  27912. + .vidioc_streamoff = vb2_ioctl_streamoff,
  27913. +
  27914. + .vidioc_log_status = v4l2_ctrl_log_status,
  27915. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  27916. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  27917. +};
  27918. +
  27919. +/* ------------------------------------------------------------------
  27920. + Driver init/finalise
  27921. + ------------------------------------------------------------------*/
  27922. +
  27923. +static const struct v4l2_file_operations camera0_fops = {
  27924. + .owner = THIS_MODULE,
  27925. + .open = v4l2_fh_open,
  27926. + .release = vb2_fop_release,
  27927. + .read = vb2_fop_read,
  27928. + .poll = vb2_fop_poll,
  27929. + .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
  27930. + .mmap = vb2_fop_mmap,
  27931. +};
  27932. +
  27933. +static struct video_device vdev_template = {
  27934. + .name = "camera0",
  27935. + .fops = &camera0_fops,
  27936. + .ioctl_ops = &camera0_ioctl_ops,
  27937. + .release = video_device_release_empty,
  27938. +};
  27939. +
  27940. +static int set_camera_parameters(struct vchiq_mmal_instance *instance,
  27941. + struct vchiq_mmal_component *camera)
  27942. +{
  27943. + int ret;
  27944. + struct mmal_parameter_camera_config cam_config = {
  27945. + .max_stills_w = MAX_WIDTH,
  27946. + .max_stills_h = MAX_HEIGHT,
  27947. + .stills_yuv422 = 1,
  27948. + .one_shot_stills = 1,
  27949. + .max_preview_video_w = (max_video_width > 1920) ?
  27950. + max_video_width : 1920,
  27951. + .max_preview_video_h = (max_video_height > 1088) ?
  27952. + max_video_height : 1088,
  27953. + .num_preview_video_frames = 3,
  27954. + .stills_capture_circular_buffer_height = 0,
  27955. + .fast_preview_resume = 0,
  27956. + .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
  27957. + };
  27958. +
  27959. + ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
  27960. + MMAL_PARAMETER_CAMERA_CONFIG,
  27961. + &cam_config, sizeof(cam_config));
  27962. + return ret;
  27963. +}
  27964. +
  27965. +/* MMAL instance and component init */
  27966. +static int __init mmal_init(struct bm2835_mmal_dev *dev)
  27967. +{
  27968. + int ret;
  27969. + struct mmal_es_format *format;
  27970. + u32 bool_true = 1;
  27971. +
  27972. + ret = vchiq_mmal_init(&dev->instance);
  27973. + if (ret < 0)
  27974. + return ret;
  27975. +
  27976. + /* get the camera component ready */
  27977. + ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
  27978. + &dev->component[MMAL_COMPONENT_CAMERA]);
  27979. + if (ret < 0)
  27980. + goto unreg_mmal;
  27981. +
  27982. + if (dev->component[MMAL_COMPONENT_CAMERA]->outputs <
  27983. + MMAL_CAMERA_PORT_COUNT) {
  27984. + ret = -EINVAL;
  27985. + goto unreg_camera;
  27986. + }
  27987. +
  27988. + ret = set_camera_parameters(dev->instance,
  27989. + dev->component[MMAL_COMPONENT_CAMERA]);
  27990. + if (ret < 0)
  27991. + goto unreg_camera;
  27992. +
  27993. + format =
  27994. + &dev->component[MMAL_COMPONENT_CAMERA]->
  27995. + output[MMAL_CAMERA_PORT_PREVIEW].format;
  27996. +
  27997. + format->encoding = MMAL_ENCODING_OPAQUE;
  27998. + format->encoding_variant = MMAL_ENCODING_I420;
  27999. +
  28000. + format->es->video.width = 1024;
  28001. + format->es->video.height = 768;
  28002. + format->es->video.crop.x = 0;
  28003. + format->es->video.crop.y = 0;
  28004. + format->es->video.crop.width = 1024;
  28005. + format->es->video.crop.height = 768;
  28006. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  28007. + format->es->video.frame_rate.den = 1;
  28008. +
  28009. + format =
  28010. + &dev->component[MMAL_COMPONENT_CAMERA]->
  28011. + output[MMAL_CAMERA_PORT_VIDEO].format;
  28012. +
  28013. + format->encoding = MMAL_ENCODING_OPAQUE;
  28014. + format->encoding_variant = MMAL_ENCODING_I420;
  28015. +
  28016. + format->es->video.width = 1024;
  28017. + format->es->video.height = 768;
  28018. + format->es->video.crop.x = 0;
  28019. + format->es->video.crop.y = 0;
  28020. + format->es->video.crop.width = 1024;
  28021. + format->es->video.crop.height = 768;
  28022. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  28023. + format->es->video.frame_rate.den = 1;
  28024. +
  28025. + vchiq_mmal_port_parameter_set(dev->instance,
  28026. + &dev->component[MMAL_COMPONENT_CAMERA]->
  28027. + output[MMAL_CAMERA_PORT_VIDEO],
  28028. + MMAL_PARAMETER_NO_IMAGE_PADDING,
  28029. + &bool_true, sizeof(bool_true));
  28030. +
  28031. + format =
  28032. + &dev->component[MMAL_COMPONENT_CAMERA]->
  28033. + output[MMAL_CAMERA_PORT_CAPTURE].format;
  28034. +
  28035. + format->encoding = MMAL_ENCODING_OPAQUE;
  28036. +
  28037. + format->es->video.width = 2592;
  28038. + format->es->video.height = 1944;
  28039. + format->es->video.crop.x = 0;
  28040. + format->es->video.crop.y = 0;
  28041. + format->es->video.crop.width = 2592;
  28042. + format->es->video.crop.height = 1944;
  28043. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  28044. + format->es->video.frame_rate.den = 1;
  28045. +
  28046. + dev->capture.width = format->es->video.width;
  28047. + dev->capture.height = format->es->video.height;
  28048. + dev->capture.fmt = &formats[0];
  28049. + dev->capture.encode_component = NULL;
  28050. + dev->capture.timeperframe = tpf_default;
  28051. + dev->capture.enc_profile = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH;
  28052. + dev->capture.enc_level = V4L2_MPEG_VIDEO_H264_LEVEL_4_0;
  28053. +
  28054. + vchiq_mmal_port_parameter_set(dev->instance,
  28055. + &dev->component[MMAL_COMPONENT_CAMERA]->
  28056. + output[MMAL_CAMERA_PORT_CAPTURE],
  28057. + MMAL_PARAMETER_NO_IMAGE_PADDING,
  28058. + &bool_true, sizeof(bool_true));
  28059. +
  28060. + /* get the preview component ready */
  28061. + ret = vchiq_mmal_component_init(
  28062. + dev->instance, "ril.video_render",
  28063. + &dev->component[MMAL_COMPONENT_PREVIEW]);
  28064. + if (ret < 0)
  28065. + goto unreg_camera;
  28066. +
  28067. + if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
  28068. + ret = -EINVAL;
  28069. + pr_debug("too few input ports %d needed %d\n",
  28070. + dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
  28071. + goto unreg_preview;
  28072. + }
  28073. +
  28074. + /* get the image encoder component ready */
  28075. + ret = vchiq_mmal_component_init(
  28076. + dev->instance, "ril.image_encode",
  28077. + &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  28078. + if (ret < 0)
  28079. + goto unreg_preview;
  28080. +
  28081. + if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
  28082. + ret = -EINVAL;
  28083. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  28084. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
  28085. + 1);
  28086. + goto unreg_image_encoder;
  28087. + }
  28088. +
  28089. + /* get the video encoder component ready */
  28090. + ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
  28091. + &dev->
  28092. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  28093. + if (ret < 0)
  28094. + goto unreg_image_encoder;
  28095. +
  28096. + if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
  28097. + ret = -EINVAL;
  28098. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  28099. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
  28100. + 1);
  28101. + goto unreg_vid_encoder;
  28102. + }
  28103. +
  28104. + {
  28105. + struct vchiq_mmal_port *encoder_port =
  28106. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  28107. + encoder_port->format.encoding = MMAL_ENCODING_H264;
  28108. + ret = vchiq_mmal_port_set_format(dev->instance,
  28109. + encoder_port);
  28110. + }
  28111. +
  28112. + {
  28113. + unsigned int enable = 1;
  28114. + vchiq_mmal_port_parameter_set(
  28115. + dev->instance,
  28116. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  28117. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  28118. + &enable, sizeof(enable));
  28119. +
  28120. + vchiq_mmal_port_parameter_set(dev->instance,
  28121. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  28122. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  28123. + &enable,
  28124. + sizeof(enable));
  28125. + }
  28126. + ret = bm2835_mmal_set_all_camera_controls(dev);
  28127. + if (ret < 0)
  28128. + goto unreg_vid_encoder;
  28129. +
  28130. + return 0;
  28131. +
  28132. +unreg_vid_encoder:
  28133. + pr_err("Cleanup: Destroy video encoder\n");
  28134. + vchiq_mmal_component_finalise(
  28135. + dev->instance,
  28136. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
  28137. +
  28138. +unreg_image_encoder:
  28139. + pr_err("Cleanup: Destroy image encoder\n");
  28140. + vchiq_mmal_component_finalise(
  28141. + dev->instance,
  28142. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  28143. +
  28144. +unreg_preview:
  28145. + pr_err("Cleanup: Destroy video render\n");
  28146. + vchiq_mmal_component_finalise(dev->instance,
  28147. + dev->component[MMAL_COMPONENT_PREVIEW]);
  28148. +
  28149. +unreg_camera:
  28150. + pr_err("Cleanup: Destroy camera\n");
  28151. + vchiq_mmal_component_finalise(dev->instance,
  28152. + dev->component[MMAL_COMPONENT_CAMERA]);
  28153. +
  28154. +unreg_mmal:
  28155. + vchiq_mmal_finalise(dev->instance);
  28156. + return ret;
  28157. +}
  28158. +
  28159. +static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
  28160. + struct video_device *vfd)
  28161. +{
  28162. + int ret;
  28163. +
  28164. + *vfd = vdev_template;
  28165. + if (gst_v4l2src_is_broken) {
  28166. + v4l2_info(&dev->v4l2_dev,
  28167. + "Work-around for gstreamer issue is active.\n");
  28168. + vfd->ioctl_ops = &camera0_ioctl_ops_gstreamer;
  28169. + }
  28170. +
  28171. + vfd->v4l2_dev = &dev->v4l2_dev;
  28172. +
  28173. + vfd->lock = &dev->mutex;
  28174. +
  28175. + vfd->queue = &dev->capture.vb_vidq;
  28176. +
  28177. + /* video device needs to be able to access instance data */
  28178. + video_set_drvdata(vfd, dev);
  28179. +
  28180. + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  28181. + if (ret < 0)
  28182. + return ret;
  28183. +
  28184. + v4l2_info(vfd->v4l2_dev,
  28185. + "V4L2 device registered as %s - stills mode > %dx%d\n",
  28186. + video_device_node_name(vfd), max_video_width, max_video_height);
  28187. +
  28188. + return 0;
  28189. +}
  28190. +
  28191. +static struct v4l2_format default_v4l2_format = {
  28192. + .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
  28193. + .fmt.pix.width = 1024,
  28194. + .fmt.pix.bytesperline = 1024,
  28195. + .fmt.pix.height = 768,
  28196. + .fmt.pix.sizeimage = 1024*768,
  28197. +};
  28198. +
  28199. +static int __init bm2835_mmal_init(void)
  28200. +{
  28201. + int ret;
  28202. + struct bm2835_mmal_dev *dev;
  28203. + struct vb2_queue *q;
  28204. +
  28205. + dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
  28206. + if (!dev)
  28207. + return -ENOMEM;
  28208. +
  28209. + /* setup device defaults */
  28210. + dev->overlay.w.left = 150;
  28211. + dev->overlay.w.top = 50;
  28212. + dev->overlay.w.width = 1024;
  28213. + dev->overlay.w.height = 768;
  28214. + dev->overlay.clipcount = 0;
  28215. + dev->overlay.field = V4L2_FIELD_NONE;
  28216. +
  28217. + dev->capture.fmt = &formats[3]; /* JPEG */
  28218. +
  28219. + /* v4l device registration */
  28220. + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
  28221. + "%s", BM2835_MMAL_MODULE_NAME);
  28222. + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
  28223. + if (ret)
  28224. + goto free_dev;
  28225. +
  28226. + /* setup v4l controls */
  28227. + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
  28228. + if (ret < 0)
  28229. + goto unreg_dev;
  28230. + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
  28231. +
  28232. + /* mmal init */
  28233. + ret = mmal_init(dev);
  28234. + if (ret < 0)
  28235. + goto unreg_dev;
  28236. +
  28237. + /* initialize queue */
  28238. + q = &dev->capture.vb_vidq;
  28239. + memset(q, 0, sizeof(*q));
  28240. + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  28241. + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
  28242. + q->drv_priv = dev;
  28243. + q->buf_struct_size = sizeof(struct mmal_buffer);
  28244. + q->ops = &bm2835_mmal_video_qops;
  28245. + q->mem_ops = &vb2_vmalloc_memops;
  28246. + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  28247. + ret = vb2_queue_init(q);
  28248. + if (ret < 0)
  28249. + goto unreg_dev;
  28250. +
  28251. + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
  28252. + mutex_init(&dev->mutex);
  28253. +
  28254. + /* initialise video devices */
  28255. + ret = bm2835_mmal_init_device(dev, &dev->vdev);
  28256. + if (ret < 0)
  28257. + goto unreg_dev;
  28258. +
  28259. + /* Really want to call vidioc_s_fmt_vid_cap with the default
  28260. + * format, but currently the APIs don't join up.
  28261. + */
  28262. + ret = mmal_setup_components(dev, &default_v4l2_format);
  28263. + if (ret < 0) {
  28264. + v4l2_err(&dev->v4l2_dev,
  28265. + "%s: could not setup components\n", __func__);
  28266. + goto unreg_dev;
  28267. + }
  28268. +
  28269. + v4l2_info(&dev->v4l2_dev,
  28270. + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
  28271. + BM2835_MMAL_VERSION);
  28272. +
  28273. + gdev = dev;
  28274. + return 0;
  28275. +
  28276. +unreg_dev:
  28277. + v4l2_ctrl_handler_free(&dev->ctrl_handler);
  28278. + v4l2_device_unregister(&dev->v4l2_dev);
  28279. +
  28280. +free_dev:
  28281. + kfree(dev);
  28282. +
  28283. + v4l2_err(&dev->v4l2_dev,
  28284. + "%s: error %d while loading driver\n",
  28285. + BM2835_MMAL_MODULE_NAME, ret);
  28286. +
  28287. + return ret;
  28288. +}
  28289. +
  28290. +static void __exit bm2835_mmal_exit(void)
  28291. +{
  28292. + if (!gdev)
  28293. + return;
  28294. +
  28295. + v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
  28296. + video_device_node_name(&gdev->vdev));
  28297. +
  28298. + video_unregister_device(&gdev->vdev);
  28299. +
  28300. + if (gdev->capture.encode_component) {
  28301. + v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
  28302. + "mmal_exit - disconnect tunnel\n");
  28303. + vchiq_mmal_port_connect_tunnel(gdev->instance,
  28304. + gdev->capture.camera_port, NULL);
  28305. + vchiq_mmal_component_disable(gdev->instance,
  28306. + gdev->capture.encode_component);
  28307. + }
  28308. + vchiq_mmal_component_disable(gdev->instance,
  28309. + gdev->component[MMAL_COMPONENT_CAMERA]);
  28310. +
  28311. + vchiq_mmal_component_finalise(gdev->instance,
  28312. + gdev->
  28313. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  28314. +
  28315. + vchiq_mmal_component_finalise(gdev->instance,
  28316. + gdev->
  28317. + component[MMAL_COMPONENT_IMAGE_ENCODE]);
  28318. +
  28319. + vchiq_mmal_component_finalise(gdev->instance,
  28320. + gdev->component[MMAL_COMPONENT_PREVIEW]);
  28321. +
  28322. + vchiq_mmal_component_finalise(gdev->instance,
  28323. + gdev->component[MMAL_COMPONENT_CAMERA]);
  28324. +
  28325. + vchiq_mmal_finalise(gdev->instance);
  28326. +
  28327. + v4l2_ctrl_handler_free(&gdev->ctrl_handler);
  28328. +
  28329. + v4l2_device_unregister(&gdev->v4l2_dev);
  28330. +
  28331. + kfree(gdev);
  28332. +}
  28333. +
  28334. +module_init(bm2835_mmal_init);
  28335. +module_exit(bm2835_mmal_exit);
  28336. diff -Nur linux-3.18.6/drivers/media/platform/bcm2835/bcm2835-camera.h linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.h
  28337. --- linux-3.18.6/drivers/media/platform/bcm2835/bcm2835-camera.h 1970-01-01 01:00:00.000000000 +0100
  28338. +++ linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.h 2015-02-09 04:40:03.000000000 +0100
  28339. @@ -0,0 +1,126 @@
  28340. +/*
  28341. + * Broadcom BM2835 V4L2 driver
  28342. + *
  28343. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  28344. + *
  28345. + * This file is subject to the terms and conditions of the GNU General Public
  28346. + * License. See the file COPYING in the main directory of this archive
  28347. + * for more details.
  28348. + *
  28349. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  28350. + * Dave Stevenson <dsteve@broadcom.com>
  28351. + * Simon Mellor <simellor@broadcom.com>
  28352. + * Luke Diamand <luked@broadcom.com>
  28353. + *
  28354. + * core driver device
  28355. + */
  28356. +
  28357. +#define V4L2_CTRL_COUNT 28 /* number of v4l controls */
  28358. +
  28359. +enum {
  28360. + MMAL_COMPONENT_CAMERA = 0,
  28361. + MMAL_COMPONENT_PREVIEW,
  28362. + MMAL_COMPONENT_IMAGE_ENCODE,
  28363. + MMAL_COMPONENT_VIDEO_ENCODE,
  28364. + MMAL_COMPONENT_COUNT
  28365. +};
  28366. +
  28367. +enum {
  28368. + MMAL_CAMERA_PORT_PREVIEW = 0,
  28369. + MMAL_CAMERA_PORT_VIDEO,
  28370. + MMAL_CAMERA_PORT_CAPTURE,
  28371. + MMAL_CAMERA_PORT_COUNT
  28372. +};
  28373. +
  28374. +#define PREVIEW_LAYER 2
  28375. +
  28376. +extern int bcm2835_v4l2_debug;
  28377. +
  28378. +struct bm2835_mmal_dev {
  28379. + /* v4l2 devices */
  28380. + struct v4l2_device v4l2_dev;
  28381. + struct video_device vdev;
  28382. + struct mutex mutex;
  28383. +
  28384. + /* controls */
  28385. + struct v4l2_ctrl_handler ctrl_handler;
  28386. + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
  28387. + enum v4l2_scene_mode scene_mode;
  28388. + struct mmal_colourfx colourfx;
  28389. + int hflip;
  28390. + int vflip;
  28391. + int red_gain;
  28392. + int blue_gain;
  28393. + enum mmal_parameter_exposuremode exposure_mode_user;
  28394. + enum v4l2_exposure_auto_type exposure_mode_v4l2_user;
  28395. + /* active exposure mode may differ if selected via a scene mode */
  28396. + enum mmal_parameter_exposuremode exposure_mode_active;
  28397. + enum mmal_parameter_exposuremeteringmode metering_mode;
  28398. + unsigned int manual_shutter_speed;
  28399. + bool exp_auto_priority;
  28400. +
  28401. + /* allocated mmal instance and components */
  28402. + struct vchiq_mmal_instance *instance;
  28403. + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
  28404. + int camera_use_count;
  28405. +
  28406. + struct v4l2_window overlay;
  28407. +
  28408. + struct {
  28409. + unsigned int width; /* width */
  28410. + unsigned int height; /* height */
  28411. + unsigned int stride; /* stride */
  28412. + unsigned int buffersize; /* buffer size with padding */
  28413. + struct mmal_fmt *fmt;
  28414. + struct v4l2_fract timeperframe;
  28415. +
  28416. + /* H264 encode bitrate */
  28417. + int encode_bitrate;
  28418. + /* H264 bitrate mode. CBR/VBR */
  28419. + int encode_bitrate_mode;
  28420. + /* H264 profile */
  28421. + enum v4l2_mpeg_video_h264_profile enc_profile;
  28422. + /* H264 level */
  28423. + enum v4l2_mpeg_video_h264_level enc_level;
  28424. + /* JPEG Q-factor */
  28425. + int q_factor;
  28426. +
  28427. + struct vb2_queue vb_vidq;
  28428. +
  28429. + /* VC start timestamp for streaming */
  28430. + s64 vc_start_timestamp;
  28431. + /* Kernel start timestamp for streaming */
  28432. + struct timeval kernel_start_ts;
  28433. +
  28434. + struct vchiq_mmal_port *port; /* port being used for capture */
  28435. + /* camera port being used for capture */
  28436. + struct vchiq_mmal_port *camera_port;
  28437. + /* component being used for encode */
  28438. + struct vchiq_mmal_component *encode_component;
  28439. + /* number of frames remaining which driver should capture */
  28440. + unsigned int frame_count;
  28441. + /* last frame completion */
  28442. + struct completion frame_cmplt;
  28443. +
  28444. + } capture;
  28445. +
  28446. +};
  28447. +
  28448. +int bm2835_mmal_init_controls(
  28449. + struct bm2835_mmal_dev *dev,
  28450. + struct v4l2_ctrl_handler *hdl);
  28451. +
  28452. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
  28453. +int set_framerate_params(struct bm2835_mmal_dev *dev);
  28454. +
  28455. +/* Debug helpers */
  28456. +
  28457. +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
  28458. +{ \
  28459. + v4l2_dbg(level, debug, dev, \
  28460. +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
  28461. + desc == NULL ? "" : desc, \
  28462. + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
  28463. + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
  28464. + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
  28465. +}
  28466. diff -Nur linux-3.18.6/drivers/media/platform/bcm2835/controls.c linux-rpi/drivers/media/platform/bcm2835/controls.c
  28467. --- linux-3.18.6/drivers/media/platform/bcm2835/controls.c 1970-01-01 01:00:00.000000000 +0100
  28468. +++ linux-rpi/drivers/media/platform/bcm2835/controls.c 2015-02-09 04:40:03.000000000 +0100
  28469. @@ -0,0 +1,1322 @@
  28470. +/*
  28471. + * Broadcom BM2835 V4L2 driver
  28472. + *
  28473. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  28474. + *
  28475. + * This file is subject to the terms and conditions of the GNU General Public
  28476. + * License. See the file COPYING in the main directory of this archive
  28477. + * for more details.
  28478. + *
  28479. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  28480. + * Dave Stevenson <dsteve@broadcom.com>
  28481. + * Simon Mellor <simellor@broadcom.com>
  28482. + * Luke Diamand <luked@broadcom.com>
  28483. + */
  28484. +
  28485. +#include <linux/errno.h>
  28486. +#include <linux/kernel.h>
  28487. +#include <linux/module.h>
  28488. +#include <linux/slab.h>
  28489. +#include <media/videobuf2-vmalloc.h>
  28490. +#include <media/v4l2-device.h>
  28491. +#include <media/v4l2-ioctl.h>
  28492. +#include <media/v4l2-ctrls.h>
  28493. +#include <media/v4l2-fh.h>
  28494. +#include <media/v4l2-event.h>
  28495. +#include <media/v4l2-common.h>
  28496. +
  28497. +#include "mmal-common.h"
  28498. +#include "mmal-vchiq.h"
  28499. +#include "mmal-parameters.h"
  28500. +#include "bcm2835-camera.h"
  28501. +
  28502. +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
  28503. + * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
  28504. + * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
  28505. + * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
  28506. + * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
  28507. + * -4 to +4
  28508. + */
  28509. +static const s64 ev_bias_qmenu[] = {
  28510. + -4000, -3667, -3333,
  28511. + -3000, -2667, -2333,
  28512. + -2000, -1667, -1333,
  28513. + -1000, -667, -333,
  28514. + 0, 333, 667,
  28515. + 1000, 1333, 1667,
  28516. + 2000, 2333, 2667,
  28517. + 3000, 3333, 3667,
  28518. + 4000
  28519. +};
  28520. +
  28521. +/* Supported ISO values
  28522. + * ISOO = auto ISO
  28523. + */
  28524. +static const s64 iso_qmenu[] = {
  28525. + 0, 100, 200, 400, 800,
  28526. +};
  28527. +
  28528. +static const s64 mains_freq_qmenu[] = {
  28529. + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
  28530. + V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
  28531. + V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
  28532. + V4L2_CID_POWER_LINE_FREQUENCY_AUTO
  28533. +};
  28534. +
  28535. +/* Supported video encode modes */
  28536. +static const s64 bitrate_mode_qmenu[] = {
  28537. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
  28538. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
  28539. +};
  28540. +
  28541. +enum bm2835_mmal_ctrl_type {
  28542. + MMAL_CONTROL_TYPE_STD,
  28543. + MMAL_CONTROL_TYPE_STD_MENU,
  28544. + MMAL_CONTROL_TYPE_INT_MENU,
  28545. + MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
  28546. +};
  28547. +
  28548. +struct bm2835_mmal_v4l2_ctrl;
  28549. +
  28550. +typedef int(bm2835_mmal_v4l2_ctrl_cb)(
  28551. + struct bm2835_mmal_dev *dev,
  28552. + struct v4l2_ctrl *ctrl,
  28553. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
  28554. +
  28555. +struct bm2835_mmal_v4l2_ctrl {
  28556. + u32 id; /* v4l2 control identifier */
  28557. + enum bm2835_mmal_ctrl_type type;
  28558. + /* control minimum value or
  28559. + * mask for MMAL_CONTROL_TYPE_STD_MENU */
  28560. + s32 min;
  28561. + s32 max; /* maximum value of control */
  28562. + s32 def; /* default value of control */
  28563. + s32 step; /* step size of the control */
  28564. + const s64 *imenu; /* integer menu array */
  28565. + u32 mmal_id; /* mmal parameter id */
  28566. + bm2835_mmal_v4l2_ctrl_cb *setter;
  28567. + bool ignore_errors;
  28568. +};
  28569. +
  28570. +struct v4l2_to_mmal_effects_setting {
  28571. + u32 v4l2_effect;
  28572. + u32 mmal_effect;
  28573. + s32 col_fx_enable;
  28574. + s32 col_fx_fixed_cbcr;
  28575. + u32 u;
  28576. + u32 v;
  28577. + u32 num_effect_params;
  28578. + u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
  28579. +};
  28580. +
  28581. +static const struct v4l2_to_mmal_effects_setting
  28582. + v4l2_to_mmal_effects_values[] = {
  28583. + { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
  28584. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28585. + { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
  28586. + 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
  28587. + { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
  28588. + 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
  28589. + { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
  28590. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28591. + { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
  28592. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28593. + { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
  28594. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28595. + { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
  28596. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28597. + { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  28598. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28599. + { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
  28600. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28601. + { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
  28602. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28603. + { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
  28604. + 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
  28605. + { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
  28606. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28607. + { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
  28608. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  28609. + { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
  28610. + 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
  28611. + { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  28612. + 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
  28613. + { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
  28614. + 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
  28615. +};
  28616. +
  28617. +struct v4l2_mmal_scene_config {
  28618. + enum v4l2_scene_mode v4l2_scene;
  28619. + enum mmal_parameter_exposuremode exposure_mode;
  28620. + enum mmal_parameter_exposuremeteringmode metering_mode;
  28621. +};
  28622. +
  28623. +static const struct v4l2_mmal_scene_config scene_configs[] = {
  28624. + /* V4L2_SCENE_MODE_NONE automatically added */
  28625. + {
  28626. + V4L2_SCENE_MODE_NIGHT,
  28627. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  28628. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  28629. + },
  28630. + {
  28631. + V4L2_SCENE_MODE_SPORTS,
  28632. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  28633. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  28634. + },
  28635. +};
  28636. +
  28637. +/* control handlers*/
  28638. +
  28639. +static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
  28640. + struct v4l2_ctrl *ctrl,
  28641. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28642. +{
  28643. + struct mmal_parameter_rational rational_value;
  28644. + struct vchiq_mmal_port *control;
  28645. +
  28646. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28647. +
  28648. + rational_value.num = ctrl->val;
  28649. + rational_value.den = 100;
  28650. +
  28651. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28652. + mmal_ctrl->mmal_id,
  28653. + &rational_value,
  28654. + sizeof(rational_value));
  28655. +}
  28656. +
  28657. +static int ctrl_set_value(struct bm2835_mmal_dev *dev,
  28658. + struct v4l2_ctrl *ctrl,
  28659. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28660. +{
  28661. + u32 u32_value;
  28662. + struct vchiq_mmal_port *control;
  28663. +
  28664. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28665. +
  28666. + u32_value = ctrl->val;
  28667. +
  28668. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28669. + mmal_ctrl->mmal_id,
  28670. + &u32_value, sizeof(u32_value));
  28671. +}
  28672. +
  28673. +static int ctrl_set_value_menu(struct bm2835_mmal_dev *dev,
  28674. + struct v4l2_ctrl *ctrl,
  28675. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28676. +{
  28677. + u32 u32_value;
  28678. + struct vchiq_mmal_port *control;
  28679. +
  28680. + if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
  28681. + return 1;
  28682. +
  28683. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28684. +
  28685. + u32_value = mmal_ctrl->imenu[ctrl->val];
  28686. +
  28687. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28688. + mmal_ctrl->mmal_id,
  28689. + &u32_value, sizeof(u32_value));
  28690. +}
  28691. +
  28692. +static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
  28693. + struct v4l2_ctrl *ctrl,
  28694. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28695. +{
  28696. + s32 s32_value;
  28697. + struct vchiq_mmal_port *control;
  28698. +
  28699. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28700. +
  28701. + s32_value = (ctrl->val-12)*2; /* Convert from index to 1/6ths */
  28702. +
  28703. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28704. + mmal_ctrl->mmal_id,
  28705. + &s32_value, sizeof(s32_value));
  28706. +}
  28707. +
  28708. +static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
  28709. + struct v4l2_ctrl *ctrl,
  28710. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28711. +{
  28712. + int ret;
  28713. + u32 u32_value;
  28714. + struct vchiq_mmal_component *camera;
  28715. +
  28716. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  28717. +
  28718. + u32_value = ((ctrl->val % 360) / 90) * 90;
  28719. +
  28720. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  28721. + mmal_ctrl->mmal_id,
  28722. + &u32_value, sizeof(u32_value));
  28723. + if (ret < 0)
  28724. + return ret;
  28725. +
  28726. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  28727. + mmal_ctrl->mmal_id,
  28728. + &u32_value, sizeof(u32_value));
  28729. + if (ret < 0)
  28730. + return ret;
  28731. +
  28732. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  28733. + mmal_ctrl->mmal_id,
  28734. + &u32_value, sizeof(u32_value));
  28735. +
  28736. + return ret;
  28737. +}
  28738. +
  28739. +static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
  28740. + struct v4l2_ctrl *ctrl,
  28741. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28742. +{
  28743. + int ret;
  28744. + u32 u32_value;
  28745. + struct vchiq_mmal_component *camera;
  28746. +
  28747. + if (ctrl->id == V4L2_CID_HFLIP)
  28748. + dev->hflip = ctrl->val;
  28749. + else
  28750. + dev->vflip = ctrl->val;
  28751. +
  28752. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  28753. +
  28754. + if (dev->hflip && dev->vflip)
  28755. + u32_value = MMAL_PARAM_MIRROR_BOTH;
  28756. + else if (dev->hflip)
  28757. + u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
  28758. + else if (dev->vflip)
  28759. + u32_value = MMAL_PARAM_MIRROR_VERTICAL;
  28760. + else
  28761. + u32_value = MMAL_PARAM_MIRROR_NONE;
  28762. +
  28763. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  28764. + mmal_ctrl->mmal_id,
  28765. + &u32_value, sizeof(u32_value));
  28766. + if (ret < 0)
  28767. + return ret;
  28768. +
  28769. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  28770. + mmal_ctrl->mmal_id,
  28771. + &u32_value, sizeof(u32_value));
  28772. + if (ret < 0)
  28773. + return ret;
  28774. +
  28775. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  28776. + mmal_ctrl->mmal_id,
  28777. + &u32_value, sizeof(u32_value));
  28778. +
  28779. + return ret;
  28780. +
  28781. +}
  28782. +
  28783. +static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
  28784. + struct v4l2_ctrl *ctrl,
  28785. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28786. +{
  28787. + enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode_user;
  28788. + u32 shutter_speed = 0;
  28789. + struct vchiq_mmal_port *control;
  28790. + int ret = 0;
  28791. +
  28792. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28793. +
  28794. + if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
  28795. + /* V4L2 is in 100usec increments.
  28796. + * MMAL is 1usec.
  28797. + */
  28798. + dev->manual_shutter_speed = ctrl->val * 100;
  28799. + } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
  28800. + switch (ctrl->val) {
  28801. + case V4L2_EXPOSURE_AUTO:
  28802. + exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
  28803. + break;
  28804. +
  28805. + case V4L2_EXPOSURE_MANUAL:
  28806. + exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
  28807. + break;
  28808. + }
  28809. + dev->exposure_mode_user = exp_mode;
  28810. + dev->exposure_mode_v4l2_user = ctrl->val;
  28811. + } else if (mmal_ctrl->id == V4L2_CID_EXPOSURE_AUTO_PRIORITY) {
  28812. + dev->exp_auto_priority = ctrl->val;
  28813. + }
  28814. +
  28815. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  28816. + if (exp_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  28817. + shutter_speed = dev->manual_shutter_speed;
  28818. +
  28819. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  28820. + control,
  28821. + MMAL_PARAMETER_SHUTTER_SPEED,
  28822. + &shutter_speed,
  28823. + sizeof(shutter_speed));
  28824. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  28825. + control,
  28826. + MMAL_PARAMETER_EXPOSURE_MODE,
  28827. + &exp_mode,
  28828. + sizeof(u32));
  28829. + dev->exposure_mode_active = exp_mode;
  28830. + }
  28831. + /* exposure_dynamic_framerate (V4L2_CID_EXPOSURE_AUTO_PRIORITY) should
  28832. + * always apply irrespective of scene mode.
  28833. + */
  28834. + ret += set_framerate_params(dev);
  28835. +
  28836. + return ret;
  28837. +}
  28838. +
  28839. +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
  28840. + struct v4l2_ctrl *ctrl,
  28841. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28842. +{
  28843. + switch (ctrl->val) {
  28844. + case V4L2_EXPOSURE_METERING_AVERAGE:
  28845. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  28846. + break;
  28847. +
  28848. + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  28849. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
  28850. + break;
  28851. +
  28852. + case V4L2_EXPOSURE_METERING_SPOT:
  28853. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
  28854. + break;
  28855. +
  28856. + /* todo matrix weighting not added to Linux API till 3.9
  28857. + case V4L2_EXPOSURE_METERING_MATRIX:
  28858. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
  28859. + break;
  28860. + */
  28861. +
  28862. + }
  28863. +
  28864. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  28865. + struct vchiq_mmal_port *control;
  28866. + u32 u32_value = dev->metering_mode;
  28867. +
  28868. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28869. +
  28870. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28871. + mmal_ctrl->mmal_id,
  28872. + &u32_value, sizeof(u32_value));
  28873. + } else
  28874. + return 0;
  28875. +}
  28876. +
  28877. +static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
  28878. + struct v4l2_ctrl *ctrl,
  28879. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28880. +{
  28881. + u32 u32_value;
  28882. + struct vchiq_mmal_port *control;
  28883. +
  28884. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28885. +
  28886. + switch (ctrl->val) {
  28887. + case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
  28888. + u32_value = MMAL_PARAM_FLICKERAVOID_OFF;
  28889. + break;
  28890. + case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
  28891. + u32_value = MMAL_PARAM_FLICKERAVOID_50HZ;
  28892. + break;
  28893. + case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
  28894. + u32_value = MMAL_PARAM_FLICKERAVOID_60HZ;
  28895. + break;
  28896. + case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
  28897. + u32_value = MMAL_PARAM_FLICKERAVOID_AUTO;
  28898. + break;
  28899. + }
  28900. +
  28901. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28902. + mmal_ctrl->mmal_id,
  28903. + &u32_value, sizeof(u32_value));
  28904. +}
  28905. +
  28906. +static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
  28907. + struct v4l2_ctrl *ctrl,
  28908. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28909. +{
  28910. + u32 u32_value;
  28911. + struct vchiq_mmal_port *control;
  28912. +
  28913. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28914. +
  28915. + switch (ctrl->val) {
  28916. + case V4L2_WHITE_BALANCE_MANUAL:
  28917. + u32_value = MMAL_PARAM_AWBMODE_OFF;
  28918. + break;
  28919. +
  28920. + case V4L2_WHITE_BALANCE_AUTO:
  28921. + u32_value = MMAL_PARAM_AWBMODE_AUTO;
  28922. + break;
  28923. +
  28924. + case V4L2_WHITE_BALANCE_INCANDESCENT:
  28925. + u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
  28926. + break;
  28927. +
  28928. + case V4L2_WHITE_BALANCE_FLUORESCENT:
  28929. + u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
  28930. + break;
  28931. +
  28932. + case V4L2_WHITE_BALANCE_FLUORESCENT_H:
  28933. + u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
  28934. + break;
  28935. +
  28936. + case V4L2_WHITE_BALANCE_HORIZON:
  28937. + u32_value = MMAL_PARAM_AWBMODE_HORIZON;
  28938. + break;
  28939. +
  28940. + case V4L2_WHITE_BALANCE_DAYLIGHT:
  28941. + u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
  28942. + break;
  28943. +
  28944. + case V4L2_WHITE_BALANCE_FLASH:
  28945. + u32_value = MMAL_PARAM_AWBMODE_FLASH;
  28946. + break;
  28947. +
  28948. + case V4L2_WHITE_BALANCE_CLOUDY:
  28949. + u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
  28950. + break;
  28951. +
  28952. + case V4L2_WHITE_BALANCE_SHADE:
  28953. + u32_value = MMAL_PARAM_AWBMODE_SHADE;
  28954. + break;
  28955. +
  28956. + }
  28957. +
  28958. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28959. + mmal_ctrl->mmal_id,
  28960. + &u32_value, sizeof(u32_value));
  28961. +}
  28962. +
  28963. +static int ctrl_set_awb_gains(struct bm2835_mmal_dev *dev,
  28964. + struct v4l2_ctrl *ctrl,
  28965. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28966. +{
  28967. + struct vchiq_mmal_port *control;
  28968. + struct mmal_parameter_awbgains gains;
  28969. +
  28970. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  28971. +
  28972. + if (ctrl->id == V4L2_CID_RED_BALANCE)
  28973. + dev->red_gain = ctrl->val;
  28974. + else if (ctrl->id == V4L2_CID_BLUE_BALANCE)
  28975. + dev->blue_gain = ctrl->val;
  28976. +
  28977. + gains.r_gain.num = dev->red_gain;
  28978. + gains.b_gain.num = dev->blue_gain;
  28979. + gains.r_gain.den = gains.b_gain.den = 1000;
  28980. +
  28981. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  28982. + mmal_ctrl->mmal_id,
  28983. + &gains, sizeof(gains));
  28984. +}
  28985. +
  28986. +static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
  28987. + struct v4l2_ctrl *ctrl,
  28988. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  28989. +{
  28990. + int ret = -EINVAL;
  28991. + int i, j;
  28992. + struct vchiq_mmal_port *control;
  28993. + struct mmal_parameter_imagefx_parameters imagefx;
  28994. +
  28995. + for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
  28996. + if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
  28997. +
  28998. + imagefx.effect =
  28999. + v4l2_to_mmal_effects_values[i].mmal_effect;
  29000. + imagefx.num_effect_params =
  29001. + v4l2_to_mmal_effects_values[i].num_effect_params;
  29002. +
  29003. + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
  29004. + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
  29005. +
  29006. + for (j = 0; j < imagefx.num_effect_params; j++)
  29007. + imagefx.effect_parameter[j] =
  29008. + v4l2_to_mmal_effects_values[i].effect_params[j];
  29009. +
  29010. + dev->colourfx.enable =
  29011. + v4l2_to_mmal_effects_values[i].col_fx_enable;
  29012. + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
  29013. + dev->colourfx.u =
  29014. + v4l2_to_mmal_effects_values[i].u;
  29015. + dev->colourfx.v =
  29016. + v4l2_to_mmal_effects_values[i].v;
  29017. + }
  29018. +
  29019. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  29020. +
  29021. + ret = vchiq_mmal_port_parameter_set(
  29022. + dev->instance, control,
  29023. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  29024. + &imagefx, sizeof(imagefx));
  29025. + if (ret)
  29026. + goto exit;
  29027. +
  29028. + ret = vchiq_mmal_port_parameter_set(
  29029. + dev->instance, control,
  29030. + MMAL_PARAMETER_COLOUR_EFFECT,
  29031. + &dev->colourfx, sizeof(dev->colourfx));
  29032. + }
  29033. + }
  29034. +
  29035. +exit:
  29036. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29037. + "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
  29038. + mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
  29039. + dev->colourfx.enable ? "true" : "false",
  29040. + dev->colourfx.u, dev->colourfx.v,
  29041. + ret, (ret == 0 ? 0 : -EINVAL));
  29042. + return (ret == 0 ? 0 : EINVAL);
  29043. +}
  29044. +
  29045. +static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
  29046. + struct v4l2_ctrl *ctrl,
  29047. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  29048. +{
  29049. + int ret = -EINVAL;
  29050. + struct vchiq_mmal_port *control;
  29051. +
  29052. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  29053. +
  29054. + dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
  29055. + dev->colourfx.enable = ctrl->val & 0xff;
  29056. +
  29057. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  29058. + MMAL_PARAMETER_COLOUR_EFFECT,
  29059. + &dev->colourfx, sizeof(dev->colourfx));
  29060. +
  29061. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29062. + "%s: After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
  29063. + __func__, mmal_ctrl, ctrl->id, ctrl->val, ret,
  29064. + (ret == 0 ? 0 : -EINVAL));
  29065. + return (ret == 0 ? 0 : EINVAL);
  29066. +}
  29067. +
  29068. +static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
  29069. + struct v4l2_ctrl *ctrl,
  29070. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  29071. +{
  29072. + int ret;
  29073. + struct vchiq_mmal_port *encoder_out;
  29074. +
  29075. + dev->capture.encode_bitrate = ctrl->val;
  29076. +
  29077. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  29078. +
  29079. + ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  29080. + mmal_ctrl->mmal_id,
  29081. + &ctrl->val, sizeof(ctrl->val));
  29082. + ret = 0;
  29083. + return ret;
  29084. +}
  29085. +
  29086. +static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
  29087. + struct v4l2_ctrl *ctrl,
  29088. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  29089. +{
  29090. + u32 bitrate_mode;
  29091. + struct vchiq_mmal_port *encoder_out;
  29092. +
  29093. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  29094. +
  29095. + dev->capture.encode_bitrate_mode = ctrl->val;
  29096. + switch (ctrl->val) {
  29097. + default:
  29098. + case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
  29099. + bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
  29100. + break;
  29101. + case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
  29102. + bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
  29103. + break;
  29104. + }
  29105. +
  29106. + vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  29107. + mmal_ctrl->mmal_id,
  29108. + &bitrate_mode,
  29109. + sizeof(bitrate_mode));
  29110. + return 0;
  29111. +}
  29112. +
  29113. +static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
  29114. + struct v4l2_ctrl *ctrl,
  29115. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  29116. +{
  29117. + u32 u32_value;
  29118. + struct vchiq_mmal_port *jpeg_out;
  29119. +
  29120. + jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  29121. +
  29122. + u32_value = ctrl->val;
  29123. +
  29124. + return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
  29125. + mmal_ctrl->mmal_id,
  29126. + &u32_value, sizeof(u32_value));
  29127. +}
  29128. +
  29129. +static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
  29130. + struct v4l2_ctrl *ctrl,
  29131. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  29132. +{
  29133. + u32 u32_value;
  29134. + struct vchiq_mmal_port *vid_enc_ctl;
  29135. +
  29136. + vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  29137. +
  29138. + u32_value = ctrl->val;
  29139. +
  29140. + return vchiq_mmal_port_parameter_set(dev->instance, vid_enc_ctl,
  29141. + mmal_ctrl->mmal_id,
  29142. + &u32_value, sizeof(u32_value));
  29143. +}
  29144. +
  29145. +static int ctrl_set_video_encode_profile_level(struct bm2835_mmal_dev *dev,
  29146. + struct v4l2_ctrl *ctrl,
  29147. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  29148. +{
  29149. + struct mmal_parameter_video_profile param;
  29150. + int ret = 0;
  29151. +
  29152. + if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_PROFILE) {
  29153. + switch (ctrl->val) {
  29154. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  29155. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  29156. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  29157. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  29158. + dev->capture.enc_profile = ctrl->val;
  29159. + break;
  29160. + default:
  29161. + ret = -EINVAL;
  29162. + break;
  29163. + }
  29164. + } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_LEVEL) {
  29165. + switch (ctrl->val) {
  29166. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  29167. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  29168. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  29169. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  29170. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  29171. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  29172. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  29173. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  29174. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  29175. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  29176. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  29177. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  29178. + dev->capture.enc_level = ctrl->val;
  29179. + break;
  29180. + default:
  29181. + ret = -EINVAL;
  29182. + break;
  29183. + }
  29184. + }
  29185. +
  29186. + if (!ret) {
  29187. + switch (dev->capture.enc_profile) {
  29188. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  29189. + param.profile = MMAL_VIDEO_PROFILE_H264_BASELINE;
  29190. + break;
  29191. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  29192. + param.profile =
  29193. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE;
  29194. + break;
  29195. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  29196. + param.profile = MMAL_VIDEO_PROFILE_H264_MAIN;
  29197. + break;
  29198. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  29199. + param.profile = MMAL_VIDEO_PROFILE_H264_HIGH;
  29200. + break;
  29201. + default:
  29202. + /* Should never get here */
  29203. + break;
  29204. + }
  29205. +
  29206. + switch (dev->capture.enc_level) {
  29207. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  29208. + param.level = MMAL_VIDEO_LEVEL_H264_1;
  29209. + break;
  29210. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  29211. + param.level = MMAL_VIDEO_LEVEL_H264_1b;
  29212. + break;
  29213. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  29214. + param.level = MMAL_VIDEO_LEVEL_H264_11;
  29215. + break;
  29216. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  29217. + param.level = MMAL_VIDEO_LEVEL_H264_12;
  29218. + break;
  29219. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  29220. + param.level = MMAL_VIDEO_LEVEL_H264_13;
  29221. + break;
  29222. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  29223. + param.level = MMAL_VIDEO_LEVEL_H264_2;
  29224. + break;
  29225. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  29226. + param.level = MMAL_VIDEO_LEVEL_H264_21;
  29227. + break;
  29228. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  29229. + param.level = MMAL_VIDEO_LEVEL_H264_22;
  29230. + break;
  29231. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  29232. + param.level = MMAL_VIDEO_LEVEL_H264_3;
  29233. + break;
  29234. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  29235. + param.level = MMAL_VIDEO_LEVEL_H264_31;
  29236. + break;
  29237. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  29238. + param.level = MMAL_VIDEO_LEVEL_H264_32;
  29239. + break;
  29240. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  29241. + param.level = MMAL_VIDEO_LEVEL_H264_4;
  29242. + break;
  29243. + default:
  29244. + /* Should never get here */
  29245. + break;
  29246. + }
  29247. +
  29248. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  29249. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0],
  29250. + mmal_ctrl->mmal_id,
  29251. + &param, sizeof(param));
  29252. + }
  29253. + return ret;
  29254. +}
  29255. +
  29256. +static int ctrl_set_scene_mode(struct bm2835_mmal_dev *dev,
  29257. + struct v4l2_ctrl *ctrl,
  29258. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  29259. +{
  29260. + int ret = 0;
  29261. + int shutter_speed;
  29262. + struct vchiq_mmal_port *control;
  29263. +
  29264. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29265. + "scene mode selected %d, was %d\n", ctrl->val,
  29266. + dev->scene_mode);
  29267. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  29268. +
  29269. + if (ctrl->val == dev->scene_mode)
  29270. + return 0;
  29271. +
  29272. + if (ctrl->val == V4L2_SCENE_MODE_NONE) {
  29273. + /* Restore all user selections */
  29274. + dev->scene_mode = V4L2_SCENE_MODE_NONE;
  29275. +
  29276. + if (dev->exposure_mode_user == MMAL_PARAM_EXPOSUREMODE_OFF)
  29277. + shutter_speed = dev->manual_shutter_speed;
  29278. + else
  29279. + shutter_speed = 0;
  29280. +
  29281. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29282. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  29283. + __func__, shutter_speed, dev->exposure_mode_user,
  29284. + dev->metering_mode);
  29285. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  29286. + control,
  29287. + MMAL_PARAMETER_SHUTTER_SPEED,
  29288. + &shutter_speed,
  29289. + sizeof(shutter_speed));
  29290. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  29291. + control,
  29292. + MMAL_PARAMETER_EXPOSURE_MODE,
  29293. + &dev->exposure_mode_user,
  29294. + sizeof(u32));
  29295. + dev->exposure_mode_active = dev->exposure_mode_user;
  29296. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  29297. + control,
  29298. + MMAL_PARAMETER_EXP_METERING_MODE,
  29299. + &dev->metering_mode,
  29300. + sizeof(u32));
  29301. + ret += set_framerate_params(dev);
  29302. + } else {
  29303. + /* Set up scene mode */
  29304. + int i;
  29305. + const struct v4l2_mmal_scene_config *scene = NULL;
  29306. + int shutter_speed;
  29307. + enum mmal_parameter_exposuremode exposure_mode;
  29308. + enum mmal_parameter_exposuremeteringmode metering_mode;
  29309. +
  29310. + for (i = 0; i < ARRAY_SIZE(scene_configs); i++) {
  29311. + if (scene_configs[i].v4l2_scene ==
  29312. + ctrl->val) {
  29313. + scene = &scene_configs[i];
  29314. + break;
  29315. + }
  29316. + }
  29317. + if (i >= ARRAY_SIZE(scene_configs))
  29318. + return -EINVAL;
  29319. +
  29320. + /* Set all the values */
  29321. + dev->scene_mode = ctrl->val;
  29322. +
  29323. + if (scene->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  29324. + shutter_speed = dev->manual_shutter_speed;
  29325. + else
  29326. + shutter_speed = 0;
  29327. + exposure_mode = scene->exposure_mode;
  29328. + metering_mode = scene->metering_mode;
  29329. +
  29330. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29331. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  29332. + __func__, shutter_speed, exposure_mode, metering_mode);
  29333. +
  29334. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  29335. + MMAL_PARAMETER_SHUTTER_SPEED,
  29336. + &shutter_speed,
  29337. + sizeof(shutter_speed));
  29338. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  29339. + control,
  29340. + MMAL_PARAMETER_EXPOSURE_MODE,
  29341. + &exposure_mode,
  29342. + sizeof(u32));
  29343. + dev->exposure_mode_active = exposure_mode;
  29344. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  29345. + MMAL_PARAMETER_EXPOSURE_MODE,
  29346. + &exposure_mode,
  29347. + sizeof(u32));
  29348. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  29349. + MMAL_PARAMETER_EXP_METERING_MODE,
  29350. + &metering_mode,
  29351. + sizeof(u32));
  29352. + ret += set_framerate_params(dev);
  29353. + }
  29354. + if (ret) {
  29355. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29356. + "%s: Setting scene to %d, ret=%d\n",
  29357. + __func__, ctrl->val, ret);
  29358. + ret = -EINVAL;
  29359. + }
  29360. + return 0;
  29361. +}
  29362. +
  29363. +static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
  29364. +{
  29365. + struct bm2835_mmal_dev *dev =
  29366. + container_of(ctrl->handler, struct bm2835_mmal_dev,
  29367. + ctrl_handler);
  29368. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
  29369. + int ret;
  29370. +
  29371. + if ((mmal_ctrl == NULL) ||
  29372. + (mmal_ctrl->id != ctrl->id) ||
  29373. + (mmal_ctrl->setter == NULL)) {
  29374. + pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
  29375. + return -EINVAL;
  29376. + }
  29377. +
  29378. + ret = mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
  29379. + if (ret)
  29380. + pr_warn("ctrl id:%d/MMAL param %08X- returned ret %d\n",
  29381. + ctrl->id, mmal_ctrl->mmal_id, ret);
  29382. + if (mmal_ctrl->ignore_errors)
  29383. + ret = 0;
  29384. + return ret;
  29385. +}
  29386. +
  29387. +static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
  29388. + .s_ctrl = bm2835_mmal_s_ctrl,
  29389. +};
  29390. +
  29391. +
  29392. +
  29393. +static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
  29394. + {
  29395. + V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
  29396. + -100, 100, 0, 1, NULL,
  29397. + MMAL_PARAMETER_SATURATION,
  29398. + &ctrl_set_rational,
  29399. + false
  29400. + },
  29401. + {
  29402. + V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
  29403. + -100, 100, 0, 1, NULL,
  29404. + MMAL_PARAMETER_SHARPNESS,
  29405. + &ctrl_set_rational,
  29406. + false
  29407. + },
  29408. + {
  29409. + V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
  29410. + -100, 100, 0, 1, NULL,
  29411. + MMAL_PARAMETER_CONTRAST,
  29412. + &ctrl_set_rational,
  29413. + false
  29414. + },
  29415. + {
  29416. + V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
  29417. + 0, 100, 50, 1, NULL,
  29418. + MMAL_PARAMETER_BRIGHTNESS,
  29419. + &ctrl_set_rational,
  29420. + false
  29421. + },
  29422. + {
  29423. + V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
  29424. + 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
  29425. + MMAL_PARAMETER_ISO,
  29426. + &ctrl_set_value_menu,
  29427. + false
  29428. + },
  29429. + {
  29430. + V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
  29431. + 0, 1, 0, 1, NULL,
  29432. + MMAL_PARAMETER_VIDEO_STABILISATION,
  29433. + &ctrl_set_value,
  29434. + false
  29435. + },
  29436. +/* {
  29437. + 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
  29438. + }, */
  29439. + {
  29440. + V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
  29441. + ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
  29442. + MMAL_PARAMETER_EXPOSURE_MODE,
  29443. + &ctrl_set_exposure,
  29444. + false
  29445. + },
  29446. +/* todo this needs mixing in with set exposure
  29447. + {
  29448. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  29449. + },
  29450. + */
  29451. + {
  29452. + V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
  29453. + /* Units of 100usecs */
  29454. + 1, 1*1000*10, 100*10, 1, NULL,
  29455. + MMAL_PARAMETER_SHUTTER_SPEED,
  29456. + &ctrl_set_exposure,
  29457. + false
  29458. + },
  29459. + {
  29460. + V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
  29461. + 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
  29462. + (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
  29463. + MMAL_PARAMETER_EXPOSURE_COMP,
  29464. + &ctrl_set_value_ev,
  29465. + false
  29466. + },
  29467. + {
  29468. + V4L2_CID_EXPOSURE_AUTO_PRIORITY, MMAL_CONTROL_TYPE_STD,
  29469. + 0, 1,
  29470. + 0, 1, NULL,
  29471. + 0, /* Dummy MMAL ID as it gets mapped into FPS range*/
  29472. + &ctrl_set_exposure,
  29473. + false
  29474. + },
  29475. + {
  29476. + V4L2_CID_EXPOSURE_METERING,
  29477. + MMAL_CONTROL_TYPE_STD_MENU,
  29478. + ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
  29479. + MMAL_PARAMETER_EXP_METERING_MODE,
  29480. + &ctrl_set_metering_mode,
  29481. + false
  29482. + },
  29483. + {
  29484. + V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
  29485. + MMAL_CONTROL_TYPE_STD_MENU,
  29486. + ~0x3ff, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
  29487. + MMAL_PARAMETER_AWB_MODE,
  29488. + &ctrl_set_awb_mode,
  29489. + false
  29490. + },
  29491. + {
  29492. + V4L2_CID_RED_BALANCE, MMAL_CONTROL_TYPE_STD,
  29493. + 1, 7999, 1000, 1, NULL,
  29494. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  29495. + &ctrl_set_awb_gains,
  29496. + false
  29497. + },
  29498. + {
  29499. + V4L2_CID_BLUE_BALANCE, MMAL_CONTROL_TYPE_STD,
  29500. + 1, 7999, 1000, 1, NULL,
  29501. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  29502. + &ctrl_set_awb_gains,
  29503. + false
  29504. + },
  29505. + {
  29506. + V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
  29507. + 0, 15, V4L2_COLORFX_NONE, 0, NULL,
  29508. + MMAL_PARAMETER_IMAGE_EFFECT,
  29509. + &ctrl_set_image_effect,
  29510. + false
  29511. + },
  29512. + {
  29513. + V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
  29514. + 0, 0xffff, 0x8080, 1, NULL,
  29515. + MMAL_PARAMETER_COLOUR_EFFECT,
  29516. + &ctrl_set_colfx,
  29517. + false
  29518. + },
  29519. + {
  29520. + V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
  29521. + 0, 360, 0, 90, NULL,
  29522. + MMAL_PARAMETER_ROTATION,
  29523. + &ctrl_set_rotate,
  29524. + false
  29525. + },
  29526. + {
  29527. + V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
  29528. + 0, 1, 0, 1, NULL,
  29529. + MMAL_PARAMETER_MIRROR,
  29530. + &ctrl_set_flip,
  29531. + false
  29532. + },
  29533. + {
  29534. + V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
  29535. + 0, 1, 0, 1, NULL,
  29536. + MMAL_PARAMETER_MIRROR,
  29537. + &ctrl_set_flip,
  29538. + false
  29539. + },
  29540. + {
  29541. + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  29542. + 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
  29543. + 0, 0, bitrate_mode_qmenu,
  29544. + MMAL_PARAMETER_RATECONTROL,
  29545. + &ctrl_set_bitrate_mode,
  29546. + false
  29547. + },
  29548. + {
  29549. + V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
  29550. + 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
  29551. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  29552. + &ctrl_set_bitrate,
  29553. + false
  29554. + },
  29555. + {
  29556. + V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
  29557. + 1, 100,
  29558. + 30, 1, NULL,
  29559. + MMAL_PARAMETER_JPEG_Q_FACTOR,
  29560. + &ctrl_set_image_encode_output,
  29561. + false
  29562. + },
  29563. + {
  29564. + V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
  29565. + 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
  29566. + 1, 1, NULL,
  29567. + MMAL_PARAMETER_FLICKER_AVOID,
  29568. + &ctrl_set_flicker_avoidance,
  29569. + false
  29570. + },
  29571. + {
  29572. + V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD,
  29573. + 0, 1,
  29574. + 0, 1, NULL,
  29575. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
  29576. + &ctrl_set_video_encode_param_output,
  29577. + true /* Errors ignored as requires latest firmware to work */
  29578. + },
  29579. + {
  29580. + V4L2_CID_MPEG_VIDEO_H264_PROFILE,
  29581. + MMAL_CONTROL_TYPE_STD_MENU,
  29582. + ~((1<<V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
  29583. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
  29584. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
  29585. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
  29586. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
  29587. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, 1, NULL,
  29588. + MMAL_PARAMETER_PROFILE,
  29589. + &ctrl_set_video_encode_profile_level,
  29590. + false
  29591. + },
  29592. + {
  29593. + V4L2_CID_MPEG_VIDEO_H264_LEVEL, MMAL_CONTROL_TYPE_STD_MENU,
  29594. + ~((1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
  29595. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1B) |
  29596. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_1) |
  29597. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_2) |
  29598. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_3) |
  29599. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
  29600. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_1) |
  29601. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_2) |
  29602. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
  29603. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
  29604. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
  29605. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
  29606. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
  29607. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 1, NULL,
  29608. + MMAL_PARAMETER_PROFILE,
  29609. + &ctrl_set_video_encode_profile_level,
  29610. + false
  29611. + },
  29612. + {
  29613. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  29614. + -1, /* Min is computed at runtime */
  29615. + V4L2_SCENE_MODE_TEXT,
  29616. + V4L2_SCENE_MODE_NONE, 1, NULL,
  29617. + MMAL_PARAMETER_PROFILE,
  29618. + &ctrl_set_scene_mode,
  29619. + false
  29620. + },
  29621. + {
  29622. + V4L2_CID_MPEG_VIDEO_H264_I_PERIOD, MMAL_CONTROL_TYPE_STD,
  29623. + 0, 0x7FFFFFFF, 60, 1, NULL,
  29624. + MMAL_PARAMETER_INTRAPERIOD,
  29625. + &ctrl_set_video_encode_param_output,
  29626. + false
  29627. + },
  29628. +};
  29629. +
  29630. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
  29631. +{
  29632. + int c;
  29633. + int ret = 0;
  29634. +
  29635. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  29636. + if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
  29637. + ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
  29638. + &v4l2_ctrls[c]);
  29639. + if (!v4l2_ctrls[c].ignore_errors && ret) {
  29640. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29641. + "Failed when setting default values for ctrl %d\n",
  29642. + c);
  29643. + break;
  29644. + }
  29645. + }
  29646. + }
  29647. + return ret;
  29648. +}
  29649. +
  29650. +int set_framerate_params(struct bm2835_mmal_dev *dev)
  29651. +{
  29652. + struct mmal_parameter_fps_range fps_range;
  29653. + int ret;
  29654. +
  29655. + if ((dev->exposure_mode_active != MMAL_PARAM_EXPOSUREMODE_OFF) &&
  29656. + (dev->exp_auto_priority)) {
  29657. + /* Variable FPS. Define min FPS as 1fps.
  29658. + * Max as max defined FPS.
  29659. + */
  29660. + fps_range.fps_low.num = 1;
  29661. + fps_range.fps_low.den = 1;
  29662. + fps_range.fps_high.num = dev->capture.timeperframe.denominator;
  29663. + fps_range.fps_high.den = dev->capture.timeperframe.numerator;
  29664. + } else {
  29665. + /* Fixed FPS - set min and max to be the same */
  29666. + fps_range.fps_low.num = fps_range.fps_high.num =
  29667. + dev->capture.timeperframe.denominator;
  29668. + fps_range.fps_low.den = fps_range.fps_high.den =
  29669. + dev->capture.timeperframe.numerator;
  29670. + }
  29671. +
  29672. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29673. + "Set fps range to %d/%d to %d/%d\n",
  29674. + fps_range.fps_low.num,
  29675. + fps_range.fps_low.den,
  29676. + fps_range.fps_high.num,
  29677. + fps_range.fps_high.den
  29678. + );
  29679. +
  29680. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  29681. + &dev->component[MMAL_COMPONENT_CAMERA]->
  29682. + output[MMAL_CAMERA_PORT_PREVIEW],
  29683. + MMAL_PARAMETER_FPS_RANGE,
  29684. + &fps_range, sizeof(fps_range));
  29685. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  29686. + &dev->component[MMAL_COMPONENT_CAMERA]->
  29687. + output[MMAL_CAMERA_PORT_VIDEO],
  29688. + MMAL_PARAMETER_FPS_RANGE,
  29689. + &fps_range, sizeof(fps_range));
  29690. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  29691. + &dev->component[MMAL_COMPONENT_CAMERA]->
  29692. + output[MMAL_CAMERA_PORT_CAPTURE],
  29693. + MMAL_PARAMETER_FPS_RANGE,
  29694. + &fps_range, sizeof(fps_range));
  29695. + if (ret)
  29696. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  29697. + "Failed to set fps ret %d\n",
  29698. + ret);
  29699. +
  29700. + return ret;
  29701. +
  29702. +}
  29703. +
  29704. +int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
  29705. + struct v4l2_ctrl_handler *hdl)
  29706. +{
  29707. + int c;
  29708. + const struct bm2835_mmal_v4l2_ctrl *ctrl;
  29709. +
  29710. + v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
  29711. +
  29712. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  29713. + ctrl = &v4l2_ctrls[c];
  29714. +
  29715. + switch (ctrl->type) {
  29716. + case MMAL_CONTROL_TYPE_STD:
  29717. + dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
  29718. + &bm2835_mmal_ctrl_ops, ctrl->id,
  29719. + ctrl->min, ctrl->max, ctrl->step, ctrl->def);
  29720. + break;
  29721. +
  29722. + case MMAL_CONTROL_TYPE_STD_MENU:
  29723. + {
  29724. + int mask = ctrl->min;
  29725. +
  29726. + if (ctrl->id == V4L2_CID_SCENE_MODE) {
  29727. + /* Special handling to work out the mask
  29728. + * value based on the scene_configs array
  29729. + * at runtime. Reduces the chance of
  29730. + * mismatches.
  29731. + */
  29732. + int i;
  29733. + mask = 1<<V4L2_SCENE_MODE_NONE;
  29734. + for (i = 0;
  29735. + i < ARRAY_SIZE(scene_configs);
  29736. + i++) {
  29737. + mask |= 1<<scene_configs[i].v4l2_scene;
  29738. + }
  29739. + mask = ~mask;
  29740. + }
  29741. +
  29742. + dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
  29743. + &bm2835_mmal_ctrl_ops, ctrl->id,
  29744. + ctrl->max, mask, ctrl->def);
  29745. + break;
  29746. + }
  29747. +
  29748. + case MMAL_CONTROL_TYPE_INT_MENU:
  29749. + dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
  29750. + &bm2835_mmal_ctrl_ops, ctrl->id,
  29751. + ctrl->max, ctrl->def, ctrl->imenu);
  29752. + break;
  29753. +
  29754. + case MMAL_CONTROL_TYPE_CLUSTER:
  29755. + /* skip this entry when constructing controls */
  29756. + continue;
  29757. + }
  29758. +
  29759. + if (hdl->error)
  29760. + break;
  29761. +
  29762. + dev->ctrls[c]->priv = (void *)ctrl;
  29763. + }
  29764. +
  29765. + if (hdl->error) {
  29766. + pr_err("error adding control %d/%d id 0x%x\n", c,
  29767. + V4L2_CTRL_COUNT, ctrl->id);
  29768. + return hdl->error;
  29769. + }
  29770. +
  29771. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  29772. + ctrl = &v4l2_ctrls[c];
  29773. +
  29774. + switch (ctrl->type) {
  29775. + case MMAL_CONTROL_TYPE_CLUSTER:
  29776. + v4l2_ctrl_auto_cluster(ctrl->min,
  29777. + &dev->ctrls[c+1],
  29778. + ctrl->max,
  29779. + ctrl->def);
  29780. + break;
  29781. +
  29782. + case MMAL_CONTROL_TYPE_STD:
  29783. + case MMAL_CONTROL_TYPE_STD_MENU:
  29784. + case MMAL_CONTROL_TYPE_INT_MENU:
  29785. + break;
  29786. + }
  29787. +
  29788. + }
  29789. +
  29790. + return 0;
  29791. +}
  29792. diff -Nur linux-3.18.6/drivers/media/platform/bcm2835/Kconfig linux-rpi/drivers/media/platform/bcm2835/Kconfig
  29793. --- linux-3.18.6/drivers/media/platform/bcm2835/Kconfig 1970-01-01 01:00:00.000000000 +0100
  29794. +++ linux-rpi/drivers/media/platform/bcm2835/Kconfig 2015-02-09 04:40:03.000000000 +0100
  29795. @@ -0,0 +1,25 @@
  29796. +# Broadcom VideoCore IV v4l2 camera support
  29797. +
  29798. +config VIDEO_BCM2835
  29799. + bool "Broadcom BCM2835 camera interface driver"
  29800. + depends on VIDEO_V4L2 && (ARCH_BCM2708 || ARCH_BCM2709)
  29801. + ---help---
  29802. + Say Y here to enable camera host interface devices for
  29803. + Broadcom BCM2835 SoC. This operates over the VCHIQ interface
  29804. + to a service running on VideoCore.
  29805. +
  29806. +
  29807. +if VIDEO_BCM2835
  29808. +
  29809. +config VIDEO_BCM2835_MMAL
  29810. + tristate "Broadcom BM2835 MMAL camera interface driver"
  29811. + depends on BCM2708_VCHIQ
  29812. + select VIDEOBUF2_VMALLOC
  29813. + ---help---
  29814. + This is a V4L2 driver for the Broadcom BCM2835 MMAL camera host interface
  29815. +
  29816. + To compile this driver as a module, choose M here: the
  29817. + module will be called bcm2835-v4l2.o
  29818. +
  29819. +
  29820. +endif # VIDEO_BM2835
  29821. diff -Nur linux-3.18.6/drivers/media/platform/bcm2835/Makefile linux-rpi/drivers/media/platform/bcm2835/Makefile
  29822. --- linux-3.18.6/drivers/media/platform/bcm2835/Makefile 1970-01-01 01:00:00.000000000 +0100
  29823. +++ linux-rpi/drivers/media/platform/bcm2835/Makefile 2015-02-09 04:40:03.000000000 +0100
  29824. @@ -0,0 +1,5 @@
  29825. +bcm2835-v4l2-objs := bcm2835-camera.o controls.o mmal-vchiq.o
  29826. +
  29827. +obj-$(CONFIG_VIDEO_BCM2835_MMAL) += bcm2835-v4l2.o
  29828. +
  29829. +ccflags-$(CONFIG_VIDEO_BCM2835) += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  29830. diff -Nur linux-3.18.6/drivers/media/platform/bcm2835/mmal-common.h linux-rpi/drivers/media/platform/bcm2835/mmal-common.h
  29831. --- linux-3.18.6/drivers/media/platform/bcm2835/mmal-common.h 1970-01-01 01:00:00.000000000 +0100
  29832. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-common.h 2015-02-09 04:40:03.000000000 +0100
  29833. @@ -0,0 +1,53 @@
  29834. +/*
  29835. + * Broadcom BM2835 V4L2 driver
  29836. + *
  29837. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  29838. + *
  29839. + * This file is subject to the terms and conditions of the GNU General Public
  29840. + * License. See the file COPYING in the main directory of this archive
  29841. + * for more details.
  29842. + *
  29843. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  29844. + * Dave Stevenson <dsteve@broadcom.com>
  29845. + * Simon Mellor <simellor@broadcom.com>
  29846. + * Luke Diamand <luked@broadcom.com>
  29847. + *
  29848. + * MMAL structures
  29849. + *
  29850. + */
  29851. +
  29852. +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
  29853. +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
  29854. +
  29855. +/** Special value signalling that time is not known */
  29856. +#define MMAL_TIME_UNKNOWN (1LL<<63)
  29857. +
  29858. +/* mapping between v4l and mmal video modes */
  29859. +struct mmal_fmt {
  29860. + char *name;
  29861. + u32 fourcc; /* v4l2 format id */
  29862. + int flags; /* v4l2 flags field */
  29863. + u32 mmal;
  29864. + int depth;
  29865. + u32 mmal_component; /* MMAL component index to be used to encode */
  29866. +};
  29867. +
  29868. +/* buffer for one video frame */
  29869. +struct mmal_buffer {
  29870. + /* v4l buffer data -- must be first */
  29871. + struct vb2_buffer vb;
  29872. +
  29873. + /* list of buffers available */
  29874. + struct list_head list;
  29875. +
  29876. + void *buffer; /* buffer pointer */
  29877. + unsigned long buffer_size; /* size of allocated buffer */
  29878. +};
  29879. +
  29880. +/* */
  29881. +struct mmal_colourfx {
  29882. + s32 enable;
  29883. + u32 u;
  29884. + u32 v;
  29885. +};
  29886. +
  29887. diff -Nur linux-3.18.6/drivers/media/platform/bcm2835/mmal-encodings.h linux-rpi/drivers/media/platform/bcm2835/mmal-encodings.h
  29888. --- linux-3.18.6/drivers/media/platform/bcm2835/mmal-encodings.h 1970-01-01 01:00:00.000000000 +0100
  29889. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-encodings.h 2015-02-09 04:40:03.000000000 +0100
  29890. @@ -0,0 +1,127 @@
  29891. +/*
  29892. + * Broadcom BM2835 V4L2 driver
  29893. + *
  29894. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  29895. + *
  29896. + * This file is subject to the terms and conditions of the GNU General Public
  29897. + * License. See the file COPYING in the main directory of this archive
  29898. + * for more details.
  29899. + *
  29900. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  29901. + * Dave Stevenson <dsteve@broadcom.com>
  29902. + * Simon Mellor <simellor@broadcom.com>
  29903. + * Luke Diamand <luked@broadcom.com>
  29904. + */
  29905. +#ifndef MMAL_ENCODINGS_H
  29906. +#define MMAL_ENCODINGS_H
  29907. +
  29908. +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
  29909. +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
  29910. +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
  29911. +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
  29912. +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
  29913. +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
  29914. +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
  29915. +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
  29916. +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
  29917. +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
  29918. +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
  29919. +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
  29920. +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
  29921. +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
  29922. +#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
  29923. +
  29924. +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
  29925. +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
  29926. +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
  29927. +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
  29928. +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
  29929. +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
  29930. +
  29931. +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
  29932. +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
  29933. +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
  29934. +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
  29935. +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
  29936. +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
  29937. +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
  29938. +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
  29939. +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
  29940. +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
  29941. +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
  29942. +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
  29943. +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
  29944. +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
  29945. +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
  29946. +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
  29947. +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
  29948. +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
  29949. +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
  29950. +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
  29951. +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
  29952. +
  29953. +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
  29954. + * This format is *not* opaque - if requested you will receive full frames
  29955. + * of YUV_UV video.
  29956. + */
  29957. +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
  29958. +
  29959. +/** VideoCore opaque image format, image handles are returned to
  29960. + * the host but not the actual image data.
  29961. + */
  29962. +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
  29963. +
  29964. +/** An EGL image handle
  29965. + */
  29966. +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
  29967. +
  29968. +/* }@ */
  29969. +
  29970. +/** \name Pre-defined audio encodings */
  29971. +/* @{ */
  29972. +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
  29973. +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
  29974. +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
  29975. +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
  29976. +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
  29977. +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
  29978. +
  29979. +/* Pre-defined H264 encoding variants */
  29980. +
  29981. +/** ISO 14496-10 Annex B byte stream format */
  29982. +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
  29983. +/** ISO 14496-15 AVC stream format */
  29984. +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
  29985. +/** Implicitly delineated NAL units without emulation prevention */
  29986. +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
  29987. +
  29988. +
  29989. +/** \defgroup MmalColorSpace List of pre-defined video color spaces
  29990. + * This defines a list of common color spaces. This list isn't exhaustive and
  29991. + * is only provided as a convenience to avoid clients having to use FourCC
  29992. + * codes directly. However components are allowed to define and use their own
  29993. + * FourCC codes.
  29994. + */
  29995. +/* @{ */
  29996. +
  29997. +/** Unknown color space */
  29998. +#define MMAL_COLOR_SPACE_UNKNOWN 0
  29999. +/** ITU-R BT.601-5 [SDTV] */
  30000. +#define MMAL_COLOR_SPACE_ITUR_BT601 MMAL_FOURCC('Y', '6', '0', '1')
  30001. +/** ITU-R BT.709-3 [HDTV] */
  30002. +#define MMAL_COLOR_SPACE_ITUR_BT709 MMAL_FOURCC('Y', '7', '0', '9')
  30003. +/** JPEG JFIF */
  30004. +#define MMAL_COLOR_SPACE_JPEG_JFIF MMAL_FOURCC('Y', 'J', 'F', 'I')
  30005. +/** Title 47 Code of Federal Regulations (2003) 73.682 (a) (20) */
  30006. +#define MMAL_COLOR_SPACE_FCC MMAL_FOURCC('Y', 'F', 'C', 'C')
  30007. +/** Society of Motion Picture and Television Engineers 240M (1999) */
  30008. +#define MMAL_COLOR_SPACE_SMPTE240M MMAL_FOURCC('Y', '2', '4', '0')
  30009. +/** ITU-R BT.470-2 System M */
  30010. +#define MMAL_COLOR_SPACE_BT470_2_M MMAL_FOURCC('Y', '_', '_', 'M')
  30011. +/** ITU-R BT.470-2 System BG */
  30012. +#define MMAL_COLOR_SPACE_BT470_2_BG MMAL_FOURCC('Y', '_', 'B', 'G')
  30013. +/** JPEG JFIF, but with 16..255 luma */
  30014. +#define MMAL_COLOR_SPACE_JFIF_Y16_255 MMAL_FOURCC('Y', 'Y', '1', '6')
  30015. +/* @} MmalColorSpace List */
  30016. +
  30017. +#endif /* MMAL_ENCODINGS_H */
  30018. diff -Nur linux-3.18.6/drivers/media/platform/bcm2835/mmal-msg-common.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-common.h
  30019. --- linux-3.18.6/drivers/media/platform/bcm2835/mmal-msg-common.h 1970-01-01 01:00:00.000000000 +0100
  30020. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-common.h 2015-02-09 04:40:03.000000000 +0100
  30021. @@ -0,0 +1,50 @@
  30022. +/*
  30023. + * Broadcom BM2835 V4L2 driver
  30024. + *
  30025. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  30026. + *
  30027. + * This file is subject to the terms and conditions of the GNU General Public
  30028. + * License. See the file COPYING in the main directory of this archive
  30029. + * for more details.
  30030. + *
  30031. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  30032. + * Dave Stevenson <dsteve@broadcom.com>
  30033. + * Simon Mellor <simellor@broadcom.com>
  30034. + * Luke Diamand <luked@broadcom.com>
  30035. + */
  30036. +
  30037. +#ifndef MMAL_MSG_COMMON_H
  30038. +#define MMAL_MSG_COMMON_H
  30039. +
  30040. +enum mmal_msg_status {
  30041. + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
  30042. + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
  30043. + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
  30044. + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
  30045. + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
  30046. + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
  30047. + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
  30048. + MMAL_MSG_STATUS_EIO, /**< I/O error */
  30049. + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
  30050. + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
  30051. + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
  30052. + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
  30053. + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
  30054. + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
  30055. + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
  30056. + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
  30057. +};
  30058. +
  30059. +struct mmal_rect {
  30060. + s32 x; /**< x coordinate (from left) */
  30061. + s32 y; /**< y coordinate (from top) */
  30062. + s32 width; /**< width */
  30063. + s32 height; /**< height */
  30064. +};
  30065. +
  30066. +struct mmal_rational {
  30067. + s32 num; /**< Numerator */
  30068. + s32 den; /**< Denominator */
  30069. +};
  30070. +
  30071. +#endif /* MMAL_MSG_COMMON_H */
  30072. diff -Nur linux-3.18.6/drivers/media/platform/bcm2835/mmal-msg-format.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-format.h
  30073. --- linux-3.18.6/drivers/media/platform/bcm2835/mmal-msg-format.h 1970-01-01 01:00:00.000000000 +0100
  30074. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-format.h 2015-02-09 04:40:03.000000000 +0100
  30075. @@ -0,0 +1,81 @@
  30076. +/*
  30077. + * Broadcom BM2835 V4L2 driver
  30078. + *
  30079. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  30080. + *
  30081. + * This file is subject to the terms and conditions of the GNU General Public
  30082. + * License. See the file COPYING in the main directory of this archive
  30083. + * for more details.
  30084. + *
  30085. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  30086. + * Dave Stevenson <dsteve@broadcom.com>
  30087. + * Simon Mellor <simellor@broadcom.com>
  30088. + * Luke Diamand <luked@broadcom.com>
  30089. + */
  30090. +
  30091. +#ifndef MMAL_MSG_FORMAT_H
  30092. +#define MMAL_MSG_FORMAT_H
  30093. +
  30094. +#include "mmal-msg-common.h"
  30095. +
  30096. +/* MMAL_ES_FORMAT_T */
  30097. +
  30098. +
  30099. +struct mmal_audio_format {
  30100. + u32 channels; /**< Number of audio channels */
  30101. + u32 sample_rate; /**< Sample rate */
  30102. +
  30103. + u32 bits_per_sample; /**< Bits per sample */
  30104. + u32 block_align; /**< Size of a block of data */
  30105. +};
  30106. +
  30107. +struct mmal_video_format {
  30108. + u32 width; /**< Width of frame in pixels */
  30109. + u32 height; /**< Height of frame in rows of pixels */
  30110. + struct mmal_rect crop; /**< Visible region of the frame */
  30111. + struct mmal_rational frame_rate; /**< Frame rate */
  30112. + struct mmal_rational par; /**< Pixel aspect ratio */
  30113. +
  30114. + /* FourCC specifying the color space of the video stream. See the
  30115. + * \ref MmalColorSpace "pre-defined color spaces" for some examples.
  30116. + */
  30117. + u32 color_space;
  30118. +};
  30119. +
  30120. +struct mmal_subpicture_format {
  30121. + u32 x_offset;
  30122. + u32 y_offset;
  30123. +};
  30124. +
  30125. +union mmal_es_specific_format {
  30126. + struct mmal_audio_format audio;
  30127. + struct mmal_video_format video;
  30128. + struct mmal_subpicture_format subpicture;
  30129. +};
  30130. +
  30131. +/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
  30132. +struct mmal_es_format {
  30133. + u32 type; /* enum mmal_es_type */
  30134. +
  30135. + u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
  30136. + u32 encoding_variant; /* FourCC specifying the specific
  30137. + * encoding variant of the elementary
  30138. + * stream.
  30139. + */
  30140. +
  30141. + union mmal_es_specific_format *es; /* TODO: pointers in
  30142. + * message serialisation?!?
  30143. + */
  30144. + /* Type specific
  30145. + * information for the
  30146. + * elementary stream
  30147. + */
  30148. +
  30149. + u32 bitrate; /**< Bitrate in bits per second */
  30150. + u32 flags; /**< Flags describing properties of the elementary stream. */
  30151. +
  30152. + u32 extradata_size; /**< Size of the codec specific data */
  30153. + u8 *extradata; /**< Codec specific data */
  30154. +};
  30155. +
  30156. +#endif /* MMAL_MSG_FORMAT_H */
  30157. diff -Nur linux-3.18.6/drivers/media/platform/bcm2835/mmal-msg.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg.h
  30158. --- linux-3.18.6/drivers/media/platform/bcm2835/mmal-msg.h 1970-01-01 01:00:00.000000000 +0100
  30159. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg.h 2015-02-09 04:40:03.000000000 +0100
  30160. @@ -0,0 +1,404 @@
  30161. +/*
  30162. + * Broadcom BM2835 V4L2 driver
  30163. + *
  30164. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  30165. + *
  30166. + * This file is subject to the terms and conditions of the GNU General Public
  30167. + * License. See the file COPYING in the main directory of this archive
  30168. + * for more details.
  30169. + *
  30170. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  30171. + * Dave Stevenson <dsteve@broadcom.com>
  30172. + * Simon Mellor <simellor@broadcom.com>
  30173. + * Luke Diamand <luked@broadcom.com>
  30174. + */
  30175. +
  30176. +/* all the data structures which serialise the MMAL protocol. note
  30177. + * these are directly mapped onto the recived message data.
  30178. + *
  30179. + * BEWARE: They seem to *assume* pointers are u32 and that there is no
  30180. + * structure padding!
  30181. + *
  30182. + * NOTE: this implementation uses kernel types to ensure sizes. Rather
  30183. + * than assigning values to enums to force their size the
  30184. + * implementation uses fixed size types and not the enums (though the
  30185. + * comments have the actual enum type
  30186. + */
  30187. +
  30188. +#define VC_MMAL_VER 15
  30189. +#define VC_MMAL_MIN_VER 10
  30190. +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
  30191. +
  30192. +/* max total message size is 512 bytes */
  30193. +#define MMAL_MSG_MAX_SIZE 512
  30194. +/* with six 32bit header elements max payload is therefore 488 bytes */
  30195. +#define MMAL_MSG_MAX_PAYLOAD 488
  30196. +
  30197. +#include "mmal-msg-common.h"
  30198. +#include "mmal-msg-format.h"
  30199. +#include "mmal-msg-port.h"
  30200. +
  30201. +enum mmal_msg_type {
  30202. + MMAL_MSG_TYPE_QUIT = 1,
  30203. + MMAL_MSG_TYPE_SERVICE_CLOSED,
  30204. + MMAL_MSG_TYPE_GET_VERSION,
  30205. + MMAL_MSG_TYPE_COMPONENT_CREATE,
  30206. + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
  30207. + MMAL_MSG_TYPE_COMPONENT_ENABLE,
  30208. + MMAL_MSG_TYPE_COMPONENT_DISABLE,
  30209. + MMAL_MSG_TYPE_PORT_INFO_GET,
  30210. + MMAL_MSG_TYPE_PORT_INFO_SET,
  30211. + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
  30212. + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
  30213. + MMAL_MSG_TYPE_BUFFER_TO_HOST,
  30214. + MMAL_MSG_TYPE_GET_STATS,
  30215. + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
  30216. + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
  30217. + MMAL_MSG_TYPE_EVENT_TO_HOST,
  30218. + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
  30219. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
  30220. + MMAL_MSG_TYPE_CONSUME_MEM,
  30221. + MMAL_MSG_TYPE_LMK, /* 20 */
  30222. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
  30223. + MMAL_MSG_TYPE_DRM_GET_LHS32,
  30224. + MMAL_MSG_TYPE_DRM_GET_TIME,
  30225. + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
  30226. + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
  30227. + MMAL_MSG_TYPE_HOST_LOG,
  30228. + MMAL_MSG_TYPE_MSG_LAST
  30229. +};
  30230. +
  30231. +/* port action request messages differ depending on the action type */
  30232. +enum mmal_msg_port_action_type {
  30233. + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
  30234. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
  30235. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
  30236. + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
  30237. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
  30238. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
  30239. + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
  30240. +};
  30241. +
  30242. +struct mmal_msg_header {
  30243. + u32 magic;
  30244. + u32 type; /** enum mmal_msg_type */
  30245. +
  30246. + /* Opaque handle to the control service */
  30247. + struct mmal_control_service *control_service;
  30248. +
  30249. + struct mmal_msg_context *context; /** a u32 per message context */
  30250. + u32 status; /** The status of the vchiq operation */
  30251. + u32 padding;
  30252. +};
  30253. +
  30254. +/* Send from VC to host to report version */
  30255. +struct mmal_msg_version {
  30256. + u32 flags;
  30257. + u32 major;
  30258. + u32 minor;
  30259. + u32 minimum;
  30260. +};
  30261. +
  30262. +/* request to VC to create component */
  30263. +struct mmal_msg_component_create {
  30264. + void *client_component; /* component context */
  30265. + char name[128];
  30266. + u32 pid; /* For debug */
  30267. +};
  30268. +
  30269. +/* reply from VC to component creation request */
  30270. +struct mmal_msg_component_create_reply {
  30271. + u32 status; /** enum mmal_msg_status - how does this differ to
  30272. + * the one in the header?
  30273. + */
  30274. + u32 component_handle; /* VideoCore handle for component */
  30275. + u32 input_num; /* Number of input ports */
  30276. + u32 output_num; /* Number of output ports */
  30277. + u32 clock_num; /* Number of clock ports */
  30278. +};
  30279. +
  30280. +/* request to VC to destroy a component */
  30281. +struct mmal_msg_component_destroy {
  30282. + u32 component_handle;
  30283. +};
  30284. +
  30285. +struct mmal_msg_component_destroy_reply {
  30286. + u32 status; /** The component destruction status */
  30287. +};
  30288. +
  30289. +
  30290. +/* request and reply to VC to enable a component */
  30291. +struct mmal_msg_component_enable {
  30292. + u32 component_handle;
  30293. +};
  30294. +
  30295. +struct mmal_msg_component_enable_reply {
  30296. + u32 status; /** The component enable status */
  30297. +};
  30298. +
  30299. +
  30300. +/* request and reply to VC to disable a component */
  30301. +struct mmal_msg_component_disable {
  30302. + u32 component_handle;
  30303. +};
  30304. +
  30305. +struct mmal_msg_component_disable_reply {
  30306. + u32 status; /** The component disable status */
  30307. +};
  30308. +
  30309. +/* request to VC to get port information */
  30310. +struct mmal_msg_port_info_get {
  30311. + u32 component_handle; /* component handle port is associated with */
  30312. + u32 port_type; /* enum mmal_msg_port_type */
  30313. + u32 index; /* port index to query */
  30314. +};
  30315. +
  30316. +/* reply from VC to get port info request */
  30317. +struct mmal_msg_port_info_get_reply {
  30318. + u32 status; /** enum mmal_msg_status */
  30319. + u32 component_handle; /* component handle port is associated with */
  30320. + u32 port_type; /* enum mmal_msg_port_type */
  30321. + u32 port_index; /* port indexed in query */
  30322. + s32 found; /* unused */
  30323. + u32 port_handle; /**< Handle to use for this port */
  30324. + struct mmal_port port;
  30325. + struct mmal_es_format format; /* elementry stream format */
  30326. + union mmal_es_specific_format es; /* es type specific data */
  30327. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
  30328. +};
  30329. +
  30330. +/* request to VC to set port information */
  30331. +struct mmal_msg_port_info_set {
  30332. + u32 component_handle;
  30333. + u32 port_type; /* enum mmal_msg_port_type */
  30334. + u32 port_index; /* port indexed in query */
  30335. + struct mmal_port port;
  30336. + struct mmal_es_format format;
  30337. + union mmal_es_specific_format es;
  30338. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  30339. +};
  30340. +
  30341. +/* reply from VC to port info set request */
  30342. +struct mmal_msg_port_info_set_reply {
  30343. + u32 status;
  30344. + u32 component_handle; /* component handle port is associated with */
  30345. + u32 port_type; /* enum mmal_msg_port_type */
  30346. + u32 index; /* port indexed in query */
  30347. + s32 found; /* unused */
  30348. + u32 port_handle; /**< Handle to use for this port */
  30349. + struct mmal_port port;
  30350. + struct mmal_es_format format;
  30351. + union mmal_es_specific_format es;
  30352. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  30353. +};
  30354. +
  30355. +
  30356. +/* port action requests that take a mmal_port as a parameter */
  30357. +struct mmal_msg_port_action_port {
  30358. + u32 component_handle;
  30359. + u32 port_handle;
  30360. + u32 action; /* enum mmal_msg_port_action_type */
  30361. + struct mmal_port port;
  30362. +};
  30363. +
  30364. +/* port action requests that take handles as a parameter */
  30365. +struct mmal_msg_port_action_handle {
  30366. + u32 component_handle;
  30367. + u32 port_handle;
  30368. + u32 action; /* enum mmal_msg_port_action_type */
  30369. + u32 connect_component_handle;
  30370. + u32 connect_port_handle;
  30371. +};
  30372. +
  30373. +struct mmal_msg_port_action_reply {
  30374. + u32 status; /** The port action operation status */
  30375. +};
  30376. +
  30377. +
  30378. +
  30379. +
  30380. +/* MMAL buffer transfer */
  30381. +
  30382. +/** Size of space reserved in a buffer message for short messages. */
  30383. +#define MMAL_VC_SHORT_DATA 128
  30384. +
  30385. +/** Signals that the current payload is the end of the stream of data */
  30386. +#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
  30387. +/** Signals that the start of the current payload starts a frame */
  30388. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
  30389. +/** Signals that the end of the current payload ends a frame */
  30390. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
  30391. +/** Signals that the current payload contains only complete frames (>1) */
  30392. +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
  30393. + (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  30394. +/** Signals that the current payload is a keyframe (i.e. self decodable) */
  30395. +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
  30396. +/** Signals a discontinuity in the stream of data (e.g. after a seek).
  30397. + * Can be used for instance by a decoder to reset its state */
  30398. +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
  30399. +/** Signals a buffer containing some kind of config data for the component
  30400. + * (e.g. codec config data) */
  30401. +#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
  30402. +/** Signals an encrypted payload */
  30403. +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
  30404. +/** Signals a buffer containing side information */
  30405. +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
  30406. +/** Signals a buffer which is the snapshot/postview image from a stills
  30407. + * capture
  30408. + */
  30409. +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
  30410. +/** Signals a buffer which contains data known to be corrupted */
  30411. +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
  30412. +/** Signals that a buffer failed to be transmitted */
  30413. +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
  30414. +
  30415. +struct mmal_driver_buffer {
  30416. + u32 magic;
  30417. + u32 component_handle;
  30418. + u32 port_handle;
  30419. + void *client_context;
  30420. +};
  30421. +
  30422. +/* buffer header */
  30423. +struct mmal_buffer_header {
  30424. + struct mmal_buffer_header *next; /* next header */
  30425. + void *priv; /* framework private data */
  30426. + u32 cmd;
  30427. + void *data;
  30428. + u32 alloc_size;
  30429. + u32 length;
  30430. + u32 offset;
  30431. + u32 flags;
  30432. + s64 pts;
  30433. + s64 dts;
  30434. + void *type;
  30435. + void *user_data;
  30436. +};
  30437. +
  30438. +struct mmal_buffer_header_type_specific {
  30439. + union {
  30440. + struct {
  30441. + u32 planes;
  30442. + u32 offset[4];
  30443. + u32 pitch[4];
  30444. + u32 flags;
  30445. + } video;
  30446. + } u;
  30447. +};
  30448. +
  30449. +struct mmal_msg_buffer_from_host {
  30450. + /* The front 32 bytes of the buffer header are copied
  30451. + * back to us in the reply to allow for context. This
  30452. + * area is used to store two mmal_driver_buffer structures to
  30453. + * allow for multiple concurrent service users.
  30454. + */
  30455. + /* control data */
  30456. + struct mmal_driver_buffer drvbuf;
  30457. +
  30458. + /* referenced control data for passthrough buffer management */
  30459. + struct mmal_driver_buffer drvbuf_ref;
  30460. + struct mmal_buffer_header buffer_header; /* buffer header itself */
  30461. + struct mmal_buffer_header_type_specific buffer_header_type_specific;
  30462. + s32 is_zero_copy;
  30463. + s32 has_reference;
  30464. +
  30465. + /** allows short data to be xfered in control message */
  30466. + u32 payload_in_message;
  30467. + u8 short_data[MMAL_VC_SHORT_DATA];
  30468. +};
  30469. +
  30470. +
  30471. +/* port parameter setting */
  30472. +
  30473. +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
  30474. +
  30475. +struct mmal_msg_port_parameter_set {
  30476. + u32 component_handle; /* component */
  30477. + u32 port_handle; /* port */
  30478. + u32 id; /* Parameter ID */
  30479. + u32 size; /* Parameter size */
  30480. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  30481. +};
  30482. +
  30483. +struct mmal_msg_port_parameter_set_reply {
  30484. + u32 status; /** enum mmal_msg_status todo: how does this
  30485. + * differ to the one in the header?
  30486. + */
  30487. +};
  30488. +
  30489. +/* port parameter getting */
  30490. +
  30491. +struct mmal_msg_port_parameter_get {
  30492. + u32 component_handle; /* component */
  30493. + u32 port_handle; /* port */
  30494. + u32 id; /* Parameter ID */
  30495. + u32 size; /* Parameter size */
  30496. +};
  30497. +
  30498. +struct mmal_msg_port_parameter_get_reply {
  30499. + u32 status; /* Status of mmal_port_parameter_get call */
  30500. + u32 id; /* Parameter ID */
  30501. + u32 size; /* Parameter size */
  30502. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  30503. +};
  30504. +
  30505. +/* event messages */
  30506. +#define MMAL_WORKER_EVENT_SPACE 256
  30507. +
  30508. +struct mmal_msg_event_to_host {
  30509. + void *client_component; /* component context */
  30510. +
  30511. + u32 port_type;
  30512. + u32 port_num;
  30513. +
  30514. + u32 cmd;
  30515. + u32 length;
  30516. + u8 data[MMAL_WORKER_EVENT_SPACE];
  30517. + struct mmal_buffer_header *delayed_buffer;
  30518. +};
  30519. +
  30520. +/* all mmal messages are serialised through this structure */
  30521. +struct mmal_msg {
  30522. + /* header */
  30523. + struct mmal_msg_header h;
  30524. + /* payload */
  30525. + union {
  30526. + struct mmal_msg_version version;
  30527. +
  30528. + struct mmal_msg_component_create component_create;
  30529. + struct mmal_msg_component_create_reply component_create_reply;
  30530. +
  30531. + struct mmal_msg_component_destroy component_destroy;
  30532. + struct mmal_msg_component_destroy_reply component_destroy_reply;
  30533. +
  30534. + struct mmal_msg_component_enable component_enable;
  30535. + struct mmal_msg_component_enable_reply component_enable_reply;
  30536. +
  30537. + struct mmal_msg_component_disable component_disable;
  30538. + struct mmal_msg_component_disable_reply component_disable_reply;
  30539. +
  30540. + struct mmal_msg_port_info_get port_info_get;
  30541. + struct mmal_msg_port_info_get_reply port_info_get_reply;
  30542. +
  30543. + struct mmal_msg_port_info_set port_info_set;
  30544. + struct mmal_msg_port_info_set_reply port_info_set_reply;
  30545. +
  30546. + struct mmal_msg_port_action_port port_action_port;
  30547. + struct mmal_msg_port_action_handle port_action_handle;
  30548. + struct mmal_msg_port_action_reply port_action_reply;
  30549. +
  30550. + struct mmal_msg_buffer_from_host buffer_from_host;
  30551. +
  30552. + struct mmal_msg_port_parameter_set port_parameter_set;
  30553. + struct mmal_msg_port_parameter_set_reply
  30554. + port_parameter_set_reply;
  30555. + struct mmal_msg_port_parameter_get
  30556. + port_parameter_get;
  30557. + struct mmal_msg_port_parameter_get_reply
  30558. + port_parameter_get_reply;
  30559. +
  30560. + struct mmal_msg_event_to_host event_to_host;
  30561. +
  30562. + u8 payload[MMAL_MSG_MAX_PAYLOAD];
  30563. + } u;
  30564. +};
  30565. diff -Nur linux-3.18.6/drivers/media/platform/bcm2835/mmal-msg-port.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-port.h
  30566. --- linux-3.18.6/drivers/media/platform/bcm2835/mmal-msg-port.h 1970-01-01 01:00:00.000000000 +0100
  30567. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-port.h 2015-02-09 04:40:03.000000000 +0100
  30568. @@ -0,0 +1,107 @@
  30569. +/*
  30570. + * Broadcom BM2835 V4L2 driver
  30571. + *
  30572. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  30573. + *
  30574. + * This file is subject to the terms and conditions of the GNU General Public
  30575. + * License. See the file COPYING in the main directory of this archive
  30576. + * for more details.
  30577. + *
  30578. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  30579. + * Dave Stevenson <dsteve@broadcom.com>
  30580. + * Simon Mellor <simellor@broadcom.com>
  30581. + * Luke Diamand <luked@broadcom.com>
  30582. + */
  30583. +
  30584. +/* MMAL_PORT_TYPE_T */
  30585. +enum mmal_port_type {
  30586. + MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
  30587. + MMAL_PORT_TYPE_CONTROL, /**< Control port */
  30588. + MMAL_PORT_TYPE_INPUT, /**< Input port */
  30589. + MMAL_PORT_TYPE_OUTPUT, /**< Output port */
  30590. + MMAL_PORT_TYPE_CLOCK, /**< Clock port */
  30591. +};
  30592. +
  30593. +/** The port is pass-through and doesn't need buffer headers allocated */
  30594. +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
  30595. +/** The port wants to allocate the buffer payloads.
  30596. + * This signals a preference that payload allocation should be done
  30597. + * on this port for efficiency reasons. */
  30598. +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
  30599. +/** The port supports format change events.
  30600. + * This applies to input ports and is used to let the client know
  30601. + * whether the port supports being reconfigured via a format
  30602. + * change event (i.e. without having to disable the port). */
  30603. +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
  30604. +
  30605. +/* mmal port structure (MMAL_PORT_T)
  30606. + *
  30607. + * most elements are informational only, the pointer values for
  30608. + * interogation messages are generally provided as additional
  30609. + * strucures within the message. When used to set values only teh
  30610. + * buffer_num, buffer_size and userdata parameters are writable.
  30611. + */
  30612. +struct mmal_port {
  30613. + void *priv; /* Private member used by the framework */
  30614. + const char *name; /* Port name. Used for debugging purposes (RO) */
  30615. +
  30616. + u32 type; /* Type of the port (RO) enum mmal_port_type */
  30617. + u16 index; /* Index of the port in its type list (RO) */
  30618. + u16 index_all; /* Index of the port in the list of all ports (RO) */
  30619. +
  30620. + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
  30621. + struct mmal_es_format *format; /* Format of the elementary stream */
  30622. +
  30623. + u32 buffer_num_min; /* Minimum number of buffers the port
  30624. + * requires (RO). This is set by the
  30625. + * component.
  30626. + */
  30627. +
  30628. + u32 buffer_size_min; /* Minimum size of buffers the port
  30629. + * requires (RO). This is set by the
  30630. + * component.
  30631. + */
  30632. +
  30633. + u32 buffer_alignment_min; /* Minimum alignment requirement for
  30634. + * the buffers (RO). A value of
  30635. + * zero means no special alignment
  30636. + * requirements. This is set by the
  30637. + * component.
  30638. + */
  30639. +
  30640. + u32 buffer_num_recommended; /* Number of buffers the port
  30641. + * recommends for optimal
  30642. + * performance (RO). A value of
  30643. + * zero means no special
  30644. + * recommendation. This is set
  30645. + * by the component.
  30646. + */
  30647. +
  30648. + u32 buffer_size_recommended; /* Size of buffers the port
  30649. + * recommends for optimal
  30650. + * performance (RO). A value of
  30651. + * zero means no special
  30652. + * recommendation. This is set
  30653. + * by the component.
  30654. + */
  30655. +
  30656. + u32 buffer_num; /* Actual number of buffers the port will use.
  30657. + * This is set by the client.
  30658. + */
  30659. +
  30660. + u32 buffer_size; /* Actual maximum size of the buffers that
  30661. + * will be sent to the port. This is set by
  30662. + * the client.
  30663. + */
  30664. +
  30665. + void *component; /* Component this port belongs to (Read Only) */
  30666. +
  30667. + void *userdata; /* Field reserved for use by the client */
  30668. +
  30669. + u32 capabilities; /* Flags describing the capabilities of a
  30670. + * port (RO). Bitwise combination of \ref
  30671. + * portcapabilities "Port capabilities"
  30672. + * values.
  30673. + */
  30674. +
  30675. +};
  30676. diff -Nur linux-3.18.6/drivers/media/platform/bcm2835/mmal-parameters.h linux-rpi/drivers/media/platform/bcm2835/mmal-parameters.h
  30677. --- linux-3.18.6/drivers/media/platform/bcm2835/mmal-parameters.h 1970-01-01 01:00:00.000000000 +0100
  30678. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-parameters.h 2015-02-09 04:40:03.000000000 +0100
  30679. @@ -0,0 +1,656 @@
  30680. +/*
  30681. + * Broadcom BM2835 V4L2 driver
  30682. + *
  30683. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  30684. + *
  30685. + * This file is subject to the terms and conditions of the GNU General Public
  30686. + * License. See the file COPYING in the main directory of this archive
  30687. + * for more details.
  30688. + *
  30689. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  30690. + * Dave Stevenson <dsteve@broadcom.com>
  30691. + * Simon Mellor <simellor@broadcom.com>
  30692. + * Luke Diamand <luked@broadcom.com>
  30693. + */
  30694. +
  30695. +/* common parameters */
  30696. +
  30697. +/** @name Parameter groups
  30698. + * Parameters are divided into groups, and then allocated sequentially within
  30699. + * a group using an enum.
  30700. + * @{
  30701. + */
  30702. +
  30703. +/** Common parameter ID group, used with many types of component. */
  30704. +#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
  30705. +/** Camera-specific parameter ID group. */
  30706. +#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
  30707. +/** Video-specific parameter ID group. */
  30708. +#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
  30709. +/** Audio-specific parameter ID group. */
  30710. +#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
  30711. +/** Clock-specific parameter ID group. */
  30712. +#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
  30713. +/** Miracast-specific parameter ID group. */
  30714. +#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
  30715. +
  30716. +/* Common parameters */
  30717. +enum mmal_parameter_common_type {
  30718. + MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
  30719. + = MMAL_PARAMETER_GROUP_COMMON,
  30720. + MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
  30721. + MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
  30722. +
  30723. + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
  30724. + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
  30725. +
  30726. + /** MMAL_PARAMETER_BOOLEAN_T */
  30727. + MMAL_PARAMETER_ZERO_COPY,
  30728. +
  30729. + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
  30730. + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
  30731. +
  30732. + MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
  30733. + MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
  30734. + MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
  30735. + MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
  30736. + MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
  30737. + MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
  30738. + MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
  30739. + MMAL_PARAMETER_SYSTEM_TIME, /**< MMAL_PARAMETER_UINT64_T */
  30740. + MMAL_PARAMETER_NO_IMAGE_PADDING /**< MMAL_PARAMETER_BOOLEAN_T */
  30741. +};
  30742. +
  30743. +/* camera parameters */
  30744. +
  30745. +enum mmal_parameter_camera_type {
  30746. + /* 0 */
  30747. + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
  30748. + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
  30749. + = MMAL_PARAMETER_GROUP_CAMERA,
  30750. + MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
  30751. + MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
  30752. + MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30753. + MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
  30754. + MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
  30755. + MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
  30756. + MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
  30757. + MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
  30758. + MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
  30759. + MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
  30760. + MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
  30761. + MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
  30762. + MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  30763. + MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
  30764. + MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
  30765. +
  30766. + /* 0x10 */
  30767. + MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
  30768. + MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30769. + MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
  30770. + MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
  30771. + MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
  30772. + MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
  30773. + MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
  30774. + MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
  30775. + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30776. + MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
  30777. + MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
  30778. + MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
  30779. + MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
  30780. + MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30781. + MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
  30782. + MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30783. +
  30784. + /* 0x20 */
  30785. + MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
  30786. + MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30787. + MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30788. + MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
  30789. + MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
  30790. + MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
  30791. + MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
  30792. + MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
  30793. + MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
  30794. + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30795. + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
  30796. + MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
  30797. + MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  30798. + MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  30799. + MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  30800. + MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  30801. +
  30802. + /* 0x30 */
  30803. + MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
  30804. + MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30805. +
  30806. + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
  30807. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  30808. +
  30809. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  30810. + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
  30811. +
  30812. + /** @ref MMAL_PARAMETER_UINT32_T */
  30813. + MMAL_PARAMETER_CAMERA_MIN_ISO,
  30814. +
  30815. + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
  30816. + MMAL_PARAMETER_CAMERA_USE_CASE,
  30817. +
  30818. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30819. + MMAL_PARAMETER_CAPTURE_STATS_PASS,
  30820. +
  30821. + /** @ref MMAL_PARAMETER_UINT32_T */
  30822. + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
  30823. +
  30824. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  30825. + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
  30826. +
  30827. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  30828. + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
  30829. +
  30830. + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
  30831. + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
  30832. +
  30833. + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
  30834. + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
  30835. + MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30836. + MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
  30837. + MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
  30838. + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  30839. +
  30840. + /* 0x40 */
  30841. + MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30842. + MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30843. + MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  30844. + MMAL_PARAMETER_SHUTTER_SPEED, /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
  30845. + MMAL_PARAMETER_CUSTOM_AWB_GAINS, /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
  30846. +};
  30847. +
  30848. +struct mmal_parameter_rational {
  30849. + s32 num; /**< Numerator */
  30850. + s32 den; /**< Denominator */
  30851. +};
  30852. +
  30853. +enum mmal_parameter_camera_config_timestamp_mode {
  30854. + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
  30855. + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
  30856. + * for the frame timestamp
  30857. + */
  30858. + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
  30859. + * but subtract the
  30860. + * timestamp of the first
  30861. + * frame sent to give a
  30862. + * zero based timestamp.
  30863. + */
  30864. +};
  30865. +
  30866. +struct mmal_parameter_fps_range {
  30867. + /**< Low end of the permitted framerate range */
  30868. + struct mmal_parameter_rational fps_low;
  30869. + /**< High end of the permitted framerate range */
  30870. + struct mmal_parameter_rational fps_high;
  30871. +};
  30872. +
  30873. +
  30874. +/* camera configuration parameter */
  30875. +struct mmal_parameter_camera_config {
  30876. + /* Parameters for setting up the image pools */
  30877. + u32 max_stills_w; /* Max size of stills capture */
  30878. + u32 max_stills_h;
  30879. + u32 stills_yuv422; /* Allow YUV422 stills capture */
  30880. + u32 one_shot_stills; /* Continuous or one shot stills captures. */
  30881. +
  30882. + u32 max_preview_video_w; /* Max size of the preview or video
  30883. + * capture frames
  30884. + */
  30885. + u32 max_preview_video_h;
  30886. + u32 num_preview_video_frames;
  30887. +
  30888. + /** Sets the height of the circular buffer for stills capture. */
  30889. + u32 stills_capture_circular_buffer_height;
  30890. +
  30891. + /** Allows preview/encode to resume as fast as possible after the stills
  30892. + * input frame has been received, and then processes the still frame in
  30893. + * the background whilst preview/encode has resumed.
  30894. + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
  30895. + */
  30896. + u32 fast_preview_resume;
  30897. +
  30898. + /** Selects algorithm for timestamping frames if
  30899. + * there is no clock component connected.
  30900. + * enum mmal_parameter_camera_config_timestamp_mode
  30901. + */
  30902. + s32 use_stc_timestamp;
  30903. +};
  30904. +
  30905. +
  30906. +enum mmal_parameter_exposuremode {
  30907. + MMAL_PARAM_EXPOSUREMODE_OFF,
  30908. + MMAL_PARAM_EXPOSUREMODE_AUTO,
  30909. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  30910. + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
  30911. + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
  30912. + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
  30913. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  30914. + MMAL_PARAM_EXPOSUREMODE_SNOW,
  30915. + MMAL_PARAM_EXPOSUREMODE_BEACH,
  30916. + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
  30917. + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
  30918. + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
  30919. + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
  30920. +};
  30921. +
  30922. +enum mmal_parameter_exposuremeteringmode {
  30923. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
  30924. + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
  30925. + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
  30926. + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
  30927. +};
  30928. +
  30929. +enum mmal_parameter_awbmode {
  30930. + MMAL_PARAM_AWBMODE_OFF,
  30931. + MMAL_PARAM_AWBMODE_AUTO,
  30932. + MMAL_PARAM_AWBMODE_SUNLIGHT,
  30933. + MMAL_PARAM_AWBMODE_CLOUDY,
  30934. + MMAL_PARAM_AWBMODE_SHADE,
  30935. + MMAL_PARAM_AWBMODE_TUNGSTEN,
  30936. + MMAL_PARAM_AWBMODE_FLUORESCENT,
  30937. + MMAL_PARAM_AWBMODE_INCANDESCENT,
  30938. + MMAL_PARAM_AWBMODE_FLASH,
  30939. + MMAL_PARAM_AWBMODE_HORIZON,
  30940. +};
  30941. +
  30942. +enum mmal_parameter_imagefx {
  30943. + MMAL_PARAM_IMAGEFX_NONE,
  30944. + MMAL_PARAM_IMAGEFX_NEGATIVE,
  30945. + MMAL_PARAM_IMAGEFX_SOLARIZE,
  30946. + MMAL_PARAM_IMAGEFX_POSTERIZE,
  30947. + MMAL_PARAM_IMAGEFX_WHITEBOARD,
  30948. + MMAL_PARAM_IMAGEFX_BLACKBOARD,
  30949. + MMAL_PARAM_IMAGEFX_SKETCH,
  30950. + MMAL_PARAM_IMAGEFX_DENOISE,
  30951. + MMAL_PARAM_IMAGEFX_EMBOSS,
  30952. + MMAL_PARAM_IMAGEFX_OILPAINT,
  30953. + MMAL_PARAM_IMAGEFX_HATCH,
  30954. + MMAL_PARAM_IMAGEFX_GPEN,
  30955. + MMAL_PARAM_IMAGEFX_PASTEL,
  30956. + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  30957. + MMAL_PARAM_IMAGEFX_FILM,
  30958. + MMAL_PARAM_IMAGEFX_BLUR,
  30959. + MMAL_PARAM_IMAGEFX_SATURATION,
  30960. + MMAL_PARAM_IMAGEFX_COLOURSWAP,
  30961. + MMAL_PARAM_IMAGEFX_WASHEDOUT,
  30962. + MMAL_PARAM_IMAGEFX_POSTERISE,
  30963. + MMAL_PARAM_IMAGEFX_COLOURPOINT,
  30964. + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  30965. + MMAL_PARAM_IMAGEFX_CARTOON,
  30966. +};
  30967. +
  30968. +enum MMAL_PARAM_FLICKERAVOID_T {
  30969. + MMAL_PARAM_FLICKERAVOID_OFF,
  30970. + MMAL_PARAM_FLICKERAVOID_AUTO,
  30971. + MMAL_PARAM_FLICKERAVOID_50HZ,
  30972. + MMAL_PARAM_FLICKERAVOID_60HZ,
  30973. + MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
  30974. +};
  30975. +
  30976. +struct mmal_parameter_awbgains {
  30977. + struct mmal_parameter_rational r_gain; /**< Red gain */
  30978. + struct mmal_parameter_rational b_gain; /**< Blue gain */
  30979. +};
  30980. +
  30981. +/** Manner of video rate control */
  30982. +enum mmal_parameter_rate_control_mode {
  30983. + MMAL_VIDEO_RATECONTROL_DEFAULT,
  30984. + MMAL_VIDEO_RATECONTROL_VARIABLE,
  30985. + MMAL_VIDEO_RATECONTROL_CONSTANT,
  30986. + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
  30987. + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
  30988. +};
  30989. +
  30990. +enum mmal_video_profile {
  30991. + MMAL_VIDEO_PROFILE_H263_BASELINE,
  30992. + MMAL_VIDEO_PROFILE_H263_H320CODING,
  30993. + MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE,
  30994. + MMAL_VIDEO_PROFILE_H263_ISWV2,
  30995. + MMAL_VIDEO_PROFILE_H263_ISWV3,
  30996. + MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION,
  30997. + MMAL_VIDEO_PROFILE_H263_INTERNET,
  30998. + MMAL_VIDEO_PROFILE_H263_INTERLACE,
  30999. + MMAL_VIDEO_PROFILE_H263_HIGHLATENCY,
  31000. + MMAL_VIDEO_PROFILE_MP4V_SIMPLE,
  31001. + MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE,
  31002. + MMAL_VIDEO_PROFILE_MP4V_CORE,
  31003. + MMAL_VIDEO_PROFILE_MP4V_MAIN,
  31004. + MMAL_VIDEO_PROFILE_MP4V_NBIT,
  31005. + MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE,
  31006. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE,
  31007. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA,
  31008. + MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED,
  31009. + MMAL_VIDEO_PROFILE_MP4V_HYBRID,
  31010. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME,
  31011. + MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE,
  31012. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING,
  31013. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE,
  31014. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE,
  31015. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE,
  31016. + MMAL_VIDEO_PROFILE_H264_BASELINE,
  31017. + MMAL_VIDEO_PROFILE_H264_MAIN,
  31018. + MMAL_VIDEO_PROFILE_H264_EXTENDED,
  31019. + MMAL_VIDEO_PROFILE_H264_HIGH,
  31020. + MMAL_VIDEO_PROFILE_H264_HIGH10,
  31021. + MMAL_VIDEO_PROFILE_H264_HIGH422,
  31022. + MMAL_VIDEO_PROFILE_H264_HIGH444,
  31023. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE,
  31024. + MMAL_VIDEO_PROFILE_DUMMY = 0x7FFFFFFF
  31025. +};
  31026. +
  31027. +enum mmal_video_level {
  31028. + MMAL_VIDEO_LEVEL_H263_10,
  31029. + MMAL_VIDEO_LEVEL_H263_20,
  31030. + MMAL_VIDEO_LEVEL_H263_30,
  31031. + MMAL_VIDEO_LEVEL_H263_40,
  31032. + MMAL_VIDEO_LEVEL_H263_45,
  31033. + MMAL_VIDEO_LEVEL_H263_50,
  31034. + MMAL_VIDEO_LEVEL_H263_60,
  31035. + MMAL_VIDEO_LEVEL_H263_70,
  31036. + MMAL_VIDEO_LEVEL_MP4V_0,
  31037. + MMAL_VIDEO_LEVEL_MP4V_0b,
  31038. + MMAL_VIDEO_LEVEL_MP4V_1,
  31039. + MMAL_VIDEO_LEVEL_MP4V_2,
  31040. + MMAL_VIDEO_LEVEL_MP4V_3,
  31041. + MMAL_VIDEO_LEVEL_MP4V_4,
  31042. + MMAL_VIDEO_LEVEL_MP4V_4a,
  31043. + MMAL_VIDEO_LEVEL_MP4V_5,
  31044. + MMAL_VIDEO_LEVEL_MP4V_6,
  31045. + MMAL_VIDEO_LEVEL_H264_1,
  31046. + MMAL_VIDEO_LEVEL_H264_1b,
  31047. + MMAL_VIDEO_LEVEL_H264_11,
  31048. + MMAL_VIDEO_LEVEL_H264_12,
  31049. + MMAL_VIDEO_LEVEL_H264_13,
  31050. + MMAL_VIDEO_LEVEL_H264_2,
  31051. + MMAL_VIDEO_LEVEL_H264_21,
  31052. + MMAL_VIDEO_LEVEL_H264_22,
  31053. + MMAL_VIDEO_LEVEL_H264_3,
  31054. + MMAL_VIDEO_LEVEL_H264_31,
  31055. + MMAL_VIDEO_LEVEL_H264_32,
  31056. + MMAL_VIDEO_LEVEL_H264_4,
  31057. + MMAL_VIDEO_LEVEL_H264_41,
  31058. + MMAL_VIDEO_LEVEL_H264_42,
  31059. + MMAL_VIDEO_LEVEL_H264_5,
  31060. + MMAL_VIDEO_LEVEL_H264_51,
  31061. + MMAL_VIDEO_LEVEL_DUMMY = 0x7FFFFFFF
  31062. +};
  31063. +
  31064. +struct mmal_parameter_video_profile {
  31065. + enum mmal_video_profile profile;
  31066. + enum mmal_video_level level;
  31067. +};
  31068. +
  31069. +/* video parameters */
  31070. +
  31071. +enum mmal_parameter_video_type {
  31072. + /** @ref MMAL_DISPLAYREGION_T */
  31073. + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
  31074. +
  31075. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  31076. + MMAL_PARAMETER_SUPPORTED_PROFILES,
  31077. +
  31078. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  31079. + MMAL_PARAMETER_PROFILE,
  31080. +
  31081. + /** @ref MMAL_PARAMETER_UINT32_T */
  31082. + MMAL_PARAMETER_INTRAPERIOD,
  31083. +
  31084. + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
  31085. + MMAL_PARAMETER_RATECONTROL,
  31086. +
  31087. + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
  31088. + MMAL_PARAMETER_NALUNITFORMAT,
  31089. +
  31090. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  31091. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  31092. +
  31093. + /** @ref MMAL_PARAMETER_UINT32_T.
  31094. + * Setting the value to zero resets to the default (one slice per frame).
  31095. + */
  31096. + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
  31097. +
  31098. + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
  31099. + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
  31100. +
  31101. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
  31102. + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
  31103. +
  31104. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
  31105. + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
  31106. +
  31107. + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
  31108. + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
  31109. + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
  31110. + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
  31111. +
  31112. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  31113. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  31114. +
  31115. + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
  31116. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  31117. +
  31118. + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
  31119. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  31120. +
  31121. + /** @ref MMAL_PARAMETER_UINT32_T. */
  31122. + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
  31123. +
  31124. + /** @ref MMAL_PARAMETER_UINT32_T. */
  31125. + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
  31126. +
  31127. + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
  31128. + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
  31129. +
  31130. + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
  31131. + /** @ref MMAL_PARAMETER_UINT32_T.
  31132. + * Changing this parameter from the default can reduce frame rate
  31133. + * because image buffers need to be re-pitched.
  31134. + */
  31135. + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
  31136. +
  31137. + /** @ref MMAL_PARAMETER_UINT32_T.
  31138. + * Changing this parameter from the default can reduce frame rate
  31139. + * because image buffers need to be re-pitched.
  31140. + */
  31141. + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
  31142. +
  31143. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  31144. + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
  31145. +
  31146. + /** @ref MMAL_PARAMETER_UINT32_T. */
  31147. + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
  31148. +
  31149. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  31150. + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
  31151. +
  31152. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  31153. + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
  31154. +
  31155. + /** @ref MMAL_PARAMETER_UINT32_T */
  31156. + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
  31157. +
  31158. + /** @ref MMAL_PARAMETER_UINT32_T. */
  31159. + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
  31160. +
  31161. + /* H264 specific parameters */
  31162. +
  31163. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  31164. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
  31165. +
  31166. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  31167. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
  31168. +
  31169. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  31170. + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
  31171. +
  31172. + /** @ref MMAL_PARAMETER_UINT32_T. */
  31173. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
  31174. +
  31175. + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
  31176. + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
  31177. +
  31178. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  31179. + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
  31180. +
  31181. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  31182. + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
  31183. +
  31184. + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
  31185. + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
  31186. +
  31187. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  31188. + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
  31189. +
  31190. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  31191. + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
  31192. +
  31193. + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
  31194. + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
  31195. +
  31196. + /** @ref MMAL_PARAMETER_BYTES_T */
  31197. + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
  31198. +
  31199. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  31200. + MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
  31201. +
  31202. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  31203. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
  31204. +
  31205. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  31206. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
  31207. +};
  31208. +
  31209. +/** Valid mirror modes */
  31210. +enum mmal_parameter_mirror {
  31211. + MMAL_PARAM_MIRROR_NONE,
  31212. + MMAL_PARAM_MIRROR_VERTICAL,
  31213. + MMAL_PARAM_MIRROR_HORIZONTAL,
  31214. + MMAL_PARAM_MIRROR_BOTH,
  31215. +};
  31216. +
  31217. +enum mmal_parameter_displaytransform {
  31218. + MMAL_DISPLAY_ROT0 = 0,
  31219. + MMAL_DISPLAY_MIRROR_ROT0 = 1,
  31220. + MMAL_DISPLAY_MIRROR_ROT180 = 2,
  31221. + MMAL_DISPLAY_ROT180 = 3,
  31222. + MMAL_DISPLAY_MIRROR_ROT90 = 4,
  31223. + MMAL_DISPLAY_ROT270 = 5,
  31224. + MMAL_DISPLAY_ROT90 = 6,
  31225. + MMAL_DISPLAY_MIRROR_ROT270 = 7,
  31226. +};
  31227. +
  31228. +enum mmal_parameter_displaymode {
  31229. + MMAL_DISPLAY_MODE_FILL = 0,
  31230. + MMAL_DISPLAY_MODE_LETTERBOX = 1,
  31231. +};
  31232. +
  31233. +enum mmal_parameter_displayset {
  31234. + MMAL_DISPLAY_SET_NONE = 0,
  31235. + MMAL_DISPLAY_SET_NUM = 1,
  31236. + MMAL_DISPLAY_SET_FULLSCREEN = 2,
  31237. + MMAL_DISPLAY_SET_TRANSFORM = 4,
  31238. + MMAL_DISPLAY_SET_DEST_RECT = 8,
  31239. + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
  31240. + MMAL_DISPLAY_SET_MODE = 0x20,
  31241. + MMAL_DISPLAY_SET_PIXEL = 0x40,
  31242. + MMAL_DISPLAY_SET_NOASPECT = 0x80,
  31243. + MMAL_DISPLAY_SET_LAYER = 0x100,
  31244. + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
  31245. + MMAL_DISPLAY_SET_ALPHA = 0x400,
  31246. +};
  31247. +
  31248. +struct mmal_parameter_displayregion {
  31249. + /** Bitfield that indicates which fields are set and should be
  31250. + * used. All other fields will maintain their current value.
  31251. + * \ref MMAL_DISPLAYSET_T defines the bits that can be
  31252. + * combined.
  31253. + */
  31254. + u32 set;
  31255. +
  31256. + /** Describes the display output device, with 0 typically
  31257. + * being a directly connected LCD display. The actual values
  31258. + * will depend on the hardware. Code using hard-wired numbers
  31259. + * (e.g. 2) is certain to fail.
  31260. + */
  31261. +
  31262. + u32 display_num;
  31263. + /** Indicates that we are using the full device screen area,
  31264. + * rather than a window of the display. If zero, then
  31265. + * dest_rect is used to specify a region of the display to
  31266. + * use.
  31267. + */
  31268. +
  31269. + s32 fullscreen;
  31270. + /** Indicates any rotation or flipping used to map frames onto
  31271. + * the natural display orientation.
  31272. + */
  31273. + u32 transform; /* enum mmal_parameter_displaytransform */
  31274. +
  31275. + /** Where to display the frame within the screen, if
  31276. + * fullscreen is zero.
  31277. + */
  31278. + struct vchiq_mmal_rect dest_rect;
  31279. +
  31280. + /** Indicates which area of the frame to display. If all
  31281. + * values are zero, the whole frame will be used.
  31282. + */
  31283. + struct vchiq_mmal_rect src_rect;
  31284. +
  31285. + /** If set to non-zero, indicates that any display scaling
  31286. + * should disregard the aspect ratio of the frame region being
  31287. + * displayed.
  31288. + */
  31289. + s32 noaspect;
  31290. +
  31291. + /** Indicates how the image should be scaled to fit the
  31292. + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
  31293. + * that the image should fill the screen by potentially
  31294. + * cropping the frames. Setting \code mode \endcode to \code
  31295. + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
  31296. + * source region should be displayed and black bars added if
  31297. + * necessary.
  31298. + */
  31299. + u32 mode; /* enum mmal_parameter_displaymode */
  31300. +
  31301. + /** If non-zero, defines the width of a source pixel relative
  31302. + * to \code pixel_y \endcode. If zero, then pixels default to
  31303. + * being square.
  31304. + */
  31305. + u32 pixel_x;
  31306. +
  31307. + /** If non-zero, defines the height of a source pixel relative
  31308. + * to \code pixel_x \endcode. If zero, then pixels default to
  31309. + * being square.
  31310. + */
  31311. + u32 pixel_y;
  31312. +
  31313. + /** Sets the relative depth of the images, with greater values
  31314. + * being in front of smaller values.
  31315. + */
  31316. + u32 layer;
  31317. +
  31318. + /** Set to non-zero to ensure copy protection is used on
  31319. + * output.
  31320. + */
  31321. + s32 copyprotect_required;
  31322. +
  31323. + /** Level of opacity of the layer, where zero is fully
  31324. + * transparent and 255 is fully opaque.
  31325. + */
  31326. + u32 alpha;
  31327. +};
  31328. +
  31329. +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
  31330. +
  31331. +struct mmal_parameter_imagefx_parameters {
  31332. + enum mmal_parameter_imagefx effect;
  31333. + u32 num_effect_params;
  31334. + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
  31335. +};
  31336. diff -Nur linux-3.18.6/drivers/media/platform/bcm2835/mmal-vchiq.c linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.c
  31337. --- linux-3.18.6/drivers/media/platform/bcm2835/mmal-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  31338. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.c 2015-02-09 04:40:03.000000000 +0100
  31339. @@ -0,0 +1,1916 @@
  31340. +/*
  31341. + * Broadcom BM2835 V4L2 driver
  31342. + *
  31343. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  31344. + *
  31345. + * This file is subject to the terms and conditions of the GNU General Public
  31346. + * License. See the file COPYING in the main directory of this archive
  31347. + * for more details.
  31348. + *
  31349. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  31350. + * Dave Stevenson <dsteve@broadcom.com>
  31351. + * Simon Mellor <simellor@broadcom.com>
  31352. + * Luke Diamand <luked@broadcom.com>
  31353. + *
  31354. + * V4L2 driver MMAL vchiq interface code
  31355. + */
  31356. +
  31357. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  31358. +
  31359. +#include <linux/errno.h>
  31360. +#include <linux/kernel.h>
  31361. +#include <linux/mutex.h>
  31362. +#include <linux/mm.h>
  31363. +#include <linux/slab.h>
  31364. +#include <linux/completion.h>
  31365. +#include <linux/vmalloc.h>
  31366. +#include <asm/cacheflush.h>
  31367. +#include <media/videobuf2-vmalloc.h>
  31368. +
  31369. +#include "mmal-common.h"
  31370. +#include "mmal-vchiq.h"
  31371. +#include "mmal-msg.h"
  31372. +
  31373. +#define USE_VCHIQ_ARM
  31374. +#include "interface/vchi/vchi.h"
  31375. +
  31376. +/* maximum number of components supported */
  31377. +#define VCHIQ_MMAL_MAX_COMPONENTS 4
  31378. +
  31379. +/*#define FULL_MSG_DUMP 1*/
  31380. +
  31381. +#ifdef DEBUG
  31382. +static const char *const msg_type_names[] = {
  31383. + "UNKNOWN",
  31384. + "QUIT",
  31385. + "SERVICE_CLOSED",
  31386. + "GET_VERSION",
  31387. + "COMPONENT_CREATE",
  31388. + "COMPONENT_DESTROY",
  31389. + "COMPONENT_ENABLE",
  31390. + "COMPONENT_DISABLE",
  31391. + "PORT_INFO_GET",
  31392. + "PORT_INFO_SET",
  31393. + "PORT_ACTION",
  31394. + "BUFFER_FROM_HOST",
  31395. + "BUFFER_TO_HOST",
  31396. + "GET_STATS",
  31397. + "PORT_PARAMETER_SET",
  31398. + "PORT_PARAMETER_GET",
  31399. + "EVENT_TO_HOST",
  31400. + "GET_CORE_STATS_FOR_PORT",
  31401. + "OPAQUE_ALLOCATOR",
  31402. + "CONSUME_MEM",
  31403. + "LMK",
  31404. + "OPAQUE_ALLOCATOR_DESC",
  31405. + "DRM_GET_LHS32",
  31406. + "DRM_GET_TIME",
  31407. + "BUFFER_FROM_HOST_ZEROLEN",
  31408. + "PORT_FLUSH",
  31409. + "HOST_LOG",
  31410. +};
  31411. +#endif
  31412. +
  31413. +static const char *const port_action_type_names[] = {
  31414. + "UNKNOWN",
  31415. + "ENABLE",
  31416. + "DISABLE",
  31417. + "FLUSH",
  31418. + "CONNECT",
  31419. + "DISCONNECT",
  31420. + "SET_REQUIREMENTS",
  31421. +};
  31422. +
  31423. +#if defined(DEBUG)
  31424. +#if defined(FULL_MSG_DUMP)
  31425. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  31426. + do { \
  31427. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  31428. + msg_type_names[(MSG)->h.type], \
  31429. + (MSG)->h.type, (MSG_LEN)); \
  31430. + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
  31431. + 16, 4, (MSG), \
  31432. + sizeof(struct mmal_msg_header), 1); \
  31433. + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
  31434. + 16, 4, \
  31435. + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
  31436. + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
  31437. + } while (0)
  31438. +#else
  31439. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  31440. + { \
  31441. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  31442. + msg_type_names[(MSG)->h.type], \
  31443. + (MSG)->h.type, (MSG_LEN)); \
  31444. + }
  31445. +#endif
  31446. +#else
  31447. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
  31448. +#endif
  31449. +
  31450. +/* normal message context */
  31451. +struct mmal_msg_context {
  31452. + union {
  31453. + struct {
  31454. + /* work struct for defered callback - must come first */
  31455. + struct work_struct work;
  31456. + /* mmal instance */
  31457. + struct vchiq_mmal_instance *instance;
  31458. + /* mmal port */
  31459. + struct vchiq_mmal_port *port;
  31460. + /* actual buffer used to store bulk reply */
  31461. + struct mmal_buffer *buffer;
  31462. + /* amount of buffer used */
  31463. + unsigned long buffer_used;
  31464. + /* MMAL buffer flags */
  31465. + u32 mmal_flags;
  31466. + /* Presentation and Decode timestamps */
  31467. + s64 pts;
  31468. + s64 dts;
  31469. +
  31470. + int status; /* context status */
  31471. +
  31472. + } bulk; /* bulk data */
  31473. +
  31474. + struct {
  31475. + /* message handle to release */
  31476. + VCHI_HELD_MSG_T msg_handle;
  31477. + /* pointer to received message */
  31478. + struct mmal_msg *msg;
  31479. + /* received message length */
  31480. + u32 msg_len;
  31481. + /* completion upon reply */
  31482. + struct completion cmplt;
  31483. + } sync; /* synchronous response */
  31484. + } u;
  31485. +
  31486. +};
  31487. +
  31488. +struct vchiq_mmal_instance {
  31489. + VCHI_SERVICE_HANDLE_T handle;
  31490. +
  31491. + /* ensure serialised access to service */
  31492. + struct mutex vchiq_mutex;
  31493. +
  31494. + /* ensure serialised access to bulk operations */
  31495. + struct mutex bulk_mutex;
  31496. +
  31497. + /* vmalloc page to receive scratch bulk xfers into */
  31498. + void *bulk_scratch;
  31499. +
  31500. + /* component to use next */
  31501. + int component_idx;
  31502. + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
  31503. +};
  31504. +
  31505. +static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
  31506. + *instance)
  31507. +{
  31508. + struct mmal_msg_context *msg_context;
  31509. +
  31510. + /* todo: should this be allocated from a pool to avoid kmalloc */
  31511. + msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
  31512. + memset(msg_context, 0, sizeof(*msg_context));
  31513. +
  31514. + return msg_context;
  31515. +}
  31516. +
  31517. +static void release_msg_context(struct mmal_msg_context *msg_context)
  31518. +{
  31519. + kfree(msg_context);
  31520. +}
  31521. +
  31522. +/* deals with receipt of event to host message */
  31523. +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
  31524. + struct mmal_msg *msg, u32 msg_len)
  31525. +{
  31526. + pr_debug("unhandled event\n");
  31527. + pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
  31528. + msg->u.event_to_host.client_component,
  31529. + msg->u.event_to_host.port_type,
  31530. + msg->u.event_to_host.port_num,
  31531. + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
  31532. +}
  31533. +
  31534. +/* workqueue scheduled callback
  31535. + *
  31536. + * we do this because it is important we do not call any other vchiq
  31537. + * sync calls from witin the message delivery thread
  31538. + */
  31539. +static void buffer_work_cb(struct work_struct *work)
  31540. +{
  31541. + struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
  31542. +
  31543. + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
  31544. + msg_context->u.bulk.port,
  31545. + msg_context->u.bulk.status,
  31546. + msg_context->u.bulk.buffer,
  31547. + msg_context->u.bulk.buffer_used,
  31548. + msg_context->u.bulk.mmal_flags,
  31549. + msg_context->u.bulk.dts,
  31550. + msg_context->u.bulk.pts);
  31551. +
  31552. + /* release message context */
  31553. + release_msg_context(msg_context);
  31554. +}
  31555. +
  31556. +/* enqueue a bulk receive for a given message context */
  31557. +static int bulk_receive(struct vchiq_mmal_instance *instance,
  31558. + struct mmal_msg *msg,
  31559. + struct mmal_msg_context *msg_context)
  31560. +{
  31561. + unsigned long rd_len;
  31562. + unsigned long flags = 0;
  31563. + int ret;
  31564. +
  31565. + /* bulk mutex stops other bulk operations while we have a
  31566. + * receive in progress - released in callback
  31567. + */
  31568. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  31569. + if (ret != 0)
  31570. + return ret;
  31571. +
  31572. + rd_len = msg->u.buffer_from_host.buffer_header.length;
  31573. +
  31574. + /* take buffer from queue */
  31575. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  31576. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  31577. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  31578. + pr_err("buffer list empty trying to submit bulk receive\n");
  31579. +
  31580. + /* todo: this is a serious error, we should never have
  31581. + * commited a buffer_to_host operation to the mmal
  31582. + * port without the buffer to back it up (underflow
  31583. + * handling) and there is no obvious way to deal with
  31584. + * this - how is the mmal servie going to react when
  31585. + * we fail to do the xfer and reschedule a buffer when
  31586. + * it arrives? perhaps a starved flag to indicate a
  31587. + * waiting bulk receive?
  31588. + */
  31589. +
  31590. + mutex_unlock(&instance->bulk_mutex);
  31591. +
  31592. + return -EINVAL;
  31593. + }
  31594. +
  31595. + msg_context->u.bulk.buffer =
  31596. + list_entry(msg_context->u.bulk.port->buffers.next,
  31597. + struct mmal_buffer, list);
  31598. + list_del(&msg_context->u.bulk.buffer->list);
  31599. +
  31600. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  31601. +
  31602. + /* ensure we do not overrun the available buffer */
  31603. + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
  31604. + rd_len = msg_context->u.bulk.buffer->buffer_size;
  31605. + pr_warn("short read as not enough receive buffer space\n");
  31606. + /* todo: is this the correct response, what happens to
  31607. + * the rest of the message data?
  31608. + */
  31609. + }
  31610. +
  31611. + /* store length */
  31612. + msg_context->u.bulk.buffer_used = rd_len;
  31613. + msg_context->u.bulk.mmal_flags =
  31614. + msg->u.buffer_from_host.buffer_header.flags;
  31615. + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
  31616. + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
  31617. +
  31618. + // only need to flush L1 cache here, as VCHIQ takes care of the L2
  31619. + // cache.
  31620. + __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
  31621. +
  31622. + /* queue the bulk submission */
  31623. + vchi_service_use(instance->handle);
  31624. + ret = vchi_bulk_queue_receive(instance->handle,
  31625. + msg_context->u.bulk.buffer->buffer,
  31626. + /* Actual receive needs to be a multiple
  31627. + * of 4 bytes
  31628. + */
  31629. + (rd_len + 3) & ~3,
  31630. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  31631. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  31632. + msg_context);
  31633. +
  31634. + vchi_service_release(instance->handle);
  31635. +
  31636. + if (ret != 0) {
  31637. + /* callback will not be clearing the mutex */
  31638. + mutex_unlock(&instance->bulk_mutex);
  31639. + }
  31640. +
  31641. + return ret;
  31642. +}
  31643. +
  31644. +/* enque a dummy bulk receive for a given message context */
  31645. +static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
  31646. + struct mmal_msg_context *msg_context)
  31647. +{
  31648. + int ret;
  31649. +
  31650. + /* bulk mutex stops other bulk operations while we have a
  31651. + * receive in progress - released in callback
  31652. + */
  31653. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  31654. + if (ret != 0)
  31655. + return ret;
  31656. +
  31657. + /* zero length indicates this was a dummy transfer */
  31658. + msg_context->u.bulk.buffer_used = 0;
  31659. +
  31660. + /* queue the bulk submission */
  31661. + vchi_service_use(instance->handle);
  31662. +
  31663. + ret = vchi_bulk_queue_receive(instance->handle,
  31664. + instance->bulk_scratch,
  31665. + 8,
  31666. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  31667. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  31668. + msg_context);
  31669. +
  31670. + vchi_service_release(instance->handle);
  31671. +
  31672. + if (ret != 0) {
  31673. + /* callback will not be clearing the mutex */
  31674. + mutex_unlock(&instance->bulk_mutex);
  31675. + }
  31676. +
  31677. + return ret;
  31678. +}
  31679. +
  31680. +/* data in message, memcpy from packet into output buffer */
  31681. +static int inline_receive(struct vchiq_mmal_instance *instance,
  31682. + struct mmal_msg *msg,
  31683. + struct mmal_msg_context *msg_context)
  31684. +{
  31685. + unsigned long flags = 0;
  31686. +
  31687. + /* take buffer from queue */
  31688. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  31689. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  31690. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  31691. + pr_err("buffer list empty trying to receive inline\n");
  31692. +
  31693. + /* todo: this is a serious error, we should never have
  31694. + * commited a buffer_to_host operation to the mmal
  31695. + * port without the buffer to back it up (with
  31696. + * underflow handling) and there is no obvious way to
  31697. + * deal with this. Less bad than the bulk case as we
  31698. + * can just drop this on the floor but...unhelpful
  31699. + */
  31700. + return -EINVAL;
  31701. + }
  31702. +
  31703. + msg_context->u.bulk.buffer =
  31704. + list_entry(msg_context->u.bulk.port->buffers.next,
  31705. + struct mmal_buffer, list);
  31706. + list_del(&msg_context->u.bulk.buffer->list);
  31707. +
  31708. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  31709. +
  31710. + memcpy(msg_context->u.bulk.buffer->buffer,
  31711. + msg->u.buffer_from_host.short_data,
  31712. + msg->u.buffer_from_host.payload_in_message);
  31713. +
  31714. + msg_context->u.bulk.buffer_used =
  31715. + msg->u.buffer_from_host.payload_in_message;
  31716. +
  31717. + return 0;
  31718. +}
  31719. +
  31720. +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
  31721. +static int
  31722. +buffer_from_host(struct vchiq_mmal_instance *instance,
  31723. + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
  31724. +{
  31725. + struct mmal_msg_context *msg_context;
  31726. + struct mmal_msg m;
  31727. + int ret;
  31728. +
  31729. + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
  31730. +
  31731. + /* bulk mutex stops other bulk operations while we
  31732. + * have a receive in progress
  31733. + */
  31734. + if (mutex_lock_interruptible(&instance->bulk_mutex))
  31735. + return -EINTR;
  31736. +
  31737. + /* get context */
  31738. + msg_context = get_msg_context(instance);
  31739. + if (msg_context == NULL)
  31740. + return -ENOMEM;
  31741. +
  31742. + /* store bulk message context for when data arrives */
  31743. + msg_context->u.bulk.instance = instance;
  31744. + msg_context->u.bulk.port = port;
  31745. + msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
  31746. + msg_context->u.bulk.buffer_used = 0;
  31747. +
  31748. + /* initialise work structure ready to schedule callback */
  31749. + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
  31750. +
  31751. + /* prep the buffer from host message */
  31752. + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
  31753. +
  31754. + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
  31755. + m.h.magic = MMAL_MAGIC;
  31756. + m.h.context = msg_context;
  31757. + m.h.status = 0;
  31758. +
  31759. + /* drvbuf is our private data passed back */
  31760. + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
  31761. + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
  31762. + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
  31763. + m.u.buffer_from_host.drvbuf.client_context = msg_context;
  31764. +
  31765. + /* buffer header */
  31766. + m.u.buffer_from_host.buffer_header.cmd = 0;
  31767. + m.u.buffer_from_host.buffer_header.data = buf->buffer;
  31768. + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
  31769. + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
  31770. + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
  31771. + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
  31772. + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
  31773. + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
  31774. +
  31775. + /* clear buffer type sepecific data */
  31776. + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
  31777. + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
  31778. +
  31779. + /* no payload in message */
  31780. + m.u.buffer_from_host.payload_in_message = 0;
  31781. +
  31782. + vchi_service_use(instance->handle);
  31783. +
  31784. + ret = vchi_msg_queue(instance->handle, &m,
  31785. + sizeof(struct mmal_msg_header) +
  31786. + sizeof(m.u.buffer_from_host),
  31787. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  31788. +
  31789. + if (ret != 0) {
  31790. + release_msg_context(msg_context);
  31791. + /* todo: is this correct error value? */
  31792. + }
  31793. +
  31794. + vchi_service_release(instance->handle);
  31795. +
  31796. + mutex_unlock(&instance->bulk_mutex);
  31797. +
  31798. + return ret;
  31799. +}
  31800. +
  31801. +/* submit a buffer to the mmal sevice
  31802. + *
  31803. + * the buffer_from_host uses size data from the ports next available
  31804. + * mmal_buffer and deals with there being no buffer available by
  31805. + * incrementing the underflow for later
  31806. + */
  31807. +static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
  31808. + struct vchiq_mmal_port *port)
  31809. +{
  31810. + int ret;
  31811. + struct mmal_buffer *buf;
  31812. + unsigned long flags = 0;
  31813. +
  31814. + if (!port->enabled)
  31815. + return -EINVAL;
  31816. +
  31817. + /* peek buffer from queue */
  31818. + spin_lock_irqsave(&port->slock, flags);
  31819. + if (list_empty(&port->buffers)) {
  31820. + port->buffer_underflow++;
  31821. + spin_unlock_irqrestore(&port->slock, flags);
  31822. + return -ENOSPC;
  31823. + }
  31824. +
  31825. + buf = list_entry(port->buffers.next, struct mmal_buffer, list);
  31826. +
  31827. + spin_unlock_irqrestore(&port->slock, flags);
  31828. +
  31829. + /* issue buffer to mmal service */
  31830. + ret = buffer_from_host(instance, port, buf);
  31831. + if (ret) {
  31832. + pr_err("adding buffer header failed\n");
  31833. + /* todo: how should this be dealt with */
  31834. + }
  31835. +
  31836. + return ret;
  31837. +}
  31838. +
  31839. +/* deals with receipt of buffer to host message */
  31840. +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
  31841. + struct mmal_msg *msg, u32 msg_len)
  31842. +{
  31843. + struct mmal_msg_context *msg_context;
  31844. +
  31845. + pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
  31846. + instance, msg, msg_len);
  31847. +
  31848. + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
  31849. + msg_context = msg->u.buffer_from_host.drvbuf.client_context;
  31850. + } else {
  31851. + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
  31852. + return;
  31853. + }
  31854. +
  31855. + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
  31856. + /* message reception had an error */
  31857. + pr_warn("error %d in reply\n", msg->h.status);
  31858. +
  31859. + msg_context->u.bulk.status = msg->h.status;
  31860. +
  31861. + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
  31862. + /* empty buffer */
  31863. + if (msg->u.buffer_from_host.buffer_header.flags &
  31864. + MMAL_BUFFER_HEADER_FLAG_EOS) {
  31865. + msg_context->u.bulk.status =
  31866. + dummy_bulk_receive(instance, msg_context);
  31867. + if (msg_context->u.bulk.status == 0)
  31868. + return; /* successful bulk submission, bulk
  31869. + * completion will trigger callback
  31870. + */
  31871. + } else {
  31872. + /* do callback with empty buffer - not EOS though */
  31873. + msg_context->u.bulk.status = 0;
  31874. + msg_context->u.bulk.buffer_used = 0;
  31875. + }
  31876. + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
  31877. + /* data is not in message, queue a bulk receive */
  31878. + msg_context->u.bulk.status =
  31879. + bulk_receive(instance, msg, msg_context);
  31880. + if (msg_context->u.bulk.status == 0)
  31881. + return; /* successful bulk submission, bulk
  31882. + * completion will trigger callback
  31883. + */
  31884. +
  31885. + /* failed to submit buffer, this will end badly */
  31886. + pr_err("error %d on bulk submission\n",
  31887. + msg_context->u.bulk.status);
  31888. +
  31889. + } else if (msg->u.buffer_from_host.payload_in_message <=
  31890. + MMAL_VC_SHORT_DATA) {
  31891. + /* data payload within message */
  31892. + msg_context->u.bulk.status = inline_receive(instance, msg,
  31893. + msg_context);
  31894. + } else {
  31895. + pr_err("message with invalid short payload\n");
  31896. +
  31897. + /* signal error */
  31898. + msg_context->u.bulk.status = -EINVAL;
  31899. + msg_context->u.bulk.buffer_used =
  31900. + msg->u.buffer_from_host.payload_in_message;
  31901. + }
  31902. +
  31903. + /* replace the buffer header */
  31904. + port_buffer_from_host(instance, msg_context->u.bulk.port);
  31905. +
  31906. + /* schedule the port callback */
  31907. + schedule_work(&msg_context->u.bulk.work);
  31908. +}
  31909. +
  31910. +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
  31911. + struct mmal_msg_context *msg_context)
  31912. +{
  31913. + /* bulk receive operation complete */
  31914. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  31915. +
  31916. + /* replace the buffer header */
  31917. + port_buffer_from_host(msg_context->u.bulk.instance,
  31918. + msg_context->u.bulk.port);
  31919. +
  31920. + msg_context->u.bulk.status = 0;
  31921. +
  31922. + /* schedule the port callback */
  31923. + schedule_work(&msg_context->u.bulk.work);
  31924. +}
  31925. +
  31926. +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
  31927. + struct mmal_msg_context *msg_context)
  31928. +{
  31929. + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
  31930. +
  31931. + /* bulk receive operation complete */
  31932. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  31933. +
  31934. + /* replace the buffer header */
  31935. + port_buffer_from_host(msg_context->u.bulk.instance,
  31936. + msg_context->u.bulk.port);
  31937. +
  31938. + msg_context->u.bulk.status = -EINTR;
  31939. +
  31940. + schedule_work(&msg_context->u.bulk.work);
  31941. +}
  31942. +
  31943. +/* incoming event service callback */
  31944. +static void service_callback(void *param,
  31945. + const VCHI_CALLBACK_REASON_T reason,
  31946. + void *bulk_ctx)
  31947. +{
  31948. + struct vchiq_mmal_instance *instance = param;
  31949. + int status;
  31950. + u32 msg_len;
  31951. + struct mmal_msg *msg;
  31952. + VCHI_HELD_MSG_T msg_handle;
  31953. +
  31954. + if (!instance) {
  31955. + pr_err("Message callback passed NULL instance\n");
  31956. + return;
  31957. + }
  31958. +
  31959. + switch (reason) {
  31960. + case VCHI_CALLBACK_MSG_AVAILABLE:
  31961. + status = vchi_msg_hold(instance->handle, (void **)&msg,
  31962. + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
  31963. + if (status) {
  31964. + pr_err("Unable to dequeue a message (%d)\n", status);
  31965. + break;
  31966. + }
  31967. +
  31968. + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
  31969. +
  31970. + /* handling is different for buffer messages */
  31971. + switch (msg->h.type) {
  31972. +
  31973. + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
  31974. + vchi_held_msg_release(&msg_handle);
  31975. + break;
  31976. +
  31977. + case MMAL_MSG_TYPE_EVENT_TO_HOST:
  31978. + event_to_host_cb(instance, msg, msg_len);
  31979. + vchi_held_msg_release(&msg_handle);
  31980. +
  31981. + break;
  31982. +
  31983. + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
  31984. + buffer_to_host_cb(instance, msg, msg_len);
  31985. + vchi_held_msg_release(&msg_handle);
  31986. + break;
  31987. +
  31988. + default:
  31989. + /* messages dependant on header context to complete */
  31990. +
  31991. + /* todo: the msg.context really ought to be sanity
  31992. + * checked before we just use it, afaict it comes back
  31993. + * and is used raw from the videocore. Perhaps it
  31994. + * should be verified the address lies in the kernel
  31995. + * address space.
  31996. + */
  31997. + if (msg->h.context == NULL) {
  31998. + pr_err("received message context was null!\n");
  31999. + vchi_held_msg_release(&msg_handle);
  32000. + break;
  32001. + }
  32002. +
  32003. + /* fill in context values */
  32004. + msg->h.context->u.sync.msg_handle = msg_handle;
  32005. + msg->h.context->u.sync.msg = msg;
  32006. + msg->h.context->u.sync.msg_len = msg_len;
  32007. +
  32008. + /* todo: should this check (completion_done()
  32009. + * == 1) for no one waiting? or do we need a
  32010. + * flag to tell us the completion has been
  32011. + * interrupted so we can free the message and
  32012. + * its context. This probably also solves the
  32013. + * message arriving after interruption todo
  32014. + * below
  32015. + */
  32016. +
  32017. + /* complete message so caller knows it happened */
  32018. + complete(&msg->h.context->u.sync.cmplt);
  32019. + break;
  32020. + }
  32021. +
  32022. + break;
  32023. +
  32024. + case VCHI_CALLBACK_BULK_RECEIVED:
  32025. + bulk_receive_cb(instance, bulk_ctx);
  32026. + break;
  32027. +
  32028. + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
  32029. + bulk_abort_cb(instance, bulk_ctx);
  32030. + break;
  32031. +
  32032. + case VCHI_CALLBACK_SERVICE_CLOSED:
  32033. + /* TODO: consider if this requires action if received when
  32034. + * driver is not explicitly closing the service
  32035. + */
  32036. + break;
  32037. +
  32038. + default:
  32039. + pr_err("Received unhandled message reason %d\n", reason);
  32040. + break;
  32041. + }
  32042. +}
  32043. +
  32044. +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
  32045. + struct mmal_msg *msg,
  32046. + unsigned int payload_len,
  32047. + struct mmal_msg **msg_out,
  32048. + VCHI_HELD_MSG_T *msg_handle_out)
  32049. +{
  32050. + struct mmal_msg_context msg_context;
  32051. + int ret;
  32052. +
  32053. + /* payload size must not cause message to exceed max size */
  32054. + if (payload_len >
  32055. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
  32056. + pr_err("payload length %d exceeds max:%d\n", payload_len,
  32057. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
  32058. + return -EINVAL;
  32059. + }
  32060. +
  32061. + init_completion(&msg_context.u.sync.cmplt);
  32062. +
  32063. + msg->h.magic = MMAL_MAGIC;
  32064. + msg->h.context = &msg_context;
  32065. + msg->h.status = 0;
  32066. +
  32067. + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
  32068. + ">>> sync message");
  32069. +
  32070. + vchi_service_use(instance->handle);
  32071. +
  32072. + ret = vchi_msg_queue(instance->handle,
  32073. + msg,
  32074. + sizeof(struct mmal_msg_header) + payload_len,
  32075. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  32076. +
  32077. + vchi_service_release(instance->handle);
  32078. +
  32079. + if (ret) {
  32080. + pr_err("error %d queuing message\n", ret);
  32081. + return ret;
  32082. + }
  32083. +
  32084. + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, 3*HZ);
  32085. + if (ret <= 0) {
  32086. + pr_err("error %d waiting for sync completion\n", ret);
  32087. + if (ret == 0)
  32088. + ret = -ETIME;
  32089. + /* todo: what happens if the message arrives after aborting */
  32090. + return ret;
  32091. + }
  32092. +
  32093. + *msg_out = msg_context.u.sync.msg;
  32094. + *msg_handle_out = msg_context.u.sync.msg_handle;
  32095. +
  32096. + return 0;
  32097. +}
  32098. +
  32099. +static void dump_port_info(struct vchiq_mmal_port *port)
  32100. +{
  32101. + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
  32102. +
  32103. + pr_debug("buffer minimum num:%d size:%d align:%d\n",
  32104. + port->minimum_buffer.num,
  32105. + port->minimum_buffer.size, port->minimum_buffer.alignment);
  32106. +
  32107. + pr_debug("buffer recommended num:%d size:%d align:%d\n",
  32108. + port->recommended_buffer.num,
  32109. + port->recommended_buffer.size,
  32110. + port->recommended_buffer.alignment);
  32111. +
  32112. + pr_debug("buffer current values num:%d size:%d align:%d\n",
  32113. + port->current_buffer.num,
  32114. + port->current_buffer.size, port->current_buffer.alignment);
  32115. +
  32116. + pr_debug("elementry stream: type:%d encoding:0x%x varient:0x%x\n",
  32117. + port->format.type,
  32118. + port->format.encoding, port->format.encoding_variant);
  32119. +
  32120. + pr_debug(" bitrate:%d flags:0x%x\n",
  32121. + port->format.bitrate, port->format.flags);
  32122. +
  32123. + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
  32124. + pr_debug
  32125. + ("es video format: width:%d height:%d colourspace:0x%x\n",
  32126. + port->es.video.width, port->es.video.height,
  32127. + port->es.video.color_space);
  32128. +
  32129. + pr_debug(" : crop xywh %d,%d,%d,%d\n",
  32130. + port->es.video.crop.x,
  32131. + port->es.video.crop.y,
  32132. + port->es.video.crop.width, port->es.video.crop.height);
  32133. + pr_debug(" : framerate %d/%d aspect %d/%d\n",
  32134. + port->es.video.frame_rate.num,
  32135. + port->es.video.frame_rate.den,
  32136. + port->es.video.par.num, port->es.video.par.den);
  32137. + }
  32138. +}
  32139. +
  32140. +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
  32141. +{
  32142. +
  32143. + /* todo do readonly fields need setting at all? */
  32144. + p->type = port->type;
  32145. + p->index = port->index;
  32146. + p->index_all = 0;
  32147. + p->is_enabled = port->enabled;
  32148. + p->buffer_num_min = port->minimum_buffer.num;
  32149. + p->buffer_size_min = port->minimum_buffer.size;
  32150. + p->buffer_alignment_min = port->minimum_buffer.alignment;
  32151. + p->buffer_num_recommended = port->recommended_buffer.num;
  32152. + p->buffer_size_recommended = port->recommended_buffer.size;
  32153. +
  32154. + /* only three writable fields in a port */
  32155. + p->buffer_num = port->current_buffer.num;
  32156. + p->buffer_size = port->current_buffer.size;
  32157. + p->userdata = port;
  32158. +}
  32159. +
  32160. +static int port_info_set(struct vchiq_mmal_instance *instance,
  32161. + struct vchiq_mmal_port *port)
  32162. +{
  32163. + int ret;
  32164. + struct mmal_msg m;
  32165. + struct mmal_msg *rmsg;
  32166. + VCHI_HELD_MSG_T rmsg_handle;
  32167. +
  32168. + pr_debug("setting port info port %p\n", port);
  32169. + if (!port)
  32170. + return -1;
  32171. + dump_port_info(port);
  32172. +
  32173. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
  32174. +
  32175. + m.u.port_info_set.component_handle = port->component->handle;
  32176. + m.u.port_info_set.port_type = port->type;
  32177. + m.u.port_info_set.port_index = port->index;
  32178. +
  32179. + port_to_mmal_msg(port, &m.u.port_info_set.port);
  32180. +
  32181. + /* elementry stream format setup */
  32182. + m.u.port_info_set.format.type = port->format.type;
  32183. + m.u.port_info_set.format.encoding = port->format.encoding;
  32184. + m.u.port_info_set.format.encoding_variant =
  32185. + port->format.encoding_variant;
  32186. + m.u.port_info_set.format.bitrate = port->format.bitrate;
  32187. + m.u.port_info_set.format.flags = port->format.flags;
  32188. +
  32189. + memcpy(&m.u.port_info_set.es, &port->es,
  32190. + sizeof(union mmal_es_specific_format));
  32191. +
  32192. + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
  32193. + memcpy(rmsg->u.port_info_set.extradata, port->format.extradata,
  32194. + port->format.extradata_size);
  32195. +
  32196. + ret = send_synchronous_mmal_msg(instance, &m,
  32197. + sizeof(m.u.port_info_set),
  32198. + &rmsg, &rmsg_handle);
  32199. + if (ret)
  32200. + return ret;
  32201. +
  32202. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
  32203. + /* got an unexpected message type in reply */
  32204. + ret = -EINVAL;
  32205. + goto release_msg;
  32206. + }
  32207. +
  32208. + /* return operation status */
  32209. + ret = -rmsg->u.port_info_get_reply.status;
  32210. +
  32211. + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
  32212. + port->component->handle, port->handle);
  32213. +
  32214. +release_msg:
  32215. + vchi_held_msg_release(&rmsg_handle);
  32216. +
  32217. + return ret;
  32218. +
  32219. +}
  32220. +
  32221. +/* use port info get message to retrive port information */
  32222. +static int port_info_get(struct vchiq_mmal_instance *instance,
  32223. + struct vchiq_mmal_port *port)
  32224. +{
  32225. + int ret;
  32226. + struct mmal_msg m;
  32227. + struct mmal_msg *rmsg;
  32228. + VCHI_HELD_MSG_T rmsg_handle;
  32229. +
  32230. + /* port info time */
  32231. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
  32232. + m.u.port_info_get.component_handle = port->component->handle;
  32233. + m.u.port_info_get.port_type = port->type;
  32234. + m.u.port_info_get.index = port->index;
  32235. +
  32236. + ret = send_synchronous_mmal_msg(instance, &m,
  32237. + sizeof(m.u.port_info_get),
  32238. + &rmsg, &rmsg_handle);
  32239. + if (ret)
  32240. + return ret;
  32241. +
  32242. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
  32243. + /* got an unexpected message type in reply */
  32244. + ret = -EINVAL;
  32245. + goto release_msg;
  32246. + }
  32247. +
  32248. + /* return operation status */
  32249. + ret = -rmsg->u.port_info_get_reply.status;
  32250. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  32251. + goto release_msg;
  32252. +
  32253. + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
  32254. + port->enabled = false;
  32255. + else
  32256. + port->enabled = true;
  32257. +
  32258. + /* copy the values out of the message */
  32259. + port->handle = rmsg->u.port_info_get_reply.port_handle;
  32260. +
  32261. + /* port type and index cached to use on port info set becuase
  32262. + * it does not use a port handle
  32263. + */
  32264. + port->type = rmsg->u.port_info_get_reply.port_type;
  32265. + port->index = rmsg->u.port_info_get_reply.port_index;
  32266. +
  32267. + port->minimum_buffer.num =
  32268. + rmsg->u.port_info_get_reply.port.buffer_num_min;
  32269. + port->minimum_buffer.size =
  32270. + rmsg->u.port_info_get_reply.port.buffer_size_min;
  32271. + port->minimum_buffer.alignment =
  32272. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  32273. +
  32274. + port->recommended_buffer.alignment =
  32275. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  32276. + port->recommended_buffer.num =
  32277. + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
  32278. +
  32279. + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
  32280. + port->current_buffer.size =
  32281. + rmsg->u.port_info_get_reply.port.buffer_size;
  32282. +
  32283. + /* stream format */
  32284. + port->format.type = rmsg->u.port_info_get_reply.format.type;
  32285. + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
  32286. + port->format.encoding_variant =
  32287. + rmsg->u.port_info_get_reply.format.encoding_variant;
  32288. + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
  32289. + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
  32290. +
  32291. + /* elementry stream format */
  32292. + memcpy(&port->es,
  32293. + &rmsg->u.port_info_get_reply.es,
  32294. + sizeof(union mmal_es_specific_format));
  32295. + port->format.es = &port->es;
  32296. +
  32297. + port->format.extradata_size =
  32298. + rmsg->u.port_info_get_reply.format.extradata_size;
  32299. + memcpy(port->format.extradata,
  32300. + rmsg->u.port_info_get_reply.extradata,
  32301. + port->format.extradata_size);
  32302. +
  32303. + pr_debug("received port info\n");
  32304. + dump_port_info(port);
  32305. +
  32306. +release_msg:
  32307. +
  32308. + pr_debug("%s:result:%d component:0x%x port:%d\n",
  32309. + __func__, ret, port->component->handle, port->handle);
  32310. +
  32311. + vchi_held_msg_release(&rmsg_handle);
  32312. +
  32313. + return ret;
  32314. +}
  32315. +
  32316. +/* create comonent on vc */
  32317. +static int create_component(struct vchiq_mmal_instance *instance,
  32318. + struct vchiq_mmal_component *component,
  32319. + const char *name)
  32320. +{
  32321. + int ret;
  32322. + struct mmal_msg m;
  32323. + struct mmal_msg *rmsg;
  32324. + VCHI_HELD_MSG_T rmsg_handle;
  32325. +
  32326. + /* build component create message */
  32327. + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
  32328. + m.u.component_create.client_component = component;
  32329. + strncpy(m.u.component_create.name, name,
  32330. + sizeof(m.u.component_create.name));
  32331. +
  32332. + ret = send_synchronous_mmal_msg(instance, &m,
  32333. + sizeof(m.u.component_create),
  32334. + &rmsg, &rmsg_handle);
  32335. + if (ret)
  32336. + return ret;
  32337. +
  32338. + if (rmsg->h.type != m.h.type) {
  32339. + /* got an unexpected message type in reply */
  32340. + ret = -EINVAL;
  32341. + goto release_msg;
  32342. + }
  32343. +
  32344. + ret = -rmsg->u.component_create_reply.status;
  32345. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  32346. + goto release_msg;
  32347. +
  32348. + /* a valid component response received */
  32349. + component->handle = rmsg->u.component_create_reply.component_handle;
  32350. + component->inputs = rmsg->u.component_create_reply.input_num;
  32351. + component->outputs = rmsg->u.component_create_reply.output_num;
  32352. + component->clocks = rmsg->u.component_create_reply.clock_num;
  32353. +
  32354. + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
  32355. + component->handle,
  32356. + component->inputs, component->outputs, component->clocks);
  32357. +
  32358. +release_msg:
  32359. + vchi_held_msg_release(&rmsg_handle);
  32360. +
  32361. + return ret;
  32362. +}
  32363. +
  32364. +/* destroys a component on vc */
  32365. +static int destroy_component(struct vchiq_mmal_instance *instance,
  32366. + struct vchiq_mmal_component *component)
  32367. +{
  32368. + int ret;
  32369. + struct mmal_msg m;
  32370. + struct mmal_msg *rmsg;
  32371. + VCHI_HELD_MSG_T rmsg_handle;
  32372. +
  32373. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
  32374. + m.u.component_destroy.component_handle = component->handle;
  32375. +
  32376. + ret = send_synchronous_mmal_msg(instance, &m,
  32377. + sizeof(m.u.component_destroy),
  32378. + &rmsg, &rmsg_handle);
  32379. + if (ret)
  32380. + return ret;
  32381. +
  32382. + if (rmsg->h.type != m.h.type) {
  32383. + /* got an unexpected message type in reply */
  32384. + ret = -EINVAL;
  32385. + goto release_msg;
  32386. + }
  32387. +
  32388. + ret = -rmsg->u.component_destroy_reply.status;
  32389. +
  32390. +release_msg:
  32391. +
  32392. + vchi_held_msg_release(&rmsg_handle);
  32393. +
  32394. + return ret;
  32395. +}
  32396. +
  32397. +/* enable a component on vc */
  32398. +static int enable_component(struct vchiq_mmal_instance *instance,
  32399. + struct vchiq_mmal_component *component)
  32400. +{
  32401. + int ret;
  32402. + struct mmal_msg m;
  32403. + struct mmal_msg *rmsg;
  32404. + VCHI_HELD_MSG_T rmsg_handle;
  32405. +
  32406. + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
  32407. + m.u.component_enable.component_handle = component->handle;
  32408. +
  32409. + ret = send_synchronous_mmal_msg(instance, &m,
  32410. + sizeof(m.u.component_enable),
  32411. + &rmsg, &rmsg_handle);
  32412. + if (ret)
  32413. + return ret;
  32414. +
  32415. + if (rmsg->h.type != m.h.type) {
  32416. + /* got an unexpected message type in reply */
  32417. + ret = -EINVAL;
  32418. + goto release_msg;
  32419. + }
  32420. +
  32421. + ret = -rmsg->u.component_enable_reply.status;
  32422. +
  32423. +release_msg:
  32424. + vchi_held_msg_release(&rmsg_handle);
  32425. +
  32426. + return ret;
  32427. +}
  32428. +
  32429. +/* disable a component on vc */
  32430. +static int disable_component(struct vchiq_mmal_instance *instance,
  32431. + struct vchiq_mmal_component *component)
  32432. +{
  32433. + int ret;
  32434. + struct mmal_msg m;
  32435. + struct mmal_msg *rmsg;
  32436. + VCHI_HELD_MSG_T rmsg_handle;
  32437. +
  32438. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
  32439. + m.u.component_disable.component_handle = component->handle;
  32440. +
  32441. + ret = send_synchronous_mmal_msg(instance, &m,
  32442. + sizeof(m.u.component_disable),
  32443. + &rmsg, &rmsg_handle);
  32444. + if (ret)
  32445. + return ret;
  32446. +
  32447. + if (rmsg->h.type != m.h.type) {
  32448. + /* got an unexpected message type in reply */
  32449. + ret = -EINVAL;
  32450. + goto release_msg;
  32451. + }
  32452. +
  32453. + ret = -rmsg->u.component_disable_reply.status;
  32454. +
  32455. +release_msg:
  32456. +
  32457. + vchi_held_msg_release(&rmsg_handle);
  32458. +
  32459. + return ret;
  32460. +}
  32461. +
  32462. +/* get version of mmal implementation */
  32463. +static int get_version(struct vchiq_mmal_instance *instance,
  32464. + u32 *major_out, u32 *minor_out)
  32465. +{
  32466. + int ret;
  32467. + struct mmal_msg m;
  32468. + struct mmal_msg *rmsg;
  32469. + VCHI_HELD_MSG_T rmsg_handle;
  32470. +
  32471. + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
  32472. +
  32473. + ret = send_synchronous_mmal_msg(instance, &m,
  32474. + sizeof(m.u.version),
  32475. + &rmsg, &rmsg_handle);
  32476. + if (ret)
  32477. + return ret;
  32478. +
  32479. + if (rmsg->h.type != m.h.type) {
  32480. + /* got an unexpected message type in reply */
  32481. + ret = -EINVAL;
  32482. + goto release_msg;
  32483. + }
  32484. +
  32485. + *major_out = rmsg->u.version.major;
  32486. + *minor_out = rmsg->u.version.minor;
  32487. +
  32488. +release_msg:
  32489. + vchi_held_msg_release(&rmsg_handle);
  32490. +
  32491. + return ret;
  32492. +}
  32493. +
  32494. +/* do a port action with a port as a parameter */
  32495. +static int port_action_port(struct vchiq_mmal_instance *instance,
  32496. + struct vchiq_mmal_port *port,
  32497. + enum mmal_msg_port_action_type action_type)
  32498. +{
  32499. + int ret;
  32500. + struct mmal_msg m;
  32501. + struct mmal_msg *rmsg;
  32502. + VCHI_HELD_MSG_T rmsg_handle;
  32503. +
  32504. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  32505. + m.u.port_action_port.component_handle = port->component->handle;
  32506. + m.u.port_action_port.port_handle = port->handle;
  32507. + m.u.port_action_port.action = action_type;
  32508. +
  32509. + port_to_mmal_msg(port, &m.u.port_action_port.port);
  32510. +
  32511. + ret = send_synchronous_mmal_msg(instance, &m,
  32512. + sizeof(m.u.port_action_port),
  32513. + &rmsg, &rmsg_handle);
  32514. + if (ret)
  32515. + return ret;
  32516. +
  32517. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  32518. + /* got an unexpected message type in reply */
  32519. + ret = -EINVAL;
  32520. + goto release_msg;
  32521. + }
  32522. +
  32523. + ret = -rmsg->u.port_action_reply.status;
  32524. +
  32525. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
  32526. + __func__,
  32527. + ret, port->component->handle, port->handle,
  32528. + port_action_type_names[action_type], action_type);
  32529. +
  32530. +release_msg:
  32531. + vchi_held_msg_release(&rmsg_handle);
  32532. +
  32533. + return ret;
  32534. +}
  32535. +
  32536. +/* do a port action with handles as parameters */
  32537. +static int port_action_handle(struct vchiq_mmal_instance *instance,
  32538. + struct vchiq_mmal_port *port,
  32539. + enum mmal_msg_port_action_type action_type,
  32540. + u32 connect_component_handle,
  32541. + u32 connect_port_handle)
  32542. +{
  32543. + int ret;
  32544. + struct mmal_msg m;
  32545. + struct mmal_msg *rmsg;
  32546. + VCHI_HELD_MSG_T rmsg_handle;
  32547. +
  32548. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  32549. +
  32550. + m.u.port_action_handle.component_handle = port->component->handle;
  32551. + m.u.port_action_handle.port_handle = port->handle;
  32552. + m.u.port_action_handle.action = action_type;
  32553. +
  32554. + m.u.port_action_handle.connect_component_handle =
  32555. + connect_component_handle;
  32556. + m.u.port_action_handle.connect_port_handle = connect_port_handle;
  32557. +
  32558. + ret = send_synchronous_mmal_msg(instance, &m,
  32559. + sizeof(m.u.port_action_handle),
  32560. + &rmsg, &rmsg_handle);
  32561. + if (ret)
  32562. + return ret;
  32563. +
  32564. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  32565. + /* got an unexpected message type in reply */
  32566. + ret = -EINVAL;
  32567. + goto release_msg;
  32568. + }
  32569. +
  32570. + ret = -rmsg->u.port_action_reply.status;
  32571. +
  32572. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
  32573. + " connect component:0x%x connect port:%d\n",
  32574. + __func__,
  32575. + ret, port->component->handle, port->handle,
  32576. + port_action_type_names[action_type],
  32577. + action_type, connect_component_handle, connect_port_handle);
  32578. +
  32579. +release_msg:
  32580. + vchi_held_msg_release(&rmsg_handle);
  32581. +
  32582. + return ret;
  32583. +}
  32584. +
  32585. +static int port_parameter_set(struct vchiq_mmal_instance *instance,
  32586. + struct vchiq_mmal_port *port,
  32587. + u32 parameter_id, void *value, u32 value_size)
  32588. +{
  32589. + int ret;
  32590. + struct mmal_msg m;
  32591. + struct mmal_msg *rmsg;
  32592. + VCHI_HELD_MSG_T rmsg_handle;
  32593. +
  32594. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
  32595. +
  32596. + m.u.port_parameter_set.component_handle = port->component->handle;
  32597. + m.u.port_parameter_set.port_handle = port->handle;
  32598. + m.u.port_parameter_set.id = parameter_id;
  32599. + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
  32600. + memcpy(&m.u.port_parameter_set.value, value, value_size);
  32601. +
  32602. + ret = send_synchronous_mmal_msg(instance, &m,
  32603. + (4 * sizeof(u32)) + value_size,
  32604. + &rmsg, &rmsg_handle);
  32605. + if (ret)
  32606. + return ret;
  32607. +
  32608. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
  32609. + /* got an unexpected message type in reply */
  32610. + ret = -EINVAL;
  32611. + goto release_msg;
  32612. + }
  32613. +
  32614. + ret = -rmsg->u.port_parameter_set_reply.status;
  32615. +
  32616. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
  32617. + __func__,
  32618. + ret, port->component->handle, port->handle, parameter_id);
  32619. +
  32620. +release_msg:
  32621. + vchi_held_msg_release(&rmsg_handle);
  32622. +
  32623. + return ret;
  32624. +}
  32625. +
  32626. +static int port_parameter_get(struct vchiq_mmal_instance *instance,
  32627. + struct vchiq_mmal_port *port,
  32628. + u32 parameter_id, void *value, u32 *value_size)
  32629. +{
  32630. + int ret;
  32631. + struct mmal_msg m;
  32632. + struct mmal_msg *rmsg;
  32633. + VCHI_HELD_MSG_T rmsg_handle;
  32634. +
  32635. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
  32636. +
  32637. + m.u.port_parameter_get.component_handle = port->component->handle;
  32638. + m.u.port_parameter_get.port_handle = port->handle;
  32639. + m.u.port_parameter_get.id = parameter_id;
  32640. + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
  32641. +
  32642. + ret = send_synchronous_mmal_msg(instance, &m,
  32643. + sizeof(struct
  32644. + mmal_msg_port_parameter_get),
  32645. + &rmsg, &rmsg_handle);
  32646. + if (ret)
  32647. + return ret;
  32648. +
  32649. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
  32650. + /* got an unexpected message type in reply */
  32651. + pr_err("Incorrect reply type %d\n", rmsg->h.type);
  32652. + ret = -EINVAL;
  32653. + goto release_msg;
  32654. + }
  32655. +
  32656. + ret = -rmsg->u.port_parameter_get_reply.status;
  32657. + if (ret) {
  32658. + /* Copy only as much as we have space for
  32659. + * but report true size of parameter
  32660. + */
  32661. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  32662. + *value_size);
  32663. + *value_size = rmsg->u.port_parameter_get_reply.size;
  32664. + } else
  32665. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  32666. + rmsg->u.port_parameter_get_reply.size);
  32667. +
  32668. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
  32669. + ret, port->component->handle, port->handle, parameter_id);
  32670. +
  32671. +release_msg:
  32672. + vchi_held_msg_release(&rmsg_handle);
  32673. +
  32674. + return ret;
  32675. +}
  32676. +
  32677. +/* disables a port and drains buffers from it */
  32678. +static int port_disable(struct vchiq_mmal_instance *instance,
  32679. + struct vchiq_mmal_port *port)
  32680. +{
  32681. + int ret;
  32682. + struct list_head *q, *buf_head;
  32683. + unsigned long flags = 0;
  32684. +
  32685. + if (!port->enabled)
  32686. + return 0;
  32687. +
  32688. + port->enabled = false;
  32689. +
  32690. + ret = port_action_port(instance, port,
  32691. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
  32692. + if (ret == 0) {
  32693. +
  32694. + /* drain all queued buffers on port */
  32695. + spin_lock_irqsave(&port->slock, flags);
  32696. +
  32697. + list_for_each_safe(buf_head, q, &port->buffers) {
  32698. + struct mmal_buffer *mmalbuf;
  32699. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  32700. + list);
  32701. + list_del(buf_head);
  32702. + if (port->buffer_cb)
  32703. + port->buffer_cb(instance,
  32704. + port, 0, mmalbuf, 0, 0,
  32705. + MMAL_TIME_UNKNOWN,
  32706. + MMAL_TIME_UNKNOWN);
  32707. + }
  32708. +
  32709. + spin_unlock_irqrestore(&port->slock, flags);
  32710. +
  32711. + ret = port_info_get(instance, port);
  32712. + }
  32713. +
  32714. + return ret;
  32715. +}
  32716. +
  32717. +/* enable a port */
  32718. +static int port_enable(struct vchiq_mmal_instance *instance,
  32719. + struct vchiq_mmal_port *port)
  32720. +{
  32721. + unsigned int hdr_count;
  32722. + struct list_head *buf_head;
  32723. + int ret;
  32724. +
  32725. + if (port->enabled)
  32726. + return 0;
  32727. +
  32728. + /* ensure there are enough buffers queued to cover the buffer headers */
  32729. + if (port->buffer_cb != NULL) {
  32730. + hdr_count = 0;
  32731. + list_for_each(buf_head, &port->buffers) {
  32732. + hdr_count++;
  32733. + }
  32734. + if (hdr_count < port->current_buffer.num)
  32735. + return -ENOSPC;
  32736. + }
  32737. +
  32738. + ret = port_action_port(instance, port,
  32739. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
  32740. + if (ret)
  32741. + goto done;
  32742. +
  32743. + port->enabled = true;
  32744. +
  32745. + if (port->buffer_cb) {
  32746. + /* send buffer headers to videocore */
  32747. + hdr_count = 1;
  32748. + list_for_each(buf_head, &port->buffers) {
  32749. + struct mmal_buffer *mmalbuf;
  32750. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  32751. + list);
  32752. + ret = buffer_from_host(instance, port, mmalbuf);
  32753. + if (ret)
  32754. + goto done;
  32755. +
  32756. + hdr_count++;
  32757. + if (hdr_count > port->current_buffer.num)
  32758. + break;
  32759. + }
  32760. + }
  32761. +
  32762. + ret = port_info_get(instance, port);
  32763. +
  32764. +done:
  32765. + return ret;
  32766. +}
  32767. +
  32768. +/* ------------------------------------------------------------------
  32769. + * Exported API
  32770. + *------------------------------------------------------------------*/
  32771. +
  32772. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  32773. + struct vchiq_mmal_port *port)
  32774. +{
  32775. + int ret;
  32776. +
  32777. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32778. + return -EINTR;
  32779. +
  32780. + ret = port_info_set(instance, port);
  32781. + if (ret)
  32782. + goto release_unlock;
  32783. +
  32784. + /* read what has actually been set */
  32785. + ret = port_info_get(instance, port);
  32786. +
  32787. +release_unlock:
  32788. + mutex_unlock(&instance->vchiq_mutex);
  32789. +
  32790. + return ret;
  32791. +
  32792. +}
  32793. +
  32794. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  32795. + struct vchiq_mmal_port *port,
  32796. + u32 parameter, void *value, u32 value_size)
  32797. +{
  32798. + int ret;
  32799. +
  32800. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32801. + return -EINTR;
  32802. +
  32803. + ret = port_parameter_set(instance, port, parameter, value, value_size);
  32804. +
  32805. + mutex_unlock(&instance->vchiq_mutex);
  32806. +
  32807. + return ret;
  32808. +}
  32809. +
  32810. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  32811. + struct vchiq_mmal_port *port,
  32812. + u32 parameter, void *value, u32 *value_size)
  32813. +{
  32814. + int ret;
  32815. +
  32816. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32817. + return -EINTR;
  32818. +
  32819. + ret = port_parameter_get(instance, port, parameter, value, value_size);
  32820. +
  32821. + mutex_unlock(&instance->vchiq_mutex);
  32822. +
  32823. + return ret;
  32824. +}
  32825. +
  32826. +/* enable a port
  32827. + *
  32828. + * enables a port and queues buffers for satisfying callbacks if we
  32829. + * provide a callback handler
  32830. + */
  32831. +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
  32832. + struct vchiq_mmal_port *port,
  32833. + vchiq_mmal_buffer_cb buffer_cb)
  32834. +{
  32835. + int ret;
  32836. +
  32837. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32838. + return -EINTR;
  32839. +
  32840. + /* already enabled - noop */
  32841. + if (port->enabled) {
  32842. + ret = 0;
  32843. + goto unlock;
  32844. + }
  32845. +
  32846. + port->buffer_cb = buffer_cb;
  32847. +
  32848. + ret = port_enable(instance, port);
  32849. +
  32850. +unlock:
  32851. + mutex_unlock(&instance->vchiq_mutex);
  32852. +
  32853. + return ret;
  32854. +}
  32855. +
  32856. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  32857. + struct vchiq_mmal_port *port)
  32858. +{
  32859. + int ret;
  32860. +
  32861. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32862. + return -EINTR;
  32863. +
  32864. + if (!port->enabled) {
  32865. + mutex_unlock(&instance->vchiq_mutex);
  32866. + return 0;
  32867. + }
  32868. +
  32869. + ret = port_disable(instance, port);
  32870. +
  32871. + mutex_unlock(&instance->vchiq_mutex);
  32872. +
  32873. + return ret;
  32874. +}
  32875. +
  32876. +/* ports will be connected in a tunneled manner so data buffers
  32877. + * are not handled by client.
  32878. + */
  32879. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  32880. + struct vchiq_mmal_port *src,
  32881. + struct vchiq_mmal_port *dst)
  32882. +{
  32883. + int ret;
  32884. +
  32885. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32886. + return -EINTR;
  32887. +
  32888. + /* disconnect ports if connected */
  32889. + if (src->connected != NULL) {
  32890. + ret = port_disable(instance, src);
  32891. + if (ret) {
  32892. + pr_err("failed disabling src port(%d)\n", ret);
  32893. + goto release_unlock;
  32894. + }
  32895. +
  32896. + /* do not need to disable the destination port as they
  32897. + * are connected and it is done automatically
  32898. + */
  32899. +
  32900. + ret = port_action_handle(instance, src,
  32901. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
  32902. + src->connected->component->handle,
  32903. + src->connected->handle);
  32904. + if (ret < 0) {
  32905. + pr_err("failed disconnecting src port\n");
  32906. + goto release_unlock;
  32907. + }
  32908. + src->connected->enabled = false;
  32909. + src->connected = NULL;
  32910. + }
  32911. +
  32912. + if (dst == NULL) {
  32913. + /* do not make new connection */
  32914. + ret = 0;
  32915. + pr_debug("not making new connection\n");
  32916. + goto release_unlock;
  32917. + }
  32918. +
  32919. + /* copy src port format to dst */
  32920. + dst->format.encoding = src->format.encoding;
  32921. + dst->es.video.width = src->es.video.width;
  32922. + dst->es.video.height = src->es.video.height;
  32923. + dst->es.video.crop.x = src->es.video.crop.x;
  32924. + dst->es.video.crop.y = src->es.video.crop.y;
  32925. + dst->es.video.crop.width = src->es.video.crop.width;
  32926. + dst->es.video.crop.height = src->es.video.crop.height;
  32927. + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
  32928. + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
  32929. +
  32930. + /* set new format */
  32931. + ret = port_info_set(instance, dst);
  32932. + if (ret) {
  32933. + pr_debug("setting port info failed\n");
  32934. + goto release_unlock;
  32935. + }
  32936. +
  32937. + /* read what has actually been set */
  32938. + ret = port_info_get(instance, dst);
  32939. + if (ret) {
  32940. + pr_debug("read back port info failed\n");
  32941. + goto release_unlock;
  32942. + }
  32943. +
  32944. + /* connect two ports together */
  32945. + ret = port_action_handle(instance, src,
  32946. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
  32947. + dst->component->handle, dst->handle);
  32948. + if (ret < 0) {
  32949. + pr_debug("connecting port %d:%d to %d:%d failed\n",
  32950. + src->component->handle, src->handle,
  32951. + dst->component->handle, dst->handle);
  32952. + goto release_unlock;
  32953. + }
  32954. + src->connected = dst;
  32955. +
  32956. +release_unlock:
  32957. +
  32958. + mutex_unlock(&instance->vchiq_mutex);
  32959. +
  32960. + return ret;
  32961. +}
  32962. +
  32963. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  32964. + struct vchiq_mmal_port *port,
  32965. + struct mmal_buffer *buffer)
  32966. +{
  32967. + unsigned long flags = 0;
  32968. +
  32969. + spin_lock_irqsave(&port->slock, flags);
  32970. + list_add_tail(&buffer->list, &port->buffers);
  32971. + spin_unlock_irqrestore(&port->slock, flags);
  32972. +
  32973. + /* the port previously underflowed because it was missing a
  32974. + * mmal_buffer which has just been added, submit that buffer
  32975. + * to the mmal service.
  32976. + */
  32977. + if (port->buffer_underflow) {
  32978. + port_buffer_from_host(instance, port);
  32979. + port->buffer_underflow--;
  32980. + }
  32981. +
  32982. + return 0;
  32983. +}
  32984. +
  32985. +/* Initialise a mmal component and its ports
  32986. + *
  32987. + */
  32988. +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
  32989. + const char *name,
  32990. + struct vchiq_mmal_component **component_out)
  32991. +{
  32992. + int ret;
  32993. + int idx; /* port index */
  32994. + struct vchiq_mmal_component *component;
  32995. +
  32996. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  32997. + return -EINTR;
  32998. +
  32999. + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
  33000. + ret = -EINVAL; /* todo is this correct error? */
  33001. + goto unlock;
  33002. + }
  33003. +
  33004. + component = &instance->component[instance->component_idx];
  33005. +
  33006. + ret = create_component(instance, component, name);
  33007. + if (ret < 0)
  33008. + goto unlock;
  33009. +
  33010. + /* ports info needs gathering */
  33011. + component->control.type = MMAL_PORT_TYPE_CONTROL;
  33012. + component->control.index = 0;
  33013. + component->control.component = component;
  33014. + spin_lock_init(&component->control.slock);
  33015. + INIT_LIST_HEAD(&component->control.buffers);
  33016. + ret = port_info_get(instance, &component->control);
  33017. + if (ret < 0)
  33018. + goto release_component;
  33019. +
  33020. + for (idx = 0; idx < component->inputs; idx++) {
  33021. + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
  33022. + component->input[idx].index = idx;
  33023. + component->input[idx].component = component;
  33024. + spin_lock_init(&component->input[idx].slock);
  33025. + INIT_LIST_HEAD(&component->input[idx].buffers);
  33026. + ret = port_info_get(instance, &component->input[idx]);
  33027. + if (ret < 0)
  33028. + goto release_component;
  33029. + }
  33030. +
  33031. + for (idx = 0; idx < component->outputs; idx++) {
  33032. + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
  33033. + component->output[idx].index = idx;
  33034. + component->output[idx].component = component;
  33035. + spin_lock_init(&component->output[idx].slock);
  33036. + INIT_LIST_HEAD(&component->output[idx].buffers);
  33037. + ret = port_info_get(instance, &component->output[idx]);
  33038. + if (ret < 0)
  33039. + goto release_component;
  33040. + }
  33041. +
  33042. + for (idx = 0; idx < component->clocks; idx++) {
  33043. + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
  33044. + component->clock[idx].index = idx;
  33045. + component->clock[idx].component = component;
  33046. + spin_lock_init(&component->clock[idx].slock);
  33047. + INIT_LIST_HEAD(&component->clock[idx].buffers);
  33048. + ret = port_info_get(instance, &component->clock[idx]);
  33049. + if (ret < 0)
  33050. + goto release_component;
  33051. + }
  33052. +
  33053. + instance->component_idx++;
  33054. +
  33055. + *component_out = component;
  33056. +
  33057. + mutex_unlock(&instance->vchiq_mutex);
  33058. +
  33059. + return 0;
  33060. +
  33061. +release_component:
  33062. + destroy_component(instance, component);
  33063. +unlock:
  33064. + mutex_unlock(&instance->vchiq_mutex);
  33065. +
  33066. + return ret;
  33067. +}
  33068. +
  33069. +/*
  33070. + * cause a mmal component to be destroyed
  33071. + */
  33072. +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
  33073. + struct vchiq_mmal_component *component)
  33074. +{
  33075. + int ret;
  33076. +
  33077. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  33078. + return -EINTR;
  33079. +
  33080. + if (component->enabled)
  33081. + ret = disable_component(instance, component);
  33082. +
  33083. + ret = destroy_component(instance, component);
  33084. +
  33085. + mutex_unlock(&instance->vchiq_mutex);
  33086. +
  33087. + return ret;
  33088. +}
  33089. +
  33090. +/*
  33091. + * cause a mmal component to be enabled
  33092. + */
  33093. +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
  33094. + struct vchiq_mmal_component *component)
  33095. +{
  33096. + int ret;
  33097. +
  33098. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  33099. + return -EINTR;
  33100. +
  33101. + if (component->enabled) {
  33102. + mutex_unlock(&instance->vchiq_mutex);
  33103. + return 0;
  33104. + }
  33105. +
  33106. + ret = enable_component(instance, component);
  33107. + if (ret == 0)
  33108. + component->enabled = true;
  33109. +
  33110. + mutex_unlock(&instance->vchiq_mutex);
  33111. +
  33112. + return ret;
  33113. +}
  33114. +
  33115. +/*
  33116. + * cause a mmal component to be enabled
  33117. + */
  33118. +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
  33119. + struct vchiq_mmal_component *component)
  33120. +{
  33121. + int ret;
  33122. +
  33123. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  33124. + return -EINTR;
  33125. +
  33126. + if (!component->enabled) {
  33127. + mutex_unlock(&instance->vchiq_mutex);
  33128. + return 0;
  33129. + }
  33130. +
  33131. + ret = disable_component(instance, component);
  33132. + if (ret == 0)
  33133. + component->enabled = false;
  33134. +
  33135. + mutex_unlock(&instance->vchiq_mutex);
  33136. +
  33137. + return ret;
  33138. +}
  33139. +
  33140. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  33141. + u32 *major_out, u32 *minor_out)
  33142. +{
  33143. + int ret;
  33144. +
  33145. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  33146. + return -EINTR;
  33147. +
  33148. + ret = get_version(instance, major_out, minor_out);
  33149. +
  33150. + mutex_unlock(&instance->vchiq_mutex);
  33151. +
  33152. + return ret;
  33153. +}
  33154. +
  33155. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
  33156. +{
  33157. + int status = 0;
  33158. +
  33159. + if (instance == NULL)
  33160. + return -EINVAL;
  33161. +
  33162. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  33163. + return -EINTR;
  33164. +
  33165. + vchi_service_use(instance->handle);
  33166. +
  33167. + status = vchi_service_close(instance->handle);
  33168. + if (status != 0)
  33169. + pr_err("mmal-vchiq: VCHIQ close failed");
  33170. +
  33171. + mutex_unlock(&instance->vchiq_mutex);
  33172. +
  33173. + vfree(instance->bulk_scratch);
  33174. +
  33175. + kfree(instance);
  33176. +
  33177. + return status;
  33178. +}
  33179. +
  33180. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
  33181. +{
  33182. + int status;
  33183. + struct vchiq_mmal_instance *instance;
  33184. + static VCHI_CONNECTION_T *vchi_connection;
  33185. + static VCHI_INSTANCE_T vchi_instance;
  33186. + SERVICE_CREATION_T params = {
  33187. + VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
  33188. + VC_MMAL_SERVER_NAME,
  33189. + vchi_connection,
  33190. + 0, /* rx fifo size (unused) */
  33191. + 0, /* tx fifo size (unused) */
  33192. + service_callback,
  33193. + NULL, /* service callback parameter */
  33194. + 1, /* unaligned bulk receives */
  33195. + 1, /* unaligned bulk transmits */
  33196. + 0 /* want crc check on bulk transfers */
  33197. + };
  33198. +
  33199. + /* compile time checks to ensure structure size as they are
  33200. + * directly (de)serialised from memory.
  33201. + */
  33202. +
  33203. + /* ensure the header structure has packed to the correct size */
  33204. + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
  33205. +
  33206. + /* ensure message structure does not exceed maximum length */
  33207. + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
  33208. +
  33209. + /* mmal port struct is correct size */
  33210. + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
  33211. +
  33212. + /* create a vchi instance */
  33213. + status = vchi_initialise(&vchi_instance);
  33214. + if (status) {
  33215. + pr_err("Failed to initialise VCHI instance (status=%d)\n",
  33216. + status);
  33217. + return -EIO;
  33218. + }
  33219. +
  33220. + status = vchi_connect(NULL, 0, vchi_instance);
  33221. + if (status) {
  33222. + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
  33223. + return -EIO;
  33224. + }
  33225. +
  33226. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  33227. + memset(instance, 0, sizeof(*instance));
  33228. +
  33229. + mutex_init(&instance->vchiq_mutex);
  33230. + mutex_init(&instance->bulk_mutex);
  33231. +
  33232. + instance->bulk_scratch = vmalloc(PAGE_SIZE);
  33233. +
  33234. + params.callback_param = instance;
  33235. +
  33236. + status = vchi_service_open(vchi_instance, &params, &instance->handle);
  33237. + if (status) {
  33238. + pr_err("Failed to open VCHI service connection (status=%d)\n",
  33239. + status);
  33240. + goto err_close_services;
  33241. + }
  33242. +
  33243. + vchi_service_release(instance->handle);
  33244. +
  33245. + *out_instance = instance;
  33246. +
  33247. + return 0;
  33248. +
  33249. +err_close_services:
  33250. +
  33251. + vchi_service_close(instance->handle);
  33252. + vfree(instance->bulk_scratch);
  33253. + kfree(instance);
  33254. + return -ENODEV;
  33255. +}
  33256. diff -Nur linux-3.18.6/drivers/media/platform/bcm2835/mmal-vchiq.h linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.h
  33257. --- linux-3.18.6/drivers/media/platform/bcm2835/mmal-vchiq.h 1970-01-01 01:00:00.000000000 +0100
  33258. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.h 2015-02-09 04:40:03.000000000 +0100
  33259. @@ -0,0 +1,178 @@
  33260. +/*
  33261. + * Broadcom BM2835 V4L2 driver
  33262. + *
  33263. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  33264. + *
  33265. + * This file is subject to the terms and conditions of the GNU General Public
  33266. + * License. See the file COPYING in the main directory of this archive
  33267. + * for more details.
  33268. + *
  33269. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  33270. + * Dave Stevenson <dsteve@broadcom.com>
  33271. + * Simon Mellor <simellor@broadcom.com>
  33272. + * Luke Diamand <luked@broadcom.com>
  33273. + *
  33274. + * MMAL interface to VCHIQ message passing
  33275. + */
  33276. +
  33277. +#ifndef MMAL_VCHIQ_H
  33278. +#define MMAL_VCHIQ_H
  33279. +
  33280. +#include "mmal-msg-format.h"
  33281. +
  33282. +#define MAX_PORT_COUNT 4
  33283. +
  33284. +/* Maximum size of the format extradata. */
  33285. +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
  33286. +
  33287. +struct vchiq_mmal_instance;
  33288. +
  33289. +enum vchiq_mmal_es_type {
  33290. + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
  33291. + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
  33292. + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
  33293. + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
  33294. + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
  33295. +};
  33296. +
  33297. +/* rectangle, used lots so it gets its own struct */
  33298. +struct vchiq_mmal_rect {
  33299. + s32 x;
  33300. + s32 y;
  33301. + s32 width;
  33302. + s32 height;
  33303. +};
  33304. +
  33305. +struct vchiq_mmal_port_buffer {
  33306. + unsigned int num; /* number of buffers */
  33307. + u32 size; /* size of buffers */
  33308. + u32 alignment; /* alignment of buffers */
  33309. +};
  33310. +
  33311. +struct vchiq_mmal_port;
  33312. +
  33313. +typedef void (*vchiq_mmal_buffer_cb)(
  33314. + struct vchiq_mmal_instance *instance,
  33315. + struct vchiq_mmal_port *port,
  33316. + int status, struct mmal_buffer *buffer,
  33317. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
  33318. +
  33319. +struct vchiq_mmal_port {
  33320. + bool enabled;
  33321. + u32 handle;
  33322. + u32 type; /* port type, cached to use on port info set */
  33323. + u32 index; /* port index, cached to use on port info set */
  33324. +
  33325. + /* component port belongs to, allows simple deref */
  33326. + struct vchiq_mmal_component *component;
  33327. +
  33328. + struct vchiq_mmal_port *connected; /* port conencted to */
  33329. +
  33330. + /* buffer info */
  33331. + struct vchiq_mmal_port_buffer minimum_buffer;
  33332. + struct vchiq_mmal_port_buffer recommended_buffer;
  33333. + struct vchiq_mmal_port_buffer current_buffer;
  33334. +
  33335. + /* stream format */
  33336. + struct mmal_es_format format;
  33337. + /* elementry stream format */
  33338. + union mmal_es_specific_format es;
  33339. +
  33340. + /* data buffers to fill */
  33341. + struct list_head buffers;
  33342. + /* lock to serialise adding and removing buffers from list */
  33343. + spinlock_t slock;
  33344. + /* count of how many buffer header refils have failed because
  33345. + * there was no buffer to satisfy them
  33346. + */
  33347. + int buffer_underflow;
  33348. + /* callback on buffer completion */
  33349. + vchiq_mmal_buffer_cb buffer_cb;
  33350. + /* callback context */
  33351. + void *cb_ctx;
  33352. +};
  33353. +
  33354. +struct vchiq_mmal_component {
  33355. + bool enabled;
  33356. + u32 handle; /* VideoCore handle for component */
  33357. + u32 inputs; /* Number of input ports */
  33358. + u32 outputs; /* Number of output ports */
  33359. + u32 clocks; /* Number of clock ports */
  33360. + struct vchiq_mmal_port control; /* control port */
  33361. + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
  33362. + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
  33363. + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
  33364. +};
  33365. +
  33366. +
  33367. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
  33368. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
  33369. +
  33370. +/* Initialise a mmal component and its ports
  33371. +*
  33372. +*/
  33373. +int vchiq_mmal_component_init(
  33374. + struct vchiq_mmal_instance *instance,
  33375. + const char *name,
  33376. + struct vchiq_mmal_component **component_out);
  33377. +
  33378. +int vchiq_mmal_component_finalise(
  33379. + struct vchiq_mmal_instance *instance,
  33380. + struct vchiq_mmal_component *component);
  33381. +
  33382. +int vchiq_mmal_component_enable(
  33383. + struct vchiq_mmal_instance *instance,
  33384. + struct vchiq_mmal_component *component);
  33385. +
  33386. +int vchiq_mmal_component_disable(
  33387. + struct vchiq_mmal_instance *instance,
  33388. + struct vchiq_mmal_component *component);
  33389. +
  33390. +
  33391. +
  33392. +/* enable a mmal port
  33393. + *
  33394. + * enables a port and if a buffer callback provided enque buffer
  33395. + * headers as apropriate for the port.
  33396. + */
  33397. +int vchiq_mmal_port_enable(
  33398. + struct vchiq_mmal_instance *instance,
  33399. + struct vchiq_mmal_port *port,
  33400. + vchiq_mmal_buffer_cb buffer_cb);
  33401. +
  33402. +/* disable a port
  33403. + *
  33404. + * disable a port will dequeue any pending buffers
  33405. + */
  33406. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  33407. + struct vchiq_mmal_port *port);
  33408. +
  33409. +
  33410. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  33411. + struct vchiq_mmal_port *port,
  33412. + u32 parameter,
  33413. + void *value,
  33414. + u32 value_size);
  33415. +
  33416. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  33417. + struct vchiq_mmal_port *port,
  33418. + u32 parameter,
  33419. + void *value,
  33420. + u32 *value_size);
  33421. +
  33422. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  33423. + struct vchiq_mmal_port *port);
  33424. +
  33425. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  33426. + struct vchiq_mmal_port *src,
  33427. + struct vchiq_mmal_port *dst);
  33428. +
  33429. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  33430. + u32 *major_out,
  33431. + u32 *minor_out);
  33432. +
  33433. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  33434. + struct vchiq_mmal_port *port,
  33435. + struct mmal_buffer *buf);
  33436. +
  33437. +#endif /* MMAL_VCHIQ_H */
  33438. diff -Nur linux-3.18.6/drivers/media/platform/Kconfig linux-rpi/drivers/media/platform/Kconfig
  33439. --- linux-3.18.6/drivers/media/platform/Kconfig 2015-02-06 15:53:48.000000000 +0100
  33440. +++ linux-rpi/drivers/media/platform/Kconfig 2015-02-09 04:40:03.000000000 +0100
  33441. @@ -126,6 +126,7 @@
  33442. source "drivers/media/platform/soc_camera/Kconfig"
  33443. source "drivers/media/platform/exynos4-is/Kconfig"
  33444. source "drivers/media/platform/s5p-tv/Kconfig"
  33445. +source "drivers/media/platform/bcm2835/Kconfig"
  33446. endif # V4L_PLATFORM_DRIVERS
  33447. diff -Nur linux-3.18.6/drivers/media/platform/Makefile linux-rpi/drivers/media/platform/Makefile
  33448. --- linux-3.18.6/drivers/media/platform/Makefile 2015-02-06 15:53:48.000000000 +0100
  33449. +++ linux-rpi/drivers/media/platform/Makefile 2015-02-09 04:40:03.000000000 +0100
  33450. @@ -49,4 +49,6 @@
  33451. obj-y += omap/
  33452. +obj-$(CONFIG_VIDEO_BCM2835) += bcm2835/
  33453. +
  33454. ccflags-y += -I$(srctree)/drivers/media/i2c
  33455. diff -Nur linux-3.18.6/drivers/media/usb/dvb-usb-v2/rtl28xxu.c linux-rpi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
  33456. --- linux-3.18.6/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2015-02-06 15:53:48.000000000 +0100
  33457. +++ linux-rpi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2015-02-09 04:40:03.000000000 +0100
  33458. @@ -1531,6 +1531,10 @@
  33459. &rtl2832u_props, "Compro VideoMate U620F", NULL) },
  33460. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
  33461. &rtl2832u_props, "MaxMedia HU394-T", NULL) },
  33462. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xb803 /*USB_PID_AUGUST_DVBT205*/,
  33463. + &rtl2832u_props, "August DVB-T 205", NULL) },
  33464. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xa803 /*USB_PID_AUGUST_DVBT205*/,
  33465. + &rtl2832u_props, "August DVB-T 205", NULL) },
  33466. { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
  33467. &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
  33468. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
  33469. diff -Nur linux-3.18.6/drivers/misc/Kconfig linux-rpi/drivers/misc/Kconfig
  33470. --- linux-3.18.6/drivers/misc/Kconfig 2015-02-06 15:53:48.000000000 +0100
  33471. +++ linux-rpi/drivers/misc/Kconfig 2015-02-09 04:40:04.000000000 +0100
  33472. @@ -524,6 +524,7 @@
  33473. source "drivers/misc/altera-stapl/Kconfig"
  33474. source "drivers/misc/mei/Kconfig"
  33475. source "drivers/misc/vmw_vmci/Kconfig"
  33476. +source "drivers/misc/vc04_services/Kconfig"
  33477. source "drivers/misc/mic/Kconfig"
  33478. source "drivers/misc/genwqe/Kconfig"
  33479. source "drivers/misc/echo/Kconfig"
  33480. diff -Nur linux-3.18.6/drivers/misc/Makefile linux-rpi/drivers/misc/Makefile
  33481. --- linux-3.18.6/drivers/misc/Makefile 2015-02-06 15:53:48.000000000 +0100
  33482. +++ linux-rpi/drivers/misc/Makefile 2015-02-09 04:40:04.000000000 +0100
  33483. @@ -51,6 +51,7 @@
  33484. obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
  33485. obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
  33486. obj-$(CONFIG_SRAM) += sram.o
  33487. +obj-$(CONFIG_BCM2708_VCHIQ) += vc04_services/
  33488. obj-y += mic/
  33489. obj-$(CONFIG_GENWQE) += genwqe/
  33490. obj-$(CONFIG_ECHO) += echo/
  33491. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchi/connections/connection.h linux-rpi/drivers/misc/vc04_services/interface/vchi/connections/connection.h
  33492. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchi/connections/connection.h 1970-01-01 01:00:00.000000000 +0100
  33493. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/connections/connection.h 2015-02-09 04:40:07.000000000 +0100
  33494. @@ -0,0 +1,328 @@
  33495. +/**
  33496. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  33497. + *
  33498. + * Redistribution and use in source and binary forms, with or without
  33499. + * modification, are permitted provided that the following conditions
  33500. + * are met:
  33501. + * 1. Redistributions of source code must retain the above copyright
  33502. + * notice, this list of conditions, and the following disclaimer,
  33503. + * without modification.
  33504. + * 2. Redistributions in binary form must reproduce the above copyright
  33505. + * notice, this list of conditions and the following disclaimer in the
  33506. + * documentation and/or other materials provided with the distribution.
  33507. + * 3. The names of the above-listed copyright holders may not be used
  33508. + * to endorse or promote products derived from this software without
  33509. + * specific prior written permission.
  33510. + *
  33511. + * ALTERNATIVELY, this software may be distributed under the terms of the
  33512. + * GNU General Public License ("GPL") version 2, as published by the Free
  33513. + * Software Foundation.
  33514. + *
  33515. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  33516. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  33517. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  33518. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  33519. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  33520. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33521. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  33522. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33523. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33524. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33525. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33526. + */
  33527. +
  33528. +#ifndef CONNECTION_H_
  33529. +#define CONNECTION_H_
  33530. +
  33531. +#include <linux/kernel.h>
  33532. +#include <linux/types.h>
  33533. +#include <linux/semaphore.h>
  33534. +
  33535. +#include "interface/vchi/vchi_cfg_internal.h"
  33536. +#include "interface/vchi/vchi_common.h"
  33537. +#include "interface/vchi/message_drivers/message.h"
  33538. +
  33539. +/******************************************************************************
  33540. + Global defs
  33541. + *****************************************************************************/
  33542. +
  33543. +// Opaque handle for a connection / service pair
  33544. +typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;
  33545. +
  33546. +// opaque handle to the connection state information
  33547. +typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;
  33548. +
  33549. +typedef struct vchi_connection_t VCHI_CONNECTION_T;
  33550. +
  33551. +
  33552. +/******************************************************************************
  33553. + API
  33554. + *****************************************************************************/
  33555. +
  33556. +// Routine to init a connection with a particular low level driver
  33557. +typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,
  33558. + const VCHI_MESSAGE_DRIVER_T * driver );
  33559. +
  33560. +// Routine to control CRC enabling at a connection level
  33561. +typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,
  33562. + VCHI_CRC_CONTROL_T control );
  33563. +
  33564. +// Routine to create a service
  33565. +typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,
  33566. + int32_t service_id,
  33567. + uint32_t rx_fifo_size,
  33568. + uint32_t tx_fifo_size,
  33569. + int server,
  33570. + VCHI_CALLBACK_T callback,
  33571. + void *callback_param,
  33572. + int32_t want_crc,
  33573. + int32_t want_unaligned_bulk_rx,
  33574. + int32_t want_unaligned_bulk_tx,
  33575. + VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );
  33576. +
  33577. +// Routine to close a service
  33578. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );
  33579. +
  33580. +// Routine to queue a message
  33581. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33582. + const void *data,
  33583. + uint32_t data_size,
  33584. + VCHI_FLAGS_T flags,
  33585. + void *msg_handle );
  33586. +
  33587. +// scatter-gather (vector) message queueing
  33588. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33589. + VCHI_MSG_VECTOR_T *vector,
  33590. + uint32_t count,
  33591. + VCHI_FLAGS_T flags,
  33592. + void *msg_handle );
  33593. +
  33594. +// Routine to dequeue a message
  33595. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33596. + void *data,
  33597. + uint32_t max_data_size_to_read,
  33598. + uint32_t *actual_msg_size,
  33599. + VCHI_FLAGS_T flags );
  33600. +
  33601. +// Routine to peek at a message
  33602. +typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33603. + void **data,
  33604. + uint32_t *msg_size,
  33605. + VCHI_FLAGS_T flags );
  33606. +
  33607. +// Routine to hold a message
  33608. +typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33609. + void **data,
  33610. + uint32_t *msg_size,
  33611. + VCHI_FLAGS_T flags,
  33612. + void **message_handle );
  33613. +
  33614. +// Routine to initialise a received message iterator
  33615. +typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33616. + VCHI_MSG_ITER_T *iter,
  33617. + VCHI_FLAGS_T flags );
  33618. +
  33619. +// Routine to release a held message
  33620. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33621. + void *message_handle );
  33622. +
  33623. +// Routine to get info on a held message
  33624. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33625. + void *message_handle,
  33626. + void **data,
  33627. + int32_t *msg_size,
  33628. + uint32_t *tx_timestamp,
  33629. + uint32_t *rx_timestamp );
  33630. +
  33631. +// Routine to check whether the iterator has a next message
  33632. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  33633. + const VCHI_MSG_ITER_T *iter );
  33634. +
  33635. +// Routine to advance the iterator
  33636. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  33637. + VCHI_MSG_ITER_T *iter,
  33638. + void **data,
  33639. + uint32_t *msg_size );
  33640. +
  33641. +// Routine to remove the last message returned by the iterator
  33642. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  33643. + VCHI_MSG_ITER_T *iter );
  33644. +
  33645. +// Routine to hold the last message returned by the iterator
  33646. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  33647. + VCHI_MSG_ITER_T *iter,
  33648. + void **msg_handle );
  33649. +
  33650. +// Routine to transmit bulk data
  33651. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33652. + const void *data_src,
  33653. + uint32_t data_size,
  33654. + VCHI_FLAGS_T flags,
  33655. + void *bulk_handle );
  33656. +
  33657. +// Routine to receive data
  33658. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  33659. + void *data_dst,
  33660. + uint32_t data_size,
  33661. + VCHI_FLAGS_T flags,
  33662. + void *bulk_handle );
  33663. +
  33664. +// Routine to report if a server is available
  33665. +typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );
  33666. +
  33667. +// Routine to report the number of RX slots available
  33668. +typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );
  33669. +
  33670. +// Routine to report the RX slot size
  33671. +typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );
  33672. +
  33673. +// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  33674. +typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,
  33675. + int32_t service,
  33676. + uint32_t length,
  33677. + MESSAGE_TX_CHANNEL_T channel,
  33678. + uint32_t channel_params,
  33679. + uint32_t data_length,
  33680. + uint32_t data_offset);
  33681. +
  33682. +// Callback to inform a service that a Xon or Xoff message has been received
  33683. +typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);
  33684. +
  33685. +// Callback to inform a service that a server available reply message has been received
  33686. +typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);
  33687. +
  33688. +// Callback to indicate that bulk auxiliary messages have arrived
  33689. +typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);
  33690. +
  33691. +// Callback to indicate that bulk auxiliary messages have arrived
  33692. +typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);
  33693. +
  33694. +// Callback with all the connection info you require
  33695. +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);
  33696. +
  33697. +// Callback to inform of a disconnect
  33698. +typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);
  33699. +
  33700. +// Callback to inform of a power control request
  33701. +typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);
  33702. +
  33703. +// allocate memory suitably aligned for this connection
  33704. +typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);
  33705. +
  33706. +// free memory allocated by buffer_allocate
  33707. +typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);
  33708. +
  33709. +
  33710. +/******************************************************************************
  33711. + System driver struct
  33712. + *****************************************************************************/
  33713. +
  33714. +struct opaque_vchi_connection_api_t
  33715. +{
  33716. + // Routine to init the connection
  33717. + VCHI_CONNECTION_INIT_T init;
  33718. +
  33719. + // Connection-level CRC control
  33720. + VCHI_CONNECTION_CRC_CONTROL_T crc_control;
  33721. +
  33722. + // Routine to connect to or create service
  33723. + VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;
  33724. +
  33725. + // Routine to disconnect from a service
  33726. + VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;
  33727. +
  33728. + // Routine to queue a message
  33729. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;
  33730. +
  33731. + // scatter-gather (vector) message queue
  33732. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;
  33733. +
  33734. + // Routine to dequeue a message
  33735. + VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;
  33736. +
  33737. + // Routine to peek at a message
  33738. + VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;
  33739. +
  33740. + // Routine to hold a message
  33741. + VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;
  33742. +
  33743. + // Routine to initialise a received message iterator
  33744. + VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;
  33745. +
  33746. + // Routine to release a message
  33747. + VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;
  33748. +
  33749. + // Routine to get information on a held message
  33750. + VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;
  33751. +
  33752. + // Routine to check for next message on iterator
  33753. + VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;
  33754. +
  33755. + // Routine to get next message on iterator
  33756. + VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;
  33757. +
  33758. + // Routine to remove the last message returned by iterator
  33759. + VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;
  33760. +
  33761. + // Routine to hold the last message returned by iterator
  33762. + VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;
  33763. +
  33764. + // Routine to transmit bulk data
  33765. + VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;
  33766. +
  33767. + // Routine to receive data
  33768. + VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;
  33769. +
  33770. + // Routine to report the available servers
  33771. + VCHI_CONNECTION_SERVER_PRESENT server_present;
  33772. +
  33773. + // Routine to report the number of RX slots available
  33774. + VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;
  33775. +
  33776. + // Routine to report the RX slot size
  33777. + VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;
  33778. +
  33779. + // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  33780. + VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;
  33781. +
  33782. + // Callback to inform a service that a Xon or Xoff message has been received
  33783. + VCHI_CONNECTION_FLOW_CONTROL flow_control;
  33784. +
  33785. + // Callback to inform a service that a server available reply message has been received
  33786. + VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;
  33787. +
  33788. + // Callback to indicate that bulk auxiliary messages have arrived
  33789. + VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;
  33790. +
  33791. + // Callback to indicate that a bulk auxiliary message has been transmitted
  33792. + VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;
  33793. +
  33794. + // Callback to provide information about the connection
  33795. + VCHI_CONNECTION_INFO connection_info;
  33796. +
  33797. + // Callback to notify that peer has requested disconnect
  33798. + VCHI_CONNECTION_DISCONNECT disconnect;
  33799. +
  33800. + // Callback to notify that peer has requested power change
  33801. + VCHI_CONNECTION_POWER_CONTROL power_control;
  33802. +
  33803. + // allocate memory suitably aligned for this connection
  33804. + VCHI_BUFFER_ALLOCATE buffer_allocate;
  33805. +
  33806. + // free memory allocated by buffer_allocate
  33807. + VCHI_BUFFER_FREE buffer_free;
  33808. +
  33809. +};
  33810. +
  33811. +struct vchi_connection_t {
  33812. + const VCHI_CONNECTION_API_T *api;
  33813. + VCHI_CONNECTION_STATE_T *state;
  33814. +#ifdef VCHI_COARSE_LOCKING
  33815. + struct semaphore sem;
  33816. +#endif
  33817. +};
  33818. +
  33819. +
  33820. +#endif /* CONNECTION_H_ */
  33821. +
  33822. +/****************************** End of file **********************************/
  33823. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h linux-rpi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h
  33824. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 1970-01-01 01:00:00.000000000 +0100
  33825. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 2015-02-09 04:40:07.000000000 +0100
  33826. @@ -0,0 +1,204 @@
  33827. +/**
  33828. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  33829. + *
  33830. + * Redistribution and use in source and binary forms, with or without
  33831. + * modification, are permitted provided that the following conditions
  33832. + * are met:
  33833. + * 1. Redistributions of source code must retain the above copyright
  33834. + * notice, this list of conditions, and the following disclaimer,
  33835. + * without modification.
  33836. + * 2. Redistributions in binary form must reproduce the above copyright
  33837. + * notice, this list of conditions and the following disclaimer in the
  33838. + * documentation and/or other materials provided with the distribution.
  33839. + * 3. The names of the above-listed copyright holders may not be used
  33840. + * to endorse or promote products derived from this software without
  33841. + * specific prior written permission.
  33842. + *
  33843. + * ALTERNATIVELY, this software may be distributed under the terms of the
  33844. + * GNU General Public License ("GPL") version 2, as published by the Free
  33845. + * Software Foundation.
  33846. + *
  33847. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  33848. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  33849. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  33850. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  33851. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  33852. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33853. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  33854. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33855. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33856. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33857. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33858. + */
  33859. +
  33860. +#ifndef _VCHI_MESSAGE_H_
  33861. +#define _VCHI_MESSAGE_H_
  33862. +
  33863. +#include <linux/kernel.h>
  33864. +#include <linux/types.h>
  33865. +#include <linux/semaphore.h>
  33866. +
  33867. +#include "interface/vchi/vchi_cfg_internal.h"
  33868. +#include "interface/vchi/vchi_common.h"
  33869. +
  33870. +
  33871. +typedef enum message_event_type {
  33872. + MESSAGE_EVENT_NONE,
  33873. + MESSAGE_EVENT_NOP,
  33874. + MESSAGE_EVENT_MESSAGE,
  33875. + MESSAGE_EVENT_SLOT_COMPLETE,
  33876. + MESSAGE_EVENT_RX_BULK_PAUSED,
  33877. + MESSAGE_EVENT_RX_BULK_COMPLETE,
  33878. + MESSAGE_EVENT_TX_COMPLETE,
  33879. + MESSAGE_EVENT_MSG_DISCARDED
  33880. +} MESSAGE_EVENT_TYPE_T;
  33881. +
  33882. +typedef enum vchi_msg_flags
  33883. +{
  33884. + VCHI_MSG_FLAGS_NONE = 0x0,
  33885. + VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
  33886. +} VCHI_MSG_FLAGS_T;
  33887. +
  33888. +typedef enum message_tx_channel
  33889. +{
  33890. + MESSAGE_TX_CHANNEL_MESSAGE = 0,
  33891. + MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  33892. +} MESSAGE_TX_CHANNEL_T;
  33893. +
  33894. +// Macros used for cycling through bulk channels
  33895. +#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)
  33896. +#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
  33897. +
  33898. +typedef enum message_rx_channel
  33899. +{
  33900. + MESSAGE_RX_CHANNEL_MESSAGE = 0,
  33901. + MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  33902. +} MESSAGE_RX_CHANNEL_T;
  33903. +
  33904. +// Message receive slot information
  33905. +typedef struct rx_msg_slot_info {
  33906. +
  33907. + struct rx_msg_slot_info *next;
  33908. + //struct slot_info *prev;
  33909. +#if !defined VCHI_COARSE_LOCKING
  33910. + struct semaphore sem;
  33911. +#endif
  33912. +
  33913. + uint8_t *addr; // base address of slot
  33914. + uint32_t len; // length of slot in bytes
  33915. +
  33916. + uint32_t write_ptr; // hardware causes this to advance
  33917. + uint32_t read_ptr; // this module does the reading
  33918. + int active; // is this slot in the hardware dma fifo?
  33919. + uint32_t msgs_parsed; // count how many messages are in this slot
  33920. + uint32_t msgs_released; // how many messages have been released
  33921. + void *state; // connection state information
  33922. + uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
  33923. +} RX_MSG_SLOTINFO_T;
  33924. +
  33925. +// The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
  33926. +// In particular, it mustn't use addr and len - they're the client buffer, but the message
  33927. +// driver will be tasked with sending the aligned core section.
  33928. +typedef struct rx_bulk_slotinfo_t {
  33929. + struct rx_bulk_slotinfo_t *next;
  33930. +
  33931. + struct semaphore *blocking;
  33932. +
  33933. + // needed by DMA
  33934. + void *addr;
  33935. + uint32_t len;
  33936. +
  33937. + // needed for the callback
  33938. + void *service;
  33939. + void *handle;
  33940. + VCHI_FLAGS_T flags;
  33941. +} RX_BULK_SLOTINFO_T;
  33942. +
  33943. +
  33944. +/* ----------------------------------------------------------------------
  33945. + * each connection driver will have a pool of the following struct.
  33946. + *
  33947. + * the pool will be managed by vchi_qman_*
  33948. + * this means there will be multiple queues (single linked lists)
  33949. + * a given struct message_info will be on exactly one of these queues
  33950. + * at any one time
  33951. + * -------------------------------------------------------------------- */
  33952. +typedef struct rx_message_info {
  33953. +
  33954. + struct message_info *next;
  33955. + //struct message_info *prev;
  33956. +
  33957. + uint8_t *addr;
  33958. + uint32_t len;
  33959. + RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
  33960. + uint32_t tx_timestamp;
  33961. + uint32_t rx_timestamp;
  33962. +
  33963. +} RX_MESSAGE_INFO_T;
  33964. +
  33965. +typedef struct {
  33966. + MESSAGE_EVENT_TYPE_T type;
  33967. +
  33968. + struct {
  33969. + // for messages
  33970. + void *addr; // address of message
  33971. + uint16_t slot_delta; // whether this message indicated slot delta
  33972. + uint32_t len; // length of message
  33973. + RX_MSG_SLOTINFO_T *slot; // slot this message is in
  33974. + int32_t service; // service id this message is destined for
  33975. + uint32_t tx_timestamp; // timestamp from the header
  33976. + uint32_t rx_timestamp; // timestamp when we parsed it
  33977. + } message;
  33978. +
  33979. + // FIXME: cleanup slot reporting...
  33980. + RX_MSG_SLOTINFO_T *rx_msg;
  33981. + RX_BULK_SLOTINFO_T *rx_bulk;
  33982. + void *tx_handle;
  33983. + MESSAGE_TX_CHANNEL_T tx_channel;
  33984. +
  33985. +} MESSAGE_EVENT_T;
  33986. +
  33987. +
  33988. +// callbacks
  33989. +typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
  33990. +
  33991. +typedef struct {
  33992. + VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
  33993. +} VCHI_MESSAGE_DRIVER_OPEN_T;
  33994. +
  33995. +
  33996. +// handle to this instance of message driver (as returned by ->open)
  33997. +typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
  33998. +
  33999. +struct opaque_vchi_message_driver_t {
  34000. + VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
  34001. + int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
  34002. + int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
  34003. + int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
  34004. + int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
  34005. + int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
  34006. + 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)
  34007. + void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
  34008. + int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
  34009. + int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
  34010. + *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
  34011. +
  34012. + int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
  34013. + int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
  34014. + void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
  34015. + void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
  34016. + int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  34017. + int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  34018. +
  34019. + int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  34020. + uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  34021. + int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  34022. + int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
  34023. + 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 );
  34024. + void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
  34025. +};
  34026. +
  34027. +
  34028. +#endif // _VCHI_MESSAGE_H_
  34029. +
  34030. +/****************************** End of file ***********************************/
  34031. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h
  34032. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 1970-01-01 01:00:00.000000000 +0100
  34033. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 2015-02-09 04:40:07.000000000 +0100
  34034. @@ -0,0 +1,224 @@
  34035. +/**
  34036. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  34037. + *
  34038. + * Redistribution and use in source and binary forms, with or without
  34039. + * modification, are permitted provided that the following conditions
  34040. + * are met:
  34041. + * 1. Redistributions of source code must retain the above copyright
  34042. + * notice, this list of conditions, and the following disclaimer,
  34043. + * without modification.
  34044. + * 2. Redistributions in binary form must reproduce the above copyright
  34045. + * notice, this list of conditions and the following disclaimer in the
  34046. + * documentation and/or other materials provided with the distribution.
  34047. + * 3. The names of the above-listed copyright holders may not be used
  34048. + * to endorse or promote products derived from this software without
  34049. + * specific prior written permission.
  34050. + *
  34051. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34052. + * GNU General Public License ("GPL") version 2, as published by the Free
  34053. + * Software Foundation.
  34054. + *
  34055. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34056. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34057. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34058. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34059. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34060. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34061. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34062. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34063. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34064. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34065. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34066. + */
  34067. +
  34068. +#ifndef VCHI_CFG_H_
  34069. +#define VCHI_CFG_H_
  34070. +
  34071. +/****************************************************************************************
  34072. + * Defines in this first section are part of the VCHI API and may be examined by VCHI
  34073. + * services.
  34074. + ***************************************************************************************/
  34075. +
  34076. +/* Required alignment of base addresses for bulk transfer, if unaligned transfers are not enabled */
  34077. +/* Really determined by the message driver, and should be available from a run-time call. */
  34078. +#ifndef VCHI_BULK_ALIGN
  34079. +# if __VCCOREVER__ >= 0x04000000
  34080. +# define VCHI_BULK_ALIGN 32 // Allows for the need to do cache cleans
  34081. +# else
  34082. +# define VCHI_BULK_ALIGN 16
  34083. +# endif
  34084. +#endif
  34085. +
  34086. +/* Required length multiple for bulk transfers, if unaligned transfers are not enabled */
  34087. +/* May be less than or greater than VCHI_BULK_ALIGN */
  34088. +/* Really determined by the message driver, and should be available from a run-time call. */
  34089. +#ifndef VCHI_BULK_GRANULARITY
  34090. +# if __VCCOREVER__ >= 0x04000000
  34091. +# define VCHI_BULK_GRANULARITY 32 // Allows for the need to do cache cleans
  34092. +# else
  34093. +# define VCHI_BULK_GRANULARITY 16
  34094. +# endif
  34095. +#endif
  34096. +
  34097. +/* The largest possible message to be queued with vchi_msg_queue. */
  34098. +#ifndef VCHI_MAX_MSG_SIZE
  34099. +# if defined VCHI_LOCAL_HOST_PORT
  34100. +# define VCHI_MAX_MSG_SIZE 16384 // makes file transfers fast, but should they be using bulk?
  34101. +# else
  34102. +# define VCHI_MAX_MSG_SIZE 4096 // NOTE: THIS MUST BE LARGER THAN OR EQUAL TO THE SIZE OF THE KHRONOS MERGE BUFFER!!
  34103. +# endif
  34104. +#endif
  34105. +
  34106. +/******************************************************************************************
  34107. + * Defines below are system configuration options, and should not be used by VCHI services.
  34108. + *****************************************************************************************/
  34109. +
  34110. +/* How many connections can we support? A localhost implementation uses 2 connections,
  34111. + * 1 for host-app, 1 for VMCS, and these are hooked together by a loopback MPHI VCFW
  34112. + * driver. */
  34113. +#ifndef VCHI_MAX_NUM_CONNECTIONS
  34114. +# define VCHI_MAX_NUM_CONNECTIONS 3
  34115. +#endif
  34116. +
  34117. +/* How many services can we open per connection? Extending this doesn't cost processing time, just a small
  34118. + * amount of static memory. */
  34119. +#ifndef VCHI_MAX_SERVICES_PER_CONNECTION
  34120. +# define VCHI_MAX_SERVICES_PER_CONNECTION 36
  34121. +#endif
  34122. +
  34123. +/* Adjust if using a message driver that supports more logical TX channels */
  34124. +#ifndef VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION
  34125. +# define VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION 9 // 1 MPHI + 8 CCP2 logical channels
  34126. +#endif
  34127. +
  34128. +/* Adjust if using a message driver that supports more logical RX channels */
  34129. +#ifndef VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION
  34130. +# define VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION 1 // 1 MPHI
  34131. +#endif
  34132. +
  34133. +/* How many receive slots do we use. This times VCHI_MAX_MSG_SIZE gives the effective
  34134. + * receive queue space, less message headers. */
  34135. +#ifndef VCHI_NUM_READ_SLOTS
  34136. +# if defined(VCHI_LOCAL_HOST_PORT)
  34137. +# define VCHI_NUM_READ_SLOTS 4
  34138. +# else
  34139. +# define VCHI_NUM_READ_SLOTS 48
  34140. +# endif
  34141. +#endif
  34142. +
  34143. +/* Do we utilise overrun facility for receive message slots? Can aid peer transmit
  34144. + * performance. Only define on VideoCore end, talking to host.
  34145. + */
  34146. +//#define VCHI_MSG_RX_OVERRUN
  34147. +
  34148. +/* How many transmit slots do we use. Generally don't need many, as the hardware driver
  34149. + * underneath VCHI will usually have its own buffering. */
  34150. +#ifndef VCHI_NUM_WRITE_SLOTS
  34151. +# define VCHI_NUM_WRITE_SLOTS 4
  34152. +#endif
  34153. +
  34154. +/* If a service has held or queued received messages in VCHI_XOFF_THRESHOLD or more slots,
  34155. + * then it's taking up too much buffer space, and the peer service will be told to stop
  34156. + * transmitting with an XOFF message. For this to be effective, the VCHI_NUM_READ_SLOTS
  34157. + * needs to be considerably bigger than VCHI_NUM_WRITE_SLOTS, or the transmit latency
  34158. + * is too high. */
  34159. +#ifndef VCHI_XOFF_THRESHOLD
  34160. +# define VCHI_XOFF_THRESHOLD (VCHI_NUM_READ_SLOTS / 2)
  34161. +#endif
  34162. +
  34163. +/* After we've sent an XOFF, the peer will be told to resume transmission once the local
  34164. + * service has dequeued/released enough messages that it's now occupying
  34165. + * VCHI_XON_THRESHOLD slots or fewer. */
  34166. +#ifndef VCHI_XON_THRESHOLD
  34167. +# define VCHI_XON_THRESHOLD (VCHI_NUM_READ_SLOTS / 4)
  34168. +#endif
  34169. +
  34170. +/* A size below which a bulk transfer omits the handshake completely and always goes
  34171. + * via the message channel, if bulk auxiliary is being sent on that service. (The user
  34172. + * can guarantee this by enabling unaligned transmits).
  34173. + * Not API. */
  34174. +#ifndef VCHI_MIN_BULK_SIZE
  34175. +# define VCHI_MIN_BULK_SIZE ( VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096 )
  34176. +#endif
  34177. +
  34178. +/* Maximum size of bulk transmission chunks, for each interface type. A trade-off between
  34179. + * speed and latency; the smaller the chunk size the better change of messages and other
  34180. + * bulk transmissions getting in when big bulk transfers are happening. Set to 0 to not
  34181. + * break transmissions into chunks.
  34182. + */
  34183. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_MPHI
  34184. +# define VCHI_MAX_BULK_CHUNK_SIZE_MPHI (16 * 1024)
  34185. +#endif
  34186. +
  34187. +/* NB Chunked CCP2 transmissions violate the letter of the CCP2 spec by using "JPEG8" mode
  34188. + * with multiple-line frames. Only use if the receiver can cope. */
  34189. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_CCP2
  34190. +# define VCHI_MAX_BULK_CHUNK_SIZE_CCP2 0
  34191. +#endif
  34192. +
  34193. +/* How many TX messages can we have pending in our transmit slots. Once exhausted,
  34194. + * vchi_msg_queue will be blocked. */
  34195. +#ifndef VCHI_TX_MSG_QUEUE_SIZE
  34196. +# define VCHI_TX_MSG_QUEUE_SIZE 256
  34197. +#endif
  34198. +
  34199. +/* How many RX messages can we have parsed in the receive slots. Once exhausted, parsing
  34200. + * will be suspended until older messages are dequeued/released. */
  34201. +#ifndef VCHI_RX_MSG_QUEUE_SIZE
  34202. +# define VCHI_RX_MSG_QUEUE_SIZE 256
  34203. +#endif
  34204. +
  34205. +/* Really should be able to cope if we run out of received message descriptors, by
  34206. + * suspending parsing as the comment above says, but we don't. This sweeps the issue
  34207. + * under the carpet. */
  34208. +#if VCHI_RX_MSG_QUEUE_SIZE < (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  34209. +# undef VCHI_RX_MSG_QUEUE_SIZE
  34210. +# define VCHI_RX_MSG_QUEUE_SIZE (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  34211. +#endif
  34212. +
  34213. +/* How many bulk transmits can we have pending. Once exhausted, vchi_bulk_queue_transmit
  34214. + * will be blocked. */
  34215. +#ifndef VCHI_TX_BULK_QUEUE_SIZE
  34216. +# define VCHI_TX_BULK_QUEUE_SIZE 64
  34217. +#endif
  34218. +
  34219. +/* How many bulk receives can we have pending. Once exhausted, vchi_bulk_queue_receive
  34220. + * will be blocked. */
  34221. +#ifndef VCHI_RX_BULK_QUEUE_SIZE
  34222. +# define VCHI_RX_BULK_QUEUE_SIZE 64
  34223. +#endif
  34224. +
  34225. +/* A limit on how many outstanding bulk requests we expect the peer to give us. If
  34226. + * the peer asks for more than this, VCHI will fail and assert. The number is determined
  34227. + * by the peer's hardware - it's the number of outstanding requests that can be queued
  34228. + * on all bulk channels. VC3's MPHI peripheral allows 16. */
  34229. +#ifndef VCHI_MAX_PEER_BULK_REQUESTS
  34230. +# define VCHI_MAX_PEER_BULK_REQUESTS 32
  34231. +#endif
  34232. +
  34233. +/* Define VCHI_CCP2TX_MANUAL_POWER if the host tells us when to turn the CCP2
  34234. + * transmitter on and off.
  34235. + */
  34236. +/*#define VCHI_CCP2TX_MANUAL_POWER*/
  34237. +
  34238. +#ifndef VCHI_CCP2TX_MANUAL_POWER
  34239. +
  34240. +/* Timeout (in milliseconds) for putting the CCP2TX interface into IDLE state. Set
  34241. + * negative for no IDLE.
  34242. + */
  34243. +# ifndef VCHI_CCP2TX_IDLE_TIMEOUT
  34244. +# define VCHI_CCP2TX_IDLE_TIMEOUT 5
  34245. +# endif
  34246. +
  34247. +/* Timeout (in milliseconds) for putting the CCP2TX interface into OFF state. Set
  34248. + * negative for no OFF.
  34249. + */
  34250. +# ifndef VCHI_CCP2TX_OFF_TIMEOUT
  34251. +# define VCHI_CCP2TX_OFF_TIMEOUT 1000
  34252. +# endif
  34253. +
  34254. +#endif /* VCHI_CCP2TX_MANUAL_POWER */
  34255. +
  34256. +#endif /* VCHI_CFG_H_ */
  34257. +
  34258. +/****************************** End of file **********************************/
  34259. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h
  34260. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 1970-01-01 01:00:00.000000000 +0100
  34261. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 2015-02-09 04:40:07.000000000 +0100
  34262. @@ -0,0 +1,71 @@
  34263. +/**
  34264. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  34265. + *
  34266. + * Redistribution and use in source and binary forms, with or without
  34267. + * modification, are permitted provided that the following conditions
  34268. + * are met:
  34269. + * 1. Redistributions of source code must retain the above copyright
  34270. + * notice, this list of conditions, and the following disclaimer,
  34271. + * without modification.
  34272. + * 2. Redistributions in binary form must reproduce the above copyright
  34273. + * notice, this list of conditions and the following disclaimer in the
  34274. + * documentation and/or other materials provided with the distribution.
  34275. + * 3. The names of the above-listed copyright holders may not be used
  34276. + * to endorse or promote products derived from this software without
  34277. + * specific prior written permission.
  34278. + *
  34279. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34280. + * GNU General Public License ("GPL") version 2, as published by the Free
  34281. + * Software Foundation.
  34282. + *
  34283. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34284. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34285. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34286. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34287. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34288. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34289. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34290. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34291. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34292. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34293. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34294. + */
  34295. +
  34296. +#ifndef VCHI_CFG_INTERNAL_H_
  34297. +#define VCHI_CFG_INTERNAL_H_
  34298. +
  34299. +/****************************************************************************************
  34300. + * Control optimisation attempts.
  34301. + ***************************************************************************************/
  34302. +
  34303. +// Don't use lots of short-term locks - use great long ones, reducing the overall locks-per-second
  34304. +#define VCHI_COARSE_LOCKING
  34305. +
  34306. +// Avoid lock then unlock on exit from blocking queue operations (msg tx, bulk rx/tx)
  34307. +// (only relevant if VCHI_COARSE_LOCKING)
  34308. +#define VCHI_ELIDE_BLOCK_EXIT_LOCK
  34309. +
  34310. +// Avoid lock on non-blocking peek
  34311. +// (only relevant if VCHI_COARSE_LOCKING)
  34312. +#define VCHI_AVOID_PEEK_LOCK
  34313. +
  34314. +// Use one slot-handler thread per connection, rather than 1 thread dealing with all connections in rotation.
  34315. +#define VCHI_MULTIPLE_HANDLER_THREADS
  34316. +
  34317. +// Put free descriptors onto the head of the free queue, rather than the tail, so that we don't thrash
  34318. +// our way through the pool of descriptors.
  34319. +#define VCHI_PUSH_FREE_DESCRIPTORS_ONTO_HEAD
  34320. +
  34321. +// Don't issue a MSG_AVAILABLE callback for every single message. Possibly only safe if VCHI_COARSE_LOCKING.
  34322. +#define VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
  34323. +
  34324. +// Don't use message descriptors for TX messages that don't need them
  34325. +#define VCHI_MINIMISE_TX_MSG_DESCRIPTORS
  34326. +
  34327. +// Nano-locks for multiqueue
  34328. +//#define VCHI_MQUEUE_NANOLOCKS
  34329. +
  34330. +// Lock-free(er) dequeuing
  34331. +//#define VCHI_RX_NANOLOCKS
  34332. +
  34333. +#endif /*VCHI_CFG_INTERNAL_H_*/
  34334. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchi/vchi_common.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_common.h
  34335. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchi/vchi_common.h 1970-01-01 01:00:00.000000000 +0100
  34336. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_common.h 2015-02-09 04:40:07.000000000 +0100
  34337. @@ -0,0 +1,174 @@
  34338. +/**
  34339. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  34340. + *
  34341. + * Redistribution and use in source and binary forms, with or without
  34342. + * modification, are permitted provided that the following conditions
  34343. + * are met:
  34344. + * 1. Redistributions of source code must retain the above copyright
  34345. + * notice, this list of conditions, and the following disclaimer,
  34346. + * without modification.
  34347. + * 2. Redistributions in binary form must reproduce the above copyright
  34348. + * notice, this list of conditions and the following disclaimer in the
  34349. + * documentation and/or other materials provided with the distribution.
  34350. + * 3. The names of the above-listed copyright holders may not be used
  34351. + * to endorse or promote products derived from this software without
  34352. + * specific prior written permission.
  34353. + *
  34354. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34355. + * GNU General Public License ("GPL") version 2, as published by the Free
  34356. + * Software Foundation.
  34357. + *
  34358. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34359. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34360. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34361. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34362. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34363. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34364. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34365. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34366. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34367. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34368. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34369. + */
  34370. +
  34371. +#ifndef VCHI_COMMON_H_
  34372. +#define VCHI_COMMON_H_
  34373. +
  34374. +
  34375. +//flags used when sending messages (must be bitmapped)
  34376. +typedef enum
  34377. +{
  34378. + VCHI_FLAGS_NONE = 0x0,
  34379. + 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)
  34380. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent
  34381. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED = 0x4, // return once the transfer is in a queue ready to go
  34382. + VCHI_FLAGS_ALLOW_PARTIAL = 0x8,
  34383. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ = 0x10,
  34384. + VCHI_FLAGS_CALLBACK_WHEN_DATA_READ = 0x20,
  34385. +
  34386. + VCHI_FLAGS_ALIGN_SLOT = 0x000080, // internal use only
  34387. + VCHI_FLAGS_BULK_AUX_QUEUED = 0x010000, // internal use only
  34388. + VCHI_FLAGS_BULK_AUX_COMPLETE = 0x020000, // internal use only
  34389. + VCHI_FLAGS_BULK_DATA_QUEUED = 0x040000, // internal use only
  34390. + VCHI_FLAGS_BULK_DATA_COMPLETE = 0x080000, // internal use only
  34391. + VCHI_FLAGS_INTERNAL = 0xFF0000
  34392. +} VCHI_FLAGS_T;
  34393. +
  34394. +// constants for vchi_crc_control()
  34395. +typedef enum {
  34396. + VCHI_CRC_NOTHING = -1,
  34397. + VCHI_CRC_PER_SERVICE = 0,
  34398. + VCHI_CRC_EVERYTHING = 1,
  34399. +} VCHI_CRC_CONTROL_T;
  34400. +
  34401. +//callback reasons when an event occurs on a service
  34402. +typedef enum
  34403. +{
  34404. + VCHI_CALLBACK_REASON_MIN,
  34405. +
  34406. + //This indicates that there is data available
  34407. + //handle is the msg id that was transmitted with the data
  34408. + // When a message is received and there was no FULL message available previously, send callback
  34409. + // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails
  34410. + VCHI_CALLBACK_MSG_AVAILABLE,
  34411. + VCHI_CALLBACK_MSG_SENT,
  34412. + VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented
  34413. +
  34414. + // This indicates that a transfer from the other side has completed
  34415. + VCHI_CALLBACK_BULK_RECEIVED,
  34416. + //This indicates that data queued up to be sent has now gone
  34417. + //handle is the msg id that was used when sending the data
  34418. + VCHI_CALLBACK_BULK_SENT,
  34419. + VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented
  34420. + VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented
  34421. +
  34422. + VCHI_CALLBACK_SERVICE_CLOSED,
  34423. +
  34424. + // this side has sent XOFF to peer due to lack of data consumption by service
  34425. + // (suggests the service may need to take some recovery action if it has
  34426. + // been deliberately holding off consuming data)
  34427. + VCHI_CALLBACK_SENT_XOFF,
  34428. + VCHI_CALLBACK_SENT_XON,
  34429. +
  34430. + // indicates that a bulk transfer has finished reading the source buffer
  34431. + VCHI_CALLBACK_BULK_DATA_READ,
  34432. +
  34433. + // power notification events (currently host side only)
  34434. + VCHI_CALLBACK_PEER_OFF,
  34435. + VCHI_CALLBACK_PEER_SUSPENDED,
  34436. + VCHI_CALLBACK_PEER_ON,
  34437. + VCHI_CALLBACK_PEER_RESUMED,
  34438. + VCHI_CALLBACK_FORCED_POWER_OFF,
  34439. +
  34440. +#ifdef USE_VCHIQ_ARM
  34441. + // some extra notifications provided by vchiq_arm
  34442. + VCHI_CALLBACK_SERVICE_OPENED,
  34443. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  34444. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  34445. +#endif
  34446. +
  34447. + VCHI_CALLBACK_REASON_MAX
  34448. +} VCHI_CALLBACK_REASON_T;
  34449. +
  34450. +// service control options
  34451. +typedef enum
  34452. +{
  34453. + VCHI_SERVICE_OPTION_MIN,
  34454. +
  34455. + VCHI_SERVICE_OPTION_TRACE,
  34456. +
  34457. + VCHI_SERVICE_OPTION_MAX
  34458. +} VCHI_SERVICE_OPTION_T;
  34459. +
  34460. +
  34461. +//Callback used by all services / bulk transfers
  34462. +typedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param
  34463. + VCHI_CALLBACK_REASON_T reason,
  34464. + void *handle ); //for transmitting msg's only
  34465. +
  34466. +
  34467. +
  34468. +/*
  34469. + * Define vector struct for scatter-gather (vector) operations
  34470. + * Vectors can be nested - if a vector element has negative length, then
  34471. + * the data pointer is treated as pointing to another vector array, with
  34472. + * '-vec_len' elements. Thus to append a header onto an existing vector,
  34473. + * you can do this:
  34474. + *
  34475. + * void foo(const VCHI_MSG_VECTOR_T *v, int n)
  34476. + * {
  34477. + * VCHI_MSG_VECTOR_T nv[2];
  34478. + * nv[0].vec_base = my_header;
  34479. + * nv[0].vec_len = sizeof my_header;
  34480. + * nv[1].vec_base = v;
  34481. + * nv[1].vec_len = -n;
  34482. + * ...
  34483. + *
  34484. + */
  34485. +typedef struct vchi_msg_vector {
  34486. + const void *vec_base;
  34487. + int32_t vec_len;
  34488. +} VCHI_MSG_VECTOR_T;
  34489. +
  34490. +// Opaque type for a connection API
  34491. +typedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T;
  34492. +
  34493. +// Opaque type for a message driver
  34494. +typedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T;
  34495. +
  34496. +
  34497. +// Iterator structure for reading ahead through received message queue. Allocated by client,
  34498. +// initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only.
  34499. +// Iterates over messages in queue at the instant of the call to vchi_msg_lookahead -
  34500. +// will not proceed to messages received since. Behaviour is undefined if an iterator
  34501. +// is used again after messages for that service are removed/dequeued by any
  34502. +// means other than vchi_msg_iter_... calls on the iterator itself.
  34503. +typedef struct {
  34504. + struct opaque_vchi_service_t *service;
  34505. + void *last;
  34506. + void *next;
  34507. + void *remove;
  34508. +} VCHI_MSG_ITER_T;
  34509. +
  34510. +
  34511. +#endif // VCHI_COMMON_H_
  34512. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchi/vchi.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi.h
  34513. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchi/vchi.h 1970-01-01 01:00:00.000000000 +0100
  34514. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi.h 2015-02-09 04:40:07.000000000 +0100
  34515. @@ -0,0 +1,378 @@
  34516. +/**
  34517. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  34518. + *
  34519. + * Redistribution and use in source and binary forms, with or without
  34520. + * modification, are permitted provided that the following conditions
  34521. + * are met:
  34522. + * 1. Redistributions of source code must retain the above copyright
  34523. + * notice, this list of conditions, and the following disclaimer,
  34524. + * without modification.
  34525. + * 2. Redistributions in binary form must reproduce the above copyright
  34526. + * notice, this list of conditions and the following disclaimer in the
  34527. + * documentation and/or other materials provided with the distribution.
  34528. + * 3. The names of the above-listed copyright holders may not be used
  34529. + * to endorse or promote products derived from this software without
  34530. + * specific prior written permission.
  34531. + *
  34532. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34533. + * GNU General Public License ("GPL") version 2, as published by the Free
  34534. + * Software Foundation.
  34535. + *
  34536. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34537. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34538. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34539. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34540. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34541. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34542. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34543. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34544. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34545. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34546. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34547. + */
  34548. +
  34549. +#ifndef VCHI_H_
  34550. +#define VCHI_H_
  34551. +
  34552. +#include "interface/vchi/vchi_cfg.h"
  34553. +#include "interface/vchi/vchi_common.h"
  34554. +#include "interface/vchi/connections/connection.h"
  34555. +#include "vchi_mh.h"
  34556. +
  34557. +
  34558. +/******************************************************************************
  34559. + Global defs
  34560. + *****************************************************************************/
  34561. +
  34562. +#define VCHI_BULK_ROUND_UP(x) ((((unsigned long)(x))+VCHI_BULK_ALIGN-1) & ~(VCHI_BULK_ALIGN-1))
  34563. +#define VCHI_BULK_ROUND_DOWN(x) (((unsigned long)(x)) & ~(VCHI_BULK_ALIGN-1))
  34564. +#define VCHI_BULK_ALIGN_NBYTES(x) (VCHI_BULK_ALIGNED(x) ? 0 : (VCHI_BULK_ALIGN - ((unsigned long)(x) & (VCHI_BULK_ALIGN-1))))
  34565. +
  34566. +#ifdef USE_VCHIQ_ARM
  34567. +#define VCHI_BULK_ALIGNED(x) 1
  34568. +#else
  34569. +#define VCHI_BULK_ALIGNED(x) (((unsigned long)(x) & (VCHI_BULK_ALIGN-1)) == 0)
  34570. +#endif
  34571. +
  34572. +struct vchi_version {
  34573. + uint32_t version;
  34574. + uint32_t version_min;
  34575. +};
  34576. +#define VCHI_VERSION(v_) { v_, v_ }
  34577. +#define VCHI_VERSION_EX(v_, m_) { v_, m_ }
  34578. +
  34579. +typedef enum
  34580. +{
  34581. + VCHI_VEC_POINTER,
  34582. + VCHI_VEC_HANDLE,
  34583. + VCHI_VEC_LIST
  34584. +} VCHI_MSG_VECTOR_TYPE_T;
  34585. +
  34586. +typedef struct vchi_msg_vector_ex {
  34587. +
  34588. + VCHI_MSG_VECTOR_TYPE_T type;
  34589. + union
  34590. + {
  34591. + // a memory handle
  34592. + struct
  34593. + {
  34594. + VCHI_MEM_HANDLE_T handle;
  34595. + uint32_t offset;
  34596. + int32_t vec_len;
  34597. + } handle;
  34598. +
  34599. + // an ordinary data pointer
  34600. + struct
  34601. + {
  34602. + const void *vec_base;
  34603. + int32_t vec_len;
  34604. + } ptr;
  34605. +
  34606. + // a nested vector list
  34607. + struct
  34608. + {
  34609. + struct vchi_msg_vector_ex *vec;
  34610. + uint32_t vec_len;
  34611. + } list;
  34612. + } u;
  34613. +} VCHI_MSG_VECTOR_EX_T;
  34614. +
  34615. +
  34616. +// Construct an entry in a msg vector for a pointer (p) of length (l)
  34617. +#define VCHI_VEC_POINTER(p,l) VCHI_VEC_POINTER, { { (VCHI_MEM_HANDLE_T)(p), (l) } }
  34618. +
  34619. +// Construct an entry in a msg vector for a message handle (h), starting at offset (o) of length (l)
  34620. +#define VCHI_VEC_HANDLE(h,o,l) VCHI_VEC_HANDLE, { { (h), (o), (l) } }
  34621. +
  34622. +// Macros to manipulate 'FOURCC' values
  34623. +#define MAKE_FOURCC(x) ((int32_t)( (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3] ))
  34624. +#define FOURCC_TO_CHAR(x) (x >> 24) & 0xFF,(x >> 16) & 0xFF,(x >> 8) & 0xFF, x & 0xFF
  34625. +
  34626. +
  34627. +// Opaque service information
  34628. +struct opaque_vchi_service_t;
  34629. +
  34630. +// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,
  34631. +// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.
  34632. +typedef struct
  34633. +{
  34634. + struct opaque_vchi_service_t *service;
  34635. + void *message;
  34636. +} VCHI_HELD_MSG_T;
  34637. +
  34638. +
  34639. +
  34640. +// structure used to provide the information needed to open a server or a client
  34641. +typedef struct {
  34642. + struct vchi_version version;
  34643. + int32_t service_id;
  34644. + VCHI_CONNECTION_T *connection;
  34645. + uint32_t rx_fifo_size;
  34646. + uint32_t tx_fifo_size;
  34647. + VCHI_CALLBACK_T callback;
  34648. + void *callback_param;
  34649. + /* client intends to receive bulk transfers of
  34650. + odd lengths or into unaligned buffers */
  34651. + int32_t want_unaligned_bulk_rx;
  34652. + /* client intends to transmit bulk transfers of
  34653. + odd lengths or out of unaligned buffers */
  34654. + int32_t want_unaligned_bulk_tx;
  34655. + /* client wants to check CRCs on (bulk) xfers.
  34656. + Only needs to be set at 1 end - will do both directions. */
  34657. + int32_t want_crc;
  34658. +} SERVICE_CREATION_T;
  34659. +
  34660. +// Opaque handle for a VCHI instance
  34661. +typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;
  34662. +
  34663. +// Opaque handle for a server or client
  34664. +typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;
  34665. +
  34666. +// Service registration & startup
  34667. +typedef void (*VCHI_SERVICE_INIT)(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections);
  34668. +
  34669. +typedef struct service_info_tag {
  34670. + const char * const vll_filename; /* VLL to load to start this service. This is an empty string if VLL is "static" */
  34671. + VCHI_SERVICE_INIT init; /* Service initialisation function */
  34672. + void *vll_handle; /* VLL handle; NULL when unloaded or a "static VLL" in build */
  34673. +} SERVICE_INFO_T;
  34674. +
  34675. +/******************************************************************************
  34676. + Global funcs - implementation is specific to which side you are on (local / remote)
  34677. + *****************************************************************************/
  34678. +
  34679. +#ifdef __cplusplus
  34680. +extern "C" {
  34681. +#endif
  34682. +
  34683. +extern /*@observer@*/ VCHI_CONNECTION_T * vchi_create_connection( const VCHI_CONNECTION_API_T * function_table,
  34684. + const VCHI_MESSAGE_DRIVER_T * low_level);
  34685. +
  34686. +
  34687. +// Routine used to initialise the vchi on both local + remote connections
  34688. +extern int32_t vchi_initialise( VCHI_INSTANCE_T *instance_handle );
  34689. +
  34690. +extern int32_t vchi_exit( void );
  34691. +
  34692. +extern int32_t vchi_connect( VCHI_CONNECTION_T **connections,
  34693. + const uint32_t num_connections,
  34694. + VCHI_INSTANCE_T instance_handle );
  34695. +
  34696. +//When this is called, ensure that all services have no data pending.
  34697. +//Bulk transfers can remain 'queued'
  34698. +extern int32_t vchi_disconnect( VCHI_INSTANCE_T instance_handle );
  34699. +
  34700. +// Global control over bulk CRC checking
  34701. +extern int32_t vchi_crc_control( VCHI_CONNECTION_T *connection,
  34702. + VCHI_CRC_CONTROL_T control );
  34703. +
  34704. +// helper functions
  34705. +extern void * vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);
  34706. +extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);
  34707. +extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
  34708. +
  34709. +
  34710. +/******************************************************************************
  34711. + Global service API
  34712. + *****************************************************************************/
  34713. +// Routine to create a named service
  34714. +extern int32_t vchi_service_create( VCHI_INSTANCE_T instance_handle,
  34715. + SERVICE_CREATION_T *setup,
  34716. + VCHI_SERVICE_HANDLE_T *handle );
  34717. +
  34718. +// Routine to destory a service
  34719. +extern int32_t vchi_service_destroy( const VCHI_SERVICE_HANDLE_T handle );
  34720. +
  34721. +// Routine to open a named service
  34722. +extern int32_t vchi_service_open( VCHI_INSTANCE_T instance_handle,
  34723. + SERVICE_CREATION_T *setup,
  34724. + VCHI_SERVICE_HANDLE_T *handle);
  34725. +
  34726. +extern int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle,
  34727. + short *peer_version );
  34728. +
  34729. +// Routine to close a named service
  34730. +extern int32_t vchi_service_close( const VCHI_SERVICE_HANDLE_T handle );
  34731. +
  34732. +// Routine to increment ref count on a named service
  34733. +extern int32_t vchi_service_use( const VCHI_SERVICE_HANDLE_T handle );
  34734. +
  34735. +// Routine to decrement ref count on a named service
  34736. +extern int32_t vchi_service_release( const VCHI_SERVICE_HANDLE_T handle );
  34737. +
  34738. +// Routine to set a control option for a named service
  34739. +extern int32_t vchi_service_set_option( const VCHI_SERVICE_HANDLE_T handle,
  34740. + VCHI_SERVICE_OPTION_T option,
  34741. + int value);
  34742. +
  34743. +// Routine to send a message across a service
  34744. +extern int32_t vchi_msg_queue( VCHI_SERVICE_HANDLE_T handle,
  34745. + const void *data,
  34746. + uint32_t data_size,
  34747. + VCHI_FLAGS_T flags,
  34748. + void *msg_handle );
  34749. +
  34750. +// scatter-gather (vector) and send message
  34751. +int32_t vchi_msg_queuev_ex( VCHI_SERVICE_HANDLE_T handle,
  34752. + VCHI_MSG_VECTOR_EX_T *vector,
  34753. + uint32_t count,
  34754. + VCHI_FLAGS_T flags,
  34755. + void *msg_handle );
  34756. +
  34757. +// legacy scatter-gather (vector) and send message, only handles pointers
  34758. +int32_t vchi_msg_queuev( VCHI_SERVICE_HANDLE_T handle,
  34759. + VCHI_MSG_VECTOR_T *vector,
  34760. + uint32_t count,
  34761. + VCHI_FLAGS_T flags,
  34762. + void *msg_handle );
  34763. +
  34764. +// Routine to receive a msg from a service
  34765. +// Dequeue is equivalent to hold, copy into client buffer, release
  34766. +extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle,
  34767. + void *data,
  34768. + uint32_t max_data_size_to_read,
  34769. + uint32_t *actual_msg_size,
  34770. + VCHI_FLAGS_T flags );
  34771. +
  34772. +// Routine to look at a message in place.
  34773. +// The message is not dequeued, so a subsequent call to peek or dequeue
  34774. +// will return the same message.
  34775. +extern int32_t vchi_msg_peek( VCHI_SERVICE_HANDLE_T handle,
  34776. + void **data,
  34777. + uint32_t *msg_size,
  34778. + VCHI_FLAGS_T flags );
  34779. +
  34780. +// Routine to remove a message after it has been read in place with peek
  34781. +// The first message on the queue is dequeued.
  34782. +extern int32_t vchi_msg_remove( VCHI_SERVICE_HANDLE_T handle );
  34783. +
  34784. +// Routine to look at a message in place.
  34785. +// The message is dequeued, so the caller is left holding it; the descriptor is
  34786. +// filled in and must be released when the user has finished with the message.
  34787. +extern int32_t vchi_msg_hold( VCHI_SERVICE_HANDLE_T handle,
  34788. + void **data, // } may be NULL, as info can be
  34789. + uint32_t *msg_size, // } obtained from HELD_MSG_T
  34790. + VCHI_FLAGS_T flags,
  34791. + VCHI_HELD_MSG_T *message_descriptor );
  34792. +
  34793. +// Initialise an iterator to look through messages in place
  34794. +extern int32_t vchi_msg_look_ahead( VCHI_SERVICE_HANDLE_T handle,
  34795. + VCHI_MSG_ITER_T *iter,
  34796. + VCHI_FLAGS_T flags );
  34797. +
  34798. +/******************************************************************************
  34799. + Global service support API - operations on held messages and message iterators
  34800. + *****************************************************************************/
  34801. +
  34802. +// Routine to get the address of a held message
  34803. +extern void *vchi_held_msg_ptr( const VCHI_HELD_MSG_T *message );
  34804. +
  34805. +// Routine to get the size of a held message
  34806. +extern int32_t vchi_held_msg_size( const VCHI_HELD_MSG_T *message );
  34807. +
  34808. +// Routine to get the transmit timestamp as written into the header by the peer
  34809. +extern uint32_t vchi_held_msg_tx_timestamp( const VCHI_HELD_MSG_T *message );
  34810. +
  34811. +// Routine to get the reception timestamp, written as we parsed the header
  34812. +extern uint32_t vchi_held_msg_rx_timestamp( const VCHI_HELD_MSG_T *message );
  34813. +
  34814. +// Routine to release a held message after it has been processed
  34815. +extern int32_t vchi_held_msg_release( VCHI_HELD_MSG_T *message );
  34816. +
  34817. +// Indicates whether the iterator has a next message.
  34818. +extern int32_t vchi_msg_iter_has_next( const VCHI_MSG_ITER_T *iter );
  34819. +
  34820. +// Return the pointer and length for the next message and advance the iterator.
  34821. +extern int32_t vchi_msg_iter_next( VCHI_MSG_ITER_T *iter,
  34822. + void **data,
  34823. + uint32_t *msg_size );
  34824. +
  34825. +// Remove the last message returned by vchi_msg_iter_next.
  34826. +// Can only be called once after each call to vchi_msg_iter_next.
  34827. +extern int32_t vchi_msg_iter_remove( VCHI_MSG_ITER_T *iter );
  34828. +
  34829. +// Hold the last message returned by vchi_msg_iter_next.
  34830. +// Can only be called once after each call to vchi_msg_iter_next.
  34831. +extern int32_t vchi_msg_iter_hold( VCHI_MSG_ITER_T *iter,
  34832. + VCHI_HELD_MSG_T *message );
  34833. +
  34834. +// Return information for the next message, and hold it, advancing the iterator.
  34835. +extern int32_t vchi_msg_iter_hold_next( VCHI_MSG_ITER_T *iter,
  34836. + void **data, // } may be NULL
  34837. + uint32_t *msg_size, // }
  34838. + VCHI_HELD_MSG_T *message );
  34839. +
  34840. +
  34841. +/******************************************************************************
  34842. + Global bulk API
  34843. + *****************************************************************************/
  34844. +
  34845. +// Routine to prepare interface for a transfer from the other side
  34846. +extern int32_t vchi_bulk_queue_receive( VCHI_SERVICE_HANDLE_T handle,
  34847. + void *data_dst,
  34848. + uint32_t data_size,
  34849. + VCHI_FLAGS_T flags,
  34850. + void *transfer_handle );
  34851. +
  34852. +
  34853. +// Prepare interface for a transfer from the other side into relocatable memory.
  34854. +int32_t vchi_bulk_queue_receive_reloc( const VCHI_SERVICE_HANDLE_T handle,
  34855. + VCHI_MEM_HANDLE_T h_dst,
  34856. + uint32_t offset,
  34857. + uint32_t data_size,
  34858. + const VCHI_FLAGS_T flags,
  34859. + void * const bulk_handle );
  34860. +
  34861. +// Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
  34862. +extern int32_t vchi_bulk_queue_transmit( VCHI_SERVICE_HANDLE_T handle,
  34863. + const void *data_src,
  34864. + uint32_t data_size,
  34865. + VCHI_FLAGS_T flags,
  34866. + void *transfer_handle );
  34867. +
  34868. +
  34869. +/******************************************************************************
  34870. + Configuration plumbing
  34871. + *****************************************************************************/
  34872. +
  34873. +// function prototypes for the different mid layers (the state info gives the different physical connections)
  34874. +extern const VCHI_CONNECTION_API_T *single_get_func_table( void );
  34875. +//extern const VCHI_CONNECTION_API_T *local_server_get_func_table( void );
  34876. +//extern const VCHI_CONNECTION_API_T *local_client_get_func_table( void );
  34877. +
  34878. +// declare all message drivers here
  34879. +const VCHI_MESSAGE_DRIVER_T *vchi_mphi_message_driver_func_table( void );
  34880. +
  34881. +#ifdef __cplusplus
  34882. +}
  34883. +#endif
  34884. +
  34885. +extern int32_t vchi_bulk_queue_transmit_reloc( VCHI_SERVICE_HANDLE_T handle,
  34886. + VCHI_MEM_HANDLE_T h_src,
  34887. + uint32_t offset,
  34888. + uint32_t data_size,
  34889. + VCHI_FLAGS_T flags,
  34890. + void *transfer_handle );
  34891. +#endif /* VCHI_H_ */
  34892. +
  34893. +/****************************** End of file **********************************/
  34894. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchi/vchi_mh.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h
  34895. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 1970-01-01 01:00:00.000000000 +0100
  34896. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 2015-02-09 04:40:07.000000000 +0100
  34897. @@ -0,0 +1,42 @@
  34898. +/**
  34899. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  34900. + *
  34901. + * Redistribution and use in source and binary forms, with or without
  34902. + * modification, are permitted provided that the following conditions
  34903. + * are met:
  34904. + * 1. Redistributions of source code must retain the above copyright
  34905. + * notice, this list of conditions, and the following disclaimer,
  34906. + * without modification.
  34907. + * 2. Redistributions in binary form must reproduce the above copyright
  34908. + * notice, this list of conditions and the following disclaimer in the
  34909. + * documentation and/or other materials provided with the distribution.
  34910. + * 3. The names of the above-listed copyright holders may not be used
  34911. + * to endorse or promote products derived from this software without
  34912. + * specific prior written permission.
  34913. + *
  34914. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34915. + * GNU General Public License ("GPL") version 2, as published by the Free
  34916. + * Software Foundation.
  34917. + *
  34918. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34919. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34920. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34921. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34922. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34923. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34924. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34925. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34926. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34927. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34928. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34929. + */
  34930. +
  34931. +#ifndef VCHI_MH_H_
  34932. +#define VCHI_MH_H_
  34933. +
  34934. +#include <linux/types.h>
  34935. +
  34936. +typedef int32_t VCHI_MEM_HANDLE_T;
  34937. +#define VCHI_MEM_HANDLE_INVALID 0
  34938. +
  34939. +#endif
  34940. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
  34941. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 1970-01-01 01:00:00.000000000 +0100
  34942. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 2015-02-09 04:40:07.000000000 +0100
  34943. @@ -0,0 +1,562 @@
  34944. +/**
  34945. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  34946. + *
  34947. + * Redistribution and use in source and binary forms, with or without
  34948. + * modification, are permitted provided that the following conditions
  34949. + * are met:
  34950. + * 1. Redistributions of source code must retain the above copyright
  34951. + * notice, this list of conditions, and the following disclaimer,
  34952. + * without modification.
  34953. + * 2. Redistributions in binary form must reproduce the above copyright
  34954. + * notice, this list of conditions and the following disclaimer in the
  34955. + * documentation and/or other materials provided with the distribution.
  34956. + * 3. The names of the above-listed copyright holders may not be used
  34957. + * to endorse or promote products derived from this software without
  34958. + * specific prior written permission.
  34959. + *
  34960. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34961. + * GNU General Public License ("GPL") version 2, as published by the Free
  34962. + * Software Foundation.
  34963. + *
  34964. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34965. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34966. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34967. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34968. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34969. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34970. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34971. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34972. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34973. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34974. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34975. + */
  34976. +
  34977. +#include <linux/kernel.h>
  34978. +#include <linux/types.h>
  34979. +#include <linux/errno.h>
  34980. +#include <linux/interrupt.h>
  34981. +#include <linux/irq.h>
  34982. +#include <linux/pagemap.h>
  34983. +#include <linux/dma-mapping.h>
  34984. +#include <linux/version.h>
  34985. +#include <linux/io.h>
  34986. +#include <linux/uaccess.h>
  34987. +#include <asm/pgtable.h>
  34988. +
  34989. +#include <mach/irqs.h>
  34990. +
  34991. +#include <mach/platform.h>
  34992. +#include <mach/vcio.h>
  34993. +
  34994. +#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
  34995. +
  34996. +#define VCHIQ_DOORBELL_IRQ IRQ_ARM_DOORBELL_0
  34997. +#define VCHIQ_ARM_ADDRESS(x) ((void *)__virt_to_bus((unsigned)x))
  34998. +
  34999. +#include "vchiq_arm.h"
  35000. +#include "vchiq_2835.h"
  35001. +#include "vchiq_connected.h"
  35002. +#include "vchiq_killable.h"
  35003. +
  35004. +#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
  35005. +
  35006. +typedef struct vchiq_2835_state_struct {
  35007. + int inited;
  35008. + VCHIQ_ARM_STATE_T arm_state;
  35009. +} VCHIQ_2835_ARM_STATE_T;
  35010. +
  35011. +static char *g_slot_mem;
  35012. +static int g_slot_mem_size;
  35013. +dma_addr_t g_slot_phys;
  35014. +static FRAGMENTS_T *g_fragments_base;
  35015. +static FRAGMENTS_T *g_free_fragments;
  35016. +struct semaphore g_free_fragments_sema;
  35017. +
  35018. +extern int vchiq_arm_log_level;
  35019. +
  35020. +static DEFINE_SEMAPHORE(g_free_fragments_mutex);
  35021. +
  35022. +static irqreturn_t
  35023. +vchiq_doorbell_irq(int irq, void *dev_id);
  35024. +
  35025. +static int
  35026. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  35027. + struct task_struct *task, PAGELIST_T ** ppagelist);
  35028. +
  35029. +static void
  35030. +free_pagelist(PAGELIST_T *pagelist, int actual);
  35031. +
  35032. +int __init
  35033. +vchiq_platform_init(VCHIQ_STATE_T *state)
  35034. +{
  35035. + VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
  35036. + int frag_mem_size;
  35037. + int err;
  35038. + int i;
  35039. +
  35040. + /* Allocate space for the channels in coherent memory */
  35041. + g_slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
  35042. + frag_mem_size = PAGE_ALIGN(sizeof(FRAGMENTS_T) * MAX_FRAGMENTS);
  35043. +
  35044. + g_slot_mem = dma_alloc_coherent(NULL, g_slot_mem_size + frag_mem_size,
  35045. + &g_slot_phys, GFP_ATOMIC);
  35046. +
  35047. + if (!g_slot_mem) {
  35048. + vchiq_log_error(vchiq_arm_log_level,
  35049. + "Unable to allocate channel memory");
  35050. + err = -ENOMEM;
  35051. + goto failed_alloc;
  35052. + }
  35053. +
  35054. + WARN_ON(((int)g_slot_mem & (PAGE_SIZE - 1)) != 0);
  35055. +
  35056. + vchiq_slot_zero = vchiq_init_slots(g_slot_mem, g_slot_mem_size);
  35057. + if (!vchiq_slot_zero) {
  35058. + err = -EINVAL;
  35059. + goto failed_init_slots;
  35060. + }
  35061. +
  35062. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] =
  35063. + (int)g_slot_phys + g_slot_mem_size;
  35064. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] =
  35065. + MAX_FRAGMENTS;
  35066. +
  35067. + g_fragments_base = (FRAGMENTS_T *)(g_slot_mem + g_slot_mem_size);
  35068. + g_slot_mem_size += frag_mem_size;
  35069. +
  35070. + g_free_fragments = g_fragments_base;
  35071. + for (i = 0; i < (MAX_FRAGMENTS - 1); i++) {
  35072. + *(FRAGMENTS_T **)&g_fragments_base[i] =
  35073. + &g_fragments_base[i + 1];
  35074. + }
  35075. + *(FRAGMENTS_T **)&g_fragments_base[i] = NULL;
  35076. + sema_init(&g_free_fragments_sema, MAX_FRAGMENTS);
  35077. +
  35078. + if (vchiq_init_state(state, vchiq_slot_zero, 0/*slave*/) !=
  35079. + VCHIQ_SUCCESS) {
  35080. + err = -EINVAL;
  35081. + goto failed_vchiq_init;
  35082. + }
  35083. +
  35084. + err = request_irq(VCHIQ_DOORBELL_IRQ, vchiq_doorbell_irq,
  35085. + IRQF_IRQPOLL, "VCHIQ doorbell",
  35086. + state);
  35087. + if (err < 0) {
  35088. + vchiq_log_error(vchiq_arm_log_level, "%s: failed to register "
  35089. + "irq=%d err=%d", __func__,
  35090. + VCHIQ_DOORBELL_IRQ, err);
  35091. + goto failed_request_irq;
  35092. + }
  35093. +
  35094. + /* Send the base address of the slots to VideoCore */
  35095. +
  35096. + dsb(); /* Ensure all writes have completed */
  35097. +
  35098. + bcm_mailbox_write(MBOX_CHAN_VCHIQ, (unsigned int)g_slot_phys);
  35099. +
  35100. + vchiq_log_info(vchiq_arm_log_level,
  35101. + "vchiq_init - done (slots %x, phys %x)",
  35102. + (unsigned int)vchiq_slot_zero, g_slot_phys);
  35103. +
  35104. + vchiq_call_connected_callbacks();
  35105. +
  35106. + return 0;
  35107. +
  35108. +failed_request_irq:
  35109. +failed_vchiq_init:
  35110. +failed_init_slots:
  35111. + dma_free_coherent(NULL, g_slot_mem_size, g_slot_mem, g_slot_phys);
  35112. +
  35113. +failed_alloc:
  35114. + return err;
  35115. +}
  35116. +
  35117. +void __exit
  35118. +vchiq_platform_exit(VCHIQ_STATE_T *state)
  35119. +{
  35120. + free_irq(VCHIQ_DOORBELL_IRQ, state);
  35121. + dma_free_coherent(NULL, g_slot_mem_size,
  35122. + g_slot_mem, g_slot_phys);
  35123. +}
  35124. +
  35125. +
  35126. +VCHIQ_STATUS_T
  35127. +vchiq_platform_init_state(VCHIQ_STATE_T *state)
  35128. +{
  35129. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  35130. + state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL);
  35131. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 1;
  35132. + status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state);
  35133. + if(status != VCHIQ_SUCCESS)
  35134. + {
  35135. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 0;
  35136. + }
  35137. + return status;
  35138. +}
  35139. +
  35140. +VCHIQ_ARM_STATE_T*
  35141. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
  35142. +{
  35143. + if(!((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited)
  35144. + {
  35145. + BUG();
  35146. + }
  35147. + return &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state;
  35148. +}
  35149. +
  35150. +void
  35151. +remote_event_signal(REMOTE_EVENT_T *event)
  35152. +{
  35153. + wmb();
  35154. +
  35155. + event->fired = 1;
  35156. +
  35157. + dsb(); /* data barrier operation */
  35158. +
  35159. + if (event->armed) {
  35160. + /* trigger vc interrupt */
  35161. +
  35162. + writel(0, __io_address(ARM_0_BELL2));
  35163. + }
  35164. +}
  35165. +
  35166. +int
  35167. +vchiq_copy_from_user(void *dst, const void *src, int size)
  35168. +{
  35169. + if ((uint32_t)src < TASK_SIZE) {
  35170. + return copy_from_user(dst, src, size);
  35171. + } else {
  35172. + memcpy(dst, src, size);
  35173. + return 0;
  35174. + }
  35175. +}
  35176. +
  35177. +VCHIQ_STATUS_T
  35178. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk, VCHI_MEM_HANDLE_T memhandle,
  35179. + void *offset, int size, int dir)
  35180. +{
  35181. + PAGELIST_T *pagelist;
  35182. + int ret;
  35183. +
  35184. + WARN_ON(memhandle != VCHI_MEM_HANDLE_INVALID);
  35185. +
  35186. + ret = create_pagelist((char __user *)offset, size,
  35187. + (dir == VCHIQ_BULK_RECEIVE)
  35188. + ? PAGELIST_READ
  35189. + : PAGELIST_WRITE,
  35190. + current,
  35191. + &pagelist);
  35192. + if (ret != 0)
  35193. + return VCHIQ_ERROR;
  35194. +
  35195. + bulk->handle = memhandle;
  35196. + bulk->data = VCHIQ_ARM_ADDRESS(pagelist);
  35197. +
  35198. + /* Store the pagelist address in remote_data, which isn't used by the
  35199. + slave. */
  35200. + bulk->remote_data = pagelist;
  35201. +
  35202. + return VCHIQ_SUCCESS;
  35203. +}
  35204. +
  35205. +void
  35206. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk)
  35207. +{
  35208. + if (bulk && bulk->remote_data && bulk->actual)
  35209. + free_pagelist((PAGELIST_T *)bulk->remote_data, bulk->actual);
  35210. +}
  35211. +
  35212. +void
  35213. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk)
  35214. +{
  35215. + /*
  35216. + * This should only be called on the master (VideoCore) side, but
  35217. + * provide an implementation to avoid the need for ifdefery.
  35218. + */
  35219. + BUG();
  35220. +}
  35221. +
  35222. +void
  35223. +vchiq_dump_platform_state(void *dump_context)
  35224. +{
  35225. + char buf[80];
  35226. + int len;
  35227. + len = snprintf(buf, sizeof(buf),
  35228. + " Platform: 2835 (VC master)");
  35229. + vchiq_dump(dump_context, buf, len + 1);
  35230. +}
  35231. +
  35232. +VCHIQ_STATUS_T
  35233. +vchiq_platform_suspend(VCHIQ_STATE_T *state)
  35234. +{
  35235. + return VCHIQ_ERROR;
  35236. +}
  35237. +
  35238. +VCHIQ_STATUS_T
  35239. +vchiq_platform_resume(VCHIQ_STATE_T *state)
  35240. +{
  35241. + return VCHIQ_SUCCESS;
  35242. +}
  35243. +
  35244. +void
  35245. +vchiq_platform_paused(VCHIQ_STATE_T *state)
  35246. +{
  35247. +}
  35248. +
  35249. +void
  35250. +vchiq_platform_resumed(VCHIQ_STATE_T *state)
  35251. +{
  35252. +}
  35253. +
  35254. +int
  35255. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T* state)
  35256. +{
  35257. + return 1; // autosuspend not supported - videocore always wanted
  35258. +}
  35259. +
  35260. +int
  35261. +vchiq_platform_use_suspend_timer(void)
  35262. +{
  35263. + return 0;
  35264. +}
  35265. +void
  35266. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state)
  35267. +{
  35268. + vchiq_log_info((vchiq_arm_log_level>=VCHIQ_LOG_INFO),"Suspend timer not in use");
  35269. +}
  35270. +void
  35271. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state)
  35272. +{
  35273. + (void)state;
  35274. +}
  35275. +/*
  35276. + * Local functions
  35277. + */
  35278. +
  35279. +static irqreturn_t
  35280. +vchiq_doorbell_irq(int irq, void *dev_id)
  35281. +{
  35282. + VCHIQ_STATE_T *state = dev_id;
  35283. + irqreturn_t ret = IRQ_NONE;
  35284. + unsigned int status;
  35285. +
  35286. + /* Read (and clear) the doorbell */
  35287. + status = readl(__io_address(ARM_0_BELL0));
  35288. +
  35289. + if (status & 0x4) { /* Was the doorbell rung? */
  35290. + remote_event_pollall(state);
  35291. + ret = IRQ_HANDLED;
  35292. + }
  35293. +
  35294. + return ret;
  35295. +}
  35296. +
  35297. +/* There is a potential problem with partial cache lines (pages?)
  35298. +** at the ends of the block when reading. If the CPU accessed anything in
  35299. +** the same line (page?) then it may have pulled old data into the cache,
  35300. +** obscuring the new data underneath. We can solve this by transferring the
  35301. +** partial cache lines separately, and allowing the ARM to copy into the
  35302. +** cached area.
  35303. +
  35304. +** N.B. This implementation plays slightly fast and loose with the Linux
  35305. +** driver programming rules, e.g. its use of __virt_to_bus instead of
  35306. +** dma_map_single, but it isn't a multi-platform driver and it benefits
  35307. +** from increased speed as a result.
  35308. +*/
  35309. +
  35310. +static int
  35311. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  35312. + struct task_struct *task, PAGELIST_T ** ppagelist)
  35313. +{
  35314. + PAGELIST_T *pagelist;
  35315. + struct page **pages;
  35316. + struct page *page;
  35317. + unsigned long *addrs;
  35318. + unsigned int num_pages, offset, i;
  35319. + char *addr, *base_addr, *next_addr;
  35320. + int run, addridx, actual_pages;
  35321. + unsigned long *need_release;
  35322. +
  35323. + offset = (unsigned int)buf & (PAGE_SIZE - 1);
  35324. + num_pages = (count + offset + PAGE_SIZE - 1) / PAGE_SIZE;
  35325. +
  35326. + *ppagelist = NULL;
  35327. +
  35328. + /* Allocate enough storage to hold the page pointers and the page
  35329. + ** list
  35330. + */
  35331. + pagelist = kmalloc(sizeof(PAGELIST_T) +
  35332. + (num_pages * sizeof(unsigned long)) +
  35333. + sizeof(unsigned long) +
  35334. + (num_pages * sizeof(pages[0])),
  35335. + GFP_KERNEL);
  35336. +
  35337. + vchiq_log_trace(vchiq_arm_log_level,
  35338. + "create_pagelist - %x", (unsigned int)pagelist);
  35339. + if (!pagelist)
  35340. + return -ENOMEM;
  35341. +
  35342. + addrs = pagelist->addrs;
  35343. + need_release = (unsigned long *)(addrs + num_pages);
  35344. + pages = (struct page **)(addrs + num_pages + 1);
  35345. +
  35346. + if (is_vmalloc_addr(buf)) {
  35347. + for (actual_pages = 0; actual_pages < num_pages; actual_pages++) {
  35348. + pages[actual_pages] = vmalloc_to_page(buf + (actual_pages * PAGE_SIZE));
  35349. + }
  35350. + *need_release = 0; /* do not try and release vmalloc pages */
  35351. + } else {
  35352. + down_read(&task->mm->mmap_sem);
  35353. + actual_pages = get_user_pages(task, task->mm,
  35354. + (unsigned long)buf & ~(PAGE_SIZE - 1),
  35355. + num_pages,
  35356. + (type == PAGELIST_READ) /*Write */ ,
  35357. + 0 /*Force */ ,
  35358. + pages,
  35359. + NULL /*vmas */);
  35360. + up_read(&task->mm->mmap_sem);
  35361. +
  35362. + if (actual_pages != num_pages) {
  35363. + vchiq_log_info(vchiq_arm_log_level,
  35364. + "create_pagelist - only %d/%d pages locked",
  35365. + actual_pages,
  35366. + num_pages);
  35367. +
  35368. + /* This is probably due to the process being killed */
  35369. + while (actual_pages > 0)
  35370. + {
  35371. + actual_pages--;
  35372. + page_cache_release(pages[actual_pages]);
  35373. + }
  35374. + kfree(pagelist);
  35375. + if (actual_pages == 0)
  35376. + actual_pages = -ENOMEM;
  35377. + return actual_pages;
  35378. + }
  35379. + *need_release = 1; /* release user pages */
  35380. + }
  35381. +
  35382. + pagelist->length = count;
  35383. + pagelist->type = type;
  35384. + pagelist->offset = offset;
  35385. +
  35386. + /* Group the pages into runs of contiguous pages */
  35387. +
  35388. + base_addr = VCHIQ_ARM_ADDRESS(page_address(pages[0]));
  35389. + next_addr = base_addr + PAGE_SIZE;
  35390. + addridx = 0;
  35391. + run = 0;
  35392. +
  35393. + for (i = 1; i < num_pages; i++) {
  35394. + addr = VCHIQ_ARM_ADDRESS(page_address(pages[i]));
  35395. + if ((addr == next_addr) && (run < (PAGE_SIZE - 1))) {
  35396. + next_addr += PAGE_SIZE;
  35397. + run++;
  35398. + } else {
  35399. + addrs[addridx] = (unsigned long)base_addr + run;
  35400. + addridx++;
  35401. + base_addr = addr;
  35402. + next_addr = addr + PAGE_SIZE;
  35403. + run = 0;
  35404. + }
  35405. + }
  35406. +
  35407. + addrs[addridx] = (unsigned long)base_addr + run;
  35408. + addridx++;
  35409. +
  35410. + /* Partial cache lines (fragments) require special measures */
  35411. + if ((type == PAGELIST_READ) &&
  35412. + ((pagelist->offset & (CACHE_LINE_SIZE - 1)) ||
  35413. + ((pagelist->offset + pagelist->length) &
  35414. + (CACHE_LINE_SIZE - 1)))) {
  35415. + FRAGMENTS_T *fragments;
  35416. +
  35417. + if (down_interruptible(&g_free_fragments_sema) != 0) {
  35418. + kfree(pagelist);
  35419. + return -EINTR;
  35420. + }
  35421. +
  35422. + WARN_ON(g_free_fragments == NULL);
  35423. +
  35424. + down(&g_free_fragments_mutex);
  35425. + fragments = (FRAGMENTS_T *) g_free_fragments;
  35426. + WARN_ON(fragments == NULL);
  35427. + g_free_fragments = *(FRAGMENTS_T **) g_free_fragments;
  35428. + up(&g_free_fragments_mutex);
  35429. + pagelist->type =
  35430. + PAGELIST_READ_WITH_FRAGMENTS + (fragments -
  35431. + g_fragments_base);
  35432. + }
  35433. +
  35434. + for (page = virt_to_page(pagelist);
  35435. + page <= virt_to_page(addrs + num_pages - 1); page++) {
  35436. + flush_dcache_page(page);
  35437. + }
  35438. +
  35439. + *ppagelist = pagelist;
  35440. +
  35441. + return 0;
  35442. +}
  35443. +
  35444. +static void
  35445. +free_pagelist(PAGELIST_T *pagelist, int actual)
  35446. +{
  35447. + unsigned long *need_release;
  35448. + struct page **pages;
  35449. + unsigned int num_pages, i;
  35450. +
  35451. + vchiq_log_trace(vchiq_arm_log_level,
  35452. + "free_pagelist - %x, %d", (unsigned int)pagelist, actual);
  35453. +
  35454. + num_pages =
  35455. + (pagelist->length + pagelist->offset + PAGE_SIZE - 1) /
  35456. + PAGE_SIZE;
  35457. +
  35458. + need_release = (unsigned long *)(pagelist->addrs + num_pages);
  35459. + pages = (struct page **)(pagelist->addrs + num_pages + 1);
  35460. +
  35461. + /* Deal with any partial cache lines (fragments) */
  35462. + if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS) {
  35463. + FRAGMENTS_T *fragments = g_fragments_base +
  35464. + (pagelist->type - PAGELIST_READ_WITH_FRAGMENTS);
  35465. + int head_bytes, tail_bytes;
  35466. + head_bytes = (CACHE_LINE_SIZE - pagelist->offset) &
  35467. + (CACHE_LINE_SIZE - 1);
  35468. + tail_bytes = (pagelist->offset + actual) &
  35469. + (CACHE_LINE_SIZE - 1);
  35470. +
  35471. + if ((actual >= 0) && (head_bytes != 0)) {
  35472. + if (head_bytes > actual)
  35473. + head_bytes = actual;
  35474. +
  35475. + memcpy((char *)page_address(pages[0]) +
  35476. + pagelist->offset,
  35477. + fragments->headbuf,
  35478. + head_bytes);
  35479. + }
  35480. + if ((actual >= 0) && (head_bytes < actual) &&
  35481. + (tail_bytes != 0)) {
  35482. + memcpy((char *)page_address(pages[num_pages - 1]) +
  35483. + ((pagelist->offset + actual) &
  35484. + (PAGE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1)),
  35485. + fragments->tailbuf, tail_bytes);
  35486. + }
  35487. +
  35488. + down(&g_free_fragments_mutex);
  35489. + *(FRAGMENTS_T **) fragments = g_free_fragments;
  35490. + g_free_fragments = fragments;
  35491. + up(&g_free_fragments_mutex);
  35492. + up(&g_free_fragments_sema);
  35493. + }
  35494. +
  35495. + if (*need_release) {
  35496. + for (i = 0; i < num_pages; i++) {
  35497. + if (pagelist->type != PAGELIST_WRITE)
  35498. + set_page_dirty(pages[i]);
  35499. +
  35500. + page_cache_release(pages[i]);
  35501. + }
  35502. + }
  35503. +
  35504. + kfree(pagelist);
  35505. +}
  35506. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h
  35507. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 1970-01-01 01:00:00.000000000 +0100
  35508. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 2015-02-09 04:40:07.000000000 +0100
  35509. @@ -0,0 +1,42 @@
  35510. +/**
  35511. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  35512. + *
  35513. + * Redistribution and use in source and binary forms, with or without
  35514. + * modification, are permitted provided that the following conditions
  35515. + * are met:
  35516. + * 1. Redistributions of source code must retain the above copyright
  35517. + * notice, this list of conditions, and the following disclaimer,
  35518. + * without modification.
  35519. + * 2. Redistributions in binary form must reproduce the above copyright
  35520. + * notice, this list of conditions and the following disclaimer in the
  35521. + * documentation and/or other materials provided with the distribution.
  35522. + * 3. The names of the above-listed copyright holders may not be used
  35523. + * to endorse or promote products derived from this software without
  35524. + * specific prior written permission.
  35525. + *
  35526. + * ALTERNATIVELY, this software may be distributed under the terms of the
  35527. + * GNU General Public License ("GPL") version 2, as published by the Free
  35528. + * Software Foundation.
  35529. + *
  35530. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  35531. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  35532. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35533. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35534. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  35535. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35536. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35537. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35538. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35539. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35540. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35541. + */
  35542. +
  35543. +#ifndef VCHIQ_2835_H
  35544. +#define VCHIQ_2835_H
  35545. +
  35546. +#include "vchiq_pagelist.h"
  35547. +
  35548. +#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
  35549. +#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX 1
  35550. +
  35551. +#endif /* VCHIQ_2835_H */
  35552. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
  35553. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 1970-01-01 01:00:00.000000000 +0100
  35554. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 2015-02-09 04:40:08.000000000 +0100
  35555. @@ -0,0 +1,2884 @@
  35556. +/**
  35557. + * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
  35558. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  35559. + *
  35560. + * Redistribution and use in source and binary forms, with or without
  35561. + * modification, are permitted provided that the following conditions
  35562. + * are met:
  35563. + * 1. Redistributions of source code must retain the above copyright
  35564. + * notice, this list of conditions, and the following disclaimer,
  35565. + * without modification.
  35566. + * 2. Redistributions in binary form must reproduce the above copyright
  35567. + * notice, this list of conditions and the following disclaimer in the
  35568. + * documentation and/or other materials provided with the distribution.
  35569. + * 3. The names of the above-listed copyright holders may not be used
  35570. + * to endorse or promote products derived from this software without
  35571. + * specific prior written permission.
  35572. + *
  35573. + * ALTERNATIVELY, this software may be distributed under the terms of the
  35574. + * GNU General Public License ("GPL") version 2, as published by the Free
  35575. + * Software Foundation.
  35576. + *
  35577. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  35578. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  35579. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35580. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35581. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  35582. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35583. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35584. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35585. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35586. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35587. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35588. + */
  35589. +
  35590. +#include <linux/kernel.h>
  35591. +#include <linux/module.h>
  35592. +#include <linux/types.h>
  35593. +#include <linux/errno.h>
  35594. +#include <linux/cdev.h>
  35595. +#include <linux/fs.h>
  35596. +#include <linux/device.h>
  35597. +#include <linux/mm.h>
  35598. +#include <linux/highmem.h>
  35599. +#include <linux/pagemap.h>
  35600. +#include <linux/bug.h>
  35601. +#include <linux/semaphore.h>
  35602. +#include <linux/list.h>
  35603. +
  35604. +#include "vchiq_core.h"
  35605. +#include "vchiq_ioctl.h"
  35606. +#include "vchiq_arm.h"
  35607. +#include "vchiq_debugfs.h"
  35608. +#include "vchiq_killable.h"
  35609. +
  35610. +#define DEVICE_NAME "vchiq"
  35611. +
  35612. +/* Override the default prefix, which would be vchiq_arm (from the filename) */
  35613. +#undef MODULE_PARAM_PREFIX
  35614. +#define MODULE_PARAM_PREFIX DEVICE_NAME "."
  35615. +
  35616. +#define VCHIQ_MINOR 0
  35617. +
  35618. +/* Some per-instance constants */
  35619. +#define MAX_COMPLETIONS 16
  35620. +#define MAX_SERVICES 64
  35621. +#define MAX_ELEMENTS 8
  35622. +#define MSG_QUEUE_SIZE 64
  35623. +
  35624. +#define KEEPALIVE_VER 1
  35625. +#define KEEPALIVE_VER_MIN KEEPALIVE_VER
  35626. +
  35627. +/* Run time control of log level, based on KERN_XXX level. */
  35628. +int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT;
  35629. +int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
  35630. +
  35631. +#define SUSPEND_TIMER_TIMEOUT_MS 100
  35632. +#define SUSPEND_RETRY_TIMER_TIMEOUT_MS 1000
  35633. +
  35634. +#define VC_SUSPEND_NUM_OFFSET 3 /* number of values before idle which are -ve */
  35635. +static const char *const suspend_state_names[] = {
  35636. + "VC_SUSPEND_FORCE_CANCELED",
  35637. + "VC_SUSPEND_REJECTED",
  35638. + "VC_SUSPEND_FAILED",
  35639. + "VC_SUSPEND_IDLE",
  35640. + "VC_SUSPEND_REQUESTED",
  35641. + "VC_SUSPEND_IN_PROGRESS",
  35642. + "VC_SUSPEND_SUSPENDED"
  35643. +};
  35644. +#define VC_RESUME_NUM_OFFSET 1 /* number of values before idle which are -ve */
  35645. +static const char *const resume_state_names[] = {
  35646. + "VC_RESUME_FAILED",
  35647. + "VC_RESUME_IDLE",
  35648. + "VC_RESUME_REQUESTED",
  35649. + "VC_RESUME_IN_PROGRESS",
  35650. + "VC_RESUME_RESUMED"
  35651. +};
  35652. +/* The number of times we allow force suspend to timeout before actually
  35653. +** _forcing_ suspend. This is to cater for SW which fails to release vchiq
  35654. +** correctly - we don't want to prevent ARM suspend indefinitely in this case.
  35655. +*/
  35656. +#define FORCE_SUSPEND_FAIL_MAX 8
  35657. +
  35658. +/* The time in ms allowed for videocore to go idle when force suspend has been
  35659. + * requested */
  35660. +#define FORCE_SUSPEND_TIMEOUT_MS 200
  35661. +
  35662. +
  35663. +static void suspend_timer_callback(unsigned long context);
  35664. +
  35665. +
  35666. +typedef struct user_service_struct {
  35667. + VCHIQ_SERVICE_T *service;
  35668. + void *userdata;
  35669. + VCHIQ_INSTANCE_T instance;
  35670. + char is_vchi;
  35671. + char dequeue_pending;
  35672. + char close_pending;
  35673. + int message_available_pos;
  35674. + int msg_insert;
  35675. + int msg_remove;
  35676. + struct semaphore insert_event;
  35677. + struct semaphore remove_event;
  35678. + struct semaphore close_event;
  35679. + VCHIQ_HEADER_T * msg_queue[MSG_QUEUE_SIZE];
  35680. +} USER_SERVICE_T;
  35681. +
  35682. +struct bulk_waiter_node {
  35683. + struct bulk_waiter bulk_waiter;
  35684. + int pid;
  35685. + struct list_head list;
  35686. +};
  35687. +
  35688. +struct vchiq_instance_struct {
  35689. + VCHIQ_STATE_T *state;
  35690. + VCHIQ_COMPLETION_DATA_T completions[MAX_COMPLETIONS];
  35691. + int completion_insert;
  35692. + int completion_remove;
  35693. + struct semaphore insert_event;
  35694. + struct semaphore remove_event;
  35695. + struct mutex completion_mutex;
  35696. +
  35697. + int connected;
  35698. + int closing;
  35699. + int pid;
  35700. + int mark;
  35701. + int use_close_delivered;
  35702. + int trace;
  35703. +
  35704. + struct list_head bulk_waiter_list;
  35705. + struct mutex bulk_waiter_list_mutex;
  35706. +
  35707. + VCHIQ_DEBUGFS_NODE_T debugfs_node;
  35708. +};
  35709. +
  35710. +typedef struct dump_context_struct {
  35711. + char __user *buf;
  35712. + size_t actual;
  35713. + size_t space;
  35714. + loff_t offset;
  35715. +} DUMP_CONTEXT_T;
  35716. +
  35717. +static struct cdev vchiq_cdev;
  35718. +static dev_t vchiq_devid;
  35719. +static VCHIQ_STATE_T g_state;
  35720. +static struct class *vchiq_class;
  35721. +static struct device *vchiq_dev;
  35722. +static DEFINE_SPINLOCK(msg_queue_spinlock);
  35723. +
  35724. +static const char *const ioctl_names[] = {
  35725. + "CONNECT",
  35726. + "SHUTDOWN",
  35727. + "CREATE_SERVICE",
  35728. + "REMOVE_SERVICE",
  35729. + "QUEUE_MESSAGE",
  35730. + "QUEUE_BULK_TRANSMIT",
  35731. + "QUEUE_BULK_RECEIVE",
  35732. + "AWAIT_COMPLETION",
  35733. + "DEQUEUE_MESSAGE",
  35734. + "GET_CLIENT_ID",
  35735. + "GET_CONFIG",
  35736. + "CLOSE_SERVICE",
  35737. + "USE_SERVICE",
  35738. + "RELEASE_SERVICE",
  35739. + "SET_SERVICE_OPTION",
  35740. + "DUMP_PHYS_MEM",
  35741. + "LIB_VERSION",
  35742. + "CLOSE_DELIVERED"
  35743. +};
  35744. +
  35745. +vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
  35746. + (VCHIQ_IOC_MAX + 1));
  35747. +
  35748. +static void
  35749. +dump_phys_mem(void *virt_addr, uint32_t num_bytes);
  35750. +
  35751. +/****************************************************************************
  35752. +*
  35753. +* add_completion
  35754. +*
  35755. +***************************************************************************/
  35756. +
  35757. +static VCHIQ_STATUS_T
  35758. +add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
  35759. + VCHIQ_HEADER_T *header, USER_SERVICE_T *user_service,
  35760. + void *bulk_userdata)
  35761. +{
  35762. + VCHIQ_COMPLETION_DATA_T *completion;
  35763. + DEBUG_INITIALISE(g_state.local)
  35764. +
  35765. + while (instance->completion_insert ==
  35766. + (instance->completion_remove + MAX_COMPLETIONS)) {
  35767. + /* Out of space - wait for the client */
  35768. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35769. + vchiq_log_trace(vchiq_arm_log_level,
  35770. + "add_completion - completion queue full");
  35771. + DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
  35772. + if (down_interruptible(&instance->remove_event) != 0) {
  35773. + vchiq_log_info(vchiq_arm_log_level,
  35774. + "service_callback interrupted");
  35775. + return VCHIQ_RETRY;
  35776. + } else if (instance->closing) {
  35777. + vchiq_log_info(vchiq_arm_log_level,
  35778. + "service_callback closing");
  35779. + return VCHIQ_ERROR;
  35780. + }
  35781. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35782. + }
  35783. +
  35784. + completion =
  35785. + &instance->completions[instance->completion_insert &
  35786. + (MAX_COMPLETIONS - 1)];
  35787. +
  35788. + completion->header = header;
  35789. + completion->reason = reason;
  35790. + /* N.B. service_userdata is updated while processing AWAIT_COMPLETION */
  35791. + completion->service_userdata = user_service->service;
  35792. + completion->bulk_userdata = bulk_userdata;
  35793. +
  35794. + if (reason == VCHIQ_SERVICE_CLOSED) {
  35795. + /* Take an extra reference, to be held until
  35796. + this CLOSED notification is delivered. */
  35797. + lock_service(user_service->service);
  35798. + if (instance->use_close_delivered)
  35799. + user_service->close_pending = 1;
  35800. + }
  35801. +
  35802. + /* A write barrier is needed here to ensure that the entire completion
  35803. + record is written out before the insert point. */
  35804. + wmb();
  35805. +
  35806. + if (reason == VCHIQ_MESSAGE_AVAILABLE)
  35807. + user_service->message_available_pos =
  35808. + instance->completion_insert;
  35809. + instance->completion_insert++;
  35810. +
  35811. + up(&instance->insert_event);
  35812. +
  35813. + return VCHIQ_SUCCESS;
  35814. +}
  35815. +
  35816. +/****************************************************************************
  35817. +*
  35818. +* service_callback
  35819. +*
  35820. +***************************************************************************/
  35821. +
  35822. +static VCHIQ_STATUS_T
  35823. +service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
  35824. + VCHIQ_SERVICE_HANDLE_T handle, void *bulk_userdata)
  35825. +{
  35826. + /* How do we ensure the callback goes to the right client?
  35827. + ** The service_user data points to a USER_SERVICE_T record containing
  35828. + ** the original callback and the user state structure, which contains a
  35829. + ** circular buffer for completion records.
  35830. + */
  35831. + USER_SERVICE_T *user_service;
  35832. + VCHIQ_SERVICE_T *service;
  35833. + VCHIQ_INSTANCE_T instance;
  35834. + DEBUG_INITIALISE(g_state.local)
  35835. +
  35836. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35837. +
  35838. + service = handle_to_service(handle);
  35839. + BUG_ON(!service);
  35840. + user_service = (USER_SERVICE_T *)service->base.userdata;
  35841. + instance = user_service->instance;
  35842. +
  35843. + if (!instance || instance->closing)
  35844. + return VCHIQ_SUCCESS;
  35845. +
  35846. + vchiq_log_trace(vchiq_arm_log_level,
  35847. + "service_callback - service %lx(%d,%p), reason %d, header %lx, "
  35848. + "instance %lx, bulk_userdata %lx",
  35849. + (unsigned long)user_service,
  35850. + service->localport, user_service->userdata,
  35851. + reason, (unsigned long)header,
  35852. + (unsigned long)instance, (unsigned long)bulk_userdata);
  35853. +
  35854. + if (header && user_service->is_vchi) {
  35855. + spin_lock(&msg_queue_spinlock);
  35856. + while (user_service->msg_insert ==
  35857. + (user_service->msg_remove + MSG_QUEUE_SIZE)) {
  35858. + spin_unlock(&msg_queue_spinlock);
  35859. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35860. + DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
  35861. + vchiq_log_trace(vchiq_arm_log_level,
  35862. + "service_callback - msg queue full");
  35863. + /* If there is no MESSAGE_AVAILABLE in the completion
  35864. + ** queue, add one
  35865. + */
  35866. + if ((user_service->message_available_pos -
  35867. + instance->completion_remove) < 0) {
  35868. + VCHIQ_STATUS_T status;
  35869. + vchiq_log_info(vchiq_arm_log_level,
  35870. + "Inserting extra MESSAGE_AVAILABLE");
  35871. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35872. + status = add_completion(instance, reason,
  35873. + NULL, user_service, bulk_userdata);
  35874. + if (status != VCHIQ_SUCCESS) {
  35875. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35876. + return status;
  35877. + }
  35878. + }
  35879. +
  35880. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35881. + if (down_interruptible(&user_service->remove_event)
  35882. + != 0) {
  35883. + vchiq_log_info(vchiq_arm_log_level,
  35884. + "service_callback interrupted");
  35885. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35886. + return VCHIQ_RETRY;
  35887. + } else if (instance->closing) {
  35888. + vchiq_log_info(vchiq_arm_log_level,
  35889. + "service_callback closing");
  35890. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35891. + return VCHIQ_ERROR;
  35892. + }
  35893. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35894. + spin_lock(&msg_queue_spinlock);
  35895. + }
  35896. +
  35897. + user_service->msg_queue[user_service->msg_insert &
  35898. + (MSG_QUEUE_SIZE - 1)] = header;
  35899. + user_service->msg_insert++;
  35900. + spin_unlock(&msg_queue_spinlock);
  35901. +
  35902. + up(&user_service->insert_event);
  35903. +
  35904. + /* If there is a thread waiting in DEQUEUE_MESSAGE, or if
  35905. + ** there is a MESSAGE_AVAILABLE in the completion queue then
  35906. + ** bypass the completion queue.
  35907. + */
  35908. + if (((user_service->message_available_pos -
  35909. + instance->completion_remove) >= 0) ||
  35910. + user_service->dequeue_pending) {
  35911. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35912. + user_service->dequeue_pending = 0;
  35913. + return VCHIQ_SUCCESS;
  35914. + }
  35915. +
  35916. + header = NULL;
  35917. + }
  35918. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  35919. +
  35920. + return add_completion(instance, reason, header, user_service,
  35921. + bulk_userdata);
  35922. +}
  35923. +
  35924. +/****************************************************************************
  35925. +*
  35926. +* user_service_free
  35927. +*
  35928. +***************************************************************************/
  35929. +static void
  35930. +user_service_free(void *userdata)
  35931. +{
  35932. + kfree(userdata);
  35933. +}
  35934. +
  35935. +/****************************************************************************
  35936. +*
  35937. +* close_delivered
  35938. +*
  35939. +***************************************************************************/
  35940. +static void close_delivered(USER_SERVICE_T *user_service)
  35941. +{
  35942. + vchiq_log_info(vchiq_arm_log_level,
  35943. + "close_delivered(handle=%x)",
  35944. + user_service->service->handle);
  35945. +
  35946. + if (user_service->close_pending) {
  35947. + /* Allow the underlying service to be culled */
  35948. + unlock_service(user_service->service);
  35949. +
  35950. + /* Wake the user-thread blocked in close_ or remove_service */
  35951. + up(&user_service->close_event);
  35952. +
  35953. + user_service->close_pending = 0;
  35954. + }
  35955. +}
  35956. +
  35957. +/****************************************************************************
  35958. +*
  35959. +* vchiq_ioctl
  35960. +*
  35961. +***************************************************************************/
  35962. +static long
  35963. +vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  35964. +{
  35965. + VCHIQ_INSTANCE_T instance = file->private_data;
  35966. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  35967. + VCHIQ_SERVICE_T *service = NULL;
  35968. + long ret = 0;
  35969. + int i, rc;
  35970. + DEBUG_INITIALISE(g_state.local)
  35971. +
  35972. + vchiq_log_trace(vchiq_arm_log_level,
  35973. + "vchiq_ioctl - instance %x, cmd %s, arg %lx",
  35974. + (unsigned int)instance,
  35975. + ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&
  35976. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?
  35977. + ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg);
  35978. +
  35979. + switch (cmd) {
  35980. + case VCHIQ_IOC_SHUTDOWN:
  35981. + if (!instance->connected)
  35982. + break;
  35983. +
  35984. + /* Remove all services */
  35985. + i = 0;
  35986. + while ((service = next_service_by_instance(instance->state,
  35987. + instance, &i)) != NULL) {
  35988. + status = vchiq_remove_service(service->handle);
  35989. + unlock_service(service);
  35990. + if (status != VCHIQ_SUCCESS)
  35991. + break;
  35992. + }
  35993. + service = NULL;
  35994. +
  35995. + if (status == VCHIQ_SUCCESS) {
  35996. + /* Wake the completion thread and ask it to exit */
  35997. + instance->closing = 1;
  35998. + up(&instance->insert_event);
  35999. + }
  36000. +
  36001. + break;
  36002. +
  36003. + case VCHIQ_IOC_CONNECT:
  36004. + if (instance->connected) {
  36005. + ret = -EINVAL;
  36006. + break;
  36007. + }
  36008. + rc = mutex_lock_interruptible(&instance->state->mutex);
  36009. + if (rc != 0) {
  36010. + vchiq_log_error(vchiq_arm_log_level,
  36011. + "vchiq: connect: could not lock mutex for "
  36012. + "state %d: %d",
  36013. + instance->state->id, rc);
  36014. + ret = -EINTR;
  36015. + break;
  36016. + }
  36017. + status = vchiq_connect_internal(instance->state, instance);
  36018. + mutex_unlock(&instance->state->mutex);
  36019. +
  36020. + if (status == VCHIQ_SUCCESS)
  36021. + instance->connected = 1;
  36022. + else
  36023. + vchiq_log_error(vchiq_arm_log_level,
  36024. + "vchiq: could not connect: %d", status);
  36025. + break;
  36026. +
  36027. + case VCHIQ_IOC_CREATE_SERVICE: {
  36028. + VCHIQ_CREATE_SERVICE_T args;
  36029. + USER_SERVICE_T *user_service = NULL;
  36030. + void *userdata;
  36031. + int srvstate;
  36032. +
  36033. + if (copy_from_user
  36034. + (&args, (const void __user *)arg,
  36035. + sizeof(args)) != 0) {
  36036. + ret = -EFAULT;
  36037. + break;
  36038. + }
  36039. +
  36040. + user_service = kmalloc(sizeof(USER_SERVICE_T), GFP_KERNEL);
  36041. + if (!user_service) {
  36042. + ret = -ENOMEM;
  36043. + break;
  36044. + }
  36045. +
  36046. + if (args.is_open) {
  36047. + if (!instance->connected) {
  36048. + ret = -ENOTCONN;
  36049. + kfree(user_service);
  36050. + break;
  36051. + }
  36052. + srvstate = VCHIQ_SRVSTATE_OPENING;
  36053. + } else {
  36054. + srvstate =
  36055. + instance->connected ?
  36056. + VCHIQ_SRVSTATE_LISTENING :
  36057. + VCHIQ_SRVSTATE_HIDDEN;
  36058. + }
  36059. +
  36060. + userdata = args.params.userdata;
  36061. + args.params.callback = service_callback;
  36062. + args.params.userdata = user_service;
  36063. + service = vchiq_add_service_internal(
  36064. + instance->state,
  36065. + &args.params, srvstate,
  36066. + instance, user_service_free);
  36067. +
  36068. + if (service != NULL) {
  36069. + user_service->service = service;
  36070. + user_service->userdata = userdata;
  36071. + user_service->instance = instance;
  36072. + user_service->is_vchi = (args.is_vchi != 0);
  36073. + user_service->dequeue_pending = 0;
  36074. + user_service->close_pending = 0;
  36075. + user_service->message_available_pos =
  36076. + instance->completion_remove - 1;
  36077. + user_service->msg_insert = 0;
  36078. + user_service->msg_remove = 0;
  36079. + sema_init(&user_service->insert_event, 0);
  36080. + sema_init(&user_service->remove_event, 0);
  36081. + sema_init(&user_service->close_event, 0);
  36082. +
  36083. + if (args.is_open) {
  36084. + status = vchiq_open_service_internal
  36085. + (service, instance->pid);
  36086. + if (status != VCHIQ_SUCCESS) {
  36087. + vchiq_remove_service(service->handle);
  36088. + service = NULL;
  36089. + ret = (status == VCHIQ_RETRY) ?
  36090. + -EINTR : -EIO;
  36091. + break;
  36092. + }
  36093. + }
  36094. +
  36095. + if (copy_to_user((void __user *)
  36096. + &(((VCHIQ_CREATE_SERVICE_T __user *)
  36097. + arg)->handle),
  36098. + (const void *)&service->handle,
  36099. + sizeof(service->handle)) != 0) {
  36100. + ret = -EFAULT;
  36101. + vchiq_remove_service(service->handle);
  36102. + }
  36103. +
  36104. + service = NULL;
  36105. + } else {
  36106. + ret = -EEXIST;
  36107. + kfree(user_service);
  36108. + }
  36109. + } break;
  36110. +
  36111. + case VCHIQ_IOC_CLOSE_SERVICE: {
  36112. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  36113. +
  36114. + service = find_service_for_instance(instance, handle);
  36115. + if (service != NULL) {
  36116. + USER_SERVICE_T *user_service =
  36117. + (USER_SERVICE_T *)service->base.userdata;
  36118. + /* close_pending is false on first entry, and when the
  36119. + wait in vchiq_close_service has been interrupted. */
  36120. + if (!user_service->close_pending) {
  36121. + status = vchiq_close_service(service->handle);
  36122. + if (status != VCHIQ_SUCCESS)
  36123. + break;
  36124. + }
  36125. +
  36126. + /* close_pending is true once the underlying service
  36127. + has been closed until the client library calls the
  36128. + CLOSE_DELIVERED ioctl, signalling close_event. */
  36129. + if (user_service->close_pending &&
  36130. + down_interruptible(&user_service->close_event))
  36131. + status = VCHIQ_RETRY;
  36132. + }
  36133. + else
  36134. + ret = -EINVAL;
  36135. + } break;
  36136. +
  36137. + case VCHIQ_IOC_REMOVE_SERVICE: {
  36138. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  36139. +
  36140. + service = find_service_for_instance(instance, handle);
  36141. + if (service != NULL) {
  36142. + USER_SERVICE_T *user_service =
  36143. + (USER_SERVICE_T *)service->base.userdata;
  36144. + /* close_pending is false on first entry, and when the
  36145. + wait in vchiq_close_service has been interrupted. */
  36146. + if (!user_service->close_pending) {
  36147. + status = vchiq_remove_service(service->handle);
  36148. + if (status != VCHIQ_SUCCESS)
  36149. + break;
  36150. + }
  36151. +
  36152. + /* close_pending is true once the underlying service
  36153. + has been closed until the client library calls the
  36154. + CLOSE_DELIVERED ioctl, signalling close_event. */
  36155. + if (user_service->close_pending &&
  36156. + down_interruptible(&user_service->close_event))
  36157. + status = VCHIQ_RETRY;
  36158. + }
  36159. + else
  36160. + ret = -EINVAL;
  36161. + } break;
  36162. +
  36163. + case VCHIQ_IOC_USE_SERVICE:
  36164. + case VCHIQ_IOC_RELEASE_SERVICE: {
  36165. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  36166. +
  36167. + service = find_service_for_instance(instance, handle);
  36168. + if (service != NULL) {
  36169. + status = (cmd == VCHIQ_IOC_USE_SERVICE) ?
  36170. + vchiq_use_service_internal(service) :
  36171. + vchiq_release_service_internal(service);
  36172. + if (status != VCHIQ_SUCCESS) {
  36173. + vchiq_log_error(vchiq_susp_log_level,
  36174. + "%s: cmd %s returned error %d for "
  36175. + "service %c%c%c%c:%03d",
  36176. + __func__,
  36177. + (cmd == VCHIQ_IOC_USE_SERVICE) ?
  36178. + "VCHIQ_IOC_USE_SERVICE" :
  36179. + "VCHIQ_IOC_RELEASE_SERVICE",
  36180. + status,
  36181. + VCHIQ_FOURCC_AS_4CHARS(
  36182. + service->base.fourcc),
  36183. + service->client_id);
  36184. + ret = -EINVAL;
  36185. + }
  36186. + } else
  36187. + ret = -EINVAL;
  36188. + } break;
  36189. +
  36190. + case VCHIQ_IOC_QUEUE_MESSAGE: {
  36191. + VCHIQ_QUEUE_MESSAGE_T args;
  36192. + if (copy_from_user
  36193. + (&args, (const void __user *)arg,
  36194. + sizeof(args)) != 0) {
  36195. + ret = -EFAULT;
  36196. + break;
  36197. + }
  36198. +
  36199. + service = find_service_for_instance(instance, args.handle);
  36200. +
  36201. + if ((service != NULL) && (args.count <= MAX_ELEMENTS)) {
  36202. + /* Copy elements into kernel space */
  36203. + VCHIQ_ELEMENT_T elements[MAX_ELEMENTS];
  36204. + if (copy_from_user(elements, args.elements,
  36205. + args.count * sizeof(VCHIQ_ELEMENT_T)) == 0)
  36206. + status = vchiq_queue_message
  36207. + (args.handle,
  36208. + elements, args.count);
  36209. + else
  36210. + ret = -EFAULT;
  36211. + } else {
  36212. + ret = -EINVAL;
  36213. + }
  36214. + } break;
  36215. +
  36216. + case VCHIQ_IOC_QUEUE_BULK_TRANSMIT:
  36217. + case VCHIQ_IOC_QUEUE_BULK_RECEIVE: {
  36218. + VCHIQ_QUEUE_BULK_TRANSFER_T args;
  36219. + struct bulk_waiter_node *waiter = NULL;
  36220. + VCHIQ_BULK_DIR_T dir =
  36221. + (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT) ?
  36222. + VCHIQ_BULK_TRANSMIT : VCHIQ_BULK_RECEIVE;
  36223. +
  36224. + if (copy_from_user
  36225. + (&args, (const void __user *)arg,
  36226. + sizeof(args)) != 0) {
  36227. + ret = -EFAULT;
  36228. + break;
  36229. + }
  36230. +
  36231. + service = find_service_for_instance(instance, args.handle);
  36232. + if (!service) {
  36233. + ret = -EINVAL;
  36234. + break;
  36235. + }
  36236. +
  36237. + if (args.mode == VCHIQ_BULK_MODE_BLOCKING) {
  36238. + waiter = kzalloc(sizeof(struct bulk_waiter_node),
  36239. + GFP_KERNEL);
  36240. + if (!waiter) {
  36241. + ret = -ENOMEM;
  36242. + break;
  36243. + }
  36244. + args.userdata = &waiter->bulk_waiter;
  36245. + } else if (args.mode == VCHIQ_BULK_MODE_WAITING) {
  36246. + struct list_head *pos;
  36247. + mutex_lock(&instance->bulk_waiter_list_mutex);
  36248. + list_for_each(pos, &instance->bulk_waiter_list) {
  36249. + if (list_entry(pos, struct bulk_waiter_node,
  36250. + list)->pid == current->pid) {
  36251. + waiter = list_entry(pos,
  36252. + struct bulk_waiter_node,
  36253. + list);
  36254. + list_del(pos);
  36255. + break;
  36256. + }
  36257. +
  36258. + }
  36259. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  36260. + if (!waiter) {
  36261. + vchiq_log_error(vchiq_arm_log_level,
  36262. + "no bulk_waiter found for pid %d",
  36263. + current->pid);
  36264. + ret = -ESRCH;
  36265. + break;
  36266. + }
  36267. + vchiq_log_info(vchiq_arm_log_level,
  36268. + "found bulk_waiter %x for pid %d",
  36269. + (unsigned int)waiter, current->pid);
  36270. + args.userdata = &waiter->bulk_waiter;
  36271. + }
  36272. + status = vchiq_bulk_transfer
  36273. + (args.handle,
  36274. + VCHI_MEM_HANDLE_INVALID,
  36275. + args.data, args.size,
  36276. + args.userdata, args.mode,
  36277. + dir);
  36278. + if (!waiter)
  36279. + break;
  36280. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  36281. + !waiter->bulk_waiter.bulk) {
  36282. + if (waiter->bulk_waiter.bulk) {
  36283. + /* Cancel the signal when the transfer
  36284. + ** completes. */
  36285. + spin_lock(&bulk_waiter_spinlock);
  36286. + waiter->bulk_waiter.bulk->userdata = NULL;
  36287. + spin_unlock(&bulk_waiter_spinlock);
  36288. + }
  36289. + kfree(waiter);
  36290. + } else {
  36291. + const VCHIQ_BULK_MODE_T mode_waiting =
  36292. + VCHIQ_BULK_MODE_WAITING;
  36293. + waiter->pid = current->pid;
  36294. + mutex_lock(&instance->bulk_waiter_list_mutex);
  36295. + list_add(&waiter->list, &instance->bulk_waiter_list);
  36296. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  36297. + vchiq_log_info(vchiq_arm_log_level,
  36298. + "saved bulk_waiter %x for pid %d",
  36299. + (unsigned int)waiter, current->pid);
  36300. +
  36301. + if (copy_to_user((void __user *)
  36302. + &(((VCHIQ_QUEUE_BULK_TRANSFER_T __user *)
  36303. + arg)->mode),
  36304. + (const void *)&mode_waiting,
  36305. + sizeof(mode_waiting)) != 0)
  36306. + ret = -EFAULT;
  36307. + }
  36308. + } break;
  36309. +
  36310. + case VCHIQ_IOC_AWAIT_COMPLETION: {
  36311. + VCHIQ_AWAIT_COMPLETION_T args;
  36312. +
  36313. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  36314. + if (!instance->connected) {
  36315. + ret = -ENOTCONN;
  36316. + break;
  36317. + }
  36318. +
  36319. + if (copy_from_user(&args, (const void __user *)arg,
  36320. + sizeof(args)) != 0) {
  36321. + ret = -EFAULT;
  36322. + break;
  36323. + }
  36324. +
  36325. + mutex_lock(&instance->completion_mutex);
  36326. +
  36327. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  36328. + while ((instance->completion_remove ==
  36329. + instance->completion_insert)
  36330. + && !instance->closing) {
  36331. + int rc;
  36332. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  36333. + mutex_unlock(&instance->completion_mutex);
  36334. + rc = down_interruptible(&instance->insert_event);
  36335. + mutex_lock(&instance->completion_mutex);
  36336. + if (rc != 0) {
  36337. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  36338. + vchiq_log_info(vchiq_arm_log_level,
  36339. + "AWAIT_COMPLETION interrupted");
  36340. + ret = -EINTR;
  36341. + break;
  36342. + }
  36343. + }
  36344. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  36345. +
  36346. + /* A read memory barrier is needed to stop prefetch of a stale
  36347. + ** completion record
  36348. + */
  36349. + rmb();
  36350. +
  36351. + if (ret == 0) {
  36352. + int msgbufcount = args.msgbufcount;
  36353. + for (ret = 0; ret < args.count; ret++) {
  36354. + VCHIQ_COMPLETION_DATA_T *completion;
  36355. + VCHIQ_SERVICE_T *service;
  36356. + USER_SERVICE_T *user_service;
  36357. + VCHIQ_HEADER_T *header;
  36358. + if (instance->completion_remove ==
  36359. + instance->completion_insert)
  36360. + break;
  36361. + completion = &instance->completions[
  36362. + instance->completion_remove &
  36363. + (MAX_COMPLETIONS - 1)];
  36364. +
  36365. + service = completion->service_userdata;
  36366. + user_service = service->base.userdata;
  36367. + completion->service_userdata =
  36368. + user_service->userdata;
  36369. +
  36370. + header = completion->header;
  36371. + if (header) {
  36372. + void __user *msgbuf;
  36373. + int msglen;
  36374. +
  36375. + msglen = header->size +
  36376. + sizeof(VCHIQ_HEADER_T);
  36377. + /* This must be a VCHIQ-style service */
  36378. + if (args.msgbufsize < msglen) {
  36379. + vchiq_log_error(
  36380. + vchiq_arm_log_level,
  36381. + "header %x: msgbufsize"
  36382. + " %x < msglen %x",
  36383. + (unsigned int)header,
  36384. + args.msgbufsize,
  36385. + msglen);
  36386. + WARN(1, "invalid message "
  36387. + "size\n");
  36388. + if (ret == 0)
  36389. + ret = -EMSGSIZE;
  36390. + break;
  36391. + }
  36392. + if (msgbufcount <= 0)
  36393. + /* Stall here for lack of a
  36394. + ** buffer for the message. */
  36395. + break;
  36396. + /* Get the pointer from user space */
  36397. + msgbufcount--;
  36398. + if (copy_from_user(&msgbuf,
  36399. + (const void __user *)
  36400. + &args.msgbufs[msgbufcount],
  36401. + sizeof(msgbuf)) != 0) {
  36402. + if (ret == 0)
  36403. + ret = -EFAULT;
  36404. + break;
  36405. + }
  36406. +
  36407. + /* Copy the message to user space */
  36408. + if (copy_to_user(msgbuf, header,
  36409. + msglen) != 0) {
  36410. + if (ret == 0)
  36411. + ret = -EFAULT;
  36412. + break;
  36413. + }
  36414. +
  36415. + /* Now it has been copied, the message
  36416. + ** can be released. */
  36417. + vchiq_release_message(service->handle,
  36418. + header);
  36419. +
  36420. + /* The completion must point to the
  36421. + ** msgbuf. */
  36422. + completion->header = msgbuf;
  36423. + }
  36424. +
  36425. + if ((completion->reason ==
  36426. + VCHIQ_SERVICE_CLOSED) &&
  36427. + !instance->use_close_delivered)
  36428. + unlock_service(service);
  36429. +
  36430. + if (copy_to_user((void __user *)(
  36431. + (size_t)args.buf +
  36432. + ret * sizeof(VCHIQ_COMPLETION_DATA_T)),
  36433. + completion,
  36434. + sizeof(VCHIQ_COMPLETION_DATA_T)) != 0) {
  36435. + if (ret == 0)
  36436. + ret = -EFAULT;
  36437. + break;
  36438. + }
  36439. +
  36440. + instance->completion_remove++;
  36441. + }
  36442. +
  36443. + if (msgbufcount != args.msgbufcount) {
  36444. + if (copy_to_user((void __user *)
  36445. + &((VCHIQ_AWAIT_COMPLETION_T *)arg)->
  36446. + msgbufcount,
  36447. + &msgbufcount,
  36448. + sizeof(msgbufcount)) != 0) {
  36449. + ret = -EFAULT;
  36450. + }
  36451. + }
  36452. + }
  36453. +
  36454. + if (ret != 0)
  36455. + up(&instance->remove_event);
  36456. + mutex_unlock(&instance->completion_mutex);
  36457. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  36458. + } break;
  36459. +
  36460. + case VCHIQ_IOC_DEQUEUE_MESSAGE: {
  36461. + VCHIQ_DEQUEUE_MESSAGE_T args;
  36462. + USER_SERVICE_T *user_service;
  36463. + VCHIQ_HEADER_T *header;
  36464. +
  36465. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  36466. + if (copy_from_user
  36467. + (&args, (const void __user *)arg,
  36468. + sizeof(args)) != 0) {
  36469. + ret = -EFAULT;
  36470. + break;
  36471. + }
  36472. + service = find_service_for_instance(instance, args.handle);
  36473. + if (!service) {
  36474. + ret = -EINVAL;
  36475. + break;
  36476. + }
  36477. + user_service = (USER_SERVICE_T *)service->base.userdata;
  36478. + if (user_service->is_vchi == 0) {
  36479. + ret = -EINVAL;
  36480. + break;
  36481. + }
  36482. +
  36483. + spin_lock(&msg_queue_spinlock);
  36484. + if (user_service->msg_remove == user_service->msg_insert) {
  36485. + if (!args.blocking) {
  36486. + spin_unlock(&msg_queue_spinlock);
  36487. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  36488. + ret = -EWOULDBLOCK;
  36489. + break;
  36490. + }
  36491. + user_service->dequeue_pending = 1;
  36492. + do {
  36493. + spin_unlock(&msg_queue_spinlock);
  36494. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  36495. + if (down_interruptible(
  36496. + &user_service->insert_event) != 0) {
  36497. + vchiq_log_info(vchiq_arm_log_level,
  36498. + "DEQUEUE_MESSAGE interrupted");
  36499. + ret = -EINTR;
  36500. + break;
  36501. + }
  36502. + spin_lock(&msg_queue_spinlock);
  36503. + } while (user_service->msg_remove ==
  36504. + user_service->msg_insert);
  36505. +
  36506. + if (ret)
  36507. + break;
  36508. + }
  36509. +
  36510. + BUG_ON((int)(user_service->msg_insert -
  36511. + user_service->msg_remove) < 0);
  36512. +
  36513. + header = user_service->msg_queue[user_service->msg_remove &
  36514. + (MSG_QUEUE_SIZE - 1)];
  36515. + user_service->msg_remove++;
  36516. + spin_unlock(&msg_queue_spinlock);
  36517. +
  36518. + up(&user_service->remove_event);
  36519. + if (header == NULL)
  36520. + ret = -ENOTCONN;
  36521. + else if (header->size <= args.bufsize) {
  36522. + /* Copy to user space if msgbuf is not NULL */
  36523. + if ((args.buf == NULL) ||
  36524. + (copy_to_user((void __user *)args.buf,
  36525. + header->data,
  36526. + header->size) == 0)) {
  36527. + ret = header->size;
  36528. + vchiq_release_message(
  36529. + service->handle,
  36530. + header);
  36531. + } else
  36532. + ret = -EFAULT;
  36533. + } else {
  36534. + vchiq_log_error(vchiq_arm_log_level,
  36535. + "header %x: bufsize %x < size %x",
  36536. + (unsigned int)header, args.bufsize,
  36537. + header->size);
  36538. + WARN(1, "invalid size\n");
  36539. + ret = -EMSGSIZE;
  36540. + }
  36541. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  36542. + } break;
  36543. +
  36544. + case VCHIQ_IOC_GET_CLIENT_ID: {
  36545. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  36546. +
  36547. + ret = vchiq_get_client_id(handle);
  36548. + } break;
  36549. +
  36550. + case VCHIQ_IOC_GET_CONFIG: {
  36551. + VCHIQ_GET_CONFIG_T args;
  36552. + VCHIQ_CONFIG_T config;
  36553. +
  36554. + if (copy_from_user(&args, (const void __user *)arg,
  36555. + sizeof(args)) != 0) {
  36556. + ret = -EFAULT;
  36557. + break;
  36558. + }
  36559. + if (args.config_size > sizeof(config)) {
  36560. + ret = -EINVAL;
  36561. + break;
  36562. + }
  36563. + status = vchiq_get_config(instance, args.config_size, &config);
  36564. + if (status == VCHIQ_SUCCESS) {
  36565. + if (copy_to_user((void __user *)args.pconfig,
  36566. + &config, args.config_size) != 0) {
  36567. + ret = -EFAULT;
  36568. + break;
  36569. + }
  36570. + }
  36571. + } break;
  36572. +
  36573. + case VCHIQ_IOC_SET_SERVICE_OPTION: {
  36574. + VCHIQ_SET_SERVICE_OPTION_T args;
  36575. +
  36576. + if (copy_from_user(
  36577. + &args, (const void __user *)arg,
  36578. + sizeof(args)) != 0) {
  36579. + ret = -EFAULT;
  36580. + break;
  36581. + }
  36582. +
  36583. + service = find_service_for_instance(instance, args.handle);
  36584. + if (!service) {
  36585. + ret = -EINVAL;
  36586. + break;
  36587. + }
  36588. +
  36589. + status = vchiq_set_service_option(
  36590. + args.handle, args.option, args.value);
  36591. + } break;
  36592. +
  36593. + case VCHIQ_IOC_DUMP_PHYS_MEM: {
  36594. + VCHIQ_DUMP_MEM_T args;
  36595. +
  36596. + if (copy_from_user
  36597. + (&args, (const void __user *)arg,
  36598. + sizeof(args)) != 0) {
  36599. + ret = -EFAULT;
  36600. + break;
  36601. + }
  36602. + dump_phys_mem(args.virt_addr, args.num_bytes);
  36603. + } break;
  36604. +
  36605. + case VCHIQ_IOC_LIB_VERSION: {
  36606. + unsigned int lib_version = (unsigned int)arg;
  36607. +
  36608. + if (lib_version < VCHIQ_VERSION_MIN)
  36609. + ret = -EINVAL;
  36610. + else if (lib_version >= VCHIQ_VERSION_CLOSE_DELIVERED)
  36611. + instance->use_close_delivered = 1;
  36612. + } break;
  36613. +
  36614. + case VCHIQ_IOC_CLOSE_DELIVERED: {
  36615. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  36616. +
  36617. + service = find_closed_service_for_instance(instance, handle);
  36618. + if (service != NULL) {
  36619. + USER_SERVICE_T *user_service =
  36620. + (USER_SERVICE_T *)service->base.userdata;
  36621. + close_delivered(user_service);
  36622. + }
  36623. + else
  36624. + ret = -EINVAL;
  36625. + } break;
  36626. +
  36627. + default:
  36628. + ret = -ENOTTY;
  36629. + break;
  36630. + }
  36631. +
  36632. + if (service)
  36633. + unlock_service(service);
  36634. +
  36635. + if (ret == 0) {
  36636. + if (status == VCHIQ_ERROR)
  36637. + ret = -EIO;
  36638. + else if (status == VCHIQ_RETRY)
  36639. + ret = -EINTR;
  36640. + }
  36641. +
  36642. + if ((status == VCHIQ_SUCCESS) && (ret < 0) && (ret != -EINTR) &&
  36643. + (ret != -EWOULDBLOCK))
  36644. + vchiq_log_info(vchiq_arm_log_level,
  36645. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  36646. + (unsigned long)instance,
  36647. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  36648. + ioctl_names[_IOC_NR(cmd)] :
  36649. + "<invalid>",
  36650. + status, ret);
  36651. + else
  36652. + vchiq_log_trace(vchiq_arm_log_level,
  36653. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  36654. + (unsigned long)instance,
  36655. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  36656. + ioctl_names[_IOC_NR(cmd)] :
  36657. + "<invalid>",
  36658. + status, ret);
  36659. +
  36660. + return ret;
  36661. +}
  36662. +
  36663. +/****************************************************************************
  36664. +*
  36665. +* vchiq_open
  36666. +*
  36667. +***************************************************************************/
  36668. +
  36669. +static int
  36670. +vchiq_open(struct inode *inode, struct file *file)
  36671. +{
  36672. + int dev = iminor(inode) & 0x0f;
  36673. + vchiq_log_info(vchiq_arm_log_level, "vchiq_open");
  36674. + switch (dev) {
  36675. + case VCHIQ_MINOR: {
  36676. + int ret;
  36677. + VCHIQ_STATE_T *state = vchiq_get_state();
  36678. + VCHIQ_INSTANCE_T instance;
  36679. +
  36680. + if (!state) {
  36681. + vchiq_log_error(vchiq_arm_log_level,
  36682. + "vchiq has no connection to VideoCore");
  36683. + return -ENOTCONN;
  36684. + }
  36685. +
  36686. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  36687. + if (!instance)
  36688. + return -ENOMEM;
  36689. +
  36690. + instance->state = state;
  36691. + instance->pid = current->tgid;
  36692. +
  36693. + ret = vchiq_debugfs_add_instance(instance);
  36694. + if (ret != 0) {
  36695. + kfree(instance);
  36696. + return ret;
  36697. + }
  36698. +
  36699. + sema_init(&instance->insert_event, 0);
  36700. + sema_init(&instance->remove_event, 0);
  36701. + mutex_init(&instance->completion_mutex);
  36702. + mutex_init(&instance->bulk_waiter_list_mutex);
  36703. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  36704. +
  36705. + file->private_data = instance;
  36706. + } break;
  36707. +
  36708. + default:
  36709. + vchiq_log_error(vchiq_arm_log_level,
  36710. + "Unknown minor device: %d", dev);
  36711. + return -ENXIO;
  36712. + }
  36713. +
  36714. + return 0;
  36715. +}
  36716. +
  36717. +/****************************************************************************
  36718. +*
  36719. +* vchiq_release
  36720. +*
  36721. +***************************************************************************/
  36722. +
  36723. +static int
  36724. +vchiq_release(struct inode *inode, struct file *file)
  36725. +{
  36726. + int dev = iminor(inode) & 0x0f;
  36727. + int ret = 0;
  36728. + switch (dev) {
  36729. + case VCHIQ_MINOR: {
  36730. + VCHIQ_INSTANCE_T instance = file->private_data;
  36731. + VCHIQ_STATE_T *state = vchiq_get_state();
  36732. + VCHIQ_SERVICE_T *service;
  36733. + int i;
  36734. +
  36735. + vchiq_log_info(vchiq_arm_log_level,
  36736. + "vchiq_release: instance=%lx",
  36737. + (unsigned long)instance);
  36738. +
  36739. + if (!state) {
  36740. + ret = -EPERM;
  36741. + goto out;
  36742. + }
  36743. +
  36744. + /* Ensure videocore is awake to allow termination. */
  36745. + vchiq_use_internal(instance->state, NULL,
  36746. + USE_TYPE_VCHIQ);
  36747. +
  36748. + mutex_lock(&instance->completion_mutex);
  36749. +
  36750. + /* Wake the completion thread and ask it to exit */
  36751. + instance->closing = 1;
  36752. + up(&instance->insert_event);
  36753. +
  36754. + mutex_unlock(&instance->completion_mutex);
  36755. +
  36756. + /* Wake the slot handler if the completion queue is full. */
  36757. + up(&instance->remove_event);
  36758. +
  36759. + /* Mark all services for termination... */
  36760. + i = 0;
  36761. + while ((service = next_service_by_instance(state, instance,
  36762. + &i)) != NULL) {
  36763. + USER_SERVICE_T *user_service = service->base.userdata;
  36764. +
  36765. + /* Wake the slot handler if the msg queue is full. */
  36766. + up(&user_service->remove_event);
  36767. +
  36768. + vchiq_terminate_service_internal(service);
  36769. + unlock_service(service);
  36770. + }
  36771. +
  36772. + /* ...and wait for them to die */
  36773. + i = 0;
  36774. + while ((service = next_service_by_instance(state, instance, &i))
  36775. + != NULL) {
  36776. + USER_SERVICE_T *user_service = service->base.userdata;
  36777. +
  36778. + down(&service->remove_event);
  36779. +
  36780. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  36781. +
  36782. + spin_lock(&msg_queue_spinlock);
  36783. +
  36784. + while (user_service->msg_remove !=
  36785. + user_service->msg_insert) {
  36786. + VCHIQ_HEADER_T *header = user_service->
  36787. + msg_queue[user_service->msg_remove &
  36788. + (MSG_QUEUE_SIZE - 1)];
  36789. + user_service->msg_remove++;
  36790. + spin_unlock(&msg_queue_spinlock);
  36791. +
  36792. + if (header)
  36793. + vchiq_release_message(
  36794. + service->handle,
  36795. + header);
  36796. + spin_lock(&msg_queue_spinlock);
  36797. + }
  36798. +
  36799. + spin_unlock(&msg_queue_spinlock);
  36800. +
  36801. + unlock_service(service);
  36802. + }
  36803. +
  36804. + /* Release any closed services */
  36805. + while (instance->completion_remove !=
  36806. + instance->completion_insert) {
  36807. + VCHIQ_COMPLETION_DATA_T *completion;
  36808. + VCHIQ_SERVICE_T *service;
  36809. + completion = &instance->completions[
  36810. + instance->completion_remove &
  36811. + (MAX_COMPLETIONS - 1)];
  36812. + service = completion->service_userdata;
  36813. + if (completion->reason == VCHIQ_SERVICE_CLOSED)
  36814. + {
  36815. + USER_SERVICE_T *user_service =
  36816. + service->base.userdata;
  36817. +
  36818. + /* Wake any blocked user-thread */
  36819. + if (instance->use_close_delivered)
  36820. + up(&user_service->close_event);
  36821. + unlock_service(service);
  36822. + }
  36823. + instance->completion_remove++;
  36824. + }
  36825. +
  36826. + /* Release the PEER service count. */
  36827. + vchiq_release_internal(instance->state, NULL);
  36828. +
  36829. + {
  36830. + struct list_head *pos, *next;
  36831. + list_for_each_safe(pos, next,
  36832. + &instance->bulk_waiter_list) {
  36833. + struct bulk_waiter_node *waiter;
  36834. + waiter = list_entry(pos,
  36835. + struct bulk_waiter_node,
  36836. + list);
  36837. + list_del(pos);
  36838. + vchiq_log_info(vchiq_arm_log_level,
  36839. + "bulk_waiter - cleaned up %x "
  36840. + "for pid %d",
  36841. + (unsigned int)waiter, waiter->pid);
  36842. + kfree(waiter);
  36843. + }
  36844. + }
  36845. +
  36846. + vchiq_debugfs_remove_instance(instance);
  36847. +
  36848. + kfree(instance);
  36849. + file->private_data = NULL;
  36850. + } break;
  36851. +
  36852. + default:
  36853. + vchiq_log_error(vchiq_arm_log_level,
  36854. + "Unknown minor device: %d", dev);
  36855. + ret = -ENXIO;
  36856. + }
  36857. +
  36858. +out:
  36859. + return ret;
  36860. +}
  36861. +
  36862. +/****************************************************************************
  36863. +*
  36864. +* vchiq_dump
  36865. +*
  36866. +***************************************************************************/
  36867. +
  36868. +void
  36869. +vchiq_dump(void *dump_context, const char *str, int len)
  36870. +{
  36871. + DUMP_CONTEXT_T *context = (DUMP_CONTEXT_T *)dump_context;
  36872. +
  36873. + if (context->actual < context->space) {
  36874. + int copy_bytes;
  36875. + if (context->offset > 0) {
  36876. + int skip_bytes = min(len, (int)context->offset);
  36877. + str += skip_bytes;
  36878. + len -= skip_bytes;
  36879. + context->offset -= skip_bytes;
  36880. + if (context->offset > 0)
  36881. + return;
  36882. + }
  36883. + copy_bytes = min(len, (int)(context->space - context->actual));
  36884. + if (copy_bytes == 0)
  36885. + return;
  36886. + if (copy_to_user(context->buf + context->actual, str,
  36887. + copy_bytes))
  36888. + context->actual = -EFAULT;
  36889. + context->actual += copy_bytes;
  36890. + len -= copy_bytes;
  36891. +
  36892. + /* If tne terminating NUL is included in the length, then it
  36893. + ** marks the end of a line and should be replaced with a
  36894. + ** carriage return. */
  36895. + if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
  36896. + char cr = '\n';
  36897. + if (copy_to_user(context->buf + context->actual - 1,
  36898. + &cr, 1))
  36899. + context->actual = -EFAULT;
  36900. + }
  36901. + }
  36902. +}
  36903. +
  36904. +/****************************************************************************
  36905. +*
  36906. +* vchiq_dump_platform_instance_state
  36907. +*
  36908. +***************************************************************************/
  36909. +
  36910. +void
  36911. +vchiq_dump_platform_instances(void *dump_context)
  36912. +{
  36913. + VCHIQ_STATE_T *state = vchiq_get_state();
  36914. + char buf[80];
  36915. + int len;
  36916. + int i;
  36917. +
  36918. + /* There is no list of instances, so instead scan all services,
  36919. + marking those that have been dumped. */
  36920. +
  36921. + for (i = 0; i < state->unused_service; i++) {
  36922. + VCHIQ_SERVICE_T *service = state->services[i];
  36923. + VCHIQ_INSTANCE_T instance;
  36924. +
  36925. + if (service && (service->base.callback == service_callback)) {
  36926. + instance = service->instance;
  36927. + if (instance)
  36928. + instance->mark = 0;
  36929. + }
  36930. + }
  36931. +
  36932. + for (i = 0; i < state->unused_service; i++) {
  36933. + VCHIQ_SERVICE_T *service = state->services[i];
  36934. + VCHIQ_INSTANCE_T instance;
  36935. +
  36936. + if (service && (service->base.callback == service_callback)) {
  36937. + instance = service->instance;
  36938. + if (instance && !instance->mark) {
  36939. + len = snprintf(buf, sizeof(buf),
  36940. + "Instance %x: pid %d,%s completions "
  36941. + "%d/%d",
  36942. + (unsigned int)instance, instance->pid,
  36943. + instance->connected ? " connected, " :
  36944. + "",
  36945. + instance->completion_insert -
  36946. + instance->completion_remove,
  36947. + MAX_COMPLETIONS);
  36948. +
  36949. + vchiq_dump(dump_context, buf, len + 1);
  36950. +
  36951. + instance->mark = 1;
  36952. + }
  36953. + }
  36954. + }
  36955. +}
  36956. +
  36957. +/****************************************************************************
  36958. +*
  36959. +* vchiq_dump_platform_service_state
  36960. +*
  36961. +***************************************************************************/
  36962. +
  36963. +void
  36964. +vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  36965. +{
  36966. + USER_SERVICE_T *user_service = (USER_SERVICE_T *)service->base.userdata;
  36967. + char buf[80];
  36968. + int len;
  36969. +
  36970. + len = snprintf(buf, sizeof(buf), " instance %x",
  36971. + (unsigned int)service->instance);
  36972. +
  36973. + if ((service->base.callback == service_callback) &&
  36974. + user_service->is_vchi) {
  36975. + len += snprintf(buf + len, sizeof(buf) - len,
  36976. + ", %d/%d messages",
  36977. + user_service->msg_insert - user_service->msg_remove,
  36978. + MSG_QUEUE_SIZE);
  36979. +
  36980. + if (user_service->dequeue_pending)
  36981. + len += snprintf(buf + len, sizeof(buf) - len,
  36982. + " (dequeue pending)");
  36983. + }
  36984. +
  36985. + vchiq_dump(dump_context, buf, len + 1);
  36986. +}
  36987. +
  36988. +/****************************************************************************
  36989. +*
  36990. +* dump_user_mem
  36991. +*
  36992. +***************************************************************************/
  36993. +
  36994. +static void
  36995. +dump_phys_mem(void *virt_addr, uint32_t num_bytes)
  36996. +{
  36997. + int rc;
  36998. + uint8_t *end_virt_addr = virt_addr + num_bytes;
  36999. + int num_pages;
  37000. + int offset;
  37001. + int end_offset;
  37002. + int page_idx;
  37003. + int prev_idx;
  37004. + struct page *page;
  37005. + struct page **pages;
  37006. + uint8_t *kmapped_virt_ptr;
  37007. +
  37008. + /* Align virtAddr and endVirtAddr to 16 byte boundaries. */
  37009. +
  37010. + virt_addr = (void *)((unsigned long)virt_addr & ~0x0fuL);
  37011. + end_virt_addr = (void *)(((unsigned long)end_virt_addr + 15uL) &
  37012. + ~0x0fuL);
  37013. +
  37014. + offset = (int)(long)virt_addr & (PAGE_SIZE - 1);
  37015. + end_offset = (int)(long)end_virt_addr & (PAGE_SIZE - 1);
  37016. +
  37017. + num_pages = (offset + num_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
  37018. +
  37019. + pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
  37020. + if (pages == NULL) {
  37021. + vchiq_log_error(vchiq_arm_log_level,
  37022. + "Unable to allocation memory for %d pages\n",
  37023. + num_pages);
  37024. + return;
  37025. + }
  37026. +
  37027. + down_read(&current->mm->mmap_sem);
  37028. + rc = get_user_pages(current, /* task */
  37029. + current->mm, /* mm */
  37030. + (unsigned long)virt_addr, /* start */
  37031. + num_pages, /* len */
  37032. + 0, /* write */
  37033. + 0, /* force */
  37034. + pages, /* pages (array of page pointers) */
  37035. + NULL); /* vmas */
  37036. + up_read(&current->mm->mmap_sem);
  37037. +
  37038. + prev_idx = -1;
  37039. + page = NULL;
  37040. +
  37041. + while (offset < end_offset) {
  37042. +
  37043. + int page_offset = offset % PAGE_SIZE;
  37044. + page_idx = offset / PAGE_SIZE;
  37045. +
  37046. + if (page_idx != prev_idx) {
  37047. +
  37048. + if (page != NULL)
  37049. + kunmap(page);
  37050. + page = pages[page_idx];
  37051. + kmapped_virt_ptr = kmap(page);
  37052. +
  37053. + prev_idx = page_idx;
  37054. + }
  37055. +
  37056. + if (vchiq_arm_log_level >= VCHIQ_LOG_TRACE)
  37057. + vchiq_log_dump_mem("ph",
  37058. + (uint32_t)(unsigned long)&kmapped_virt_ptr[
  37059. + page_offset],
  37060. + &kmapped_virt_ptr[page_offset], 16);
  37061. +
  37062. + offset += 16;
  37063. + }
  37064. + if (page != NULL)
  37065. + kunmap(page);
  37066. +
  37067. + for (page_idx = 0; page_idx < num_pages; page_idx++)
  37068. + page_cache_release(pages[page_idx]);
  37069. +
  37070. + kfree(pages);
  37071. +}
  37072. +
  37073. +/****************************************************************************
  37074. +*
  37075. +* vchiq_read
  37076. +*
  37077. +***************************************************************************/
  37078. +
  37079. +static ssize_t
  37080. +vchiq_read(struct file *file, char __user *buf,
  37081. + size_t count, loff_t *ppos)
  37082. +{
  37083. + DUMP_CONTEXT_T context;
  37084. + context.buf = buf;
  37085. + context.actual = 0;
  37086. + context.space = count;
  37087. + context.offset = *ppos;
  37088. +
  37089. + vchiq_dump_state(&context, &g_state);
  37090. +
  37091. + *ppos += context.actual;
  37092. +
  37093. + return context.actual;
  37094. +}
  37095. +
  37096. +VCHIQ_STATE_T *
  37097. +vchiq_get_state(void)
  37098. +{
  37099. +
  37100. + if (g_state.remote == NULL)
  37101. + printk(KERN_ERR "%s: g_state.remote == NULL\n", __func__);
  37102. + else if (g_state.remote->initialised != 1)
  37103. + printk(KERN_NOTICE "%s: g_state.remote->initialised != 1 (%d)\n",
  37104. + __func__, g_state.remote->initialised);
  37105. +
  37106. + return ((g_state.remote != NULL) &&
  37107. + (g_state.remote->initialised == 1)) ? &g_state : NULL;
  37108. +}
  37109. +
  37110. +static const struct file_operations
  37111. +vchiq_fops = {
  37112. + .owner = THIS_MODULE,
  37113. + .unlocked_ioctl = vchiq_ioctl,
  37114. + .open = vchiq_open,
  37115. + .release = vchiq_release,
  37116. + .read = vchiq_read
  37117. +};
  37118. +
  37119. +/*
  37120. + * Autosuspend related functionality
  37121. + */
  37122. +
  37123. +int
  37124. +vchiq_videocore_wanted(VCHIQ_STATE_T *state)
  37125. +{
  37126. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37127. + if (!arm_state)
  37128. + /* autosuspend not supported - always return wanted */
  37129. + return 1;
  37130. + else if (arm_state->blocked_count)
  37131. + return 1;
  37132. + else if (!arm_state->videocore_use_count)
  37133. + /* usage count zero - check for override unless we're forcing */
  37134. + if (arm_state->resume_blocked)
  37135. + return 0;
  37136. + else
  37137. + return vchiq_platform_videocore_wanted(state);
  37138. + else
  37139. + /* non-zero usage count - videocore still required */
  37140. + return 1;
  37141. +}
  37142. +
  37143. +static VCHIQ_STATUS_T
  37144. +vchiq_keepalive_vchiq_callback(VCHIQ_REASON_T reason,
  37145. + VCHIQ_HEADER_T *header,
  37146. + VCHIQ_SERVICE_HANDLE_T service_user,
  37147. + void *bulk_user)
  37148. +{
  37149. + vchiq_log_error(vchiq_susp_log_level,
  37150. + "%s callback reason %d", __func__, reason);
  37151. + return 0;
  37152. +}
  37153. +
  37154. +static int
  37155. +vchiq_keepalive_thread_func(void *v)
  37156. +{
  37157. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  37158. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37159. +
  37160. + VCHIQ_STATUS_T status;
  37161. + VCHIQ_INSTANCE_T instance;
  37162. + VCHIQ_SERVICE_HANDLE_T ka_handle;
  37163. +
  37164. + VCHIQ_SERVICE_PARAMS_T params = {
  37165. + .fourcc = VCHIQ_MAKE_FOURCC('K', 'E', 'E', 'P'),
  37166. + .callback = vchiq_keepalive_vchiq_callback,
  37167. + .version = KEEPALIVE_VER,
  37168. + .version_min = KEEPALIVE_VER_MIN
  37169. + };
  37170. +
  37171. + status = vchiq_initialise(&instance);
  37172. + if (status != VCHIQ_SUCCESS) {
  37173. + vchiq_log_error(vchiq_susp_log_level,
  37174. + "%s vchiq_initialise failed %d", __func__, status);
  37175. + goto exit;
  37176. + }
  37177. +
  37178. + status = vchiq_connect(instance);
  37179. + if (status != VCHIQ_SUCCESS) {
  37180. + vchiq_log_error(vchiq_susp_log_level,
  37181. + "%s vchiq_connect failed %d", __func__, status);
  37182. + goto shutdown;
  37183. + }
  37184. +
  37185. + status = vchiq_add_service(instance, &params, &ka_handle);
  37186. + if (status != VCHIQ_SUCCESS) {
  37187. + vchiq_log_error(vchiq_susp_log_level,
  37188. + "%s vchiq_open_service failed %d", __func__, status);
  37189. + goto shutdown;
  37190. + }
  37191. +
  37192. + while (1) {
  37193. + long rc = 0, uc = 0;
  37194. + if (wait_for_completion_interruptible(&arm_state->ka_evt)
  37195. + != 0) {
  37196. + vchiq_log_error(vchiq_susp_log_level,
  37197. + "%s interrupted", __func__);
  37198. + flush_signals(current);
  37199. + continue;
  37200. + }
  37201. +
  37202. + /* read and clear counters. Do release_count then use_count to
  37203. + * prevent getting more releases than uses */
  37204. + rc = atomic_xchg(&arm_state->ka_release_count, 0);
  37205. + uc = atomic_xchg(&arm_state->ka_use_count, 0);
  37206. +
  37207. + /* Call use/release service the requisite number of times.
  37208. + * Process use before release so use counts don't go negative */
  37209. + while (uc--) {
  37210. + atomic_inc(&arm_state->ka_use_ack_count);
  37211. + status = vchiq_use_service(ka_handle);
  37212. + if (status != VCHIQ_SUCCESS) {
  37213. + vchiq_log_error(vchiq_susp_log_level,
  37214. + "%s vchiq_use_service error %d",
  37215. + __func__, status);
  37216. + }
  37217. + }
  37218. + while (rc--) {
  37219. + status = vchiq_release_service(ka_handle);
  37220. + if (status != VCHIQ_SUCCESS) {
  37221. + vchiq_log_error(vchiq_susp_log_level,
  37222. + "%s vchiq_release_service error %d",
  37223. + __func__, status);
  37224. + }
  37225. + }
  37226. + }
  37227. +
  37228. +shutdown:
  37229. + vchiq_shutdown(instance);
  37230. +exit:
  37231. + return 0;
  37232. +}
  37233. +
  37234. +
  37235. +
  37236. +VCHIQ_STATUS_T
  37237. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state)
  37238. +{
  37239. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  37240. +
  37241. + if (arm_state) {
  37242. + rwlock_init(&arm_state->susp_res_lock);
  37243. +
  37244. + init_completion(&arm_state->ka_evt);
  37245. + atomic_set(&arm_state->ka_use_count, 0);
  37246. + atomic_set(&arm_state->ka_use_ack_count, 0);
  37247. + atomic_set(&arm_state->ka_release_count, 0);
  37248. +
  37249. + init_completion(&arm_state->vc_suspend_complete);
  37250. +
  37251. + init_completion(&arm_state->vc_resume_complete);
  37252. + /* Initialise to 'done' state. We only want to block on resume
  37253. + * completion while videocore is suspended. */
  37254. + set_resume_state(arm_state, VC_RESUME_RESUMED);
  37255. +
  37256. + init_completion(&arm_state->resume_blocker);
  37257. + /* Initialise to 'done' state. We only want to block on this
  37258. + * completion while resume is blocked */
  37259. + complete_all(&arm_state->resume_blocker);
  37260. +
  37261. + init_completion(&arm_state->blocked_blocker);
  37262. + /* Initialise to 'done' state. We only want to block on this
  37263. + * completion while things are waiting on the resume blocker */
  37264. + complete_all(&arm_state->blocked_blocker);
  37265. +
  37266. + arm_state->suspend_timer_timeout = SUSPEND_TIMER_TIMEOUT_MS;
  37267. + arm_state->suspend_timer_running = 0;
  37268. + init_timer(&arm_state->suspend_timer);
  37269. + arm_state->suspend_timer.data = (unsigned long)(state);
  37270. + arm_state->suspend_timer.function = suspend_timer_callback;
  37271. +
  37272. + arm_state->first_connect = 0;
  37273. +
  37274. + }
  37275. + return status;
  37276. +}
  37277. +
  37278. +/*
  37279. +** Functions to modify the state variables;
  37280. +** set_suspend_state
  37281. +** set_resume_state
  37282. +**
  37283. +** There are more state variables than we might like, so ensure they remain in
  37284. +** step. Suspend and resume state are maintained separately, since most of
  37285. +** these state machines can operate independently. However, there are a few
  37286. +** states where state transitions in one state machine cause a reset to the
  37287. +** other state machine. In addition, there are some completion events which
  37288. +** need to occur on state machine reset and end-state(s), so these are also
  37289. +** dealt with in these functions.
  37290. +**
  37291. +** In all states we set the state variable according to the input, but in some
  37292. +** cases we perform additional steps outlined below;
  37293. +**
  37294. +** VC_SUSPEND_IDLE - Initialise the suspend completion at the same time.
  37295. +** The suspend completion is completed after any suspend
  37296. +** attempt. When we reset the state machine we also reset
  37297. +** the completion. This reset occurs when videocore is
  37298. +** resumed, and also if we initiate suspend after a suspend
  37299. +** failure.
  37300. +**
  37301. +** VC_SUSPEND_IN_PROGRESS - This state is considered the point of no return for
  37302. +** suspend - ie from this point on we must try to suspend
  37303. +** before resuming can occur. We therefore also reset the
  37304. +** resume state machine to VC_RESUME_IDLE in this state.
  37305. +**
  37306. +** VC_SUSPEND_SUSPENDED - Suspend has completed successfully. Also call
  37307. +** complete_all on the suspend completion to notify
  37308. +** anything waiting for suspend to happen.
  37309. +**
  37310. +** VC_SUSPEND_REJECTED - Videocore rejected suspend. Videocore will also
  37311. +** initiate resume, so no need to alter resume state.
  37312. +** We call complete_all on the suspend completion to notify
  37313. +** of suspend rejection.
  37314. +**
  37315. +** VC_SUSPEND_FAILED - We failed to initiate videocore suspend. We notify the
  37316. +** suspend completion and reset the resume state machine.
  37317. +**
  37318. +** VC_RESUME_IDLE - Initialise the resume completion at the same time. The
  37319. +** resume completion is in it's 'done' state whenever
  37320. +** videcore is running. Therfore, the VC_RESUME_IDLE state
  37321. +** implies that videocore is suspended.
  37322. +** Hence, any thread which needs to wait until videocore is
  37323. +** running can wait on this completion - it will only block
  37324. +** if videocore is suspended.
  37325. +**
  37326. +** VC_RESUME_RESUMED - Resume has completed successfully. Videocore is running.
  37327. +** Call complete_all on the resume completion to unblock
  37328. +** any threads waiting for resume. Also reset the suspend
  37329. +** state machine to it's idle state.
  37330. +**
  37331. +** VC_RESUME_FAILED - Currently unused - no mechanism to fail resume exists.
  37332. +*/
  37333. +
  37334. +inline void
  37335. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  37336. + enum vc_suspend_status new_state)
  37337. +{
  37338. + /* set the state in all cases */
  37339. + arm_state->vc_suspend_state = new_state;
  37340. +
  37341. + /* state specific additional actions */
  37342. + switch (new_state) {
  37343. + case VC_SUSPEND_FORCE_CANCELED:
  37344. + complete_all(&arm_state->vc_suspend_complete);
  37345. + break;
  37346. + case VC_SUSPEND_REJECTED:
  37347. + complete_all(&arm_state->vc_suspend_complete);
  37348. + break;
  37349. + case VC_SUSPEND_FAILED:
  37350. + complete_all(&arm_state->vc_suspend_complete);
  37351. + arm_state->vc_resume_state = VC_RESUME_RESUMED;
  37352. + complete_all(&arm_state->vc_resume_complete);
  37353. + break;
  37354. + case VC_SUSPEND_IDLE:
  37355. + reinit_completion(&arm_state->vc_suspend_complete);
  37356. + break;
  37357. + case VC_SUSPEND_REQUESTED:
  37358. + break;
  37359. + case VC_SUSPEND_IN_PROGRESS:
  37360. + set_resume_state(arm_state, VC_RESUME_IDLE);
  37361. + break;
  37362. + case VC_SUSPEND_SUSPENDED:
  37363. + complete_all(&arm_state->vc_suspend_complete);
  37364. + break;
  37365. + default:
  37366. + BUG();
  37367. + break;
  37368. + }
  37369. +}
  37370. +
  37371. +inline void
  37372. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  37373. + enum vc_resume_status new_state)
  37374. +{
  37375. + /* set the state in all cases */
  37376. + arm_state->vc_resume_state = new_state;
  37377. +
  37378. + /* state specific additional actions */
  37379. + switch (new_state) {
  37380. + case VC_RESUME_FAILED:
  37381. + break;
  37382. + case VC_RESUME_IDLE:
  37383. + reinit_completion(&arm_state->vc_resume_complete);
  37384. + break;
  37385. + case VC_RESUME_REQUESTED:
  37386. + break;
  37387. + case VC_RESUME_IN_PROGRESS:
  37388. + break;
  37389. + case VC_RESUME_RESUMED:
  37390. + complete_all(&arm_state->vc_resume_complete);
  37391. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  37392. + break;
  37393. + default:
  37394. + BUG();
  37395. + break;
  37396. + }
  37397. +}
  37398. +
  37399. +
  37400. +/* should be called with the write lock held */
  37401. +inline void
  37402. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  37403. +{
  37404. + del_timer(&arm_state->suspend_timer);
  37405. + arm_state->suspend_timer.expires = jiffies +
  37406. + msecs_to_jiffies(arm_state->
  37407. + suspend_timer_timeout);
  37408. + add_timer(&arm_state->suspend_timer);
  37409. + arm_state->suspend_timer_running = 1;
  37410. +}
  37411. +
  37412. +/* should be called with the write lock held */
  37413. +static inline void
  37414. +stop_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  37415. +{
  37416. + if (arm_state->suspend_timer_running) {
  37417. + del_timer(&arm_state->suspend_timer);
  37418. + arm_state->suspend_timer_running = 0;
  37419. + }
  37420. +}
  37421. +
  37422. +static inline int
  37423. +need_resume(VCHIQ_STATE_T *state)
  37424. +{
  37425. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37426. + return (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) &&
  37427. + (arm_state->vc_resume_state < VC_RESUME_REQUESTED) &&
  37428. + vchiq_videocore_wanted(state);
  37429. +}
  37430. +
  37431. +static int
  37432. +block_resume(VCHIQ_ARM_STATE_T *arm_state)
  37433. +{
  37434. + int status = VCHIQ_SUCCESS;
  37435. + const unsigned long timeout_val =
  37436. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS);
  37437. + int resume_count = 0;
  37438. +
  37439. + /* Allow any threads which were blocked by the last force suspend to
  37440. + * complete if they haven't already. Only give this one shot; if
  37441. + * blocked_count is incremented after blocked_blocker is completed
  37442. + * (which only happens when blocked_count hits 0) then those threads
  37443. + * will have to wait until next time around */
  37444. + if (arm_state->blocked_count) {
  37445. + reinit_completion(&arm_state->blocked_blocker);
  37446. + write_unlock_bh(&arm_state->susp_res_lock);
  37447. + vchiq_log_info(vchiq_susp_log_level, "%s wait for previously "
  37448. + "blocked clients", __func__);
  37449. + if (wait_for_completion_interruptible_timeout(
  37450. + &arm_state->blocked_blocker, timeout_val)
  37451. + <= 0) {
  37452. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  37453. + "previously blocked clients failed" , __func__);
  37454. + status = VCHIQ_ERROR;
  37455. + write_lock_bh(&arm_state->susp_res_lock);
  37456. + goto out;
  37457. + }
  37458. + vchiq_log_info(vchiq_susp_log_level, "%s previously blocked "
  37459. + "clients resumed", __func__);
  37460. + write_lock_bh(&arm_state->susp_res_lock);
  37461. + }
  37462. +
  37463. + /* We need to wait for resume to complete if it's in process */
  37464. + while (arm_state->vc_resume_state != VC_RESUME_RESUMED &&
  37465. + arm_state->vc_resume_state > VC_RESUME_IDLE) {
  37466. + if (resume_count > 1) {
  37467. + status = VCHIQ_ERROR;
  37468. + vchiq_log_error(vchiq_susp_log_level, "%s waited too "
  37469. + "many times for resume" , __func__);
  37470. + goto out;
  37471. + }
  37472. + write_unlock_bh(&arm_state->susp_res_lock);
  37473. + vchiq_log_info(vchiq_susp_log_level, "%s wait for resume",
  37474. + __func__);
  37475. + if (wait_for_completion_interruptible_timeout(
  37476. + &arm_state->vc_resume_complete, timeout_val)
  37477. + <= 0) {
  37478. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  37479. + "resume failed (%s)", __func__,
  37480. + resume_state_names[arm_state->vc_resume_state +
  37481. + VC_RESUME_NUM_OFFSET]);
  37482. + status = VCHIQ_ERROR;
  37483. + write_lock_bh(&arm_state->susp_res_lock);
  37484. + goto out;
  37485. + }
  37486. + vchiq_log_info(vchiq_susp_log_level, "%s resumed", __func__);
  37487. + write_lock_bh(&arm_state->susp_res_lock);
  37488. + resume_count++;
  37489. + }
  37490. + reinit_completion(&arm_state->resume_blocker);
  37491. + arm_state->resume_blocked = 1;
  37492. +
  37493. +out:
  37494. + return status;
  37495. +}
  37496. +
  37497. +static inline void
  37498. +unblock_resume(VCHIQ_ARM_STATE_T *arm_state)
  37499. +{
  37500. + complete_all(&arm_state->resume_blocker);
  37501. + arm_state->resume_blocked = 0;
  37502. +}
  37503. +
  37504. +/* Initiate suspend via slot handler. Should be called with the write lock
  37505. + * held */
  37506. +VCHIQ_STATUS_T
  37507. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state)
  37508. +{
  37509. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  37510. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37511. +
  37512. + if (!arm_state)
  37513. + goto out;
  37514. +
  37515. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37516. + status = VCHIQ_SUCCESS;
  37517. +
  37518. +
  37519. + switch (arm_state->vc_suspend_state) {
  37520. + case VC_SUSPEND_REQUESTED:
  37521. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already "
  37522. + "requested", __func__);
  37523. + break;
  37524. + case VC_SUSPEND_IN_PROGRESS:
  37525. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already in "
  37526. + "progress", __func__);
  37527. + break;
  37528. +
  37529. + default:
  37530. + /* We don't expect to be in other states, so log but continue
  37531. + * anyway */
  37532. + vchiq_log_error(vchiq_susp_log_level,
  37533. + "%s unexpected suspend state %s", __func__,
  37534. + suspend_state_names[arm_state->vc_suspend_state +
  37535. + VC_SUSPEND_NUM_OFFSET]);
  37536. + /* fall through */
  37537. + case VC_SUSPEND_REJECTED:
  37538. + case VC_SUSPEND_FAILED:
  37539. + /* Ensure any idle state actions have been run */
  37540. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  37541. + /* fall through */
  37542. + case VC_SUSPEND_IDLE:
  37543. + vchiq_log_info(vchiq_susp_log_level,
  37544. + "%s: suspending", __func__);
  37545. + set_suspend_state(arm_state, VC_SUSPEND_REQUESTED);
  37546. + /* kick the slot handler thread to initiate suspend */
  37547. + request_poll(state, NULL, 0);
  37548. + break;
  37549. + }
  37550. +
  37551. +out:
  37552. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  37553. + return status;
  37554. +}
  37555. +
  37556. +void
  37557. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state)
  37558. +{
  37559. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37560. + int susp = 0;
  37561. +
  37562. + if (!arm_state)
  37563. + goto out;
  37564. +
  37565. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37566. +
  37567. + write_lock_bh(&arm_state->susp_res_lock);
  37568. + if (arm_state->vc_suspend_state == VC_SUSPEND_REQUESTED &&
  37569. + arm_state->vc_resume_state == VC_RESUME_RESUMED) {
  37570. + set_suspend_state(arm_state, VC_SUSPEND_IN_PROGRESS);
  37571. + susp = 1;
  37572. + }
  37573. + write_unlock_bh(&arm_state->susp_res_lock);
  37574. +
  37575. + if (susp)
  37576. + vchiq_platform_suspend(state);
  37577. +
  37578. +out:
  37579. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  37580. + return;
  37581. +}
  37582. +
  37583. +
  37584. +static void
  37585. +output_timeout_error(VCHIQ_STATE_T *state)
  37586. +{
  37587. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37588. + char service_err[50] = "";
  37589. + int vc_use_count = arm_state->videocore_use_count;
  37590. + int active_services = state->unused_service;
  37591. + int i;
  37592. +
  37593. + if (!arm_state->videocore_use_count) {
  37594. + snprintf(service_err, 50, " Videocore usecount is 0");
  37595. + goto output_msg;
  37596. + }
  37597. + for (i = 0; i < active_services; i++) {
  37598. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  37599. + if (service_ptr && service_ptr->service_use_count &&
  37600. + (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE)) {
  37601. + snprintf(service_err, 50, " %c%c%c%c(%d) service has "
  37602. + "use count %d%s", VCHIQ_FOURCC_AS_4CHARS(
  37603. + service_ptr->base.fourcc),
  37604. + service_ptr->client_id,
  37605. + service_ptr->service_use_count,
  37606. + service_ptr->service_use_count ==
  37607. + vc_use_count ? "" : " (+ more)");
  37608. + break;
  37609. + }
  37610. + }
  37611. +
  37612. +output_msg:
  37613. + vchiq_log_error(vchiq_susp_log_level,
  37614. + "timed out waiting for vc suspend (%d).%s",
  37615. + arm_state->autosuspend_override, service_err);
  37616. +
  37617. +}
  37618. +
  37619. +/* Try to get videocore into suspended state, regardless of autosuspend state.
  37620. +** We don't actually force suspend, since videocore may get into a bad state
  37621. +** if we force suspend at a bad time. Instead, we wait for autosuspend to
  37622. +** determine a good point to suspend. If this doesn't happen within 100ms we
  37623. +** report failure.
  37624. +**
  37625. +** Returns VCHIQ_SUCCESS if videocore suspended successfully, VCHIQ_RETRY if
  37626. +** videocore failed to suspend in time or VCHIQ_ERROR if interrupted.
  37627. +*/
  37628. +VCHIQ_STATUS_T
  37629. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state)
  37630. +{
  37631. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37632. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  37633. + long rc = 0;
  37634. + int repeat = -1;
  37635. +
  37636. + if (!arm_state)
  37637. + goto out;
  37638. +
  37639. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37640. +
  37641. + write_lock_bh(&arm_state->susp_res_lock);
  37642. +
  37643. + status = block_resume(arm_state);
  37644. + if (status != VCHIQ_SUCCESS)
  37645. + goto unlock;
  37646. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  37647. + /* Already suspended - just block resume and exit */
  37648. + vchiq_log_info(vchiq_susp_log_level, "%s already suspended",
  37649. + __func__);
  37650. + status = VCHIQ_SUCCESS;
  37651. + goto unlock;
  37652. + } else if (arm_state->vc_suspend_state <= VC_SUSPEND_IDLE) {
  37653. + /* initiate suspend immediately in the case that we're waiting
  37654. + * for the timeout */
  37655. + stop_suspend_timer(arm_state);
  37656. + if (!vchiq_videocore_wanted(state)) {
  37657. + vchiq_log_info(vchiq_susp_log_level, "%s videocore "
  37658. + "idle, initiating suspend", __func__);
  37659. + status = vchiq_arm_vcsuspend(state);
  37660. + } else if (arm_state->autosuspend_override <
  37661. + FORCE_SUSPEND_FAIL_MAX) {
  37662. + vchiq_log_info(vchiq_susp_log_level, "%s letting "
  37663. + "videocore go idle", __func__);
  37664. + status = VCHIQ_SUCCESS;
  37665. + } else {
  37666. + vchiq_log_warning(vchiq_susp_log_level, "%s failed too "
  37667. + "many times - attempting suspend", __func__);
  37668. + status = vchiq_arm_vcsuspend(state);
  37669. + }
  37670. + } else {
  37671. + vchiq_log_info(vchiq_susp_log_level, "%s videocore suspend "
  37672. + "in progress - wait for completion", __func__);
  37673. + status = VCHIQ_SUCCESS;
  37674. + }
  37675. +
  37676. + /* Wait for suspend to happen due to system idle (not forced..) */
  37677. + if (status != VCHIQ_SUCCESS)
  37678. + goto unblock_resume;
  37679. +
  37680. + do {
  37681. + write_unlock_bh(&arm_state->susp_res_lock);
  37682. +
  37683. + rc = wait_for_completion_interruptible_timeout(
  37684. + &arm_state->vc_suspend_complete,
  37685. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS));
  37686. +
  37687. + write_lock_bh(&arm_state->susp_res_lock);
  37688. + if (rc < 0) {
  37689. + vchiq_log_warning(vchiq_susp_log_level, "%s "
  37690. + "interrupted waiting for suspend", __func__);
  37691. + status = VCHIQ_ERROR;
  37692. + goto unblock_resume;
  37693. + } else if (rc == 0) {
  37694. + if (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) {
  37695. + /* Repeat timeout once if in progress */
  37696. + if (repeat < 0) {
  37697. + repeat = 1;
  37698. + continue;
  37699. + }
  37700. + }
  37701. + arm_state->autosuspend_override++;
  37702. + output_timeout_error(state);
  37703. +
  37704. + status = VCHIQ_RETRY;
  37705. + goto unblock_resume;
  37706. + }
  37707. + } while (0 < (repeat--));
  37708. +
  37709. + /* Check and report state in case we need to abort ARM suspend */
  37710. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED) {
  37711. + status = VCHIQ_RETRY;
  37712. + vchiq_log_error(vchiq_susp_log_level,
  37713. + "%s videocore suspend failed (state %s)", __func__,
  37714. + suspend_state_names[arm_state->vc_suspend_state +
  37715. + VC_SUSPEND_NUM_OFFSET]);
  37716. + /* Reset the state only if it's still in an error state.
  37717. + * Something could have already initiated another suspend. */
  37718. + if (arm_state->vc_suspend_state < VC_SUSPEND_IDLE)
  37719. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  37720. +
  37721. + goto unblock_resume;
  37722. + }
  37723. +
  37724. + /* successfully suspended - unlock and exit */
  37725. + goto unlock;
  37726. +
  37727. +unblock_resume:
  37728. + /* all error states need to unblock resume before exit */
  37729. + unblock_resume(arm_state);
  37730. +
  37731. +unlock:
  37732. + write_unlock_bh(&arm_state->susp_res_lock);
  37733. +
  37734. +out:
  37735. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  37736. + return status;
  37737. +}
  37738. +
  37739. +void
  37740. +vchiq_check_suspend(VCHIQ_STATE_T *state)
  37741. +{
  37742. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37743. +
  37744. + if (!arm_state)
  37745. + goto out;
  37746. +
  37747. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37748. +
  37749. + write_lock_bh(&arm_state->susp_res_lock);
  37750. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED &&
  37751. + arm_state->first_connect &&
  37752. + !vchiq_videocore_wanted(state)) {
  37753. + vchiq_arm_vcsuspend(state);
  37754. + }
  37755. + write_unlock_bh(&arm_state->susp_res_lock);
  37756. +
  37757. +out:
  37758. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  37759. + return;
  37760. +}
  37761. +
  37762. +
  37763. +int
  37764. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state)
  37765. +{
  37766. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37767. + int resume = 0;
  37768. + int ret = -1;
  37769. +
  37770. + if (!arm_state)
  37771. + goto out;
  37772. +
  37773. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37774. +
  37775. + write_lock_bh(&arm_state->susp_res_lock);
  37776. + unblock_resume(arm_state);
  37777. + resume = vchiq_check_resume(state);
  37778. + write_unlock_bh(&arm_state->susp_res_lock);
  37779. +
  37780. + if (resume) {
  37781. + if (wait_for_completion_interruptible(
  37782. + &arm_state->vc_resume_complete) < 0) {
  37783. + vchiq_log_error(vchiq_susp_log_level,
  37784. + "%s interrupted", __func__);
  37785. + /* failed, cannot accurately derive suspend
  37786. + * state, so exit early. */
  37787. + goto out;
  37788. + }
  37789. + }
  37790. +
  37791. + read_lock_bh(&arm_state->susp_res_lock);
  37792. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  37793. + vchiq_log_info(vchiq_susp_log_level,
  37794. + "%s: Videocore remains suspended", __func__);
  37795. + } else {
  37796. + vchiq_log_info(vchiq_susp_log_level,
  37797. + "%s: Videocore resumed", __func__);
  37798. + ret = 0;
  37799. + }
  37800. + read_unlock_bh(&arm_state->susp_res_lock);
  37801. +out:
  37802. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  37803. + return ret;
  37804. +}
  37805. +
  37806. +/* This function should be called with the write lock held */
  37807. +int
  37808. +vchiq_check_resume(VCHIQ_STATE_T *state)
  37809. +{
  37810. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37811. + int resume = 0;
  37812. +
  37813. + if (!arm_state)
  37814. + goto out;
  37815. +
  37816. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37817. +
  37818. + if (need_resume(state)) {
  37819. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  37820. + request_poll(state, NULL, 0);
  37821. + resume = 1;
  37822. + }
  37823. +
  37824. +out:
  37825. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  37826. + return resume;
  37827. +}
  37828. +
  37829. +void
  37830. +vchiq_platform_check_resume(VCHIQ_STATE_T *state)
  37831. +{
  37832. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37833. + int res = 0;
  37834. +
  37835. + if (!arm_state)
  37836. + goto out;
  37837. +
  37838. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37839. +
  37840. + write_lock_bh(&arm_state->susp_res_lock);
  37841. + if (arm_state->wake_address == 0) {
  37842. + vchiq_log_info(vchiq_susp_log_level,
  37843. + "%s: already awake", __func__);
  37844. + goto unlock;
  37845. + }
  37846. + if (arm_state->vc_resume_state == VC_RESUME_IN_PROGRESS) {
  37847. + vchiq_log_info(vchiq_susp_log_level,
  37848. + "%s: already resuming", __func__);
  37849. + goto unlock;
  37850. + }
  37851. +
  37852. + if (arm_state->vc_resume_state == VC_RESUME_REQUESTED) {
  37853. + set_resume_state(arm_state, VC_RESUME_IN_PROGRESS);
  37854. + res = 1;
  37855. + } else
  37856. + vchiq_log_trace(vchiq_susp_log_level,
  37857. + "%s: not resuming (resume state %s)", __func__,
  37858. + resume_state_names[arm_state->vc_resume_state +
  37859. + VC_RESUME_NUM_OFFSET]);
  37860. +
  37861. +unlock:
  37862. + write_unlock_bh(&arm_state->susp_res_lock);
  37863. +
  37864. + if (res)
  37865. + vchiq_platform_resume(state);
  37866. +
  37867. +out:
  37868. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  37869. + return;
  37870. +
  37871. +}
  37872. +
  37873. +
  37874. +
  37875. +VCHIQ_STATUS_T
  37876. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  37877. + enum USE_TYPE_E use_type)
  37878. +{
  37879. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  37880. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  37881. + char entity[16];
  37882. + int *entity_uc;
  37883. + int local_uc, local_entity_uc;
  37884. +
  37885. + if (!arm_state)
  37886. + goto out;
  37887. +
  37888. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  37889. +
  37890. + if (use_type == USE_TYPE_VCHIQ) {
  37891. + sprintf(entity, "VCHIQ: ");
  37892. + entity_uc = &arm_state->peer_use_count;
  37893. + } else if (service) {
  37894. + sprintf(entity, "%c%c%c%c:%03d",
  37895. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  37896. + service->client_id);
  37897. + entity_uc = &service->service_use_count;
  37898. + } else {
  37899. + vchiq_log_error(vchiq_susp_log_level, "%s null service "
  37900. + "ptr", __func__);
  37901. + ret = VCHIQ_ERROR;
  37902. + goto out;
  37903. + }
  37904. +
  37905. + write_lock_bh(&arm_state->susp_res_lock);
  37906. + while (arm_state->resume_blocked) {
  37907. + /* If we call 'use' while force suspend is waiting for suspend,
  37908. + * then we're about to block the thread which the force is
  37909. + * waiting to complete, so we're bound to just time out. In this
  37910. + * case, set the suspend state such that the wait will be
  37911. + * canceled, so we can complete as quickly as possible. */
  37912. + if (arm_state->resume_blocked && arm_state->vc_suspend_state ==
  37913. + VC_SUSPEND_IDLE) {
  37914. + set_suspend_state(arm_state, VC_SUSPEND_FORCE_CANCELED);
  37915. + break;
  37916. + }
  37917. + /* If suspend is already in progress then we need to block */
  37918. + if (!try_wait_for_completion(&arm_state->resume_blocker)) {
  37919. + /* Indicate that there are threads waiting on the resume
  37920. + * blocker. These need to be allowed to complete before
  37921. + * a _second_ call to force suspend can complete,
  37922. + * otherwise low priority threads might never actually
  37923. + * continue */
  37924. + arm_state->blocked_count++;
  37925. + write_unlock_bh(&arm_state->susp_res_lock);
  37926. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  37927. + "blocked - waiting...", __func__, entity);
  37928. + if (wait_for_completion_killable(
  37929. + &arm_state->resume_blocker) != 0) {
  37930. + vchiq_log_error(vchiq_susp_log_level, "%s %s "
  37931. + "wait for resume blocker interrupted",
  37932. + __func__, entity);
  37933. + ret = VCHIQ_ERROR;
  37934. + write_lock_bh(&arm_state->susp_res_lock);
  37935. + arm_state->blocked_count--;
  37936. + write_unlock_bh(&arm_state->susp_res_lock);
  37937. + goto out;
  37938. + }
  37939. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  37940. + "unblocked", __func__, entity);
  37941. + write_lock_bh(&arm_state->susp_res_lock);
  37942. + if (--arm_state->blocked_count == 0)
  37943. + complete_all(&arm_state->blocked_blocker);
  37944. + }
  37945. + }
  37946. +
  37947. + stop_suspend_timer(arm_state);
  37948. +
  37949. + local_uc = ++arm_state->videocore_use_count;
  37950. + local_entity_uc = ++(*entity_uc);
  37951. +
  37952. + /* If there's a pending request which hasn't yet been serviced then
  37953. + * just clear it. If we're past VC_SUSPEND_REQUESTED state then
  37954. + * vc_resume_complete will block until we either resume or fail to
  37955. + * suspend */
  37956. + if (arm_state->vc_suspend_state <= VC_SUSPEND_REQUESTED)
  37957. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  37958. +
  37959. + if ((use_type != USE_TYPE_SERVICE_NO_RESUME) && need_resume(state)) {
  37960. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  37961. + vchiq_log_info(vchiq_susp_log_level,
  37962. + "%s %s count %d, state count %d",
  37963. + __func__, entity, local_entity_uc, local_uc);
  37964. + request_poll(state, NULL, 0);
  37965. + } else
  37966. + vchiq_log_trace(vchiq_susp_log_level,
  37967. + "%s %s count %d, state count %d",
  37968. + __func__, entity, *entity_uc, local_uc);
  37969. +
  37970. +
  37971. + write_unlock_bh(&arm_state->susp_res_lock);
  37972. +
  37973. + /* Completion is in a done state when we're not suspended, so this won't
  37974. + * block for the non-suspended case. */
  37975. + if (!try_wait_for_completion(&arm_state->vc_resume_complete)) {
  37976. + vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume",
  37977. + __func__, entity);
  37978. + if (wait_for_completion_killable(
  37979. + &arm_state->vc_resume_complete) != 0) {
  37980. + vchiq_log_error(vchiq_susp_log_level, "%s %s wait for "
  37981. + "resume interrupted", __func__, entity);
  37982. + ret = VCHIQ_ERROR;
  37983. + goto out;
  37984. + }
  37985. + vchiq_log_info(vchiq_susp_log_level, "%s %s resumed", __func__,
  37986. + entity);
  37987. + }
  37988. +
  37989. + if (ret == VCHIQ_SUCCESS) {
  37990. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  37991. + long ack_cnt = atomic_xchg(&arm_state->ka_use_ack_count, 0);
  37992. + while (ack_cnt && (status == VCHIQ_SUCCESS)) {
  37993. + /* Send the use notify to videocore */
  37994. + status = vchiq_send_remote_use_active(state);
  37995. + if (status == VCHIQ_SUCCESS)
  37996. + ack_cnt--;
  37997. + else
  37998. + atomic_add(ack_cnt,
  37999. + &arm_state->ka_use_ack_count);
  38000. + }
  38001. + }
  38002. +
  38003. +out:
  38004. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  38005. + return ret;
  38006. +}
  38007. +
  38008. +VCHIQ_STATUS_T
  38009. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service)
  38010. +{
  38011. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  38012. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  38013. + char entity[16];
  38014. + int *entity_uc;
  38015. + int local_uc, local_entity_uc;
  38016. +
  38017. + if (!arm_state)
  38018. + goto out;
  38019. +
  38020. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  38021. +
  38022. + if (service) {
  38023. + sprintf(entity, "%c%c%c%c:%03d",
  38024. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  38025. + service->client_id);
  38026. + entity_uc = &service->service_use_count;
  38027. + } else {
  38028. + sprintf(entity, "PEER: ");
  38029. + entity_uc = &arm_state->peer_use_count;
  38030. + }
  38031. +
  38032. + write_lock_bh(&arm_state->susp_res_lock);
  38033. + if (!arm_state->videocore_use_count || !(*entity_uc)) {
  38034. + /* Don't use BUG_ON - don't allow user thread to crash kernel */
  38035. + WARN_ON(!arm_state->videocore_use_count);
  38036. + WARN_ON(!(*entity_uc));
  38037. + ret = VCHIQ_ERROR;
  38038. + goto unlock;
  38039. + }
  38040. + local_uc = --arm_state->videocore_use_count;
  38041. + local_entity_uc = --(*entity_uc);
  38042. +
  38043. + if (!vchiq_videocore_wanted(state)) {
  38044. + if (vchiq_platform_use_suspend_timer() &&
  38045. + !arm_state->resume_blocked) {
  38046. + /* Only use the timer if we're not trying to force
  38047. + * suspend (=> resume_blocked) */
  38048. + start_suspend_timer(arm_state);
  38049. + } else {
  38050. + vchiq_log_info(vchiq_susp_log_level,
  38051. + "%s %s count %d, state count %d - suspending",
  38052. + __func__, entity, *entity_uc,
  38053. + arm_state->videocore_use_count);
  38054. + vchiq_arm_vcsuspend(state);
  38055. + }
  38056. + } else
  38057. + vchiq_log_trace(vchiq_susp_log_level,
  38058. + "%s %s count %d, state count %d",
  38059. + __func__, entity, *entity_uc,
  38060. + arm_state->videocore_use_count);
  38061. +
  38062. +unlock:
  38063. + write_unlock_bh(&arm_state->susp_res_lock);
  38064. +
  38065. +out:
  38066. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  38067. + return ret;
  38068. +}
  38069. +
  38070. +void
  38071. +vchiq_on_remote_use(VCHIQ_STATE_T *state)
  38072. +{
  38073. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  38074. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  38075. + atomic_inc(&arm_state->ka_use_count);
  38076. + complete(&arm_state->ka_evt);
  38077. +}
  38078. +
  38079. +void
  38080. +vchiq_on_remote_release(VCHIQ_STATE_T *state)
  38081. +{
  38082. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  38083. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  38084. + atomic_inc(&arm_state->ka_release_count);
  38085. + complete(&arm_state->ka_evt);
  38086. +}
  38087. +
  38088. +VCHIQ_STATUS_T
  38089. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service)
  38090. +{
  38091. + return vchiq_use_internal(service->state, service, USE_TYPE_SERVICE);
  38092. +}
  38093. +
  38094. +VCHIQ_STATUS_T
  38095. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service)
  38096. +{
  38097. + return vchiq_release_internal(service->state, service);
  38098. +}
  38099. +
  38100. +VCHIQ_DEBUGFS_NODE_T *
  38101. +vchiq_instance_get_debugfs_node(VCHIQ_INSTANCE_T instance)
  38102. +{
  38103. + return &instance->debugfs_node;
  38104. +}
  38105. +
  38106. +int
  38107. +vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance)
  38108. +{
  38109. + VCHIQ_SERVICE_T *service;
  38110. + int use_count = 0, i;
  38111. + i = 0;
  38112. + while ((service = next_service_by_instance(instance->state,
  38113. + instance, &i)) != NULL) {
  38114. + use_count += service->service_use_count;
  38115. + unlock_service(service);
  38116. + }
  38117. + return use_count;
  38118. +}
  38119. +
  38120. +int
  38121. +vchiq_instance_get_pid(VCHIQ_INSTANCE_T instance)
  38122. +{
  38123. + return instance->pid;
  38124. +}
  38125. +
  38126. +int
  38127. +vchiq_instance_get_trace(VCHIQ_INSTANCE_T instance)
  38128. +{
  38129. + return instance->trace;
  38130. +}
  38131. +
  38132. +void
  38133. +vchiq_instance_set_trace(VCHIQ_INSTANCE_T instance, int trace)
  38134. +{
  38135. + VCHIQ_SERVICE_T *service;
  38136. + int i;
  38137. + i = 0;
  38138. + while ((service = next_service_by_instance(instance->state,
  38139. + instance, &i)) != NULL) {
  38140. + service->trace = trace;
  38141. + unlock_service(service);
  38142. + }
  38143. + instance->trace = (trace != 0);
  38144. +}
  38145. +
  38146. +static void suspend_timer_callback(unsigned long context)
  38147. +{
  38148. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *)context;
  38149. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  38150. + if (!arm_state)
  38151. + goto out;
  38152. + vchiq_log_info(vchiq_susp_log_level,
  38153. + "%s - suspend timer expired - check suspend", __func__);
  38154. + vchiq_check_suspend(state);
  38155. +out:
  38156. + return;
  38157. +}
  38158. +
  38159. +VCHIQ_STATUS_T
  38160. +vchiq_use_service_no_resume(VCHIQ_SERVICE_HANDLE_T handle)
  38161. +{
  38162. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  38163. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  38164. + if (service) {
  38165. + ret = vchiq_use_internal(service->state, service,
  38166. + USE_TYPE_SERVICE_NO_RESUME);
  38167. + unlock_service(service);
  38168. + }
  38169. + return ret;
  38170. +}
  38171. +
  38172. +VCHIQ_STATUS_T
  38173. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle)
  38174. +{
  38175. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  38176. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  38177. + if (service) {
  38178. + ret = vchiq_use_internal(service->state, service,
  38179. + USE_TYPE_SERVICE);
  38180. + unlock_service(service);
  38181. + }
  38182. + return ret;
  38183. +}
  38184. +
  38185. +VCHIQ_STATUS_T
  38186. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle)
  38187. +{
  38188. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  38189. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  38190. + if (service) {
  38191. + ret = vchiq_release_internal(service->state, service);
  38192. + unlock_service(service);
  38193. + }
  38194. + return ret;
  38195. +}
  38196. +
  38197. +void
  38198. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
  38199. +{
  38200. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  38201. + int i, j = 0;
  38202. + /* Only dump 64 services */
  38203. + static const int local_max_services = 64;
  38204. + /* If there's more than 64 services, only dump ones with
  38205. + * non-zero counts */
  38206. + int only_nonzero = 0;
  38207. + static const char *nz = "<-- preventing suspend";
  38208. +
  38209. + enum vc_suspend_status vc_suspend_state;
  38210. + enum vc_resume_status vc_resume_state;
  38211. + int peer_count;
  38212. + int vc_use_count;
  38213. + int active_services;
  38214. + struct service_data_struct {
  38215. + int fourcc;
  38216. + int clientid;
  38217. + int use_count;
  38218. + } service_data[local_max_services];
  38219. +
  38220. + if (!arm_state)
  38221. + return;
  38222. +
  38223. + read_lock_bh(&arm_state->susp_res_lock);
  38224. + vc_suspend_state = arm_state->vc_suspend_state;
  38225. + vc_resume_state = arm_state->vc_resume_state;
  38226. + peer_count = arm_state->peer_use_count;
  38227. + vc_use_count = arm_state->videocore_use_count;
  38228. + active_services = state->unused_service;
  38229. + if (active_services > local_max_services)
  38230. + only_nonzero = 1;
  38231. +
  38232. + for (i = 0; (i < active_services) && (j < local_max_services); i++) {
  38233. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  38234. + if (!service_ptr)
  38235. + continue;
  38236. +
  38237. + if (only_nonzero && !service_ptr->service_use_count)
  38238. + continue;
  38239. +
  38240. + if (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE) {
  38241. + service_data[j].fourcc = service_ptr->base.fourcc;
  38242. + service_data[j].clientid = service_ptr->client_id;
  38243. + service_data[j++].use_count = service_ptr->
  38244. + service_use_count;
  38245. + }
  38246. + }
  38247. +
  38248. + read_unlock_bh(&arm_state->susp_res_lock);
  38249. +
  38250. + vchiq_log_warning(vchiq_susp_log_level,
  38251. + "-- Videcore suspend state: %s --",
  38252. + suspend_state_names[vc_suspend_state + VC_SUSPEND_NUM_OFFSET]);
  38253. + vchiq_log_warning(vchiq_susp_log_level,
  38254. + "-- Videcore resume state: %s --",
  38255. + resume_state_names[vc_resume_state + VC_RESUME_NUM_OFFSET]);
  38256. +
  38257. + if (only_nonzero)
  38258. + vchiq_log_warning(vchiq_susp_log_level, "Too many active "
  38259. + "services (%d). Only dumping up to first %d services "
  38260. + "with non-zero use-count", active_services,
  38261. + local_max_services);
  38262. +
  38263. + for (i = 0; i < j; i++) {
  38264. + vchiq_log_warning(vchiq_susp_log_level,
  38265. + "----- %c%c%c%c:%d service count %d %s",
  38266. + VCHIQ_FOURCC_AS_4CHARS(service_data[i].fourcc),
  38267. + service_data[i].clientid,
  38268. + service_data[i].use_count,
  38269. + service_data[i].use_count ? nz : "");
  38270. + }
  38271. + vchiq_log_warning(vchiq_susp_log_level,
  38272. + "----- VCHIQ use count count %d", peer_count);
  38273. + vchiq_log_warning(vchiq_susp_log_level,
  38274. + "--- Overall vchiq instance use count %d", vc_use_count);
  38275. +
  38276. + vchiq_dump_platform_use_state(state);
  38277. +}
  38278. +
  38279. +VCHIQ_STATUS_T
  38280. +vchiq_check_service(VCHIQ_SERVICE_T *service)
  38281. +{
  38282. + VCHIQ_ARM_STATE_T *arm_state;
  38283. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  38284. +
  38285. + if (!service || !service->state)
  38286. + goto out;
  38287. +
  38288. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  38289. +
  38290. + arm_state = vchiq_platform_get_arm_state(service->state);
  38291. +
  38292. + read_lock_bh(&arm_state->susp_res_lock);
  38293. + if (service->service_use_count)
  38294. + ret = VCHIQ_SUCCESS;
  38295. + read_unlock_bh(&arm_state->susp_res_lock);
  38296. +
  38297. + if (ret == VCHIQ_ERROR) {
  38298. + vchiq_log_error(vchiq_susp_log_level,
  38299. + "%s ERROR - %c%c%c%c:%d service count %d, "
  38300. + "state count %d, videocore suspend state %s", __func__,
  38301. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  38302. + service->client_id, service->service_use_count,
  38303. + arm_state->videocore_use_count,
  38304. + suspend_state_names[arm_state->vc_suspend_state +
  38305. + VC_SUSPEND_NUM_OFFSET]);
  38306. + vchiq_dump_service_use_state(service->state);
  38307. + }
  38308. +out:
  38309. + return ret;
  38310. +}
  38311. +
  38312. +/* stub functions */
  38313. +void vchiq_on_remote_use_active(VCHIQ_STATE_T *state)
  38314. +{
  38315. + (void)state;
  38316. +}
  38317. +
  38318. +void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  38319. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate)
  38320. +{
  38321. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  38322. + vchiq_log_info(vchiq_susp_log_level, "%d: %s->%s", state->id,
  38323. + get_conn_state_name(oldstate), get_conn_state_name(newstate));
  38324. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) {
  38325. + write_lock_bh(&arm_state->susp_res_lock);
  38326. + if (!arm_state->first_connect) {
  38327. + char threadname[10];
  38328. + arm_state->first_connect = 1;
  38329. + write_unlock_bh(&arm_state->susp_res_lock);
  38330. + snprintf(threadname, sizeof(threadname), "VCHIQka-%d",
  38331. + state->id);
  38332. + arm_state->ka_thread = kthread_create(
  38333. + &vchiq_keepalive_thread_func,
  38334. + (void *)state,
  38335. + threadname);
  38336. + if (arm_state->ka_thread == NULL) {
  38337. + vchiq_log_error(vchiq_susp_log_level,
  38338. + "vchiq: FATAL: couldn't create thread %s",
  38339. + threadname);
  38340. + } else {
  38341. + wake_up_process(arm_state->ka_thread);
  38342. + }
  38343. + } else
  38344. + write_unlock_bh(&arm_state->susp_res_lock);
  38345. + }
  38346. +}
  38347. +
  38348. +
  38349. +/****************************************************************************
  38350. +*
  38351. +* vchiq_init - called when the module is loaded.
  38352. +*
  38353. +***************************************************************************/
  38354. +
  38355. +static int __init
  38356. +vchiq_init(void)
  38357. +{
  38358. + int err;
  38359. + void *ptr_err;
  38360. +
  38361. + /* create debugfs entries */
  38362. + err = vchiq_debugfs_init();
  38363. + if (err != 0)
  38364. + goto failed_debugfs_init;
  38365. +
  38366. + err = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME);
  38367. + if (err != 0) {
  38368. + vchiq_log_error(vchiq_arm_log_level,
  38369. + "Unable to allocate device number");
  38370. + goto failed_alloc_chrdev;
  38371. + }
  38372. + cdev_init(&vchiq_cdev, &vchiq_fops);
  38373. + vchiq_cdev.owner = THIS_MODULE;
  38374. + err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
  38375. + if (err != 0) {
  38376. + vchiq_log_error(vchiq_arm_log_level,
  38377. + "Unable to register device");
  38378. + goto failed_cdev_add;
  38379. + }
  38380. +
  38381. + /* create sysfs entries */
  38382. + vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
  38383. + ptr_err = vchiq_class;
  38384. + if (IS_ERR(ptr_err))
  38385. + goto failed_class_create;
  38386. +
  38387. + vchiq_dev = device_create(vchiq_class, NULL,
  38388. + vchiq_devid, NULL, "vchiq");
  38389. + ptr_err = vchiq_dev;
  38390. + if (IS_ERR(ptr_err))
  38391. + goto failed_device_create;
  38392. +
  38393. + err = vchiq_platform_init(&g_state);
  38394. + if (err != 0)
  38395. + goto failed_platform_init;
  38396. +
  38397. + vchiq_log_info(vchiq_arm_log_level,
  38398. + "vchiq: initialised - version %d (min %d), device %d.%d",
  38399. + VCHIQ_VERSION, VCHIQ_VERSION_MIN,
  38400. + MAJOR(vchiq_devid), MINOR(vchiq_devid));
  38401. +
  38402. + return 0;
  38403. +
  38404. +failed_platform_init:
  38405. + device_destroy(vchiq_class, vchiq_devid);
  38406. +failed_device_create:
  38407. + class_destroy(vchiq_class);
  38408. +failed_class_create:
  38409. + cdev_del(&vchiq_cdev);
  38410. + err = PTR_ERR(ptr_err);
  38411. +failed_cdev_add:
  38412. + unregister_chrdev_region(vchiq_devid, 1);
  38413. +failed_alloc_chrdev:
  38414. + vchiq_debugfs_deinit();
  38415. +failed_debugfs_init:
  38416. + vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq");
  38417. + return err;
  38418. +}
  38419. +
  38420. +/****************************************************************************
  38421. +*
  38422. +* vchiq_exit - called when the module is unloaded.
  38423. +*
  38424. +***************************************************************************/
  38425. +
  38426. +static void __exit
  38427. +vchiq_exit(void)
  38428. +{
  38429. + vchiq_platform_exit(&g_state);
  38430. + device_destroy(vchiq_class, vchiq_devid);
  38431. + class_destroy(vchiq_class);
  38432. + cdev_del(&vchiq_cdev);
  38433. + unregister_chrdev_region(vchiq_devid, 1);
  38434. +}
  38435. +
  38436. +module_init(vchiq_init);
  38437. +module_exit(vchiq_exit);
  38438. +MODULE_LICENSE("GPL");
  38439. +MODULE_AUTHOR("Broadcom Corporation");
  38440. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h
  38441. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 1970-01-01 01:00:00.000000000 +0100
  38442. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 2015-02-09 04:40:08.000000000 +0100
  38443. @@ -0,0 +1,223 @@
  38444. +/**
  38445. + * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
  38446. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  38447. + *
  38448. + * Redistribution and use in source and binary forms, with or without
  38449. + * modification, are permitted provided that the following conditions
  38450. + * are met:
  38451. + * 1. Redistributions of source code must retain the above copyright
  38452. + * notice, this list of conditions, and the following disclaimer,
  38453. + * without modification.
  38454. + * 2. Redistributions in binary form must reproduce the above copyright
  38455. + * notice, this list of conditions and the following disclaimer in the
  38456. + * documentation and/or other materials provided with the distribution.
  38457. + * 3. The names of the above-listed copyright holders may not be used
  38458. + * to endorse or promote products derived from this software without
  38459. + * specific prior written permission.
  38460. + *
  38461. + * ALTERNATIVELY, this software may be distributed under the terms of the
  38462. + * GNU General Public License ("GPL") version 2, as published by the Free
  38463. + * Software Foundation.
  38464. + *
  38465. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  38466. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  38467. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38468. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  38469. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38470. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38471. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38472. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  38473. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38474. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38475. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38476. + */
  38477. +
  38478. +#ifndef VCHIQ_ARM_H
  38479. +#define VCHIQ_ARM_H
  38480. +
  38481. +#include <linux/mutex.h>
  38482. +#include <linux/semaphore.h>
  38483. +#include <linux/atomic.h>
  38484. +#include "vchiq_core.h"
  38485. +#include "vchiq_debugfs.h"
  38486. +
  38487. +
  38488. +enum vc_suspend_status {
  38489. + VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */
  38490. + VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */
  38491. + VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */
  38492. + VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */
  38493. + VC_SUSPEND_REQUESTED, /* User has requested suspend */
  38494. + VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */
  38495. + VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */
  38496. +};
  38497. +
  38498. +enum vc_resume_status {
  38499. + VC_RESUME_FAILED = -1, /* Videocore resume failed */
  38500. + VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */
  38501. + VC_RESUME_REQUESTED, /* User has requested resume */
  38502. + VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */
  38503. + VC_RESUME_RESUMED /* Videocore resumed successfully (active) */
  38504. +};
  38505. +
  38506. +
  38507. +enum USE_TYPE_E {
  38508. + USE_TYPE_SERVICE,
  38509. + USE_TYPE_SERVICE_NO_RESUME,
  38510. + USE_TYPE_VCHIQ
  38511. +};
  38512. +
  38513. +
  38514. +
  38515. +typedef struct vchiq_arm_state_struct {
  38516. + /* Keepalive-related data */
  38517. + struct task_struct *ka_thread;
  38518. + struct completion ka_evt;
  38519. + atomic_t ka_use_count;
  38520. + atomic_t ka_use_ack_count;
  38521. + atomic_t ka_release_count;
  38522. +
  38523. + struct completion vc_suspend_complete;
  38524. + struct completion vc_resume_complete;
  38525. +
  38526. + rwlock_t susp_res_lock;
  38527. + enum vc_suspend_status vc_suspend_state;
  38528. + enum vc_resume_status vc_resume_state;
  38529. +
  38530. + unsigned int wake_address;
  38531. +
  38532. + struct timer_list suspend_timer;
  38533. + int suspend_timer_timeout;
  38534. + int suspend_timer_running;
  38535. +
  38536. + /* Global use count for videocore.
  38537. + ** This is equal to the sum of the use counts for all services. When
  38538. + ** this hits zero the videocore suspend procedure will be initiated.
  38539. + */
  38540. + int videocore_use_count;
  38541. +
  38542. + /* Use count to track requests from videocore peer.
  38543. + ** This use count is not associated with a service, so needs to be
  38544. + ** tracked separately with the state.
  38545. + */
  38546. + int peer_use_count;
  38547. +
  38548. + /* Flag to indicate whether resume is blocked. This happens when the
  38549. + ** ARM is suspending
  38550. + */
  38551. + struct completion resume_blocker;
  38552. + int resume_blocked;
  38553. + struct completion blocked_blocker;
  38554. + int blocked_count;
  38555. +
  38556. + int autosuspend_override;
  38557. +
  38558. + /* Flag to indicate that the first vchiq connect has made it through.
  38559. + ** This means that both sides should be fully ready, and we should
  38560. + ** be able to suspend after this point.
  38561. + */
  38562. + int first_connect;
  38563. +
  38564. + unsigned long long suspend_start_time;
  38565. + unsigned long long sleep_start_time;
  38566. + unsigned long long resume_start_time;
  38567. + unsigned long long last_wake_time;
  38568. +
  38569. +} VCHIQ_ARM_STATE_T;
  38570. +
  38571. +extern int vchiq_arm_log_level;
  38572. +extern int vchiq_susp_log_level;
  38573. +
  38574. +extern int __init
  38575. +vchiq_platform_init(VCHIQ_STATE_T *state);
  38576. +
  38577. +extern void __exit
  38578. +vchiq_platform_exit(VCHIQ_STATE_T *state);
  38579. +
  38580. +extern VCHIQ_STATE_T *
  38581. +vchiq_get_state(void);
  38582. +
  38583. +extern VCHIQ_STATUS_T
  38584. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state);
  38585. +
  38586. +extern VCHIQ_STATUS_T
  38587. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state);
  38588. +
  38589. +extern int
  38590. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state);
  38591. +
  38592. +extern VCHIQ_STATUS_T
  38593. +vchiq_arm_vcresume(VCHIQ_STATE_T *state);
  38594. +
  38595. +extern VCHIQ_STATUS_T
  38596. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state);
  38597. +
  38598. +extern int
  38599. +vchiq_check_resume(VCHIQ_STATE_T *state);
  38600. +
  38601. +extern void
  38602. +vchiq_check_suspend(VCHIQ_STATE_T *state);
  38603. + VCHIQ_STATUS_T
  38604. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle);
  38605. +
  38606. +extern VCHIQ_STATUS_T
  38607. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle);
  38608. +
  38609. +extern VCHIQ_STATUS_T
  38610. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  38611. +
  38612. +extern VCHIQ_STATUS_T
  38613. +vchiq_platform_suspend(VCHIQ_STATE_T *state);
  38614. +
  38615. +extern int
  38616. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state);
  38617. +
  38618. +extern int
  38619. +vchiq_platform_use_suspend_timer(void);
  38620. +
  38621. +extern void
  38622. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state);
  38623. +
  38624. +extern void
  38625. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state);
  38626. +
  38627. +extern VCHIQ_ARM_STATE_T*
  38628. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state);
  38629. +
  38630. +extern int
  38631. +vchiq_videocore_wanted(VCHIQ_STATE_T *state);
  38632. +
  38633. +extern VCHIQ_STATUS_T
  38634. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  38635. + enum USE_TYPE_E use_type);
  38636. +extern VCHIQ_STATUS_T
  38637. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service);
  38638. +
  38639. +extern VCHIQ_DEBUGFS_NODE_T *
  38640. +vchiq_instance_get_debugfs_node(VCHIQ_INSTANCE_T instance);
  38641. +
  38642. +extern int
  38643. +vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance);
  38644. +
  38645. +extern int
  38646. +vchiq_instance_get_pid(VCHIQ_INSTANCE_T instance);
  38647. +
  38648. +extern int
  38649. +vchiq_instance_get_trace(VCHIQ_INSTANCE_T instance);
  38650. +
  38651. +extern void
  38652. +vchiq_instance_set_trace(VCHIQ_INSTANCE_T instance, int trace);
  38653. +
  38654. +extern void
  38655. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  38656. + enum vc_suspend_status new_state);
  38657. +
  38658. +extern void
  38659. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  38660. + enum vc_resume_status new_state);
  38661. +
  38662. +extern void
  38663. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state);
  38664. +
  38665. +
  38666. +#endif /* VCHIQ_ARM_H */
  38667. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h
  38668. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 1970-01-01 01:00:00.000000000 +0100
  38669. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 2015-02-09 04:40:08.000000000 +0100
  38670. @@ -0,0 +1,37 @@
  38671. +/**
  38672. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  38673. + *
  38674. + * Redistribution and use in source and binary forms, with or without
  38675. + * modification, are permitted provided that the following conditions
  38676. + * are met:
  38677. + * 1. Redistributions of source code must retain the above copyright
  38678. + * notice, this list of conditions, and the following disclaimer,
  38679. + * without modification.
  38680. + * 2. Redistributions in binary form must reproduce the above copyright
  38681. + * notice, this list of conditions and the following disclaimer in the
  38682. + * documentation and/or other materials provided with the distribution.
  38683. + * 3. The names of the above-listed copyright holders may not be used
  38684. + * to endorse or promote products derived from this software without
  38685. + * specific prior written permission.
  38686. + *
  38687. + * ALTERNATIVELY, this software may be distributed under the terms of the
  38688. + * GNU General Public License ("GPL") version 2, as published by the Free
  38689. + * Software Foundation.
  38690. + *
  38691. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  38692. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  38693. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38694. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  38695. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38696. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38697. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38698. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  38699. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38700. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38701. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38702. + */
  38703. +
  38704. +const char *vchiq_get_build_hostname(void);
  38705. +const char *vchiq_get_build_version(void);
  38706. +const char *vchiq_get_build_time(void);
  38707. +const char *vchiq_get_build_date(void);
  38708. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h
  38709. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 1970-01-01 01:00:00.000000000 +0100
  38710. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 2015-02-09 04:40:08.000000000 +0100
  38711. @@ -0,0 +1,66 @@
  38712. +/**
  38713. + * Copyright (c) 2010-2014 Broadcom. All rights reserved.
  38714. + *
  38715. + * Redistribution and use in source and binary forms, with or without
  38716. + * modification, are permitted provided that the following conditions
  38717. + * are met:
  38718. + * 1. Redistributions of source code must retain the above copyright
  38719. + * notice, this list of conditions, and the following disclaimer,
  38720. + * without modification.
  38721. + * 2. Redistributions in binary form must reproduce the above copyright
  38722. + * notice, this list of conditions and the following disclaimer in the
  38723. + * documentation and/or other materials provided with the distribution.
  38724. + * 3. The names of the above-listed copyright holders may not be used
  38725. + * to endorse or promote products derived from this software without
  38726. + * specific prior written permission.
  38727. + *
  38728. + * ALTERNATIVELY, this software may be distributed under the terms of the
  38729. + * GNU General Public License ("GPL") version 2, as published by the Free
  38730. + * Software Foundation.
  38731. + *
  38732. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  38733. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  38734. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38735. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  38736. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38737. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38738. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38739. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  38740. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38741. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38742. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38743. + */
  38744. +
  38745. +#ifndef VCHIQ_CFG_H
  38746. +#define VCHIQ_CFG_H
  38747. +
  38748. +#define VCHIQ_MAGIC VCHIQ_MAKE_FOURCC('V', 'C', 'H', 'I')
  38749. +/* The version of VCHIQ - change with any non-trivial change */
  38750. +#define VCHIQ_VERSION 7
  38751. +/* The minimum compatible version - update to match VCHIQ_VERSION with any
  38752. +** incompatible change */
  38753. +#define VCHIQ_VERSION_MIN 3
  38754. +
  38755. +/* The version that introduced the VCHIQ_IOC_LIB_VERSION ioctl */
  38756. +#define VCHIQ_VERSION_LIB_VERSION 7
  38757. +
  38758. +/* The version that introduced the VCHIQ_IOC_CLOSE_DELIVERED ioctl */
  38759. +#define VCHIQ_VERSION_CLOSE_DELIVERED 7
  38760. +
  38761. +#define VCHIQ_MAX_STATES 1
  38762. +#define VCHIQ_MAX_SERVICES 4096
  38763. +#define VCHIQ_MAX_SLOTS 128
  38764. +#define VCHIQ_MAX_SLOTS_PER_SIDE 64
  38765. +
  38766. +#define VCHIQ_NUM_CURRENT_BULKS 32
  38767. +#define VCHIQ_NUM_SERVICE_BULKS 4
  38768. +
  38769. +#ifndef VCHIQ_ENABLE_DEBUG
  38770. +#define VCHIQ_ENABLE_DEBUG 1
  38771. +#endif
  38772. +
  38773. +#ifndef VCHIQ_ENABLE_STATS
  38774. +#define VCHIQ_ENABLE_STATS 1
  38775. +#endif
  38776. +
  38777. +#endif /* VCHIQ_CFG_H */
  38778. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
  38779. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 1970-01-01 01:00:00.000000000 +0100
  38780. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 2015-02-09 04:40:08.000000000 +0100
  38781. @@ -0,0 +1,120 @@
  38782. +/**
  38783. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  38784. + *
  38785. + * Redistribution and use in source and binary forms, with or without
  38786. + * modification, are permitted provided that the following conditions
  38787. + * are met:
  38788. + * 1. Redistributions of source code must retain the above copyright
  38789. + * notice, this list of conditions, and the following disclaimer,
  38790. + * without modification.
  38791. + * 2. Redistributions in binary form must reproduce the above copyright
  38792. + * notice, this list of conditions and the following disclaimer in the
  38793. + * documentation and/or other materials provided with the distribution.
  38794. + * 3. The names of the above-listed copyright holders may not be used
  38795. + * to endorse or promote products derived from this software without
  38796. + * specific prior written permission.
  38797. + *
  38798. + * ALTERNATIVELY, this software may be distributed under the terms of the
  38799. + * GNU General Public License ("GPL") version 2, as published by the Free
  38800. + * Software Foundation.
  38801. + *
  38802. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  38803. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  38804. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38805. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  38806. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38807. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38808. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38809. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  38810. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38811. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38812. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38813. + */
  38814. +
  38815. +#include "vchiq_connected.h"
  38816. +#include "vchiq_core.h"
  38817. +#include "vchiq_killable.h"
  38818. +#include <linux/module.h>
  38819. +#include <linux/mutex.h>
  38820. +
  38821. +#define MAX_CALLBACKS 10
  38822. +
  38823. +static int g_connected;
  38824. +static int g_num_deferred_callbacks;
  38825. +static VCHIQ_CONNECTED_CALLBACK_T g_deferred_callback[MAX_CALLBACKS];
  38826. +static int g_once_init;
  38827. +static struct mutex g_connected_mutex;
  38828. +
  38829. +/****************************************************************************
  38830. +*
  38831. +* Function to initialize our lock.
  38832. +*
  38833. +***************************************************************************/
  38834. +
  38835. +static void connected_init(void)
  38836. +{
  38837. + if (!g_once_init) {
  38838. + mutex_init(&g_connected_mutex);
  38839. + g_once_init = 1;
  38840. + }
  38841. +}
  38842. +
  38843. +/****************************************************************************
  38844. +*
  38845. +* This function is used to defer initialization until the vchiq stack is
  38846. +* initialized. If the stack is already initialized, then the callback will
  38847. +* be made immediately, otherwise it will be deferred until
  38848. +* vchiq_call_connected_callbacks is called.
  38849. +*
  38850. +***************************************************************************/
  38851. +
  38852. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback)
  38853. +{
  38854. + connected_init();
  38855. +
  38856. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  38857. + return;
  38858. +
  38859. + if (g_connected)
  38860. + /* We're already connected. Call the callback immediately. */
  38861. +
  38862. + callback();
  38863. + else {
  38864. + if (g_num_deferred_callbacks >= MAX_CALLBACKS)
  38865. + vchiq_log_error(vchiq_core_log_level,
  38866. + "There already %d callback registered - "
  38867. + "please increase MAX_CALLBACKS",
  38868. + g_num_deferred_callbacks);
  38869. + else {
  38870. + g_deferred_callback[g_num_deferred_callbacks] =
  38871. + callback;
  38872. + g_num_deferred_callbacks++;
  38873. + }
  38874. + }
  38875. + mutex_unlock(&g_connected_mutex);
  38876. +}
  38877. +
  38878. +/****************************************************************************
  38879. +*
  38880. +* This function is called by the vchiq stack once it has been connected to
  38881. +* the videocore and clients can start to use the stack.
  38882. +*
  38883. +***************************************************************************/
  38884. +
  38885. +void vchiq_call_connected_callbacks(void)
  38886. +{
  38887. + int i;
  38888. +
  38889. + connected_init();
  38890. +
  38891. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  38892. + return;
  38893. +
  38894. + for (i = 0; i < g_num_deferred_callbacks; i++)
  38895. + g_deferred_callback[i]();
  38896. +
  38897. + g_num_deferred_callbacks = 0;
  38898. + g_connected = 1;
  38899. + mutex_unlock(&g_connected_mutex);
  38900. +}
  38901. +EXPORT_SYMBOL(vchiq_add_connected_callback);
  38902. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h
  38903. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 1970-01-01 01:00:00.000000000 +0100
  38904. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 2015-02-09 04:40:08.000000000 +0100
  38905. @@ -0,0 +1,50 @@
  38906. +/**
  38907. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  38908. + *
  38909. + * Redistribution and use in source and binary forms, with or without
  38910. + * modification, are permitted provided that the following conditions
  38911. + * are met:
  38912. + * 1. Redistributions of source code must retain the above copyright
  38913. + * notice, this list of conditions, and the following disclaimer,
  38914. + * without modification.
  38915. + * 2. Redistributions in binary form must reproduce the above copyright
  38916. + * notice, this list of conditions and the following disclaimer in the
  38917. + * documentation and/or other materials provided with the distribution.
  38918. + * 3. The names of the above-listed copyright holders may not be used
  38919. + * to endorse or promote products derived from this software without
  38920. + * specific prior written permission.
  38921. + *
  38922. + * ALTERNATIVELY, this software may be distributed under the terms of the
  38923. + * GNU General Public License ("GPL") version 2, as published by the Free
  38924. + * Software Foundation.
  38925. + *
  38926. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  38927. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  38928. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38929. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  38930. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38931. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38932. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38933. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  38934. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38935. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38936. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38937. + */
  38938. +
  38939. +#ifndef VCHIQ_CONNECTED_H
  38940. +#define VCHIQ_CONNECTED_H
  38941. +
  38942. +/* ---- Include Files ----------------------------------------------------- */
  38943. +
  38944. +/* ---- Constants and Types ---------------------------------------------- */
  38945. +
  38946. +typedef void (*VCHIQ_CONNECTED_CALLBACK_T)(void);
  38947. +
  38948. +/* ---- Variable Externs ------------------------------------------------- */
  38949. +
  38950. +/* ---- Function Prototypes ---------------------------------------------- */
  38951. +
  38952. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback);
  38953. +void vchiq_call_connected_callbacks(void);
  38954. +
  38955. +#endif /* VCHIQ_CONNECTED_H */
  38956. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
  38957. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 1970-01-01 01:00:00.000000000 +0100
  38958. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 2015-02-09 04:40:08.000000000 +0100
  38959. @@ -0,0 +1,3862 @@
  38960. +/**
  38961. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  38962. + *
  38963. + * Redistribution and use in source and binary forms, with or without
  38964. + * modification, are permitted provided that the following conditions
  38965. + * are met:
  38966. + * 1. Redistributions of source code must retain the above copyright
  38967. + * notice, this list of conditions, and the following disclaimer,
  38968. + * without modification.
  38969. + * 2. Redistributions in binary form must reproduce the above copyright
  38970. + * notice, this list of conditions and the following disclaimer in the
  38971. + * documentation and/or other materials provided with the distribution.
  38972. + * 3. The names of the above-listed copyright holders may not be used
  38973. + * to endorse or promote products derived from this software without
  38974. + * specific prior written permission.
  38975. + *
  38976. + * ALTERNATIVELY, this software may be distributed under the terms of the
  38977. + * GNU General Public License ("GPL") version 2, as published by the Free
  38978. + * Software Foundation.
  38979. + *
  38980. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  38981. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  38982. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38983. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  38984. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38985. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38986. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38987. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  38988. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38989. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38990. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38991. + */
  38992. +
  38993. +#include "vchiq_core.h"
  38994. +#include "vchiq_killable.h"
  38995. +
  38996. +#define VCHIQ_SLOT_HANDLER_STACK 8192
  38997. +
  38998. +#define HANDLE_STATE_SHIFT 12
  38999. +
  39000. +#define SLOT_INFO_FROM_INDEX(state, index) (state->slot_info + (index))
  39001. +#define SLOT_DATA_FROM_INDEX(state, index) (state->slot_data + (index))
  39002. +#define SLOT_INDEX_FROM_DATA(state, data) \
  39003. + (((unsigned int)((char *)data - (char *)state->slot_data)) / \
  39004. + VCHIQ_SLOT_SIZE)
  39005. +#define SLOT_INDEX_FROM_INFO(state, info) \
  39006. + ((unsigned int)(info - state->slot_info))
  39007. +#define SLOT_QUEUE_INDEX_FROM_POS(pos) \
  39008. + ((int)((unsigned int)(pos) / VCHIQ_SLOT_SIZE))
  39009. +
  39010. +#define BULK_INDEX(x) (x & (VCHIQ_NUM_SERVICE_BULKS - 1))
  39011. +
  39012. +#define SRVTRACE_LEVEL(srv) \
  39013. + (((srv) && (srv)->trace) ? VCHIQ_LOG_TRACE : vchiq_core_msg_log_level)
  39014. +#define SRVTRACE_ENABLED(srv, lev) \
  39015. + (((srv) && (srv)->trace) || (vchiq_core_msg_log_level >= (lev)))
  39016. +
  39017. +struct vchiq_open_payload {
  39018. + int fourcc;
  39019. + int client_id;
  39020. + short version;
  39021. + short version_min;
  39022. +};
  39023. +
  39024. +struct vchiq_openack_payload {
  39025. + short version;
  39026. +};
  39027. +
  39028. +/* we require this for consistency between endpoints */
  39029. +vchiq_static_assert(sizeof(VCHIQ_HEADER_T) == 8);
  39030. +vchiq_static_assert(IS_POW2(sizeof(VCHIQ_HEADER_T)));
  39031. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_CURRENT_BULKS));
  39032. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_SERVICE_BULKS));
  39033. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SERVICES));
  39034. +vchiq_static_assert(VCHIQ_VERSION >= VCHIQ_VERSION_MIN);
  39035. +
  39036. +/* Run time control of log level, based on KERN_XXX level. */
  39037. +int vchiq_core_log_level = VCHIQ_LOG_DEFAULT;
  39038. +int vchiq_core_msg_log_level = VCHIQ_LOG_DEFAULT;
  39039. +int vchiq_sync_log_level = VCHIQ_LOG_DEFAULT;
  39040. +
  39041. +static atomic_t pause_bulks_count = ATOMIC_INIT(0);
  39042. +
  39043. +static DEFINE_SPINLOCK(service_spinlock);
  39044. +DEFINE_SPINLOCK(bulk_waiter_spinlock);
  39045. +DEFINE_SPINLOCK(quota_spinlock);
  39046. +
  39047. +VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  39048. +static unsigned int handle_seq;
  39049. +
  39050. +static const char *const srvstate_names[] = {
  39051. + "FREE",
  39052. + "HIDDEN",
  39053. + "LISTENING",
  39054. + "OPENING",
  39055. + "OPEN",
  39056. + "OPENSYNC",
  39057. + "CLOSESENT",
  39058. + "CLOSERECVD",
  39059. + "CLOSEWAIT",
  39060. + "CLOSED"
  39061. +};
  39062. +
  39063. +static const char *const reason_names[] = {
  39064. + "SERVICE_OPENED",
  39065. + "SERVICE_CLOSED",
  39066. + "MESSAGE_AVAILABLE",
  39067. + "BULK_TRANSMIT_DONE",
  39068. + "BULK_RECEIVE_DONE",
  39069. + "BULK_TRANSMIT_ABORTED",
  39070. + "BULK_RECEIVE_ABORTED"
  39071. +};
  39072. +
  39073. +static const char *const conn_state_names[] = {
  39074. + "DISCONNECTED",
  39075. + "CONNECTING",
  39076. + "CONNECTED",
  39077. + "PAUSING",
  39078. + "PAUSE_SENT",
  39079. + "PAUSED",
  39080. + "RESUMING",
  39081. + "PAUSE_TIMEOUT",
  39082. + "RESUME_TIMEOUT"
  39083. +};
  39084. +
  39085. +
  39086. +static void
  39087. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header);
  39088. +
  39089. +static const char *msg_type_str(unsigned int msg_type)
  39090. +{
  39091. + switch (msg_type) {
  39092. + case VCHIQ_MSG_PADDING: return "PADDING";
  39093. + case VCHIQ_MSG_CONNECT: return "CONNECT";
  39094. + case VCHIQ_MSG_OPEN: return "OPEN";
  39095. + case VCHIQ_MSG_OPENACK: return "OPENACK";
  39096. + case VCHIQ_MSG_CLOSE: return "CLOSE";
  39097. + case VCHIQ_MSG_DATA: return "DATA";
  39098. + case VCHIQ_MSG_BULK_RX: return "BULK_RX";
  39099. + case VCHIQ_MSG_BULK_TX: return "BULK_TX";
  39100. + case VCHIQ_MSG_BULK_RX_DONE: return "BULK_RX_DONE";
  39101. + case VCHIQ_MSG_BULK_TX_DONE: return "BULK_TX_DONE";
  39102. + case VCHIQ_MSG_PAUSE: return "PAUSE";
  39103. + case VCHIQ_MSG_RESUME: return "RESUME";
  39104. + case VCHIQ_MSG_REMOTE_USE: return "REMOTE_USE";
  39105. + case VCHIQ_MSG_REMOTE_RELEASE: return "REMOTE_RELEASE";
  39106. + case VCHIQ_MSG_REMOTE_USE_ACTIVE: return "REMOTE_USE_ACTIVE";
  39107. + }
  39108. + return "???";
  39109. +}
  39110. +
  39111. +static inline void
  39112. +vchiq_set_service_state(VCHIQ_SERVICE_T *service, int newstate)
  39113. +{
  39114. + vchiq_log_info(vchiq_core_log_level, "%d: srv:%d %s->%s",
  39115. + service->state->id, service->localport,
  39116. + srvstate_names[service->srvstate],
  39117. + srvstate_names[newstate]);
  39118. + service->srvstate = newstate;
  39119. +}
  39120. +
  39121. +VCHIQ_SERVICE_T *
  39122. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle)
  39123. +{
  39124. + VCHIQ_SERVICE_T *service;
  39125. +
  39126. + spin_lock(&service_spinlock);
  39127. + service = handle_to_service(handle);
  39128. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  39129. + (service->handle == handle)) {
  39130. + BUG_ON(service->ref_count == 0);
  39131. + service->ref_count++;
  39132. + } else
  39133. + service = NULL;
  39134. + spin_unlock(&service_spinlock);
  39135. +
  39136. + if (!service)
  39137. + vchiq_log_info(vchiq_core_log_level,
  39138. + "Invalid service handle 0x%x", handle);
  39139. +
  39140. + return service;
  39141. +}
  39142. +
  39143. +VCHIQ_SERVICE_T *
  39144. +find_service_by_port(VCHIQ_STATE_T *state, int localport)
  39145. +{
  39146. + VCHIQ_SERVICE_T *service = NULL;
  39147. + if ((unsigned int)localport <= VCHIQ_PORT_MAX) {
  39148. + spin_lock(&service_spinlock);
  39149. + service = state->services[localport];
  39150. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE)) {
  39151. + BUG_ON(service->ref_count == 0);
  39152. + service->ref_count++;
  39153. + } else
  39154. + service = NULL;
  39155. + spin_unlock(&service_spinlock);
  39156. + }
  39157. +
  39158. + if (!service)
  39159. + vchiq_log_info(vchiq_core_log_level,
  39160. + "Invalid port %d", localport);
  39161. +
  39162. + return service;
  39163. +}
  39164. +
  39165. +VCHIQ_SERVICE_T *
  39166. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  39167. + VCHIQ_SERVICE_HANDLE_T handle) {
  39168. + VCHIQ_SERVICE_T *service;
  39169. +
  39170. + spin_lock(&service_spinlock);
  39171. + service = handle_to_service(handle);
  39172. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  39173. + (service->handle == handle) &&
  39174. + (service->instance == instance)) {
  39175. + BUG_ON(service->ref_count == 0);
  39176. + service->ref_count++;
  39177. + } else
  39178. + service = NULL;
  39179. + spin_unlock(&service_spinlock);
  39180. +
  39181. + if (!service)
  39182. + vchiq_log_info(vchiq_core_log_level,
  39183. + "Invalid service handle 0x%x", handle);
  39184. +
  39185. + return service;
  39186. +}
  39187. +
  39188. +VCHIQ_SERVICE_T *
  39189. +find_closed_service_for_instance(VCHIQ_INSTANCE_T instance,
  39190. + VCHIQ_SERVICE_HANDLE_T handle) {
  39191. + VCHIQ_SERVICE_T *service;
  39192. +
  39193. + spin_lock(&service_spinlock);
  39194. + service = handle_to_service(handle);
  39195. + if (service &&
  39196. + ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  39197. + (service->srvstate == VCHIQ_SRVSTATE_CLOSED)) &&
  39198. + (service->handle == handle) &&
  39199. + (service->instance == instance)) {
  39200. + BUG_ON(service->ref_count == 0);
  39201. + service->ref_count++;
  39202. + } else
  39203. + service = NULL;
  39204. + spin_unlock(&service_spinlock);
  39205. +
  39206. + if (!service)
  39207. + vchiq_log_info(vchiq_core_log_level,
  39208. + "Invalid service handle 0x%x", handle);
  39209. +
  39210. + return service;
  39211. +}
  39212. +
  39213. +VCHIQ_SERVICE_T *
  39214. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  39215. + int *pidx)
  39216. +{
  39217. + VCHIQ_SERVICE_T *service = NULL;
  39218. + int idx = *pidx;
  39219. +
  39220. + spin_lock(&service_spinlock);
  39221. + while (idx < state->unused_service) {
  39222. + VCHIQ_SERVICE_T *srv = state->services[idx++];
  39223. + if (srv && (srv->srvstate != VCHIQ_SRVSTATE_FREE) &&
  39224. + (srv->instance == instance)) {
  39225. + service = srv;
  39226. + BUG_ON(service->ref_count == 0);
  39227. + service->ref_count++;
  39228. + break;
  39229. + }
  39230. + }
  39231. + spin_unlock(&service_spinlock);
  39232. +
  39233. + *pidx = idx;
  39234. +
  39235. + return service;
  39236. +}
  39237. +
  39238. +void
  39239. +lock_service(VCHIQ_SERVICE_T *service)
  39240. +{
  39241. + spin_lock(&service_spinlock);
  39242. + BUG_ON(!service || (service->ref_count == 0));
  39243. + if (service)
  39244. + service->ref_count++;
  39245. + spin_unlock(&service_spinlock);
  39246. +}
  39247. +
  39248. +void
  39249. +unlock_service(VCHIQ_SERVICE_T *service)
  39250. +{
  39251. + VCHIQ_STATE_T *state = service->state;
  39252. + spin_lock(&service_spinlock);
  39253. + BUG_ON(!service || (service->ref_count == 0));
  39254. + if (service && service->ref_count) {
  39255. + service->ref_count--;
  39256. + if (!service->ref_count) {
  39257. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  39258. + state->services[service->localport] = NULL;
  39259. + } else
  39260. + service = NULL;
  39261. + }
  39262. + spin_unlock(&service_spinlock);
  39263. +
  39264. + if (service && service->userdata_term)
  39265. + service->userdata_term(service->base.userdata);
  39266. +
  39267. + kfree(service);
  39268. +}
  39269. +
  39270. +int
  39271. +vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T handle)
  39272. +{
  39273. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  39274. + int id;
  39275. +
  39276. + id = service ? service->client_id : 0;
  39277. + if (service)
  39278. + unlock_service(service);
  39279. +
  39280. + return id;
  39281. +}
  39282. +
  39283. +void *
  39284. +vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T handle)
  39285. +{
  39286. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  39287. +
  39288. + return service ? service->base.userdata : NULL;
  39289. +}
  39290. +
  39291. +int
  39292. +vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T handle)
  39293. +{
  39294. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  39295. +
  39296. + return service ? service->base.fourcc : 0;
  39297. +}
  39298. +
  39299. +static void
  39300. +mark_service_closing_internal(VCHIQ_SERVICE_T *service, int sh_thread)
  39301. +{
  39302. + VCHIQ_STATE_T *state = service->state;
  39303. + VCHIQ_SERVICE_QUOTA_T *service_quota;
  39304. +
  39305. + service->closing = 1;
  39306. +
  39307. + /* Synchronise with other threads. */
  39308. + mutex_lock(&state->recycle_mutex);
  39309. + mutex_unlock(&state->recycle_mutex);
  39310. + if (!sh_thread || (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT)) {
  39311. + /* If we're pausing then the slot_mutex is held until resume
  39312. + * by the slot handler. Therefore don't try to acquire this
  39313. + * mutex if we're the slot handler and in the pause sent state.
  39314. + * We don't need to in this case anyway. */
  39315. + mutex_lock(&state->slot_mutex);
  39316. + mutex_unlock(&state->slot_mutex);
  39317. + }
  39318. +
  39319. + /* Unblock any sending thread. */
  39320. + service_quota = &state->service_quotas[service->localport];
  39321. + up(&service_quota->quota_event);
  39322. +}
  39323. +
  39324. +static void
  39325. +mark_service_closing(VCHIQ_SERVICE_T *service)
  39326. +{
  39327. + mark_service_closing_internal(service, 0);
  39328. +}
  39329. +
  39330. +static inline VCHIQ_STATUS_T
  39331. +make_service_callback(VCHIQ_SERVICE_T *service, VCHIQ_REASON_T reason,
  39332. + VCHIQ_HEADER_T *header, void *bulk_userdata)
  39333. +{
  39334. + VCHIQ_STATUS_T status;
  39335. + vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %x, %x)",
  39336. + service->state->id, service->localport, reason_names[reason],
  39337. + (unsigned int)header, (unsigned int)bulk_userdata);
  39338. + status = service->base.callback(reason, header, service->handle,
  39339. + bulk_userdata);
  39340. + if (status == VCHIQ_ERROR) {
  39341. + vchiq_log_warning(vchiq_core_log_level,
  39342. + "%d: ignoring ERROR from callback to service %x",
  39343. + service->state->id, service->handle);
  39344. + status = VCHIQ_SUCCESS;
  39345. + }
  39346. + return status;
  39347. +}
  39348. +
  39349. +inline void
  39350. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate)
  39351. +{
  39352. + VCHIQ_CONNSTATE_T oldstate = state->conn_state;
  39353. + vchiq_log_info(vchiq_core_log_level, "%d: %s->%s", state->id,
  39354. + conn_state_names[oldstate],
  39355. + conn_state_names[newstate]);
  39356. + state->conn_state = newstate;
  39357. + vchiq_platform_conn_state_changed(state, oldstate, newstate);
  39358. +}
  39359. +
  39360. +static inline void
  39361. +remote_event_create(REMOTE_EVENT_T *event)
  39362. +{
  39363. + event->armed = 0;
  39364. + /* Don't clear the 'fired' flag because it may already have been set
  39365. + ** by the other side. */
  39366. + sema_init(event->event, 0);
  39367. +}
  39368. +
  39369. +static inline void
  39370. +remote_event_destroy(REMOTE_EVENT_T *event)
  39371. +{
  39372. + (void)event;
  39373. +}
  39374. +
  39375. +static inline int
  39376. +remote_event_wait(REMOTE_EVENT_T *event)
  39377. +{
  39378. + if (!event->fired) {
  39379. + event->armed = 1;
  39380. + dsb();
  39381. + if (!event->fired) {
  39382. + if (down_interruptible(event->event) != 0) {
  39383. + event->armed = 0;
  39384. + return 0;
  39385. + }
  39386. + }
  39387. + event->armed = 0;
  39388. + wmb();
  39389. + }
  39390. +
  39391. + event->fired = 0;
  39392. + return 1;
  39393. +}
  39394. +
  39395. +static inline void
  39396. +remote_event_signal_local(REMOTE_EVENT_T *event)
  39397. +{
  39398. + event->armed = 0;
  39399. + up(event->event);
  39400. +}
  39401. +
  39402. +static inline void
  39403. +remote_event_poll(REMOTE_EVENT_T *event)
  39404. +{
  39405. + if (event->fired && event->armed)
  39406. + remote_event_signal_local(event);
  39407. +}
  39408. +
  39409. +void
  39410. +remote_event_pollall(VCHIQ_STATE_T *state)
  39411. +{
  39412. + remote_event_poll(&state->local->sync_trigger);
  39413. + remote_event_poll(&state->local->sync_release);
  39414. + remote_event_poll(&state->local->trigger);
  39415. + remote_event_poll(&state->local->recycle);
  39416. +}
  39417. +
  39418. +/* Round up message sizes so that any space at the end of a slot is always big
  39419. +** enough for a header. This relies on header size being a power of two, which
  39420. +** has been verified earlier by a static assertion. */
  39421. +
  39422. +static inline unsigned int
  39423. +calc_stride(unsigned int size)
  39424. +{
  39425. + /* Allow room for the header */
  39426. + size += sizeof(VCHIQ_HEADER_T);
  39427. +
  39428. + /* Round up */
  39429. + return (size + sizeof(VCHIQ_HEADER_T) - 1) & ~(sizeof(VCHIQ_HEADER_T)
  39430. + - 1);
  39431. +}
  39432. +
  39433. +/* Called by the slot handler thread */
  39434. +static VCHIQ_SERVICE_T *
  39435. +get_listening_service(VCHIQ_STATE_T *state, int fourcc)
  39436. +{
  39437. + int i;
  39438. +
  39439. + WARN_ON(fourcc == VCHIQ_FOURCC_INVALID);
  39440. +
  39441. + for (i = 0; i < state->unused_service; i++) {
  39442. + VCHIQ_SERVICE_T *service = state->services[i];
  39443. + if (service &&
  39444. + (service->public_fourcc == fourcc) &&
  39445. + ((service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  39446. + ((service->srvstate == VCHIQ_SRVSTATE_OPEN) &&
  39447. + (service->remoteport == VCHIQ_PORT_FREE)))) {
  39448. + lock_service(service);
  39449. + return service;
  39450. + }
  39451. + }
  39452. +
  39453. + return NULL;
  39454. +}
  39455. +
  39456. +/* Called by the slot handler thread */
  39457. +static VCHIQ_SERVICE_T *
  39458. +get_connected_service(VCHIQ_STATE_T *state, unsigned int port)
  39459. +{
  39460. + int i;
  39461. + for (i = 0; i < state->unused_service; i++) {
  39462. + VCHIQ_SERVICE_T *service = state->services[i];
  39463. + if (service && (service->srvstate == VCHIQ_SRVSTATE_OPEN)
  39464. + && (service->remoteport == port)) {
  39465. + lock_service(service);
  39466. + return service;
  39467. + }
  39468. + }
  39469. + return NULL;
  39470. +}
  39471. +
  39472. +inline void
  39473. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type)
  39474. +{
  39475. + uint32_t value;
  39476. +
  39477. + if (service) {
  39478. + do {
  39479. + value = atomic_read(&service->poll_flags);
  39480. + } while (atomic_cmpxchg(&service->poll_flags, value,
  39481. + value | (1 << poll_type)) != value);
  39482. +
  39483. + do {
  39484. + value = atomic_read(&state->poll_services[
  39485. + service->localport>>5]);
  39486. + } while (atomic_cmpxchg(
  39487. + &state->poll_services[service->localport>>5],
  39488. + value, value | (1 << (service->localport & 0x1f)))
  39489. + != value);
  39490. + }
  39491. +
  39492. + state->poll_needed = 1;
  39493. + wmb();
  39494. +
  39495. + /* ... and ensure the slot handler runs. */
  39496. + remote_event_signal_local(&state->local->trigger);
  39497. +}
  39498. +
  39499. +/* Called from queue_message, by the slot handler and application threads,
  39500. +** with slot_mutex held */
  39501. +static VCHIQ_HEADER_T *
  39502. +reserve_space(VCHIQ_STATE_T *state, int space, int is_blocking)
  39503. +{
  39504. + VCHIQ_SHARED_STATE_T *local = state->local;
  39505. + int tx_pos = state->local_tx_pos;
  39506. + int slot_space = VCHIQ_SLOT_SIZE - (tx_pos & VCHIQ_SLOT_MASK);
  39507. +
  39508. + if (space > slot_space) {
  39509. + VCHIQ_HEADER_T *header;
  39510. + /* Fill the remaining space with padding */
  39511. + WARN_ON(state->tx_data == NULL);
  39512. + header = (VCHIQ_HEADER_T *)
  39513. + (state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  39514. + header->msgid = VCHIQ_MSGID_PADDING;
  39515. + header->size = slot_space - sizeof(VCHIQ_HEADER_T);
  39516. +
  39517. + tx_pos += slot_space;
  39518. + }
  39519. +
  39520. + /* If necessary, get the next slot. */
  39521. + if ((tx_pos & VCHIQ_SLOT_MASK) == 0) {
  39522. + int slot_index;
  39523. +
  39524. + /* If there is no free slot... */
  39525. +
  39526. + if (down_trylock(&state->slot_available_event) != 0) {
  39527. + /* ...wait for one. */
  39528. +
  39529. + VCHIQ_STATS_INC(state, slot_stalls);
  39530. +
  39531. + /* But first, flush through the last slot. */
  39532. + state->local_tx_pos = tx_pos;
  39533. + local->tx_pos = tx_pos;
  39534. + remote_event_signal(&state->remote->trigger);
  39535. +
  39536. + if (!is_blocking ||
  39537. + (down_interruptible(
  39538. + &state->slot_available_event) != 0))
  39539. + return NULL; /* No space available */
  39540. + }
  39541. +
  39542. + BUG_ON(tx_pos ==
  39543. + (state->slot_queue_available * VCHIQ_SLOT_SIZE));
  39544. +
  39545. + slot_index = local->slot_queue[
  39546. + SLOT_QUEUE_INDEX_FROM_POS(tx_pos) &
  39547. + VCHIQ_SLOT_QUEUE_MASK];
  39548. + state->tx_data =
  39549. + (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  39550. + }
  39551. +
  39552. + state->local_tx_pos = tx_pos + space;
  39553. +
  39554. + return (VCHIQ_HEADER_T *)(state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  39555. +}
  39556. +
  39557. +/* Called by the recycle thread. */
  39558. +static void
  39559. +process_free_queue(VCHIQ_STATE_T *state)
  39560. +{
  39561. + VCHIQ_SHARED_STATE_T *local = state->local;
  39562. + BITSET_T service_found[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  39563. + int slot_queue_available;
  39564. +
  39565. + /* Use a read memory barrier to ensure that any state that may have
  39566. + ** been modified by another thread is not masked by stale prefetched
  39567. + ** values. */
  39568. + rmb();
  39569. +
  39570. + /* Find slots which have been freed by the other side, and return them
  39571. + ** to the available queue. */
  39572. + slot_queue_available = state->slot_queue_available;
  39573. +
  39574. + while (slot_queue_available != local->slot_queue_recycle) {
  39575. + unsigned int pos;
  39576. + int slot_index = local->slot_queue[slot_queue_available++ &
  39577. + VCHIQ_SLOT_QUEUE_MASK];
  39578. + char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  39579. + int data_found = 0;
  39580. +
  39581. + vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%x %x %x",
  39582. + state->id, slot_index, (unsigned int)data,
  39583. + local->slot_queue_recycle, slot_queue_available);
  39584. +
  39585. + /* Initialise the bitmask for services which have used this
  39586. + ** slot */
  39587. + BITSET_ZERO(service_found);
  39588. +
  39589. + pos = 0;
  39590. +
  39591. + while (pos < VCHIQ_SLOT_SIZE) {
  39592. + VCHIQ_HEADER_T *header =
  39593. + (VCHIQ_HEADER_T *)(data + pos);
  39594. + int msgid = header->msgid;
  39595. + if (VCHIQ_MSG_TYPE(msgid) == VCHIQ_MSG_DATA) {
  39596. + int port = VCHIQ_MSG_SRCPORT(msgid);
  39597. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  39598. + &state->service_quotas[port];
  39599. + int count;
  39600. + spin_lock(&quota_spinlock);
  39601. + count = service_quota->message_use_count;
  39602. + if (count > 0)
  39603. + service_quota->message_use_count =
  39604. + count - 1;
  39605. + spin_unlock(&quota_spinlock);
  39606. +
  39607. + if (count == service_quota->message_quota)
  39608. + /* Signal the service that it
  39609. + ** has dropped below its quota
  39610. + */
  39611. + up(&service_quota->quota_event);
  39612. + else if (count == 0) {
  39613. + vchiq_log_error(vchiq_core_log_level,
  39614. + "service %d "
  39615. + "message_use_count=%d "
  39616. + "(header %x, msgid %x, "
  39617. + "header->msgid %x, "
  39618. + "header->size %x)",
  39619. + port,
  39620. + service_quota->
  39621. + message_use_count,
  39622. + (unsigned int)header, msgid,
  39623. + header->msgid,
  39624. + header->size);
  39625. + WARN(1, "invalid message use count\n");
  39626. + }
  39627. + if (!BITSET_IS_SET(service_found, port)) {
  39628. + /* Set the found bit for this service */
  39629. + BITSET_SET(service_found, port);
  39630. +
  39631. + spin_lock(&quota_spinlock);
  39632. + count = service_quota->slot_use_count;
  39633. + if (count > 0)
  39634. + service_quota->slot_use_count =
  39635. + count - 1;
  39636. + spin_unlock(&quota_spinlock);
  39637. +
  39638. + if (count > 0) {
  39639. + /* Signal the service in case
  39640. + ** it has dropped below its
  39641. + ** quota */
  39642. + up(&service_quota->quota_event);
  39643. + vchiq_log_trace(
  39644. + vchiq_core_log_level,
  39645. + "%d: pfq:%d %x@%x - "
  39646. + "slot_use->%d",
  39647. + state->id, port,
  39648. + header->size,
  39649. + (unsigned int)header,
  39650. + count - 1);
  39651. + } else {
  39652. + vchiq_log_error(
  39653. + vchiq_core_log_level,
  39654. + "service %d "
  39655. + "slot_use_count"
  39656. + "=%d (header %x"
  39657. + ", msgid %x, "
  39658. + "header->msgid"
  39659. + " %x, header->"
  39660. + "size %x)",
  39661. + port, count,
  39662. + (unsigned int)header,
  39663. + msgid,
  39664. + header->msgid,
  39665. + header->size);
  39666. + WARN(1, "bad slot use count\n");
  39667. + }
  39668. + }
  39669. +
  39670. + data_found = 1;
  39671. + }
  39672. +
  39673. + pos += calc_stride(header->size);
  39674. + if (pos > VCHIQ_SLOT_SIZE) {
  39675. + vchiq_log_error(vchiq_core_log_level,
  39676. + "pfq - pos %x: header %x, msgid %x, "
  39677. + "header->msgid %x, header->size %x",
  39678. + pos, (unsigned int)header, msgid,
  39679. + header->msgid, header->size);
  39680. + WARN(1, "invalid slot position\n");
  39681. + }
  39682. + }
  39683. +
  39684. + if (data_found) {
  39685. + int count;
  39686. + spin_lock(&quota_spinlock);
  39687. + count = state->data_use_count;
  39688. + if (count > 0)
  39689. + state->data_use_count =
  39690. + count - 1;
  39691. + spin_unlock(&quota_spinlock);
  39692. + if (count == state->data_quota)
  39693. + up(&state->data_quota_event);
  39694. + }
  39695. +
  39696. + state->slot_queue_available = slot_queue_available;
  39697. + up(&state->slot_available_event);
  39698. + }
  39699. +}
  39700. +
  39701. +/* Called by the slot handler and application threads */
  39702. +static VCHIQ_STATUS_T
  39703. +queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  39704. + int msgid, const VCHIQ_ELEMENT_T *elements,
  39705. + int count, int size, int is_blocking)
  39706. +{
  39707. + VCHIQ_SHARED_STATE_T *local;
  39708. + VCHIQ_SERVICE_QUOTA_T *service_quota = NULL;
  39709. + VCHIQ_HEADER_T *header;
  39710. + int type = VCHIQ_MSG_TYPE(msgid);
  39711. +
  39712. + unsigned int stride;
  39713. +
  39714. + local = state->local;
  39715. +
  39716. + stride = calc_stride(size);
  39717. +
  39718. + WARN_ON(!(stride <= VCHIQ_SLOT_SIZE));
  39719. +
  39720. + if ((type != VCHIQ_MSG_RESUME) &&
  39721. + (mutex_lock_interruptible(&state->slot_mutex) != 0))
  39722. + return VCHIQ_RETRY;
  39723. +
  39724. + if (type == VCHIQ_MSG_DATA) {
  39725. + int tx_end_index;
  39726. +
  39727. + BUG_ON(!service);
  39728. +
  39729. + if (service->closing) {
  39730. + /* The service has been closed */
  39731. + mutex_unlock(&state->slot_mutex);
  39732. + return VCHIQ_ERROR;
  39733. + }
  39734. +
  39735. + service_quota = &state->service_quotas[service->localport];
  39736. +
  39737. + spin_lock(&quota_spinlock);
  39738. +
  39739. + /* Ensure this service doesn't use more than its quota of
  39740. + ** messages or slots */
  39741. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  39742. + state->local_tx_pos + stride - 1);
  39743. +
  39744. + /* Ensure data messages don't use more than their quota of
  39745. + ** slots */
  39746. + while ((tx_end_index != state->previous_data_index) &&
  39747. + (state->data_use_count == state->data_quota)) {
  39748. + VCHIQ_STATS_INC(state, data_stalls);
  39749. + spin_unlock(&quota_spinlock);
  39750. + mutex_unlock(&state->slot_mutex);
  39751. +
  39752. + if (down_interruptible(&state->data_quota_event)
  39753. + != 0)
  39754. + return VCHIQ_RETRY;
  39755. +
  39756. + mutex_lock(&state->slot_mutex);
  39757. + spin_lock(&quota_spinlock);
  39758. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  39759. + state->local_tx_pos + stride - 1);
  39760. + if ((tx_end_index == state->previous_data_index) ||
  39761. + (state->data_use_count < state->data_quota)) {
  39762. + /* Pass the signal on to other waiters */
  39763. + up(&state->data_quota_event);
  39764. + break;
  39765. + }
  39766. + }
  39767. +
  39768. + while ((service_quota->message_use_count ==
  39769. + service_quota->message_quota) ||
  39770. + ((tx_end_index != service_quota->previous_tx_index) &&
  39771. + (service_quota->slot_use_count ==
  39772. + service_quota->slot_quota))) {
  39773. + spin_unlock(&quota_spinlock);
  39774. + vchiq_log_trace(vchiq_core_log_level,
  39775. + "%d: qm:%d %s,%x - quota stall "
  39776. + "(msg %d, slot %d)",
  39777. + state->id, service->localport,
  39778. + msg_type_str(type), size,
  39779. + service_quota->message_use_count,
  39780. + service_quota->slot_use_count);
  39781. + VCHIQ_SERVICE_STATS_INC(service, quota_stalls);
  39782. + mutex_unlock(&state->slot_mutex);
  39783. + if (down_interruptible(&service_quota->quota_event)
  39784. + != 0)
  39785. + return VCHIQ_RETRY;
  39786. + if (service->closing)
  39787. + return VCHIQ_ERROR;
  39788. + if (mutex_lock_interruptible(&state->slot_mutex) != 0)
  39789. + return VCHIQ_RETRY;
  39790. + if (service->srvstate != VCHIQ_SRVSTATE_OPEN) {
  39791. + /* The service has been closed */
  39792. + mutex_unlock(&state->slot_mutex);
  39793. + return VCHIQ_ERROR;
  39794. + }
  39795. + spin_lock(&quota_spinlock);
  39796. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  39797. + state->local_tx_pos + stride - 1);
  39798. + }
  39799. +
  39800. + spin_unlock(&quota_spinlock);
  39801. + }
  39802. +
  39803. + header = reserve_space(state, stride, is_blocking);
  39804. +
  39805. + if (!header) {
  39806. + if (service)
  39807. + VCHIQ_SERVICE_STATS_INC(service, slot_stalls);
  39808. + mutex_unlock(&state->slot_mutex);
  39809. + return VCHIQ_RETRY;
  39810. + }
  39811. +
  39812. + if (type == VCHIQ_MSG_DATA) {
  39813. + int i, pos;
  39814. + int tx_end_index;
  39815. + int slot_use_count;
  39816. +
  39817. + vchiq_log_info(vchiq_core_log_level,
  39818. + "%d: qm %s@%x,%x (%d->%d)",
  39819. + state->id,
  39820. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  39821. + (unsigned int)header, size,
  39822. + VCHIQ_MSG_SRCPORT(msgid),
  39823. + VCHIQ_MSG_DSTPORT(msgid));
  39824. +
  39825. + BUG_ON(!service);
  39826. +
  39827. + for (i = 0, pos = 0; i < (unsigned int)count;
  39828. + pos += elements[i++].size)
  39829. + if (elements[i].size) {
  39830. + if (vchiq_copy_from_user
  39831. + (header->data + pos, elements[i].data,
  39832. + (size_t) elements[i].size) !=
  39833. + VCHIQ_SUCCESS) {
  39834. + mutex_unlock(&state->slot_mutex);
  39835. + VCHIQ_SERVICE_STATS_INC(service,
  39836. + error_count);
  39837. + return VCHIQ_ERROR;
  39838. + }
  39839. + if (i == 0) {
  39840. + if (SRVTRACE_ENABLED(service,
  39841. + VCHIQ_LOG_INFO))
  39842. + vchiq_log_dump_mem("Sent", 0,
  39843. + header->data + pos,
  39844. + min(64u,
  39845. + elements[0].size));
  39846. + }
  39847. + }
  39848. +
  39849. + spin_lock(&quota_spinlock);
  39850. + service_quota->message_use_count++;
  39851. +
  39852. + tx_end_index =
  39853. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos - 1);
  39854. +
  39855. + /* If this transmission can't fit in the last slot used by any
  39856. + ** service, the data_use_count must be increased. */
  39857. + if (tx_end_index != state->previous_data_index) {
  39858. + state->previous_data_index = tx_end_index;
  39859. + state->data_use_count++;
  39860. + }
  39861. +
  39862. + /* If this isn't the same slot last used by this service,
  39863. + ** the service's slot_use_count must be increased. */
  39864. + if (tx_end_index != service_quota->previous_tx_index) {
  39865. + service_quota->previous_tx_index = tx_end_index;
  39866. + slot_use_count = ++service_quota->slot_use_count;
  39867. + } else {
  39868. + slot_use_count = 0;
  39869. + }
  39870. +
  39871. + spin_unlock(&quota_spinlock);
  39872. +
  39873. + if (slot_use_count)
  39874. + vchiq_log_trace(vchiq_core_log_level,
  39875. + "%d: qm:%d %s,%x - slot_use->%d (hdr %p)",
  39876. + state->id, service->localport,
  39877. + msg_type_str(VCHIQ_MSG_TYPE(msgid)), size,
  39878. + slot_use_count, header);
  39879. +
  39880. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  39881. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  39882. + } else {
  39883. + vchiq_log_info(vchiq_core_log_level,
  39884. + "%d: qm %s@%x,%x (%d->%d)", state->id,
  39885. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  39886. + (unsigned int)header, size,
  39887. + VCHIQ_MSG_SRCPORT(msgid),
  39888. + VCHIQ_MSG_DSTPORT(msgid));
  39889. + if (size != 0) {
  39890. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  39891. + memcpy(header->data, elements[0].data,
  39892. + elements[0].size);
  39893. + }
  39894. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  39895. + }
  39896. +
  39897. + header->msgid = msgid;
  39898. + header->size = size;
  39899. +
  39900. + {
  39901. + int svc_fourcc;
  39902. +
  39903. + svc_fourcc = service
  39904. + ? service->base.fourcc
  39905. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  39906. +
  39907. + vchiq_log_info(SRVTRACE_LEVEL(service),
  39908. + "Sent Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  39909. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  39910. + VCHIQ_MSG_TYPE(msgid),
  39911. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  39912. + VCHIQ_MSG_SRCPORT(msgid),
  39913. + VCHIQ_MSG_DSTPORT(msgid),
  39914. + size);
  39915. + }
  39916. +
  39917. + /* Make sure the new header is visible to the peer. */
  39918. + wmb();
  39919. +
  39920. + /* Make the new tx_pos visible to the peer. */
  39921. + local->tx_pos = state->local_tx_pos;
  39922. + wmb();
  39923. +
  39924. + if (service && (type == VCHIQ_MSG_CLOSE))
  39925. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_CLOSESENT);
  39926. +
  39927. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  39928. + mutex_unlock(&state->slot_mutex);
  39929. +
  39930. + remote_event_signal(&state->remote->trigger);
  39931. +
  39932. + return VCHIQ_SUCCESS;
  39933. +}
  39934. +
  39935. +/* Called by the slot handler and application threads */
  39936. +static VCHIQ_STATUS_T
  39937. +queue_message_sync(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  39938. + int msgid, const VCHIQ_ELEMENT_T *elements,
  39939. + int count, int size, int is_blocking)
  39940. +{
  39941. + VCHIQ_SHARED_STATE_T *local;
  39942. + VCHIQ_HEADER_T *header;
  39943. +
  39944. + local = state->local;
  39945. +
  39946. + if ((VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_RESUME) &&
  39947. + (mutex_lock_interruptible(&state->sync_mutex) != 0))
  39948. + return VCHIQ_RETRY;
  39949. +
  39950. + remote_event_wait(&local->sync_release);
  39951. +
  39952. + rmb();
  39953. +
  39954. + header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  39955. + local->slot_sync);
  39956. +
  39957. + {
  39958. + int oldmsgid = header->msgid;
  39959. + if (oldmsgid != VCHIQ_MSGID_PADDING)
  39960. + vchiq_log_error(vchiq_core_log_level,
  39961. + "%d: qms - msgid %x, not PADDING",
  39962. + state->id, oldmsgid);
  39963. + }
  39964. +
  39965. + if (service) {
  39966. + int i, pos;
  39967. +
  39968. + vchiq_log_info(vchiq_sync_log_level,
  39969. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  39970. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  39971. + (unsigned int)header, size,
  39972. + VCHIQ_MSG_SRCPORT(msgid),
  39973. + VCHIQ_MSG_DSTPORT(msgid));
  39974. +
  39975. + for (i = 0, pos = 0; i < (unsigned int)count;
  39976. + pos += elements[i++].size)
  39977. + if (elements[i].size) {
  39978. + if (vchiq_copy_from_user
  39979. + (header->data + pos, elements[i].data,
  39980. + (size_t) elements[i].size) !=
  39981. + VCHIQ_SUCCESS) {
  39982. + mutex_unlock(&state->sync_mutex);
  39983. + VCHIQ_SERVICE_STATS_INC(service,
  39984. + error_count);
  39985. + return VCHIQ_ERROR;
  39986. + }
  39987. + if (i == 0) {
  39988. + if (vchiq_sync_log_level >=
  39989. + VCHIQ_LOG_TRACE)
  39990. + vchiq_log_dump_mem("Sent Sync",
  39991. + 0, header->data + pos,
  39992. + min(64u,
  39993. + elements[0].size));
  39994. + }
  39995. + }
  39996. +
  39997. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  39998. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  39999. + } else {
  40000. + vchiq_log_info(vchiq_sync_log_level,
  40001. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  40002. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  40003. + (unsigned int)header, size,
  40004. + VCHIQ_MSG_SRCPORT(msgid),
  40005. + VCHIQ_MSG_DSTPORT(msgid));
  40006. + if (size != 0) {
  40007. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  40008. + memcpy(header->data, elements[0].data,
  40009. + elements[0].size);
  40010. + }
  40011. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  40012. + }
  40013. +
  40014. + header->size = size;
  40015. + header->msgid = msgid;
  40016. +
  40017. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  40018. + int svc_fourcc;
  40019. +
  40020. + svc_fourcc = service
  40021. + ? service->base.fourcc
  40022. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  40023. +
  40024. + vchiq_log_trace(vchiq_sync_log_level,
  40025. + "Sent Sync Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  40026. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  40027. + VCHIQ_MSG_TYPE(msgid),
  40028. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  40029. + VCHIQ_MSG_SRCPORT(msgid),
  40030. + VCHIQ_MSG_DSTPORT(msgid),
  40031. + size);
  40032. + }
  40033. +
  40034. + /* Make sure the new header is visible to the peer. */
  40035. + wmb();
  40036. +
  40037. + remote_event_signal(&state->remote->sync_trigger);
  40038. +
  40039. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  40040. + mutex_unlock(&state->sync_mutex);
  40041. +
  40042. + return VCHIQ_SUCCESS;
  40043. +}
  40044. +
  40045. +static inline void
  40046. +claim_slot(VCHIQ_SLOT_INFO_T *slot)
  40047. +{
  40048. + slot->use_count++;
  40049. +}
  40050. +
  40051. +static void
  40052. +release_slot(VCHIQ_STATE_T *state, VCHIQ_SLOT_INFO_T *slot_info,
  40053. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_T *service)
  40054. +{
  40055. + int release_count;
  40056. +
  40057. + mutex_lock(&state->recycle_mutex);
  40058. +
  40059. + if (header) {
  40060. + int msgid = header->msgid;
  40061. + if (((msgid & VCHIQ_MSGID_CLAIMED) == 0) ||
  40062. + (service && service->closing)) {
  40063. + mutex_unlock(&state->recycle_mutex);
  40064. + return;
  40065. + }
  40066. +
  40067. + /* Rewrite the message header to prevent a double
  40068. + ** release */
  40069. + header->msgid = msgid & ~VCHIQ_MSGID_CLAIMED;
  40070. + }
  40071. +
  40072. + release_count = slot_info->release_count;
  40073. + slot_info->release_count = ++release_count;
  40074. +
  40075. + if (release_count == slot_info->use_count) {
  40076. + int slot_queue_recycle;
  40077. + /* Add to the freed queue */
  40078. +
  40079. + /* A read barrier is necessary here to prevent speculative
  40080. + ** fetches of remote->slot_queue_recycle from overtaking the
  40081. + ** mutex. */
  40082. + rmb();
  40083. +
  40084. + slot_queue_recycle = state->remote->slot_queue_recycle;
  40085. + state->remote->slot_queue[slot_queue_recycle &
  40086. + VCHIQ_SLOT_QUEUE_MASK] =
  40087. + SLOT_INDEX_FROM_INFO(state, slot_info);
  40088. + state->remote->slot_queue_recycle = slot_queue_recycle + 1;
  40089. + vchiq_log_info(vchiq_core_log_level,
  40090. + "%d: release_slot %d - recycle->%x",
  40091. + state->id, SLOT_INDEX_FROM_INFO(state, slot_info),
  40092. + state->remote->slot_queue_recycle);
  40093. +
  40094. + /* A write barrier is necessary, but remote_event_signal
  40095. + ** contains one. */
  40096. + remote_event_signal(&state->remote->recycle);
  40097. + }
  40098. +
  40099. + mutex_unlock(&state->recycle_mutex);
  40100. +}
  40101. +
  40102. +/* Called by the slot handler - don't hold the bulk mutex */
  40103. +static VCHIQ_STATUS_T
  40104. +notify_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue,
  40105. + int retry_poll)
  40106. +{
  40107. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  40108. +
  40109. + vchiq_log_trace(vchiq_core_log_level,
  40110. + "%d: nb:%d %cx - p=%x rn=%x r=%x",
  40111. + service->state->id, service->localport,
  40112. + (queue == &service->bulk_tx) ? 't' : 'r',
  40113. + queue->process, queue->remote_notify, queue->remove);
  40114. +
  40115. + if (service->state->is_master) {
  40116. + while (queue->remote_notify != queue->process) {
  40117. + VCHIQ_BULK_T *bulk =
  40118. + &queue->bulks[BULK_INDEX(queue->remote_notify)];
  40119. + int msgtype = (bulk->dir == VCHIQ_BULK_TRANSMIT) ?
  40120. + VCHIQ_MSG_BULK_RX_DONE : VCHIQ_MSG_BULK_TX_DONE;
  40121. + int msgid = VCHIQ_MAKE_MSG(msgtype, service->localport,
  40122. + service->remoteport);
  40123. + VCHIQ_ELEMENT_T element = { &bulk->actual, 4 };
  40124. + /* Only reply to non-dummy bulk requests */
  40125. + if (bulk->remote_data) {
  40126. + status = queue_message(service->state, NULL,
  40127. + msgid, &element, 1, 4, 0);
  40128. + if (status != VCHIQ_SUCCESS)
  40129. + break;
  40130. + }
  40131. + queue->remote_notify++;
  40132. + }
  40133. + } else {
  40134. + queue->remote_notify = queue->process;
  40135. + }
  40136. +
  40137. + if (status == VCHIQ_SUCCESS) {
  40138. + while (queue->remove != queue->remote_notify) {
  40139. + VCHIQ_BULK_T *bulk =
  40140. + &queue->bulks[BULK_INDEX(queue->remove)];
  40141. +
  40142. + /* Only generate callbacks for non-dummy bulk
  40143. + ** requests, and non-terminated services */
  40144. + if (bulk->data && service->instance) {
  40145. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
  40146. + if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
  40147. + VCHIQ_SERVICE_STATS_INC(service,
  40148. + bulk_tx_count);
  40149. + VCHIQ_SERVICE_STATS_ADD(service,
  40150. + bulk_tx_bytes,
  40151. + bulk->actual);
  40152. + } else {
  40153. + VCHIQ_SERVICE_STATS_INC(service,
  40154. + bulk_rx_count);
  40155. + VCHIQ_SERVICE_STATS_ADD(service,
  40156. + bulk_rx_bytes,
  40157. + bulk->actual);
  40158. + }
  40159. + } else {
  40160. + VCHIQ_SERVICE_STATS_INC(service,
  40161. + bulk_aborted_count);
  40162. + }
  40163. + if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
  40164. + struct bulk_waiter *waiter;
  40165. + spin_lock(&bulk_waiter_spinlock);
  40166. + waiter = bulk->userdata;
  40167. + if (waiter) {
  40168. + waiter->actual = bulk->actual;
  40169. + up(&waiter->event);
  40170. + }
  40171. + spin_unlock(&bulk_waiter_spinlock);
  40172. + } else if (bulk->mode ==
  40173. + VCHIQ_BULK_MODE_CALLBACK) {
  40174. + VCHIQ_REASON_T reason = (bulk->dir ==
  40175. + VCHIQ_BULK_TRANSMIT) ?
  40176. + ((bulk->actual ==
  40177. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  40178. + VCHIQ_BULK_TRANSMIT_ABORTED :
  40179. + VCHIQ_BULK_TRANSMIT_DONE) :
  40180. + ((bulk->actual ==
  40181. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  40182. + VCHIQ_BULK_RECEIVE_ABORTED :
  40183. + VCHIQ_BULK_RECEIVE_DONE);
  40184. + status = make_service_callback(service,
  40185. + reason, NULL, bulk->userdata);
  40186. + if (status == VCHIQ_RETRY)
  40187. + break;
  40188. + }
  40189. + }
  40190. +
  40191. + queue->remove++;
  40192. + up(&service->bulk_remove_event);
  40193. + }
  40194. + if (!retry_poll)
  40195. + status = VCHIQ_SUCCESS;
  40196. + }
  40197. +
  40198. + if (status == VCHIQ_RETRY)
  40199. + request_poll(service->state, service,
  40200. + (queue == &service->bulk_tx) ?
  40201. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  40202. +
  40203. + return status;
  40204. +}
  40205. +
  40206. +/* Called by the slot handler thread */
  40207. +static void
  40208. +poll_services(VCHIQ_STATE_T *state)
  40209. +{
  40210. + int group, i;
  40211. +
  40212. + for (group = 0; group < BITSET_SIZE(state->unused_service); group++) {
  40213. + uint32_t flags;
  40214. + flags = atomic_xchg(&state->poll_services[group], 0);
  40215. + for (i = 0; flags; i++) {
  40216. + if (flags & (1 << i)) {
  40217. + VCHIQ_SERVICE_T *service =
  40218. + find_service_by_port(state,
  40219. + (group<<5) + i);
  40220. + uint32_t service_flags;
  40221. + flags &= ~(1 << i);
  40222. + if (!service)
  40223. + continue;
  40224. + service_flags =
  40225. + atomic_xchg(&service->poll_flags, 0);
  40226. + if (service_flags &
  40227. + (1 << VCHIQ_POLL_REMOVE)) {
  40228. + vchiq_log_info(vchiq_core_log_level,
  40229. + "%d: ps - remove %d<->%d",
  40230. + state->id, service->localport,
  40231. + service->remoteport);
  40232. +
  40233. + /* Make it look like a client, because
  40234. + it must be removed and not left in
  40235. + the LISTENING state. */
  40236. + service->public_fourcc =
  40237. + VCHIQ_FOURCC_INVALID;
  40238. +
  40239. + if (vchiq_close_service_internal(
  40240. + service, 0/*!close_recvd*/) !=
  40241. + VCHIQ_SUCCESS)
  40242. + request_poll(state, service,
  40243. + VCHIQ_POLL_REMOVE);
  40244. + } else if (service_flags &
  40245. + (1 << VCHIQ_POLL_TERMINATE)) {
  40246. + vchiq_log_info(vchiq_core_log_level,
  40247. + "%d: ps - terminate %d<->%d",
  40248. + state->id, service->localport,
  40249. + service->remoteport);
  40250. + if (vchiq_close_service_internal(
  40251. + service, 0/*!close_recvd*/) !=
  40252. + VCHIQ_SUCCESS)
  40253. + request_poll(state, service,
  40254. + VCHIQ_POLL_TERMINATE);
  40255. + }
  40256. + if (service_flags & (1 << VCHIQ_POLL_TXNOTIFY))
  40257. + notify_bulks(service,
  40258. + &service->bulk_tx,
  40259. + 1/*retry_poll*/);
  40260. + if (service_flags & (1 << VCHIQ_POLL_RXNOTIFY))
  40261. + notify_bulks(service,
  40262. + &service->bulk_rx,
  40263. + 1/*retry_poll*/);
  40264. + unlock_service(service);
  40265. + }
  40266. + }
  40267. + }
  40268. +}
  40269. +
  40270. +/* Called by the slot handler or application threads, holding the bulk mutex. */
  40271. +static int
  40272. +resolve_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  40273. +{
  40274. + VCHIQ_STATE_T *state = service->state;
  40275. + int resolved = 0;
  40276. + int rc;
  40277. +
  40278. + while ((queue->process != queue->local_insert) &&
  40279. + (queue->process != queue->remote_insert)) {
  40280. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  40281. +
  40282. + vchiq_log_trace(vchiq_core_log_level,
  40283. + "%d: rb:%d %cx - li=%x ri=%x p=%x",
  40284. + state->id, service->localport,
  40285. + (queue == &service->bulk_tx) ? 't' : 'r',
  40286. + queue->local_insert, queue->remote_insert,
  40287. + queue->process);
  40288. +
  40289. + WARN_ON(!((int)(queue->local_insert - queue->process) > 0));
  40290. + WARN_ON(!((int)(queue->remote_insert - queue->process) > 0));
  40291. +
  40292. + rc = mutex_lock_interruptible(&state->bulk_transfer_mutex);
  40293. + if (rc != 0)
  40294. + break;
  40295. +
  40296. + vchiq_transfer_bulk(bulk);
  40297. + mutex_unlock(&state->bulk_transfer_mutex);
  40298. +
  40299. + if (SRVTRACE_ENABLED(service, VCHIQ_LOG_INFO)) {
  40300. + const char *header = (queue == &service->bulk_tx) ?
  40301. + "Send Bulk to" : "Recv Bulk from";
  40302. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED)
  40303. + vchiq_log_info(SRVTRACE_LEVEL(service),
  40304. + "%s %c%c%c%c d:%d len:%d %x<->%x",
  40305. + header,
  40306. + VCHIQ_FOURCC_AS_4CHARS(
  40307. + service->base.fourcc),
  40308. + service->remoteport,
  40309. + bulk->size,
  40310. + (unsigned int)bulk->data,
  40311. + (unsigned int)bulk->remote_data);
  40312. + else
  40313. + vchiq_log_info(SRVTRACE_LEVEL(service),
  40314. + "%s %c%c%c%c d:%d ABORTED - tx len:%d,"
  40315. + " rx len:%d %x<->%x",
  40316. + header,
  40317. + VCHIQ_FOURCC_AS_4CHARS(
  40318. + service->base.fourcc),
  40319. + service->remoteport,
  40320. + bulk->size,
  40321. + bulk->remote_size,
  40322. + (unsigned int)bulk->data,
  40323. + (unsigned int)bulk->remote_data);
  40324. + }
  40325. +
  40326. + vchiq_complete_bulk(bulk);
  40327. + queue->process++;
  40328. + resolved++;
  40329. + }
  40330. + return resolved;
  40331. +}
  40332. +
  40333. +/* Called with the bulk_mutex held */
  40334. +static void
  40335. +abort_outstanding_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  40336. +{
  40337. + int is_tx = (queue == &service->bulk_tx);
  40338. + vchiq_log_trace(vchiq_core_log_level,
  40339. + "%d: aob:%d %cx - li=%x ri=%x p=%x",
  40340. + service->state->id, service->localport, is_tx ? 't' : 'r',
  40341. + queue->local_insert, queue->remote_insert, queue->process);
  40342. +
  40343. + WARN_ON(!((int)(queue->local_insert - queue->process) >= 0));
  40344. + WARN_ON(!((int)(queue->remote_insert - queue->process) >= 0));
  40345. +
  40346. + while ((queue->process != queue->local_insert) ||
  40347. + (queue->process != queue->remote_insert)) {
  40348. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  40349. +
  40350. + if (queue->process == queue->remote_insert) {
  40351. + /* fabricate a matching dummy bulk */
  40352. + bulk->remote_data = NULL;
  40353. + bulk->remote_size = 0;
  40354. + queue->remote_insert++;
  40355. + }
  40356. +
  40357. + if (queue->process != queue->local_insert) {
  40358. + vchiq_complete_bulk(bulk);
  40359. +
  40360. + vchiq_log_info(SRVTRACE_LEVEL(service),
  40361. + "%s %c%c%c%c d:%d ABORTED - tx len:%d, "
  40362. + "rx len:%d",
  40363. + is_tx ? "Send Bulk to" : "Recv Bulk from",
  40364. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  40365. + service->remoteport,
  40366. + bulk->size,
  40367. + bulk->remote_size);
  40368. + } else {
  40369. + /* fabricate a matching dummy bulk */
  40370. + bulk->data = NULL;
  40371. + bulk->size = 0;
  40372. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  40373. + bulk->dir = is_tx ? VCHIQ_BULK_TRANSMIT :
  40374. + VCHIQ_BULK_RECEIVE;
  40375. + queue->local_insert++;
  40376. + }
  40377. +
  40378. + queue->process++;
  40379. + }
  40380. +}
  40381. +
  40382. +/* Called from the slot handler thread */
  40383. +static void
  40384. +pause_bulks(VCHIQ_STATE_T *state)
  40385. +{
  40386. + if (unlikely(atomic_inc_return(&pause_bulks_count) != 1)) {
  40387. + WARN_ON_ONCE(1);
  40388. + atomic_set(&pause_bulks_count, 1);
  40389. + return;
  40390. + }
  40391. +
  40392. + /* Block bulk transfers from all services */
  40393. + mutex_lock(&state->bulk_transfer_mutex);
  40394. +}
  40395. +
  40396. +/* Called from the slot handler thread */
  40397. +static void
  40398. +resume_bulks(VCHIQ_STATE_T *state)
  40399. +{
  40400. + int i;
  40401. + if (unlikely(atomic_dec_return(&pause_bulks_count) != 0)) {
  40402. + WARN_ON_ONCE(1);
  40403. + atomic_set(&pause_bulks_count, 0);
  40404. + return;
  40405. + }
  40406. +
  40407. + /* Allow bulk transfers from all services */
  40408. + mutex_unlock(&state->bulk_transfer_mutex);
  40409. +
  40410. + if (state->deferred_bulks == 0)
  40411. + return;
  40412. +
  40413. + /* Deal with any bulks which had to be deferred due to being in
  40414. + * paused state. Don't try to match up to number of deferred bulks
  40415. + * in case we've had something come and close the service in the
  40416. + * interim - just process all bulk queues for all services */
  40417. + vchiq_log_info(vchiq_core_log_level, "%s: processing %d deferred bulks",
  40418. + __func__, state->deferred_bulks);
  40419. +
  40420. + for (i = 0; i < state->unused_service; i++) {
  40421. + VCHIQ_SERVICE_T *service = state->services[i];
  40422. + int resolved_rx = 0;
  40423. + int resolved_tx = 0;
  40424. + if (!service || (service->srvstate != VCHIQ_SRVSTATE_OPEN))
  40425. + continue;
  40426. +
  40427. + mutex_lock(&service->bulk_mutex);
  40428. + resolved_rx = resolve_bulks(service, &service->bulk_rx);
  40429. + resolved_tx = resolve_bulks(service, &service->bulk_tx);
  40430. + mutex_unlock(&service->bulk_mutex);
  40431. + if (resolved_rx)
  40432. + notify_bulks(service, &service->bulk_rx, 1);
  40433. + if (resolved_tx)
  40434. + notify_bulks(service, &service->bulk_tx, 1);
  40435. + }
  40436. + state->deferred_bulks = 0;
  40437. +}
  40438. +
  40439. +static int
  40440. +parse_open(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  40441. +{
  40442. + VCHIQ_SERVICE_T *service = NULL;
  40443. + int msgid, size;
  40444. + int type;
  40445. + unsigned int localport, remoteport;
  40446. +
  40447. + msgid = header->msgid;
  40448. + size = header->size;
  40449. + type = VCHIQ_MSG_TYPE(msgid);
  40450. + localport = VCHIQ_MSG_DSTPORT(msgid);
  40451. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  40452. + if (size >= sizeof(struct vchiq_open_payload)) {
  40453. + const struct vchiq_open_payload *payload =
  40454. + (struct vchiq_open_payload *)header->data;
  40455. + unsigned int fourcc;
  40456. +
  40457. + fourcc = payload->fourcc;
  40458. + vchiq_log_info(vchiq_core_log_level,
  40459. + "%d: prs OPEN@%x (%d->'%c%c%c%c')",
  40460. + state->id, (unsigned int)header,
  40461. + localport,
  40462. + VCHIQ_FOURCC_AS_4CHARS(fourcc));
  40463. +
  40464. + service = get_listening_service(state, fourcc);
  40465. +
  40466. + if (service) {
  40467. + /* A matching service exists */
  40468. + short version = payload->version;
  40469. + short version_min = payload->version_min;
  40470. + if ((service->version < version_min) ||
  40471. + (version < service->version_min)) {
  40472. + /* Version mismatch */
  40473. + vchiq_loud_error_header();
  40474. + vchiq_loud_error("%d: service %d (%c%c%c%c) "
  40475. + "version mismatch - local (%d, min %d)"
  40476. + " vs. remote (%d, min %d)",
  40477. + state->id, service->localport,
  40478. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  40479. + service->version, service->version_min,
  40480. + version, version_min);
  40481. + vchiq_loud_error_footer();
  40482. + unlock_service(service);
  40483. + service = NULL;
  40484. + goto fail_open;
  40485. + }
  40486. + service->peer_version = version;
  40487. +
  40488. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  40489. + struct vchiq_openack_payload ack_payload = {
  40490. + service->version
  40491. + };
  40492. + VCHIQ_ELEMENT_T body = {
  40493. + &ack_payload,
  40494. + sizeof(ack_payload)
  40495. + };
  40496. +
  40497. + /* Acknowledge the OPEN */
  40498. + if (service->sync) {
  40499. + if (queue_message_sync(state, NULL,
  40500. + VCHIQ_MAKE_MSG(
  40501. + VCHIQ_MSG_OPENACK,
  40502. + service->localport,
  40503. + remoteport),
  40504. + &body, 1, sizeof(ack_payload),
  40505. + 0) == VCHIQ_RETRY)
  40506. + goto bail_not_ready;
  40507. + } else {
  40508. + if (queue_message(state, NULL,
  40509. + VCHIQ_MAKE_MSG(
  40510. + VCHIQ_MSG_OPENACK,
  40511. + service->localport,
  40512. + remoteport),
  40513. + &body, 1, sizeof(ack_payload),
  40514. + 0) == VCHIQ_RETRY)
  40515. + goto bail_not_ready;
  40516. + }
  40517. +
  40518. + /* The service is now open */
  40519. + vchiq_set_service_state(service,
  40520. + service->sync ? VCHIQ_SRVSTATE_OPENSYNC
  40521. + : VCHIQ_SRVSTATE_OPEN);
  40522. + }
  40523. +
  40524. + service->remoteport = remoteport;
  40525. + service->client_id = ((int *)header->data)[1];
  40526. + if (make_service_callback(service, VCHIQ_SERVICE_OPENED,
  40527. + NULL, NULL) == VCHIQ_RETRY) {
  40528. + /* Bail out if not ready */
  40529. + service->remoteport = VCHIQ_PORT_FREE;
  40530. + goto bail_not_ready;
  40531. + }
  40532. +
  40533. + /* Success - the message has been dealt with */
  40534. + unlock_service(service);
  40535. + return 1;
  40536. + }
  40537. + }
  40538. +
  40539. +fail_open:
  40540. + /* No available service, or an invalid request - send a CLOSE */
  40541. + if (queue_message(state, NULL,
  40542. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)),
  40543. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  40544. + goto bail_not_ready;
  40545. +
  40546. + return 1;
  40547. +
  40548. +bail_not_ready:
  40549. + if (service)
  40550. + unlock_service(service);
  40551. +
  40552. + return 0;
  40553. +}
  40554. +
  40555. +/* Called by the slot handler thread */
  40556. +static void
  40557. +parse_rx_slots(VCHIQ_STATE_T *state)
  40558. +{
  40559. + VCHIQ_SHARED_STATE_T *remote = state->remote;
  40560. + VCHIQ_SERVICE_T *service = NULL;
  40561. + int tx_pos;
  40562. + DEBUG_INITIALISE(state->local)
  40563. +
  40564. + tx_pos = remote->tx_pos;
  40565. +
  40566. + while (state->rx_pos != tx_pos) {
  40567. + VCHIQ_HEADER_T *header;
  40568. + int msgid, size;
  40569. + int type;
  40570. + unsigned int localport, remoteport;
  40571. +
  40572. + DEBUG_TRACE(PARSE_LINE);
  40573. + if (!state->rx_data) {
  40574. + int rx_index;
  40575. + WARN_ON(!((state->rx_pos & VCHIQ_SLOT_MASK) == 0));
  40576. + rx_index = remote->slot_queue[
  40577. + SLOT_QUEUE_INDEX_FROM_POS(state->rx_pos) &
  40578. + VCHIQ_SLOT_QUEUE_MASK];
  40579. + state->rx_data = (char *)SLOT_DATA_FROM_INDEX(state,
  40580. + rx_index);
  40581. + state->rx_info = SLOT_INFO_FROM_INDEX(state, rx_index);
  40582. +
  40583. + /* Initialise use_count to one, and increment
  40584. + ** release_count at the end of the slot to avoid
  40585. + ** releasing the slot prematurely. */
  40586. + state->rx_info->use_count = 1;
  40587. + state->rx_info->release_count = 0;
  40588. + }
  40589. +
  40590. + header = (VCHIQ_HEADER_T *)(state->rx_data +
  40591. + (state->rx_pos & VCHIQ_SLOT_MASK));
  40592. + DEBUG_VALUE(PARSE_HEADER, (int)header);
  40593. + msgid = header->msgid;
  40594. + DEBUG_VALUE(PARSE_MSGID, msgid);
  40595. + size = header->size;
  40596. + type = VCHIQ_MSG_TYPE(msgid);
  40597. + localport = VCHIQ_MSG_DSTPORT(msgid);
  40598. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  40599. +
  40600. + if (type != VCHIQ_MSG_DATA)
  40601. + VCHIQ_STATS_INC(state, ctrl_rx_count);
  40602. +
  40603. + switch (type) {
  40604. + case VCHIQ_MSG_OPENACK:
  40605. + case VCHIQ_MSG_CLOSE:
  40606. + case VCHIQ_MSG_DATA:
  40607. + case VCHIQ_MSG_BULK_RX:
  40608. + case VCHIQ_MSG_BULK_TX:
  40609. + case VCHIQ_MSG_BULK_RX_DONE:
  40610. + case VCHIQ_MSG_BULK_TX_DONE:
  40611. + service = find_service_by_port(state, localport);
  40612. + if ((!service ||
  40613. + ((service->remoteport != remoteport) &&
  40614. + (service->remoteport != VCHIQ_PORT_FREE))) &&
  40615. + (localport == 0) &&
  40616. + (type == VCHIQ_MSG_CLOSE)) {
  40617. + /* This could be a CLOSE from a client which
  40618. + hadn't yet received the OPENACK - look for
  40619. + the connected service */
  40620. + if (service)
  40621. + unlock_service(service);
  40622. + service = get_connected_service(state,
  40623. + remoteport);
  40624. + if (service)
  40625. + vchiq_log_warning(vchiq_core_log_level,
  40626. + "%d: prs %s@%x (%d->%d) - "
  40627. + "found connected service %d",
  40628. + state->id, msg_type_str(type),
  40629. + (unsigned int)header,
  40630. + remoteport, localport,
  40631. + service->localport);
  40632. + }
  40633. +
  40634. + if (!service) {
  40635. + vchiq_log_error(vchiq_core_log_level,
  40636. + "%d: prs %s@%x (%d->%d) - "
  40637. + "invalid/closed service %d",
  40638. + state->id, msg_type_str(type),
  40639. + (unsigned int)header,
  40640. + remoteport, localport, localport);
  40641. + goto skip_message;
  40642. + }
  40643. + break;
  40644. + default:
  40645. + break;
  40646. + }
  40647. +
  40648. + if (SRVTRACE_ENABLED(service, VCHIQ_LOG_INFO)) {
  40649. + int svc_fourcc;
  40650. +
  40651. + svc_fourcc = service
  40652. + ? service->base.fourcc
  40653. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  40654. + vchiq_log_info(SRVTRACE_LEVEL(service),
  40655. + "Rcvd Msg %s(%u) from %c%c%c%c s:%d d:%d "
  40656. + "len:%d",
  40657. + msg_type_str(type), type,
  40658. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  40659. + remoteport, localport, size);
  40660. + if (size > 0)
  40661. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  40662. + min(64, size));
  40663. + }
  40664. +
  40665. + if (((unsigned int)header & VCHIQ_SLOT_MASK) + calc_stride(size)
  40666. + > VCHIQ_SLOT_SIZE) {
  40667. + vchiq_log_error(vchiq_core_log_level,
  40668. + "header %x (msgid %x) - size %x too big for "
  40669. + "slot",
  40670. + (unsigned int)header, (unsigned int)msgid,
  40671. + (unsigned int)size);
  40672. + WARN(1, "oversized for slot\n");
  40673. + }
  40674. +
  40675. + switch (type) {
  40676. + case VCHIQ_MSG_OPEN:
  40677. + WARN_ON(!(VCHIQ_MSG_DSTPORT(msgid) == 0));
  40678. + if (!parse_open(state, header))
  40679. + goto bail_not_ready;
  40680. + break;
  40681. + case VCHIQ_MSG_OPENACK:
  40682. + if (size >= sizeof(struct vchiq_openack_payload)) {
  40683. + const struct vchiq_openack_payload *payload =
  40684. + (struct vchiq_openack_payload *)
  40685. + header->data;
  40686. + service->peer_version = payload->version;
  40687. + }
  40688. + vchiq_log_info(vchiq_core_log_level,
  40689. + "%d: prs OPENACK@%x,%x (%d->%d) v:%d",
  40690. + state->id, (unsigned int)header, size,
  40691. + remoteport, localport, service->peer_version);
  40692. + if (service->srvstate ==
  40693. + VCHIQ_SRVSTATE_OPENING) {
  40694. + service->remoteport = remoteport;
  40695. + vchiq_set_service_state(service,
  40696. + VCHIQ_SRVSTATE_OPEN);
  40697. + up(&service->remove_event);
  40698. + } else
  40699. + vchiq_log_error(vchiq_core_log_level,
  40700. + "OPENACK received in state %s",
  40701. + srvstate_names[service->srvstate]);
  40702. + break;
  40703. + case VCHIQ_MSG_CLOSE:
  40704. + WARN_ON(size != 0); /* There should be no data */
  40705. +
  40706. + vchiq_log_info(vchiq_core_log_level,
  40707. + "%d: prs CLOSE@%x (%d->%d)",
  40708. + state->id, (unsigned int)header,
  40709. + remoteport, localport);
  40710. +
  40711. + mark_service_closing_internal(service, 1);
  40712. +
  40713. + if (vchiq_close_service_internal(service,
  40714. + 1/*close_recvd*/) == VCHIQ_RETRY)
  40715. + goto bail_not_ready;
  40716. +
  40717. + vchiq_log_info(vchiq_core_log_level,
  40718. + "Close Service %c%c%c%c s:%u d:%d",
  40719. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  40720. + service->localport,
  40721. + service->remoteport);
  40722. + break;
  40723. + case VCHIQ_MSG_DATA:
  40724. + vchiq_log_trace(vchiq_core_log_level,
  40725. + "%d: prs DATA@%x,%x (%d->%d)",
  40726. + state->id, (unsigned int)header, size,
  40727. + remoteport, localport);
  40728. +
  40729. + if ((service->remoteport == remoteport)
  40730. + && (service->srvstate ==
  40731. + VCHIQ_SRVSTATE_OPEN)) {
  40732. + header->msgid = msgid | VCHIQ_MSGID_CLAIMED;
  40733. + claim_slot(state->rx_info);
  40734. + DEBUG_TRACE(PARSE_LINE);
  40735. + if (make_service_callback(service,
  40736. + VCHIQ_MESSAGE_AVAILABLE, header,
  40737. + NULL) == VCHIQ_RETRY) {
  40738. + DEBUG_TRACE(PARSE_LINE);
  40739. + goto bail_not_ready;
  40740. + }
  40741. + VCHIQ_SERVICE_STATS_INC(service, ctrl_rx_count);
  40742. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_rx_bytes,
  40743. + size);
  40744. + } else {
  40745. + VCHIQ_STATS_INC(state, error_count);
  40746. + }
  40747. + break;
  40748. + case VCHIQ_MSG_CONNECT:
  40749. + vchiq_log_info(vchiq_core_log_level,
  40750. + "%d: prs CONNECT@%x",
  40751. + state->id, (unsigned int)header);
  40752. + up(&state->connect);
  40753. + break;
  40754. + case VCHIQ_MSG_BULK_RX:
  40755. + case VCHIQ_MSG_BULK_TX: {
  40756. + VCHIQ_BULK_QUEUE_T *queue;
  40757. + WARN_ON(!state->is_master);
  40758. + queue = (type == VCHIQ_MSG_BULK_RX) ?
  40759. + &service->bulk_tx : &service->bulk_rx;
  40760. + if ((service->remoteport == remoteport)
  40761. + && (service->srvstate ==
  40762. + VCHIQ_SRVSTATE_OPEN)) {
  40763. + VCHIQ_BULK_T *bulk;
  40764. + int resolved = 0;
  40765. +
  40766. + DEBUG_TRACE(PARSE_LINE);
  40767. + if (mutex_lock_interruptible(
  40768. + &service->bulk_mutex) != 0) {
  40769. + DEBUG_TRACE(PARSE_LINE);
  40770. + goto bail_not_ready;
  40771. + }
  40772. +
  40773. + WARN_ON(!(queue->remote_insert < queue->remove +
  40774. + VCHIQ_NUM_SERVICE_BULKS));
  40775. + bulk = &queue->bulks[
  40776. + BULK_INDEX(queue->remote_insert)];
  40777. + bulk->remote_data =
  40778. + (void *)((int *)header->data)[0];
  40779. + bulk->remote_size = ((int *)header->data)[1];
  40780. + wmb();
  40781. +
  40782. + vchiq_log_info(vchiq_core_log_level,
  40783. + "%d: prs %s@%x (%d->%d) %x@%x",
  40784. + state->id, msg_type_str(type),
  40785. + (unsigned int)header,
  40786. + remoteport, localport,
  40787. + bulk->remote_size,
  40788. + (unsigned int)bulk->remote_data);
  40789. +
  40790. + queue->remote_insert++;
  40791. +
  40792. + if (atomic_read(&pause_bulks_count)) {
  40793. + state->deferred_bulks++;
  40794. + vchiq_log_info(vchiq_core_log_level,
  40795. + "%s: deferring bulk (%d)",
  40796. + __func__,
  40797. + state->deferred_bulks);
  40798. + if (state->conn_state !=
  40799. + VCHIQ_CONNSTATE_PAUSE_SENT)
  40800. + vchiq_log_error(
  40801. + vchiq_core_log_level,
  40802. + "%s: bulks paused in "
  40803. + "unexpected state %s",
  40804. + __func__,
  40805. + conn_state_names[
  40806. + state->conn_state]);
  40807. + } else if (state->conn_state ==
  40808. + VCHIQ_CONNSTATE_CONNECTED) {
  40809. + DEBUG_TRACE(PARSE_LINE);
  40810. + resolved = resolve_bulks(service,
  40811. + queue);
  40812. + }
  40813. +
  40814. + mutex_unlock(&service->bulk_mutex);
  40815. + if (resolved)
  40816. + notify_bulks(service, queue,
  40817. + 1/*retry_poll*/);
  40818. + }
  40819. + } break;
  40820. + case VCHIQ_MSG_BULK_RX_DONE:
  40821. + case VCHIQ_MSG_BULK_TX_DONE:
  40822. + WARN_ON(state->is_master);
  40823. + if ((service->remoteport == remoteport)
  40824. + && (service->srvstate !=
  40825. + VCHIQ_SRVSTATE_FREE)) {
  40826. + VCHIQ_BULK_QUEUE_T *queue;
  40827. + VCHIQ_BULK_T *bulk;
  40828. +
  40829. + queue = (type == VCHIQ_MSG_BULK_RX_DONE) ?
  40830. + &service->bulk_rx : &service->bulk_tx;
  40831. +
  40832. + DEBUG_TRACE(PARSE_LINE);
  40833. + if (mutex_lock_interruptible(
  40834. + &service->bulk_mutex) != 0) {
  40835. + DEBUG_TRACE(PARSE_LINE);
  40836. + goto bail_not_ready;
  40837. + }
  40838. + if ((int)(queue->remote_insert -
  40839. + queue->local_insert) >= 0) {
  40840. + vchiq_log_error(vchiq_core_log_level,
  40841. + "%d: prs %s@%x (%d->%d) "
  40842. + "unexpected (ri=%d,li=%d)",
  40843. + state->id, msg_type_str(type),
  40844. + (unsigned int)header,
  40845. + remoteport, localport,
  40846. + queue->remote_insert,
  40847. + queue->local_insert);
  40848. + mutex_unlock(&service->bulk_mutex);
  40849. + break;
  40850. + }
  40851. +
  40852. + BUG_ON(queue->process == queue->local_insert);
  40853. + BUG_ON(queue->process != queue->remote_insert);
  40854. +
  40855. + bulk = &queue->bulks[
  40856. + BULK_INDEX(queue->remote_insert)];
  40857. + bulk->actual = *(int *)header->data;
  40858. + queue->remote_insert++;
  40859. +
  40860. + vchiq_log_info(vchiq_core_log_level,
  40861. + "%d: prs %s@%x (%d->%d) %x@%x",
  40862. + state->id, msg_type_str(type),
  40863. + (unsigned int)header,
  40864. + remoteport, localport,
  40865. + bulk->actual, (unsigned int)bulk->data);
  40866. +
  40867. + vchiq_log_trace(vchiq_core_log_level,
  40868. + "%d: prs:%d %cx li=%x ri=%x p=%x",
  40869. + state->id, localport,
  40870. + (type == VCHIQ_MSG_BULK_RX_DONE) ?
  40871. + 'r' : 't',
  40872. + queue->local_insert,
  40873. + queue->remote_insert, queue->process);
  40874. +
  40875. + DEBUG_TRACE(PARSE_LINE);
  40876. + WARN_ON(queue->process == queue->local_insert);
  40877. + vchiq_complete_bulk(bulk);
  40878. + queue->process++;
  40879. + mutex_unlock(&service->bulk_mutex);
  40880. + DEBUG_TRACE(PARSE_LINE);
  40881. + notify_bulks(service, queue, 1/*retry_poll*/);
  40882. + DEBUG_TRACE(PARSE_LINE);
  40883. + }
  40884. + break;
  40885. + case VCHIQ_MSG_PADDING:
  40886. + vchiq_log_trace(vchiq_core_log_level,
  40887. + "%d: prs PADDING@%x,%x",
  40888. + state->id, (unsigned int)header, size);
  40889. + break;
  40890. + case VCHIQ_MSG_PAUSE:
  40891. + /* If initiated, signal the application thread */
  40892. + vchiq_log_trace(vchiq_core_log_level,
  40893. + "%d: prs PAUSE@%x,%x",
  40894. + state->id, (unsigned int)header, size);
  40895. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  40896. + vchiq_log_error(vchiq_core_log_level,
  40897. + "%d: PAUSE received in state PAUSED",
  40898. + state->id);
  40899. + break;
  40900. + }
  40901. + if (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT) {
  40902. + /* Send a PAUSE in response */
  40903. + if (queue_message(state, NULL,
  40904. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  40905. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  40906. + goto bail_not_ready;
  40907. + if (state->is_master)
  40908. + pause_bulks(state);
  40909. + }
  40910. + /* At this point slot_mutex is held */
  40911. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSED);
  40912. + vchiq_platform_paused(state);
  40913. + break;
  40914. + case VCHIQ_MSG_RESUME:
  40915. + vchiq_log_trace(vchiq_core_log_level,
  40916. + "%d: prs RESUME@%x,%x",
  40917. + state->id, (unsigned int)header, size);
  40918. + /* Release the slot mutex */
  40919. + mutex_unlock(&state->slot_mutex);
  40920. + if (state->is_master)
  40921. + resume_bulks(state);
  40922. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  40923. + vchiq_platform_resumed(state);
  40924. + break;
  40925. +
  40926. + case VCHIQ_MSG_REMOTE_USE:
  40927. + vchiq_on_remote_use(state);
  40928. + break;
  40929. + case VCHIQ_MSG_REMOTE_RELEASE:
  40930. + vchiq_on_remote_release(state);
  40931. + break;
  40932. + case VCHIQ_MSG_REMOTE_USE_ACTIVE:
  40933. + vchiq_on_remote_use_active(state);
  40934. + break;
  40935. +
  40936. + default:
  40937. + vchiq_log_error(vchiq_core_log_level,
  40938. + "%d: prs invalid msgid %x@%x,%x",
  40939. + state->id, msgid, (unsigned int)header, size);
  40940. + WARN(1, "invalid message\n");
  40941. + break;
  40942. + }
  40943. +
  40944. +skip_message:
  40945. + if (service) {
  40946. + unlock_service(service);
  40947. + service = NULL;
  40948. + }
  40949. +
  40950. + state->rx_pos += calc_stride(size);
  40951. +
  40952. + DEBUG_TRACE(PARSE_LINE);
  40953. + /* Perform some housekeeping when the end of the slot is
  40954. + ** reached. */
  40955. + if ((state->rx_pos & VCHIQ_SLOT_MASK) == 0) {
  40956. + /* Remove the extra reference count. */
  40957. + release_slot(state, state->rx_info, NULL, NULL);
  40958. + state->rx_data = NULL;
  40959. + }
  40960. + }
  40961. +
  40962. +bail_not_ready:
  40963. + if (service)
  40964. + unlock_service(service);
  40965. +}
  40966. +
  40967. +/* Called by the slot handler thread */
  40968. +static int
  40969. +slot_handler_func(void *v)
  40970. +{
  40971. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  40972. + VCHIQ_SHARED_STATE_T *local = state->local;
  40973. + DEBUG_INITIALISE(local)
  40974. +
  40975. + while (1) {
  40976. + DEBUG_COUNT(SLOT_HANDLER_COUNT);
  40977. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  40978. + remote_event_wait(&local->trigger);
  40979. +
  40980. + rmb();
  40981. +
  40982. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  40983. + if (state->poll_needed) {
  40984. + /* Check if we need to suspend - may change our
  40985. + * conn_state */
  40986. + vchiq_platform_check_suspend(state);
  40987. +
  40988. + state->poll_needed = 0;
  40989. +
  40990. + /* Handle service polling and other rare conditions here
  40991. + ** out of the mainline code */
  40992. + switch (state->conn_state) {
  40993. + case VCHIQ_CONNSTATE_CONNECTED:
  40994. + /* Poll the services as requested */
  40995. + poll_services(state);
  40996. + break;
  40997. +
  40998. + case VCHIQ_CONNSTATE_PAUSING:
  40999. + if (state->is_master)
  41000. + pause_bulks(state);
  41001. + if (queue_message(state, NULL,
  41002. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  41003. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  41004. + vchiq_set_conn_state(state,
  41005. + VCHIQ_CONNSTATE_PAUSE_SENT);
  41006. + } else {
  41007. + if (state->is_master)
  41008. + resume_bulks(state);
  41009. + /* Retry later */
  41010. + state->poll_needed = 1;
  41011. + }
  41012. + break;
  41013. +
  41014. + case VCHIQ_CONNSTATE_PAUSED:
  41015. + vchiq_platform_resume(state);
  41016. + break;
  41017. +
  41018. + case VCHIQ_CONNSTATE_RESUMING:
  41019. + if (queue_message(state, NULL,
  41020. + VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0),
  41021. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  41022. + if (state->is_master)
  41023. + resume_bulks(state);
  41024. + vchiq_set_conn_state(state,
  41025. + VCHIQ_CONNSTATE_CONNECTED);
  41026. + vchiq_platform_resumed(state);
  41027. + } else {
  41028. + /* This should really be impossible,
  41029. + ** since the PAUSE should have flushed
  41030. + ** through outstanding messages. */
  41031. + vchiq_log_error(vchiq_core_log_level,
  41032. + "Failed to send RESUME "
  41033. + "message");
  41034. + BUG();
  41035. + }
  41036. + break;
  41037. +
  41038. + case VCHIQ_CONNSTATE_PAUSE_TIMEOUT:
  41039. + case VCHIQ_CONNSTATE_RESUME_TIMEOUT:
  41040. + vchiq_platform_handle_timeout(state);
  41041. + break;
  41042. + default:
  41043. + break;
  41044. + }
  41045. +
  41046. +
  41047. + }
  41048. +
  41049. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  41050. + parse_rx_slots(state);
  41051. + }
  41052. + return 0;
  41053. +}
  41054. +
  41055. +
  41056. +/* Called by the recycle thread */
  41057. +static int
  41058. +recycle_func(void *v)
  41059. +{
  41060. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  41061. + VCHIQ_SHARED_STATE_T *local = state->local;
  41062. +
  41063. + while (1) {
  41064. + remote_event_wait(&local->recycle);
  41065. +
  41066. + process_free_queue(state);
  41067. + }
  41068. + return 0;
  41069. +}
  41070. +
  41071. +
  41072. +/* Called by the sync thread */
  41073. +static int
  41074. +sync_func(void *v)
  41075. +{
  41076. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  41077. + VCHIQ_SHARED_STATE_T *local = state->local;
  41078. + VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  41079. + state->remote->slot_sync);
  41080. +
  41081. + while (1) {
  41082. + VCHIQ_SERVICE_T *service;
  41083. + int msgid, size;
  41084. + int type;
  41085. + unsigned int localport, remoteport;
  41086. +
  41087. + remote_event_wait(&local->sync_trigger);
  41088. +
  41089. + rmb();
  41090. +
  41091. + msgid = header->msgid;
  41092. + size = header->size;
  41093. + type = VCHIQ_MSG_TYPE(msgid);
  41094. + localport = VCHIQ_MSG_DSTPORT(msgid);
  41095. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  41096. +
  41097. + service = find_service_by_port(state, localport);
  41098. +
  41099. + if (!service) {
  41100. + vchiq_log_error(vchiq_sync_log_level,
  41101. + "%d: sf %s@%x (%d->%d) - "
  41102. + "invalid/closed service %d",
  41103. + state->id, msg_type_str(type),
  41104. + (unsigned int)header,
  41105. + remoteport, localport, localport);
  41106. + release_message_sync(state, header);
  41107. + continue;
  41108. + }
  41109. +
  41110. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  41111. + int svc_fourcc;
  41112. +
  41113. + svc_fourcc = service
  41114. + ? service->base.fourcc
  41115. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  41116. + vchiq_log_trace(vchiq_sync_log_level,
  41117. + "Rcvd Msg %s from %c%c%c%c s:%d d:%d len:%d",
  41118. + msg_type_str(type),
  41119. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  41120. + remoteport, localport, size);
  41121. + if (size > 0)
  41122. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  41123. + min(64, size));
  41124. + }
  41125. +
  41126. + switch (type) {
  41127. + case VCHIQ_MSG_OPENACK:
  41128. + if (size >= sizeof(struct vchiq_openack_payload)) {
  41129. + const struct vchiq_openack_payload *payload =
  41130. + (struct vchiq_openack_payload *)
  41131. + header->data;
  41132. + service->peer_version = payload->version;
  41133. + }
  41134. + vchiq_log_info(vchiq_sync_log_level,
  41135. + "%d: sf OPENACK@%x,%x (%d->%d) v:%d",
  41136. + state->id, (unsigned int)header, size,
  41137. + remoteport, localport, service->peer_version);
  41138. + if (service->srvstate == VCHIQ_SRVSTATE_OPENING) {
  41139. + service->remoteport = remoteport;
  41140. + vchiq_set_service_state(service,
  41141. + VCHIQ_SRVSTATE_OPENSYNC);
  41142. + up(&service->remove_event);
  41143. + }
  41144. + release_message_sync(state, header);
  41145. + break;
  41146. +
  41147. + case VCHIQ_MSG_DATA:
  41148. + vchiq_log_trace(vchiq_sync_log_level,
  41149. + "%d: sf DATA@%x,%x (%d->%d)",
  41150. + state->id, (unsigned int)header, size,
  41151. + remoteport, localport);
  41152. +
  41153. + if ((service->remoteport == remoteport) &&
  41154. + (service->srvstate ==
  41155. + VCHIQ_SRVSTATE_OPENSYNC)) {
  41156. + if (make_service_callback(service,
  41157. + VCHIQ_MESSAGE_AVAILABLE, header,
  41158. + NULL) == VCHIQ_RETRY)
  41159. + vchiq_log_error(vchiq_sync_log_level,
  41160. + "synchronous callback to "
  41161. + "service %d returns "
  41162. + "VCHIQ_RETRY",
  41163. + localport);
  41164. + }
  41165. + break;
  41166. +
  41167. + default:
  41168. + vchiq_log_error(vchiq_sync_log_level,
  41169. + "%d: sf unexpected msgid %x@%x,%x",
  41170. + state->id, msgid, (unsigned int)header, size);
  41171. + release_message_sync(state, header);
  41172. + break;
  41173. + }
  41174. +
  41175. + unlock_service(service);
  41176. + }
  41177. +
  41178. + return 0;
  41179. +}
  41180. +
  41181. +
  41182. +static void
  41183. +init_bulk_queue(VCHIQ_BULK_QUEUE_T *queue)
  41184. +{
  41185. + queue->local_insert = 0;
  41186. + queue->remote_insert = 0;
  41187. + queue->process = 0;
  41188. + queue->remote_notify = 0;
  41189. + queue->remove = 0;
  41190. +}
  41191. +
  41192. +
  41193. +inline const char *
  41194. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state)
  41195. +{
  41196. + return conn_state_names[conn_state];
  41197. +}
  41198. +
  41199. +
  41200. +VCHIQ_SLOT_ZERO_T *
  41201. +vchiq_init_slots(void *mem_base, int mem_size)
  41202. +{
  41203. + int mem_align = (VCHIQ_SLOT_SIZE - (int)mem_base) & VCHIQ_SLOT_MASK;
  41204. + VCHIQ_SLOT_ZERO_T *slot_zero =
  41205. + (VCHIQ_SLOT_ZERO_T *)((char *)mem_base + mem_align);
  41206. + int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE;
  41207. + int first_data_slot = VCHIQ_SLOT_ZERO_SLOTS;
  41208. +
  41209. + /* Ensure there is enough memory to run an absolutely minimum system */
  41210. + num_slots -= first_data_slot;
  41211. +
  41212. + if (num_slots < 4) {
  41213. + vchiq_log_error(vchiq_core_log_level,
  41214. + "vchiq_init_slots - insufficient memory %x bytes",
  41215. + mem_size);
  41216. + return NULL;
  41217. + }
  41218. +
  41219. + memset(slot_zero, 0, sizeof(VCHIQ_SLOT_ZERO_T));
  41220. +
  41221. + slot_zero->magic = VCHIQ_MAGIC;
  41222. + slot_zero->version = VCHIQ_VERSION;
  41223. + slot_zero->version_min = VCHIQ_VERSION_MIN;
  41224. + slot_zero->slot_zero_size = sizeof(VCHIQ_SLOT_ZERO_T);
  41225. + slot_zero->slot_size = VCHIQ_SLOT_SIZE;
  41226. + slot_zero->max_slots = VCHIQ_MAX_SLOTS;
  41227. + slot_zero->max_slots_per_side = VCHIQ_MAX_SLOTS_PER_SIDE;
  41228. +
  41229. + slot_zero->master.slot_sync = first_data_slot;
  41230. + slot_zero->master.slot_first = first_data_slot + 1;
  41231. + slot_zero->master.slot_last = first_data_slot + (num_slots/2) - 1;
  41232. + slot_zero->slave.slot_sync = first_data_slot + (num_slots/2);
  41233. + slot_zero->slave.slot_first = first_data_slot + (num_slots/2) + 1;
  41234. + slot_zero->slave.slot_last = first_data_slot + num_slots - 1;
  41235. +
  41236. + return slot_zero;
  41237. +}
  41238. +
  41239. +VCHIQ_STATUS_T
  41240. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  41241. + int is_master)
  41242. +{
  41243. + VCHIQ_SHARED_STATE_T *local;
  41244. + VCHIQ_SHARED_STATE_T *remote;
  41245. + VCHIQ_STATUS_T status;
  41246. + char threadname[10];
  41247. + static int id;
  41248. + int i;
  41249. +
  41250. + vchiq_log_warning(vchiq_core_log_level,
  41251. + "%s: slot_zero = 0x%08lx, is_master = %d",
  41252. + __func__, (unsigned long)slot_zero, is_master);
  41253. +
  41254. + /* Check the input configuration */
  41255. +
  41256. + if (slot_zero->magic != VCHIQ_MAGIC) {
  41257. + vchiq_loud_error_header();
  41258. + vchiq_loud_error("Invalid VCHIQ magic value found.");
  41259. + vchiq_loud_error("slot_zero=%x: magic=%x (expected %x)",
  41260. + (unsigned int)slot_zero, slot_zero->magic, VCHIQ_MAGIC);
  41261. + vchiq_loud_error_footer();
  41262. + return VCHIQ_ERROR;
  41263. + }
  41264. +
  41265. + if (slot_zero->version < VCHIQ_VERSION_MIN) {
  41266. + vchiq_loud_error_header();
  41267. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  41268. + vchiq_loud_error("slot_zero=%x: VideoCore version=%d "
  41269. + "(minimum %d)",
  41270. + (unsigned int)slot_zero, slot_zero->version,
  41271. + VCHIQ_VERSION_MIN);
  41272. + vchiq_loud_error("Restart with a newer VideoCore image.");
  41273. + vchiq_loud_error_footer();
  41274. + return VCHIQ_ERROR;
  41275. + }
  41276. +
  41277. + if (VCHIQ_VERSION < slot_zero->version_min) {
  41278. + vchiq_loud_error_header();
  41279. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  41280. + vchiq_loud_error("slot_zero=%x: version=%d (VideoCore "
  41281. + "minimum %d)",
  41282. + (unsigned int)slot_zero, VCHIQ_VERSION,
  41283. + slot_zero->version_min);
  41284. + vchiq_loud_error("Restart with a newer kernel.");
  41285. + vchiq_loud_error_footer();
  41286. + return VCHIQ_ERROR;
  41287. + }
  41288. +
  41289. + if ((slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T)) ||
  41290. + (slot_zero->slot_size != VCHIQ_SLOT_SIZE) ||
  41291. + (slot_zero->max_slots != VCHIQ_MAX_SLOTS) ||
  41292. + (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)) {
  41293. + vchiq_loud_error_header();
  41294. + if (slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T))
  41295. + vchiq_loud_error("slot_zero=%x: slot_zero_size=%x "
  41296. + "(expected %x)",
  41297. + (unsigned int)slot_zero,
  41298. + slot_zero->slot_zero_size,
  41299. + sizeof(VCHIQ_SLOT_ZERO_T));
  41300. + if (slot_zero->slot_size != VCHIQ_SLOT_SIZE)
  41301. + vchiq_loud_error("slot_zero=%x: slot_size=%d "
  41302. + "(expected %d",
  41303. + (unsigned int)slot_zero, slot_zero->slot_size,
  41304. + VCHIQ_SLOT_SIZE);
  41305. + if (slot_zero->max_slots != VCHIQ_MAX_SLOTS)
  41306. + vchiq_loud_error("slot_zero=%x: max_slots=%d "
  41307. + "(expected %d)",
  41308. + (unsigned int)slot_zero, slot_zero->max_slots,
  41309. + VCHIQ_MAX_SLOTS);
  41310. + if (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)
  41311. + vchiq_loud_error("slot_zero=%x: max_slots_per_side=%d "
  41312. + "(expected %d)",
  41313. + (unsigned int)slot_zero,
  41314. + slot_zero->max_slots_per_side,
  41315. + VCHIQ_MAX_SLOTS_PER_SIDE);
  41316. + vchiq_loud_error_footer();
  41317. + return VCHIQ_ERROR;
  41318. + }
  41319. +
  41320. + if (is_master) {
  41321. + local = &slot_zero->master;
  41322. + remote = &slot_zero->slave;
  41323. + } else {
  41324. + local = &slot_zero->slave;
  41325. + remote = &slot_zero->master;
  41326. + }
  41327. +
  41328. + if (local->initialised) {
  41329. + vchiq_loud_error_header();
  41330. + if (remote->initialised)
  41331. + vchiq_loud_error("local state has already been "
  41332. + "initialised");
  41333. + else
  41334. + vchiq_loud_error("master/slave mismatch - two %ss",
  41335. + is_master ? "master" : "slave");
  41336. + vchiq_loud_error_footer();
  41337. + return VCHIQ_ERROR;
  41338. + }
  41339. +
  41340. + memset(state, 0, sizeof(VCHIQ_STATE_T));
  41341. +
  41342. + state->id = id++;
  41343. + state->is_master = is_master;
  41344. +
  41345. + /*
  41346. + initialize shared state pointers
  41347. + */
  41348. +
  41349. + state->local = local;
  41350. + state->remote = remote;
  41351. + state->slot_data = (VCHIQ_SLOT_T *)slot_zero;
  41352. +
  41353. + /*
  41354. + initialize events and mutexes
  41355. + */
  41356. +
  41357. + sema_init(&state->connect, 0);
  41358. + mutex_init(&state->mutex);
  41359. + sema_init(&state->trigger_event, 0);
  41360. + sema_init(&state->recycle_event, 0);
  41361. + sema_init(&state->sync_trigger_event, 0);
  41362. + sema_init(&state->sync_release_event, 0);
  41363. +
  41364. + mutex_init(&state->slot_mutex);
  41365. + mutex_init(&state->recycle_mutex);
  41366. + mutex_init(&state->sync_mutex);
  41367. + mutex_init(&state->bulk_transfer_mutex);
  41368. +
  41369. + sema_init(&state->slot_available_event, 0);
  41370. + sema_init(&state->slot_remove_event, 0);
  41371. + sema_init(&state->data_quota_event, 0);
  41372. +
  41373. + state->slot_queue_available = 0;
  41374. +
  41375. + for (i = 0; i < VCHIQ_MAX_SERVICES; i++) {
  41376. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  41377. + &state->service_quotas[i];
  41378. + sema_init(&service_quota->quota_event, 0);
  41379. + }
  41380. +
  41381. + for (i = local->slot_first; i <= local->slot_last; i++) {
  41382. + local->slot_queue[state->slot_queue_available++] = i;
  41383. + up(&state->slot_available_event);
  41384. + }
  41385. +
  41386. + state->default_slot_quota = state->slot_queue_available/2;
  41387. + state->default_message_quota =
  41388. + min((unsigned short)(state->default_slot_quota * 256),
  41389. + (unsigned short)~0);
  41390. +
  41391. + state->previous_data_index = -1;
  41392. + state->data_use_count = 0;
  41393. + state->data_quota = state->slot_queue_available - 1;
  41394. +
  41395. + local->trigger.event = &state->trigger_event;
  41396. + remote_event_create(&local->trigger);
  41397. + local->tx_pos = 0;
  41398. +
  41399. + local->recycle.event = &state->recycle_event;
  41400. + remote_event_create(&local->recycle);
  41401. + local->slot_queue_recycle = state->slot_queue_available;
  41402. +
  41403. + local->sync_trigger.event = &state->sync_trigger_event;
  41404. + remote_event_create(&local->sync_trigger);
  41405. +
  41406. + local->sync_release.event = &state->sync_release_event;
  41407. + remote_event_create(&local->sync_release);
  41408. +
  41409. + /* At start-of-day, the slot is empty and available */
  41410. + ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, local->slot_sync))->msgid
  41411. + = VCHIQ_MSGID_PADDING;
  41412. + remote_event_signal_local(&local->sync_release);
  41413. +
  41414. + local->debug[DEBUG_ENTRIES] = DEBUG_MAX;
  41415. +
  41416. + status = vchiq_platform_init_state(state);
  41417. +
  41418. + /*
  41419. + bring up slot handler thread
  41420. + */
  41421. + snprintf(threadname, sizeof(threadname), "VCHIQ-%d", state->id);
  41422. + state->slot_handler_thread = kthread_create(&slot_handler_func,
  41423. + (void *)state,
  41424. + threadname);
  41425. +
  41426. + if (state->slot_handler_thread == NULL) {
  41427. + vchiq_loud_error_header();
  41428. + vchiq_loud_error("couldn't create thread %s", threadname);
  41429. + vchiq_loud_error_footer();
  41430. + return VCHIQ_ERROR;
  41431. + }
  41432. + set_user_nice(state->slot_handler_thread, -19);
  41433. + wake_up_process(state->slot_handler_thread);
  41434. +
  41435. + snprintf(threadname, sizeof(threadname), "VCHIQr-%d", state->id);
  41436. + state->recycle_thread = kthread_create(&recycle_func,
  41437. + (void *)state,
  41438. + threadname);
  41439. + if (state->recycle_thread == NULL) {
  41440. + vchiq_loud_error_header();
  41441. + vchiq_loud_error("couldn't create thread %s", threadname);
  41442. + vchiq_loud_error_footer();
  41443. + return VCHIQ_ERROR;
  41444. + }
  41445. + set_user_nice(state->recycle_thread, -19);
  41446. + wake_up_process(state->recycle_thread);
  41447. +
  41448. + snprintf(threadname, sizeof(threadname), "VCHIQs-%d", state->id);
  41449. + state->sync_thread = kthread_create(&sync_func,
  41450. + (void *)state,
  41451. + threadname);
  41452. + if (state->sync_thread == NULL) {
  41453. + vchiq_loud_error_header();
  41454. + vchiq_loud_error("couldn't create thread %s", threadname);
  41455. + vchiq_loud_error_footer();
  41456. + return VCHIQ_ERROR;
  41457. + }
  41458. + set_user_nice(state->sync_thread, -20);
  41459. + wake_up_process(state->sync_thread);
  41460. +
  41461. + BUG_ON(state->id >= VCHIQ_MAX_STATES);
  41462. + vchiq_states[state->id] = state;
  41463. +
  41464. + /* Indicate readiness to the other side */
  41465. + local->initialised = 1;
  41466. +
  41467. + return status;
  41468. +}
  41469. +
  41470. +/* Called from application thread when a client or server service is created. */
  41471. +VCHIQ_SERVICE_T *
  41472. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  41473. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  41474. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term)
  41475. +{
  41476. + VCHIQ_SERVICE_T *service;
  41477. +
  41478. + service = kmalloc(sizeof(VCHIQ_SERVICE_T), GFP_KERNEL);
  41479. + if (service) {
  41480. + service->base.fourcc = params->fourcc;
  41481. + service->base.callback = params->callback;
  41482. + service->base.userdata = params->userdata;
  41483. + service->handle = VCHIQ_SERVICE_HANDLE_INVALID;
  41484. + service->ref_count = 1;
  41485. + service->srvstate = VCHIQ_SRVSTATE_FREE;
  41486. + service->userdata_term = userdata_term;
  41487. + service->localport = VCHIQ_PORT_FREE;
  41488. + service->remoteport = VCHIQ_PORT_FREE;
  41489. +
  41490. + service->public_fourcc = (srvstate == VCHIQ_SRVSTATE_OPENING) ?
  41491. + VCHIQ_FOURCC_INVALID : params->fourcc;
  41492. + service->client_id = 0;
  41493. + service->auto_close = 1;
  41494. + service->sync = 0;
  41495. + service->closing = 0;
  41496. + service->trace = 0;
  41497. + atomic_set(&service->poll_flags, 0);
  41498. + service->version = params->version;
  41499. + service->version_min = params->version_min;
  41500. + service->state = state;
  41501. + service->instance = instance;
  41502. + service->service_use_count = 0;
  41503. + init_bulk_queue(&service->bulk_tx);
  41504. + init_bulk_queue(&service->bulk_rx);
  41505. + sema_init(&service->remove_event, 0);
  41506. + sema_init(&service->bulk_remove_event, 0);
  41507. + mutex_init(&service->bulk_mutex);
  41508. + memset(&service->stats, 0, sizeof(service->stats));
  41509. + } else {
  41510. + vchiq_log_error(vchiq_core_log_level,
  41511. + "Out of memory");
  41512. + }
  41513. +
  41514. + if (service) {
  41515. + VCHIQ_SERVICE_T **pservice = NULL;
  41516. + int i;
  41517. +
  41518. + /* Although it is perfectly possible to use service_spinlock
  41519. + ** to protect the creation of services, it is overkill as it
  41520. + ** disables interrupts while the array is searched.
  41521. + ** The only danger is of another thread trying to create a
  41522. + ** service - service deletion is safe.
  41523. + ** Therefore it is preferable to use state->mutex which,
  41524. + ** although slower to claim, doesn't block interrupts while
  41525. + ** it is held.
  41526. + */
  41527. +
  41528. + mutex_lock(&state->mutex);
  41529. +
  41530. + /* Prepare to use a previously unused service */
  41531. + if (state->unused_service < VCHIQ_MAX_SERVICES)
  41532. + pservice = &state->services[state->unused_service];
  41533. +
  41534. + if (srvstate == VCHIQ_SRVSTATE_OPENING) {
  41535. + for (i = 0; i < state->unused_service; i++) {
  41536. + VCHIQ_SERVICE_T *srv = state->services[i];
  41537. + if (!srv) {
  41538. + pservice = &state->services[i];
  41539. + break;
  41540. + }
  41541. + }
  41542. + } else {
  41543. + for (i = (state->unused_service - 1); i >= 0; i--) {
  41544. + VCHIQ_SERVICE_T *srv = state->services[i];
  41545. + if (!srv)
  41546. + pservice = &state->services[i];
  41547. + else if ((srv->public_fourcc == params->fourcc)
  41548. + && ((srv->instance != instance) ||
  41549. + (srv->base.callback !=
  41550. + params->callback))) {
  41551. + /* There is another server using this
  41552. + ** fourcc which doesn't match. */
  41553. + pservice = NULL;
  41554. + break;
  41555. + }
  41556. + }
  41557. + }
  41558. +
  41559. + if (pservice) {
  41560. + service->localport = (pservice - state->services);
  41561. + if (!handle_seq)
  41562. + handle_seq = VCHIQ_MAX_STATES *
  41563. + VCHIQ_MAX_SERVICES;
  41564. + service->handle = handle_seq |
  41565. + (state->id * VCHIQ_MAX_SERVICES) |
  41566. + service->localport;
  41567. + handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES;
  41568. + *pservice = service;
  41569. + if (pservice == &state->services[state->unused_service])
  41570. + state->unused_service++;
  41571. + }
  41572. +
  41573. + mutex_unlock(&state->mutex);
  41574. +
  41575. + if (!pservice) {
  41576. + kfree(service);
  41577. + service = NULL;
  41578. + }
  41579. + }
  41580. +
  41581. + if (service) {
  41582. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  41583. + &state->service_quotas[service->localport];
  41584. + service_quota->slot_quota = state->default_slot_quota;
  41585. + service_quota->message_quota = state->default_message_quota;
  41586. + if (service_quota->slot_use_count == 0)
  41587. + service_quota->previous_tx_index =
  41588. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos)
  41589. + - 1;
  41590. +
  41591. + /* Bring this service online */
  41592. + vchiq_set_service_state(service, srvstate);
  41593. +
  41594. + vchiq_log_info(vchiq_core_msg_log_level,
  41595. + "%s Service %c%c%c%c SrcPort:%d",
  41596. + (srvstate == VCHIQ_SRVSTATE_OPENING)
  41597. + ? "Open" : "Add",
  41598. + VCHIQ_FOURCC_AS_4CHARS(params->fourcc),
  41599. + service->localport);
  41600. + }
  41601. +
  41602. + /* Don't unlock the service - leave it with a ref_count of 1. */
  41603. +
  41604. + return service;
  41605. +}
  41606. +
  41607. +VCHIQ_STATUS_T
  41608. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id)
  41609. +{
  41610. + struct vchiq_open_payload payload = {
  41611. + service->base.fourcc,
  41612. + client_id,
  41613. + service->version,
  41614. + service->version_min
  41615. + };
  41616. + VCHIQ_ELEMENT_T body = { &payload, sizeof(payload) };
  41617. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  41618. +
  41619. + service->client_id = client_id;
  41620. + vchiq_use_service_internal(service);
  41621. + status = queue_message(service->state, NULL,
  41622. + VCHIQ_MAKE_MSG(VCHIQ_MSG_OPEN, service->localport, 0),
  41623. + &body, 1, sizeof(payload), 1);
  41624. + if (status == VCHIQ_SUCCESS) {
  41625. + /* Wait for the ACK/NAK */
  41626. + if (down_interruptible(&service->remove_event) != 0) {
  41627. + status = VCHIQ_RETRY;
  41628. + vchiq_release_service_internal(service);
  41629. + } else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
  41630. + (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) {
  41631. + if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT)
  41632. + vchiq_log_error(vchiq_core_log_level,
  41633. + "%d: osi - srvstate = %s (ref %d)",
  41634. + service->state->id,
  41635. + srvstate_names[service->srvstate],
  41636. + service->ref_count);
  41637. + status = VCHIQ_ERROR;
  41638. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  41639. + vchiq_release_service_internal(service);
  41640. + }
  41641. + }
  41642. + return status;
  41643. +}
  41644. +
  41645. +static void
  41646. +release_service_messages(VCHIQ_SERVICE_T *service)
  41647. +{
  41648. + VCHIQ_STATE_T *state = service->state;
  41649. + int slot_last = state->remote->slot_last;
  41650. + int i;
  41651. +
  41652. + /* Release any claimed messages */
  41653. + for (i = state->remote->slot_first; i <= slot_last; i++) {
  41654. + VCHIQ_SLOT_INFO_T *slot_info =
  41655. + SLOT_INFO_FROM_INDEX(state, i);
  41656. + if (slot_info->release_count != slot_info->use_count) {
  41657. + char *data =
  41658. + (char *)SLOT_DATA_FROM_INDEX(state, i);
  41659. + unsigned int pos, end;
  41660. +
  41661. + end = VCHIQ_SLOT_SIZE;
  41662. + if (data == state->rx_data)
  41663. + /* This buffer is still being read from - stop
  41664. + ** at the current read position */
  41665. + end = state->rx_pos & VCHIQ_SLOT_MASK;
  41666. +
  41667. + pos = 0;
  41668. +
  41669. + while (pos < end) {
  41670. + VCHIQ_HEADER_T *header =
  41671. + (VCHIQ_HEADER_T *)(data + pos);
  41672. + int msgid = header->msgid;
  41673. + int port = VCHIQ_MSG_DSTPORT(msgid);
  41674. + if ((port == service->localport) &&
  41675. + (msgid & VCHIQ_MSGID_CLAIMED)) {
  41676. + vchiq_log_info(vchiq_core_log_level,
  41677. + " fsi - hdr %x",
  41678. + (unsigned int)header);
  41679. + release_slot(state, slot_info, header,
  41680. + NULL);
  41681. + }
  41682. + pos += calc_stride(header->size);
  41683. + if (pos > VCHIQ_SLOT_SIZE) {
  41684. + vchiq_log_error(vchiq_core_log_level,
  41685. + "fsi - pos %x: header %x, "
  41686. + "msgid %x, header->msgid %x, "
  41687. + "header->size %x",
  41688. + pos, (unsigned int)header,
  41689. + msgid, header->msgid,
  41690. + header->size);
  41691. + WARN(1, "invalid slot position\n");
  41692. + }
  41693. + }
  41694. + }
  41695. + }
  41696. +}
  41697. +
  41698. +static int
  41699. +do_abort_bulks(VCHIQ_SERVICE_T *service)
  41700. +{
  41701. + VCHIQ_STATUS_T status;
  41702. +
  41703. + /* Abort any outstanding bulk transfers */
  41704. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0)
  41705. + return 0;
  41706. + abort_outstanding_bulks(service, &service->bulk_tx);
  41707. + abort_outstanding_bulks(service, &service->bulk_rx);
  41708. + mutex_unlock(&service->bulk_mutex);
  41709. +
  41710. + status = notify_bulks(service, &service->bulk_tx, 0/*!retry_poll*/);
  41711. + if (status == VCHIQ_SUCCESS)
  41712. + status = notify_bulks(service, &service->bulk_rx,
  41713. + 0/*!retry_poll*/);
  41714. + return (status == VCHIQ_SUCCESS);
  41715. +}
  41716. +
  41717. +static VCHIQ_STATUS_T
  41718. +close_service_complete(VCHIQ_SERVICE_T *service, int failstate)
  41719. +{
  41720. + VCHIQ_STATUS_T status;
  41721. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  41722. + int newstate;
  41723. +
  41724. + switch (service->srvstate) {
  41725. + case VCHIQ_SRVSTATE_OPEN:
  41726. + case VCHIQ_SRVSTATE_CLOSESENT:
  41727. + case VCHIQ_SRVSTATE_CLOSERECVD:
  41728. + if (is_server) {
  41729. + if (service->auto_close) {
  41730. + service->client_id = 0;
  41731. + service->remoteport = VCHIQ_PORT_FREE;
  41732. + newstate = VCHIQ_SRVSTATE_LISTENING;
  41733. + } else
  41734. + newstate = VCHIQ_SRVSTATE_CLOSEWAIT;
  41735. + } else
  41736. + newstate = VCHIQ_SRVSTATE_CLOSED;
  41737. + vchiq_set_service_state(service, newstate);
  41738. + break;
  41739. + case VCHIQ_SRVSTATE_LISTENING:
  41740. + break;
  41741. + default:
  41742. + vchiq_log_error(vchiq_core_log_level,
  41743. + "close_service_complete(%x) called in state %s",
  41744. + service->handle, srvstate_names[service->srvstate]);
  41745. + WARN(1, "close_service_complete in unexpected state\n");
  41746. + return VCHIQ_ERROR;
  41747. + }
  41748. +
  41749. + status = make_service_callback(service,
  41750. + VCHIQ_SERVICE_CLOSED, NULL, NULL);
  41751. +
  41752. + if (status != VCHIQ_RETRY) {
  41753. + int uc = service->service_use_count;
  41754. + int i;
  41755. + /* Complete the close process */
  41756. + for (i = 0; i < uc; i++)
  41757. + /* cater for cases where close is forced and the
  41758. + ** client may not close all it's handles */
  41759. + vchiq_release_service_internal(service);
  41760. +
  41761. + service->client_id = 0;
  41762. + service->remoteport = VCHIQ_PORT_FREE;
  41763. +
  41764. + if (service->srvstate == VCHIQ_SRVSTATE_CLOSED)
  41765. + vchiq_free_service_internal(service);
  41766. + else if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT) {
  41767. + if (is_server)
  41768. + service->closing = 0;
  41769. +
  41770. + up(&service->remove_event);
  41771. + }
  41772. + } else
  41773. + vchiq_set_service_state(service, failstate);
  41774. +
  41775. + return status;
  41776. +}
  41777. +
  41778. +/* Called by the slot handler */
  41779. +VCHIQ_STATUS_T
  41780. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd)
  41781. +{
  41782. + VCHIQ_STATE_T *state = service->state;
  41783. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  41784. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  41785. +
  41786. + vchiq_log_info(vchiq_core_log_level, "%d: csi:%d,%d (%s)",
  41787. + service->state->id, service->localport, close_recvd,
  41788. + srvstate_names[service->srvstate]);
  41789. +
  41790. + switch (service->srvstate) {
  41791. + case VCHIQ_SRVSTATE_CLOSED:
  41792. + case VCHIQ_SRVSTATE_HIDDEN:
  41793. + case VCHIQ_SRVSTATE_LISTENING:
  41794. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  41795. + if (close_recvd)
  41796. + vchiq_log_error(vchiq_core_log_level,
  41797. + "vchiq_close_service_internal(1) called "
  41798. + "in state %s",
  41799. + srvstate_names[service->srvstate]);
  41800. + else if (is_server) {
  41801. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  41802. + status = VCHIQ_ERROR;
  41803. + } else {
  41804. + service->client_id = 0;
  41805. + service->remoteport = VCHIQ_PORT_FREE;
  41806. + if (service->srvstate ==
  41807. + VCHIQ_SRVSTATE_CLOSEWAIT)
  41808. + vchiq_set_service_state(service,
  41809. + VCHIQ_SRVSTATE_LISTENING);
  41810. + }
  41811. + up(&service->remove_event);
  41812. + } else
  41813. + vchiq_free_service_internal(service);
  41814. + break;
  41815. + case VCHIQ_SRVSTATE_OPENING:
  41816. + if (close_recvd) {
  41817. + /* The open was rejected - tell the user */
  41818. + vchiq_set_service_state(service,
  41819. + VCHIQ_SRVSTATE_CLOSEWAIT);
  41820. + up(&service->remove_event);
  41821. + } else {
  41822. + /* Shutdown mid-open - let the other side know */
  41823. + status = queue_message(state, service,
  41824. + VCHIQ_MAKE_MSG
  41825. + (VCHIQ_MSG_CLOSE,
  41826. + service->localport,
  41827. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  41828. + NULL, 0, 0, 0);
  41829. + }
  41830. + break;
  41831. +
  41832. + case VCHIQ_SRVSTATE_OPENSYNC:
  41833. + mutex_lock(&state->sync_mutex);
  41834. + /* Drop through */
  41835. +
  41836. + case VCHIQ_SRVSTATE_OPEN:
  41837. + if (state->is_master || close_recvd) {
  41838. + if (!do_abort_bulks(service))
  41839. + status = VCHIQ_RETRY;
  41840. + }
  41841. +
  41842. + release_service_messages(service);
  41843. +
  41844. + if (status == VCHIQ_SUCCESS)
  41845. + status = queue_message(state, service,
  41846. + VCHIQ_MAKE_MSG
  41847. + (VCHIQ_MSG_CLOSE,
  41848. + service->localport,
  41849. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  41850. + NULL, 0, 0, 0);
  41851. +
  41852. + if (status == VCHIQ_SUCCESS) {
  41853. + if (!close_recvd)
  41854. + break;
  41855. + } else if (service->srvstate == VCHIQ_SRVSTATE_OPENSYNC) {
  41856. + mutex_unlock(&state->sync_mutex);
  41857. + break;
  41858. + } else
  41859. + break;
  41860. +
  41861. + status = close_service_complete(service,
  41862. + VCHIQ_SRVSTATE_CLOSERECVD);
  41863. + break;
  41864. +
  41865. + case VCHIQ_SRVSTATE_CLOSESENT:
  41866. + if (!close_recvd)
  41867. + /* This happens when a process is killed mid-close */
  41868. + break;
  41869. +
  41870. + if (!state->is_master) {
  41871. + if (!do_abort_bulks(service)) {
  41872. + status = VCHIQ_RETRY;
  41873. + break;
  41874. + }
  41875. + }
  41876. +
  41877. + if (status == VCHIQ_SUCCESS)
  41878. + status = close_service_complete(service,
  41879. + VCHIQ_SRVSTATE_CLOSERECVD);
  41880. + break;
  41881. +
  41882. + case VCHIQ_SRVSTATE_CLOSERECVD:
  41883. + if (!close_recvd && is_server)
  41884. + /* Force into LISTENING mode */
  41885. + vchiq_set_service_state(service,
  41886. + VCHIQ_SRVSTATE_LISTENING);
  41887. + status = close_service_complete(service,
  41888. + VCHIQ_SRVSTATE_CLOSERECVD);
  41889. + break;
  41890. +
  41891. + default:
  41892. + vchiq_log_error(vchiq_core_log_level,
  41893. + "vchiq_close_service_internal(%d) called in state %s",
  41894. + close_recvd, srvstate_names[service->srvstate]);
  41895. + break;
  41896. + }
  41897. +
  41898. + return status;
  41899. +}
  41900. +
  41901. +/* Called from the application process upon process death */
  41902. +void
  41903. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service)
  41904. +{
  41905. + VCHIQ_STATE_T *state = service->state;
  41906. +
  41907. + vchiq_log_info(vchiq_core_log_level, "%d: tsi - (%d<->%d)",
  41908. + state->id, service->localport, service->remoteport);
  41909. +
  41910. + mark_service_closing(service);
  41911. +
  41912. + /* Mark the service for removal by the slot handler */
  41913. + request_poll(state, service, VCHIQ_POLL_REMOVE);
  41914. +}
  41915. +
  41916. +/* Called from the slot handler */
  41917. +void
  41918. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service)
  41919. +{
  41920. + VCHIQ_STATE_T *state = service->state;
  41921. +
  41922. + vchiq_log_info(vchiq_core_log_level, "%d: fsi - (%d)",
  41923. + state->id, service->localport);
  41924. +
  41925. + switch (service->srvstate) {
  41926. + case VCHIQ_SRVSTATE_OPENING:
  41927. + case VCHIQ_SRVSTATE_CLOSED:
  41928. + case VCHIQ_SRVSTATE_HIDDEN:
  41929. + case VCHIQ_SRVSTATE_LISTENING:
  41930. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  41931. + break;
  41932. + default:
  41933. + vchiq_log_error(vchiq_core_log_level,
  41934. + "%d: fsi - (%d) in state %s",
  41935. + state->id, service->localport,
  41936. + srvstate_names[service->srvstate]);
  41937. + return;
  41938. + }
  41939. +
  41940. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_FREE);
  41941. +
  41942. + up(&service->remove_event);
  41943. +
  41944. + /* Release the initial lock */
  41945. + unlock_service(service);
  41946. +}
  41947. +
  41948. +VCHIQ_STATUS_T
  41949. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  41950. +{
  41951. + VCHIQ_SERVICE_T *service;
  41952. + int i;
  41953. +
  41954. + /* Find all services registered to this client and enable them. */
  41955. + i = 0;
  41956. + while ((service = next_service_by_instance(state, instance,
  41957. + &i)) != NULL) {
  41958. + if (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)
  41959. + vchiq_set_service_state(service,
  41960. + VCHIQ_SRVSTATE_LISTENING);
  41961. + unlock_service(service);
  41962. + }
  41963. +
  41964. + if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) {
  41965. + if (queue_message(state, NULL,
  41966. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, 0,
  41967. + 0, 1) == VCHIQ_RETRY)
  41968. + return VCHIQ_RETRY;
  41969. +
  41970. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTING);
  41971. + }
  41972. +
  41973. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTING) {
  41974. + if (down_interruptible(&state->connect) != 0)
  41975. + return VCHIQ_RETRY;
  41976. +
  41977. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  41978. + up(&state->connect);
  41979. + }
  41980. +
  41981. + return VCHIQ_SUCCESS;
  41982. +}
  41983. +
  41984. +VCHIQ_STATUS_T
  41985. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  41986. +{
  41987. + VCHIQ_SERVICE_T *service;
  41988. + int i;
  41989. +
  41990. + /* Find all services registered to this client and enable them. */
  41991. + i = 0;
  41992. + while ((service = next_service_by_instance(state, instance,
  41993. + &i)) != NULL) {
  41994. + (void)vchiq_remove_service(service->handle);
  41995. + unlock_service(service);
  41996. + }
  41997. +
  41998. + return VCHIQ_SUCCESS;
  41999. +}
  42000. +
  42001. +VCHIQ_STATUS_T
  42002. +vchiq_pause_internal(VCHIQ_STATE_T *state)
  42003. +{
  42004. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  42005. +
  42006. + switch (state->conn_state) {
  42007. + case VCHIQ_CONNSTATE_CONNECTED:
  42008. + /* Request a pause */
  42009. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSING);
  42010. + request_poll(state, NULL, 0);
  42011. + break;
  42012. + default:
  42013. + vchiq_log_error(vchiq_core_log_level,
  42014. + "vchiq_pause_internal in state %s\n",
  42015. + conn_state_names[state->conn_state]);
  42016. + status = VCHIQ_ERROR;
  42017. + VCHIQ_STATS_INC(state, error_count);
  42018. + break;
  42019. + }
  42020. +
  42021. + return status;
  42022. +}
  42023. +
  42024. +VCHIQ_STATUS_T
  42025. +vchiq_resume_internal(VCHIQ_STATE_T *state)
  42026. +{
  42027. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  42028. +
  42029. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  42030. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_RESUMING);
  42031. + request_poll(state, NULL, 0);
  42032. + } else {
  42033. + status = VCHIQ_ERROR;
  42034. + VCHIQ_STATS_INC(state, error_count);
  42035. + }
  42036. +
  42037. + return status;
  42038. +}
  42039. +
  42040. +VCHIQ_STATUS_T
  42041. +vchiq_close_service(VCHIQ_SERVICE_HANDLE_T handle)
  42042. +{
  42043. + /* Unregister the service */
  42044. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  42045. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  42046. +
  42047. + if (!service)
  42048. + return VCHIQ_ERROR;
  42049. +
  42050. + vchiq_log_info(vchiq_core_log_level,
  42051. + "%d: close_service:%d",
  42052. + service->state->id, service->localport);
  42053. +
  42054. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  42055. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  42056. + (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)) {
  42057. + unlock_service(service);
  42058. + return VCHIQ_ERROR;
  42059. + }
  42060. +
  42061. + mark_service_closing(service);
  42062. +
  42063. + if (current == service->state->slot_handler_thread) {
  42064. + status = vchiq_close_service_internal(service,
  42065. + 0/*!close_recvd*/);
  42066. + BUG_ON(status == VCHIQ_RETRY);
  42067. + } else {
  42068. + /* Mark the service for termination by the slot handler */
  42069. + request_poll(service->state, service, VCHIQ_POLL_TERMINATE);
  42070. + }
  42071. +
  42072. + while (1) {
  42073. + if (down_interruptible(&service->remove_event) != 0) {
  42074. + status = VCHIQ_RETRY;
  42075. + break;
  42076. + }
  42077. +
  42078. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  42079. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  42080. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  42081. + break;
  42082. +
  42083. + vchiq_log_warning(vchiq_core_log_level,
  42084. + "%d: close_service:%d - waiting in state %s",
  42085. + service->state->id, service->localport,
  42086. + srvstate_names[service->srvstate]);
  42087. + }
  42088. +
  42089. + if ((status == VCHIQ_SUCCESS) &&
  42090. + (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  42091. + (service->srvstate != VCHIQ_SRVSTATE_LISTENING))
  42092. + status = VCHIQ_ERROR;
  42093. +
  42094. + unlock_service(service);
  42095. +
  42096. + return status;
  42097. +}
  42098. +
  42099. +VCHIQ_STATUS_T
  42100. +vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T handle)
  42101. +{
  42102. + /* Unregister the service */
  42103. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  42104. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  42105. +
  42106. + if (!service)
  42107. + return VCHIQ_ERROR;
  42108. +
  42109. + vchiq_log_info(vchiq_core_log_level,
  42110. + "%d: remove_service:%d",
  42111. + service->state->id, service->localport);
  42112. +
  42113. + if (service->srvstate == VCHIQ_SRVSTATE_FREE) {
  42114. + unlock_service(service);
  42115. + return VCHIQ_ERROR;
  42116. + }
  42117. +
  42118. + mark_service_closing(service);
  42119. +
  42120. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  42121. + (current == service->state->slot_handler_thread)) {
  42122. + /* Make it look like a client, because it must be removed and
  42123. + not left in the LISTENING state. */
  42124. + service->public_fourcc = VCHIQ_FOURCC_INVALID;
  42125. +
  42126. + status = vchiq_close_service_internal(service,
  42127. + 0/*!close_recvd*/);
  42128. + BUG_ON(status == VCHIQ_RETRY);
  42129. + } else {
  42130. + /* Mark the service for removal by the slot handler */
  42131. + request_poll(service->state, service, VCHIQ_POLL_REMOVE);
  42132. + }
  42133. + while (1) {
  42134. + if (down_interruptible(&service->remove_event) != 0) {
  42135. + status = VCHIQ_RETRY;
  42136. + break;
  42137. + }
  42138. +
  42139. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  42140. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  42141. + break;
  42142. +
  42143. + vchiq_log_warning(vchiq_core_log_level,
  42144. + "%d: remove_service:%d - waiting in state %s",
  42145. + service->state->id, service->localport,
  42146. + srvstate_names[service->srvstate]);
  42147. + }
  42148. +
  42149. + if ((status == VCHIQ_SUCCESS) &&
  42150. + (service->srvstate != VCHIQ_SRVSTATE_FREE))
  42151. + status = VCHIQ_ERROR;
  42152. +
  42153. + unlock_service(service);
  42154. +
  42155. + return status;
  42156. +}
  42157. +
  42158. +
  42159. +/* This function may be called by kernel threads or user threads.
  42160. + * User threads may receive VCHIQ_RETRY to indicate that a signal has been
  42161. + * received and the call should be retried after being returned to user
  42162. + * context.
  42163. + * When called in blocking mode, the userdata field points to a bulk_waiter
  42164. + * structure.
  42165. + */
  42166. +VCHIQ_STATUS_T
  42167. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  42168. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  42169. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir)
  42170. +{
  42171. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  42172. + VCHIQ_BULK_QUEUE_T *queue;
  42173. + VCHIQ_BULK_T *bulk;
  42174. + VCHIQ_STATE_T *state;
  42175. + struct bulk_waiter *bulk_waiter = NULL;
  42176. + const char dir_char = (dir == VCHIQ_BULK_TRANSMIT) ? 't' : 'r';
  42177. + const int dir_msgtype = (dir == VCHIQ_BULK_TRANSMIT) ?
  42178. + VCHIQ_MSG_BULK_TX : VCHIQ_MSG_BULK_RX;
  42179. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  42180. +
  42181. + if (!service ||
  42182. + (service->srvstate != VCHIQ_SRVSTATE_OPEN) ||
  42183. + ((memhandle == VCHI_MEM_HANDLE_INVALID) && (offset == NULL)) ||
  42184. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  42185. + goto error_exit;
  42186. +
  42187. + switch (mode) {
  42188. + case VCHIQ_BULK_MODE_NOCALLBACK:
  42189. + case VCHIQ_BULK_MODE_CALLBACK:
  42190. + break;
  42191. + case VCHIQ_BULK_MODE_BLOCKING:
  42192. + bulk_waiter = (struct bulk_waiter *)userdata;
  42193. + sema_init(&bulk_waiter->event, 0);
  42194. + bulk_waiter->actual = 0;
  42195. + bulk_waiter->bulk = NULL;
  42196. + break;
  42197. + case VCHIQ_BULK_MODE_WAITING:
  42198. + bulk_waiter = (struct bulk_waiter *)userdata;
  42199. + bulk = bulk_waiter->bulk;
  42200. + goto waiting;
  42201. + default:
  42202. + goto error_exit;
  42203. + }
  42204. +
  42205. + state = service->state;
  42206. +
  42207. + queue = (dir == VCHIQ_BULK_TRANSMIT) ?
  42208. + &service->bulk_tx : &service->bulk_rx;
  42209. +
  42210. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0) {
  42211. + status = VCHIQ_RETRY;
  42212. + goto error_exit;
  42213. + }
  42214. +
  42215. + if (queue->local_insert == queue->remove + VCHIQ_NUM_SERVICE_BULKS) {
  42216. + VCHIQ_SERVICE_STATS_INC(service, bulk_stalls);
  42217. + do {
  42218. + mutex_unlock(&service->bulk_mutex);
  42219. + if (down_interruptible(&service->bulk_remove_event)
  42220. + != 0) {
  42221. + status = VCHIQ_RETRY;
  42222. + goto error_exit;
  42223. + }
  42224. + if (mutex_lock_interruptible(&service->bulk_mutex)
  42225. + != 0) {
  42226. + status = VCHIQ_RETRY;
  42227. + goto error_exit;
  42228. + }
  42229. + } while (queue->local_insert == queue->remove +
  42230. + VCHIQ_NUM_SERVICE_BULKS);
  42231. + }
  42232. +
  42233. + bulk = &queue->bulks[BULK_INDEX(queue->local_insert)];
  42234. +
  42235. + bulk->mode = mode;
  42236. + bulk->dir = dir;
  42237. + bulk->userdata = userdata;
  42238. + bulk->size = size;
  42239. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  42240. +
  42241. + if (vchiq_prepare_bulk_data(bulk, memhandle, offset, size, dir) !=
  42242. + VCHIQ_SUCCESS)
  42243. + goto unlock_error_exit;
  42244. +
  42245. + wmb();
  42246. +
  42247. + vchiq_log_info(vchiq_core_log_level,
  42248. + "%d: bt (%d->%d) %cx %x@%x %x",
  42249. + state->id,
  42250. + service->localport, service->remoteport, dir_char,
  42251. + size, (unsigned int)bulk->data, (unsigned int)userdata);
  42252. +
  42253. + if (state->is_master) {
  42254. + queue->local_insert++;
  42255. + if (resolve_bulks(service, queue))
  42256. + request_poll(state, service,
  42257. + (dir == VCHIQ_BULK_TRANSMIT) ?
  42258. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  42259. + } else {
  42260. + int payload[2] = { (int)bulk->data, bulk->size };
  42261. + VCHIQ_ELEMENT_T element = { payload, sizeof(payload) };
  42262. +
  42263. + status = queue_message(state, NULL,
  42264. + VCHIQ_MAKE_MSG(dir_msgtype,
  42265. + service->localport, service->remoteport),
  42266. + &element, 1, sizeof(payload), 1);
  42267. + if (status != VCHIQ_SUCCESS) {
  42268. + vchiq_complete_bulk(bulk);
  42269. + goto unlock_error_exit;
  42270. + }
  42271. + queue->local_insert++;
  42272. + }
  42273. +
  42274. + mutex_unlock(&service->bulk_mutex);
  42275. +
  42276. + vchiq_log_trace(vchiq_core_log_level,
  42277. + "%d: bt:%d %cx li=%x ri=%x p=%x",
  42278. + state->id,
  42279. + service->localport, dir_char,
  42280. + queue->local_insert, queue->remote_insert, queue->process);
  42281. +
  42282. +waiting:
  42283. + unlock_service(service);
  42284. +
  42285. + status = VCHIQ_SUCCESS;
  42286. +
  42287. + if (bulk_waiter) {
  42288. + bulk_waiter->bulk = bulk;
  42289. + if (down_interruptible(&bulk_waiter->event) != 0)
  42290. + status = VCHIQ_RETRY;
  42291. + else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED)
  42292. + status = VCHIQ_ERROR;
  42293. + }
  42294. +
  42295. + return status;
  42296. +
  42297. +unlock_error_exit:
  42298. + mutex_unlock(&service->bulk_mutex);
  42299. +
  42300. +error_exit:
  42301. + if (service)
  42302. + unlock_service(service);
  42303. + return status;
  42304. +}
  42305. +
  42306. +VCHIQ_STATUS_T
  42307. +vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T handle,
  42308. + const VCHIQ_ELEMENT_T *elements, unsigned int count)
  42309. +{
  42310. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  42311. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  42312. +
  42313. + unsigned int size = 0;
  42314. + unsigned int i;
  42315. +
  42316. + if (!service ||
  42317. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  42318. + goto error_exit;
  42319. +
  42320. + for (i = 0; i < (unsigned int)count; i++) {
  42321. + if (elements[i].size) {
  42322. + if (elements[i].data == NULL) {
  42323. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  42324. + goto error_exit;
  42325. + }
  42326. + size += elements[i].size;
  42327. + }
  42328. + }
  42329. +
  42330. + if (size > VCHIQ_MAX_MSG_SIZE) {
  42331. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  42332. + goto error_exit;
  42333. + }
  42334. +
  42335. + switch (service->srvstate) {
  42336. + case VCHIQ_SRVSTATE_OPEN:
  42337. + status = queue_message(service->state, service,
  42338. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  42339. + service->localport,
  42340. + service->remoteport),
  42341. + elements, count, size, 1);
  42342. + break;
  42343. + case VCHIQ_SRVSTATE_OPENSYNC:
  42344. + status = queue_message_sync(service->state, service,
  42345. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  42346. + service->localport,
  42347. + service->remoteport),
  42348. + elements, count, size, 1);
  42349. + break;
  42350. + default:
  42351. + status = VCHIQ_ERROR;
  42352. + break;
  42353. + }
  42354. +
  42355. +error_exit:
  42356. + if (service)
  42357. + unlock_service(service);
  42358. +
  42359. + return status;
  42360. +}
  42361. +
  42362. +void
  42363. +vchiq_release_message(VCHIQ_SERVICE_HANDLE_T handle, VCHIQ_HEADER_T *header)
  42364. +{
  42365. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  42366. + VCHIQ_SHARED_STATE_T *remote;
  42367. + VCHIQ_STATE_T *state;
  42368. + int slot_index;
  42369. +
  42370. + if (!service)
  42371. + return;
  42372. +
  42373. + state = service->state;
  42374. + remote = state->remote;
  42375. +
  42376. + slot_index = SLOT_INDEX_FROM_DATA(state, (void *)header);
  42377. +
  42378. + if ((slot_index >= remote->slot_first) &&
  42379. + (slot_index <= remote->slot_last)) {
  42380. + int msgid = header->msgid;
  42381. + if (msgid & VCHIQ_MSGID_CLAIMED) {
  42382. + VCHIQ_SLOT_INFO_T *slot_info =
  42383. + SLOT_INFO_FROM_INDEX(state, slot_index);
  42384. +
  42385. + release_slot(state, slot_info, header, service);
  42386. + }
  42387. + } else if (slot_index == remote->slot_sync)
  42388. + release_message_sync(state, header);
  42389. +
  42390. + unlock_service(service);
  42391. +}
  42392. +
  42393. +static void
  42394. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  42395. +{
  42396. + header->msgid = VCHIQ_MSGID_PADDING;
  42397. + wmb();
  42398. + remote_event_signal(&state->remote->sync_release);
  42399. +}
  42400. +
  42401. +VCHIQ_STATUS_T
  42402. +vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, short *peer_version)
  42403. +{
  42404. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  42405. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  42406. +
  42407. + if (!service ||
  42408. + (vchiq_check_service(service) != VCHIQ_SUCCESS) ||
  42409. + !peer_version)
  42410. + goto exit;
  42411. + *peer_version = service->peer_version;
  42412. + status = VCHIQ_SUCCESS;
  42413. +
  42414. +exit:
  42415. + if (service)
  42416. + unlock_service(service);
  42417. + return status;
  42418. +}
  42419. +
  42420. +VCHIQ_STATUS_T
  42421. +vchiq_get_config(VCHIQ_INSTANCE_T instance,
  42422. + int config_size, VCHIQ_CONFIG_T *pconfig)
  42423. +{
  42424. + VCHIQ_CONFIG_T config;
  42425. +
  42426. + (void)instance;
  42427. +
  42428. + config.max_msg_size = VCHIQ_MAX_MSG_SIZE;
  42429. + config.bulk_threshold = VCHIQ_MAX_MSG_SIZE;
  42430. + config.max_outstanding_bulks = VCHIQ_NUM_SERVICE_BULKS;
  42431. + config.max_services = VCHIQ_MAX_SERVICES;
  42432. + config.version = VCHIQ_VERSION;
  42433. + config.version_min = VCHIQ_VERSION_MIN;
  42434. +
  42435. + if (config_size > sizeof(VCHIQ_CONFIG_T))
  42436. + return VCHIQ_ERROR;
  42437. +
  42438. + memcpy(pconfig, &config,
  42439. + min(config_size, (int)(sizeof(VCHIQ_CONFIG_T))));
  42440. +
  42441. + return VCHIQ_SUCCESS;
  42442. +}
  42443. +
  42444. +VCHIQ_STATUS_T
  42445. +vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T handle,
  42446. + VCHIQ_SERVICE_OPTION_T option, int value)
  42447. +{
  42448. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  42449. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  42450. +
  42451. + if (service) {
  42452. + switch (option) {
  42453. + case VCHIQ_SERVICE_OPTION_AUTOCLOSE:
  42454. + service->auto_close = value;
  42455. + status = VCHIQ_SUCCESS;
  42456. + break;
  42457. +
  42458. + case VCHIQ_SERVICE_OPTION_SLOT_QUOTA: {
  42459. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  42460. + &service->state->service_quotas[
  42461. + service->localport];
  42462. + if (value == 0)
  42463. + value = service->state->default_slot_quota;
  42464. + if ((value >= service_quota->slot_use_count) &&
  42465. + (value < (unsigned short)~0)) {
  42466. + service_quota->slot_quota = value;
  42467. + if ((value >= service_quota->slot_use_count) &&
  42468. + (service_quota->message_quota >=
  42469. + service_quota->message_use_count)) {
  42470. + /* Signal the service that it may have
  42471. + ** dropped below its quota */
  42472. + up(&service_quota->quota_event);
  42473. + }
  42474. + status = VCHIQ_SUCCESS;
  42475. + }
  42476. + } break;
  42477. +
  42478. + case VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA: {
  42479. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  42480. + &service->state->service_quotas[
  42481. + service->localport];
  42482. + if (value == 0)
  42483. + value = service->state->default_message_quota;
  42484. + if ((value >= service_quota->message_use_count) &&
  42485. + (value < (unsigned short)~0)) {
  42486. + service_quota->message_quota = value;
  42487. + if ((value >=
  42488. + service_quota->message_use_count) &&
  42489. + (service_quota->slot_quota >=
  42490. + service_quota->slot_use_count))
  42491. + /* Signal the service that it may have
  42492. + ** dropped below its quota */
  42493. + up(&service_quota->quota_event);
  42494. + status = VCHIQ_SUCCESS;
  42495. + }
  42496. + } break;
  42497. +
  42498. + case VCHIQ_SERVICE_OPTION_SYNCHRONOUS:
  42499. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  42500. + (service->srvstate ==
  42501. + VCHIQ_SRVSTATE_LISTENING)) {
  42502. + service->sync = value;
  42503. + status = VCHIQ_SUCCESS;
  42504. + }
  42505. + break;
  42506. +
  42507. + case VCHIQ_SERVICE_OPTION_TRACE:
  42508. + service->trace = value;
  42509. + status = VCHIQ_SUCCESS;
  42510. + break;
  42511. +
  42512. + default:
  42513. + break;
  42514. + }
  42515. + unlock_service(service);
  42516. + }
  42517. +
  42518. + return status;
  42519. +}
  42520. +
  42521. +void
  42522. +vchiq_dump_shared_state(void *dump_context, VCHIQ_STATE_T *state,
  42523. + VCHIQ_SHARED_STATE_T *shared, const char *label)
  42524. +{
  42525. + static const char *const debug_names[] = {
  42526. + "<entries>",
  42527. + "SLOT_HANDLER_COUNT",
  42528. + "SLOT_HANDLER_LINE",
  42529. + "PARSE_LINE",
  42530. + "PARSE_HEADER",
  42531. + "PARSE_MSGID",
  42532. + "AWAIT_COMPLETION_LINE",
  42533. + "DEQUEUE_MESSAGE_LINE",
  42534. + "SERVICE_CALLBACK_LINE",
  42535. + "MSG_QUEUE_FULL_COUNT",
  42536. + "COMPLETION_QUEUE_FULL_COUNT"
  42537. + };
  42538. + int i;
  42539. +
  42540. + char buf[80];
  42541. + int len;
  42542. + len = snprintf(buf, sizeof(buf),
  42543. + " %s: slots %d-%d tx_pos=%x recycle=%x",
  42544. + label, shared->slot_first, shared->slot_last,
  42545. + shared->tx_pos, shared->slot_queue_recycle);
  42546. + vchiq_dump(dump_context, buf, len + 1);
  42547. +
  42548. + len = snprintf(buf, sizeof(buf),
  42549. + " Slots claimed:");
  42550. + vchiq_dump(dump_context, buf, len + 1);
  42551. +
  42552. + for (i = shared->slot_first; i <= shared->slot_last; i++) {
  42553. + VCHIQ_SLOT_INFO_T slot_info = *SLOT_INFO_FROM_INDEX(state, i);
  42554. + if (slot_info.use_count != slot_info.release_count) {
  42555. + len = snprintf(buf, sizeof(buf),
  42556. + " %d: %d/%d", i, slot_info.use_count,
  42557. + slot_info.release_count);
  42558. + vchiq_dump(dump_context, buf, len + 1);
  42559. + }
  42560. + }
  42561. +
  42562. + for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) {
  42563. + len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)",
  42564. + debug_names[i], shared->debug[i], shared->debug[i]);
  42565. + vchiq_dump(dump_context, buf, len + 1);
  42566. + }
  42567. +}
  42568. +
  42569. +void
  42570. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state)
  42571. +{
  42572. + char buf[80];
  42573. + int len;
  42574. + int i;
  42575. +
  42576. + len = snprintf(buf, sizeof(buf), "State %d: %s", state->id,
  42577. + conn_state_names[state->conn_state]);
  42578. + vchiq_dump(dump_context, buf, len + 1);
  42579. +
  42580. + len = snprintf(buf, sizeof(buf),
  42581. + " tx_pos=%x(@%x), rx_pos=%x(@%x)",
  42582. + state->local->tx_pos,
  42583. + (uint32_t)state->tx_data +
  42584. + (state->local_tx_pos & VCHIQ_SLOT_MASK),
  42585. + state->rx_pos,
  42586. + (uint32_t)state->rx_data +
  42587. + (state->rx_pos & VCHIQ_SLOT_MASK));
  42588. + vchiq_dump(dump_context, buf, len + 1);
  42589. +
  42590. + len = snprintf(buf, sizeof(buf),
  42591. + " Version: %d (min %d)",
  42592. + VCHIQ_VERSION, VCHIQ_VERSION_MIN);
  42593. + vchiq_dump(dump_context, buf, len + 1);
  42594. +
  42595. + if (VCHIQ_ENABLE_STATS) {
  42596. + len = snprintf(buf, sizeof(buf),
  42597. + " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, "
  42598. + "error_count=%d",
  42599. + state->stats.ctrl_tx_count, state->stats.ctrl_rx_count,
  42600. + state->stats.error_count);
  42601. + vchiq_dump(dump_context, buf, len + 1);
  42602. + }
  42603. +
  42604. + len = snprintf(buf, sizeof(buf),
  42605. + " Slots: %d available (%d data), %d recyclable, %d stalls "
  42606. + "(%d data)",
  42607. + ((state->slot_queue_available * VCHIQ_SLOT_SIZE) -
  42608. + state->local_tx_pos) / VCHIQ_SLOT_SIZE,
  42609. + state->data_quota - state->data_use_count,
  42610. + state->local->slot_queue_recycle - state->slot_queue_available,
  42611. + state->stats.slot_stalls, state->stats.data_stalls);
  42612. + vchiq_dump(dump_context, buf, len + 1);
  42613. +
  42614. + vchiq_dump_platform_state(dump_context);
  42615. +
  42616. + vchiq_dump_shared_state(dump_context, state, state->local, "Local");
  42617. + vchiq_dump_shared_state(dump_context, state, state->remote, "Remote");
  42618. +
  42619. + vchiq_dump_platform_instances(dump_context);
  42620. +
  42621. + for (i = 0; i < state->unused_service; i++) {
  42622. + VCHIQ_SERVICE_T *service = find_service_by_port(state, i);
  42623. +
  42624. + if (service) {
  42625. + vchiq_dump_service_state(dump_context, service);
  42626. + unlock_service(service);
  42627. + }
  42628. + }
  42629. +}
  42630. +
  42631. +void
  42632. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  42633. +{
  42634. + char buf[80];
  42635. + int len;
  42636. +
  42637. + len = snprintf(buf, sizeof(buf), "Service %d: %s (ref %u)",
  42638. + service->localport, srvstate_names[service->srvstate],
  42639. + service->ref_count - 1); /*Don't include the lock just taken*/
  42640. +
  42641. + if (service->srvstate != VCHIQ_SRVSTATE_FREE) {
  42642. + char remoteport[30];
  42643. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  42644. + &service->state->service_quotas[service->localport];
  42645. + int fourcc = service->base.fourcc;
  42646. + int tx_pending, rx_pending;
  42647. + if (service->remoteport != VCHIQ_PORT_FREE) {
  42648. + int len2 = snprintf(remoteport, sizeof(remoteport),
  42649. + "%d", service->remoteport);
  42650. + if (service->public_fourcc != VCHIQ_FOURCC_INVALID)
  42651. + snprintf(remoteport + len2,
  42652. + sizeof(remoteport) - len2,
  42653. + " (client %x)", service->client_id);
  42654. + } else
  42655. + strcpy(remoteport, "n/a");
  42656. +
  42657. + len += snprintf(buf + len, sizeof(buf) - len,
  42658. + " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)",
  42659. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  42660. + remoteport,
  42661. + service_quota->message_use_count,
  42662. + service_quota->message_quota,
  42663. + service_quota->slot_use_count,
  42664. + service_quota->slot_quota);
  42665. +
  42666. + vchiq_dump(dump_context, buf, len + 1);
  42667. +
  42668. + tx_pending = service->bulk_tx.local_insert -
  42669. + service->bulk_tx.remote_insert;
  42670. +
  42671. + rx_pending = service->bulk_rx.local_insert -
  42672. + service->bulk_rx.remote_insert;
  42673. +
  42674. + len = snprintf(buf, sizeof(buf),
  42675. + " Bulk: tx_pending=%d (size %d),"
  42676. + " rx_pending=%d (size %d)",
  42677. + tx_pending,
  42678. + tx_pending ? service->bulk_tx.bulks[
  42679. + BULK_INDEX(service->bulk_tx.remove)].size : 0,
  42680. + rx_pending,
  42681. + rx_pending ? service->bulk_rx.bulks[
  42682. + BULK_INDEX(service->bulk_rx.remove)].size : 0);
  42683. +
  42684. + if (VCHIQ_ENABLE_STATS) {
  42685. + vchiq_dump(dump_context, buf, len + 1);
  42686. +
  42687. + len = snprintf(buf, sizeof(buf),
  42688. + " Ctrl: tx_count=%d, tx_bytes=%llu, "
  42689. + "rx_count=%d, rx_bytes=%llu",
  42690. + service->stats.ctrl_tx_count,
  42691. + service->stats.ctrl_tx_bytes,
  42692. + service->stats.ctrl_rx_count,
  42693. + service->stats.ctrl_rx_bytes);
  42694. + vchiq_dump(dump_context, buf, len + 1);
  42695. +
  42696. + len = snprintf(buf, sizeof(buf),
  42697. + " Bulk: tx_count=%d, tx_bytes=%llu, "
  42698. + "rx_count=%d, rx_bytes=%llu",
  42699. + service->stats.bulk_tx_count,
  42700. + service->stats.bulk_tx_bytes,
  42701. + service->stats.bulk_rx_count,
  42702. + service->stats.bulk_rx_bytes);
  42703. + vchiq_dump(dump_context, buf, len + 1);
  42704. +
  42705. + len = snprintf(buf, sizeof(buf),
  42706. + " %d quota stalls, %d slot stalls, "
  42707. + "%d bulk stalls, %d aborted, %d errors",
  42708. + service->stats.quota_stalls,
  42709. + service->stats.slot_stalls,
  42710. + service->stats.bulk_stalls,
  42711. + service->stats.bulk_aborted_count,
  42712. + service->stats.error_count);
  42713. + }
  42714. + }
  42715. +
  42716. + vchiq_dump(dump_context, buf, len + 1);
  42717. +
  42718. + if (service->srvstate != VCHIQ_SRVSTATE_FREE)
  42719. + vchiq_dump_platform_service_state(dump_context, service);
  42720. +}
  42721. +
  42722. +
  42723. +void
  42724. +vchiq_loud_error_header(void)
  42725. +{
  42726. + vchiq_log_error(vchiq_core_log_level,
  42727. + "============================================================"
  42728. + "================");
  42729. + vchiq_log_error(vchiq_core_log_level,
  42730. + "============================================================"
  42731. + "================");
  42732. + vchiq_log_error(vchiq_core_log_level, "=====");
  42733. +}
  42734. +
  42735. +void
  42736. +vchiq_loud_error_footer(void)
  42737. +{
  42738. + vchiq_log_error(vchiq_core_log_level, "=====");
  42739. + vchiq_log_error(vchiq_core_log_level,
  42740. + "============================================================"
  42741. + "================");
  42742. + vchiq_log_error(vchiq_core_log_level,
  42743. + "============================================================"
  42744. + "================");
  42745. +}
  42746. +
  42747. +
  42748. +VCHIQ_STATUS_T vchiq_send_remote_use(VCHIQ_STATE_T *state)
  42749. +{
  42750. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  42751. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  42752. + status = queue_message(state, NULL,
  42753. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0),
  42754. + NULL, 0, 0, 0);
  42755. + return status;
  42756. +}
  42757. +
  42758. +VCHIQ_STATUS_T vchiq_send_remote_release(VCHIQ_STATE_T *state)
  42759. +{
  42760. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  42761. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  42762. + status = queue_message(state, NULL,
  42763. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0),
  42764. + NULL, 0, 0, 0);
  42765. + return status;
  42766. +}
  42767. +
  42768. +VCHIQ_STATUS_T vchiq_send_remote_use_active(VCHIQ_STATE_T *state)
  42769. +{
  42770. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  42771. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  42772. + status = queue_message(state, NULL,
  42773. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0),
  42774. + NULL, 0, 0, 0);
  42775. + return status;
  42776. +}
  42777. +
  42778. +void vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  42779. + size_t numBytes)
  42780. +{
  42781. + const uint8_t *mem = (const uint8_t *)voidMem;
  42782. + size_t offset;
  42783. + char lineBuf[100];
  42784. + char *s;
  42785. +
  42786. + while (numBytes > 0) {
  42787. + s = lineBuf;
  42788. +
  42789. + for (offset = 0; offset < 16; offset++) {
  42790. + if (offset < numBytes)
  42791. + s += snprintf(s, 4, "%02x ", mem[offset]);
  42792. + else
  42793. + s += snprintf(s, 4, " ");
  42794. + }
  42795. +
  42796. + for (offset = 0; offset < 16; offset++) {
  42797. + if (offset < numBytes) {
  42798. + uint8_t ch = mem[offset];
  42799. +
  42800. + if ((ch < ' ') || (ch > '~'))
  42801. + ch = '.';
  42802. + *s++ = (char)ch;
  42803. + }
  42804. + }
  42805. + *s++ = '\0';
  42806. +
  42807. + if ((label != NULL) && (*label != '\0'))
  42808. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  42809. + "%s: %08x: %s", label, addr, lineBuf);
  42810. + else
  42811. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  42812. + "%08x: %s", addr, lineBuf);
  42813. +
  42814. + addr += 16;
  42815. + mem += 16;
  42816. + if (numBytes > 16)
  42817. + numBytes -= 16;
  42818. + else
  42819. + numBytes = 0;
  42820. + }
  42821. +}
  42822. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h
  42823. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 1970-01-01 01:00:00.000000000 +0100
  42824. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 2015-02-09 04:40:08.000000000 +0100
  42825. @@ -0,0 +1,711 @@
  42826. +/**
  42827. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  42828. + *
  42829. + * Redistribution and use in source and binary forms, with or without
  42830. + * modification, are permitted provided that the following conditions
  42831. + * are met:
  42832. + * 1. Redistributions of source code must retain the above copyright
  42833. + * notice, this list of conditions, and the following disclaimer,
  42834. + * without modification.
  42835. + * 2. Redistributions in binary form must reproduce the above copyright
  42836. + * notice, this list of conditions and the following disclaimer in the
  42837. + * documentation and/or other materials provided with the distribution.
  42838. + * 3. The names of the above-listed copyright holders may not be used
  42839. + * to endorse or promote products derived from this software without
  42840. + * specific prior written permission.
  42841. + *
  42842. + * ALTERNATIVELY, this software may be distributed under the terms of the
  42843. + * GNU General Public License ("GPL") version 2, as published by the Free
  42844. + * Software Foundation.
  42845. + *
  42846. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  42847. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  42848. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  42849. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  42850. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  42851. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  42852. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  42853. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  42854. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  42855. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  42856. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42857. + */
  42858. +
  42859. +#ifndef VCHIQ_CORE_H
  42860. +#define VCHIQ_CORE_H
  42861. +
  42862. +#include <linux/mutex.h>
  42863. +#include <linux/semaphore.h>
  42864. +#include <linux/kthread.h>
  42865. +
  42866. +#include "vchiq_cfg.h"
  42867. +
  42868. +#include "vchiq.h"
  42869. +
  42870. +/* Run time control of log level, based on KERN_XXX level. */
  42871. +#define VCHIQ_LOG_DEFAULT 4
  42872. +#define VCHIQ_LOG_ERROR 3
  42873. +#define VCHIQ_LOG_WARNING 4
  42874. +#define VCHIQ_LOG_INFO 6
  42875. +#define VCHIQ_LOG_TRACE 7
  42876. +
  42877. +#define VCHIQ_LOG_PREFIX KERN_INFO "vchiq: "
  42878. +
  42879. +#ifndef vchiq_log_error
  42880. +#define vchiq_log_error(cat, fmt, ...) \
  42881. + do { if (cat >= VCHIQ_LOG_ERROR) \
  42882. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  42883. +#endif
  42884. +#ifndef vchiq_log_warning
  42885. +#define vchiq_log_warning(cat, fmt, ...) \
  42886. + do { if (cat >= VCHIQ_LOG_WARNING) \
  42887. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  42888. +#endif
  42889. +#ifndef vchiq_log_info
  42890. +#define vchiq_log_info(cat, fmt, ...) \
  42891. + do { if (cat >= VCHIQ_LOG_INFO) \
  42892. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  42893. +#endif
  42894. +#ifndef vchiq_log_trace
  42895. +#define vchiq_log_trace(cat, fmt, ...) \
  42896. + do { if (cat >= VCHIQ_LOG_TRACE) \
  42897. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  42898. +#endif
  42899. +
  42900. +#define vchiq_loud_error(...) \
  42901. + vchiq_log_error(vchiq_core_log_level, "===== " __VA_ARGS__)
  42902. +
  42903. +#ifndef vchiq_static_assert
  42904. +#define vchiq_static_assert(cond) __attribute__((unused)) \
  42905. + extern int vchiq_static_assert[(cond) ? 1 : -1]
  42906. +#endif
  42907. +
  42908. +#define IS_POW2(x) (x && ((x & (x - 1)) == 0))
  42909. +
  42910. +/* Ensure that the slot size and maximum number of slots are powers of 2 */
  42911. +vchiq_static_assert(IS_POW2(VCHIQ_SLOT_SIZE));
  42912. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS));
  42913. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS_PER_SIDE));
  42914. +
  42915. +#define VCHIQ_SLOT_MASK (VCHIQ_SLOT_SIZE - 1)
  42916. +#define VCHIQ_SLOT_QUEUE_MASK (VCHIQ_MAX_SLOTS_PER_SIDE - 1)
  42917. +#define VCHIQ_SLOT_ZERO_SLOTS ((sizeof(VCHIQ_SLOT_ZERO_T) + \
  42918. + VCHIQ_SLOT_SIZE - 1) / VCHIQ_SLOT_SIZE)
  42919. +
  42920. +#define VCHIQ_MSG_PADDING 0 /* - */
  42921. +#define VCHIQ_MSG_CONNECT 1 /* - */
  42922. +#define VCHIQ_MSG_OPEN 2 /* + (srcport, -), fourcc, client_id */
  42923. +#define VCHIQ_MSG_OPENACK 3 /* + (srcport, dstport) */
  42924. +#define VCHIQ_MSG_CLOSE 4 /* + (srcport, dstport) */
  42925. +#define VCHIQ_MSG_DATA 5 /* + (srcport, dstport) */
  42926. +#define VCHIQ_MSG_BULK_RX 6 /* + (srcport, dstport), data, size */
  42927. +#define VCHIQ_MSG_BULK_TX 7 /* + (srcport, dstport), data, size */
  42928. +#define VCHIQ_MSG_BULK_RX_DONE 8 /* + (srcport, dstport), actual */
  42929. +#define VCHIQ_MSG_BULK_TX_DONE 9 /* + (srcport, dstport), actual */
  42930. +#define VCHIQ_MSG_PAUSE 10 /* - */
  42931. +#define VCHIQ_MSG_RESUME 11 /* - */
  42932. +#define VCHIQ_MSG_REMOTE_USE 12 /* - */
  42933. +#define VCHIQ_MSG_REMOTE_RELEASE 13 /* - */
  42934. +#define VCHIQ_MSG_REMOTE_USE_ACTIVE 14 /* - */
  42935. +
  42936. +#define VCHIQ_PORT_MAX (VCHIQ_MAX_SERVICES - 1)
  42937. +#define VCHIQ_PORT_FREE 0x1000
  42938. +#define VCHIQ_PORT_IS_VALID(port) (port < VCHIQ_PORT_FREE)
  42939. +#define VCHIQ_MAKE_MSG(type, srcport, dstport) \
  42940. + ((type<<24) | (srcport<<12) | (dstport<<0))
  42941. +#define VCHIQ_MSG_TYPE(msgid) ((unsigned int)msgid >> 24)
  42942. +#define VCHIQ_MSG_SRCPORT(msgid) \
  42943. + (unsigned short)(((unsigned int)msgid >> 12) & 0xfff)
  42944. +#define VCHIQ_MSG_DSTPORT(msgid) \
  42945. + ((unsigned short)msgid & 0xfff)
  42946. +
  42947. +#define VCHIQ_FOURCC_AS_4CHARS(fourcc) \
  42948. + ((fourcc) >> 24) & 0xff, \
  42949. + ((fourcc) >> 16) & 0xff, \
  42950. + ((fourcc) >> 8) & 0xff, \
  42951. + (fourcc) & 0xff
  42952. +
  42953. +/* Ensure the fields are wide enough */
  42954. +vchiq_static_assert(VCHIQ_MSG_SRCPORT(VCHIQ_MAKE_MSG(0, 0, VCHIQ_PORT_MAX))
  42955. + == 0);
  42956. +vchiq_static_assert(VCHIQ_MSG_TYPE(VCHIQ_MAKE_MSG(0, VCHIQ_PORT_MAX, 0)) == 0);
  42957. +vchiq_static_assert((unsigned int)VCHIQ_PORT_MAX <
  42958. + (unsigned int)VCHIQ_PORT_FREE);
  42959. +
  42960. +#define VCHIQ_MSGID_PADDING VCHIQ_MAKE_MSG(VCHIQ_MSG_PADDING, 0, 0)
  42961. +#define VCHIQ_MSGID_CLAIMED 0x40000000
  42962. +
  42963. +#define VCHIQ_FOURCC_INVALID 0x00000000
  42964. +#define VCHIQ_FOURCC_IS_LEGAL(fourcc) (fourcc != VCHIQ_FOURCC_INVALID)
  42965. +
  42966. +#define VCHIQ_BULK_ACTUAL_ABORTED -1
  42967. +
  42968. +typedef uint32_t BITSET_T;
  42969. +
  42970. +vchiq_static_assert((sizeof(BITSET_T) * 8) == 32);
  42971. +
  42972. +#define BITSET_SIZE(b) ((b + 31) >> 5)
  42973. +#define BITSET_WORD(b) (b >> 5)
  42974. +#define BITSET_BIT(b) (1 << (b & 31))
  42975. +#define BITSET_ZERO(bs) memset(bs, 0, sizeof(bs))
  42976. +#define BITSET_IS_SET(bs, b) (bs[BITSET_WORD(b)] & BITSET_BIT(b))
  42977. +#define BITSET_SET(bs, b) (bs[BITSET_WORD(b)] |= BITSET_BIT(b))
  42978. +#define BITSET_CLR(bs, b) (bs[BITSET_WORD(b)] &= ~BITSET_BIT(b))
  42979. +
  42980. +#if VCHIQ_ENABLE_STATS
  42981. +#define VCHIQ_STATS_INC(state, stat) (state->stats. stat++)
  42982. +#define VCHIQ_SERVICE_STATS_INC(service, stat) (service->stats. stat++)
  42983. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) \
  42984. + (service->stats. stat += addend)
  42985. +#else
  42986. +#define VCHIQ_STATS_INC(state, stat) ((void)0)
  42987. +#define VCHIQ_SERVICE_STATS_INC(service, stat) ((void)0)
  42988. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) ((void)0)
  42989. +#endif
  42990. +
  42991. +enum {
  42992. + DEBUG_ENTRIES,
  42993. +#if VCHIQ_ENABLE_DEBUG
  42994. + DEBUG_SLOT_HANDLER_COUNT,
  42995. + DEBUG_SLOT_HANDLER_LINE,
  42996. + DEBUG_PARSE_LINE,
  42997. + DEBUG_PARSE_HEADER,
  42998. + DEBUG_PARSE_MSGID,
  42999. + DEBUG_AWAIT_COMPLETION_LINE,
  43000. + DEBUG_DEQUEUE_MESSAGE_LINE,
  43001. + DEBUG_SERVICE_CALLBACK_LINE,
  43002. + DEBUG_MSG_QUEUE_FULL_COUNT,
  43003. + DEBUG_COMPLETION_QUEUE_FULL_COUNT,
  43004. +#endif
  43005. + DEBUG_MAX
  43006. +};
  43007. +
  43008. +#if VCHIQ_ENABLE_DEBUG
  43009. +
  43010. +#define DEBUG_INITIALISE(local) int *debug_ptr = (local)->debug;
  43011. +#define DEBUG_TRACE(d) \
  43012. + do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(); } while (0)
  43013. +#define DEBUG_VALUE(d, v) \
  43014. + do { debug_ptr[DEBUG_ ## d] = (v); dsb(); } while (0)
  43015. +#define DEBUG_COUNT(d) \
  43016. + do { debug_ptr[DEBUG_ ## d]++; dsb(); } while (0)
  43017. +
  43018. +#else /* VCHIQ_ENABLE_DEBUG */
  43019. +
  43020. +#define DEBUG_INITIALISE(local)
  43021. +#define DEBUG_TRACE(d)
  43022. +#define DEBUG_VALUE(d, v)
  43023. +#define DEBUG_COUNT(d)
  43024. +
  43025. +#endif /* VCHIQ_ENABLE_DEBUG */
  43026. +
  43027. +typedef enum {
  43028. + VCHIQ_CONNSTATE_DISCONNECTED,
  43029. + VCHIQ_CONNSTATE_CONNECTING,
  43030. + VCHIQ_CONNSTATE_CONNECTED,
  43031. + VCHIQ_CONNSTATE_PAUSING,
  43032. + VCHIQ_CONNSTATE_PAUSE_SENT,
  43033. + VCHIQ_CONNSTATE_PAUSED,
  43034. + VCHIQ_CONNSTATE_RESUMING,
  43035. + VCHIQ_CONNSTATE_PAUSE_TIMEOUT,
  43036. + VCHIQ_CONNSTATE_RESUME_TIMEOUT
  43037. +} VCHIQ_CONNSTATE_T;
  43038. +
  43039. +enum {
  43040. + VCHIQ_SRVSTATE_FREE,
  43041. + VCHIQ_SRVSTATE_HIDDEN,
  43042. + VCHIQ_SRVSTATE_LISTENING,
  43043. + VCHIQ_SRVSTATE_OPENING,
  43044. + VCHIQ_SRVSTATE_OPEN,
  43045. + VCHIQ_SRVSTATE_OPENSYNC,
  43046. + VCHIQ_SRVSTATE_CLOSESENT,
  43047. + VCHIQ_SRVSTATE_CLOSERECVD,
  43048. + VCHIQ_SRVSTATE_CLOSEWAIT,
  43049. + VCHIQ_SRVSTATE_CLOSED
  43050. +};
  43051. +
  43052. +enum {
  43053. + VCHIQ_POLL_TERMINATE,
  43054. + VCHIQ_POLL_REMOVE,
  43055. + VCHIQ_POLL_TXNOTIFY,
  43056. + VCHIQ_POLL_RXNOTIFY,
  43057. + VCHIQ_POLL_COUNT
  43058. +};
  43059. +
  43060. +typedef enum {
  43061. + VCHIQ_BULK_TRANSMIT,
  43062. + VCHIQ_BULK_RECEIVE
  43063. +} VCHIQ_BULK_DIR_T;
  43064. +
  43065. +typedef void (*VCHIQ_USERDATA_TERM_T)(void *userdata);
  43066. +
  43067. +typedef struct vchiq_bulk_struct {
  43068. + short mode;
  43069. + short dir;
  43070. + void *userdata;
  43071. + VCHI_MEM_HANDLE_T handle;
  43072. + void *data;
  43073. + int size;
  43074. + void *remote_data;
  43075. + int remote_size;
  43076. + int actual;
  43077. +} VCHIQ_BULK_T;
  43078. +
  43079. +typedef struct vchiq_bulk_queue_struct {
  43080. + int local_insert; /* Where to insert the next local bulk */
  43081. + int remote_insert; /* Where to insert the next remote bulk (master) */
  43082. + int process; /* Bulk to transfer next */
  43083. + int remote_notify; /* Bulk to notify the remote client of next (mstr) */
  43084. + int remove; /* Bulk to notify the local client of, and remove,
  43085. + ** next */
  43086. + VCHIQ_BULK_T bulks[VCHIQ_NUM_SERVICE_BULKS];
  43087. +} VCHIQ_BULK_QUEUE_T;
  43088. +
  43089. +typedef struct remote_event_struct {
  43090. + int armed;
  43091. + int fired;
  43092. + struct semaphore *event;
  43093. +} REMOTE_EVENT_T;
  43094. +
  43095. +typedef struct opaque_platform_state_t *VCHIQ_PLATFORM_STATE_T;
  43096. +
  43097. +typedef struct vchiq_state_struct VCHIQ_STATE_T;
  43098. +
  43099. +typedef struct vchiq_slot_struct {
  43100. + char data[VCHIQ_SLOT_SIZE];
  43101. +} VCHIQ_SLOT_T;
  43102. +
  43103. +typedef struct vchiq_slot_info_struct {
  43104. + /* Use two counters rather than one to avoid the need for a mutex. */
  43105. + short use_count;
  43106. + short release_count;
  43107. +} VCHIQ_SLOT_INFO_T;
  43108. +
  43109. +typedef struct vchiq_service_struct {
  43110. + VCHIQ_SERVICE_BASE_T base;
  43111. + VCHIQ_SERVICE_HANDLE_T handle;
  43112. + unsigned int ref_count;
  43113. + int srvstate;
  43114. + VCHIQ_USERDATA_TERM_T userdata_term;
  43115. + unsigned int localport;
  43116. + unsigned int remoteport;
  43117. + int public_fourcc;
  43118. + int client_id;
  43119. + char auto_close;
  43120. + char sync;
  43121. + char closing;
  43122. + char trace;
  43123. + atomic_t poll_flags;
  43124. + short version;
  43125. + short version_min;
  43126. + short peer_version;
  43127. +
  43128. + VCHIQ_STATE_T *state;
  43129. + VCHIQ_INSTANCE_T instance;
  43130. +
  43131. + int service_use_count;
  43132. +
  43133. + VCHIQ_BULK_QUEUE_T bulk_tx;
  43134. + VCHIQ_BULK_QUEUE_T bulk_rx;
  43135. +
  43136. + struct semaphore remove_event;
  43137. + struct semaphore bulk_remove_event;
  43138. + struct mutex bulk_mutex;
  43139. +
  43140. + struct service_stats_struct {
  43141. + int quota_stalls;
  43142. + int slot_stalls;
  43143. + int bulk_stalls;
  43144. + int error_count;
  43145. + int ctrl_tx_count;
  43146. + int ctrl_rx_count;
  43147. + int bulk_tx_count;
  43148. + int bulk_rx_count;
  43149. + int bulk_aborted_count;
  43150. + uint64_t ctrl_tx_bytes;
  43151. + uint64_t ctrl_rx_bytes;
  43152. + uint64_t bulk_tx_bytes;
  43153. + uint64_t bulk_rx_bytes;
  43154. + } stats;
  43155. +} VCHIQ_SERVICE_T;
  43156. +
  43157. +/* The quota information is outside VCHIQ_SERVICE_T so that it can be
  43158. + statically allocated, since for accounting reasons a service's slot
  43159. + usage is carried over between users of the same port number.
  43160. + */
  43161. +typedef struct vchiq_service_quota_struct {
  43162. + unsigned short slot_quota;
  43163. + unsigned short slot_use_count;
  43164. + unsigned short message_quota;
  43165. + unsigned short message_use_count;
  43166. + struct semaphore quota_event;
  43167. + int previous_tx_index;
  43168. +} VCHIQ_SERVICE_QUOTA_T;
  43169. +
  43170. +typedef struct vchiq_shared_state_struct {
  43171. +
  43172. + /* A non-zero value here indicates that the content is valid. */
  43173. + int initialised;
  43174. +
  43175. + /* The first and last (inclusive) slots allocated to the owner. */
  43176. + int slot_first;
  43177. + int slot_last;
  43178. +
  43179. + /* The slot allocated to synchronous messages from the owner. */
  43180. + int slot_sync;
  43181. +
  43182. + /* Signalling this event indicates that owner's slot handler thread
  43183. + ** should run. */
  43184. + REMOTE_EVENT_T trigger;
  43185. +
  43186. + /* Indicates the byte position within the stream where the next message
  43187. + ** will be written. The least significant bits are an index into the
  43188. + ** slot. The next bits are the index of the slot in slot_queue. */
  43189. + int tx_pos;
  43190. +
  43191. + /* This event should be signalled when a slot is recycled. */
  43192. + REMOTE_EVENT_T recycle;
  43193. +
  43194. + /* The slot_queue index where the next recycled slot will be written. */
  43195. + int slot_queue_recycle;
  43196. +
  43197. + /* This event should be signalled when a synchronous message is sent. */
  43198. + REMOTE_EVENT_T sync_trigger;
  43199. +
  43200. + /* This event should be signalled when a synchronous message has been
  43201. + ** released. */
  43202. + REMOTE_EVENT_T sync_release;
  43203. +
  43204. + /* A circular buffer of slot indexes. */
  43205. + int slot_queue[VCHIQ_MAX_SLOTS_PER_SIDE];
  43206. +
  43207. + /* Debugging state */
  43208. + int debug[DEBUG_MAX];
  43209. +} VCHIQ_SHARED_STATE_T;
  43210. +
  43211. +typedef struct vchiq_slot_zero_struct {
  43212. + int magic;
  43213. + short version;
  43214. + short version_min;
  43215. + int slot_zero_size;
  43216. + int slot_size;
  43217. + int max_slots;
  43218. + int max_slots_per_side;
  43219. + int platform_data[2];
  43220. + VCHIQ_SHARED_STATE_T master;
  43221. + VCHIQ_SHARED_STATE_T slave;
  43222. + VCHIQ_SLOT_INFO_T slots[VCHIQ_MAX_SLOTS];
  43223. +} VCHIQ_SLOT_ZERO_T;
  43224. +
  43225. +struct vchiq_state_struct {
  43226. + int id;
  43227. + int initialised;
  43228. + VCHIQ_CONNSTATE_T conn_state;
  43229. + int is_master;
  43230. +
  43231. + VCHIQ_SHARED_STATE_T *local;
  43232. + VCHIQ_SHARED_STATE_T *remote;
  43233. + VCHIQ_SLOT_T *slot_data;
  43234. +
  43235. + unsigned short default_slot_quota;
  43236. + unsigned short default_message_quota;
  43237. +
  43238. + /* Event indicating connect message received */
  43239. + struct semaphore connect;
  43240. +
  43241. + /* Mutex protecting services */
  43242. + struct mutex mutex;
  43243. + VCHIQ_INSTANCE_T *instance;
  43244. +
  43245. + /* Processes incoming messages */
  43246. + struct task_struct *slot_handler_thread;
  43247. +
  43248. + /* Processes recycled slots */
  43249. + struct task_struct *recycle_thread;
  43250. +
  43251. + /* Processes synchronous messages */
  43252. + struct task_struct *sync_thread;
  43253. +
  43254. + /* Local implementation of the trigger remote event */
  43255. + struct semaphore trigger_event;
  43256. +
  43257. + /* Local implementation of the recycle remote event */
  43258. + struct semaphore recycle_event;
  43259. +
  43260. + /* Local implementation of the sync trigger remote event */
  43261. + struct semaphore sync_trigger_event;
  43262. +
  43263. + /* Local implementation of the sync release remote event */
  43264. + struct semaphore sync_release_event;
  43265. +
  43266. + char *tx_data;
  43267. + char *rx_data;
  43268. + VCHIQ_SLOT_INFO_T *rx_info;
  43269. +
  43270. + struct mutex slot_mutex;
  43271. +
  43272. + struct mutex recycle_mutex;
  43273. +
  43274. + struct mutex sync_mutex;
  43275. +
  43276. + struct mutex bulk_transfer_mutex;
  43277. +
  43278. + /* Indicates the byte position within the stream from where the next
  43279. + ** message will be read. The least significant bits are an index into
  43280. + ** the slot.The next bits are the index of the slot in
  43281. + ** remote->slot_queue. */
  43282. + int rx_pos;
  43283. +
  43284. + /* A cached copy of local->tx_pos. Only write to local->tx_pos, and read
  43285. + from remote->tx_pos. */
  43286. + int local_tx_pos;
  43287. +
  43288. + /* The slot_queue index of the slot to become available next. */
  43289. + int slot_queue_available;
  43290. +
  43291. + /* A flag to indicate if any poll has been requested */
  43292. + int poll_needed;
  43293. +
  43294. + /* Ths index of the previous slot used for data messages. */
  43295. + int previous_data_index;
  43296. +
  43297. + /* The number of slots occupied by data messages. */
  43298. + unsigned short data_use_count;
  43299. +
  43300. + /* The maximum number of slots to be occupied by data messages. */
  43301. + unsigned short data_quota;
  43302. +
  43303. + /* An array of bit sets indicating which services must be polled. */
  43304. + atomic_t poll_services[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  43305. +
  43306. + /* The number of the first unused service */
  43307. + int unused_service;
  43308. +
  43309. + /* Signalled when a free slot becomes available. */
  43310. + struct semaphore slot_available_event;
  43311. +
  43312. + struct semaphore slot_remove_event;
  43313. +
  43314. + /* Signalled when a free data slot becomes available. */
  43315. + struct semaphore data_quota_event;
  43316. +
  43317. + /* Incremented when there are bulk transfers which cannot be processed
  43318. + * whilst paused and must be processed on resume */
  43319. + int deferred_bulks;
  43320. +
  43321. + struct state_stats_struct {
  43322. + int slot_stalls;
  43323. + int data_stalls;
  43324. + int ctrl_tx_count;
  43325. + int ctrl_rx_count;
  43326. + int error_count;
  43327. + } stats;
  43328. +
  43329. + VCHIQ_SERVICE_T * services[VCHIQ_MAX_SERVICES];
  43330. + VCHIQ_SERVICE_QUOTA_T service_quotas[VCHIQ_MAX_SERVICES];
  43331. + VCHIQ_SLOT_INFO_T slot_info[VCHIQ_MAX_SLOTS];
  43332. +
  43333. + VCHIQ_PLATFORM_STATE_T platform_state;
  43334. +};
  43335. +
  43336. +struct bulk_waiter {
  43337. + VCHIQ_BULK_T *bulk;
  43338. + struct semaphore event;
  43339. + int actual;
  43340. +};
  43341. +
  43342. +extern spinlock_t bulk_waiter_spinlock;
  43343. +
  43344. +extern int vchiq_core_log_level;
  43345. +extern int vchiq_core_msg_log_level;
  43346. +extern int vchiq_sync_log_level;
  43347. +
  43348. +extern VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  43349. +
  43350. +extern const char *
  43351. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state);
  43352. +
  43353. +extern VCHIQ_SLOT_ZERO_T *
  43354. +vchiq_init_slots(void *mem_base, int mem_size);
  43355. +
  43356. +extern VCHIQ_STATUS_T
  43357. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  43358. + int is_master);
  43359. +
  43360. +extern VCHIQ_STATUS_T
  43361. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  43362. +
  43363. +extern VCHIQ_SERVICE_T *
  43364. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  43365. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  43366. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term);
  43367. +
  43368. +extern VCHIQ_STATUS_T
  43369. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id);
  43370. +
  43371. +extern VCHIQ_STATUS_T
  43372. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd);
  43373. +
  43374. +extern void
  43375. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service);
  43376. +
  43377. +extern void
  43378. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service);
  43379. +
  43380. +extern VCHIQ_STATUS_T
  43381. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  43382. +
  43383. +extern VCHIQ_STATUS_T
  43384. +vchiq_pause_internal(VCHIQ_STATE_T *state);
  43385. +
  43386. +extern VCHIQ_STATUS_T
  43387. +vchiq_resume_internal(VCHIQ_STATE_T *state);
  43388. +
  43389. +extern void
  43390. +remote_event_pollall(VCHIQ_STATE_T *state);
  43391. +
  43392. +extern VCHIQ_STATUS_T
  43393. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  43394. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  43395. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir);
  43396. +
  43397. +extern void
  43398. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state);
  43399. +
  43400. +extern void
  43401. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service);
  43402. +
  43403. +extern void
  43404. +vchiq_loud_error_header(void);
  43405. +
  43406. +extern void
  43407. +vchiq_loud_error_footer(void);
  43408. +
  43409. +extern void
  43410. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type);
  43411. +
  43412. +static inline VCHIQ_SERVICE_T *
  43413. +handle_to_service(VCHIQ_SERVICE_HANDLE_T handle)
  43414. +{
  43415. + VCHIQ_STATE_T *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) &
  43416. + (VCHIQ_MAX_STATES - 1)];
  43417. + if (!state)
  43418. + return NULL;
  43419. +
  43420. + return state->services[handle & (VCHIQ_MAX_SERVICES - 1)];
  43421. +}
  43422. +
  43423. +extern VCHIQ_SERVICE_T *
  43424. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle);
  43425. +
  43426. +extern VCHIQ_SERVICE_T *
  43427. +find_service_by_port(VCHIQ_STATE_T *state, int localport);
  43428. +
  43429. +extern VCHIQ_SERVICE_T *
  43430. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  43431. + VCHIQ_SERVICE_HANDLE_T handle);
  43432. +
  43433. +extern VCHIQ_SERVICE_T *
  43434. +find_closed_service_for_instance(VCHIQ_INSTANCE_T instance,
  43435. + VCHIQ_SERVICE_HANDLE_T handle);
  43436. +
  43437. +extern VCHIQ_SERVICE_T *
  43438. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  43439. + int *pidx);
  43440. +
  43441. +extern void
  43442. +lock_service(VCHIQ_SERVICE_T *service);
  43443. +
  43444. +extern void
  43445. +unlock_service(VCHIQ_SERVICE_T *service);
  43446. +
  43447. +/* The following functions are called from vchiq_core, and external
  43448. +** implementations must be provided. */
  43449. +
  43450. +extern VCHIQ_STATUS_T
  43451. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk,
  43452. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, int dir);
  43453. +
  43454. +extern void
  43455. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk);
  43456. +
  43457. +extern void
  43458. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk);
  43459. +
  43460. +extern VCHIQ_STATUS_T
  43461. +vchiq_copy_from_user(void *dst, const void *src, int size);
  43462. +
  43463. +extern void
  43464. +remote_event_signal(REMOTE_EVENT_T *event);
  43465. +
  43466. +void
  43467. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state);
  43468. +
  43469. +extern void
  43470. +vchiq_platform_paused(VCHIQ_STATE_T *state);
  43471. +
  43472. +extern VCHIQ_STATUS_T
  43473. +vchiq_platform_resume(VCHIQ_STATE_T *state);
  43474. +
  43475. +extern void
  43476. +vchiq_platform_resumed(VCHIQ_STATE_T *state);
  43477. +
  43478. +extern void
  43479. +vchiq_dump(void *dump_context, const char *str, int len);
  43480. +
  43481. +extern void
  43482. +vchiq_dump_platform_state(void *dump_context);
  43483. +
  43484. +extern void
  43485. +vchiq_dump_platform_instances(void *dump_context);
  43486. +
  43487. +extern void
  43488. +vchiq_dump_platform_service_state(void *dump_context,
  43489. + VCHIQ_SERVICE_T *service);
  43490. +
  43491. +extern VCHIQ_STATUS_T
  43492. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service);
  43493. +
  43494. +extern VCHIQ_STATUS_T
  43495. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service);
  43496. +
  43497. +extern void
  43498. +vchiq_on_remote_use(VCHIQ_STATE_T *state);
  43499. +
  43500. +extern void
  43501. +vchiq_on_remote_release(VCHIQ_STATE_T *state);
  43502. +
  43503. +extern VCHIQ_STATUS_T
  43504. +vchiq_platform_init_state(VCHIQ_STATE_T *state);
  43505. +
  43506. +extern VCHIQ_STATUS_T
  43507. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  43508. +
  43509. +extern void
  43510. +vchiq_on_remote_use_active(VCHIQ_STATE_T *state);
  43511. +
  43512. +extern VCHIQ_STATUS_T
  43513. +vchiq_send_remote_use(VCHIQ_STATE_T *state);
  43514. +
  43515. +extern VCHIQ_STATUS_T
  43516. +vchiq_send_remote_release(VCHIQ_STATE_T *state);
  43517. +
  43518. +extern VCHIQ_STATUS_T
  43519. +vchiq_send_remote_use_active(VCHIQ_STATE_T *state);
  43520. +
  43521. +extern void
  43522. +vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  43523. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate);
  43524. +
  43525. +extern void
  43526. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state);
  43527. +
  43528. +extern void
  43529. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate);
  43530. +
  43531. +
  43532. +extern void
  43533. +vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  43534. + size_t numBytes);
  43535. +
  43536. +#endif
  43537. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.c
  43538. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.c 1970-01-01 01:00:00.000000000 +0100
  43539. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.c 2015-02-09 04:40:08.000000000 +0100
  43540. @@ -0,0 +1,383 @@
  43541. +/**
  43542. + * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
  43543. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  43544. + *
  43545. + * Redistribution and use in source and binary forms, with or without
  43546. + * modification, are permitted provided that the following conditions
  43547. + * are met:
  43548. + * 1. Redistributions of source code must retain the above copyright
  43549. + * notice, this list of conditions, and the following disclaimer,
  43550. + * without modification.
  43551. + * 2. Redistributions in binary form must reproduce the above copyright
  43552. + * notice, this list of conditions and the following disclaimer in the
  43553. + * documentation and/or other materials provided with the distribution.
  43554. + * 3. The names of the above-listed copyright holders may not be used
  43555. + * to endorse or promote products derived from this software without
  43556. + * specific prior written permission.
  43557. + *
  43558. + * ALTERNATIVELY, this software may be distributed under the terms of the
  43559. + * GNU General Public License ("GPL") version 2, as published by the Free
  43560. + * Software Foundation.
  43561. + *
  43562. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  43563. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  43564. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  43565. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  43566. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43567. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43568. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43569. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  43570. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  43571. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  43572. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43573. + */
  43574. +
  43575. +
  43576. +#include <linux/debugfs.h>
  43577. +#include "vchiq_core.h"
  43578. +#include "vchiq_arm.h"
  43579. +#include "vchiq_debugfs.h"
  43580. +
  43581. +#ifdef CONFIG_DEBUG_FS
  43582. +
  43583. +/****************************************************************************
  43584. +*
  43585. +* log category entries
  43586. +*
  43587. +***************************************************************************/
  43588. +#define DEBUGFS_WRITE_BUF_SIZE 256
  43589. +
  43590. +#define VCHIQ_LOG_ERROR_STR "error"
  43591. +#define VCHIQ_LOG_WARNING_STR "warning"
  43592. +#define VCHIQ_LOG_INFO_STR "info"
  43593. +#define VCHIQ_LOG_TRACE_STR "trace"
  43594. +
  43595. +
  43596. +/* Top-level debug info */
  43597. +struct vchiq_debugfs_info {
  43598. + /* Global 'vchiq' debugfs entry used by all instances */
  43599. + struct dentry *vchiq_cfg_dir;
  43600. +
  43601. + /* one entry per client process */
  43602. + struct dentry *clients;
  43603. +
  43604. + /* log categories */
  43605. + struct dentry *log_categories;
  43606. +};
  43607. +
  43608. +static struct vchiq_debugfs_info debugfs_info;
  43609. +
  43610. +/* Log category debugfs entries */
  43611. +struct vchiq_debugfs_log_entry {
  43612. + const char *name;
  43613. + int *plevel;
  43614. + struct dentry *dir;
  43615. +};
  43616. +
  43617. +static struct vchiq_debugfs_log_entry vchiq_debugfs_log_entries[] = {
  43618. + { "core", &vchiq_core_log_level },
  43619. + { "msg", &vchiq_core_msg_log_level },
  43620. + { "sync", &vchiq_sync_log_level },
  43621. + { "susp", &vchiq_susp_log_level },
  43622. + { "arm", &vchiq_arm_log_level },
  43623. +};
  43624. +static int n_log_entries =
  43625. + sizeof(vchiq_debugfs_log_entries)/sizeof(vchiq_debugfs_log_entries[0]);
  43626. +
  43627. +
  43628. +static struct dentry *vchiq_clients_top(void);
  43629. +static struct dentry *vchiq_debugfs_top(void);
  43630. +
  43631. +static int debugfs_log_show(struct seq_file *f, void *offset)
  43632. +{
  43633. + int *levp = f->private;
  43634. + char *log_value = NULL;
  43635. +
  43636. + switch (*levp) {
  43637. + case VCHIQ_LOG_ERROR:
  43638. + log_value = VCHIQ_LOG_ERROR_STR;
  43639. + break;
  43640. + case VCHIQ_LOG_WARNING:
  43641. + log_value = VCHIQ_LOG_WARNING_STR;
  43642. + break;
  43643. + case VCHIQ_LOG_INFO:
  43644. + log_value = VCHIQ_LOG_INFO_STR;
  43645. + break;
  43646. + case VCHIQ_LOG_TRACE:
  43647. + log_value = VCHIQ_LOG_TRACE_STR;
  43648. + break;
  43649. + default:
  43650. + break;
  43651. + }
  43652. +
  43653. + seq_printf(f, "%s\n", log_value ? log_value : "(null)");
  43654. +
  43655. + return 0;
  43656. +}
  43657. +
  43658. +static int debugfs_log_open(struct inode *inode, struct file *file)
  43659. +{
  43660. + return single_open(file, debugfs_log_show, inode->i_private);
  43661. +}
  43662. +
  43663. +static int debugfs_log_write(struct file *file,
  43664. + const char __user *buffer,
  43665. + size_t count, loff_t *ppos)
  43666. +{
  43667. + struct seq_file *f = (struct seq_file *)file->private_data;
  43668. + int *levp = f->private;
  43669. + char kbuf[DEBUGFS_WRITE_BUF_SIZE + 1];
  43670. +
  43671. + memset(kbuf, 0, DEBUGFS_WRITE_BUF_SIZE + 1);
  43672. + if (count >= DEBUGFS_WRITE_BUF_SIZE)
  43673. + count = DEBUGFS_WRITE_BUF_SIZE;
  43674. +
  43675. + if (copy_from_user(kbuf, buffer, count) != 0)
  43676. + return -EFAULT;
  43677. + kbuf[count - 1] = 0;
  43678. +
  43679. + if (strncmp("error", kbuf, strlen("error")) == 0)
  43680. + *levp = VCHIQ_LOG_ERROR;
  43681. + else if (strncmp("warning", kbuf, strlen("warning")) == 0)
  43682. + *levp = VCHIQ_LOG_WARNING;
  43683. + else if (strncmp("info", kbuf, strlen("info")) == 0)
  43684. + *levp = VCHIQ_LOG_INFO;
  43685. + else if (strncmp("trace", kbuf, strlen("trace")) == 0)
  43686. + *levp = VCHIQ_LOG_TRACE;
  43687. + else
  43688. + *levp = VCHIQ_LOG_DEFAULT;
  43689. +
  43690. + *ppos += count;
  43691. +
  43692. + return count;
  43693. +}
  43694. +
  43695. +static const struct file_operations debugfs_log_fops = {
  43696. + .owner = THIS_MODULE,
  43697. + .open = debugfs_log_open,
  43698. + .write = debugfs_log_write,
  43699. + .read = seq_read,
  43700. + .llseek = seq_lseek,
  43701. + .release = single_release,
  43702. +};
  43703. +
  43704. +/* create an entry under <debugfs>/vchiq/log for each log category */
  43705. +static int vchiq_debugfs_create_log_entries(struct dentry *top)
  43706. +{
  43707. + struct dentry *dir;
  43708. + size_t i;
  43709. + int ret = 0;
  43710. + dir = debugfs_create_dir("log", vchiq_debugfs_top());
  43711. + if (!dir)
  43712. + return -ENOMEM;
  43713. + debugfs_info.log_categories = dir;
  43714. +
  43715. + for (i = 0; i < n_log_entries; i++) {
  43716. + void *levp = (void *)vchiq_debugfs_log_entries[i].plevel;
  43717. + dir = debugfs_create_file(vchiq_debugfs_log_entries[i].name,
  43718. + 0644,
  43719. + debugfs_info.log_categories,
  43720. + levp,
  43721. + &debugfs_log_fops);
  43722. + if (!dir) {
  43723. + ret = -ENOMEM;
  43724. + break;
  43725. + }
  43726. +
  43727. + vchiq_debugfs_log_entries[i].dir = dir;
  43728. + }
  43729. + return ret;
  43730. +}
  43731. +
  43732. +static int debugfs_usecount_show(struct seq_file *f, void *offset)
  43733. +{
  43734. + VCHIQ_INSTANCE_T instance = f->private;
  43735. + int use_count;
  43736. +
  43737. + use_count = vchiq_instance_get_use_count(instance);
  43738. + seq_printf(f, "%d\n", use_count);
  43739. +
  43740. + return 0;
  43741. +}
  43742. +
  43743. +static int debugfs_usecount_open(struct inode *inode, struct file *file)
  43744. +{
  43745. + return single_open(file, debugfs_usecount_show, inode->i_private);
  43746. +}
  43747. +
  43748. +static const struct file_operations debugfs_usecount_fops = {
  43749. + .owner = THIS_MODULE,
  43750. + .open = debugfs_usecount_open,
  43751. + .read = seq_read,
  43752. + .llseek = seq_lseek,
  43753. + .release = single_release,
  43754. +};
  43755. +
  43756. +static int debugfs_trace_show(struct seq_file *f, void *offset)
  43757. +{
  43758. + VCHIQ_INSTANCE_T instance = f->private;
  43759. + int trace;
  43760. +
  43761. + trace = vchiq_instance_get_trace(instance);
  43762. + seq_printf(f, "%s\n", trace ? "Y" : "N");
  43763. +
  43764. + return 0;
  43765. +}
  43766. +
  43767. +static int debugfs_trace_open(struct inode *inode, struct file *file)
  43768. +{
  43769. + return single_open(file, debugfs_trace_show, inode->i_private);
  43770. +}
  43771. +
  43772. +static int debugfs_trace_write(struct file *file,
  43773. + const char __user *buffer,
  43774. + size_t count, loff_t *ppos)
  43775. +{
  43776. + struct seq_file *f = (struct seq_file *)file->private_data;
  43777. + VCHIQ_INSTANCE_T instance = f->private;
  43778. + char firstchar;
  43779. +
  43780. + if (copy_from_user(&firstchar, buffer, 1) != 0)
  43781. + return -EFAULT;
  43782. +
  43783. + switch (firstchar) {
  43784. + case 'Y':
  43785. + case 'y':
  43786. + case '1':
  43787. + vchiq_instance_set_trace(instance, 1);
  43788. + break;
  43789. + case 'N':
  43790. + case 'n':
  43791. + case '0':
  43792. + vchiq_instance_set_trace(instance, 0);
  43793. + break;
  43794. + default:
  43795. + break;
  43796. + }
  43797. +
  43798. + *ppos += count;
  43799. +
  43800. + return count;
  43801. +}
  43802. +
  43803. +static const struct file_operations debugfs_trace_fops = {
  43804. + .owner = THIS_MODULE,
  43805. + .open = debugfs_trace_open,
  43806. + .write = debugfs_trace_write,
  43807. + .read = seq_read,
  43808. + .llseek = seq_lseek,
  43809. + .release = single_release,
  43810. +};
  43811. +
  43812. +/* add an instance (process) to the debugfs entries */
  43813. +int vchiq_debugfs_add_instance(VCHIQ_INSTANCE_T instance)
  43814. +{
  43815. + char pidstr[16];
  43816. + struct dentry *top, *use_count, *trace;
  43817. + struct dentry *clients = vchiq_clients_top();
  43818. +
  43819. + snprintf(pidstr, sizeof(pidstr), "%d",
  43820. + vchiq_instance_get_pid(instance));
  43821. +
  43822. + top = debugfs_create_dir(pidstr, clients);
  43823. + if (!top)
  43824. + goto fail_top;
  43825. +
  43826. + use_count = debugfs_create_file("use_count",
  43827. + 0444, top,
  43828. + instance,
  43829. + &debugfs_usecount_fops);
  43830. + if (!use_count)
  43831. + goto fail_use_count;
  43832. +
  43833. + trace = debugfs_create_file("trace",
  43834. + 0644, top,
  43835. + instance,
  43836. + &debugfs_trace_fops);
  43837. + if (!trace)
  43838. + goto fail_trace;
  43839. +
  43840. + vchiq_instance_get_debugfs_node(instance)->dentry = top;
  43841. +
  43842. + return 0;
  43843. +
  43844. +fail_trace:
  43845. + debugfs_remove(use_count);
  43846. +fail_use_count:
  43847. + debugfs_remove(top);
  43848. +fail_top:
  43849. + return -ENOMEM;
  43850. +}
  43851. +
  43852. +void vchiq_debugfs_remove_instance(VCHIQ_INSTANCE_T instance)
  43853. +{
  43854. + VCHIQ_DEBUGFS_NODE_T *node = vchiq_instance_get_debugfs_node(instance);
  43855. + debugfs_remove_recursive(node->dentry);
  43856. +}
  43857. +
  43858. +
  43859. +int vchiq_debugfs_init(void)
  43860. +{
  43861. + BUG_ON(debugfs_info.vchiq_cfg_dir != NULL);
  43862. +
  43863. + debugfs_info.vchiq_cfg_dir = debugfs_create_dir("vchiq", NULL);
  43864. + if (debugfs_info.vchiq_cfg_dir == NULL)
  43865. + goto fail;
  43866. +
  43867. + debugfs_info.clients = debugfs_create_dir("clients",
  43868. + vchiq_debugfs_top());
  43869. + if (!debugfs_info.clients)
  43870. + goto fail;
  43871. +
  43872. + if (vchiq_debugfs_create_log_entries(vchiq_debugfs_top()) != 0)
  43873. + goto fail;
  43874. +
  43875. + return 0;
  43876. +
  43877. +fail:
  43878. + vchiq_debugfs_deinit();
  43879. + vchiq_log_error(vchiq_arm_log_level,
  43880. + "%s: failed to create debugfs directory",
  43881. + __func__);
  43882. +
  43883. + return -ENOMEM;
  43884. +}
  43885. +
  43886. +/* remove all the debugfs entries */
  43887. +void vchiq_debugfs_deinit(void)
  43888. +{
  43889. + debugfs_remove_recursive(vchiq_debugfs_top());
  43890. +}
  43891. +
  43892. +static struct dentry *vchiq_clients_top(void)
  43893. +{
  43894. + return debugfs_info.clients;
  43895. +}
  43896. +
  43897. +static struct dentry *vchiq_debugfs_top(void)
  43898. +{
  43899. + BUG_ON(debugfs_info.vchiq_cfg_dir == NULL);
  43900. + return debugfs_info.vchiq_cfg_dir;
  43901. +}
  43902. +
  43903. +#else /* CONFIG_DEBUG_FS */
  43904. +
  43905. +int vchiq_debugfs_init(void)
  43906. +{
  43907. + return 0;
  43908. +}
  43909. +
  43910. +void vchiq_debugfs_deinit(void)
  43911. +{
  43912. +}
  43913. +
  43914. +int vchiq_debugfs_add_instance(VCHIQ_INSTANCE_T instance)
  43915. +{
  43916. + return 0;
  43917. +}
  43918. +
  43919. +void vchiq_debugfs_remove_instance(VCHIQ_INSTANCE_T instance)
  43920. +{
  43921. +}
  43922. +
  43923. +#endif /* CONFIG_DEBUG_FS */
  43924. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.h
  43925. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.h 1970-01-01 01:00:00.000000000 +0100
  43926. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.h 2015-02-09 04:40:08.000000000 +0100
  43927. @@ -0,0 +1,52 @@
  43928. +/**
  43929. + * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
  43930. + *
  43931. + * Redistribution and use in source and binary forms, with or without
  43932. + * modification, are permitted provided that the following conditions
  43933. + * are met:
  43934. + * 1. Redistributions of source code must retain the above copyright
  43935. + * notice, this list of conditions, and the following disclaimer,
  43936. + * without modification.
  43937. + * 2. Redistributions in binary form must reproduce the above copyright
  43938. + * notice, this list of conditions and the following disclaimer in the
  43939. + * documentation and/or other materials provided with the distribution.
  43940. + * 3. The names of the above-listed copyright holders may not be used
  43941. + * to endorse or promote products derived from this software without
  43942. + * specific prior written permission.
  43943. + *
  43944. + * ALTERNATIVELY, this software may be distributed under the terms of the
  43945. + * GNU General Public License ("GPL") version 2, as published by the Free
  43946. + * Software Foundation.
  43947. + *
  43948. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  43949. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  43950. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  43951. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  43952. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43953. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43954. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43955. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  43956. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  43957. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  43958. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43959. + */
  43960. +
  43961. +#ifndef VCHIQ_DEBUGFS_H
  43962. +#define VCHIQ_DEBUGFS_H
  43963. +
  43964. +#include "vchiq_core.h"
  43965. +
  43966. +typedef struct vchiq_debugfs_node_struct
  43967. +{
  43968. + struct dentry *dentry;
  43969. +} VCHIQ_DEBUGFS_NODE_T;
  43970. +
  43971. +int vchiq_debugfs_init(void);
  43972. +
  43973. +void vchiq_debugfs_deinit(void);
  43974. +
  43975. +int vchiq_debugfs_add_instance(VCHIQ_INSTANCE_T instance);
  43976. +
  43977. +void vchiq_debugfs_remove_instance(VCHIQ_INSTANCE_T instance);
  43978. +
  43979. +#endif /* VCHIQ_DEBUGFS_H */
  43980. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion
  43981. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 1970-01-01 01:00:00.000000000 +0100
  43982. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 2015-02-09 04:40:08.000000000 +0100
  43983. @@ -0,0 +1,87 @@
  43984. +#!/usr/bin/perl -w
  43985. +
  43986. +use strict;
  43987. +
  43988. +#
  43989. +# Generate a version from available information
  43990. +#
  43991. +
  43992. +my $prefix = shift @ARGV;
  43993. +my $root = shift @ARGV;
  43994. +
  43995. +
  43996. +if ( not defined $root ) {
  43997. + die "usage: $0 prefix root-dir\n";
  43998. +}
  43999. +
  44000. +if ( ! -d $root ) {
  44001. + die "root directory $root not found\n";
  44002. +}
  44003. +
  44004. +my $version = "unknown";
  44005. +my $tainted = "";
  44006. +
  44007. +if ( -d "$root/.git" ) {
  44008. + # attempt to work out git version. only do so
  44009. + # on a linux build host, as cygwin builds are
  44010. + # already slow enough
  44011. +
  44012. + if ( -f "/usr/bin/git" || -f "/usr/local/bin/git" ) {
  44013. + if (not open(F, "git --git-dir $root/.git rev-parse --verify HEAD|")) {
  44014. + $version = "no git version";
  44015. + }
  44016. + else {
  44017. + $version = <F>;
  44018. + $version =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  44019. + $version =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  44020. + }
  44021. +
  44022. + if (open(G, "git --git-dir $root/.git status --porcelain|")) {
  44023. + $tainted = <G>;
  44024. + $tainted =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  44025. + $tainted =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  44026. + if (length $tainted) {
  44027. + $version = join ' ', $version, "(tainted)";
  44028. + }
  44029. + else {
  44030. + $version = join ' ', $version, "(clean)";
  44031. + }
  44032. + }
  44033. + }
  44034. +}
  44035. +
  44036. +my $hostname = `hostname`;
  44037. +$hostname =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  44038. +$hostname =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  44039. +
  44040. +
  44041. +print STDERR "Version $version\n";
  44042. +print <<EOF;
  44043. +#include "${prefix}_build_info.h"
  44044. +#include <linux/broadcom/vc_debug_sym.h>
  44045. +
  44046. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_hostname, "$hostname" );
  44047. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_version, "$version" );
  44048. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_time, __TIME__ );
  44049. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_date, __DATE__ );
  44050. +
  44051. +const char *vchiq_get_build_hostname( void )
  44052. +{
  44053. + return vchiq_build_hostname;
  44054. +}
  44055. +
  44056. +const char *vchiq_get_build_version( void )
  44057. +{
  44058. + return vchiq_build_version;
  44059. +}
  44060. +
  44061. +const char *vchiq_get_build_date( void )
  44062. +{
  44063. + return vchiq_build_date;
  44064. +}
  44065. +
  44066. +const char *vchiq_get_build_time( void )
  44067. +{
  44068. + return vchiq_build_time;
  44069. +}
  44070. +EOF
  44071. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h
  44072. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 1970-01-01 01:00:00.000000000 +0100
  44073. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 2015-02-09 04:40:07.000000000 +0100
  44074. @@ -0,0 +1,40 @@
  44075. +/**
  44076. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  44077. + *
  44078. + * Redistribution and use in source and binary forms, with or without
  44079. + * modification, are permitted provided that the following conditions
  44080. + * are met:
  44081. + * 1. Redistributions of source code must retain the above copyright
  44082. + * notice, this list of conditions, and the following disclaimer,
  44083. + * without modification.
  44084. + * 2. Redistributions in binary form must reproduce the above copyright
  44085. + * notice, this list of conditions and the following disclaimer in the
  44086. + * documentation and/or other materials provided with the distribution.
  44087. + * 3. The names of the above-listed copyright holders may not be used
  44088. + * to endorse or promote products derived from this software without
  44089. + * specific prior written permission.
  44090. + *
  44091. + * ALTERNATIVELY, this software may be distributed under the terms of the
  44092. + * GNU General Public License ("GPL") version 2, as published by the Free
  44093. + * Software Foundation.
  44094. + *
  44095. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  44096. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  44097. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  44098. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  44099. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44100. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44101. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44102. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  44103. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44104. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44105. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44106. + */
  44107. +
  44108. +#ifndef VCHIQ_VCHIQ_H
  44109. +#define VCHIQ_VCHIQ_H
  44110. +
  44111. +#include "vchiq_if.h"
  44112. +#include "vchiq_util.h"
  44113. +
  44114. +#endif
  44115. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h
  44116. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 1970-01-01 01:00:00.000000000 +0100
  44117. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 2015-02-09 04:40:08.000000000 +0100
  44118. @@ -0,0 +1,189 @@
  44119. +/**
  44120. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  44121. + *
  44122. + * Redistribution and use in source and binary forms, with or without
  44123. + * modification, are permitted provided that the following conditions
  44124. + * are met:
  44125. + * 1. Redistributions of source code must retain the above copyright
  44126. + * notice, this list of conditions, and the following disclaimer,
  44127. + * without modification.
  44128. + * 2. Redistributions in binary form must reproduce the above copyright
  44129. + * notice, this list of conditions and the following disclaimer in the
  44130. + * documentation and/or other materials provided with the distribution.
  44131. + * 3. The names of the above-listed copyright holders may not be used
  44132. + * to endorse or promote products derived from this software without
  44133. + * specific prior written permission.
  44134. + *
  44135. + * ALTERNATIVELY, this software may be distributed under the terms of the
  44136. + * GNU General Public License ("GPL") version 2, as published by the Free
  44137. + * Software Foundation.
  44138. + *
  44139. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  44140. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  44141. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  44142. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  44143. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44144. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44145. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44146. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  44147. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44148. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44149. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44150. + */
  44151. +
  44152. +#ifndef VCHIQ_IF_H
  44153. +#define VCHIQ_IF_H
  44154. +
  44155. +#include "interface/vchi/vchi_mh.h"
  44156. +
  44157. +#define VCHIQ_SERVICE_HANDLE_INVALID 0
  44158. +
  44159. +#define VCHIQ_SLOT_SIZE 4096
  44160. +#define VCHIQ_MAX_MSG_SIZE (VCHIQ_SLOT_SIZE - sizeof(VCHIQ_HEADER_T))
  44161. +#define VCHIQ_CHANNEL_SIZE VCHIQ_MAX_MSG_SIZE /* For backwards compatibility */
  44162. +
  44163. +#define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \
  44164. + (((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3))
  44165. +#define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service)
  44166. +#define VCHIQ_GET_SERVICE_FOURCC(service) vchiq_get_service_fourcc(service)
  44167. +
  44168. +typedef enum {
  44169. + VCHIQ_SERVICE_OPENED, /* service, -, - */
  44170. + VCHIQ_SERVICE_CLOSED, /* service, -, - */
  44171. + VCHIQ_MESSAGE_AVAILABLE, /* service, header, - */
  44172. + VCHIQ_BULK_TRANSMIT_DONE, /* service, -, bulk_userdata */
  44173. + VCHIQ_BULK_RECEIVE_DONE, /* service, -, bulk_userdata */
  44174. + VCHIQ_BULK_TRANSMIT_ABORTED, /* service, -, bulk_userdata */
  44175. + VCHIQ_BULK_RECEIVE_ABORTED /* service, -, bulk_userdata */
  44176. +} VCHIQ_REASON_T;
  44177. +
  44178. +typedef enum {
  44179. + VCHIQ_ERROR = -1,
  44180. + VCHIQ_SUCCESS = 0,
  44181. + VCHIQ_RETRY = 1
  44182. +} VCHIQ_STATUS_T;
  44183. +
  44184. +typedef enum {
  44185. + VCHIQ_BULK_MODE_CALLBACK,
  44186. + VCHIQ_BULK_MODE_BLOCKING,
  44187. + VCHIQ_BULK_MODE_NOCALLBACK,
  44188. + VCHIQ_BULK_MODE_WAITING /* Reserved for internal use */
  44189. +} VCHIQ_BULK_MODE_T;
  44190. +
  44191. +typedef enum {
  44192. + VCHIQ_SERVICE_OPTION_AUTOCLOSE,
  44193. + VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
  44194. + VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
  44195. + VCHIQ_SERVICE_OPTION_SYNCHRONOUS,
  44196. + VCHIQ_SERVICE_OPTION_TRACE
  44197. +} VCHIQ_SERVICE_OPTION_T;
  44198. +
  44199. +typedef struct vchiq_header_struct {
  44200. + /* The message identifier - opaque to applications. */
  44201. + int msgid;
  44202. +
  44203. + /* Size of message data. */
  44204. + unsigned int size;
  44205. +
  44206. + char data[0]; /* message */
  44207. +} VCHIQ_HEADER_T;
  44208. +
  44209. +typedef struct {
  44210. + const void *data;
  44211. + unsigned int size;
  44212. +} VCHIQ_ELEMENT_T;
  44213. +
  44214. +typedef unsigned int VCHIQ_SERVICE_HANDLE_T;
  44215. +
  44216. +typedef VCHIQ_STATUS_T (*VCHIQ_CALLBACK_T)(VCHIQ_REASON_T, VCHIQ_HEADER_T *,
  44217. + VCHIQ_SERVICE_HANDLE_T, void *);
  44218. +
  44219. +typedef struct vchiq_service_base_struct {
  44220. + int fourcc;
  44221. + VCHIQ_CALLBACK_T callback;
  44222. + void *userdata;
  44223. +} VCHIQ_SERVICE_BASE_T;
  44224. +
  44225. +typedef struct vchiq_service_params_struct {
  44226. + int fourcc;
  44227. + VCHIQ_CALLBACK_T callback;
  44228. + void *userdata;
  44229. + short version; /* Increment for non-trivial changes */
  44230. + short version_min; /* Update for incompatible changes */
  44231. +} VCHIQ_SERVICE_PARAMS_T;
  44232. +
  44233. +typedef struct vchiq_config_struct {
  44234. + unsigned int max_msg_size;
  44235. + unsigned int bulk_threshold; /* The message size above which it
  44236. + is better to use a bulk transfer
  44237. + (<= max_msg_size) */
  44238. + unsigned int max_outstanding_bulks;
  44239. + unsigned int max_services;
  44240. + short version; /* The version of VCHIQ */
  44241. + short version_min; /* The minimum compatible version of VCHIQ */
  44242. +} VCHIQ_CONFIG_T;
  44243. +
  44244. +typedef struct vchiq_instance_struct *VCHIQ_INSTANCE_T;
  44245. +typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void *cb_arg);
  44246. +
  44247. +extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance);
  44248. +extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance);
  44249. +extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance);
  44250. +extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance,
  44251. + const VCHIQ_SERVICE_PARAMS_T *params,
  44252. + VCHIQ_SERVICE_HANDLE_T *pservice);
  44253. +extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance,
  44254. + const VCHIQ_SERVICE_PARAMS_T *params,
  44255. + VCHIQ_SERVICE_HANDLE_T *pservice);
  44256. +extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service);
  44257. +extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service);
  44258. +extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service);
  44259. +extern VCHIQ_STATUS_T vchiq_use_service_no_resume(
  44260. + VCHIQ_SERVICE_HANDLE_T service);
  44261. +extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service);
  44262. +
  44263. +extern VCHIQ_STATUS_T vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T service,
  44264. + const VCHIQ_ELEMENT_T *elements, unsigned int count);
  44265. +extern void vchiq_release_message(VCHIQ_SERVICE_HANDLE_T service,
  44266. + VCHIQ_HEADER_T *header);
  44267. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  44268. + const void *data, unsigned int size, void *userdata);
  44269. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  44270. + void *data, unsigned int size, void *userdata);
  44271. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit_handle(
  44272. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  44273. + const void *offset, unsigned int size, void *userdata);
  44274. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive_handle(
  44275. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  44276. + void *offset, unsigned int size, void *userdata);
  44277. +extern VCHIQ_STATUS_T vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  44278. + const void *data, unsigned int size, void *userdata,
  44279. + VCHIQ_BULK_MODE_T mode);
  44280. +extern VCHIQ_STATUS_T vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  44281. + void *data, unsigned int size, void *userdata,
  44282. + VCHIQ_BULK_MODE_T mode);
  44283. +extern VCHIQ_STATUS_T vchiq_bulk_transmit_handle(VCHIQ_SERVICE_HANDLE_T service,
  44284. + VCHI_MEM_HANDLE_T handle, const void *offset, unsigned int size,
  44285. + void *userdata, VCHIQ_BULK_MODE_T mode);
  44286. +extern VCHIQ_STATUS_T vchiq_bulk_receive_handle(VCHIQ_SERVICE_HANDLE_T service,
  44287. + VCHI_MEM_HANDLE_T handle, void *offset, unsigned int size,
  44288. + void *userdata, VCHIQ_BULK_MODE_T mode);
  44289. +extern int vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T service);
  44290. +extern void *vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T service);
  44291. +extern int vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T service);
  44292. +extern VCHIQ_STATUS_T vchiq_get_config(VCHIQ_INSTANCE_T instance,
  44293. + int config_size, VCHIQ_CONFIG_T *pconfig);
  44294. +extern VCHIQ_STATUS_T vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T service,
  44295. + VCHIQ_SERVICE_OPTION_T option, int value);
  44296. +
  44297. +extern VCHIQ_STATUS_T vchiq_remote_use(VCHIQ_INSTANCE_T instance,
  44298. + VCHIQ_REMOTE_USE_CALLBACK_T callback, void *cb_arg);
  44299. +extern VCHIQ_STATUS_T vchiq_remote_release(VCHIQ_INSTANCE_T instance);
  44300. +
  44301. +extern VCHIQ_STATUS_T vchiq_dump_phys_mem(VCHIQ_SERVICE_HANDLE_T service,
  44302. + void *ptr, size_t num_bytes);
  44303. +
  44304. +extern VCHIQ_STATUS_T vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle,
  44305. + short *peer_version);
  44306. +
  44307. +#endif /* VCHIQ_IF_H */
  44308. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
  44309. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  44310. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 2015-02-09 04:40:08.000000000 +0100
  44311. @@ -0,0 +1,131 @@
  44312. +/**
  44313. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  44314. + *
  44315. + * Redistribution and use in source and binary forms, with or without
  44316. + * modification, are permitted provided that the following conditions
  44317. + * are met:
  44318. + * 1. Redistributions of source code must retain the above copyright
  44319. + * notice, this list of conditions, and the following disclaimer,
  44320. + * without modification.
  44321. + * 2. Redistributions in binary form must reproduce the above copyright
  44322. + * notice, this list of conditions and the following disclaimer in the
  44323. + * documentation and/or other materials provided with the distribution.
  44324. + * 3. The names of the above-listed copyright holders may not be used
  44325. + * to endorse or promote products derived from this software without
  44326. + * specific prior written permission.
  44327. + *
  44328. + * ALTERNATIVELY, this software may be distributed under the terms of the
  44329. + * GNU General Public License ("GPL") version 2, as published by the Free
  44330. + * Software Foundation.
  44331. + *
  44332. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  44333. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  44334. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  44335. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  44336. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44337. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44338. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44339. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  44340. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44341. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44342. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44343. + */
  44344. +
  44345. +#ifndef VCHIQ_IOCTLS_H
  44346. +#define VCHIQ_IOCTLS_H
  44347. +
  44348. +#include <linux/ioctl.h>
  44349. +#include "vchiq_if.h"
  44350. +
  44351. +#define VCHIQ_IOC_MAGIC 0xc4
  44352. +#define VCHIQ_INVALID_HANDLE (~0)
  44353. +
  44354. +typedef struct {
  44355. + VCHIQ_SERVICE_PARAMS_T params;
  44356. + int is_open;
  44357. + int is_vchi;
  44358. + unsigned int handle; /* OUT */
  44359. +} VCHIQ_CREATE_SERVICE_T;
  44360. +
  44361. +typedef struct {
  44362. + unsigned int handle;
  44363. + unsigned int count;
  44364. + const VCHIQ_ELEMENT_T *elements;
  44365. +} VCHIQ_QUEUE_MESSAGE_T;
  44366. +
  44367. +typedef struct {
  44368. + unsigned int handle;
  44369. + void *data;
  44370. + unsigned int size;
  44371. + void *userdata;
  44372. + VCHIQ_BULK_MODE_T mode;
  44373. +} VCHIQ_QUEUE_BULK_TRANSFER_T;
  44374. +
  44375. +typedef struct {
  44376. + VCHIQ_REASON_T reason;
  44377. + VCHIQ_HEADER_T *header;
  44378. + void *service_userdata;
  44379. + void *bulk_userdata;
  44380. +} VCHIQ_COMPLETION_DATA_T;
  44381. +
  44382. +typedef struct {
  44383. + unsigned int count;
  44384. + VCHIQ_COMPLETION_DATA_T *buf;
  44385. + unsigned int msgbufsize;
  44386. + unsigned int msgbufcount; /* IN/OUT */
  44387. + void **msgbufs;
  44388. +} VCHIQ_AWAIT_COMPLETION_T;
  44389. +
  44390. +typedef struct {
  44391. + unsigned int handle;
  44392. + int blocking;
  44393. + unsigned int bufsize;
  44394. + void *buf;
  44395. +} VCHIQ_DEQUEUE_MESSAGE_T;
  44396. +
  44397. +typedef struct {
  44398. + unsigned int config_size;
  44399. + VCHIQ_CONFIG_T *pconfig;
  44400. +} VCHIQ_GET_CONFIG_T;
  44401. +
  44402. +typedef struct {
  44403. + unsigned int handle;
  44404. + VCHIQ_SERVICE_OPTION_T option;
  44405. + int value;
  44406. +} VCHIQ_SET_SERVICE_OPTION_T;
  44407. +
  44408. +typedef struct {
  44409. + void *virt_addr;
  44410. + size_t num_bytes;
  44411. +} VCHIQ_DUMP_MEM_T;
  44412. +
  44413. +#define VCHIQ_IOC_CONNECT _IO(VCHIQ_IOC_MAGIC, 0)
  44414. +#define VCHIQ_IOC_SHUTDOWN _IO(VCHIQ_IOC_MAGIC, 1)
  44415. +#define VCHIQ_IOC_CREATE_SERVICE \
  44416. + _IOWR(VCHIQ_IOC_MAGIC, 2, VCHIQ_CREATE_SERVICE_T)
  44417. +#define VCHIQ_IOC_REMOVE_SERVICE _IO(VCHIQ_IOC_MAGIC, 3)
  44418. +#define VCHIQ_IOC_QUEUE_MESSAGE \
  44419. + _IOW(VCHIQ_IOC_MAGIC, 4, VCHIQ_QUEUE_MESSAGE_T)
  44420. +#define VCHIQ_IOC_QUEUE_BULK_TRANSMIT \
  44421. + _IOWR(VCHIQ_IOC_MAGIC, 5, VCHIQ_QUEUE_BULK_TRANSFER_T)
  44422. +#define VCHIQ_IOC_QUEUE_BULK_RECEIVE \
  44423. + _IOWR(VCHIQ_IOC_MAGIC, 6, VCHIQ_QUEUE_BULK_TRANSFER_T)
  44424. +#define VCHIQ_IOC_AWAIT_COMPLETION \
  44425. + _IOWR(VCHIQ_IOC_MAGIC, 7, VCHIQ_AWAIT_COMPLETION_T)
  44426. +#define VCHIQ_IOC_DEQUEUE_MESSAGE \
  44427. + _IOWR(VCHIQ_IOC_MAGIC, 8, VCHIQ_DEQUEUE_MESSAGE_T)
  44428. +#define VCHIQ_IOC_GET_CLIENT_ID _IO(VCHIQ_IOC_MAGIC, 9)
  44429. +#define VCHIQ_IOC_GET_CONFIG \
  44430. + _IOWR(VCHIQ_IOC_MAGIC, 10, VCHIQ_GET_CONFIG_T)
  44431. +#define VCHIQ_IOC_CLOSE_SERVICE _IO(VCHIQ_IOC_MAGIC, 11)
  44432. +#define VCHIQ_IOC_USE_SERVICE _IO(VCHIQ_IOC_MAGIC, 12)
  44433. +#define VCHIQ_IOC_RELEASE_SERVICE _IO(VCHIQ_IOC_MAGIC, 13)
  44434. +#define VCHIQ_IOC_SET_SERVICE_OPTION \
  44435. + _IOW(VCHIQ_IOC_MAGIC, 14, VCHIQ_SET_SERVICE_OPTION_T)
  44436. +#define VCHIQ_IOC_DUMP_PHYS_MEM \
  44437. + _IOW(VCHIQ_IOC_MAGIC, 15, VCHIQ_DUMP_MEM_T)
  44438. +#define VCHIQ_IOC_LIB_VERSION _IO(VCHIQ_IOC_MAGIC, 16)
  44439. +#define VCHIQ_IOC_CLOSE_DELIVERED _IO(VCHIQ_IOC_MAGIC, 17)
  44440. +#define VCHIQ_IOC_MAX 17
  44441. +
  44442. +#endif
  44443. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
  44444. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 1970-01-01 01:00:00.000000000 +0100
  44445. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 2015-02-09 04:40:08.000000000 +0100
  44446. @@ -0,0 +1,458 @@
  44447. +/**
  44448. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  44449. + *
  44450. + * Redistribution and use in source and binary forms, with or without
  44451. + * modification, are permitted provided that the following conditions
  44452. + * are met:
  44453. + * 1. Redistributions of source code must retain the above copyright
  44454. + * notice, this list of conditions, and the following disclaimer,
  44455. + * without modification.
  44456. + * 2. Redistributions in binary form must reproduce the above copyright
  44457. + * notice, this list of conditions and the following disclaimer in the
  44458. + * documentation and/or other materials provided with the distribution.
  44459. + * 3. The names of the above-listed copyright holders may not be used
  44460. + * to endorse or promote products derived from this software without
  44461. + * specific prior written permission.
  44462. + *
  44463. + * ALTERNATIVELY, this software may be distributed under the terms of the
  44464. + * GNU General Public License ("GPL") version 2, as published by the Free
  44465. + * Software Foundation.
  44466. + *
  44467. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  44468. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  44469. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  44470. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  44471. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44472. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44473. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44474. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  44475. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44476. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44477. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44478. + */
  44479. +
  44480. +/* ---- Include Files ---------------------------------------------------- */
  44481. +
  44482. +#include <linux/kernel.h>
  44483. +#include <linux/module.h>
  44484. +#include <linux/mutex.h>
  44485. +
  44486. +#include "vchiq_core.h"
  44487. +#include "vchiq_arm.h"
  44488. +#include "vchiq_killable.h"
  44489. +
  44490. +/* ---- Public Variables ------------------------------------------------- */
  44491. +
  44492. +/* ---- Private Constants and Types -------------------------------------- */
  44493. +
  44494. +struct bulk_waiter_node {
  44495. + struct bulk_waiter bulk_waiter;
  44496. + int pid;
  44497. + struct list_head list;
  44498. +};
  44499. +
  44500. +struct vchiq_instance_struct {
  44501. + VCHIQ_STATE_T *state;
  44502. +
  44503. + int connected;
  44504. +
  44505. + struct list_head bulk_waiter_list;
  44506. + struct mutex bulk_waiter_list_mutex;
  44507. +};
  44508. +
  44509. +static VCHIQ_STATUS_T
  44510. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  44511. + unsigned int size, VCHIQ_BULK_DIR_T dir);
  44512. +
  44513. +/****************************************************************************
  44514. +*
  44515. +* vchiq_initialise
  44516. +*
  44517. +***************************************************************************/
  44518. +#define VCHIQ_INIT_RETRIES 10
  44519. +VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instanceOut)
  44520. +{
  44521. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  44522. + VCHIQ_STATE_T *state;
  44523. + VCHIQ_INSTANCE_T instance = NULL;
  44524. + int i;
  44525. +
  44526. + vchiq_log_trace(vchiq_core_log_level, "%s called", __func__);
  44527. +
  44528. + /* VideoCore may not be ready due to boot up timing.
  44529. + It may never be ready if kernel and firmware are mismatched, so don't block forever. */
  44530. + for (i=0; i<VCHIQ_INIT_RETRIES; i++) {
  44531. + state = vchiq_get_state();
  44532. + if (state)
  44533. + break;
  44534. + udelay(500);
  44535. + }
  44536. + if (i==VCHIQ_INIT_RETRIES) {
  44537. + vchiq_log_error(vchiq_core_log_level,
  44538. + "%s: videocore not initialized\n", __func__);
  44539. + goto failed;
  44540. + } else if (i>0) {
  44541. + vchiq_log_warning(vchiq_core_log_level,
  44542. + "%s: videocore initialized after %d retries\n", __func__, i);
  44543. + }
  44544. +
  44545. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  44546. + if (!instance) {
  44547. + vchiq_log_error(vchiq_core_log_level,
  44548. + "%s: error allocating vchiq instance\n", __func__);
  44549. + goto failed;
  44550. + }
  44551. +
  44552. + instance->connected = 0;
  44553. + instance->state = state;
  44554. + mutex_init(&instance->bulk_waiter_list_mutex);
  44555. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  44556. +
  44557. + *instanceOut = instance;
  44558. +
  44559. + status = VCHIQ_SUCCESS;
  44560. +
  44561. +failed:
  44562. + vchiq_log_trace(vchiq_core_log_level,
  44563. + "%s(%p): returning %d", __func__, instance, status);
  44564. +
  44565. + return status;
  44566. +}
  44567. +EXPORT_SYMBOL(vchiq_initialise);
  44568. +
  44569. +/****************************************************************************
  44570. +*
  44571. +* vchiq_shutdown
  44572. +*
  44573. +***************************************************************************/
  44574. +
  44575. +VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
  44576. +{
  44577. + VCHIQ_STATUS_T status;
  44578. + VCHIQ_STATE_T *state = instance->state;
  44579. +
  44580. + vchiq_log_trace(vchiq_core_log_level,
  44581. + "%s(%p) called", __func__, instance);
  44582. +
  44583. + if (mutex_lock_interruptible(&state->mutex) != 0)
  44584. + return VCHIQ_RETRY;
  44585. +
  44586. + /* Remove all services */
  44587. + status = vchiq_shutdown_internal(state, instance);
  44588. +
  44589. + mutex_unlock(&state->mutex);
  44590. +
  44591. + vchiq_log_trace(vchiq_core_log_level,
  44592. + "%s(%p): returning %d", __func__, instance, status);
  44593. +
  44594. + if (status == VCHIQ_SUCCESS) {
  44595. + struct list_head *pos, *next;
  44596. + list_for_each_safe(pos, next,
  44597. + &instance->bulk_waiter_list) {
  44598. + struct bulk_waiter_node *waiter;
  44599. + waiter = list_entry(pos,
  44600. + struct bulk_waiter_node,
  44601. + list);
  44602. + list_del(pos);
  44603. + vchiq_log_info(vchiq_arm_log_level,
  44604. + "bulk_waiter - cleaned up %x "
  44605. + "for pid %d",
  44606. + (unsigned int)waiter, waiter->pid);
  44607. + kfree(waiter);
  44608. + }
  44609. + kfree(instance);
  44610. + }
  44611. +
  44612. + return status;
  44613. +}
  44614. +EXPORT_SYMBOL(vchiq_shutdown);
  44615. +
  44616. +/****************************************************************************
  44617. +*
  44618. +* vchiq_is_connected
  44619. +*
  44620. +***************************************************************************/
  44621. +
  44622. +int vchiq_is_connected(VCHIQ_INSTANCE_T instance)
  44623. +{
  44624. + return instance->connected;
  44625. +}
  44626. +
  44627. +/****************************************************************************
  44628. +*
  44629. +* vchiq_connect
  44630. +*
  44631. +***************************************************************************/
  44632. +
  44633. +VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance)
  44634. +{
  44635. + VCHIQ_STATUS_T status;
  44636. + VCHIQ_STATE_T *state = instance->state;
  44637. +
  44638. + vchiq_log_trace(vchiq_core_log_level,
  44639. + "%s(%p) called", __func__, instance);
  44640. +
  44641. + if (mutex_lock_interruptible(&state->mutex) != 0) {
  44642. + vchiq_log_trace(vchiq_core_log_level,
  44643. + "%s: call to mutex_lock failed", __func__);
  44644. + status = VCHIQ_RETRY;
  44645. + goto failed;
  44646. + }
  44647. + status = vchiq_connect_internal(state, instance);
  44648. +
  44649. + if (status == VCHIQ_SUCCESS)
  44650. + instance->connected = 1;
  44651. +
  44652. + mutex_unlock(&state->mutex);
  44653. +
  44654. +failed:
  44655. + vchiq_log_trace(vchiq_core_log_level,
  44656. + "%s(%p): returning %d", __func__, instance, status);
  44657. +
  44658. + return status;
  44659. +}
  44660. +EXPORT_SYMBOL(vchiq_connect);
  44661. +
  44662. +/****************************************************************************
  44663. +*
  44664. +* vchiq_add_service
  44665. +*
  44666. +***************************************************************************/
  44667. +
  44668. +VCHIQ_STATUS_T vchiq_add_service(
  44669. + VCHIQ_INSTANCE_T instance,
  44670. + const VCHIQ_SERVICE_PARAMS_T *params,
  44671. + VCHIQ_SERVICE_HANDLE_T *phandle)
  44672. +{
  44673. + VCHIQ_STATUS_T status;
  44674. + VCHIQ_STATE_T *state = instance->state;
  44675. + VCHIQ_SERVICE_T *service = NULL;
  44676. + int srvstate;
  44677. +
  44678. + vchiq_log_trace(vchiq_core_log_level,
  44679. + "%s(%p) called", __func__, instance);
  44680. +
  44681. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  44682. +
  44683. + srvstate = vchiq_is_connected(instance)
  44684. + ? VCHIQ_SRVSTATE_LISTENING
  44685. + : VCHIQ_SRVSTATE_HIDDEN;
  44686. +
  44687. + service = vchiq_add_service_internal(
  44688. + state,
  44689. + params,
  44690. + srvstate,
  44691. + instance,
  44692. + NULL);
  44693. +
  44694. + if (service) {
  44695. + *phandle = service->handle;
  44696. + status = VCHIQ_SUCCESS;
  44697. + } else
  44698. + status = VCHIQ_ERROR;
  44699. +
  44700. + vchiq_log_trace(vchiq_core_log_level,
  44701. + "%s(%p): returning %d", __func__, instance, status);
  44702. +
  44703. + return status;
  44704. +}
  44705. +EXPORT_SYMBOL(vchiq_add_service);
  44706. +
  44707. +/****************************************************************************
  44708. +*
  44709. +* vchiq_open_service
  44710. +*
  44711. +***************************************************************************/
  44712. +
  44713. +VCHIQ_STATUS_T vchiq_open_service(
  44714. + VCHIQ_INSTANCE_T instance,
  44715. + const VCHIQ_SERVICE_PARAMS_T *params,
  44716. + VCHIQ_SERVICE_HANDLE_T *phandle)
  44717. +{
  44718. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  44719. + VCHIQ_STATE_T *state = instance->state;
  44720. + VCHIQ_SERVICE_T *service = NULL;
  44721. +
  44722. + vchiq_log_trace(vchiq_core_log_level,
  44723. + "%s(%p) called", __func__, instance);
  44724. +
  44725. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  44726. +
  44727. + if (!vchiq_is_connected(instance))
  44728. + goto failed;
  44729. +
  44730. + service = vchiq_add_service_internal(state,
  44731. + params,
  44732. + VCHIQ_SRVSTATE_OPENING,
  44733. + instance,
  44734. + NULL);
  44735. +
  44736. + if (service) {
  44737. + *phandle = service->handle;
  44738. + status = vchiq_open_service_internal(service, current->pid);
  44739. + if (status != VCHIQ_SUCCESS) {
  44740. + vchiq_remove_service(service->handle);
  44741. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  44742. + }
  44743. + }
  44744. +
  44745. +failed:
  44746. + vchiq_log_trace(vchiq_core_log_level,
  44747. + "%s(%p): returning %d", __func__, instance, status);
  44748. +
  44749. + return status;
  44750. +}
  44751. +EXPORT_SYMBOL(vchiq_open_service);
  44752. +
  44753. +VCHIQ_STATUS_T
  44754. +vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle,
  44755. + const void *data, unsigned int size, void *userdata)
  44756. +{
  44757. + return vchiq_bulk_transfer(handle,
  44758. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  44759. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_TRANSMIT);
  44760. +}
  44761. +EXPORT_SYMBOL(vchiq_queue_bulk_transmit);
  44762. +
  44763. +VCHIQ_STATUS_T
  44764. +vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  44765. + unsigned int size, void *userdata)
  44766. +{
  44767. + return vchiq_bulk_transfer(handle,
  44768. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  44769. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_RECEIVE);
  44770. +}
  44771. +EXPORT_SYMBOL(vchiq_queue_bulk_receive);
  44772. +
  44773. +VCHIQ_STATUS_T
  44774. +vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle, const void *data,
  44775. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  44776. +{
  44777. + VCHIQ_STATUS_T status;
  44778. +
  44779. + switch (mode) {
  44780. + case VCHIQ_BULK_MODE_NOCALLBACK:
  44781. + case VCHIQ_BULK_MODE_CALLBACK:
  44782. + status = vchiq_bulk_transfer(handle,
  44783. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  44784. + mode, VCHIQ_BULK_TRANSMIT);
  44785. + break;
  44786. + case VCHIQ_BULK_MODE_BLOCKING:
  44787. + status = vchiq_blocking_bulk_transfer(handle,
  44788. + (void *)data, size, VCHIQ_BULK_TRANSMIT);
  44789. + break;
  44790. + default:
  44791. + return VCHIQ_ERROR;
  44792. + }
  44793. +
  44794. + return status;
  44795. +}
  44796. +EXPORT_SYMBOL(vchiq_bulk_transmit);
  44797. +
  44798. +VCHIQ_STATUS_T
  44799. +vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  44800. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  44801. +{
  44802. + VCHIQ_STATUS_T status;
  44803. +
  44804. + switch (mode) {
  44805. + case VCHIQ_BULK_MODE_NOCALLBACK:
  44806. + case VCHIQ_BULK_MODE_CALLBACK:
  44807. + status = vchiq_bulk_transfer(handle,
  44808. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  44809. + mode, VCHIQ_BULK_RECEIVE);
  44810. + break;
  44811. + case VCHIQ_BULK_MODE_BLOCKING:
  44812. + status = vchiq_blocking_bulk_transfer(handle,
  44813. + (void *)data, size, VCHIQ_BULK_RECEIVE);
  44814. + break;
  44815. + default:
  44816. + return VCHIQ_ERROR;
  44817. + }
  44818. +
  44819. + return status;
  44820. +}
  44821. +EXPORT_SYMBOL(vchiq_bulk_receive);
  44822. +
  44823. +static VCHIQ_STATUS_T
  44824. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  44825. + unsigned int size, VCHIQ_BULK_DIR_T dir)
  44826. +{
  44827. + VCHIQ_INSTANCE_T instance;
  44828. + VCHIQ_SERVICE_T *service;
  44829. + VCHIQ_STATUS_T status;
  44830. + struct bulk_waiter_node *waiter = NULL;
  44831. + struct list_head *pos;
  44832. +
  44833. + service = find_service_by_handle(handle);
  44834. + if (!service)
  44835. + return VCHIQ_ERROR;
  44836. +
  44837. + instance = service->instance;
  44838. +
  44839. + unlock_service(service);
  44840. +
  44841. + mutex_lock(&instance->bulk_waiter_list_mutex);
  44842. + list_for_each(pos, &instance->bulk_waiter_list) {
  44843. + if (list_entry(pos, struct bulk_waiter_node,
  44844. + list)->pid == current->pid) {
  44845. + waiter = list_entry(pos,
  44846. + struct bulk_waiter_node,
  44847. + list);
  44848. + list_del(pos);
  44849. + break;
  44850. + }
  44851. + }
  44852. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  44853. +
  44854. + if (waiter) {
  44855. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  44856. + if (bulk) {
  44857. + /* This thread has an outstanding bulk transfer. */
  44858. + if ((bulk->data != data) ||
  44859. + (bulk->size != size)) {
  44860. + /* This is not a retry of the previous one.
  44861. + ** Cancel the signal when the transfer
  44862. + ** completes. */
  44863. + spin_lock(&bulk_waiter_spinlock);
  44864. + bulk->userdata = NULL;
  44865. + spin_unlock(&bulk_waiter_spinlock);
  44866. + }
  44867. + }
  44868. + }
  44869. +
  44870. + if (!waiter) {
  44871. + waiter = kzalloc(sizeof(struct bulk_waiter_node), GFP_KERNEL);
  44872. + if (!waiter) {
  44873. + vchiq_log_error(vchiq_core_log_level,
  44874. + "%s - out of memory", __func__);
  44875. + return VCHIQ_ERROR;
  44876. + }
  44877. + }
  44878. +
  44879. + status = vchiq_bulk_transfer(handle, VCHI_MEM_HANDLE_INVALID,
  44880. + data, size, &waiter->bulk_waiter, VCHIQ_BULK_MODE_BLOCKING,
  44881. + dir);
  44882. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  44883. + !waiter->bulk_waiter.bulk) {
  44884. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  44885. + if (bulk) {
  44886. + /* Cancel the signal when the transfer
  44887. + ** completes. */
  44888. + spin_lock(&bulk_waiter_spinlock);
  44889. + bulk->userdata = NULL;
  44890. + spin_unlock(&bulk_waiter_spinlock);
  44891. + }
  44892. + kfree(waiter);
  44893. + } else {
  44894. + waiter->pid = current->pid;
  44895. + mutex_lock(&instance->bulk_waiter_list_mutex);
  44896. + list_add(&waiter->list, &instance->bulk_waiter_list);
  44897. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  44898. + vchiq_log_info(vchiq_arm_log_level,
  44899. + "saved bulk_waiter %x for pid %d",
  44900. + (unsigned int)waiter, current->pid);
  44901. + }
  44902. +
  44903. + return status;
  44904. +}
  44905. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h
  44906. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h 1970-01-01 01:00:00.000000000 +0100
  44907. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h 2015-02-09 04:40:08.000000000 +0100
  44908. @@ -0,0 +1,69 @@
  44909. +/**
  44910. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  44911. + *
  44912. + * Redistribution and use in source and binary forms, with or without
  44913. + * modification, are permitted provided that the following conditions
  44914. + * are met:
  44915. + * 1. Redistributions of source code must retain the above copyright
  44916. + * notice, this list of conditions, and the following disclaimer,
  44917. + * without modification.
  44918. + * 2. Redistributions in binary form must reproduce the above copyright
  44919. + * notice, this list of conditions and the following disclaimer in the
  44920. + * documentation and/or other materials provided with the distribution.
  44921. + * 3. The names of the above-listed copyright holders may not be used
  44922. + * to endorse or promote products derived from this software without
  44923. + * specific prior written permission.
  44924. + *
  44925. + * ALTERNATIVELY, this software may be distributed under the terms of the
  44926. + * GNU General Public License ("GPL") version 2, as published by the Free
  44927. + * Software Foundation.
  44928. + *
  44929. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  44930. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  44931. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  44932. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  44933. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44934. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44935. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44936. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  44937. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44938. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44939. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44940. + */
  44941. +
  44942. +#ifndef VCHIQ_KILLABLE_H
  44943. +#define VCHIQ_KILLABLE_H
  44944. +
  44945. +#include <linux/mutex.h>
  44946. +#include <linux/semaphore.h>
  44947. +
  44948. +#define SHUTDOWN_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | sigmask(SIGQUIT) | sigmask(SIGTRAP) | sigmask(SIGSTOP) | sigmask(SIGCONT))
  44949. +
  44950. +static inline int __must_check down_interruptible_killable(struct semaphore *sem)
  44951. +{
  44952. + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
  44953. + int ret;
  44954. + sigset_t blocked, oldset;
  44955. + siginitsetinv(&blocked, SHUTDOWN_SIGS);
  44956. + sigprocmask(SIG_SETMASK, &blocked, &oldset);
  44957. + ret = down_interruptible(sem);
  44958. + sigprocmask(SIG_SETMASK, &oldset, NULL);
  44959. + return ret;
  44960. +}
  44961. +#define down_interruptible down_interruptible_killable
  44962. +
  44963. +
  44964. +static inline int __must_check mutex_lock_interruptible_killable(struct mutex *lock)
  44965. +{
  44966. + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
  44967. + int ret;
  44968. + sigset_t blocked, oldset;
  44969. + siginitsetinv(&blocked, SHUTDOWN_SIGS);
  44970. + sigprocmask(SIG_SETMASK, &blocked, &oldset);
  44971. + ret = mutex_lock_interruptible(lock);
  44972. + sigprocmask(SIG_SETMASK, &oldset, NULL);
  44973. + return ret;
  44974. +}
  44975. +#define mutex_lock_interruptible mutex_lock_interruptible_killable
  44976. +
  44977. +#endif
  44978. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h
  44979. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 1970-01-01 01:00:00.000000000 +0100
  44980. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 2015-02-09 04:40:08.000000000 +0100
  44981. @@ -0,0 +1,71 @@
  44982. +/**
  44983. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  44984. + *
  44985. + * Redistribution and use in source and binary forms, with or without
  44986. + * modification, are permitted provided that the following conditions
  44987. + * are met:
  44988. + * 1. Redistributions of source code must retain the above copyright
  44989. + * notice, this list of conditions, and the following disclaimer,
  44990. + * without modification.
  44991. + * 2. Redistributions in binary form must reproduce the above copyright
  44992. + * notice, this list of conditions and the following disclaimer in the
  44993. + * documentation and/or other materials provided with the distribution.
  44994. + * 3. The names of the above-listed copyright holders may not be used
  44995. + * to endorse or promote products derived from this software without
  44996. + * specific prior written permission.
  44997. + *
  44998. + * ALTERNATIVELY, this software may be distributed under the terms of the
  44999. + * GNU General Public License ("GPL") version 2, as published by the Free
  45000. + * Software Foundation.
  45001. + *
  45002. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  45003. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  45004. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  45005. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  45006. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  45007. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  45008. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  45009. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  45010. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  45011. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  45012. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45013. + */
  45014. +
  45015. +#ifndef VCHIQ_MEMDRV_H
  45016. +#define VCHIQ_MEMDRV_H
  45017. +
  45018. +/* ---- Include Files ----------------------------------------------------- */
  45019. +
  45020. +#include <linux/kernel.h>
  45021. +#include "vchiq_if.h"
  45022. +
  45023. +/* ---- Constants and Types ---------------------------------------------- */
  45024. +
  45025. +typedef struct {
  45026. + void *armSharedMemVirt;
  45027. + dma_addr_t armSharedMemPhys;
  45028. + size_t armSharedMemSize;
  45029. +
  45030. + void *vcSharedMemVirt;
  45031. + dma_addr_t vcSharedMemPhys;
  45032. + size_t vcSharedMemSize;
  45033. +} VCHIQ_SHARED_MEM_INFO_T;
  45034. +
  45035. +/* ---- Variable Externs ------------------------------------------------- */
  45036. +
  45037. +/* ---- Function Prototypes ---------------------------------------------- */
  45038. +
  45039. +void vchiq_get_shared_mem_info(VCHIQ_SHARED_MEM_INFO_T *info);
  45040. +
  45041. +VCHIQ_STATUS_T vchiq_memdrv_initialise(void);
  45042. +
  45043. +VCHIQ_STATUS_T vchiq_userdrv_create_instance(
  45044. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  45045. +
  45046. +VCHIQ_STATUS_T vchiq_userdrv_suspend(
  45047. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  45048. +
  45049. +VCHIQ_STATUS_T vchiq_userdrv_resume(
  45050. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  45051. +
  45052. +#endif
  45053. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h
  45054. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 1970-01-01 01:00:00.000000000 +0100
  45055. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 2015-02-09 04:40:08.000000000 +0100
  45056. @@ -0,0 +1,58 @@
  45057. +/**
  45058. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  45059. + *
  45060. + * Redistribution and use in source and binary forms, with or without
  45061. + * modification, are permitted provided that the following conditions
  45062. + * are met:
  45063. + * 1. Redistributions of source code must retain the above copyright
  45064. + * notice, this list of conditions, and the following disclaimer,
  45065. + * without modification.
  45066. + * 2. Redistributions in binary form must reproduce the above copyright
  45067. + * notice, this list of conditions and the following disclaimer in the
  45068. + * documentation and/or other materials provided with the distribution.
  45069. + * 3. The names of the above-listed copyright holders may not be used
  45070. + * to endorse or promote products derived from this software without
  45071. + * specific prior written permission.
  45072. + *
  45073. + * ALTERNATIVELY, this software may be distributed under the terms of the
  45074. + * GNU General Public License ("GPL") version 2, as published by the Free
  45075. + * Software Foundation.
  45076. + *
  45077. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  45078. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  45079. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  45080. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  45081. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  45082. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  45083. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  45084. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  45085. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  45086. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  45087. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45088. + */
  45089. +
  45090. +#ifndef VCHIQ_PAGELIST_H
  45091. +#define VCHIQ_PAGELIST_H
  45092. +
  45093. +#ifndef PAGE_SIZE
  45094. +#define PAGE_SIZE 4096
  45095. +#endif
  45096. +#define CACHE_LINE_SIZE 32
  45097. +#define PAGELIST_WRITE 0
  45098. +#define PAGELIST_READ 1
  45099. +#define PAGELIST_READ_WITH_FRAGMENTS 2
  45100. +
  45101. +typedef struct pagelist_struct {
  45102. + unsigned long length;
  45103. + unsigned short type;
  45104. + unsigned short offset;
  45105. + unsigned long addrs[1]; /* N.B. 12 LSBs hold the number of following
  45106. + pages at consecutive addresses. */
  45107. +} PAGELIST_T;
  45108. +
  45109. +typedef struct fragments_struct {
  45110. + char headbuf[CACHE_LINE_SIZE];
  45111. + char tailbuf[CACHE_LINE_SIZE];
  45112. +} FRAGMENTS_T;
  45113. +
  45114. +#endif /* VCHIQ_PAGELIST_H */
  45115. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c
  45116. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 1970-01-01 01:00:00.000000000 +0100
  45117. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 2015-02-09 04:40:08.000000000 +0100
  45118. @@ -0,0 +1,857 @@
  45119. +/**
  45120. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  45121. + *
  45122. + * Redistribution and use in source and binary forms, with or without
  45123. + * modification, are permitted provided that the following conditions
  45124. + * are met:
  45125. + * 1. Redistributions of source code must retain the above copyright
  45126. + * notice, this list of conditions, and the following disclaimer,
  45127. + * without modification.
  45128. + * 2. Redistributions in binary form must reproduce the above copyright
  45129. + * notice, this list of conditions and the following disclaimer in the
  45130. + * documentation and/or other materials provided with the distribution.
  45131. + * 3. The names of the above-listed copyright holders may not be used
  45132. + * to endorse or promote products derived from this software without
  45133. + * specific prior written permission.
  45134. + *
  45135. + * ALTERNATIVELY, this software may be distributed under the terms of the
  45136. + * GNU General Public License ("GPL") version 2, as published by the Free
  45137. + * Software Foundation.
  45138. + *
  45139. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  45140. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  45141. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  45142. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  45143. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  45144. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  45145. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  45146. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  45147. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  45148. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  45149. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45150. + */
  45151. +#include <linux/module.h>
  45152. +#include <linux/types.h>
  45153. +
  45154. +#include "interface/vchi/vchi.h"
  45155. +#include "vchiq.h"
  45156. +#include "vchiq_core.h"
  45157. +
  45158. +#include "vchiq_util.h"
  45159. +
  45160. +#include <stddef.h>
  45161. +
  45162. +#define vchiq_status_to_vchi(status) ((int32_t)status)
  45163. +
  45164. +typedef struct {
  45165. + VCHIQ_SERVICE_HANDLE_T handle;
  45166. +
  45167. + VCHIU_QUEUE_T queue;
  45168. +
  45169. + VCHI_CALLBACK_T callback;
  45170. + void *callback_param;
  45171. +} SHIM_SERVICE_T;
  45172. +
  45173. +/* ----------------------------------------------------------------------
  45174. + * return pointer to the mphi message driver function table
  45175. + * -------------------------------------------------------------------- */
  45176. +const VCHI_MESSAGE_DRIVER_T *
  45177. +vchi_mphi_message_driver_func_table(void)
  45178. +{
  45179. + return NULL;
  45180. +}
  45181. +
  45182. +/* ----------------------------------------------------------------------
  45183. + * return a pointer to the 'single' connection driver fops
  45184. + * -------------------------------------------------------------------- */
  45185. +const VCHI_CONNECTION_API_T *
  45186. +single_get_func_table(void)
  45187. +{
  45188. + return NULL;
  45189. +}
  45190. +
  45191. +VCHI_CONNECTION_T *vchi_create_connection(
  45192. + const VCHI_CONNECTION_API_T *function_table,
  45193. + const VCHI_MESSAGE_DRIVER_T *low_level)
  45194. +{
  45195. + (void)function_table;
  45196. + (void)low_level;
  45197. + return NULL;
  45198. +}
  45199. +
  45200. +/***********************************************************
  45201. + * Name: vchi_msg_peek
  45202. + *
  45203. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  45204. + * void **data,
  45205. + * uint32_t *msg_size,
  45206. +
  45207. +
  45208. + * VCHI_FLAGS_T flags
  45209. + *
  45210. + * Description: Routine to return a pointer to the current message (to allow in
  45211. + * place processing). The message can be removed using
  45212. + * vchi_msg_remove when you're finished
  45213. + *
  45214. + * Returns: int32_t - success == 0
  45215. + *
  45216. + ***********************************************************/
  45217. +int32_t vchi_msg_peek(VCHI_SERVICE_HANDLE_T handle,
  45218. + void **data,
  45219. + uint32_t *msg_size,
  45220. + VCHI_FLAGS_T flags)
  45221. +{
  45222. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45223. + VCHIQ_HEADER_T *header;
  45224. +
  45225. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  45226. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  45227. +
  45228. + if (flags == VCHI_FLAGS_NONE)
  45229. + if (vchiu_queue_is_empty(&service->queue))
  45230. + return -1;
  45231. +
  45232. + header = vchiu_queue_peek(&service->queue);
  45233. +
  45234. + *data = header->data;
  45235. + *msg_size = header->size;
  45236. +
  45237. + return 0;
  45238. +}
  45239. +EXPORT_SYMBOL(vchi_msg_peek);
  45240. +
  45241. +/***********************************************************
  45242. + * Name: vchi_msg_remove
  45243. + *
  45244. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  45245. + *
  45246. + * Description: Routine to remove a message (after it has been read with
  45247. + * vchi_msg_peek)
  45248. + *
  45249. + * Returns: int32_t - success == 0
  45250. + *
  45251. + ***********************************************************/
  45252. +int32_t vchi_msg_remove(VCHI_SERVICE_HANDLE_T handle)
  45253. +{
  45254. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45255. + VCHIQ_HEADER_T *header;
  45256. +
  45257. + header = vchiu_queue_pop(&service->queue);
  45258. +
  45259. + vchiq_release_message(service->handle, header);
  45260. +
  45261. + return 0;
  45262. +}
  45263. +EXPORT_SYMBOL(vchi_msg_remove);
  45264. +
  45265. +/***********************************************************
  45266. + * Name: vchi_msg_queue
  45267. + *
  45268. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  45269. + * const void *data,
  45270. + * uint32_t data_size,
  45271. + * VCHI_FLAGS_T flags,
  45272. + * void *msg_handle,
  45273. + *
  45274. + * Description: Thin wrapper to queue a message onto a connection
  45275. + *
  45276. + * Returns: int32_t - success == 0
  45277. + *
  45278. + ***********************************************************/
  45279. +int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
  45280. + const void *data,
  45281. + uint32_t data_size,
  45282. + VCHI_FLAGS_T flags,
  45283. + void *msg_handle)
  45284. +{
  45285. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45286. + VCHIQ_ELEMENT_T element = {data, data_size};
  45287. + VCHIQ_STATUS_T status;
  45288. +
  45289. + (void)msg_handle;
  45290. +
  45291. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  45292. +
  45293. + status = vchiq_queue_message(service->handle, &element, 1);
  45294. +
  45295. + /* vchiq_queue_message() may return VCHIQ_RETRY, so we need to
  45296. + ** implement a retry mechanism since this function is supposed
  45297. + ** to block until queued
  45298. + */
  45299. + while (status == VCHIQ_RETRY) {
  45300. + msleep(1);
  45301. + status = vchiq_queue_message(service->handle, &element, 1);
  45302. + }
  45303. +
  45304. + return vchiq_status_to_vchi(status);
  45305. +}
  45306. +EXPORT_SYMBOL(vchi_msg_queue);
  45307. +
  45308. +/***********************************************************
  45309. + * Name: vchi_bulk_queue_receive
  45310. + *
  45311. + * Arguments: VCHI_BULK_HANDLE_T handle,
  45312. + * void *data_dst,
  45313. + * const uint32_t data_size,
  45314. + * VCHI_FLAGS_T flags
  45315. + * void *bulk_handle
  45316. + *
  45317. + * Description: Routine to setup a rcv buffer
  45318. + *
  45319. + * Returns: int32_t - success == 0
  45320. + *
  45321. + ***********************************************************/
  45322. +int32_t vchi_bulk_queue_receive(VCHI_SERVICE_HANDLE_T handle,
  45323. + void *data_dst,
  45324. + uint32_t data_size,
  45325. + VCHI_FLAGS_T flags,
  45326. + void *bulk_handle)
  45327. +{
  45328. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45329. + VCHIQ_BULK_MODE_T mode;
  45330. + VCHIQ_STATUS_T status;
  45331. +
  45332. + switch ((int)flags) {
  45333. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  45334. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  45335. + WARN_ON(!service->callback);
  45336. + mode = VCHIQ_BULK_MODE_CALLBACK;
  45337. + break;
  45338. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  45339. + mode = VCHIQ_BULK_MODE_BLOCKING;
  45340. + break;
  45341. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  45342. + case VCHI_FLAGS_NONE:
  45343. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  45344. + break;
  45345. + default:
  45346. + WARN(1, "unsupported message\n");
  45347. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  45348. + }
  45349. +
  45350. + status = vchiq_bulk_receive(service->handle, data_dst, data_size,
  45351. + bulk_handle, mode);
  45352. +
  45353. + /* vchiq_bulk_receive() may return VCHIQ_RETRY, so we need to
  45354. + ** implement a retry mechanism since this function is supposed
  45355. + ** to block until queued
  45356. + */
  45357. + while (status == VCHIQ_RETRY) {
  45358. + msleep(1);
  45359. + status = vchiq_bulk_receive(service->handle, data_dst,
  45360. + data_size, bulk_handle, mode);
  45361. + }
  45362. +
  45363. + return vchiq_status_to_vchi(status);
  45364. +}
  45365. +EXPORT_SYMBOL(vchi_bulk_queue_receive);
  45366. +
  45367. +/***********************************************************
  45368. + * Name: vchi_bulk_queue_transmit
  45369. + *
  45370. + * Arguments: VCHI_BULK_HANDLE_T handle,
  45371. + * const void *data_src,
  45372. + * uint32_t data_size,
  45373. + * VCHI_FLAGS_T flags,
  45374. + * void *bulk_handle
  45375. + *
  45376. + * Description: Routine to transmit some data
  45377. + *
  45378. + * Returns: int32_t - success == 0
  45379. + *
  45380. + ***********************************************************/
  45381. +int32_t vchi_bulk_queue_transmit(VCHI_SERVICE_HANDLE_T handle,
  45382. + const void *data_src,
  45383. + uint32_t data_size,
  45384. + VCHI_FLAGS_T flags,
  45385. + void *bulk_handle)
  45386. +{
  45387. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45388. + VCHIQ_BULK_MODE_T mode;
  45389. + VCHIQ_STATUS_T status;
  45390. +
  45391. + switch ((int)flags) {
  45392. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  45393. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  45394. + WARN_ON(!service->callback);
  45395. + mode = VCHIQ_BULK_MODE_CALLBACK;
  45396. + break;
  45397. + case VCHI_FLAGS_BLOCK_UNTIL_DATA_READ:
  45398. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  45399. + mode = VCHIQ_BULK_MODE_BLOCKING;
  45400. + break;
  45401. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  45402. + case VCHI_FLAGS_NONE:
  45403. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  45404. + break;
  45405. + default:
  45406. + WARN(1, "unsupported message\n");
  45407. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  45408. + }
  45409. +
  45410. + status = vchiq_bulk_transmit(service->handle, data_src, data_size,
  45411. + bulk_handle, mode);
  45412. +
  45413. + /* vchiq_bulk_transmit() may return VCHIQ_RETRY, so we need to
  45414. + ** implement a retry mechanism since this function is supposed
  45415. + ** to block until queued
  45416. + */
  45417. + while (status == VCHIQ_RETRY) {
  45418. + msleep(1);
  45419. + status = vchiq_bulk_transmit(service->handle, data_src,
  45420. + data_size, bulk_handle, mode);
  45421. + }
  45422. +
  45423. + return vchiq_status_to_vchi(status);
  45424. +}
  45425. +EXPORT_SYMBOL(vchi_bulk_queue_transmit);
  45426. +
  45427. +/***********************************************************
  45428. + * Name: vchi_msg_dequeue
  45429. + *
  45430. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  45431. + * void *data,
  45432. + * uint32_t max_data_size_to_read,
  45433. + * uint32_t *actual_msg_size
  45434. + * VCHI_FLAGS_T flags
  45435. + *
  45436. + * Description: Routine to dequeue a message into the supplied buffer
  45437. + *
  45438. + * Returns: int32_t - success == 0
  45439. + *
  45440. + ***********************************************************/
  45441. +int32_t vchi_msg_dequeue(VCHI_SERVICE_HANDLE_T handle,
  45442. + void *data,
  45443. + uint32_t max_data_size_to_read,
  45444. + uint32_t *actual_msg_size,
  45445. + VCHI_FLAGS_T flags)
  45446. +{
  45447. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45448. + VCHIQ_HEADER_T *header;
  45449. +
  45450. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  45451. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  45452. +
  45453. + if (flags == VCHI_FLAGS_NONE)
  45454. + if (vchiu_queue_is_empty(&service->queue))
  45455. + return -1;
  45456. +
  45457. + header = vchiu_queue_pop(&service->queue);
  45458. +
  45459. + memcpy(data, header->data, header->size < max_data_size_to_read ?
  45460. + header->size : max_data_size_to_read);
  45461. +
  45462. + *actual_msg_size = header->size;
  45463. +
  45464. + vchiq_release_message(service->handle, header);
  45465. +
  45466. + return 0;
  45467. +}
  45468. +EXPORT_SYMBOL(vchi_msg_dequeue);
  45469. +
  45470. +/***********************************************************
  45471. + * Name: vchi_msg_queuev
  45472. + *
  45473. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  45474. + * VCHI_MSG_VECTOR_T *vector,
  45475. + * uint32_t count,
  45476. + * VCHI_FLAGS_T flags,
  45477. + * void *msg_handle
  45478. + *
  45479. + * Description: Thin wrapper to queue a message onto a connection
  45480. + *
  45481. + * Returns: int32_t - success == 0
  45482. + *
  45483. + ***********************************************************/
  45484. +
  45485. +vchiq_static_assert(sizeof(VCHI_MSG_VECTOR_T) == sizeof(VCHIQ_ELEMENT_T));
  45486. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_base) ==
  45487. + offsetof(VCHIQ_ELEMENT_T, data));
  45488. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_len) ==
  45489. + offsetof(VCHIQ_ELEMENT_T, size));
  45490. +
  45491. +int32_t vchi_msg_queuev(VCHI_SERVICE_HANDLE_T handle,
  45492. + VCHI_MSG_VECTOR_T *vector,
  45493. + uint32_t count,
  45494. + VCHI_FLAGS_T flags,
  45495. + void *msg_handle)
  45496. +{
  45497. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45498. +
  45499. + (void)msg_handle;
  45500. +
  45501. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  45502. +
  45503. + return vchiq_status_to_vchi(vchiq_queue_message(service->handle,
  45504. + (const VCHIQ_ELEMENT_T *)vector, count));
  45505. +}
  45506. +EXPORT_SYMBOL(vchi_msg_queuev);
  45507. +
  45508. +/***********************************************************
  45509. + * Name: vchi_held_msg_release
  45510. + *
  45511. + * Arguments: VCHI_HELD_MSG_T *message
  45512. + *
  45513. + * Description: Routine to release a held message (after it has been read with
  45514. + * vchi_msg_hold)
  45515. + *
  45516. + * Returns: int32_t - success == 0
  45517. + *
  45518. + ***********************************************************/
  45519. +int32_t vchi_held_msg_release(VCHI_HELD_MSG_T *message)
  45520. +{
  45521. + vchiq_release_message((VCHIQ_SERVICE_HANDLE_T)message->service,
  45522. + (VCHIQ_HEADER_T *)message->message);
  45523. +
  45524. + return 0;
  45525. +}
  45526. +EXPORT_SYMBOL(vchi_held_msg_release);
  45527. +
  45528. +/***********************************************************
  45529. + * Name: vchi_msg_hold
  45530. + *
  45531. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  45532. + * void **data,
  45533. + * uint32_t *msg_size,
  45534. + * VCHI_FLAGS_T flags,
  45535. + * VCHI_HELD_MSG_T *message_handle
  45536. + *
  45537. + * Description: Routine to return a pointer to the current message (to allow
  45538. + * in place processing). The message is dequeued - don't forget
  45539. + * to release the message using vchi_held_msg_release when you're
  45540. + * finished.
  45541. + *
  45542. + * Returns: int32_t - success == 0
  45543. + *
  45544. + ***********************************************************/
  45545. +int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle,
  45546. + void **data,
  45547. + uint32_t *msg_size,
  45548. + VCHI_FLAGS_T flags,
  45549. + VCHI_HELD_MSG_T *message_handle)
  45550. +{
  45551. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45552. + VCHIQ_HEADER_T *header;
  45553. +
  45554. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  45555. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  45556. +
  45557. + if (flags == VCHI_FLAGS_NONE)
  45558. + if (vchiu_queue_is_empty(&service->queue))
  45559. + return -1;
  45560. +
  45561. + header = vchiu_queue_pop(&service->queue);
  45562. +
  45563. + *data = header->data;
  45564. + *msg_size = header->size;
  45565. +
  45566. + message_handle->service =
  45567. + (struct opaque_vchi_service_t *)service->handle;
  45568. + message_handle->message = header;
  45569. +
  45570. + return 0;
  45571. +}
  45572. +EXPORT_SYMBOL(vchi_msg_hold);
  45573. +
  45574. +/***********************************************************
  45575. + * Name: vchi_initialise
  45576. + *
  45577. + * Arguments: VCHI_INSTANCE_T *instance_handle
  45578. + *
  45579. + * Description: Initialises the hardware but does not transmit anything
  45580. + * When run as a Host App this will be called twice hence the need
  45581. + * to malloc the state information
  45582. + *
  45583. + * Returns: 0 if successful, failure otherwise
  45584. + *
  45585. + ***********************************************************/
  45586. +
  45587. +int32_t vchi_initialise(VCHI_INSTANCE_T *instance_handle)
  45588. +{
  45589. + VCHIQ_INSTANCE_T instance;
  45590. + VCHIQ_STATUS_T status;
  45591. +
  45592. + status = vchiq_initialise(&instance);
  45593. +
  45594. + *instance_handle = (VCHI_INSTANCE_T)instance;
  45595. +
  45596. + return vchiq_status_to_vchi(status);
  45597. +}
  45598. +EXPORT_SYMBOL(vchi_initialise);
  45599. +
  45600. +/***********************************************************
  45601. + * Name: vchi_connect
  45602. + *
  45603. + * Arguments: VCHI_CONNECTION_T **connections
  45604. + * const uint32_t num_connections
  45605. + * VCHI_INSTANCE_T instance_handle)
  45606. + *
  45607. + * Description: Starts the command service on each connection,
  45608. + * causing INIT messages to be pinged back and forth
  45609. + *
  45610. + * Returns: 0 if successful, failure otherwise
  45611. + *
  45612. + ***********************************************************/
  45613. +int32_t vchi_connect(VCHI_CONNECTION_T **connections,
  45614. + const uint32_t num_connections,
  45615. + VCHI_INSTANCE_T instance_handle)
  45616. +{
  45617. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  45618. +
  45619. + (void)connections;
  45620. + (void)num_connections;
  45621. +
  45622. + return vchiq_connect(instance);
  45623. +}
  45624. +EXPORT_SYMBOL(vchi_connect);
  45625. +
  45626. +
  45627. +/***********************************************************
  45628. + * Name: vchi_disconnect
  45629. + *
  45630. + * Arguments: VCHI_INSTANCE_T instance_handle
  45631. + *
  45632. + * Description: Stops the command service on each connection,
  45633. + * causing DE-INIT messages to be pinged back and forth
  45634. + *
  45635. + * Returns: 0 if successful, failure otherwise
  45636. + *
  45637. + ***********************************************************/
  45638. +int32_t vchi_disconnect(VCHI_INSTANCE_T instance_handle)
  45639. +{
  45640. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  45641. + return vchiq_status_to_vchi(vchiq_shutdown(instance));
  45642. +}
  45643. +EXPORT_SYMBOL(vchi_disconnect);
  45644. +
  45645. +
  45646. +/***********************************************************
  45647. + * Name: vchi_service_open
  45648. + * Name: vchi_service_create
  45649. + *
  45650. + * Arguments: VCHI_INSTANCE_T *instance_handle
  45651. + * SERVICE_CREATION_T *setup,
  45652. + * VCHI_SERVICE_HANDLE_T *handle
  45653. + *
  45654. + * Description: Routine to open a service
  45655. + *
  45656. + * Returns: int32_t - success == 0
  45657. + *
  45658. + ***********************************************************/
  45659. +
  45660. +static VCHIQ_STATUS_T shim_callback(VCHIQ_REASON_T reason,
  45661. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_HANDLE_T handle, void *bulk_user)
  45662. +{
  45663. + SHIM_SERVICE_T *service =
  45664. + (SHIM_SERVICE_T *)VCHIQ_GET_SERVICE_USERDATA(handle);
  45665. +
  45666. + if (!service->callback)
  45667. + goto release;
  45668. +
  45669. + switch (reason) {
  45670. + case VCHIQ_MESSAGE_AVAILABLE:
  45671. + vchiu_queue_push(&service->queue, header);
  45672. +
  45673. + service->callback(service->callback_param,
  45674. + VCHI_CALLBACK_MSG_AVAILABLE, NULL);
  45675. +
  45676. + goto done;
  45677. + break;
  45678. +
  45679. + case VCHIQ_BULK_TRANSMIT_DONE:
  45680. + service->callback(service->callback_param,
  45681. + VCHI_CALLBACK_BULK_SENT, bulk_user);
  45682. + break;
  45683. +
  45684. + case VCHIQ_BULK_RECEIVE_DONE:
  45685. + service->callback(service->callback_param,
  45686. + VCHI_CALLBACK_BULK_RECEIVED, bulk_user);
  45687. + break;
  45688. +
  45689. + case VCHIQ_SERVICE_CLOSED:
  45690. + service->callback(service->callback_param,
  45691. + VCHI_CALLBACK_SERVICE_CLOSED, NULL);
  45692. + break;
  45693. +
  45694. + case VCHIQ_SERVICE_OPENED:
  45695. + /* No equivalent VCHI reason */
  45696. + break;
  45697. +
  45698. + case VCHIQ_BULK_TRANSMIT_ABORTED:
  45699. + service->callback(service->callback_param,
  45700. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  45701. + bulk_user);
  45702. + break;
  45703. +
  45704. + case VCHIQ_BULK_RECEIVE_ABORTED:
  45705. + service->callback(service->callback_param,
  45706. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  45707. + bulk_user);
  45708. + break;
  45709. +
  45710. + default:
  45711. + WARN(1, "not supported\n");
  45712. + break;
  45713. + }
  45714. +
  45715. +release:
  45716. + vchiq_release_message(service->handle, header);
  45717. +done:
  45718. + return VCHIQ_SUCCESS;
  45719. +}
  45720. +
  45721. +static SHIM_SERVICE_T *service_alloc(VCHIQ_INSTANCE_T instance,
  45722. + SERVICE_CREATION_T *setup)
  45723. +{
  45724. + SHIM_SERVICE_T *service = kzalloc(sizeof(SHIM_SERVICE_T), GFP_KERNEL);
  45725. +
  45726. + (void)instance;
  45727. +
  45728. + if (service) {
  45729. + if (vchiu_queue_init(&service->queue, 64)) {
  45730. + service->callback = setup->callback;
  45731. + service->callback_param = setup->callback_param;
  45732. + } else {
  45733. + kfree(service);
  45734. + service = NULL;
  45735. + }
  45736. + }
  45737. +
  45738. + return service;
  45739. +}
  45740. +
  45741. +static void service_free(SHIM_SERVICE_T *service)
  45742. +{
  45743. + if (service) {
  45744. + vchiu_queue_delete(&service->queue);
  45745. + kfree(service);
  45746. + }
  45747. +}
  45748. +
  45749. +int32_t vchi_service_open(VCHI_INSTANCE_T instance_handle,
  45750. + SERVICE_CREATION_T *setup,
  45751. + VCHI_SERVICE_HANDLE_T *handle)
  45752. +{
  45753. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  45754. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  45755. +
  45756. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  45757. +
  45758. + if (service) {
  45759. + VCHIQ_SERVICE_PARAMS_T params;
  45760. + VCHIQ_STATUS_T status;
  45761. +
  45762. + memset(&params, 0, sizeof(params));
  45763. + params.fourcc = setup->service_id;
  45764. + params.callback = shim_callback;
  45765. + params.userdata = service;
  45766. + params.version = setup->version.version;
  45767. + params.version_min = setup->version.version_min;
  45768. +
  45769. + status = vchiq_open_service(instance, &params,
  45770. + &service->handle);
  45771. + if (status != VCHIQ_SUCCESS) {
  45772. + service_free(service);
  45773. + service = NULL;
  45774. + *handle = NULL;
  45775. + }
  45776. + }
  45777. +
  45778. + return (service != NULL) ? 0 : -1;
  45779. +}
  45780. +EXPORT_SYMBOL(vchi_service_open);
  45781. +
  45782. +int32_t vchi_service_create(VCHI_INSTANCE_T instance_handle,
  45783. + SERVICE_CREATION_T *setup,
  45784. + VCHI_SERVICE_HANDLE_T *handle)
  45785. +{
  45786. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  45787. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  45788. +
  45789. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  45790. +
  45791. + if (service) {
  45792. + VCHIQ_SERVICE_PARAMS_T params;
  45793. + VCHIQ_STATUS_T status;
  45794. +
  45795. + memset(&params, 0, sizeof(params));
  45796. + params.fourcc = setup->service_id;
  45797. + params.callback = shim_callback;
  45798. + params.userdata = service;
  45799. + params.version = setup->version.version;
  45800. + params.version_min = setup->version.version_min;
  45801. + status = vchiq_add_service(instance, &params, &service->handle);
  45802. +
  45803. + if (status != VCHIQ_SUCCESS) {
  45804. + service_free(service);
  45805. + service = NULL;
  45806. + *handle = NULL;
  45807. + }
  45808. + }
  45809. +
  45810. + return (service != NULL) ? 0 : -1;
  45811. +}
  45812. +EXPORT_SYMBOL(vchi_service_create);
  45813. +
  45814. +int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle)
  45815. +{
  45816. + int32_t ret = -1;
  45817. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45818. + if (service) {
  45819. + VCHIQ_STATUS_T status = vchiq_close_service(service->handle);
  45820. + if (status == VCHIQ_SUCCESS) {
  45821. + service_free(service);
  45822. + service = NULL;
  45823. + }
  45824. +
  45825. + ret = vchiq_status_to_vchi(status);
  45826. + }
  45827. + return ret;
  45828. +}
  45829. +EXPORT_SYMBOL(vchi_service_close);
  45830. +
  45831. +int32_t vchi_service_destroy(const VCHI_SERVICE_HANDLE_T handle)
  45832. +{
  45833. + int32_t ret = -1;
  45834. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45835. + if (service) {
  45836. + VCHIQ_STATUS_T status = vchiq_remove_service(service->handle);
  45837. + if (status == VCHIQ_SUCCESS) {
  45838. + service_free(service);
  45839. + service = NULL;
  45840. + }
  45841. +
  45842. + ret = vchiq_status_to_vchi(status);
  45843. + }
  45844. + return ret;
  45845. +}
  45846. +EXPORT_SYMBOL(vchi_service_destroy);
  45847. +
  45848. +int32_t vchi_service_set_option(const VCHI_SERVICE_HANDLE_T handle,
  45849. + VCHI_SERVICE_OPTION_T option,
  45850. + int value)
  45851. +{
  45852. + int32_t ret = -1;
  45853. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45854. + VCHIQ_SERVICE_OPTION_T vchiq_option;
  45855. + switch (option) {
  45856. + case VCHI_SERVICE_OPTION_TRACE:
  45857. + vchiq_option = VCHIQ_SERVICE_OPTION_TRACE;
  45858. + break;
  45859. + default:
  45860. + service = NULL;
  45861. + break;
  45862. + }
  45863. + if (service) {
  45864. + VCHIQ_STATUS_T status =
  45865. + vchiq_set_service_option(service->handle,
  45866. + vchiq_option,
  45867. + value);
  45868. +
  45869. + ret = vchiq_status_to_vchi(status);
  45870. + }
  45871. + return ret;
  45872. +}
  45873. +EXPORT_SYMBOL(vchi_service_set_option);
  45874. +
  45875. +int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle, short *peer_version )
  45876. +{
  45877. + int32_t ret = -1;
  45878. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45879. + if(service)
  45880. + {
  45881. + VCHIQ_STATUS_T status = vchiq_get_peer_version(service->handle, peer_version);
  45882. + ret = vchiq_status_to_vchi( status );
  45883. + }
  45884. + return ret;
  45885. +}
  45886. +EXPORT_SYMBOL(vchi_get_peer_version);
  45887. +
  45888. +/* ----------------------------------------------------------------------
  45889. + * read a uint32_t from buffer.
  45890. + * network format is defined to be little endian
  45891. + * -------------------------------------------------------------------- */
  45892. +uint32_t
  45893. +vchi_readbuf_uint32(const void *_ptr)
  45894. +{
  45895. + const unsigned char *ptr = _ptr;
  45896. + return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
  45897. +}
  45898. +
  45899. +/* ----------------------------------------------------------------------
  45900. + * write a uint32_t to buffer.
  45901. + * network format is defined to be little endian
  45902. + * -------------------------------------------------------------------- */
  45903. +void
  45904. +vchi_writebuf_uint32(void *_ptr, uint32_t value)
  45905. +{
  45906. + unsigned char *ptr = _ptr;
  45907. + ptr[0] = (unsigned char)((value >> 0) & 0xFF);
  45908. + ptr[1] = (unsigned char)((value >> 8) & 0xFF);
  45909. + ptr[2] = (unsigned char)((value >> 16) & 0xFF);
  45910. + ptr[3] = (unsigned char)((value >> 24) & 0xFF);
  45911. +}
  45912. +
  45913. +/* ----------------------------------------------------------------------
  45914. + * read a uint16_t from buffer.
  45915. + * network format is defined to be little endian
  45916. + * -------------------------------------------------------------------- */
  45917. +uint16_t
  45918. +vchi_readbuf_uint16(const void *_ptr)
  45919. +{
  45920. + const unsigned char *ptr = _ptr;
  45921. + return ptr[0] | (ptr[1] << 8);
  45922. +}
  45923. +
  45924. +/* ----------------------------------------------------------------------
  45925. + * write a uint16_t into the buffer.
  45926. + * network format is defined to be little endian
  45927. + * -------------------------------------------------------------------- */
  45928. +void
  45929. +vchi_writebuf_uint16(void *_ptr, uint16_t value)
  45930. +{
  45931. + unsigned char *ptr = _ptr;
  45932. + ptr[0] = (value >> 0) & 0xFF;
  45933. + ptr[1] = (value >> 8) & 0xFF;
  45934. +}
  45935. +
  45936. +/***********************************************************
  45937. + * Name: vchi_service_use
  45938. + *
  45939. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  45940. + *
  45941. + * Description: Routine to increment refcount on a service
  45942. + *
  45943. + * Returns: void
  45944. + *
  45945. + ***********************************************************/
  45946. +int32_t vchi_service_use(const VCHI_SERVICE_HANDLE_T handle)
  45947. +{
  45948. + int32_t ret = -1;
  45949. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45950. + if (service)
  45951. + ret = vchiq_status_to_vchi(vchiq_use_service(service->handle));
  45952. + return ret;
  45953. +}
  45954. +EXPORT_SYMBOL(vchi_service_use);
  45955. +
  45956. +/***********************************************************
  45957. + * Name: vchi_service_release
  45958. + *
  45959. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  45960. + *
  45961. + * Description: Routine to decrement refcount on a service
  45962. + *
  45963. + * Returns: void
  45964. + *
  45965. + ***********************************************************/
  45966. +int32_t vchi_service_release(const VCHI_SERVICE_HANDLE_T handle)
  45967. +{
  45968. + int32_t ret = -1;
  45969. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  45970. + if (service)
  45971. + ret = vchiq_status_to_vchi(
  45972. + vchiq_release_service(service->handle));
  45973. + return ret;
  45974. +}
  45975. +EXPORT_SYMBOL(vchi_service_release);
  45976. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
  45977. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 1970-01-01 01:00:00.000000000 +0100
  45978. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 2015-02-09 04:40:08.000000000 +0100
  45979. @@ -0,0 +1,152 @@
  45980. +/**
  45981. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  45982. + *
  45983. + * Redistribution and use in source and binary forms, with or without
  45984. + * modification, are permitted provided that the following conditions
  45985. + * are met:
  45986. + * 1. Redistributions of source code must retain the above copyright
  45987. + * notice, this list of conditions, and the following disclaimer,
  45988. + * without modification.
  45989. + * 2. Redistributions in binary form must reproduce the above copyright
  45990. + * notice, this list of conditions and the following disclaimer in the
  45991. + * documentation and/or other materials provided with the distribution.
  45992. + * 3. The names of the above-listed copyright holders may not be used
  45993. + * to endorse or promote products derived from this software without
  45994. + * specific prior written permission.
  45995. + *
  45996. + * ALTERNATIVELY, this software may be distributed under the terms of the
  45997. + * GNU General Public License ("GPL") version 2, as published by the Free
  45998. + * Software Foundation.
  45999. + *
  46000. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  46001. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  46002. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  46003. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  46004. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  46005. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  46006. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  46007. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  46008. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  46009. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  46010. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46011. + */
  46012. +
  46013. +#include "vchiq_util.h"
  46014. +#include "vchiq_killable.h"
  46015. +
  46016. +static inline int is_pow2(int i)
  46017. +{
  46018. + return i && !(i & (i - 1));
  46019. +}
  46020. +
  46021. +int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size)
  46022. +{
  46023. + WARN_ON(!is_pow2(size));
  46024. +
  46025. + queue->size = size;
  46026. + queue->read = 0;
  46027. + queue->write = 0;
  46028. +
  46029. + sema_init(&queue->pop, 0);
  46030. + sema_init(&queue->push, 0);
  46031. +
  46032. + queue->storage = kzalloc(size * sizeof(VCHIQ_HEADER_T *), GFP_KERNEL);
  46033. + if (queue->storage == NULL) {
  46034. + vchiu_queue_delete(queue);
  46035. + return 0;
  46036. + }
  46037. + return 1;
  46038. +}
  46039. +
  46040. +void vchiu_queue_delete(VCHIU_QUEUE_T *queue)
  46041. +{
  46042. + if (queue->storage != NULL)
  46043. + kfree(queue->storage);
  46044. +}
  46045. +
  46046. +int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue)
  46047. +{
  46048. + return queue->read == queue->write;
  46049. +}
  46050. +
  46051. +int vchiu_queue_is_full(VCHIU_QUEUE_T *queue)
  46052. +{
  46053. + return queue->write == queue->read + queue->size;
  46054. +}
  46055. +
  46056. +void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header)
  46057. +{
  46058. + while (queue->write == queue->read + queue->size) {
  46059. + if (down_interruptible(&queue->pop) != 0) {
  46060. + flush_signals(current);
  46061. + }
  46062. + }
  46063. +
  46064. + /*
  46065. + * Write to queue->storage must be visible after read from
  46066. + * queue->read
  46067. + */
  46068. + smp_mb();
  46069. +
  46070. + queue->storage[queue->write & (queue->size - 1)] = header;
  46071. +
  46072. + /*
  46073. + * Write to queue->storage must be visible before write to
  46074. + * queue->write
  46075. + */
  46076. + smp_wmb();
  46077. +
  46078. + queue->write++;
  46079. +
  46080. + up(&queue->push);
  46081. +}
  46082. +
  46083. +VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue)
  46084. +{
  46085. + while (queue->write == queue->read) {
  46086. + if (down_interruptible(&queue->push) != 0) {
  46087. + flush_signals(current);
  46088. + }
  46089. + }
  46090. +
  46091. + up(&queue->push); // We haven't removed anything from the queue.
  46092. +
  46093. + /*
  46094. + * Read from queue->storage must be visible after read from
  46095. + * queue->write
  46096. + */
  46097. + smp_rmb();
  46098. +
  46099. + return queue->storage[queue->read & (queue->size - 1)];
  46100. +}
  46101. +
  46102. +VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue)
  46103. +{
  46104. + VCHIQ_HEADER_T *header;
  46105. +
  46106. + while (queue->write == queue->read) {
  46107. + if (down_interruptible(&queue->push) != 0) {
  46108. + flush_signals(current);
  46109. + }
  46110. + }
  46111. +
  46112. + /*
  46113. + * Read from queue->storage must be visible after read from
  46114. + * queue->write
  46115. + */
  46116. + smp_rmb();
  46117. +
  46118. + header = queue->storage[queue->read & (queue->size - 1)];
  46119. +
  46120. + /*
  46121. + * Read from queue->storage must be visible before write to
  46122. + * queue->read
  46123. + */
  46124. + smp_mb();
  46125. +
  46126. + queue->read++;
  46127. +
  46128. + up(&queue->pop);
  46129. +
  46130. + return header;
  46131. +}
  46132. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h
  46133. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 1970-01-01 01:00:00.000000000 +0100
  46134. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 2015-02-09 04:40:08.000000000 +0100
  46135. @@ -0,0 +1,81 @@
  46136. +/**
  46137. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  46138. + *
  46139. + * Redistribution and use in source and binary forms, with or without
  46140. + * modification, are permitted provided that the following conditions
  46141. + * are met:
  46142. + * 1. Redistributions of source code must retain the above copyright
  46143. + * notice, this list of conditions, and the following disclaimer,
  46144. + * without modification.
  46145. + * 2. Redistributions in binary form must reproduce the above copyright
  46146. + * notice, this list of conditions and the following disclaimer in the
  46147. + * documentation and/or other materials provided with the distribution.
  46148. + * 3. The names of the above-listed copyright holders may not be used
  46149. + * to endorse or promote products derived from this software without
  46150. + * specific prior written permission.
  46151. + *
  46152. + * ALTERNATIVELY, this software may be distributed under the terms of the
  46153. + * GNU General Public License ("GPL") version 2, as published by the Free
  46154. + * Software Foundation.
  46155. + *
  46156. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  46157. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  46158. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  46159. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  46160. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  46161. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  46162. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  46163. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  46164. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  46165. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  46166. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46167. + */
  46168. +
  46169. +#ifndef VCHIQ_UTIL_H
  46170. +#define VCHIQ_UTIL_H
  46171. +
  46172. +#include <linux/types.h>
  46173. +#include <linux/semaphore.h>
  46174. +#include <linux/mutex.h>
  46175. +#include <linux/bitops.h>
  46176. +#include <linux/kthread.h>
  46177. +#include <linux/wait.h>
  46178. +#include <linux/vmalloc.h>
  46179. +#include <linux/jiffies.h>
  46180. +#include <linux/delay.h>
  46181. +#include <linux/string.h>
  46182. +#include <linux/types.h>
  46183. +#include <linux/interrupt.h>
  46184. +#include <linux/random.h>
  46185. +#include <linux/sched.h>
  46186. +#include <linux/ctype.h>
  46187. +#include <linux/uaccess.h>
  46188. +#include <linux/time.h> /* for time_t */
  46189. +#include <linux/slab.h>
  46190. +#include <linux/vmalloc.h>
  46191. +
  46192. +#include "vchiq_if.h"
  46193. +
  46194. +typedef struct {
  46195. + int size;
  46196. + int read;
  46197. + int write;
  46198. +
  46199. + struct semaphore pop;
  46200. + struct semaphore push;
  46201. +
  46202. + VCHIQ_HEADER_T **storage;
  46203. +} VCHIU_QUEUE_T;
  46204. +
  46205. +extern int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size);
  46206. +extern void vchiu_queue_delete(VCHIU_QUEUE_T *queue);
  46207. +
  46208. +extern int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue);
  46209. +extern int vchiu_queue_is_full(VCHIU_QUEUE_T *queue);
  46210. +
  46211. +extern void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header);
  46212. +
  46213. +extern VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue);
  46214. +extern VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue);
  46215. +
  46216. +#endif
  46217. diff -Nur linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c
  46218. --- linux-3.18.6/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 1970-01-01 01:00:00.000000000 +0100
  46219. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 2015-02-09 04:40:08.000000000 +0100
  46220. @@ -0,0 +1,59 @@
  46221. +/**
  46222. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  46223. + *
  46224. + * Redistribution and use in source and binary forms, with or without
  46225. + * modification, are permitted provided that the following conditions
  46226. + * are met:
  46227. + * 1. Redistributions of source code must retain the above copyright
  46228. + * notice, this list of conditions, and the following disclaimer,
  46229. + * without modification.
  46230. + * 2. Redistributions in binary form must reproduce the above copyright
  46231. + * notice, this list of conditions and the following disclaimer in the
  46232. + * documentation and/or other materials provided with the distribution.
  46233. + * 3. The names of the above-listed copyright holders may not be used
  46234. + * to endorse or promote products derived from this software without
  46235. + * specific prior written permission.
  46236. + *
  46237. + * ALTERNATIVELY, this software may be distributed under the terms of the
  46238. + * GNU General Public License ("GPL") version 2, as published by the Free
  46239. + * Software Foundation.
  46240. + *
  46241. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  46242. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  46243. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  46244. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  46245. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  46246. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  46247. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  46248. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  46249. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  46250. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  46251. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46252. + */
  46253. +#include "vchiq_build_info.h"
  46254. +#include <linux/broadcom/vc_debug_sym.h>
  46255. +
  46256. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_hostname, "dc4-arm-01" );
  46257. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_version, "9245b4c35b99b3870e1f7dc598c5692b3c66a6f0 (tainted)" );
  46258. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_time, __TIME__ );
  46259. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_date, __DATE__ );
  46260. +
  46261. +const char *vchiq_get_build_hostname( void )
  46262. +{
  46263. + return vchiq_build_hostname;
  46264. +}
  46265. +
  46266. +const char *vchiq_get_build_version( void )
  46267. +{
  46268. + return vchiq_build_version;
  46269. +}
  46270. +
  46271. +const char *vchiq_get_build_date( void )
  46272. +{
  46273. + return vchiq_build_date;
  46274. +}
  46275. +
  46276. +const char *vchiq_get_build_time( void )
  46277. +{
  46278. + return vchiq_build_time;
  46279. +}
  46280. diff -Nur linux-3.18.6/drivers/misc/vc04_services/Kconfig linux-rpi/drivers/misc/vc04_services/Kconfig
  46281. --- linux-3.18.6/drivers/misc/vc04_services/Kconfig 1970-01-01 01:00:00.000000000 +0100
  46282. +++ linux-rpi/drivers/misc/vc04_services/Kconfig 2015-02-09 04:40:07.000000000 +0100
  46283. @@ -0,0 +1,9 @@
  46284. +config BCM2708_VCHIQ
  46285. + tristate "Videocore VCHIQ"
  46286. + depends on MACH_BCM2708 || MACH_BCM2709
  46287. + default y
  46288. + help
  46289. + Kernel to VideoCore communication interface for the
  46290. + BCM2708 family of products.
  46291. + Defaults to Y when the Broadcom Videocore services
  46292. + are included in the build, N otherwise.
  46293. diff -Nur linux-3.18.6/drivers/misc/vc04_services/Makefile linux-rpi/drivers/misc/vc04_services/Makefile
  46294. --- linux-3.18.6/drivers/misc/vc04_services/Makefile 1970-01-01 01:00:00.000000000 +0100
  46295. +++ linux-rpi/drivers/misc/vc04_services/Makefile 2015-02-09 04:40:07.000000000 +0100
  46296. @@ -0,0 +1,14 @@
  46297. +obj-$(CONFIG_BCM2708_VCHIQ) += vchiq.o
  46298. +
  46299. +vchiq-objs := \
  46300. + interface/vchiq_arm/vchiq_core.o \
  46301. + interface/vchiq_arm/vchiq_arm.o \
  46302. + interface/vchiq_arm/vchiq_kern_lib.o \
  46303. + interface/vchiq_arm/vchiq_2835_arm.o \
  46304. + interface/vchiq_arm/vchiq_debugfs.o \
  46305. + interface/vchiq_arm/vchiq_shim.o \
  46306. + interface/vchiq_arm/vchiq_util.o \
  46307. + interface/vchiq_arm/vchiq_connected.o \
  46308. +
  46309. +ccflags-y += -DVCOS_VERIFY_BKPTS=1 -Idrivers/misc/vc04_services -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000
  46310. +
  46311. diff -Nur linux-3.18.6/drivers/mmc/core/quirks.c linux-rpi/drivers/mmc/core/quirks.c
  46312. --- linux-3.18.6/drivers/mmc/core/quirks.c 2015-02-06 15:53:48.000000000 +0100
  46313. +++ linux-rpi/drivers/mmc/core/quirks.c 2015-02-09 04:40:08.000000000 +0100
  46314. @@ -95,5 +95,9 @@
  46315. f->vendor_fixup(card, f->data);
  46316. }
  46317. }
  46318. + /* SDHCI on BCM2708 - bug causes a certain sequence of CMD23 operations to fail.
  46319. + * Disable this flag for all cards (fall-back to CMD25/CMD18 multi-block transfers).
  46320. + */
  46321. + card->quirks |= MMC_QUIRK_BLK_NO_CMD23;
  46322. }
  46323. EXPORT_SYMBOL(mmc_fixup_device);
  46324. diff -Nur linux-3.18.6/drivers/mmc/host/bcm2835-mmc.c linux-rpi/drivers/mmc/host/bcm2835-mmc.c
  46325. --- linux-3.18.6/drivers/mmc/host/bcm2835-mmc.c 1970-01-01 01:00:00.000000000 +0100
  46326. +++ linux-rpi/drivers/mmc/host/bcm2835-mmc.c 2015-02-09 04:40:09.000000000 +0100
  46327. @@ -0,0 +1,1557 @@
  46328. +/*
  46329. + * BCM2835 MMC host driver.
  46330. + *
  46331. + * Author: Gellert Weisz <gellert@raspberrypi.org>
  46332. + * Copyright 2014
  46333. + *
  46334. + * Based on
  46335. + * sdhci-bcm2708.c by Broadcom
  46336. + * sdhci-bcm2835.c by Stephen Warren and Oleksandr Tymoshenko
  46337. + * sdhci.c and sdhci-pci.c by Pierre Ossman
  46338. + *
  46339. + * This program is free software; you can redistribute it and/or modify it
  46340. + * under the terms and conditions of the GNU General Public License,
  46341. + * version 2, as published by the Free Software Foundation.
  46342. + *
  46343. + * This program is distributed in the hope it will be useful, but WITHOUT
  46344. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  46345. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  46346. + * more details.
  46347. + *
  46348. + * You should have received a copy of the GNU General Public License
  46349. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  46350. + */
  46351. +
  46352. +#include <linux/delay.h>
  46353. +#include <linux/module.h>
  46354. +#include <linux/io.h>
  46355. +#include <linux/mmc/mmc.h>
  46356. +#include <linux/mmc/host.h>
  46357. +#include <linux/mmc/sd.h>
  46358. +#include <linux/scatterlist.h>
  46359. +#include <linux/of_address.h>
  46360. +#include <linux/of_irq.h>
  46361. +#include <linux/clk.h>
  46362. +#include <linux/platform_device.h>
  46363. +#include <linux/err.h>
  46364. +#include <linux/blkdev.h>
  46365. +#include <linux/dmaengine.h>
  46366. +#include <linux/dma-mapping.h>
  46367. +#include <linux/of_dma.h>
  46368. +
  46369. +#include "sdhci.h"
  46370. +
  46371. +
  46372. +#ifndef CONFIG_ARCH_BCM2835
  46373. + #define BCM2835_CLOCK_FREQ 250000000
  46374. +#endif
  46375. +
  46376. +#define DRIVER_NAME "mmc-bcm2835"
  46377. +
  46378. +#define DBG(f, x...) \
  46379. +pr_debug(DRIVER_NAME " [%s()]: " f, __func__, ## x)
  46380. +
  46381. +#ifndef CONFIG_MMC_BCM2835_DMA
  46382. + #define FORCE_PIO
  46383. +#endif
  46384. +
  46385. +
  46386. +/* the inclusive limit in bytes under which PIO will be used instead of DMA */
  46387. +#ifdef CONFIG_MMC_BCM2835_PIO_DMA_BARRIER
  46388. +#define PIO_DMA_BARRIER CONFIG_MMC_BCM2835_PIO_DMA_BARRIER
  46389. +#else
  46390. +#define PIO_DMA_BARRIER 00
  46391. +#endif
  46392. +
  46393. +#define MIN_FREQ 400000
  46394. +#define TIMEOUT_VAL 0xE
  46395. +#define BCM2835_SDHCI_WRITE_DELAY(f) (((2 * 1000000) / f) + 1)
  46396. +
  46397. +#ifndef BCM2708_PERI_BASE
  46398. + #define BCM2708_PERI_BASE 0x20000000
  46399. +#endif
  46400. +
  46401. +/* FIXME: Needs IOMMU support */
  46402. +#define BCM2835_VCMMU_SHIFT (0x7E000000 - BCM2708_PERI_BASE)
  46403. +
  46404. +
  46405. +struct bcm2835_host {
  46406. + spinlock_t lock;
  46407. +
  46408. + void __iomem *ioaddr;
  46409. + u32 phys_addr;
  46410. +
  46411. + struct mmc_host *mmc;
  46412. +
  46413. + u32 timeout;
  46414. +
  46415. + int clock; /* Current clock speed */
  46416. + u8 pwr; /* Current voltage */
  46417. +
  46418. + unsigned int max_clk; /* Max possible freq */
  46419. + unsigned int timeout_clk; /* Timeout freq (KHz) */
  46420. + unsigned int clk_mul; /* Clock Muliplier value */
  46421. +
  46422. + struct tasklet_struct finish_tasklet; /* Tasklet structures */
  46423. +
  46424. + struct timer_list timer; /* Timer for timeouts */
  46425. +
  46426. + struct sg_mapping_iter sg_miter; /* SG state for PIO */
  46427. + unsigned int blocks; /* remaining PIO blocks */
  46428. +
  46429. + int irq; /* Device IRQ */
  46430. +
  46431. +
  46432. + u32 ier; /* cached registers */
  46433. +
  46434. + struct mmc_request *mrq; /* Current request */
  46435. + struct mmc_command *cmd; /* Current command */
  46436. + struct mmc_data *data; /* Current data request */
  46437. + unsigned int data_early:1; /* Data finished before cmd */
  46438. +
  46439. + wait_queue_head_t buf_ready_int; /* Waitqueue for Buffer Read Ready interrupt */
  46440. +
  46441. + u32 thread_isr;
  46442. +
  46443. + u32 shadow;
  46444. +
  46445. + /*DMA part*/
  46446. + struct dma_chan *dma_chan_rx; /* DMA channel for reads */
  46447. + struct dma_chan *dma_chan_tx; /* DMA channel for writes */
  46448. + struct dma_async_tx_descriptor *tx_desc; /* descriptor */
  46449. +
  46450. + bool have_dma;
  46451. + bool use_dma;
  46452. + /*end of DMA part*/
  46453. +
  46454. + int max_delay; /* maximum length of time spent waiting */
  46455. +
  46456. + int flags; /* Host attributes */
  46457. +#define SDHCI_USE_SDMA (1<<0) /* Host is SDMA capable */
  46458. +#define SDHCI_USE_ADMA (1<<1) /* Host is ADMA capable */
  46459. +#define SDHCI_REQ_USE_DMA (1<<2) /* Use DMA for this req. */
  46460. +#define SDHCI_DEVICE_DEAD (1<<3) /* Device unresponsive */
  46461. +#define SDHCI_AUTO_CMD12 (1<<6) /* Auto CMD12 support */
  46462. +#define SDHCI_AUTO_CMD23 (1<<7) /* Auto CMD23 support */
  46463. +#define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */
  46464. +#define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  46465. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  46466. +};
  46467. +
  46468. +
  46469. +static inline void bcm2835_mmc_writel(struct bcm2835_host *host, u32 val, int reg)
  46470. +{
  46471. + writel(val, host->ioaddr + reg);
  46472. + udelay(BCM2835_SDHCI_WRITE_DELAY(max(host->clock, MIN_FREQ)));
  46473. +}
  46474. +
  46475. +static inline void mmc_raw_writel(struct bcm2835_host *host, u32 val, int reg)
  46476. +{
  46477. + writel(val, host->ioaddr + reg);
  46478. +}
  46479. +
  46480. +static inline u32 bcm2835_mmc_readl(struct bcm2835_host *host, int reg)
  46481. +{
  46482. + return readl(host->ioaddr + reg);
  46483. +}
  46484. +
  46485. +static inline void bcm2835_mmc_writew(struct bcm2835_host *host, u16 val, int reg)
  46486. +{
  46487. + u32 oldval = (reg == SDHCI_COMMAND) ? host->shadow :
  46488. + bcm2835_mmc_readl(host, reg & ~3);
  46489. + u32 word_num = (reg >> 1) & 1;
  46490. + u32 word_shift = word_num * 16;
  46491. + u32 mask = 0xffff << word_shift;
  46492. + u32 newval = (oldval & ~mask) | (val << word_shift);
  46493. +
  46494. + if (reg == SDHCI_TRANSFER_MODE)
  46495. + host->shadow = newval;
  46496. + else
  46497. + bcm2835_mmc_writel(host, newval, reg & ~3);
  46498. +
  46499. +}
  46500. +
  46501. +static inline void bcm2835_mmc_writeb(struct bcm2835_host *host, u8 val, int reg)
  46502. +{
  46503. + u32 oldval = bcm2835_mmc_readl(host, reg & ~3);
  46504. + u32 byte_num = reg & 3;
  46505. + u32 byte_shift = byte_num * 8;
  46506. + u32 mask = 0xff << byte_shift;
  46507. + u32 newval = (oldval & ~mask) | (val << byte_shift);
  46508. +
  46509. + bcm2835_mmc_writel(host, newval, reg & ~3);
  46510. +}
  46511. +
  46512. +
  46513. +static inline u16 bcm2835_mmc_readw(struct bcm2835_host *host, int reg)
  46514. +{
  46515. + u32 val = bcm2835_mmc_readl(host, (reg & ~3));
  46516. + u32 word_num = (reg >> 1) & 1;
  46517. + u32 word_shift = word_num * 16;
  46518. + u32 word = (val >> word_shift) & 0xffff;
  46519. +
  46520. + return word;
  46521. +}
  46522. +
  46523. +static inline u8 bcm2835_mmc_readb(struct bcm2835_host *host, int reg)
  46524. +{
  46525. + u32 val = bcm2835_mmc_readl(host, (reg & ~3));
  46526. + u32 byte_num = reg & 3;
  46527. + u32 byte_shift = byte_num * 8;
  46528. + u32 byte = (val >> byte_shift) & 0xff;
  46529. +
  46530. + return byte;
  46531. +}
  46532. +
  46533. +static void bcm2835_mmc_unsignal_irqs(struct bcm2835_host *host, u32 clear)
  46534. +{
  46535. + u32 ier;
  46536. +
  46537. + ier = bcm2835_mmc_readl(host, SDHCI_SIGNAL_ENABLE);
  46538. + ier &= ~clear;
  46539. + /* change which requests generate IRQs - makes no difference to
  46540. + the content of SDHCI_INT_STATUS, or the need to acknowledge IRQs */
  46541. + bcm2835_mmc_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  46542. +}
  46543. +
  46544. +
  46545. +static void bcm2835_mmc_dumpregs(struct bcm2835_host *host)
  46546. +{
  46547. + pr_debug(DRIVER_NAME ": =========== REGISTER DUMP (%s)===========\n",
  46548. + mmc_hostname(host->mmc));
  46549. +
  46550. + pr_debug(DRIVER_NAME ": Sys addr: 0x%08x | Version: 0x%08x\n",
  46551. + bcm2835_mmc_readl(host, SDHCI_DMA_ADDRESS),
  46552. + bcm2835_mmc_readw(host, SDHCI_HOST_VERSION));
  46553. + pr_debug(DRIVER_NAME ": Blk size: 0x%08x | Blk cnt: 0x%08x\n",
  46554. + bcm2835_mmc_readw(host, SDHCI_BLOCK_SIZE),
  46555. + bcm2835_mmc_readw(host, SDHCI_BLOCK_COUNT));
  46556. + pr_debug(DRIVER_NAME ": Argument: 0x%08x | Trn mode: 0x%08x\n",
  46557. + bcm2835_mmc_readl(host, SDHCI_ARGUMENT),
  46558. + bcm2835_mmc_readw(host, SDHCI_TRANSFER_MODE));
  46559. + pr_debug(DRIVER_NAME ": Present: 0x%08x | Host ctl: 0x%08x\n",
  46560. + bcm2835_mmc_readl(host, SDHCI_PRESENT_STATE),
  46561. + bcm2835_mmc_readb(host, SDHCI_HOST_CONTROL));
  46562. + pr_debug(DRIVER_NAME ": Power: 0x%08x | Blk gap: 0x%08x\n",
  46563. + bcm2835_mmc_readb(host, SDHCI_POWER_CONTROL),
  46564. + bcm2835_mmc_readb(host, SDHCI_BLOCK_GAP_CONTROL));
  46565. + pr_debug(DRIVER_NAME ": Wake-up: 0x%08x | Clock: 0x%08x\n",
  46566. + bcm2835_mmc_readb(host, SDHCI_WAKE_UP_CONTROL),
  46567. + bcm2835_mmc_readw(host, SDHCI_CLOCK_CONTROL));
  46568. + pr_debug(DRIVER_NAME ": Timeout: 0x%08x | Int stat: 0x%08x\n",
  46569. + bcm2835_mmc_readb(host, SDHCI_TIMEOUT_CONTROL),
  46570. + bcm2835_mmc_readl(host, SDHCI_INT_STATUS));
  46571. + pr_debug(DRIVER_NAME ": Int enab: 0x%08x | Sig enab: 0x%08x\n",
  46572. + bcm2835_mmc_readl(host, SDHCI_INT_ENABLE),
  46573. + bcm2835_mmc_readl(host, SDHCI_SIGNAL_ENABLE));
  46574. + pr_debug(DRIVER_NAME ": AC12 err: 0x%08x | Slot int: 0x%08x\n",
  46575. + bcm2835_mmc_readw(host, SDHCI_ACMD12_ERR),
  46576. + bcm2835_mmc_readw(host, SDHCI_SLOT_INT_STATUS));
  46577. + pr_debug(DRIVER_NAME ": Caps: 0x%08x | Caps_1: 0x%08x\n",
  46578. + bcm2835_mmc_readl(host, SDHCI_CAPABILITIES),
  46579. + bcm2835_mmc_readl(host, SDHCI_CAPABILITIES_1));
  46580. + pr_debug(DRIVER_NAME ": Cmd: 0x%08x | Max curr: 0x%08x\n",
  46581. + bcm2835_mmc_readw(host, SDHCI_COMMAND),
  46582. + bcm2835_mmc_readl(host, SDHCI_MAX_CURRENT));
  46583. + pr_debug(DRIVER_NAME ": Host ctl2: 0x%08x\n",
  46584. + bcm2835_mmc_readw(host, SDHCI_HOST_CONTROL2));
  46585. +
  46586. + pr_debug(DRIVER_NAME ": ===========================================\n");
  46587. +}
  46588. +
  46589. +
  46590. +static void bcm2835_mmc_reset(struct bcm2835_host *host, u8 mask)
  46591. +{
  46592. + unsigned long timeout;
  46593. +
  46594. + bcm2835_mmc_writeb(host, mask, SDHCI_SOFTWARE_RESET);
  46595. +
  46596. + if (mask & SDHCI_RESET_ALL)
  46597. + host->clock = 0;
  46598. +
  46599. + /* Wait max 100 ms */
  46600. + timeout = 100;
  46601. +
  46602. + /* hw clears the bit when it's done */
  46603. + while (bcm2835_mmc_readb(host, SDHCI_SOFTWARE_RESET) & mask) {
  46604. + if (timeout == 0) {
  46605. + pr_err("%s: Reset 0x%x never completed.\n",
  46606. + mmc_hostname(host->mmc), (int)mask);
  46607. + bcm2835_mmc_dumpregs(host);
  46608. + return;
  46609. + }
  46610. + timeout--;
  46611. + mdelay(1);
  46612. + }
  46613. +
  46614. + if (100-timeout > 10 && 100-timeout > host->max_delay) {
  46615. + host->max_delay = 100-timeout;
  46616. + pr_warning("Warning: MMC controller hung for %d ms\n", host->max_delay);
  46617. + }
  46618. +}
  46619. +
  46620. +static void bcm2835_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios);
  46621. +
  46622. +static void bcm2835_mmc_init(struct bcm2835_host *host, int soft)
  46623. +{
  46624. + if (soft)
  46625. + bcm2835_mmc_reset(host, SDHCI_RESET_CMD|SDHCI_RESET_DATA);
  46626. + else
  46627. + bcm2835_mmc_reset(host, SDHCI_RESET_ALL);
  46628. +
  46629. + host->ier = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT |
  46630. + SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT |
  46631. + SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC |
  46632. + SDHCI_INT_TIMEOUT | SDHCI_INT_DATA_END |
  46633. + SDHCI_INT_RESPONSE;
  46634. +
  46635. + bcm2835_mmc_writel(host, host->ier, SDHCI_INT_ENABLE);
  46636. + bcm2835_mmc_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
  46637. +
  46638. + if (soft) {
  46639. + /* force clock reconfiguration */
  46640. + host->clock = 0;
  46641. + bcm2835_mmc_set_ios(host->mmc, &host->mmc->ios);
  46642. + }
  46643. +}
  46644. +
  46645. +
  46646. +
  46647. +static void bcm2835_mmc_finish_data(struct bcm2835_host *host);
  46648. +
  46649. +static void bcm2835_mmc_dma_complete(void *param)
  46650. +{
  46651. + struct bcm2835_host *host = param;
  46652. + struct dma_chan *dma_chan;
  46653. + unsigned long flags;
  46654. + u32 dir_data;
  46655. +
  46656. + spin_lock_irqsave(&host->lock, flags);
  46657. +
  46658. + if (host->data && !(host->data->flags & MMC_DATA_WRITE)) {
  46659. + /* otherwise handled in SDHCI IRQ */
  46660. + dma_chan = host->dma_chan_rx;
  46661. + dir_data = DMA_FROM_DEVICE;
  46662. +
  46663. + dma_unmap_sg(dma_chan->device->dev,
  46664. + host->data->sg, host->data->sg_len,
  46665. + dir_data);
  46666. +
  46667. + bcm2835_mmc_finish_data(host);
  46668. + }
  46669. +
  46670. + spin_unlock_irqrestore(&host->lock, flags);
  46671. +}
  46672. +
  46673. +static void bcm2835_bcm2835_mmc_read_block_pio(struct bcm2835_host *host)
  46674. +{
  46675. + unsigned long flags;
  46676. + size_t blksize, len, chunk;
  46677. +
  46678. + u32 uninitialized_var(scratch);
  46679. + u8 *buf;
  46680. +
  46681. + blksize = host->data->blksz;
  46682. + chunk = 0;
  46683. +
  46684. + local_irq_save(flags);
  46685. +
  46686. + while (blksize) {
  46687. + if (!sg_miter_next(&host->sg_miter))
  46688. + BUG();
  46689. +
  46690. + len = min(host->sg_miter.length, blksize);
  46691. +
  46692. + blksize -= len;
  46693. + host->sg_miter.consumed = len;
  46694. +
  46695. + buf = host->sg_miter.addr;
  46696. +
  46697. + while (len) {
  46698. + if (chunk == 0) {
  46699. + scratch = bcm2835_mmc_readl(host, SDHCI_BUFFER);
  46700. + chunk = 4;
  46701. + }
  46702. +
  46703. + *buf = scratch & 0xFF;
  46704. +
  46705. + buf++;
  46706. + scratch >>= 8;
  46707. + chunk--;
  46708. + len--;
  46709. + }
  46710. + }
  46711. +
  46712. + sg_miter_stop(&host->sg_miter);
  46713. +
  46714. + local_irq_restore(flags);
  46715. +}
  46716. +
  46717. +static void bcm2835_bcm2835_mmc_write_block_pio(struct bcm2835_host *host)
  46718. +{
  46719. + unsigned long flags;
  46720. + size_t blksize, len, chunk;
  46721. + u32 scratch;
  46722. + u8 *buf;
  46723. +
  46724. + blksize = host->data->blksz;
  46725. + chunk = 0;
  46726. + chunk = 0;
  46727. + scratch = 0;
  46728. +
  46729. + local_irq_save(flags);
  46730. +
  46731. + while (blksize) {
  46732. + if (!sg_miter_next(&host->sg_miter))
  46733. + BUG();
  46734. +
  46735. + len = min(host->sg_miter.length, blksize);
  46736. +
  46737. + blksize -= len;
  46738. + host->sg_miter.consumed = len;
  46739. +
  46740. + buf = host->sg_miter.addr;
  46741. +
  46742. + while (len) {
  46743. + scratch |= (u32)*buf << (chunk * 8);
  46744. +
  46745. + buf++;
  46746. + chunk++;
  46747. + len--;
  46748. +
  46749. + if ((chunk == 4) || ((len == 0) && (blksize == 0))) {
  46750. + mmc_raw_writel(host, scratch, SDHCI_BUFFER);
  46751. + chunk = 0;
  46752. + scratch = 0;
  46753. + }
  46754. + }
  46755. + }
  46756. +
  46757. + sg_miter_stop(&host->sg_miter);
  46758. +
  46759. + local_irq_restore(flags);
  46760. +}
  46761. +
  46762. +
  46763. +static void bcm2835_mmc_transfer_pio(struct bcm2835_host *host)
  46764. +{
  46765. + u32 mask;
  46766. +
  46767. + BUG_ON(!host->data);
  46768. +
  46769. + if (host->blocks == 0)
  46770. + return;
  46771. +
  46772. + if (host->data->flags & MMC_DATA_READ)
  46773. + mask = SDHCI_DATA_AVAILABLE;
  46774. + else
  46775. + mask = SDHCI_SPACE_AVAILABLE;
  46776. +
  46777. + while (bcm2835_mmc_readl(host, SDHCI_PRESENT_STATE) & mask) {
  46778. +
  46779. + if (host->data->flags & MMC_DATA_READ)
  46780. + bcm2835_bcm2835_mmc_read_block_pio(host);
  46781. + else
  46782. + bcm2835_bcm2835_mmc_write_block_pio(host);
  46783. +
  46784. + host->blocks--;
  46785. +
  46786. + /* QUIRK used in sdhci.c removes the 'if' */
  46787. + /* but it seems this is unnecessary */
  46788. + if (host->blocks == 0)
  46789. + break;
  46790. +
  46791. +
  46792. + }
  46793. +}
  46794. +
  46795. +
  46796. +static void bcm2835_mmc_transfer_dma(struct bcm2835_host *host)
  46797. +{
  46798. + u32 len, dir_data, dir_slave;
  46799. + struct dma_async_tx_descriptor *desc = NULL;
  46800. + struct dma_chan *dma_chan;
  46801. +
  46802. +
  46803. + WARN_ON(!host->data);
  46804. +
  46805. + if (!host->data)
  46806. + return;
  46807. +
  46808. + if (host->blocks == 0)
  46809. + return;
  46810. +
  46811. + if (host->data->flags & MMC_DATA_READ) {
  46812. + dma_chan = host->dma_chan_rx;
  46813. + dir_data = DMA_FROM_DEVICE;
  46814. + dir_slave = DMA_DEV_TO_MEM;
  46815. + } else {
  46816. + dma_chan = host->dma_chan_tx;
  46817. + dir_data = DMA_TO_DEVICE;
  46818. + dir_slave = DMA_MEM_TO_DEV;
  46819. + }
  46820. +
  46821. + BUG_ON(!dma_chan->device);
  46822. + BUG_ON(!dma_chan->device->dev);
  46823. + BUG_ON(!host->data->sg);
  46824. +
  46825. + len = dma_map_sg(dma_chan->device->dev, host->data->sg,
  46826. + host->data->sg_len, dir_data);
  46827. + if (len > 0) {
  46828. + desc = dmaengine_prep_slave_sg(dma_chan, host->data->sg,
  46829. + len, dir_slave,
  46830. + DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  46831. + } else {
  46832. + dev_err(mmc_dev(host->mmc), "dma_map_sg returned zero length\n");
  46833. + }
  46834. + if (desc) {
  46835. + bcm2835_mmc_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  46836. + SDHCI_INT_SPACE_AVAIL);
  46837. + host->tx_desc = desc;
  46838. + desc->callback = bcm2835_mmc_dma_complete;
  46839. + desc->callback_param = host;
  46840. + dmaengine_submit(desc);
  46841. + dma_async_issue_pending(dma_chan);
  46842. + }
  46843. +
  46844. +}
  46845. +
  46846. +
  46847. +
  46848. +static void bcm2835_mmc_set_transfer_irqs(struct bcm2835_host *host)
  46849. +{
  46850. + u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
  46851. + u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
  46852. +
  46853. + if (host->use_dma)
  46854. + host->ier = (host->ier & ~pio_irqs) | dma_irqs;
  46855. + else
  46856. + host->ier = (host->ier & ~dma_irqs) | pio_irqs;
  46857. +
  46858. + bcm2835_mmc_writel(host, host->ier, SDHCI_INT_ENABLE);
  46859. + bcm2835_mmc_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
  46860. +}
  46861. +
  46862. +
  46863. +static void bcm2835_mmc_prepare_data(struct bcm2835_host *host, struct mmc_command *cmd)
  46864. +{
  46865. + u8 count;
  46866. + struct mmc_data *data = cmd->data;
  46867. +
  46868. + WARN_ON(host->data);
  46869. +
  46870. + if (data || (cmd->flags & MMC_RSP_BUSY)) {
  46871. + count = TIMEOUT_VAL;
  46872. + bcm2835_mmc_writeb(host, count, SDHCI_TIMEOUT_CONTROL);
  46873. + }
  46874. +
  46875. + if (!data)
  46876. + return;
  46877. +
  46878. + /* Sanity checks */
  46879. + BUG_ON(data->blksz * data->blocks > 524288);
  46880. + BUG_ON(data->blksz > host->mmc->max_blk_size);
  46881. + BUG_ON(data->blocks > 65535);
  46882. +
  46883. + host->data = data;
  46884. + host->data_early = 0;
  46885. + host->data->bytes_xfered = 0;
  46886. +
  46887. +
  46888. + if (!(host->flags & SDHCI_REQ_USE_DMA)) {
  46889. + int flags;
  46890. +
  46891. + flags = SG_MITER_ATOMIC;
  46892. + if (host->data->flags & MMC_DATA_READ)
  46893. + flags |= SG_MITER_TO_SG;
  46894. + else
  46895. + flags |= SG_MITER_FROM_SG;
  46896. + sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
  46897. + host->blocks = data->blocks;
  46898. + }
  46899. +
  46900. + host->use_dma = host->have_dma && data->blocks > PIO_DMA_BARRIER;
  46901. +
  46902. + bcm2835_mmc_set_transfer_irqs(host);
  46903. +
  46904. + /* Set the DMA boundary value and block size */
  46905. + bcm2835_mmc_writew(host, SDHCI_MAKE_BLKSZ(SDHCI_DEFAULT_BOUNDARY_ARG,
  46906. + data->blksz), SDHCI_BLOCK_SIZE);
  46907. + bcm2835_mmc_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
  46908. +
  46909. + BUG_ON(!host->data);
  46910. +}
  46911. +
  46912. +static void bcm2835_mmc_set_transfer_mode(struct bcm2835_host *host,
  46913. + struct mmc_command *cmd)
  46914. +{
  46915. + u16 mode;
  46916. + struct mmc_data *data = cmd->data;
  46917. +
  46918. + if (data == NULL) {
  46919. + /* clear Auto CMD settings for no data CMDs */
  46920. + mode = bcm2835_mmc_readw(host, SDHCI_TRANSFER_MODE);
  46921. + bcm2835_mmc_writew(host, mode & ~(SDHCI_TRNS_AUTO_CMD12 |
  46922. + SDHCI_TRNS_AUTO_CMD23), SDHCI_TRANSFER_MODE);
  46923. + return;
  46924. + }
  46925. +
  46926. + WARN_ON(!host->data);
  46927. +
  46928. + mode = SDHCI_TRNS_BLK_CNT_EN;
  46929. +
  46930. + if ((mmc_op_multi(cmd->opcode) || data->blocks > 1)) {
  46931. + mode |= SDHCI_TRNS_MULTI;
  46932. +
  46933. + /*
  46934. + * If we are sending CMD23, CMD12 never gets sent
  46935. + * on successful completion (so no Auto-CMD12).
  46936. + */
  46937. + if (!host->mrq->sbc && (host->flags & SDHCI_AUTO_CMD12))
  46938. + mode |= SDHCI_TRNS_AUTO_CMD12;
  46939. + else if (host->mrq->sbc && (host->flags & SDHCI_AUTO_CMD23)) {
  46940. + mode |= SDHCI_TRNS_AUTO_CMD23;
  46941. + bcm2835_mmc_writel(host, host->mrq->sbc->arg, SDHCI_ARGUMENT2);
  46942. + }
  46943. + }
  46944. +
  46945. + if (data->flags & MMC_DATA_READ)
  46946. + mode |= SDHCI_TRNS_READ;
  46947. + if (host->flags & SDHCI_REQ_USE_DMA)
  46948. + mode |= SDHCI_TRNS_DMA;
  46949. +
  46950. + bcm2835_mmc_writew(host, mode, SDHCI_TRANSFER_MODE);
  46951. +}
  46952. +
  46953. +void bcm2835_mmc_send_command(struct bcm2835_host *host, struct mmc_command *cmd)
  46954. +{
  46955. + int flags;
  46956. + u32 mask;
  46957. + unsigned long timeout;
  46958. +
  46959. + WARN_ON(host->cmd);
  46960. +
  46961. + /* Wait max 10 ms */
  46962. + timeout = 1000;
  46963. +
  46964. + mask = SDHCI_CMD_INHIBIT;
  46965. + if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
  46966. + mask |= SDHCI_DATA_INHIBIT;
  46967. +
  46968. + /* We shouldn't wait for data inihibit for stop commands, even
  46969. + though they might use busy signaling */
  46970. + if (host->mrq->data && (cmd == host->mrq->data->stop))
  46971. + mask &= ~SDHCI_DATA_INHIBIT;
  46972. +
  46973. + while (bcm2835_mmc_readl(host, SDHCI_PRESENT_STATE) & mask) {
  46974. + if (timeout == 0) {
  46975. + pr_err("%s: Controller never released inhibit bit(s).\n",
  46976. + mmc_hostname(host->mmc));
  46977. + bcm2835_mmc_dumpregs(host);
  46978. + cmd->error = -EIO;
  46979. + tasklet_schedule(&host->finish_tasklet);
  46980. + return;
  46981. + }
  46982. + timeout--;
  46983. + udelay(10);
  46984. + }
  46985. +
  46986. + if ((1000-timeout)/100 > 1 && (1000-timeout)/100 > host->max_delay) {
  46987. + host->max_delay = (1000-timeout)/100;
  46988. + pr_warning("Warning: MMC controller hung for %d ms\n", host->max_delay);
  46989. + }
  46990. +
  46991. + timeout = jiffies;
  46992. +#ifdef CONFIG_ARCH_BCM2835
  46993. + if (!cmd->data && cmd->busy_timeout > 9000)
  46994. + timeout += DIV_ROUND_UP(cmd->busy_timeout, 1000) * HZ + HZ;
  46995. + else
  46996. +#endif
  46997. + timeout += 10 * HZ;
  46998. + mod_timer(&host->timer, timeout);
  46999. +
  47000. + host->cmd = cmd;
  47001. +
  47002. + bcm2835_mmc_prepare_data(host, cmd);
  47003. +
  47004. + bcm2835_mmc_writel(host, cmd->arg, SDHCI_ARGUMENT);
  47005. +
  47006. + bcm2835_mmc_set_transfer_mode(host, cmd);
  47007. +
  47008. + if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
  47009. + pr_err("%s: Unsupported response type!\n",
  47010. + mmc_hostname(host->mmc));
  47011. + cmd->error = -EINVAL;
  47012. + tasklet_schedule(&host->finish_tasklet);
  47013. + return;
  47014. + }
  47015. +
  47016. + if (!(cmd->flags & MMC_RSP_PRESENT))
  47017. + flags = SDHCI_CMD_RESP_NONE;
  47018. + else if (cmd->flags & MMC_RSP_136)
  47019. + flags = SDHCI_CMD_RESP_LONG;
  47020. + else if (cmd->flags & MMC_RSP_BUSY)
  47021. + flags = SDHCI_CMD_RESP_SHORT_BUSY;
  47022. + else
  47023. + flags = SDHCI_CMD_RESP_SHORT;
  47024. +
  47025. + if (cmd->flags & MMC_RSP_CRC)
  47026. + flags |= SDHCI_CMD_CRC;
  47027. + if (cmd->flags & MMC_RSP_OPCODE)
  47028. + flags |= SDHCI_CMD_INDEX;
  47029. +
  47030. + if (cmd->data)
  47031. + flags |= SDHCI_CMD_DATA;
  47032. +
  47033. + bcm2835_mmc_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND);
  47034. +}
  47035. +
  47036. +
  47037. +static void bcm2835_mmc_finish_data(struct bcm2835_host *host)
  47038. +{
  47039. + struct mmc_data *data;
  47040. +
  47041. + BUG_ON(!host->data);
  47042. +
  47043. + data = host->data;
  47044. + host->data = NULL;
  47045. +
  47046. + if (data->error)
  47047. + data->bytes_xfered = 0;
  47048. + else
  47049. + data->bytes_xfered = data->blksz * data->blocks;
  47050. +
  47051. + /*
  47052. + * Need to send CMD12 if -
  47053. + * a) open-ended multiblock transfer (no CMD23)
  47054. + * b) error in multiblock transfer
  47055. + */
  47056. + if (data->stop &&
  47057. + (data->error ||
  47058. + !host->mrq->sbc)) {
  47059. +
  47060. + /*
  47061. + * The controller needs a reset of internal state machines
  47062. + * upon error conditions.
  47063. + */
  47064. + if (data->error) {
  47065. + bcm2835_mmc_reset(host, SDHCI_RESET_CMD);
  47066. + bcm2835_mmc_reset(host, SDHCI_RESET_DATA);
  47067. + }
  47068. +
  47069. + bcm2835_mmc_send_command(host, data->stop);
  47070. + } else
  47071. + tasklet_schedule(&host->finish_tasklet);
  47072. +}
  47073. +
  47074. +static void bcm2835_mmc_finish_command(struct bcm2835_host *host)
  47075. +{
  47076. + int i;
  47077. +
  47078. + BUG_ON(host->cmd == NULL);
  47079. +
  47080. + if (host->cmd->flags & MMC_RSP_PRESENT) {
  47081. + if (host->cmd->flags & MMC_RSP_136) {
  47082. + /* CRC is stripped so we need to do some shifting. */
  47083. + for (i = 0; i < 4; i++) {
  47084. + host->cmd->resp[i] = bcm2835_mmc_readl(host,
  47085. + SDHCI_RESPONSE + (3-i)*4) << 8;
  47086. + if (i != 3)
  47087. + host->cmd->resp[i] |=
  47088. + bcm2835_mmc_readb(host,
  47089. + SDHCI_RESPONSE + (3-i)*4-1);
  47090. + }
  47091. + } else {
  47092. + host->cmd->resp[0] = bcm2835_mmc_readl(host, SDHCI_RESPONSE);
  47093. + }
  47094. + }
  47095. +
  47096. + host->cmd->error = 0;
  47097. +
  47098. + /* Finished CMD23, now send actual command. */
  47099. + if (host->cmd == host->mrq->sbc) {
  47100. + host->cmd = NULL;
  47101. + bcm2835_mmc_send_command(host, host->mrq->cmd);
  47102. +
  47103. + if (host->mrq->cmd->data && host->use_dma) {
  47104. + /* DMA transfer starts now, PIO starts after interrupt */
  47105. + bcm2835_mmc_transfer_dma(host);
  47106. + }
  47107. + } else {
  47108. +
  47109. + /* Processed actual command. */
  47110. + if (host->data && host->data_early)
  47111. + bcm2835_mmc_finish_data(host);
  47112. +
  47113. + if (!host->cmd->data)
  47114. + tasklet_schedule(&host->finish_tasklet);
  47115. +
  47116. + host->cmd = NULL;
  47117. + }
  47118. +}
  47119. +
  47120. +
  47121. +static void bcm2835_mmc_timeout_timer(unsigned long data)
  47122. +{
  47123. + struct bcm2835_host *host;
  47124. + unsigned long flags;
  47125. +
  47126. + host = (struct bcm2835_host *)data;
  47127. +
  47128. + spin_lock_irqsave(&host->lock, flags);
  47129. +
  47130. + if (host->mrq) {
  47131. + pr_err("%s: Timeout waiting for hardware interrupt.\n",
  47132. + mmc_hostname(host->mmc));
  47133. + bcm2835_mmc_dumpregs(host);
  47134. +
  47135. + if (host->data) {
  47136. + host->data->error = -ETIMEDOUT;
  47137. + bcm2835_mmc_finish_data(host);
  47138. + } else {
  47139. + if (host->cmd)
  47140. + host->cmd->error = -ETIMEDOUT;
  47141. + else
  47142. + host->mrq->cmd->error = -ETIMEDOUT;
  47143. +
  47144. + tasklet_schedule(&host->finish_tasklet);
  47145. + }
  47146. + }
  47147. +
  47148. + mmiowb();
  47149. + spin_unlock_irqrestore(&host->lock, flags);
  47150. +}
  47151. +
  47152. +
  47153. +static void bcm2835_mmc_enable_sdio_irq_nolock(struct bcm2835_host *host, int enable)
  47154. +{
  47155. + if (!(host->flags & SDHCI_DEVICE_DEAD)) {
  47156. + if (enable)
  47157. + host->ier |= SDHCI_INT_CARD_INT;
  47158. + else
  47159. + host->ier &= ~SDHCI_INT_CARD_INT;
  47160. +
  47161. + bcm2835_mmc_writel(host, host->ier, SDHCI_INT_ENABLE);
  47162. + bcm2835_mmc_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
  47163. + mmiowb();
  47164. + }
  47165. +}
  47166. +
  47167. +static void bcm2835_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
  47168. +{
  47169. + struct bcm2835_host *host = mmc_priv(mmc);
  47170. + unsigned long flags;
  47171. +
  47172. + spin_lock_irqsave(&host->lock, flags);
  47173. + if (enable)
  47174. + host->flags |= SDHCI_SDIO_IRQ_ENABLED;
  47175. + else
  47176. + host->flags &= ~SDHCI_SDIO_IRQ_ENABLED;
  47177. +
  47178. + bcm2835_mmc_enable_sdio_irq_nolock(host, enable);
  47179. + spin_unlock_irqrestore(&host->lock, flags);
  47180. +}
  47181. +
  47182. +static void bcm2835_mmc_cmd_irq(struct bcm2835_host *host, u32 intmask)
  47183. +{
  47184. +
  47185. + BUG_ON(intmask == 0);
  47186. +
  47187. + if (!host->cmd) {
  47188. + pr_err("%s: Got command interrupt 0x%08x even "
  47189. + "though no command operation was in progress.\n",
  47190. + mmc_hostname(host->mmc), (unsigned)intmask);
  47191. + bcm2835_mmc_dumpregs(host);
  47192. + return;
  47193. + }
  47194. +
  47195. + if (intmask & SDHCI_INT_TIMEOUT)
  47196. + host->cmd->error = -ETIMEDOUT;
  47197. + else if (intmask & (SDHCI_INT_CRC | SDHCI_INT_END_BIT |
  47198. + SDHCI_INT_INDEX)) {
  47199. + host->cmd->error = -EILSEQ;
  47200. + }
  47201. +
  47202. + if (host->cmd->error) {
  47203. + tasklet_schedule(&host->finish_tasklet);
  47204. + return;
  47205. + }
  47206. +
  47207. + if (intmask & SDHCI_INT_RESPONSE)
  47208. + bcm2835_mmc_finish_command(host);
  47209. +
  47210. +}
  47211. +
  47212. +static void bcm2835_mmc_data_irq(struct bcm2835_host *host, u32 intmask)
  47213. +{
  47214. + struct dma_chan *dma_chan;
  47215. + u32 dir_data;
  47216. +
  47217. + BUG_ON(intmask == 0);
  47218. +
  47219. + if (!host->data) {
  47220. + /*
  47221. + * The "data complete" interrupt is also used to
  47222. + * indicate that a busy state has ended. See comment
  47223. + * above in sdhci_cmd_irq().
  47224. + */
  47225. + if (host->cmd && (host->cmd->flags & MMC_RSP_BUSY)) {
  47226. + if (intmask & SDHCI_INT_DATA_END) {
  47227. + bcm2835_mmc_finish_command(host);
  47228. + return;
  47229. + }
  47230. + }
  47231. +
  47232. + pr_debug("%s: Got data interrupt 0x%08x even "
  47233. + "though no data operation was in progress.\n",
  47234. + mmc_hostname(host->mmc), (unsigned)intmask);
  47235. + bcm2835_mmc_dumpregs(host);
  47236. +
  47237. + return;
  47238. + }
  47239. +
  47240. + if (intmask & SDHCI_INT_DATA_TIMEOUT)
  47241. + host->data->error = -ETIMEDOUT;
  47242. + else if (intmask & SDHCI_INT_DATA_END_BIT)
  47243. + host->data->error = -EILSEQ;
  47244. + else if ((intmask & SDHCI_INT_DATA_CRC) &&
  47245. + SDHCI_GET_CMD(bcm2835_mmc_readw(host, SDHCI_COMMAND))
  47246. + != MMC_BUS_TEST_R)
  47247. + host->data->error = -EILSEQ;
  47248. +
  47249. + if (host->use_dma) {
  47250. + if (host->data->flags & MMC_DATA_WRITE) {
  47251. + /* IRQ handled here */
  47252. +
  47253. + dma_chan = host->dma_chan_tx;
  47254. + dir_data = DMA_TO_DEVICE;
  47255. + dma_unmap_sg(dma_chan->device->dev,
  47256. + host->data->sg, host->data->sg_len,
  47257. + dir_data);
  47258. +
  47259. + bcm2835_mmc_finish_data(host);
  47260. + }
  47261. +
  47262. + } else {
  47263. + if (host->data->error)
  47264. + bcm2835_mmc_finish_data(host);
  47265. + else {
  47266. + if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
  47267. + bcm2835_mmc_transfer_pio(host);
  47268. +
  47269. + if (intmask & SDHCI_INT_DATA_END) {
  47270. + if (host->cmd) {
  47271. + /*
  47272. + * Data managed to finish before the
  47273. + * command completed. Make sure we do
  47274. + * things in the proper order.
  47275. + */
  47276. + host->data_early = 1;
  47277. + } else {
  47278. + bcm2835_mmc_finish_data(host);
  47279. + }
  47280. + }
  47281. + }
  47282. + }
  47283. +}
  47284. +
  47285. +
  47286. +static irqreturn_t bcm2835_mmc_irq(int irq, void *dev_id)
  47287. +{
  47288. + irqreturn_t result = IRQ_NONE;
  47289. + struct bcm2835_host *host = dev_id;
  47290. + u32 intmask, mask, unexpected = 0;
  47291. + int max_loops = 16;
  47292. +#ifndef CONFIG_ARCH_BCM2835
  47293. + int cardint = 0;
  47294. +#endif
  47295. +
  47296. + spin_lock(&host->lock);
  47297. +
  47298. + intmask = bcm2835_mmc_readl(host, SDHCI_INT_STATUS);
  47299. +
  47300. + if (!intmask || intmask == 0xffffffff) {
  47301. + result = IRQ_NONE;
  47302. + goto out;
  47303. + }
  47304. +
  47305. + do {
  47306. + /* Clear selected interrupts. */
  47307. + mask = intmask & (SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK |
  47308. + SDHCI_INT_BUS_POWER);
  47309. + bcm2835_mmc_writel(host, mask, SDHCI_INT_STATUS);
  47310. +
  47311. +
  47312. + if (intmask & SDHCI_INT_CMD_MASK)
  47313. + bcm2835_mmc_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK);
  47314. +
  47315. + if (intmask & SDHCI_INT_DATA_MASK)
  47316. + bcm2835_mmc_data_irq(host, intmask & SDHCI_INT_DATA_MASK);
  47317. +
  47318. + if (intmask & SDHCI_INT_BUS_POWER)
  47319. + pr_err("%s: Card is consuming too much power!\n",
  47320. + mmc_hostname(host->mmc));
  47321. +
  47322. + if (intmask & SDHCI_INT_CARD_INT) {
  47323. +#ifndef CONFIG_ARCH_BCM2835
  47324. + cardint = 1;
  47325. +#else
  47326. + bcm2835_mmc_enable_sdio_irq_nolock(host, false);
  47327. + host->thread_isr |= SDHCI_INT_CARD_INT;
  47328. + result = IRQ_WAKE_THREAD;
  47329. +#endif
  47330. + }
  47331. +
  47332. + intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE |
  47333. + SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK |
  47334. + SDHCI_INT_ERROR | SDHCI_INT_BUS_POWER |
  47335. + SDHCI_INT_CARD_INT);
  47336. +
  47337. + if (intmask) {
  47338. + unexpected |= intmask;
  47339. + bcm2835_mmc_writel(host, intmask, SDHCI_INT_STATUS);
  47340. + }
  47341. +
  47342. + if (result == IRQ_NONE)
  47343. + result = IRQ_HANDLED;
  47344. +
  47345. + intmask = bcm2835_mmc_readl(host, SDHCI_INT_STATUS);
  47346. + } while (intmask && --max_loops);
  47347. +out:
  47348. + spin_unlock(&host->lock);
  47349. +
  47350. + if (unexpected) {
  47351. + pr_err("%s: Unexpected interrupt 0x%08x.\n",
  47352. + mmc_hostname(host->mmc), unexpected);
  47353. + bcm2835_mmc_dumpregs(host);
  47354. + }
  47355. +
  47356. +#ifndef CONFIG_ARCH_BCM2835
  47357. + if (cardint)
  47358. + mmc_signal_sdio_irq(host->mmc);
  47359. +#endif
  47360. +
  47361. + return result;
  47362. +}
  47363. +
  47364. +#ifdef CONFIG_ARCH_BCM2835
  47365. +static irqreturn_t bcm2835_mmc_thread_irq(int irq, void *dev_id)
  47366. +{
  47367. + struct bcm2835_host *host = dev_id;
  47368. + unsigned long flags;
  47369. + u32 isr;
  47370. +
  47371. + spin_lock_irqsave(&host->lock, flags);
  47372. + isr = host->thread_isr;
  47373. + host->thread_isr = 0;
  47374. + spin_unlock_irqrestore(&host->lock, flags);
  47375. +
  47376. + if (isr & SDHCI_INT_CARD_INT) {
  47377. + sdio_run_irqs(host->mmc);
  47378. +
  47379. + spin_lock_irqsave(&host->lock, flags);
  47380. + if (host->flags & SDHCI_SDIO_IRQ_ENABLED)
  47381. + bcm2835_mmc_enable_sdio_irq_nolock(host, true);
  47382. + spin_unlock_irqrestore(&host->lock, flags);
  47383. + }
  47384. +
  47385. + return isr ? IRQ_HANDLED : IRQ_NONE;
  47386. +}
  47387. +#endif
  47388. +
  47389. +
  47390. +
  47391. +void bcm2835_mmc_set_clock(struct bcm2835_host *host, unsigned int clock)
  47392. +{
  47393. + int div = 0; /* Initialized for compiler warning */
  47394. + int real_div = div, clk_mul = 1;
  47395. + u16 clk = 0;
  47396. + unsigned long timeout;
  47397. +
  47398. +
  47399. + host->mmc->actual_clock = 0;
  47400. +
  47401. + bcm2835_mmc_writew(host, 0, SDHCI_CLOCK_CONTROL);
  47402. +
  47403. + if (clock == 0)
  47404. + return;
  47405. +
  47406. + /* Version 3.00 divisors must be a multiple of 2. */
  47407. + if (host->max_clk <= clock)
  47408. + div = 1;
  47409. + else {
  47410. + for (div = 2; div < SDHCI_MAX_DIV_SPEC_300;
  47411. + div += 2) {
  47412. + if ((host->max_clk / div) <= clock)
  47413. + break;
  47414. + }
  47415. + }
  47416. +
  47417. + real_div = div;
  47418. + div >>= 1;
  47419. +
  47420. + if (real_div)
  47421. + host->mmc->actual_clock = (host->max_clk * clk_mul) / real_div;
  47422. +
  47423. + clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT;
  47424. + clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIV_MASK_LEN)
  47425. + << SDHCI_DIVIDER_HI_SHIFT;
  47426. + clk |= SDHCI_CLOCK_INT_EN;
  47427. + bcm2835_mmc_writew(host, clk, SDHCI_CLOCK_CONTROL);
  47428. +
  47429. + /* Wait max 20 ms */
  47430. + timeout = 20;
  47431. + while (!((clk = bcm2835_mmc_readw(host, SDHCI_CLOCK_CONTROL))
  47432. + & SDHCI_CLOCK_INT_STABLE)) {
  47433. + if (timeout == 0) {
  47434. + pr_err("%s: Internal clock never "
  47435. + "stabilised.\n", mmc_hostname(host->mmc));
  47436. + bcm2835_mmc_dumpregs(host);
  47437. + return;
  47438. + }
  47439. + timeout--;
  47440. + mdelay(1);
  47441. + }
  47442. +
  47443. + if (20-timeout > 10 && 20-timeout > host->max_delay) {
  47444. + host->max_delay = 20-timeout;
  47445. + pr_warning("Warning: MMC controller hung for %d ms\n", host->max_delay);
  47446. + }
  47447. +
  47448. + clk |= SDHCI_CLOCK_CARD_EN;
  47449. + bcm2835_mmc_writew(host, clk, SDHCI_CLOCK_CONTROL);
  47450. +}
  47451. +
  47452. +static void bcm2835_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
  47453. +{
  47454. + struct bcm2835_host *host;
  47455. + unsigned long flags;
  47456. +
  47457. + host = mmc_priv(mmc);
  47458. +
  47459. + spin_lock_irqsave(&host->lock, flags);
  47460. +
  47461. + WARN_ON(host->mrq != NULL);
  47462. +
  47463. + host->mrq = mrq;
  47464. +
  47465. + if (mrq->sbc && !(host->flags & SDHCI_AUTO_CMD23))
  47466. + bcm2835_mmc_send_command(host, mrq->sbc);
  47467. + else
  47468. + bcm2835_mmc_send_command(host, mrq->cmd);
  47469. +
  47470. + mmiowb();
  47471. + spin_unlock_irqrestore(&host->lock, flags);
  47472. +
  47473. + if (!(mrq->sbc && !(host->flags & SDHCI_AUTO_CMD23)) && mrq->cmd->data && host->use_dma) {
  47474. + /* DMA transfer starts now, PIO starts after interrupt */
  47475. + bcm2835_mmc_transfer_dma(host);
  47476. + }
  47477. +}
  47478. +
  47479. +
  47480. +static void bcm2835_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  47481. +{
  47482. +
  47483. + struct bcm2835_host *host = mmc_priv(mmc);
  47484. + unsigned long flags;
  47485. + u8 ctrl;
  47486. + u16 clk, ctrl_2;
  47487. +
  47488. +
  47489. + spin_lock_irqsave(&host->lock, flags);
  47490. +
  47491. + if (!ios->clock || ios->clock != host->clock) {
  47492. + bcm2835_mmc_set_clock(host, ios->clock);
  47493. + host->clock = ios->clock;
  47494. + }
  47495. +
  47496. + if (host->pwr != SDHCI_POWER_330) {
  47497. + host->pwr = SDHCI_POWER_330;
  47498. + bcm2835_mmc_writeb(host, SDHCI_POWER_330 | SDHCI_POWER_ON, SDHCI_POWER_CONTROL);
  47499. + }
  47500. +
  47501. + ctrl = bcm2835_mmc_readb(host, SDHCI_HOST_CONTROL);
  47502. +
  47503. + /* set bus width */
  47504. + ctrl &= ~SDHCI_CTRL_8BITBUS;
  47505. + if (ios->bus_width == MMC_BUS_WIDTH_4)
  47506. + ctrl |= SDHCI_CTRL_4BITBUS;
  47507. + else
  47508. + ctrl &= ~SDHCI_CTRL_4BITBUS;
  47509. +
  47510. + ctrl &= ~SDHCI_CTRL_HISPD; /* NO_HISPD_BIT */
  47511. +
  47512. +
  47513. + bcm2835_mmc_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  47514. + /*
  47515. + * We only need to set Driver Strength if the
  47516. + * preset value enable is not set.
  47517. + */
  47518. + ctrl_2 = bcm2835_mmc_readw(host, SDHCI_HOST_CONTROL2);
  47519. + ctrl_2 &= ~SDHCI_CTRL_DRV_TYPE_MASK;
  47520. + if (ios->drv_type == MMC_SET_DRIVER_TYPE_A)
  47521. + ctrl_2 |= SDHCI_CTRL_DRV_TYPE_A;
  47522. + else if (ios->drv_type == MMC_SET_DRIVER_TYPE_C)
  47523. + ctrl_2 |= SDHCI_CTRL_DRV_TYPE_C;
  47524. +
  47525. + bcm2835_mmc_writew(host, ctrl_2, SDHCI_HOST_CONTROL2);
  47526. +
  47527. + /* Reset SD Clock Enable */
  47528. + clk = bcm2835_mmc_readw(host, SDHCI_CLOCK_CONTROL);
  47529. + clk &= ~SDHCI_CLOCK_CARD_EN;
  47530. + bcm2835_mmc_writew(host, clk, SDHCI_CLOCK_CONTROL);
  47531. +
  47532. + /* Re-enable SD Clock */
  47533. + bcm2835_mmc_set_clock(host, host->clock);
  47534. + bcm2835_mmc_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  47535. +
  47536. + mmiowb();
  47537. +
  47538. + spin_unlock_irqrestore(&host->lock, flags);
  47539. +}
  47540. +
  47541. +
  47542. +static struct mmc_host_ops bcm2835_ops = {
  47543. + .request = bcm2835_mmc_request,
  47544. + .set_ios = bcm2835_mmc_set_ios,
  47545. + .enable_sdio_irq = bcm2835_mmc_enable_sdio_irq,
  47546. +};
  47547. +
  47548. +
  47549. +static void bcm2835_mmc_tasklet_finish(unsigned long param)
  47550. +{
  47551. + struct bcm2835_host *host;
  47552. + unsigned long flags;
  47553. + struct mmc_request *mrq;
  47554. +
  47555. + host = (struct bcm2835_host *)param;
  47556. +
  47557. + spin_lock_irqsave(&host->lock, flags);
  47558. +
  47559. + /*
  47560. + * If this tasklet gets rescheduled while running, it will
  47561. + * be run again afterwards but without any active request.
  47562. + */
  47563. + if (!host->mrq) {
  47564. + spin_unlock_irqrestore(&host->lock, flags);
  47565. + return;
  47566. + }
  47567. +
  47568. + del_timer(&host->timer);
  47569. +
  47570. + mrq = host->mrq;
  47571. +
  47572. + /*
  47573. + * The controller needs a reset of internal state machines
  47574. + * upon error conditions.
  47575. + */
  47576. + if (!(host->flags & SDHCI_DEVICE_DEAD) &&
  47577. + ((mrq->cmd && mrq->cmd->error) ||
  47578. + (mrq->data && (mrq->data->error ||
  47579. + (mrq->data->stop && mrq->data->stop->error))))) {
  47580. +
  47581. + bcm2835_mmc_reset(host, SDHCI_RESET_CMD);
  47582. + bcm2835_mmc_reset(host, SDHCI_RESET_DATA);
  47583. + }
  47584. +
  47585. + host->mrq = NULL;
  47586. + host->cmd = NULL;
  47587. + host->data = NULL;
  47588. +
  47589. + mmiowb();
  47590. +
  47591. + spin_unlock_irqrestore(&host->lock, flags);
  47592. + mmc_request_done(host->mmc, mrq);
  47593. +}
  47594. +
  47595. +
  47596. +
  47597. +int bcm2835_mmc_add_host(struct bcm2835_host *host)
  47598. +{
  47599. + struct mmc_host *mmc;
  47600. +#ifndef FORCE_PIO
  47601. + struct dma_slave_config cfg;
  47602. +#endif
  47603. + int ret;
  47604. +
  47605. + mmc = host->mmc;
  47606. +
  47607. + bcm2835_mmc_reset(host, SDHCI_RESET_ALL);
  47608. +
  47609. + host->clk_mul = 0;
  47610. +
  47611. + mmc->ops = &bcm2835_ops;
  47612. + mmc->f_max = host->max_clk;
  47613. + mmc->f_max = host->max_clk;
  47614. + mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300;
  47615. +
  47616. + /* SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK */
  47617. + host->timeout_clk = mmc->f_max / 1000;
  47618. +#ifdef CONFIG_ARCH_BCM2835
  47619. + mmc->max_busy_timeout = (1 << 27) / host->timeout_clk;
  47620. +#endif
  47621. + /* host controller capabilities */
  47622. + mmc->caps = MMC_CAP_CMD23 | MMC_CAP_ERASE | MMC_CAP_NEEDS_POLL | MMC_CAP_SDIO_IRQ |
  47623. + MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_4_BIT_DATA;
  47624. +
  47625. + host->flags = SDHCI_AUTO_CMD23;
  47626. +
  47627. + spin_lock_init(&host->lock);
  47628. +
  47629. +
  47630. +#ifdef FORCE_PIO
  47631. + pr_info("Forcing PIO mode\n");
  47632. + host->have_dma = false;
  47633. +#else
  47634. + if (!host->dma_chan_tx || !host->dma_chan_rx ||
  47635. + IS_ERR(host->dma_chan_tx) || IS_ERR(host->dma_chan_rx)) {
  47636. + pr_err("%s: Unable to initialise DMA channels. Falling back to PIO\n", DRIVER_NAME);
  47637. + host->have_dma = false;
  47638. + } else {
  47639. + pr_info("DMA channels allocated for the MMC driver");
  47640. + host->have_dma = true;
  47641. +
  47642. + cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  47643. + cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  47644. + cfg.slave_id = 11; /* DREQ channel */
  47645. +
  47646. + cfg.direction = DMA_MEM_TO_DEV;
  47647. + cfg.src_addr = 0;
  47648. + cfg.dst_addr = host->phys_addr + SDHCI_BUFFER;
  47649. + ret = dmaengine_slave_config(host->dma_chan_tx, &cfg);
  47650. +
  47651. + cfg.direction = DMA_DEV_TO_MEM;
  47652. + cfg.src_addr = host->phys_addr + SDHCI_BUFFER;
  47653. + cfg.dst_addr = 0;
  47654. + ret = dmaengine_slave_config(host->dma_chan_rx, &cfg);
  47655. + }
  47656. +#endif
  47657. +
  47658. +
  47659. + mmc->max_segs = 128;
  47660. + mmc->max_req_size = 524288;
  47661. + mmc->max_seg_size = mmc->max_req_size;
  47662. + mmc->max_blk_size = 512;
  47663. + mmc->max_blk_count = 65535;
  47664. +
  47665. + /* report supported voltage ranges */
  47666. + mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
  47667. +
  47668. + tasklet_init(&host->finish_tasklet,
  47669. + bcm2835_mmc_tasklet_finish, (unsigned long)host);
  47670. +
  47671. + setup_timer(&host->timer, bcm2835_mmc_timeout_timer, (unsigned long)host);
  47672. + init_waitqueue_head(&host->buf_ready_int);
  47673. +
  47674. + bcm2835_mmc_init(host, 0);
  47675. +#ifndef CONFIG_ARCH_BCM2835
  47676. + ret = request_irq(host->irq, bcm2835_mmc_irq, 0 /*IRQF_SHARED*/,
  47677. + mmc_hostname(mmc), host);
  47678. +#else
  47679. + ret = request_threaded_irq(host->irq, bcm2835_mmc_irq, bcm2835_mmc_thread_irq,
  47680. + IRQF_SHARED, mmc_hostname(mmc), host);
  47681. +#endif
  47682. + if (ret) {
  47683. + pr_err("%s: Failed to request IRQ %d: %d\n",
  47684. + mmc_hostname(mmc), host->irq, ret);
  47685. + goto untasklet;
  47686. + }
  47687. +
  47688. + mmiowb();
  47689. + mmc_add_host(mmc);
  47690. +
  47691. + pr_info("Load BCM2835 MMC driver\n");
  47692. +
  47693. + return 0;
  47694. +
  47695. +untasklet:
  47696. + tasklet_kill(&host->finish_tasklet);
  47697. +
  47698. + return ret;
  47699. +}
  47700. +
  47701. +static int bcm2835_mmc_probe(struct platform_device *pdev)
  47702. +{
  47703. + struct device *dev = &pdev->dev;
  47704. +#ifdef CONFIG_ARCH_BCM2835
  47705. + struct device_node *node = dev->of_node;
  47706. + struct clk *clk;
  47707. +#endif
  47708. + struct resource *iomem;
  47709. + struct bcm2835_host *host = NULL;
  47710. +
  47711. + int ret;
  47712. + struct mmc_host *mmc;
  47713. +#if !defined(CONFIG_ARCH_BCM2835) && !defined(FORCE_PIO)
  47714. + dma_cap_mask_t mask;
  47715. +#endif
  47716. +
  47717. + iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  47718. + if (!iomem) {
  47719. + ret = -ENOMEM;
  47720. + goto err;
  47721. + }
  47722. +
  47723. + if (resource_size(iomem) < 0x100)
  47724. + dev_err(&pdev->dev, "Invalid iomem size!\n");
  47725. +
  47726. + mmc = mmc_alloc_host(sizeof(struct bcm2835_host), dev);
  47727. + host = mmc_priv(mmc);
  47728. + host->mmc = mmc;
  47729. +
  47730. +
  47731. + if (IS_ERR(host)) {
  47732. + ret = PTR_ERR(host);
  47733. + goto err;
  47734. + }
  47735. +
  47736. + host->phys_addr = iomem->start + BCM2835_VCMMU_SHIFT;
  47737. +
  47738. +#ifndef CONFIG_ARCH_BCM2835
  47739. +#ifndef FORCE_PIO
  47740. + dma_cap_zero(mask);
  47741. + /* we don't care about the channel, any would work */
  47742. + dma_cap_set(DMA_SLAVE, mask);
  47743. +
  47744. + host->dma_chan_tx = dma_request_channel(mask, NULL, NULL);
  47745. + host->dma_chan_rx = dma_request_channel(mask, NULL, NULL);
  47746. +#endif
  47747. + host->max_clk = BCM2835_CLOCK_FREQ;
  47748. +
  47749. +#else
  47750. +#ifndef FORCE_PIO
  47751. + host->dma_chan_tx = of_dma_request_slave_channel(node, "tx");
  47752. + host->dma_chan_rx = of_dma_request_slave_channel(node, "rx");
  47753. +#endif
  47754. + clk = of_clk_get(node, 0);
  47755. + if (IS_ERR(clk)) {
  47756. + dev_err(dev, "get CLOCK failed\n");
  47757. + ret = PTR_ERR(clk);
  47758. + goto out;
  47759. + }
  47760. + host->max_clk = (clk_get_rate(clk));
  47761. +#endif
  47762. + host->irq = platform_get_irq(pdev, 0);
  47763. +
  47764. + if (!request_mem_region(iomem->start, resource_size(iomem),
  47765. + mmc_hostname(host->mmc))) {
  47766. + dev_err(&pdev->dev, "cannot request region\n");
  47767. + ret = -EBUSY;
  47768. + goto err_request;
  47769. + }
  47770. +
  47771. + host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  47772. + if (!host->ioaddr) {
  47773. + dev_err(&pdev->dev, "failed to remap registers\n");
  47774. + ret = -ENOMEM;
  47775. + goto err_remap;
  47776. + }
  47777. +
  47778. + platform_set_drvdata(pdev, host);
  47779. +
  47780. +
  47781. + if (host->irq <= 0) {
  47782. + dev_err(dev, "get IRQ failed\n");
  47783. + ret = -EINVAL;
  47784. + goto out;
  47785. + }
  47786. +
  47787. +
  47788. +#ifndef CONFIG_ARCH_BCM2835
  47789. + mmc->caps |= MMC_CAP_4_BIT_DATA;
  47790. +#else
  47791. + mmc_of_parse(mmc);
  47792. +#endif
  47793. + host->timeout = msecs_to_jiffies(1000);
  47794. + spin_lock_init(&host->lock);
  47795. + mmc->ops = &bcm2835_ops;
  47796. + return bcm2835_mmc_add_host(host);
  47797. +
  47798. +
  47799. +err_remap:
  47800. + release_mem_region(iomem->start, resource_size(iomem));
  47801. +err_request:
  47802. + mmc_free_host(host->mmc);
  47803. +err:
  47804. + dev_err(&pdev->dev, "%s failed %d\n", __func__, ret);
  47805. + return ret;
  47806. +out:
  47807. + if (mmc)
  47808. + mmc_free_host(mmc);
  47809. + return ret;
  47810. +}
  47811. +
  47812. +static int bcm2835_mmc_remove(struct platform_device *pdev)
  47813. +{
  47814. + struct bcm2835_host *host = platform_get_drvdata(pdev);
  47815. + struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  47816. + unsigned long flags;
  47817. + int dead;
  47818. + u32 scratch;
  47819. +
  47820. + dead = 0;
  47821. + scratch = bcm2835_mmc_readl(host, SDHCI_INT_STATUS);
  47822. + if (scratch == (u32)-1)
  47823. + dead = 1;
  47824. +
  47825. +
  47826. + if (dead) {
  47827. + spin_lock_irqsave(&host->lock, flags);
  47828. +
  47829. + host->flags |= SDHCI_DEVICE_DEAD;
  47830. +
  47831. + if (host->mrq) {
  47832. + pr_err("%s: Controller removed during "
  47833. + " transfer!\n", mmc_hostname(host->mmc));
  47834. +
  47835. + host->mrq->cmd->error = -ENOMEDIUM;
  47836. + tasklet_schedule(&host->finish_tasklet);
  47837. + }
  47838. +
  47839. + spin_unlock_irqrestore(&host->lock, flags);
  47840. + }
  47841. +
  47842. + mmc_remove_host(host->mmc);
  47843. +
  47844. + if (!dead)
  47845. + bcm2835_mmc_reset(host, SDHCI_RESET_ALL);
  47846. +
  47847. + free_irq(host->irq, host);
  47848. +
  47849. + del_timer_sync(&host->timer);
  47850. +
  47851. + tasklet_kill(&host->finish_tasklet);
  47852. +
  47853. + iounmap(host->ioaddr);
  47854. + release_mem_region(iomem->start, resource_size(iomem));
  47855. + mmc_free_host(host->mmc);
  47856. + platform_set_drvdata(pdev, NULL);
  47857. +
  47858. + return 0;
  47859. +}
  47860. +
  47861. +
  47862. +static const struct of_device_id bcm2835_mmc_match[] = {
  47863. + { .compatible = "brcm,bcm2835-mmc" },
  47864. + { }
  47865. +};
  47866. +MODULE_DEVICE_TABLE(of, bcm2835_mmc_match);
  47867. +
  47868. +
  47869. +
  47870. +static struct platform_driver bcm2835_mmc_driver = {
  47871. + .probe = bcm2835_mmc_probe,
  47872. + .remove = bcm2835_mmc_remove,
  47873. + .driver = {
  47874. + .name = DRIVER_NAME,
  47875. + .owner = THIS_MODULE,
  47876. + .of_match_table = bcm2835_mmc_match,
  47877. + },
  47878. +};
  47879. +module_platform_driver(bcm2835_mmc_driver);
  47880. +
  47881. +MODULE_ALIAS("platform:mmc-bcm2835");
  47882. +MODULE_DESCRIPTION("BCM2835 SDHCI driver");
  47883. +MODULE_LICENSE("GPL v2");
  47884. +MODULE_AUTHOR("Gellert Weisz");
  47885. diff -Nur linux-3.18.6/drivers/mmc/host/Kconfig linux-rpi/drivers/mmc/host/Kconfig
  47886. --- linux-3.18.6/drivers/mmc/host/Kconfig 2015-02-06 15:53:48.000000000 +0100
  47887. +++ linux-rpi/drivers/mmc/host/Kconfig 2015-02-09 04:40:08.000000000 +0100
  47888. @@ -281,17 +281,6 @@
  47889. If you have a controller with this interface, say Y or M here.
  47890. -config MMC_SDHCI_BCM2835
  47891. - tristate "SDHCI platform support for the BCM2835 SD/MMC Controller"
  47892. - depends on ARCH_BCM2835
  47893. - depends on MMC_SDHCI_PLTFM
  47894. - select MMC_SDHCI_IO_ACCESSORS
  47895. - help
  47896. - This selects the BCM2835 SD/MMC controller. If you have a BCM2835
  47897. - platform with SD or MMC devices, say Y or M here.
  47898. -
  47899. - If unsure, say N.
  47900. -
  47901. config MMC_MOXART
  47902. tristate "MOXART SD/MMC Host Controller support"
  47903. depends on ARCH_MOXART && MMC
  47904. @@ -313,6 +302,35 @@
  47905. If you have a controller with this interface, say Y or M here.
  47906. If unsure, say N.
  47907. +config MMC_BCM2835
  47908. + tristate "MMC support on BCM2835"
  47909. + depends on (MACH_BCM2708 || MACH_BCM2709)
  47910. + help
  47911. + This selects the MMC Interface on BCM2835.
  47912. +
  47913. + If you have a controller with this interface, say Y or M here.
  47914. +
  47915. + If unsure, say N.
  47916. +
  47917. +config MMC_BCM2835_DMA
  47918. + bool "DMA support on BCM2835 Arasan controller"
  47919. + depends on MMC_BCM2835
  47920. + help
  47921. + Enable DMA support on the Arasan SDHCI controller in Broadcom 2708
  47922. + based chips.
  47923. +
  47924. + If unsure, say N.
  47925. +
  47926. +config MMC_BCM2835_PIO_DMA_BARRIER
  47927. + int "Block count limit for PIO transfers"
  47928. + depends on MMC_BCM2835 && MMC_BCM2835_DMA
  47929. + range 0 256
  47930. + default 2
  47931. + help
  47932. + The inclusive limit in bytes under which PIO will be used instead of DMA
  47933. +
  47934. + If unsure, say 2 here.
  47935. +
  47936. config MMC_OMAP
  47937. tristate "TI OMAP Multimedia Card Interface support"
  47938. depends on ARCH_OMAP
  47939. diff -Nur linux-3.18.6/drivers/mmc/host/Makefile linux-rpi/drivers/mmc/host/Makefile
  47940. --- linux-3.18.6/drivers/mmc/host/Makefile 2015-02-06 15:53:48.000000000 +0100
  47941. +++ linux-rpi/drivers/mmc/host/Makefile 2015-02-09 04:40:08.000000000 +0100
  47942. @@ -17,6 +17,7 @@
  47943. obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
  47944. obj-$(CONFIG_MMC_SDHCI_SIRF) += sdhci-sirf.o
  47945. obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
  47946. +obj-$(CONFIG_MMC_BCM2835) += bcm2835-mmc.o
  47947. obj-$(CONFIG_MMC_WBSD) += wbsd.o
  47948. obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
  47949. obj-$(CONFIG_MMC_OMAP) += omap.o
  47950. diff -Nur linux-3.18.6/drivers/net/usb/smsc95xx.c linux-rpi/drivers/net/usb/smsc95xx.c
  47951. --- linux-3.18.6/drivers/net/usb/smsc95xx.c 2015-02-06 15:53:48.000000000 +0100
  47952. +++ linux-rpi/drivers/net/usb/smsc95xx.c 2015-02-09 04:40:14.000000000 +0100
  47953. @@ -59,6 +59,7 @@
  47954. #define SUSPEND_SUSPEND3 (0x08)
  47955. #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
  47956. SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
  47957. +#define MAC_ADDR_LEN (6)
  47958. struct smsc95xx_priv {
  47959. u32 mac_cr;
  47960. @@ -74,6 +75,10 @@
  47961. module_param(turbo_mode, bool, 0644);
  47962. MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
  47963. +static char *macaddr = ":";
  47964. +module_param(macaddr, charp, 0);
  47965. +MODULE_PARM_DESC(macaddr, "MAC address");
  47966. +
  47967. static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
  47968. u32 *data, int in_pm)
  47969. {
  47970. @@ -763,8 +768,59 @@
  47971. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  47972. }
  47973. +/* Check the macaddr module parameter for a MAC address */
  47974. +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
  47975. +{
  47976. + int i, j, got_num, num;
  47977. + u8 mtbl[MAC_ADDR_LEN];
  47978. +
  47979. + if (macaddr[0] == ':')
  47980. + return 0;
  47981. +
  47982. + i = 0;
  47983. + j = 0;
  47984. + num = 0;
  47985. + got_num = 0;
  47986. + while (j < MAC_ADDR_LEN) {
  47987. + if (macaddr[i] && macaddr[i] != ':') {
  47988. + got_num++;
  47989. + if ('0' <= macaddr[i] && macaddr[i] <= '9')
  47990. + num = num * 16 + macaddr[i] - '0';
  47991. + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
  47992. + num = num * 16 + 10 + macaddr[i] - 'A';
  47993. + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
  47994. + num = num * 16 + 10 + macaddr[i] - 'a';
  47995. + else
  47996. + break;
  47997. + i++;
  47998. + } else if (got_num == 2) {
  47999. + mtbl[j++] = (u8) num;
  48000. + num = 0;
  48001. + got_num = 0;
  48002. + i++;
  48003. + } else {
  48004. + break;
  48005. + }
  48006. + }
  48007. +
  48008. + if (j == MAC_ADDR_LEN) {
  48009. + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
  48010. + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
  48011. + mtbl[3], mtbl[4], mtbl[5]);
  48012. + for (i = 0; i < MAC_ADDR_LEN; i++)
  48013. + dev_mac[i] = mtbl[i];
  48014. + return 1;
  48015. + } else {
  48016. + return 0;
  48017. + }
  48018. +}
  48019. +
  48020. static void smsc95xx_init_mac_address(struct usbnet *dev)
  48021. {
  48022. + /* Check module parameters */
  48023. + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
  48024. + return;
  48025. +
  48026. /* try reading mac address from EEPROM */
  48027. if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  48028. dev->net->dev_addr) == 0) {
  48029. diff -Nur linux-3.18.6/drivers/of/fdt.c linux-rpi/drivers/of/fdt.c
  48030. --- linux-3.18.6/drivers/of/fdt.c 2015-02-06 15:53:48.000000000 +0100
  48031. +++ linux-rpi/drivers/of/fdt.c 2015-02-09 04:40:15.000000000 +0100
  48032. @@ -901,19 +901,38 @@
  48033. /* Retrieve command line */
  48034. p = of_get_flat_dt_prop(node, "bootargs", &l);
  48035. - if (p != NULL && l > 0)
  48036. - strlcpy(data, p, min((int)l, COMMAND_LINE_SIZE));
  48037. /*
  48038. * CONFIG_CMDLINE is meant to be a default in case nothing else
  48039. * managed to set the command line, unless CONFIG_CMDLINE_FORCE
  48040. * is set in which case we override whatever was found earlier.
  48041. + *
  48042. + * However, it can be useful to be able to treat the default as
  48043. + * a starting point to be extended using CONFIG_CMDLINE_EXTEND.
  48044. */
  48045. + ((char *)data)[0] = '\0';
  48046. +
  48047. #ifdef CONFIG_CMDLINE
  48048. -#ifndef CONFIG_CMDLINE_FORCE
  48049. - if (!((char *)data)[0])
  48050. + strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
  48051. +
  48052. + if (p != NULL && l > 0) {
  48053. +#if defined(CONFIG_CMDLINE_EXTEND)
  48054. + int len = strlen(data);
  48055. + if (len > 0) {
  48056. + strlcat(data, " ", COMMAND_LINE_SIZE);
  48057. + len++;
  48058. + }
  48059. + strlcpy((char *)data + len, p, min((int)l, COMMAND_LINE_SIZE - len));
  48060. +#elif defined(CONFIG_CMDLINE_FORCE)
  48061. + pr_warning("Ignoring bootargs property (using the default kernel command line)\n");
  48062. +#else
  48063. + /* Neither extend nor force - just override */
  48064. + strlcpy(data, p, min((int)l, COMMAND_LINE_SIZE));
  48065. #endif
  48066. - strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
  48067. + }
  48068. +#else /* CONFIG_CMDLINE */
  48069. + if (p != NULL && l > 0) {
  48070. + strlcpy(data, p, min((int)l, COMMAND_LINE_SIZE));
  48071. #endif /* CONFIG_CMDLINE */
  48072. pr_debug("Command line is: %s\n", (char*)data);
  48073. @@ -1083,8 +1102,12 @@
  48074. static int __init of_flat_dt_debugfs_export_fdt(void)
  48075. {
  48076. - struct dentry *d = debugfs_create_dir("device-tree", NULL);
  48077. + struct dentry *d;
  48078. +
  48079. + if (!initial_boot_params)
  48080. + return -ENOENT;
  48081. + d = debugfs_create_dir("device-tree", NULL);
  48082. if (!d)
  48083. return -ENOENT;
  48084. diff -Nur linux-3.18.6/drivers/pinctrl/pinctrl-bcm2835.c linux-rpi/drivers/pinctrl/pinctrl-bcm2835.c
  48085. --- linux-3.18.6/drivers/pinctrl/pinctrl-bcm2835.c 2015-02-06 15:53:48.000000000 +0100
  48086. +++ linux-rpi/drivers/pinctrl/pinctrl-bcm2835.c 2015-02-09 04:40:16.000000000 +0100
  48087. @@ -355,7 +355,14 @@
  48088. static int bcm2835_gpio_direction_output(struct gpio_chip *chip,
  48089. unsigned offset, int value)
  48090. {
  48091. - return pinctrl_gpio_direction_output(chip->base + offset);
  48092. + struct bcm2835_pinctrl *pc = dev_get_drvdata(chip->dev);
  48093. + int ret;
  48094. +
  48095. + ret = pinctrl_gpio_direction_output(chip->base + offset);
  48096. + if (ret >= 0)
  48097. + bcm2835_gpio_set_bit(pc, value ? GPSET0 : GPCLR0, offset);
  48098. +
  48099. + return ret;
  48100. }
  48101. static void bcm2835_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  48102. @@ -382,7 +389,7 @@
  48103. .get = bcm2835_gpio_get,
  48104. .set = bcm2835_gpio_set,
  48105. .to_irq = bcm2835_gpio_to_irq,
  48106. - .base = -1,
  48107. + .base = 0,
  48108. .ngpio = BCM2835_NUM_GPIOS,
  48109. .can_sleep = false,
  48110. };
  48111. diff -Nur linux-3.18.6/drivers/rtc/rtc-ds1307.c linux-rpi/drivers/rtc/rtc-ds1307.c
  48112. --- linux-3.18.6/drivers/rtc/rtc-ds1307.c 2015-02-06 15:53:48.000000000 +0100
  48113. +++ linux-rpi/drivers/rtc/rtc-ds1307.c 2015-02-09 04:40:16.000000000 +0100
  48114. @@ -1241,6 +1241,14 @@
  48115. return 0;
  48116. }
  48117. +#ifdef CONFIG_OF
  48118. +static const struct of_device_id ds1307_of_match[] = {
  48119. + { .compatible = "maxim,ds1307" },
  48120. + { }
  48121. +};
  48122. +MODULE_DEVICE_TABLE(of, ds1307_of_match);
  48123. +#endif
  48124. +
  48125. static struct i2c_driver ds1307_driver = {
  48126. .driver = {
  48127. .name = "rtc-ds1307",
  48128. diff -Nur linux-3.18.6/drivers/spi/Kconfig linux-rpi/drivers/spi/Kconfig
  48129. --- linux-3.18.6/drivers/spi/Kconfig 2015-02-06 15:53:48.000000000 +0100
  48130. +++ linux-rpi/drivers/spi/Kconfig 2015-02-09 04:40:23.000000000 +0100
  48131. @@ -77,7 +77,7 @@
  48132. config SPI_BCM2835
  48133. tristate "BCM2835 SPI controller"
  48134. - depends on ARCH_BCM2835 || COMPILE_TEST
  48135. + depends on ARCH_BCM2835 || ARCH_BCM2708 || ARCH_BCM2709 || COMPILE_TEST
  48136. help
  48137. This selects a driver for the Broadcom BCM2835 SPI master.
  48138. @@ -86,6 +86,14 @@
  48139. is for the regular SPI controller. Slave mode operation is not also
  48140. not supported.
  48141. +config SPI_BCM2708
  48142. + tristate "BCM2708 SPI controller driver (SPI0)"
  48143. + depends on MACH_BCM2708 || MACH_BCM2709
  48144. + help
  48145. + This selects a driver for the Broadcom BCM2708 SPI master (SPI0). This
  48146. + driver is not compatible with the "Universal SPI Master" or the SPI slave
  48147. + device.
  48148. +
  48149. config SPI_BFIN5XX
  48150. tristate "SPI controller driver for ADI Blackfin5xx"
  48151. depends on BLACKFIN && !BF60x
  48152. diff -Nur linux-3.18.6/drivers/spi/Makefile linux-rpi/drivers/spi/Makefile
  48153. --- linux-3.18.6/drivers/spi/Makefile 2015-02-06 15:53:48.000000000 +0100
  48154. +++ linux-rpi/drivers/spi/Makefile 2015-02-09 04:40:23.000000000 +0100
  48155. @@ -20,6 +20,7 @@
  48156. obj-$(CONFIG_SPI_BCM63XX_HSSPI) += spi-bcm63xx-hsspi.o
  48157. obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
  48158. obj-$(CONFIG_SPI_ADI_V3) += spi-adi-v3.o
  48159. +obj-$(CONFIG_SPI_BCM2708) += spi-bcm2708.o
  48160. obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o
  48161. obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o
  48162. obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o
  48163. diff -Nur linux-3.18.6/drivers/spi/spi-bcm2708.c linux-rpi/drivers/spi/spi-bcm2708.c
  48164. --- linux-3.18.6/drivers/spi/spi-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  48165. +++ linux-rpi/drivers/spi/spi-bcm2708.c 2015-02-09 04:40:23.000000000 +0100
  48166. @@ -0,0 +1,635 @@
  48167. +/*
  48168. + * Driver for Broadcom BCM2708 SPI Controllers
  48169. + *
  48170. + * Copyright (C) 2012 Chris Boot
  48171. + *
  48172. + * This driver is inspired by:
  48173. + * spi-ath79.c, Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
  48174. + * spi-atmel.c, Copyright (C) 2006 Atmel Corporation
  48175. + *
  48176. + * This program is free software; you can redistribute it and/or modify
  48177. + * it under the terms of the GNU General Public License as published by
  48178. + * the Free Software Foundation; either version 2 of the License, or
  48179. + * (at your option) any later version.
  48180. + *
  48181. + * This program is distributed in the hope that it will be useful,
  48182. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  48183. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  48184. + * GNU General Public License for more details.
  48185. + *
  48186. + * You should have received a copy of the GNU General Public License
  48187. + * along with this program; if not, write to the Free Software
  48188. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  48189. + */
  48190. +
  48191. +#include <linux/kernel.h>
  48192. +#include <linux/module.h>
  48193. +#include <linux/spinlock.h>
  48194. +#include <linux/clk.h>
  48195. +#include <linux/err.h>
  48196. +#include <linux/platform_device.h>
  48197. +#include <linux/io.h>
  48198. +#include <linux/spi/spi.h>
  48199. +#include <linux/interrupt.h>
  48200. +#include <linux/delay.h>
  48201. +#include <linux/log2.h>
  48202. +#include <linux/sched.h>
  48203. +#include <linux/wait.h>
  48204. +
  48205. +/* SPI register offsets */
  48206. +#define SPI_CS 0x00
  48207. +#define SPI_FIFO 0x04
  48208. +#define SPI_CLK 0x08
  48209. +#define SPI_DLEN 0x0c
  48210. +#define SPI_LTOH 0x10
  48211. +#define SPI_DC 0x14
  48212. +
  48213. +/* Bitfields in CS */
  48214. +#define SPI_CS_LEN_LONG 0x02000000
  48215. +#define SPI_CS_DMA_LEN 0x01000000
  48216. +#define SPI_CS_CSPOL2 0x00800000
  48217. +#define SPI_CS_CSPOL1 0x00400000
  48218. +#define SPI_CS_CSPOL0 0x00200000
  48219. +#define SPI_CS_RXF 0x00100000
  48220. +#define SPI_CS_RXR 0x00080000
  48221. +#define SPI_CS_TXD 0x00040000
  48222. +#define SPI_CS_RXD 0x00020000
  48223. +#define SPI_CS_DONE 0x00010000
  48224. +#define SPI_CS_LEN 0x00002000
  48225. +#define SPI_CS_REN 0x00001000
  48226. +#define SPI_CS_ADCS 0x00000800
  48227. +#define SPI_CS_INTR 0x00000400
  48228. +#define SPI_CS_INTD 0x00000200
  48229. +#define SPI_CS_DMAEN 0x00000100
  48230. +#define SPI_CS_TA 0x00000080
  48231. +#define SPI_CS_CSPOL 0x00000040
  48232. +#define SPI_CS_CLEAR_RX 0x00000020
  48233. +#define SPI_CS_CLEAR_TX 0x00000010
  48234. +#define SPI_CS_CPOL 0x00000008
  48235. +#define SPI_CS_CPHA 0x00000004
  48236. +#define SPI_CS_CS_10 0x00000002
  48237. +#define SPI_CS_CS_01 0x00000001
  48238. +
  48239. +#define SPI_TIMEOUT_MS 150
  48240. +
  48241. +#define DRV_NAME "bcm2708_spi"
  48242. +
  48243. +struct bcm2708_spi {
  48244. + spinlock_t lock;
  48245. + void __iomem *base;
  48246. + int irq;
  48247. + struct clk *clk;
  48248. + bool stopping;
  48249. +
  48250. + struct list_head queue;
  48251. + struct workqueue_struct *workq;
  48252. + struct work_struct work;
  48253. + struct completion done;
  48254. +
  48255. + const u8 *tx_buf;
  48256. + u8 *rx_buf;
  48257. + int len;
  48258. +};
  48259. +
  48260. +struct bcm2708_spi_state {
  48261. + u32 cs;
  48262. + u16 cdiv;
  48263. +};
  48264. +
  48265. +/*
  48266. + * This function sets the ALT mode on the SPI pins so that we can use them with
  48267. + * the SPI hardware.
  48268. + *
  48269. + * FIXME: This is a hack. Use pinmux / pinctrl.
  48270. + */
  48271. +static void bcm2708_init_pinmode(void)
  48272. +{
  48273. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  48274. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  48275. +
  48276. + int pin;
  48277. + u32 *gpio = ioremap(GPIO_BASE, SZ_16K);
  48278. +
  48279. + /* SPI is on GPIO 7..11 */
  48280. + for (pin = 7; pin <= 11; pin++) {
  48281. + INP_GPIO(pin); /* set mode to GPIO input first */
  48282. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  48283. + }
  48284. +
  48285. + iounmap(gpio);
  48286. +
  48287. +#undef INP_GPIO
  48288. +#undef SET_GPIO_ALT
  48289. +}
  48290. +
  48291. +static inline u32 bcm2708_rd(struct bcm2708_spi *bs, unsigned reg)
  48292. +{
  48293. + return readl(bs->base + reg);
  48294. +}
  48295. +
  48296. +static inline void bcm2708_wr(struct bcm2708_spi *bs, unsigned reg, u32 val)
  48297. +{
  48298. + writel(val, bs->base + reg);
  48299. +}
  48300. +
  48301. +static inline void bcm2708_rd_fifo(struct bcm2708_spi *bs, int len)
  48302. +{
  48303. + u8 byte;
  48304. +
  48305. + while (len--) {
  48306. + byte = bcm2708_rd(bs, SPI_FIFO);
  48307. + if (bs->rx_buf)
  48308. + *bs->rx_buf++ = byte;
  48309. + }
  48310. +}
  48311. +
  48312. +static inline void bcm2708_wr_fifo(struct bcm2708_spi *bs, int len)
  48313. +{
  48314. + u8 byte;
  48315. + u16 val;
  48316. +
  48317. + if (len > bs->len)
  48318. + len = bs->len;
  48319. +
  48320. + if (unlikely(bcm2708_rd(bs, SPI_CS) & SPI_CS_LEN)) {
  48321. + /* LoSSI mode */
  48322. + if (unlikely(len % 2)) {
  48323. + printk(KERN_ERR"bcm2708_wr_fifo: length must be even, skipping.\n");
  48324. + bs->len = 0;
  48325. + return;
  48326. + }
  48327. + while (len) {
  48328. + if (bs->tx_buf) {
  48329. + val = *(const u16 *)bs->tx_buf;
  48330. + bs->tx_buf += 2;
  48331. + } else
  48332. + val = 0;
  48333. + bcm2708_wr(bs, SPI_FIFO, val);
  48334. + bs->len -= 2;
  48335. + len -= 2;
  48336. + }
  48337. + return;
  48338. + }
  48339. +
  48340. + while (len--) {
  48341. + byte = bs->tx_buf ? *bs->tx_buf++ : 0;
  48342. + bcm2708_wr(bs, SPI_FIFO, byte);
  48343. + bs->len--;
  48344. + }
  48345. +}
  48346. +
  48347. +static irqreturn_t bcm2708_spi_interrupt(int irq, void *dev_id)
  48348. +{
  48349. + struct spi_master *master = dev_id;
  48350. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  48351. + u32 cs;
  48352. +
  48353. + spin_lock(&bs->lock);
  48354. +
  48355. + cs = bcm2708_rd(bs, SPI_CS);
  48356. +
  48357. + if (cs & SPI_CS_DONE) {
  48358. + if (bs->len) { /* first interrupt in a transfer */
  48359. + /* fill the TX fifo with up to 16 bytes */
  48360. + bcm2708_wr_fifo(bs, 16);
  48361. + } else { /* transfer complete */
  48362. + /* disable interrupts */
  48363. + cs &= ~(SPI_CS_INTR | SPI_CS_INTD);
  48364. + bcm2708_wr(bs, SPI_CS, cs);
  48365. +
  48366. + /* drain RX FIFO */
  48367. + while (cs & SPI_CS_RXD) {
  48368. + bcm2708_rd_fifo(bs, 1);
  48369. + cs = bcm2708_rd(bs, SPI_CS);
  48370. + }
  48371. +
  48372. + /* wake up our bh */
  48373. + complete(&bs->done);
  48374. + }
  48375. + } else if (cs & SPI_CS_RXR) {
  48376. + /* read 12 bytes of data */
  48377. + bcm2708_rd_fifo(bs, 12);
  48378. +
  48379. + /* write up to 12 bytes */
  48380. + bcm2708_wr_fifo(bs, 12);
  48381. + }
  48382. +
  48383. + spin_unlock(&bs->lock);
  48384. +
  48385. + return IRQ_HANDLED;
  48386. +}
  48387. +
  48388. +static int bcm2708_setup_state(struct spi_master *master,
  48389. + struct device *dev, struct bcm2708_spi_state *state,
  48390. + u32 hz, u8 csel, u8 mode, u8 bpw)
  48391. +{
  48392. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  48393. + int cdiv;
  48394. + unsigned long bus_hz;
  48395. + u32 cs = 0;
  48396. +
  48397. + bus_hz = clk_get_rate(bs->clk);
  48398. +
  48399. + if (hz >= bus_hz) {
  48400. + cdiv = 2; /* bus_hz / 2 is as fast as we can go */
  48401. + } else if (hz) {
  48402. + cdiv = DIV_ROUND_UP(bus_hz, hz);
  48403. +
  48404. + /* CDIV must be a power of 2, so round up */
  48405. + cdiv = roundup_pow_of_two(cdiv);
  48406. +
  48407. + if (cdiv > 65536) {
  48408. + dev_dbg(dev,
  48409. + "setup: %d Hz too slow, cdiv %u; min %ld Hz\n",
  48410. + hz, cdiv, bus_hz / 65536);
  48411. + return -EINVAL;
  48412. + } else if (cdiv == 65536) {
  48413. + cdiv = 0;
  48414. + } else if (cdiv == 1) {
  48415. + cdiv = 2; /* 1 gets rounded down to 0; == 65536 */
  48416. + }
  48417. + } else {
  48418. + cdiv = 0;
  48419. + }
  48420. +
  48421. + switch (bpw) {
  48422. + case 8:
  48423. + break;
  48424. + case 9:
  48425. + /* Reading in LoSSI mode is a special case. See 'BCM2835 ARM Peripherals' datasheet */
  48426. + cs |= SPI_CS_LEN;
  48427. + break;
  48428. + default:
  48429. + dev_dbg(dev, "setup: invalid bits_per_word %u (must be 8 or 9)\n",
  48430. + bpw);
  48431. + return -EINVAL;
  48432. + }
  48433. +
  48434. + if (mode & SPI_CPOL)
  48435. + cs |= SPI_CS_CPOL;
  48436. + if (mode & SPI_CPHA)
  48437. + cs |= SPI_CS_CPHA;
  48438. +
  48439. + if (!(mode & SPI_NO_CS)) {
  48440. + if (mode & SPI_CS_HIGH) {
  48441. + cs |= SPI_CS_CSPOL;
  48442. + cs |= SPI_CS_CSPOL0 << csel;
  48443. + }
  48444. +
  48445. + cs |= csel;
  48446. + } else {
  48447. + cs |= SPI_CS_CS_10 | SPI_CS_CS_01;
  48448. + }
  48449. +
  48450. + if (state) {
  48451. + state->cs = cs;
  48452. + state->cdiv = cdiv;
  48453. + dev_dbg(dev, "setup: want %d Hz; "
  48454. + "bus_hz=%lu / cdiv=%u == %lu Hz; "
  48455. + "mode %u: cs 0x%08X\n",
  48456. + hz, bus_hz, cdiv, bus_hz/cdiv, mode, cs);
  48457. + }
  48458. +
  48459. + return 0;
  48460. +}
  48461. +
  48462. +static int bcm2708_process_transfer(struct bcm2708_spi *bs,
  48463. + struct spi_message *msg, struct spi_transfer *xfer)
  48464. +{
  48465. + struct spi_device *spi = msg->spi;
  48466. + struct bcm2708_spi_state state, *stp;
  48467. + int ret;
  48468. + u32 cs;
  48469. +
  48470. + if (bs->stopping)
  48471. + return -ESHUTDOWN;
  48472. +
  48473. + if (xfer->bits_per_word || xfer->speed_hz) {
  48474. + ret = bcm2708_setup_state(spi->master, &spi->dev, &state,
  48475. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  48476. + spi->chip_select, spi->mode,
  48477. + xfer->bits_per_word ? xfer->bits_per_word :
  48478. + spi->bits_per_word);
  48479. + if (ret)
  48480. + return ret;
  48481. +
  48482. + stp = &state;
  48483. + } else {
  48484. + stp = spi->controller_state;
  48485. + }
  48486. +
  48487. + reinit_completion(&bs->done);
  48488. + bs->tx_buf = xfer->tx_buf;
  48489. + bs->rx_buf = xfer->rx_buf;
  48490. + bs->len = xfer->len;
  48491. +
  48492. + cs = stp->cs | SPI_CS_INTR | SPI_CS_INTD | SPI_CS_TA;
  48493. +
  48494. + bcm2708_wr(bs, SPI_CLK, stp->cdiv);
  48495. + bcm2708_wr(bs, SPI_CS, cs);
  48496. +
  48497. + ret = wait_for_completion_timeout(&bs->done,
  48498. + msecs_to_jiffies(SPI_TIMEOUT_MS));
  48499. + if (ret == 0) {
  48500. + dev_err(&spi->dev, "transfer timed out\n");
  48501. + return -ETIMEDOUT;
  48502. + }
  48503. +
  48504. + if (xfer->delay_usecs)
  48505. + udelay(xfer->delay_usecs);
  48506. +
  48507. + if (list_is_last(&xfer->transfer_list, &msg->transfers) ||
  48508. + xfer->cs_change) {
  48509. + /* clear TA and interrupt flags */
  48510. + bcm2708_wr(bs, SPI_CS, stp->cs);
  48511. + }
  48512. +
  48513. + msg->actual_length += (xfer->len - bs->len);
  48514. +
  48515. + return 0;
  48516. +}
  48517. +
  48518. +static void bcm2708_work(struct work_struct *work)
  48519. +{
  48520. + struct bcm2708_spi *bs = container_of(work, struct bcm2708_spi, work);
  48521. + unsigned long flags;
  48522. + struct spi_message *msg;
  48523. + struct spi_transfer *xfer;
  48524. + int status = 0;
  48525. +
  48526. + spin_lock_irqsave(&bs->lock, flags);
  48527. + while (!list_empty(&bs->queue)) {
  48528. + msg = list_first_entry(&bs->queue, struct spi_message, queue);
  48529. + list_del_init(&msg->queue);
  48530. + spin_unlock_irqrestore(&bs->lock, flags);
  48531. +
  48532. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  48533. + status = bcm2708_process_transfer(bs, msg, xfer);
  48534. + if (status)
  48535. + break;
  48536. + }
  48537. +
  48538. + msg->status = status;
  48539. + msg->complete(msg->context);
  48540. +
  48541. + spin_lock_irqsave(&bs->lock, flags);
  48542. + }
  48543. + spin_unlock_irqrestore(&bs->lock, flags);
  48544. +}
  48545. +
  48546. +static int bcm2708_spi_setup(struct spi_device *spi)
  48547. +{
  48548. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  48549. + struct bcm2708_spi_state *state;
  48550. + int ret;
  48551. +
  48552. + if (bs->stopping)
  48553. + return -ESHUTDOWN;
  48554. +
  48555. + if (!(spi->mode & SPI_NO_CS) &&
  48556. + (spi->chip_select > spi->master->num_chipselect)) {
  48557. + dev_dbg(&spi->dev,
  48558. + "setup: invalid chipselect %u (%u defined)\n",
  48559. + spi->chip_select, spi->master->num_chipselect);
  48560. + return -EINVAL;
  48561. + }
  48562. +
  48563. + state = spi->controller_state;
  48564. + if (!state) {
  48565. + state = kzalloc(sizeof(*state), GFP_KERNEL);
  48566. + if (!state)
  48567. + return -ENOMEM;
  48568. +
  48569. + spi->controller_state = state;
  48570. + }
  48571. +
  48572. + ret = bcm2708_setup_state(spi->master, &spi->dev, state,
  48573. + spi->max_speed_hz, spi->chip_select, spi->mode,
  48574. + spi->bits_per_word);
  48575. + if (ret < 0) {
  48576. + kfree(state);
  48577. + spi->controller_state = NULL;
  48578. + return ret;
  48579. + }
  48580. +
  48581. + dev_dbg(&spi->dev,
  48582. + "setup: cd %d: %d Hz, bpw %u, mode 0x%x -> CS=%08x CDIV=%04x\n",
  48583. + spi->chip_select, spi->max_speed_hz, spi->bits_per_word,
  48584. + spi->mode, state->cs, state->cdiv);
  48585. +
  48586. + return 0;
  48587. +}
  48588. +
  48589. +static int bcm2708_spi_transfer(struct spi_device *spi, struct spi_message *msg)
  48590. +{
  48591. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  48592. + struct spi_transfer *xfer;
  48593. + int ret;
  48594. + unsigned long flags;
  48595. +
  48596. + if (unlikely(list_empty(&msg->transfers)))
  48597. + return -EINVAL;
  48598. +
  48599. + if (bs->stopping)
  48600. + return -ESHUTDOWN;
  48601. +
  48602. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  48603. + if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) {
  48604. + dev_dbg(&spi->dev, "missing rx or tx buf\n");
  48605. + return -EINVAL;
  48606. + }
  48607. +
  48608. + if (!xfer->bits_per_word || xfer->speed_hz)
  48609. + continue;
  48610. +
  48611. + ret = bcm2708_setup_state(spi->master, &spi->dev, NULL,
  48612. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  48613. + spi->chip_select, spi->mode,
  48614. + xfer->bits_per_word ? xfer->bits_per_word :
  48615. + spi->bits_per_word);
  48616. + if (ret)
  48617. + return ret;
  48618. + }
  48619. +
  48620. + msg->status = -EINPROGRESS;
  48621. + msg->actual_length = 0;
  48622. +
  48623. + spin_lock_irqsave(&bs->lock, flags);
  48624. + list_add_tail(&msg->queue, &bs->queue);
  48625. + queue_work(bs->workq, &bs->work);
  48626. + spin_unlock_irqrestore(&bs->lock, flags);
  48627. +
  48628. + return 0;
  48629. +}
  48630. +
  48631. +static void bcm2708_spi_cleanup(struct spi_device *spi)
  48632. +{
  48633. + if (spi->controller_state) {
  48634. + kfree(spi->controller_state);
  48635. + spi->controller_state = NULL;
  48636. + }
  48637. +}
  48638. +
  48639. +static int bcm2708_spi_probe(struct platform_device *pdev)
  48640. +{
  48641. + struct resource *regs;
  48642. + int irq, err = -ENOMEM;
  48643. + struct clk *clk;
  48644. + struct spi_master *master;
  48645. + struct bcm2708_spi *bs;
  48646. +
  48647. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  48648. + if (!regs) {
  48649. + dev_err(&pdev->dev, "could not get IO memory\n");
  48650. + return -ENXIO;
  48651. + }
  48652. +
  48653. + irq = platform_get_irq(pdev, 0);
  48654. + if (irq < 0) {
  48655. + dev_err(&pdev->dev, "could not get IRQ\n");
  48656. + return irq;
  48657. + }
  48658. +
  48659. + clk = clk_get(&pdev->dev, NULL);
  48660. + if (IS_ERR(clk)) {
  48661. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  48662. + return PTR_ERR(clk);
  48663. + }
  48664. +
  48665. + bcm2708_init_pinmode();
  48666. +
  48667. + master = spi_alloc_master(&pdev->dev, sizeof(*bs));
  48668. + if (!master) {
  48669. + dev_err(&pdev->dev, "spi_alloc_master() failed\n");
  48670. + goto out_clk_put;
  48671. + }
  48672. +
  48673. + /* the spi->mode bits understood by this driver: */
  48674. + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
  48675. +
  48676. + master->bus_num = pdev->id;
  48677. + master->num_chipselect = 3;
  48678. + master->setup = bcm2708_spi_setup;
  48679. + master->transfer = bcm2708_spi_transfer;
  48680. + master->cleanup = bcm2708_spi_cleanup;
  48681. + master->dev.of_node = pdev->dev.of_node;
  48682. + platform_set_drvdata(pdev, master);
  48683. +
  48684. + bs = spi_master_get_devdata(master);
  48685. +
  48686. + spin_lock_init(&bs->lock);
  48687. + INIT_LIST_HEAD(&bs->queue);
  48688. + init_completion(&bs->done);
  48689. + INIT_WORK(&bs->work, bcm2708_work);
  48690. +
  48691. + bs->base = ioremap(regs->start, resource_size(regs));
  48692. + if (!bs->base) {
  48693. + dev_err(&pdev->dev, "could not remap memory\n");
  48694. + goto out_master_put;
  48695. + }
  48696. +
  48697. + bs->workq = create_singlethread_workqueue(dev_name(&pdev->dev));
  48698. + if (!bs->workq) {
  48699. + dev_err(&pdev->dev, "could not create workqueue\n");
  48700. + goto out_iounmap;
  48701. + }
  48702. +
  48703. + bs->irq = irq;
  48704. + bs->clk = clk;
  48705. + bs->stopping = false;
  48706. +
  48707. + err = request_irq(irq, bcm2708_spi_interrupt, 0, dev_name(&pdev->dev),
  48708. + master);
  48709. + if (err) {
  48710. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  48711. + goto out_workqueue;
  48712. + }
  48713. +
  48714. + /* initialise the hardware */
  48715. + clk_prepare_enable(clk);
  48716. + bcm2708_wr(bs, SPI_CS, SPI_CS_REN | SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  48717. +
  48718. + err = spi_register_master(master);
  48719. + if (err) {
  48720. + dev_err(&pdev->dev, "could not register SPI master: %d\n", err);
  48721. + goto out_free_irq;
  48722. + }
  48723. +
  48724. + dev_info(&pdev->dev, "SPI Controller at 0x%08lx (irq %d)\n",
  48725. + (unsigned long)regs->start, irq);
  48726. +
  48727. + return 0;
  48728. +
  48729. +out_free_irq:
  48730. + free_irq(bs->irq, master);
  48731. + clk_disable_unprepare(bs->clk);
  48732. +out_workqueue:
  48733. + destroy_workqueue(bs->workq);
  48734. +out_iounmap:
  48735. + iounmap(bs->base);
  48736. +out_master_put:
  48737. + spi_master_put(master);
  48738. +out_clk_put:
  48739. + clk_put(clk);
  48740. + return err;
  48741. +}
  48742. +
  48743. +static int bcm2708_spi_remove(struct platform_device *pdev)
  48744. +{
  48745. + struct spi_master *master = platform_get_drvdata(pdev);
  48746. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  48747. +
  48748. + /* reset the hardware and block queue progress */
  48749. + spin_lock_irq(&bs->lock);
  48750. + bs->stopping = true;
  48751. + bcm2708_wr(bs, SPI_CS, SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  48752. + spin_unlock_irq(&bs->lock);
  48753. +
  48754. + flush_work(&bs->work);
  48755. +
  48756. + clk_disable_unprepare(bs->clk);
  48757. + clk_put(bs->clk);
  48758. + free_irq(bs->irq, master);
  48759. + iounmap(bs->base);
  48760. +
  48761. + spi_unregister_master(master);
  48762. +
  48763. + return 0;
  48764. +}
  48765. +
  48766. +static const struct of_device_id bcm2708_spi_match[] = {
  48767. + { .compatible = "brcm,bcm2708-spi", },
  48768. + {}
  48769. +};
  48770. +MODULE_DEVICE_TABLE(of, bcm2708_spi_match);
  48771. +
  48772. +static struct platform_driver bcm2708_spi_driver = {
  48773. + .driver = {
  48774. + .name = DRV_NAME,
  48775. + .owner = THIS_MODULE,
  48776. + .of_match_table = bcm2708_spi_match,
  48777. + },
  48778. + .probe = bcm2708_spi_probe,
  48779. + .remove = bcm2708_spi_remove,
  48780. +};
  48781. +
  48782. +
  48783. +static int __init bcm2708_spi_init(void)
  48784. +{
  48785. + return platform_driver_probe(&bcm2708_spi_driver, bcm2708_spi_probe);
  48786. +}
  48787. +module_init(bcm2708_spi_init);
  48788. +
  48789. +static void __exit bcm2708_spi_exit(void)
  48790. +{
  48791. + platform_driver_unregister(&bcm2708_spi_driver);
  48792. +}
  48793. +module_exit(bcm2708_spi_exit);
  48794. +
  48795. +
  48796. +//module_platform_driver(bcm2708_spi_driver);
  48797. +
  48798. +MODULE_DESCRIPTION("SPI controller driver for Broadcom BCM2708");
  48799. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  48800. +MODULE_LICENSE("GPL v2");
  48801. +MODULE_ALIAS("platform:" DRV_NAME);
  48802. diff -Nur linux-3.18.6/drivers/staging/media/lirc/Kconfig linux-rpi/drivers/staging/media/lirc/Kconfig
  48803. --- linux-3.18.6/drivers/staging/media/lirc/Kconfig 2015-02-06 15:53:48.000000000 +0100
  48804. +++ linux-rpi/drivers/staging/media/lirc/Kconfig 2015-02-09 04:40:25.000000000 +0100
  48805. @@ -38,6 +38,12 @@
  48806. help
  48807. Driver for Homebrew Parallel Port Receivers
  48808. +config LIRC_RPI
  48809. + tristate "Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi"
  48810. + depends on LIRC
  48811. + help
  48812. + Driver for Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi
  48813. +
  48814. config LIRC_SASEM
  48815. tristate "Sasem USB IR Remote"
  48816. depends on LIRC && USB
  48817. diff -Nur linux-3.18.6/drivers/staging/media/lirc/lirc_rpi.c linux-rpi/drivers/staging/media/lirc/lirc_rpi.c
  48818. --- linux-3.18.6/drivers/staging/media/lirc/lirc_rpi.c 1970-01-01 01:00:00.000000000 +0100
  48819. +++ linux-rpi/drivers/staging/media/lirc/lirc_rpi.c 2015-02-09 04:40:25.000000000 +0100
  48820. @@ -0,0 +1,757 @@
  48821. +/*
  48822. + * lirc_rpi.c
  48823. + *
  48824. + * lirc_rpi - Device driver that records pulse- and pause-lengths
  48825. + * (space-lengths) (just like the lirc_serial driver does)
  48826. + * between GPIO interrupt events on the Raspberry Pi.
  48827. + * Lots of code has been taken from the lirc_serial module,
  48828. + * so I would like say thanks to the authors.
  48829. + *
  48830. + * Copyright (C) 2012 Aron Robert Szabo <aron@reon.hu>,
  48831. + * Michael Bishop <cleverca22@gmail.com>
  48832. + * This program is free software; you can redistribute it and/or modify
  48833. + * it under the terms of the GNU General Public License as published by
  48834. + * the Free Software Foundation; either version 2 of the License, or
  48835. + * (at your option) any later version.
  48836. + *
  48837. + * This program is distributed in the hope that it will be useful,
  48838. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  48839. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  48840. + * GNU General Public License for more details.
  48841. + *
  48842. + * You should have received a copy of the GNU General Public License
  48843. + * along with this program; if not, write to the Free Software
  48844. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  48845. + */
  48846. +
  48847. +#include <linux/module.h>
  48848. +#include <linux/errno.h>
  48849. +#include <linux/interrupt.h>
  48850. +#include <linux/sched.h>
  48851. +#include <linux/kernel.h>
  48852. +#include <linux/time.h>
  48853. +#include <linux/timex.h>
  48854. +#include <linux/string.h>
  48855. +#include <linux/delay.h>
  48856. +#include <linux/platform_device.h>
  48857. +#include <linux/irq.h>
  48858. +#include <linux/spinlock.h>
  48859. +#include <media/lirc.h>
  48860. +#include <media/lirc_dev.h>
  48861. +#include <mach/gpio.h>
  48862. +#include <linux/gpio.h>
  48863. +#include <linux/of_platform.h>
  48864. +
  48865. +#include <linux/platform_data/bcm2708.h>
  48866. +
  48867. +#define LIRC_DRIVER_NAME "lirc_rpi"
  48868. +#define RBUF_LEN 256
  48869. +#define LIRC_TRANSMITTER_LATENCY 50
  48870. +
  48871. +#ifndef MAX_UDELAY_MS
  48872. +#define MAX_UDELAY_US 5000
  48873. +#else
  48874. +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
  48875. +#endif
  48876. +
  48877. +#define dprintk(fmt, args...) \
  48878. + do { \
  48879. + if (debug) \
  48880. + printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
  48881. + fmt, ## args); \
  48882. + } while (0)
  48883. +
  48884. +/* module parameters */
  48885. +
  48886. +/* set the default GPIO input pin */
  48887. +static int gpio_in_pin = 18;
  48888. +/* set the default pull behaviour for input pin */
  48889. +static int gpio_in_pull = BCM2708_PULL_DOWN;
  48890. +/* set the default GPIO output pin */
  48891. +static int gpio_out_pin = 17;
  48892. +/* enable debugging messages */
  48893. +static bool debug;
  48894. +/* -1 = auto, 0 = active high, 1 = active low */
  48895. +static int sense = -1;
  48896. +/* use softcarrier by default */
  48897. +static bool softcarrier = 1;
  48898. +/* 0 = do not invert output, 1 = invert output */
  48899. +static bool invert = 0;
  48900. +
  48901. +struct gpio_chip *gpiochip;
  48902. +static int irq_num;
  48903. +
  48904. +/* forward declarations */
  48905. +static long send_pulse(unsigned long length);
  48906. +static void send_space(long length);
  48907. +static void lirc_rpi_exit(void);
  48908. +
  48909. +static struct platform_device *lirc_rpi_dev;
  48910. +static struct timeval lasttv = { 0, 0 };
  48911. +static struct lirc_buffer rbuf;
  48912. +static spinlock_t lock;
  48913. +
  48914. +/* initialized/set in init_timing_params() */
  48915. +static unsigned int freq = 38000;
  48916. +static unsigned int duty_cycle = 50;
  48917. +static unsigned long period;
  48918. +static unsigned long pulse_width;
  48919. +static unsigned long space_width;
  48920. +
  48921. +static void safe_udelay(unsigned long usecs)
  48922. +{
  48923. + while (usecs > MAX_UDELAY_US) {
  48924. + udelay(MAX_UDELAY_US);
  48925. + usecs -= MAX_UDELAY_US;
  48926. + }
  48927. + udelay(usecs);
  48928. +}
  48929. +
  48930. +static int init_timing_params(unsigned int new_duty_cycle,
  48931. + unsigned int new_freq)
  48932. +{
  48933. + if (1000 * 1000000L / new_freq * new_duty_cycle / 100 <=
  48934. + LIRC_TRANSMITTER_LATENCY)
  48935. + return -EINVAL;
  48936. + if (1000 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
  48937. + LIRC_TRANSMITTER_LATENCY)
  48938. + return -EINVAL;
  48939. + duty_cycle = new_duty_cycle;
  48940. + freq = new_freq;
  48941. + period = 1000 * 1000000L / freq;
  48942. + pulse_width = period * duty_cycle / 100;
  48943. + space_width = period - pulse_width;
  48944. + dprintk("in init_timing_params, freq=%d pulse=%ld, "
  48945. + "space=%ld\n", freq, pulse_width, space_width);
  48946. + return 0;
  48947. +}
  48948. +
  48949. +static long send_pulse_softcarrier(unsigned long length)
  48950. +{
  48951. + int flag;
  48952. + unsigned long actual, target;
  48953. + unsigned long actual_us, initial_us, target_us;
  48954. +
  48955. + length *= 1000;
  48956. +
  48957. + actual = 0; target = 0; flag = 0;
  48958. + read_current_timer(&actual_us);
  48959. +
  48960. + while (actual < length) {
  48961. + if (flag) {
  48962. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  48963. + target += space_width;
  48964. + } else {
  48965. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  48966. + target += pulse_width;
  48967. + }
  48968. + initial_us = actual_us;
  48969. + target_us = actual_us + (target - actual) / 1000;
  48970. + /*
  48971. + * Note - we've checked in ioctl that the pulse/space
  48972. + * widths are big enough so that d is > 0
  48973. + */
  48974. + if ((int)(target_us - actual_us) > 0)
  48975. + udelay(target_us - actual_us);
  48976. + read_current_timer(&actual_us);
  48977. + actual += (actual_us - initial_us) * 1000;
  48978. + flag = !flag;
  48979. + }
  48980. + return (actual-length) / 1000;
  48981. +}
  48982. +
  48983. +static long send_pulse(unsigned long length)
  48984. +{
  48985. + if (length <= 0)
  48986. + return 0;
  48987. +
  48988. + if (softcarrier) {
  48989. + return send_pulse_softcarrier(length);
  48990. + } else {
  48991. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  48992. + safe_udelay(length);
  48993. + return 0;
  48994. + }
  48995. +}
  48996. +
  48997. +static void send_space(long length)
  48998. +{
  48999. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  49000. + if (length <= 0)
  49001. + return;
  49002. + safe_udelay(length);
  49003. +}
  49004. +
  49005. +static void rbwrite(int l)
  49006. +{
  49007. + if (lirc_buffer_full(&rbuf)) {
  49008. + /* no new signals will be accepted */
  49009. + dprintk("Buffer overrun\n");
  49010. + return;
  49011. + }
  49012. + lirc_buffer_write(&rbuf, (void *)&l);
  49013. +}
  49014. +
  49015. +static void frbwrite(int l)
  49016. +{
  49017. + /* simple noise filter */
  49018. + static int pulse, space;
  49019. + static unsigned int ptr;
  49020. +
  49021. + if (ptr > 0 && (l & PULSE_BIT)) {
  49022. + pulse += l & PULSE_MASK;
  49023. + if (pulse > 250) {
  49024. + rbwrite(space);
  49025. + rbwrite(pulse | PULSE_BIT);
  49026. + ptr = 0;
  49027. + pulse = 0;
  49028. + }
  49029. + return;
  49030. + }
  49031. + if (!(l & PULSE_BIT)) {
  49032. + if (ptr == 0) {
  49033. + if (l > 20000) {
  49034. + space = l;
  49035. + ptr++;
  49036. + return;
  49037. + }
  49038. + } else {
  49039. + if (l > 20000) {
  49040. + space += pulse;
  49041. + if (space > PULSE_MASK)
  49042. + space = PULSE_MASK;
  49043. + space += l;
  49044. + if (space > PULSE_MASK)
  49045. + space = PULSE_MASK;
  49046. + pulse = 0;
  49047. + return;
  49048. + }
  49049. + rbwrite(space);
  49050. + rbwrite(pulse | PULSE_BIT);
  49051. + ptr = 0;
  49052. + pulse = 0;
  49053. + }
  49054. + }
  49055. + rbwrite(l);
  49056. +}
  49057. +
  49058. +static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
  49059. +{
  49060. + struct timeval tv;
  49061. + long deltv;
  49062. + int data;
  49063. + int signal;
  49064. +
  49065. + /* use the GPIO signal level */
  49066. + signal = gpiochip->get(gpiochip, gpio_in_pin);
  49067. +
  49068. + if (sense != -1) {
  49069. + /* get current time */
  49070. + do_gettimeofday(&tv);
  49071. +
  49072. + /* calc time since last interrupt in microseconds */
  49073. + deltv = tv.tv_sec-lasttv.tv_sec;
  49074. + if (tv.tv_sec < lasttv.tv_sec ||
  49075. + (tv.tv_sec == lasttv.tv_sec &&
  49076. + tv.tv_usec < lasttv.tv_usec)) {
  49077. + printk(KERN_WARNING LIRC_DRIVER_NAME
  49078. + ": AIEEEE: your clock just jumped backwards\n");
  49079. + printk(KERN_WARNING LIRC_DRIVER_NAME
  49080. + ": %d %d %lx %lx %lx %lx\n", signal, sense,
  49081. + tv.tv_sec, lasttv.tv_sec,
  49082. + tv.tv_usec, lasttv.tv_usec);
  49083. + data = PULSE_MASK;
  49084. + } else if (deltv > 15) {
  49085. + data = PULSE_MASK; /* really long time */
  49086. + if (!(signal^sense)) {
  49087. + /* sanity check */
  49088. + printk(KERN_WARNING LIRC_DRIVER_NAME
  49089. + ": AIEEEE: %d %d %lx %lx %lx %lx\n",
  49090. + signal, sense, tv.tv_sec, lasttv.tv_sec,
  49091. + tv.tv_usec, lasttv.tv_usec);
  49092. + /*
  49093. + * detecting pulse while this
  49094. + * MUST be a space!
  49095. + */
  49096. + sense = sense ? 0 : 1;
  49097. + }
  49098. + } else {
  49099. + data = (int) (deltv*1000000 +
  49100. + (tv.tv_usec - lasttv.tv_usec));
  49101. + }
  49102. + frbwrite(signal^sense ? data : (data|PULSE_BIT));
  49103. + lasttv = tv;
  49104. + wake_up_interruptible(&rbuf.wait_poll);
  49105. + }
  49106. +
  49107. + return IRQ_HANDLED;
  49108. +}
  49109. +
  49110. +static int is_right_chip(struct gpio_chip *chip, void *data)
  49111. +{
  49112. + dprintk("is_right_chip %s %d\n", chip->label, strcmp(data, chip->label));
  49113. +
  49114. + if (strcmp(data, chip->label) == 0)
  49115. + return 1;
  49116. + return 0;
  49117. +}
  49118. +
  49119. +static inline int read_bool_property(const struct device_node *np,
  49120. + const char *propname,
  49121. + bool *out_value)
  49122. +{
  49123. + u32 value = 0;
  49124. + int err = of_property_read_u32(np, propname, &value);
  49125. + if (err == 0)
  49126. + *out_value = (value != 0);
  49127. + return err;
  49128. +}
  49129. +
  49130. +static void read_pin_settings(struct device_node *node)
  49131. +{
  49132. + u32 pin;
  49133. + int index;
  49134. +
  49135. + for (index = 0;
  49136. + of_property_read_u32_index(
  49137. + node,
  49138. + "brcm,pins",
  49139. + index,
  49140. + &pin) == 0;
  49141. + index++) {
  49142. + u32 function;
  49143. + int err;
  49144. + err = of_property_read_u32_index(
  49145. + node,
  49146. + "brcm,function",
  49147. + index,
  49148. + &function);
  49149. + if (err == 0) {
  49150. + if (function == 1) /* Output */
  49151. + gpio_out_pin = pin;
  49152. + else if (function == 0) /* Input */
  49153. + gpio_in_pin = pin;
  49154. + }
  49155. + }
  49156. +}
  49157. +
  49158. +static int init_port(void)
  49159. +{
  49160. + int i, nlow, nhigh, ret;
  49161. + struct device_node *node;
  49162. +
  49163. + node = lirc_rpi_dev->dev.of_node;
  49164. +
  49165. + gpiochip = gpiochip_find("bcm2708_gpio", is_right_chip);
  49166. +
  49167. + /*
  49168. + * Because of the lack of a setpull function, only support
  49169. + * pinctrl-bcm2835 if using device tree.
  49170. + */
  49171. + if (!gpiochip && node)
  49172. + gpiochip = gpiochip_find("pinctrl-bcm2835", is_right_chip);
  49173. +
  49174. + if (!gpiochip) {
  49175. + pr_err(LIRC_DRIVER_NAME ": gpio chip not found!\n");
  49176. + return -ENODEV;
  49177. + }
  49178. +
  49179. + if (node) {
  49180. + struct device_node *pins_node;
  49181. +
  49182. + pins_node = of_parse_phandle(node, "pinctrl-0", 0);
  49183. + if (!pins_node) {
  49184. + printk(KERN_ERR LIRC_DRIVER_NAME
  49185. + ": pinctrl settings not found!\n");
  49186. + ret = -EINVAL;
  49187. + goto exit_init_port;
  49188. + }
  49189. +
  49190. + read_pin_settings(pins_node);
  49191. +
  49192. + of_property_read_u32(node, "rpi,sense", &sense);
  49193. +
  49194. + read_bool_property(node, "rpi,softcarrier", &softcarrier);
  49195. +
  49196. + read_bool_property(node, "rpi,invert", &invert);
  49197. +
  49198. + read_bool_property(node, "rpi,debug", &debug);
  49199. +
  49200. + }
  49201. + else
  49202. + {
  49203. + if (gpio_in_pin >= BCM2708_NR_GPIOS ||
  49204. + gpio_out_pin >= BCM2708_NR_GPIOS) {
  49205. + ret = -EINVAL;
  49206. + printk(KERN_ERR LIRC_DRIVER_NAME
  49207. + ": invalid GPIO pin(s) specified!\n");
  49208. + goto exit_init_port;
  49209. + }
  49210. +
  49211. + if (gpio_request(gpio_out_pin, LIRC_DRIVER_NAME " ir/out")) {
  49212. + printk(KERN_ALERT LIRC_DRIVER_NAME
  49213. + ": cant claim gpio pin %d\n", gpio_out_pin);
  49214. + ret = -ENODEV;
  49215. + goto exit_init_port;
  49216. + }
  49217. +
  49218. + if (gpio_request(gpio_in_pin, LIRC_DRIVER_NAME " ir/in")) {
  49219. + printk(KERN_ALERT LIRC_DRIVER_NAME
  49220. + ": cant claim gpio pin %d\n", gpio_in_pin);
  49221. + ret = -ENODEV;
  49222. + goto exit_gpio_free_out_pin;
  49223. + }
  49224. +
  49225. + bcm2708_gpio_setpull(gpiochip, gpio_in_pin, gpio_in_pull);
  49226. + gpiochip->direction_input(gpiochip, gpio_in_pin);
  49227. + gpiochip->direction_output(gpiochip, gpio_out_pin, 1);
  49228. + }
  49229. +
  49230. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  49231. +
  49232. + irq_num = gpiochip->to_irq(gpiochip, gpio_in_pin);
  49233. + dprintk("to_irq %d\n", irq_num);
  49234. +
  49235. + /* if pin is high, then this must be an active low receiver. */
  49236. + if (sense == -1) {
  49237. + /* wait 1/2 sec for the power supply */
  49238. + msleep(500);
  49239. +
  49240. + /*
  49241. + * probe 9 times every 0.04s, collect "votes" for
  49242. + * active high/low
  49243. + */
  49244. + nlow = 0;
  49245. + nhigh = 0;
  49246. + for (i = 0; i < 9; i++) {
  49247. + if (gpiochip->get(gpiochip, gpio_in_pin))
  49248. + nlow++;
  49249. + else
  49250. + nhigh++;
  49251. + msleep(40);
  49252. + }
  49253. + sense = (nlow >= nhigh ? 1 : 0);
  49254. + printk(KERN_INFO LIRC_DRIVER_NAME
  49255. + ": auto-detected active %s receiver on GPIO pin %d\n",
  49256. + sense ? "low" : "high", gpio_in_pin);
  49257. + } else {
  49258. + printk(KERN_INFO LIRC_DRIVER_NAME
  49259. + ": manually using active %s receiver on GPIO pin %d\n",
  49260. + sense ? "low" : "high", gpio_in_pin);
  49261. + }
  49262. +
  49263. + return 0;
  49264. +
  49265. + exit_gpio_free_out_pin:
  49266. + gpio_free(gpio_out_pin);
  49267. +
  49268. + exit_init_port:
  49269. + return ret;
  49270. +}
  49271. +
  49272. +// called when the character device is opened
  49273. +static int set_use_inc(void *data)
  49274. +{
  49275. + int result;
  49276. +
  49277. + /* initialize timestamp */
  49278. + do_gettimeofday(&lasttv);
  49279. +
  49280. + result = request_irq(irq_num,
  49281. + (irq_handler_t) irq_handler,
  49282. + IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING,
  49283. + LIRC_DRIVER_NAME, (void*) 0);
  49284. +
  49285. + switch (result) {
  49286. + case -EBUSY:
  49287. + printk(KERN_ERR LIRC_DRIVER_NAME
  49288. + ": IRQ %d is busy\n",
  49289. + irq_num);
  49290. + return -EBUSY;
  49291. + case -EINVAL:
  49292. + printk(KERN_ERR LIRC_DRIVER_NAME
  49293. + ": Bad irq number or handler\n");
  49294. + return -EINVAL;
  49295. + default:
  49296. + dprintk("Interrupt %d obtained\n",
  49297. + irq_num);
  49298. + break;
  49299. + };
  49300. +
  49301. + /* initialize pulse/space widths */
  49302. + init_timing_params(duty_cycle, freq);
  49303. +
  49304. + return 0;
  49305. +}
  49306. +
  49307. +static void set_use_dec(void *data)
  49308. +{
  49309. + /* GPIO Pin Falling/Rising Edge Detect Disable */
  49310. + irq_set_irq_type(irq_num, 0);
  49311. + disable_irq(irq_num);
  49312. +
  49313. + free_irq(irq_num, (void *) 0);
  49314. +
  49315. + dprintk(KERN_INFO LIRC_DRIVER_NAME
  49316. + ": freed IRQ %d\n", irq_num);
  49317. +}
  49318. +
  49319. +static ssize_t lirc_write(struct file *file, const char *buf,
  49320. + size_t n, loff_t *ppos)
  49321. +{
  49322. + int i, count;
  49323. + unsigned long flags;
  49324. + long delta = 0;
  49325. + int *wbuf;
  49326. +
  49327. + count = n / sizeof(int);
  49328. + if (n % sizeof(int) || count % 2 == 0)
  49329. + return -EINVAL;
  49330. + wbuf = memdup_user(buf, n);
  49331. + if (IS_ERR(wbuf))
  49332. + return PTR_ERR(wbuf);
  49333. + spin_lock_irqsave(&lock, flags);
  49334. +
  49335. + for (i = 0; i < count; i++) {
  49336. + if (i%2)
  49337. + send_space(wbuf[i] - delta);
  49338. + else
  49339. + delta = send_pulse(wbuf[i]);
  49340. + }
  49341. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  49342. +
  49343. + spin_unlock_irqrestore(&lock, flags);
  49344. + kfree(wbuf);
  49345. + return n;
  49346. +}
  49347. +
  49348. +static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  49349. +{
  49350. + int result;
  49351. + __u32 value;
  49352. +
  49353. + switch (cmd) {
  49354. + case LIRC_GET_SEND_MODE:
  49355. + return -ENOIOCTLCMD;
  49356. + break;
  49357. +
  49358. + case LIRC_SET_SEND_MODE:
  49359. + result = get_user(value, (__u32 *) arg);
  49360. + if (result)
  49361. + return result;
  49362. + /* only LIRC_MODE_PULSE supported */
  49363. + if (value != LIRC_MODE_PULSE)
  49364. + return -ENOSYS;
  49365. + break;
  49366. +
  49367. + case LIRC_GET_LENGTH:
  49368. + return -ENOSYS;
  49369. + break;
  49370. +
  49371. + case LIRC_SET_SEND_DUTY_CYCLE:
  49372. + dprintk("SET_SEND_DUTY_CYCLE\n");
  49373. + result = get_user(value, (__u32 *) arg);
  49374. + if (result)
  49375. + return result;
  49376. + if (value <= 0 || value > 100)
  49377. + return -EINVAL;
  49378. + return init_timing_params(value, freq);
  49379. + break;
  49380. +
  49381. + case LIRC_SET_SEND_CARRIER:
  49382. + dprintk("SET_SEND_CARRIER\n");
  49383. + result = get_user(value, (__u32 *) arg);
  49384. + if (result)
  49385. + return result;
  49386. + if (value > 500000 || value < 20000)
  49387. + return -EINVAL;
  49388. + return init_timing_params(duty_cycle, value);
  49389. + break;
  49390. +
  49391. + default:
  49392. + return lirc_dev_fop_ioctl(filep, cmd, arg);
  49393. + }
  49394. + return 0;
  49395. +}
  49396. +
  49397. +static const struct file_operations lirc_fops = {
  49398. + .owner = THIS_MODULE,
  49399. + .write = lirc_write,
  49400. + .unlocked_ioctl = lirc_ioctl,
  49401. + .read = lirc_dev_fop_read,
  49402. + .poll = lirc_dev_fop_poll,
  49403. + .open = lirc_dev_fop_open,
  49404. + .release = lirc_dev_fop_close,
  49405. + .llseek = no_llseek,
  49406. +};
  49407. +
  49408. +static struct lirc_driver driver = {
  49409. + .name = LIRC_DRIVER_NAME,
  49410. + .minor = -1,
  49411. + .code_length = 1,
  49412. + .sample_rate = 0,
  49413. + .data = NULL,
  49414. + .add_to_buf = NULL,
  49415. + .rbuf = &rbuf,
  49416. + .set_use_inc = set_use_inc,
  49417. + .set_use_dec = set_use_dec,
  49418. + .fops = &lirc_fops,
  49419. + .dev = NULL,
  49420. + .owner = THIS_MODULE,
  49421. +};
  49422. +
  49423. +static const struct of_device_id lirc_rpi_of_match[] = {
  49424. + { .compatible = "rpi,lirc-rpi", },
  49425. + {},
  49426. +};
  49427. +MODULE_DEVICE_TABLE(of, lirc_rpi_of_match);
  49428. +
  49429. +static struct platform_driver lirc_rpi_driver = {
  49430. + .driver = {
  49431. + .name = LIRC_DRIVER_NAME,
  49432. + .owner = THIS_MODULE,
  49433. + .of_match_table = of_match_ptr(lirc_rpi_of_match),
  49434. + },
  49435. +};
  49436. +
  49437. +static int __init lirc_rpi_init(void)
  49438. +{
  49439. + struct device_node *node;
  49440. + int result;
  49441. +
  49442. + /* Init read buffer. */
  49443. + result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
  49444. + if (result < 0)
  49445. + return -ENOMEM;
  49446. +
  49447. + result = platform_driver_register(&lirc_rpi_driver);
  49448. + if (result) {
  49449. + printk(KERN_ERR LIRC_DRIVER_NAME
  49450. + ": lirc register returned %d\n", result);
  49451. + goto exit_buffer_free;
  49452. + }
  49453. +
  49454. + node = of_find_compatible_node(NULL, NULL,
  49455. + lirc_rpi_of_match[0].compatible);
  49456. +
  49457. + if (node) {
  49458. + /* DT-enabled */
  49459. + lirc_rpi_dev = of_find_device_by_node(node);
  49460. + WARN_ON(lirc_rpi_dev->dev.of_node != node);
  49461. + of_node_put(node);
  49462. + }
  49463. + else {
  49464. + lirc_rpi_dev = platform_device_alloc(LIRC_DRIVER_NAME, 0);
  49465. + if (!lirc_rpi_dev) {
  49466. + result = -ENOMEM;
  49467. + goto exit_driver_unregister;
  49468. + }
  49469. +
  49470. + result = platform_device_add(lirc_rpi_dev);
  49471. + if (result)
  49472. + goto exit_device_put;
  49473. + }
  49474. +
  49475. + return 0;
  49476. +
  49477. + exit_device_put:
  49478. + platform_device_put(lirc_rpi_dev);
  49479. +
  49480. + exit_driver_unregister:
  49481. + platform_driver_unregister(&lirc_rpi_driver);
  49482. +
  49483. + exit_buffer_free:
  49484. + lirc_buffer_free(&rbuf);
  49485. +
  49486. + return result;
  49487. +}
  49488. +
  49489. +static void lirc_rpi_exit(void)
  49490. +{
  49491. + if (!lirc_rpi_dev->dev.of_node)
  49492. + platform_device_unregister(lirc_rpi_dev);
  49493. + platform_driver_unregister(&lirc_rpi_driver);
  49494. + lirc_buffer_free(&rbuf);
  49495. +}
  49496. +
  49497. +static int __init lirc_rpi_init_module(void)
  49498. +{
  49499. + int result;
  49500. +
  49501. + result = lirc_rpi_init();
  49502. + if (result)
  49503. + return result;
  49504. +
  49505. + result = init_port();
  49506. + if (result < 0)
  49507. + goto exit_rpi;
  49508. +
  49509. + driver.features = LIRC_CAN_SET_SEND_DUTY_CYCLE |
  49510. + LIRC_CAN_SET_SEND_CARRIER |
  49511. + LIRC_CAN_SEND_PULSE |
  49512. + LIRC_CAN_REC_MODE2;
  49513. +
  49514. + driver.dev = &lirc_rpi_dev->dev;
  49515. + driver.minor = lirc_register_driver(&driver);
  49516. +
  49517. + if (driver.minor < 0) {
  49518. + printk(KERN_ERR LIRC_DRIVER_NAME
  49519. + ": device registration failed with %d\n", result);
  49520. + result = -EIO;
  49521. + goto exit_rpi;
  49522. + }
  49523. +
  49524. + printk(KERN_INFO LIRC_DRIVER_NAME ": driver registered!\n");
  49525. +
  49526. + return 0;
  49527. +
  49528. + exit_rpi:
  49529. + lirc_rpi_exit();
  49530. +
  49531. + return result;
  49532. +}
  49533. +
  49534. +static void __exit lirc_rpi_exit_module(void)
  49535. +{
  49536. + lirc_unregister_driver(driver.minor);
  49537. +
  49538. + gpio_free(gpio_out_pin);
  49539. + gpio_free(gpio_in_pin);
  49540. +
  49541. + lirc_rpi_exit();
  49542. +
  49543. + printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
  49544. +}
  49545. +
  49546. +module_init(lirc_rpi_init_module);
  49547. +module_exit(lirc_rpi_exit_module);
  49548. +
  49549. +MODULE_DESCRIPTION("Infra-red receiver and blaster driver for Raspberry Pi GPIO.");
  49550. +MODULE_AUTHOR("Aron Robert Szabo <aron@reon.hu>");
  49551. +MODULE_AUTHOR("Michael Bishop <cleverca22@gmail.com>");
  49552. +MODULE_LICENSE("GPL");
  49553. +
  49554. +module_param(gpio_out_pin, int, S_IRUGO);
  49555. +MODULE_PARM_DESC(gpio_out_pin, "GPIO output/transmitter pin number of the BCM"
  49556. + " processor. (default 17");
  49557. +
  49558. +module_param(gpio_in_pin, int, S_IRUGO);
  49559. +MODULE_PARM_DESC(gpio_in_pin, "GPIO input pin number of the BCM processor."
  49560. + " (default 18");
  49561. +
  49562. +module_param(gpio_in_pull, int, S_IRUGO);
  49563. +MODULE_PARM_DESC(gpio_in_pull, "GPIO input pin pull configuration."
  49564. + " (0 = off, 1 = up, 2 = down, default down)");
  49565. +
  49566. +module_param(sense, int, S_IRUGO);
  49567. +MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
  49568. + " (0 = active high, 1 = active low )");
  49569. +
  49570. +module_param(softcarrier, bool, S_IRUGO);
  49571. +MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
  49572. +
  49573. +module_param(invert, bool, S_IRUGO);
  49574. +MODULE_PARM_DESC(invert, "Invert output (0 = off, 1 = on, default off");
  49575. +
  49576. +module_param(debug, bool, S_IRUGO | S_IWUSR);
  49577. +MODULE_PARM_DESC(debug, "Enable debugging messages");
  49578. diff -Nur linux-3.18.6/drivers/staging/media/lirc/Makefile linux-rpi/drivers/staging/media/lirc/Makefile
  49579. --- linux-3.18.6/drivers/staging/media/lirc/Makefile 2015-02-06 15:53:48.000000000 +0100
  49580. +++ linux-rpi/drivers/staging/media/lirc/Makefile 2015-02-09 04:40:25.000000000 +0100
  49581. @@ -7,6 +7,7 @@
  49582. obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
  49583. obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
  49584. obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
  49585. +obj-$(CONFIG_LIRC_RPI) += lirc_rpi.o
  49586. obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
  49587. obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
  49588. obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
  49589. diff -Nur linux-3.18.6/drivers/thermal/bcm2835-thermal.c linux-rpi/drivers/thermal/bcm2835-thermal.c
  49590. --- linux-3.18.6/drivers/thermal/bcm2835-thermal.c 1970-01-01 01:00:00.000000000 +0100
  49591. +++ linux-rpi/drivers/thermal/bcm2835-thermal.c 2015-02-09 04:40:27.000000000 +0100
  49592. @@ -0,0 +1,184 @@
  49593. +/*****************************************************************************
  49594. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  49595. +*
  49596. +* Unless you and Broadcom execute a separate written software license
  49597. +* agreement governing use of this software, this software is licensed to you
  49598. +* under the terms of the GNU General Public License version 2, available at
  49599. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  49600. +*
  49601. +* Notwithstanding the above, under no circumstances may you combine this
  49602. +* software in any way with any other Broadcom software provided under a
  49603. +* license other than the GPL, without Broadcom's express prior written
  49604. +* consent.
  49605. +*****************************************************************************/
  49606. +
  49607. +#include <linux/kernel.h>
  49608. +#include <linux/module.h>
  49609. +#include <linux/init.h>
  49610. +#include <linux/platform_device.h>
  49611. +#include <linux/slab.h>
  49612. +#include <linux/sysfs.h>
  49613. +#include <mach/vcio.h>
  49614. +#include <linux/thermal.h>
  49615. +
  49616. +
  49617. +/* --- DEFINITIONS --- */
  49618. +#define MODULE_NAME "bcm2835_thermal"
  49619. +
  49620. +/*#define THERMAL_DEBUG_ENABLE*/
  49621. +
  49622. +#ifdef THERMAL_DEBUG_ENABLE
  49623. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  49624. +#else
  49625. +#define print_debug(fmt,...)
  49626. +#endif
  49627. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  49628. +
  49629. +#define VC_TAG_GET_TEMP 0x00030006
  49630. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  49631. +
  49632. +typedef enum {
  49633. + TEMP,
  49634. + MAX_TEMP,
  49635. +} temp_type;
  49636. +
  49637. +/* --- STRUCTS --- */
  49638. +/* tag part of the message */
  49639. +struct vc_msg_tag {
  49640. + uint32_t tag_id; /* the tag ID for the temperature */
  49641. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  49642. + uint32_t request_code; /* identifies message as a request (should be 0) */
  49643. + uint32_t id; /* extra ID field (should be 0) */
  49644. + uint32_t val; /* returned value of the temperature */
  49645. +};
  49646. +
  49647. +/* message structure to be sent to videocore */
  49648. +struct vc_msg {
  49649. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  49650. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  49651. + struct vc_msg_tag tag; /* the tag structure above to make */
  49652. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  49653. +};
  49654. +
  49655. +struct bcm2835_thermal_data {
  49656. + struct thermal_zone_device *thermal_dev;
  49657. + struct vc_msg msg;
  49658. +};
  49659. +
  49660. +/* --- GLOBALS --- */
  49661. +static struct bcm2835_thermal_data bcm2835_data;
  49662. +
  49663. +/* Thermal Device Operations */
  49664. +static struct thermal_zone_device_ops ops;
  49665. +
  49666. +/* --- FUNCTIONS --- */
  49667. +
  49668. +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
  49669. +{
  49670. + int result = -1, retry = 3;
  49671. + print_debug("IN");
  49672. +
  49673. + *temp = 0;
  49674. + while (result != 0 && retry-- > 0) {
  49675. + /* wipe all previous message data */
  49676. + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
  49677. +
  49678. + /* prepare message */
  49679. + bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
  49680. + bcm2835_data.msg.tag.buffer_size = 8;
  49681. + bcm2835_data.msg.tag.tag_id = tag_id;
  49682. +
  49683. + /* send the message */
  49684. + result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
  49685. + 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);
  49686. + if (!(bcm2835_data.msg.request_code & 0x80000000))
  49687. + result = -1;
  49688. + }
  49689. +
  49690. + /* check if it was all ok and return the rate in milli degrees C */
  49691. + if (result == 0)
  49692. + *temp = (uint)bcm2835_data.msg.tag.val;
  49693. + else
  49694. + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
  49695. + print_debug("OUT");
  49696. + return result;
  49697. +}
  49698. +
  49699. +static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
  49700. +{
  49701. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
  49702. +}
  49703. +
  49704. +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
  49705. +{
  49706. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
  49707. +}
  49708. +
  49709. +static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)
  49710. +{
  49711. + *trip_type = THERMAL_TRIP_HOT;
  49712. + return 0;
  49713. +}
  49714. +
  49715. +
  49716. +static int bcm2835_get_mode(struct thermal_zone_device *thermal_dev, enum thermal_device_mode *dev_mode)
  49717. +{
  49718. + *dev_mode = THERMAL_DEVICE_ENABLED;
  49719. + return 0;
  49720. +}
  49721. +
  49722. +
  49723. +static int bcm2835_thermal_probe(struct platform_device *pdev)
  49724. +{
  49725. + print_debug("IN");
  49726. + print_debug("THERMAL Driver has been probed!");
  49727. +
  49728. + /* check that the device isn't null!*/
  49729. + if(pdev == NULL)
  49730. + {
  49731. + print_debug("Platform device is empty!");
  49732. + return -ENODEV;
  49733. + }
  49734. +
  49735. + if(!(bcm2835_data.thermal_dev = thermal_zone_device_register("bcm2835_thermal", 1, 0, NULL, &ops, NULL, 0, 0)))
  49736. + {
  49737. + print_debug("Unable to register the thermal device!");
  49738. + return -EFAULT;
  49739. + }
  49740. + return 0;
  49741. +}
  49742. +
  49743. +
  49744. +static int bcm2835_thermal_remove(struct platform_device *pdev)
  49745. +{
  49746. + print_debug("IN");
  49747. +
  49748. + thermal_zone_device_unregister(bcm2835_data.thermal_dev);
  49749. +
  49750. + print_debug("OUT");
  49751. +
  49752. + return 0;
  49753. +}
  49754. +
  49755. +static struct thermal_zone_device_ops ops = {
  49756. + .get_temp = bcm2835_get_temp,
  49757. + .get_trip_temp = bcm2835_get_max_temp,
  49758. + .get_trip_type = bcm2835_get_trip_type,
  49759. + .get_mode = bcm2835_get_mode,
  49760. +};
  49761. +
  49762. +/* Thermal Driver */
  49763. +static struct platform_driver bcm2835_thermal_driver = {
  49764. + .probe = bcm2835_thermal_probe,
  49765. + .remove = bcm2835_thermal_remove,
  49766. + .driver = {
  49767. + .name = "bcm2835_thermal",
  49768. + .owner = THIS_MODULE,
  49769. + },
  49770. +};
  49771. +
  49772. +MODULE_LICENSE("GPL");
  49773. +MODULE_AUTHOR("Dorian Peake");
  49774. +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
  49775. +
  49776. +module_platform_driver(bcm2835_thermal_driver);
  49777. diff -Nur linux-3.18.6/drivers/thermal/Kconfig linux-rpi/drivers/thermal/Kconfig
  49778. --- linux-3.18.6/drivers/thermal/Kconfig 2015-02-06 15:53:48.000000000 +0100
  49779. +++ linux-rpi/drivers/thermal/Kconfig 2015-02-09 04:40:27.000000000 +0100
  49780. @@ -206,6 +206,12 @@
  49781. enforce idle time which results in more package C-state residency. The
  49782. user interface is exposed via generic thermal framework.
  49783. +config THERMAL_BCM2835
  49784. + tristate "BCM2835 Thermal Driver"
  49785. + help
  49786. + This will enable temperature monitoring for the Broadcom BCM2835
  49787. + chip. If built as a module, it will be called 'bcm2835-thermal'.
  49788. +
  49789. config X86_PKG_TEMP_THERMAL
  49790. tristate "X86 package temperature thermal driver"
  49791. depends on X86_THERMAL_VECTOR
  49792. diff -Nur linux-3.18.6/drivers/thermal/Makefile linux-rpi/drivers/thermal/Makefile
  49793. --- linux-3.18.6/drivers/thermal/Makefile 2015-02-06 15:53:48.000000000 +0100
  49794. +++ linux-rpi/drivers/thermal/Makefile 2015-02-09 04:40:27.000000000 +0100
  49795. @@ -29,6 +29,7 @@
  49796. obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
  49797. obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
  49798. obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
  49799. +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o
  49800. obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o
  49801. obj-$(CONFIG_INTEL_SOC_DTS_THERMAL) += intel_soc_dts_thermal.o
  49802. obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/
  49803. diff -Nur linux-3.18.6/drivers/tty/serial/amba-pl011.c linux-rpi/drivers/tty/serial/amba-pl011.c
  49804. --- linux-3.18.6/drivers/tty/serial/amba-pl011.c 2015-02-06 15:53:48.000000000 +0100
  49805. +++ linux-rpi/drivers/tty/serial/amba-pl011.c 2015-02-09 04:40:28.000000000 +0100
  49806. @@ -84,7 +84,7 @@
  49807. static unsigned int get_fifosize_arm(struct amba_device *dev)
  49808. {
  49809. - return amba_rev(dev) < 3 ? 16 : 32;
  49810. + return 16; //TODO: fix: amba_rev(dev) < 3 ? 16 : 32;
  49811. }
  49812. static struct vendor_data vendor_arm = {
  49813. diff -Nur linux-3.18.6/drivers/usb/core/generic.c linux-rpi/drivers/usb/core/generic.c
  49814. --- linux-3.18.6/drivers/usb/core/generic.c 2015-02-06 15:53:48.000000000 +0100
  49815. +++ linux-rpi/drivers/usb/core/generic.c 2015-02-09 04:40:28.000000000 +0100
  49816. @@ -152,6 +152,7 @@
  49817. dev_warn(&udev->dev,
  49818. "no configuration chosen from %d choice%s\n",
  49819. num_configs, plural(num_configs));
  49820. + dev_warn(&udev->dev, "No support over %dmA\n", udev->bus_mA);
  49821. }
  49822. return i;
  49823. }
  49824. diff -Nur linux-3.18.6/drivers/usb/core/hub.c linux-rpi/drivers/usb/core/hub.c
  49825. --- linux-3.18.6/drivers/usb/core/hub.c 2015-02-06 15:53:48.000000000 +0100
  49826. +++ linux-rpi/drivers/usb/core/hub.c 2015-02-09 04:40:28.000000000 +0100
  49827. @@ -4923,7 +4923,7 @@
  49828. if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
  49829. u16 status = 0, unused;
  49830. - dev_dbg(&port_dev->dev, "over-current change\n");
  49831. + dev_notice(&port_dev->dev, "over-current change\n");
  49832. usb_clear_port_feature(hdev, port1,
  49833. USB_PORT_FEAT_C_OVER_CURRENT);
  49834. msleep(100); /* Cool down */
  49835. diff -Nur linux-3.18.6/drivers/usb/core/message.c linux-rpi/drivers/usb/core/message.c
  49836. --- linux-3.18.6/drivers/usb/core/message.c 2015-02-06 15:53:48.000000000 +0100
  49837. +++ linux-rpi/drivers/usb/core/message.c 2015-02-09 04:40:28.000000000 +0100
  49838. @@ -1889,6 +1889,85 @@
  49839. if (cp->string == NULL &&
  49840. !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
  49841. cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
  49842. +/* Uncomment this define to enable the HS Electrical Test support */
  49843. +#define DWC_HS_ELECT_TST 1
  49844. +#ifdef DWC_HS_ELECT_TST
  49845. + /* Here we implement the HS Electrical Test support. The
  49846. + * tester uses a vendor ID of 0x1A0A to indicate we should
  49847. + * run a special test sequence. The product ID tells us
  49848. + * which sequence to run. We invoke the test sequence by
  49849. + * sending a non-standard SetFeature command to our root
  49850. + * hub port. Our dwc_otg_hcd_hub_control() routine will
  49851. + * recognize the command and perform the desired test
  49852. + * sequence.
  49853. + */
  49854. + if (dev->descriptor.idVendor == 0x1A0A) {
  49855. + /* HSOTG Electrical Test */
  49856. + dev_warn(&dev->dev, "VID from HSOTG Electrical Test Fixture\n");
  49857. +
  49858. + if (dev->bus && dev->bus->root_hub) {
  49859. + struct usb_device *hdev = dev->bus->root_hub;
  49860. + dev_warn(&dev->dev, "Got PID 0x%x\n", dev->descriptor.idProduct);
  49861. +
  49862. + switch (dev->descriptor.idProduct) {
  49863. + case 0x0101: /* TEST_SE0_NAK */
  49864. + dev_warn(&dev->dev, "TEST_SE0_NAK\n");
  49865. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  49866. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  49867. + USB_PORT_FEAT_TEST, 0x300, NULL, 0, HZ);
  49868. + break;
  49869. +
  49870. + case 0x0102: /* TEST_J */
  49871. + dev_warn(&dev->dev, "TEST_J\n");
  49872. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  49873. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  49874. + USB_PORT_FEAT_TEST, 0x100, NULL, 0, HZ);
  49875. + break;
  49876. +
  49877. + case 0x0103: /* TEST_K */
  49878. + dev_warn(&dev->dev, "TEST_K\n");
  49879. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  49880. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  49881. + USB_PORT_FEAT_TEST, 0x200, NULL, 0, HZ);
  49882. + break;
  49883. +
  49884. + case 0x0104: /* TEST_PACKET */
  49885. + dev_warn(&dev->dev, "TEST_PACKET\n");
  49886. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  49887. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  49888. + USB_PORT_FEAT_TEST, 0x400, NULL, 0, HZ);
  49889. + break;
  49890. +
  49891. + case 0x0105: /* TEST_FORCE_ENABLE */
  49892. + dev_warn(&dev->dev, "TEST_FORCE_ENABLE\n");
  49893. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  49894. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  49895. + USB_PORT_FEAT_TEST, 0x500, NULL, 0, HZ);
  49896. + break;
  49897. +
  49898. + case 0x0106: /* HS_HOST_PORT_SUSPEND_RESUME */
  49899. + dev_warn(&dev->dev, "HS_HOST_PORT_SUSPEND_RESUME\n");
  49900. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  49901. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  49902. + USB_PORT_FEAT_TEST, 0x600, NULL, 0, 40 * HZ);
  49903. + break;
  49904. +
  49905. + case 0x0107: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  49906. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup\n");
  49907. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  49908. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  49909. + USB_PORT_FEAT_TEST, 0x700, NULL, 0, 40 * HZ);
  49910. + break;
  49911. +
  49912. + case 0x0108: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  49913. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute\n");
  49914. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  49915. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  49916. + USB_PORT_FEAT_TEST, 0x800, NULL, 0, 40 * HZ);
  49917. + }
  49918. + }
  49919. + }
  49920. +#endif /* DWC_HS_ELECT_TST */
  49921. /* Now that the interfaces are installed, re-enable LPM. */
  49922. usb_unlocked_enable_lpm(dev);
  49923. diff -Nur linux-3.18.6/drivers/usb/core/otg_whitelist.h linux-rpi/drivers/usb/core/otg_whitelist.h
  49924. --- linux-3.18.6/drivers/usb/core/otg_whitelist.h 2015-02-06 15:53:48.000000000 +0100
  49925. +++ linux-rpi/drivers/usb/core/otg_whitelist.h 2015-02-09 04:40:28.000000000 +0100
  49926. @@ -19,33 +19,82 @@
  49927. static struct usb_device_id whitelist_table [] = {
  49928. /* hubs are optional in OTG, but very handy ... */
  49929. +#define CERT_WITHOUT_HUBS
  49930. +#if defined(CERT_WITHOUT_HUBS)
  49931. +{ USB_DEVICE( 0x0000, 0x0000 ), }, /* Root HUB Only*/
  49932. +#else
  49933. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
  49934. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
  49935. +{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 2), },
  49936. +#endif
  49937. #ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
  49938. /* FIXME actually, printers are NOT supposed to use device classes;
  49939. * they're supposed to use interface classes...
  49940. */
  49941. -{ USB_DEVICE_INFO(7, 1, 1) },
  49942. -{ USB_DEVICE_INFO(7, 1, 2) },
  49943. -{ USB_DEVICE_INFO(7, 1, 3) },
  49944. +//{ USB_DEVICE_INFO(7, 1, 1) },
  49945. +//{ USB_DEVICE_INFO(7, 1, 2) },
  49946. +//{ USB_DEVICE_INFO(7, 1, 3) },
  49947. #endif
  49948. #ifdef CONFIG_USB_NET_CDCETHER
  49949. /* Linux-USB CDC Ethernet gadget */
  49950. -{ USB_DEVICE(0x0525, 0xa4a1), },
  49951. +//{ USB_DEVICE(0x0525, 0xa4a1), },
  49952. /* Linux-USB CDC Ethernet + RNDIS gadget */
  49953. -{ USB_DEVICE(0x0525, 0xa4a2), },
  49954. +//{ USB_DEVICE(0x0525, 0xa4a2), },
  49955. #endif
  49956. #if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE)
  49957. /* gadget zero, for testing */
  49958. -{ USB_DEVICE(0x0525, 0xa4a0), },
  49959. +//{ USB_DEVICE(0x0525, 0xa4a0), },
  49960. #endif
  49961. +/* OPT Tester */
  49962. +{ USB_DEVICE( 0x1a0a, 0x0101 ), }, /* TEST_SE0_NAK */
  49963. +{ USB_DEVICE( 0x1a0a, 0x0102 ), }, /* Test_J */
  49964. +{ USB_DEVICE( 0x1a0a, 0x0103 ), }, /* Test_K */
  49965. +{ USB_DEVICE( 0x1a0a, 0x0104 ), }, /* Test_PACKET */
  49966. +{ USB_DEVICE( 0x1a0a, 0x0105 ), }, /* Test_FORCE_ENABLE */
  49967. +{ USB_DEVICE( 0x1a0a, 0x0106 ), }, /* HS_PORT_SUSPEND_RESUME */
  49968. +{ USB_DEVICE( 0x1a0a, 0x0107 ), }, /* SINGLE_STEP_GET_DESCRIPTOR setup */
  49969. +{ USB_DEVICE( 0x1a0a, 0x0108 ), }, /* SINGLE_STEP_GET_DESCRIPTOR execute */
  49970. +
  49971. +/* Sony cameras */
  49972. +{ USB_DEVICE_VER(0x054c,0x0010,0x0410, 0x0500), },
  49973. +
  49974. +/* Memory Devices */
  49975. +//{ USB_DEVICE( 0x0781, 0x5150 ), }, /* SanDisk */
  49976. +//{ USB_DEVICE( 0x05DC, 0x0080 ), }, /* Lexar */
  49977. +//{ USB_DEVICE( 0x4146, 0x9281 ), }, /* IOMEGA */
  49978. +//{ USB_DEVICE( 0x067b, 0x2507 ), }, /* Hammer 20GB External HD */
  49979. +{ USB_DEVICE( 0x0EA0, 0x2168 ), }, /* Ours Technology Inc. (BUFFALO ClipDrive)*/
  49980. +//{ USB_DEVICE( 0x0457, 0x0150 ), }, /* Silicon Integrated Systems Corp. */
  49981. +
  49982. +/* HP Printers */
  49983. +//{ USB_DEVICE( 0x03F0, 0x1102 ), }, /* HP Photosmart 245 */
  49984. +//{ USB_DEVICE( 0x03F0, 0x1302 ), }, /* HP Photosmart 370 Series */
  49985. +
  49986. +/* Speakers */
  49987. +//{ USB_DEVICE( 0x0499, 0x3002 ), }, /* YAMAHA YST-MS35D USB Speakers */
  49988. +//{ USB_DEVICE( 0x0672, 0x1041 ), }, /* Labtec USB Headset */
  49989. +
  49990. { } /* Terminating entry */
  49991. };
  49992. +static inline void report_errors(struct usb_device *dev)
  49993. +{
  49994. + /* OTG MESSAGE: report errors here, customize to match your product */
  49995. + dev_info(&dev->dev, "device Vendor:%04x Product:%04x is not supported\n",
  49996. + le16_to_cpu(dev->descriptor.idVendor),
  49997. + le16_to_cpu(dev->descriptor.idProduct));
  49998. + if (USB_CLASS_HUB == dev->descriptor.bDeviceClass){
  49999. + dev_printk(KERN_CRIT, &dev->dev, "Unsupported Hub Topology\n");
  50000. + } else {
  50001. + dev_printk(KERN_CRIT, &dev->dev, "Attached Device is not Supported\n");
  50002. + }
  50003. +}
  50004. +
  50005. +
  50006. static int is_targeted(struct usb_device *dev)
  50007. {
  50008. struct usb_device_id *id = whitelist_table;
  50009. @@ -95,16 +144,57 @@
  50010. continue;
  50011. return 1;
  50012. - }
  50013. + /* NOTE: can't use usb_match_id() since interface caches
  50014. + * aren't set up yet. this is cut/paste from that code.
  50015. + */
  50016. + for (id = whitelist_table; id->match_flags; id++) {
  50017. +#ifdef DEBUG
  50018. + dev_dbg(&dev->dev,
  50019. + "ID: V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  50020. + id->idVendor,
  50021. + id->idProduct,
  50022. + id->bDeviceClass,
  50023. + id->bDeviceSubClass,
  50024. + id->bDeviceProtocol);
  50025. +#endif
  50026. - /* add other match criteria here ... */
  50027. + if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  50028. + id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  50029. + continue;
  50030. +
  50031. + if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  50032. + id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  50033. + continue;
  50034. +
  50035. + /* No need to test id->bcdDevice_lo != 0, since 0 is never
  50036. + greater than any unsigned number. */
  50037. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  50038. + (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  50039. + continue;
  50040. +
  50041. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  50042. + (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  50043. + continue;
  50044. +
  50045. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  50046. + (id->bDeviceClass != dev->descriptor.bDeviceClass))
  50047. + continue;
  50048. +
  50049. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  50050. + (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  50051. + continue;
  50052. +
  50053. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  50054. + (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  50055. + continue;
  50056. + return 1;
  50057. + }
  50058. + }
  50059. - /* OTG MESSAGE: report errors here, customize to match your product */
  50060. - dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
  50061. - le16_to_cpu(dev->descriptor.idVendor),
  50062. - le16_to_cpu(dev->descriptor.idProduct));
  50063. + /* add other match criteria here ... */
  50064. + report_errors(dev);
  50065. return 0;
  50066. }
  50067. diff -Nur linux-3.18.6/drivers/usb/gadget/file_storage.c linux-rpi/drivers/usb/gadget/file_storage.c
  50068. --- linux-3.18.6/drivers/usb/gadget/file_storage.c 1970-01-01 01:00:00.000000000 +0100
  50069. +++ linux-rpi/drivers/usb/gadget/file_storage.c 2015-02-09 04:40:28.000000000 +0100
  50070. @@ -0,0 +1,3676 @@
  50071. +/*
  50072. + * file_storage.c -- File-backed USB Storage Gadget, for USB development
  50073. + *
  50074. + * Copyright (C) 2003-2008 Alan Stern
  50075. + * All rights reserved.
  50076. + *
  50077. + * Redistribution and use in source and binary forms, with or without
  50078. + * modification, are permitted provided that the following conditions
  50079. + * are met:
  50080. + * 1. Redistributions of source code must retain the above copyright
  50081. + * notice, this list of conditions, and the following disclaimer,
  50082. + * without modification.
  50083. + * 2. Redistributions in binary form must reproduce the above copyright
  50084. + * notice, this list of conditions and the following disclaimer in the
  50085. + * documentation and/or other materials provided with the distribution.
  50086. + * 3. The names of the above-listed copyright holders may not be used
  50087. + * to endorse or promote products derived from this software without
  50088. + * specific prior written permission.
  50089. + *
  50090. + * ALTERNATIVELY, this software may be distributed under the terms of the
  50091. + * GNU General Public License ("GPL") as published by the Free Software
  50092. + * Foundation, either version 2 of that License or (at your option) any
  50093. + * later version.
  50094. + *
  50095. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  50096. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  50097. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50098. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  50099. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  50100. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  50101. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  50102. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  50103. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  50104. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  50105. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  50106. + */
  50107. +
  50108. +
  50109. +/*
  50110. + * The File-backed Storage Gadget acts as a USB Mass Storage device,
  50111. + * appearing to the host as a disk drive or as a CD-ROM drive. In addition
  50112. + * to providing an example of a genuinely useful gadget driver for a USB
  50113. + * device, it also illustrates a technique of double-buffering for increased
  50114. + * throughput. Last but not least, it gives an easy way to probe the
  50115. + * behavior of the Mass Storage drivers in a USB host.
  50116. + *
  50117. + * Backing storage is provided by a regular file or a block device, specified
  50118. + * by the "file" module parameter. Access can be limited to read-only by
  50119. + * setting the optional "ro" module parameter. (For CD-ROM emulation,
  50120. + * access is always read-only.) The gadget will indicate that it has
  50121. + * removable media if the optional "removable" module parameter is set.
  50122. + *
  50123. + * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI),
  50124. + * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected
  50125. + * by the optional "transport" module parameter. It also supports the
  50126. + * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03),
  50127. + * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by
  50128. + * the optional "protocol" module parameter. In addition, the default
  50129. + * Vendor ID, Product ID, release number and serial number can be overridden.
  50130. + *
  50131. + * There is support for multiple logical units (LUNs), each of which has
  50132. + * its own backing file. The number of LUNs can be set using the optional
  50133. + * "luns" module parameter (anywhere from 1 to 8), and the corresponding
  50134. + * files are specified using comma-separated lists for "file" and "ro".
  50135. + * The default number of LUNs is taken from the number of "file" elements;
  50136. + * it is 1 if "file" is not given. If "removable" is not set then a backing
  50137. + * file must be specified for each LUN. If it is set, then an unspecified
  50138. + * or empty backing filename means the LUN's medium is not loaded. Ideally
  50139. + * each LUN would be settable independently as a disk drive or a CD-ROM
  50140. + * drive, but currently all LUNs have to be the same type. The CD-ROM
  50141. + * emulation includes a single data track and no audio tracks; hence there
  50142. + * need be only one backing file per LUN.
  50143. + *
  50144. + * Requirements are modest; only a bulk-in and a bulk-out endpoint are
  50145. + * needed (an interrupt-out endpoint is also needed for CBI). The memory
  50146. + * requirement amounts to two 16K buffers, size configurable by a parameter.
  50147. + * Support is included for both full-speed and high-speed operation.
  50148. + *
  50149. + * Note that the driver is slightly non-portable in that it assumes a
  50150. + * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
  50151. + * interrupt-in endpoints. With most device controllers this isn't an
  50152. + * issue, but there may be some with hardware restrictions that prevent
  50153. + * a buffer from being used by more than one endpoint.
  50154. + *
  50155. + * Module options:
  50156. + *
  50157. + * file=filename[,filename...]
  50158. + * Required if "removable" is not set, names of
  50159. + * the files or block devices used for
  50160. + * backing storage
  50161. + * serial=HHHH... Required serial number (string of hex chars)
  50162. + * ro=b[,b...] Default false, booleans for read-only access
  50163. + * removable Default false, boolean for removable media
  50164. + * luns=N Default N = number of filenames, number of
  50165. + * LUNs to support
  50166. + * nofua=b[,b...] Default false, booleans for ignore FUA flag
  50167. + * in SCSI WRITE(10,12) commands
  50168. + * stall Default determined according to the type of
  50169. + * USB device controller (usually true),
  50170. + * boolean to permit the driver to halt
  50171. + * bulk endpoints
  50172. + * cdrom Default false, boolean for whether to emulate
  50173. + * a CD-ROM drive
  50174. + * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
  50175. + * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
  50176. + * ATAPI, QIC, UFI, 8070, or SCSI;
  50177. + * also 1 - 6)
  50178. + * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
  50179. + * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
  50180. + * release=0xRRRR Override the USB release number (bcdDevice)
  50181. + * buflen=N Default N=16384, buffer size used (will be
  50182. + * rounded down to a multiple of
  50183. + * PAGE_CACHE_SIZE)
  50184. + *
  50185. + * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
  50186. + * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
  50187. + * default values are used for everything else.
  50188. + *
  50189. + * The pathnames of the backing files and the ro settings are available in
  50190. + * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of
  50191. + * the gadget's sysfs directory. If the "removable" option is set, writing to
  50192. + * these files will simulate ejecting/loading the medium (writing an empty
  50193. + * line means eject) and adjusting a write-enable tab. Changes to the ro
  50194. + * setting are not allowed when the medium is loaded or if CD-ROM emulation
  50195. + * is being used.
  50196. + *
  50197. + * This gadget driver is heavily based on "Gadget Zero" by David Brownell.
  50198. + * The driver's SCSI command interface was based on the "Information
  50199. + * technology - Small Computer System Interface - 2" document from
  50200. + * X3T9.2 Project 375D, Revision 10L, 7-SEP-93, available at
  50201. + * <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>. The single exception
  50202. + * is opcode 0x23 (READ FORMAT CAPACITIES), which was based on the
  50203. + * "Universal Serial Bus Mass Storage Class UFI Command Specification"
  50204. + * document, Revision 1.0, December 14, 1998, available at
  50205. + * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
  50206. + */
  50207. +
  50208. +
  50209. +/*
  50210. + * Driver Design
  50211. + *
  50212. + * The FSG driver is fairly straightforward. There is a main kernel
  50213. + * thread that handles most of the work. Interrupt routines field
  50214. + * callbacks from the controller driver: bulk- and interrupt-request
  50215. + * completion notifications, endpoint-0 events, and disconnect events.
  50216. + * Completion events are passed to the main thread by wakeup calls. Many
  50217. + * ep0 requests are handled at interrupt time, but SetInterface,
  50218. + * SetConfiguration, and device reset requests are forwarded to the
  50219. + * thread in the form of "exceptions" using SIGUSR1 signals (since they
  50220. + * should interrupt any ongoing file I/O operations).
  50221. + *
  50222. + * The thread's main routine implements the standard command/data/status
  50223. + * parts of a SCSI interaction. It and its subroutines are full of tests
  50224. + * for pending signals/exceptions -- all this polling is necessary since
  50225. + * the kernel has no setjmp/longjmp equivalents. (Maybe this is an
  50226. + * indication that the driver really wants to be running in userspace.)
  50227. + * An important point is that so long as the thread is alive it keeps an
  50228. + * open reference to the backing file. This will prevent unmounting
  50229. + * the backing file's underlying filesystem and could cause problems
  50230. + * during system shutdown, for example. To prevent such problems, the
  50231. + * thread catches INT, TERM, and KILL signals and converts them into
  50232. + * an EXIT exception.
  50233. + *
  50234. + * In normal operation the main thread is started during the gadget's
  50235. + * fsg_bind() callback and stopped during fsg_unbind(). But it can also
  50236. + * exit when it receives a signal, and there's no point leaving the
  50237. + * gadget running when the thread is dead. So just before the thread
  50238. + * exits, it deregisters the gadget driver. This makes things a little
  50239. + * tricky: The driver is deregistered at two places, and the exiting
  50240. + * thread can indirectly call fsg_unbind() which in turn can tell the
  50241. + * thread to exit. The first problem is resolved through the use of the
  50242. + * REGISTERED atomic bitflag; the driver will only be deregistered once.
  50243. + * The second problem is resolved by having fsg_unbind() check
  50244. + * fsg->state; it won't try to stop the thread if the state is already
  50245. + * FSG_STATE_TERMINATED.
  50246. + *
  50247. + * To provide maximum throughput, the driver uses a circular pipeline of
  50248. + * buffer heads (struct fsg_buffhd). In principle the pipeline can be
  50249. + * arbitrarily long; in practice the benefits don't justify having more
  50250. + * than 2 stages (i.e., double buffering). But it helps to think of the
  50251. + * pipeline as being a long one. Each buffer head contains a bulk-in and
  50252. + * a bulk-out request pointer (since the buffer can be used for both
  50253. + * output and input -- directions always are given from the host's
  50254. + * point of view) as well as a pointer to the buffer and various state
  50255. + * variables.
  50256. + *
  50257. + * Use of the pipeline follows a simple protocol. There is a variable
  50258. + * (fsg->next_buffhd_to_fill) that points to the next buffer head to use.
  50259. + * At any time that buffer head may still be in use from an earlier
  50260. + * request, so each buffer head has a state variable indicating whether
  50261. + * it is EMPTY, FULL, or BUSY. Typical use involves waiting for the
  50262. + * buffer head to be EMPTY, filling the buffer either by file I/O or by
  50263. + * USB I/O (during which the buffer head is BUSY), and marking the buffer
  50264. + * head FULL when the I/O is complete. Then the buffer will be emptied
  50265. + * (again possibly by USB I/O, during which it is marked BUSY) and
  50266. + * finally marked EMPTY again (possibly by a completion routine).
  50267. + *
  50268. + * A module parameter tells the driver to avoid stalling the bulk
  50269. + * endpoints wherever the transport specification allows. This is
  50270. + * necessary for some UDCs like the SuperH, which cannot reliably clear a
  50271. + * halt on a bulk endpoint. However, under certain circumstances the
  50272. + * Bulk-only specification requires a stall. In such cases the driver
  50273. + * will halt the endpoint and set a flag indicating that it should clear
  50274. + * the halt in software during the next device reset. Hopefully this
  50275. + * will permit everything to work correctly. Furthermore, although the
  50276. + * specification allows the bulk-out endpoint to halt when the host sends
  50277. + * too much data, implementing this would cause an unavoidable race.
  50278. + * The driver will always use the "no-stall" approach for OUT transfers.
  50279. + *
  50280. + * One subtle point concerns sending status-stage responses for ep0
  50281. + * requests. Some of these requests, such as device reset, can involve
  50282. + * interrupting an ongoing file I/O operation, which might take an
  50283. + * arbitrarily long time. During that delay the host might give up on
  50284. + * the original ep0 request and issue a new one. When that happens the
  50285. + * driver should not notify the host about completion of the original
  50286. + * request, as the host will no longer be waiting for it. So the driver
  50287. + * assigns to each ep0 request a unique tag, and it keeps track of the
  50288. + * tag value of the request associated with a long-running exception
  50289. + * (device-reset, interface-change, or configuration-change). When the
  50290. + * exception handler is finished, the status-stage response is submitted
  50291. + * only if the current ep0 request tag is equal to the exception request
  50292. + * tag. Thus only the most recently received ep0 request will get a
  50293. + * status-stage response.
  50294. + *
  50295. + * Warning: This driver source file is too long. It ought to be split up
  50296. + * into a header file plus about 3 separate .c files, to handle the details
  50297. + * of the Gadget, USB Mass Storage, and SCSI protocols.
  50298. + */
  50299. +
  50300. +
  50301. +/* #define VERBOSE_DEBUG */
  50302. +/* #define DUMP_MSGS */
  50303. +
  50304. +
  50305. +#include <linux/blkdev.h>
  50306. +#include <linux/completion.h>
  50307. +#include <linux/dcache.h>
  50308. +#include <linux/delay.h>
  50309. +#include <linux/device.h>
  50310. +#include <linux/fcntl.h>
  50311. +#include <linux/file.h>
  50312. +#include <linux/fs.h>
  50313. +#include <linux/kref.h>
  50314. +#include <linux/kthread.h>
  50315. +#include <linux/limits.h>
  50316. +#include <linux/module.h>
  50317. +#include <linux/rwsem.h>
  50318. +#include <linux/slab.h>
  50319. +#include <linux/spinlock.h>
  50320. +#include <linux/string.h>
  50321. +#include <linux/freezer.h>
  50322. +#include <linux/utsname.h>
  50323. +
  50324. +#include <linux/usb/ch9.h>
  50325. +#include <linux/usb/gadget.h>
  50326. +
  50327. +#include "gadget_chips.h"
  50328. +
  50329. +
  50330. +
  50331. +/*
  50332. + * Kbuild is not very cooperative with respect to linking separately
  50333. + * compiled library objects into one module. So for now we won't use
  50334. + * separate compilation ... ensuring init/exit sections work to shrink
  50335. + * the runtime footprint, and giving us at least some parts of what
  50336. + * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  50337. + */
  50338. +#include "usbstring.c"
  50339. +#include "config.c"
  50340. +#include "epautoconf.c"
  50341. +
  50342. +/*-------------------------------------------------------------------------*/
  50343. +
  50344. +#define DRIVER_DESC "File-backed Storage Gadget"
  50345. +#define DRIVER_NAME "g_file_storage"
  50346. +#define DRIVER_VERSION "1 September 2010"
  50347. +
  50348. +static char fsg_string_manufacturer[64];
  50349. +static const char fsg_string_product[] = DRIVER_DESC;
  50350. +static const char fsg_string_config[] = "Self-powered";
  50351. +static const char fsg_string_interface[] = "Mass Storage";
  50352. +
  50353. +
  50354. +#include "storage_common.c"
  50355. +
  50356. +
  50357. +MODULE_DESCRIPTION(DRIVER_DESC);
  50358. +MODULE_AUTHOR("Alan Stern");
  50359. +MODULE_LICENSE("Dual BSD/GPL");
  50360. +
  50361. +/*
  50362. + * This driver assumes self-powered hardware and has no way for users to
  50363. + * trigger remote wakeup. It uses autoconfiguration to select endpoints
  50364. + * and endpoint addresses.
  50365. + */
  50366. +
  50367. +
  50368. +/*-------------------------------------------------------------------------*/
  50369. +
  50370. +
  50371. +/* Encapsulate the module parameter settings */
  50372. +
  50373. +static struct {
  50374. + char *file[FSG_MAX_LUNS];
  50375. + char *serial;
  50376. + bool ro[FSG_MAX_LUNS];
  50377. + bool nofua[FSG_MAX_LUNS];
  50378. + unsigned int num_filenames;
  50379. + unsigned int num_ros;
  50380. + unsigned int num_nofuas;
  50381. + unsigned int nluns;
  50382. +
  50383. + bool removable;
  50384. + bool can_stall;
  50385. + bool cdrom;
  50386. +
  50387. + char *transport_parm;
  50388. + char *protocol_parm;
  50389. + unsigned short vendor;
  50390. + unsigned short product;
  50391. + unsigned short release;
  50392. + unsigned int buflen;
  50393. +
  50394. + int transport_type;
  50395. + char *transport_name;
  50396. + int protocol_type;
  50397. + char *protocol_name;
  50398. +
  50399. +} mod_data = { // Default values
  50400. + .transport_parm = "BBB",
  50401. + .protocol_parm = "SCSI",
  50402. + .removable = 0,
  50403. + .can_stall = 1,
  50404. + .cdrom = 0,
  50405. + .vendor = FSG_VENDOR_ID,
  50406. + .product = FSG_PRODUCT_ID,
  50407. + .release = 0xffff, // Use controller chip type
  50408. + .buflen = 16384,
  50409. + };
  50410. +
  50411. +
  50412. +module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
  50413. + S_IRUGO);
  50414. +MODULE_PARM_DESC(file, "names of backing files or devices");
  50415. +
  50416. +module_param_named(serial, mod_data.serial, charp, S_IRUGO);
  50417. +MODULE_PARM_DESC(serial, "USB serial number");
  50418. +
  50419. +module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
  50420. +MODULE_PARM_DESC(ro, "true to force read-only");
  50421. +
  50422. +module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas,
  50423. + S_IRUGO);
  50424. +MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit");
  50425. +
  50426. +module_param_named(luns, mod_data.nluns, uint, S_IRUGO);
  50427. +MODULE_PARM_DESC(luns, "number of LUNs");
  50428. +
  50429. +module_param_named(removable, mod_data.removable, bool, S_IRUGO);
  50430. +MODULE_PARM_DESC(removable, "true to simulate removable media");
  50431. +
  50432. +module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
  50433. +MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
  50434. +
  50435. +module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
  50436. +MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
  50437. +
  50438. +/* In the non-TEST version, only the module parameters listed above
  50439. + * are available. */
  50440. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  50441. +
  50442. +module_param_named(transport, mod_data.transport_parm, charp, S_IRUGO);
  50443. +MODULE_PARM_DESC(transport, "type of transport (BBB, CBI, or CB)");
  50444. +
  50445. +module_param_named(protocol, mod_data.protocol_parm, charp, S_IRUGO);
  50446. +MODULE_PARM_DESC(protocol, "type of protocol (RBC, 8020, QIC, UFI, "
  50447. + "8070, or SCSI)");
  50448. +
  50449. +module_param_named(vendor, mod_data.vendor, ushort, S_IRUGO);
  50450. +MODULE_PARM_DESC(vendor, "USB Vendor ID");
  50451. +
  50452. +module_param_named(product, mod_data.product, ushort, S_IRUGO);
  50453. +MODULE_PARM_DESC(product, "USB Product ID");
  50454. +
  50455. +module_param_named(release, mod_data.release, ushort, S_IRUGO);
  50456. +MODULE_PARM_DESC(release, "USB release number");
  50457. +
  50458. +module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
  50459. +MODULE_PARM_DESC(buflen, "I/O buffer size");
  50460. +
  50461. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  50462. +
  50463. +
  50464. +/*
  50465. + * These definitions will permit the compiler to avoid generating code for
  50466. + * parts of the driver that aren't used in the non-TEST version. Even gcc
  50467. + * can recognize when a test of a constant expression yields a dead code
  50468. + * path.
  50469. + */
  50470. +
  50471. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  50472. +
  50473. +#define transport_is_bbb() (mod_data.transport_type == USB_PR_BULK)
  50474. +#define transport_is_cbi() (mod_data.transport_type == USB_PR_CBI)
  50475. +#define protocol_is_scsi() (mod_data.protocol_type == USB_SC_SCSI)
  50476. +
  50477. +#else
  50478. +
  50479. +#define transport_is_bbb() 1
  50480. +#define transport_is_cbi() 0
  50481. +#define protocol_is_scsi() 1
  50482. +
  50483. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  50484. +
  50485. +
  50486. +/*-------------------------------------------------------------------------*/
  50487. +
  50488. +
  50489. +struct fsg_dev {
  50490. + /* lock protects: state, all the req_busy's, and cbbuf_cmnd */
  50491. + spinlock_t lock;
  50492. + struct usb_gadget *gadget;
  50493. +
  50494. + /* filesem protects: backing files in use */
  50495. + struct rw_semaphore filesem;
  50496. +
  50497. + /* reference counting: wait until all LUNs are released */
  50498. + struct kref ref;
  50499. +
  50500. + struct usb_ep *ep0; // Handy copy of gadget->ep0
  50501. + struct usb_request *ep0req; // For control responses
  50502. + unsigned int ep0_req_tag;
  50503. + const char *ep0req_name;
  50504. +
  50505. + struct usb_request *intreq; // For interrupt responses
  50506. + int intreq_busy;
  50507. + struct fsg_buffhd *intr_buffhd;
  50508. +
  50509. + unsigned int bulk_out_maxpacket;
  50510. + enum fsg_state state; // For exception handling
  50511. + unsigned int exception_req_tag;
  50512. +
  50513. + u8 config, new_config;
  50514. +
  50515. + unsigned int running : 1;
  50516. + unsigned int bulk_in_enabled : 1;
  50517. + unsigned int bulk_out_enabled : 1;
  50518. + unsigned int intr_in_enabled : 1;
  50519. + unsigned int phase_error : 1;
  50520. + unsigned int short_packet_received : 1;
  50521. + unsigned int bad_lun_okay : 1;
  50522. +
  50523. + unsigned long atomic_bitflags;
  50524. +#define REGISTERED 0
  50525. +#define IGNORE_BULK_OUT 1
  50526. +#define SUSPENDED 2
  50527. +
  50528. + struct usb_ep *bulk_in;
  50529. + struct usb_ep *bulk_out;
  50530. + struct usb_ep *intr_in;
  50531. +
  50532. + struct fsg_buffhd *next_buffhd_to_fill;
  50533. + struct fsg_buffhd *next_buffhd_to_drain;
  50534. +
  50535. + int thread_wakeup_needed;
  50536. + struct completion thread_notifier;
  50537. + struct task_struct *thread_task;
  50538. +
  50539. + int cmnd_size;
  50540. + u8 cmnd[MAX_COMMAND_SIZE];
  50541. + enum data_direction data_dir;
  50542. + u32 data_size;
  50543. + u32 data_size_from_cmnd;
  50544. + u32 tag;
  50545. + unsigned int lun;
  50546. + u32 residue;
  50547. + u32 usb_amount_left;
  50548. +
  50549. + /* The CB protocol offers no way for a host to know when a command
  50550. + * has completed. As a result the next command may arrive early,
  50551. + * and we will still have to handle it. For that reason we need
  50552. + * a buffer to store new commands when using CB (or CBI, which
  50553. + * does not oblige a host to wait for command completion either). */
  50554. + int cbbuf_cmnd_size;
  50555. + u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
  50556. +
  50557. + unsigned int nluns;
  50558. + struct fsg_lun *luns;
  50559. + struct fsg_lun *curlun;
  50560. + /* Must be the last entry */
  50561. + struct fsg_buffhd buffhds[];
  50562. +};
  50563. +
  50564. +typedef void (*fsg_routine_t)(struct fsg_dev *);
  50565. +
  50566. +static int exception_in_progress(struct fsg_dev *fsg)
  50567. +{
  50568. + return (fsg->state > FSG_STATE_IDLE);
  50569. +}
  50570. +
  50571. +/* Make bulk-out requests be divisible by the maxpacket size */
  50572. +static void set_bulk_out_req_length(struct fsg_dev *fsg,
  50573. + struct fsg_buffhd *bh, unsigned int length)
  50574. +{
  50575. + unsigned int rem;
  50576. +
  50577. + bh->bulk_out_intended_length = length;
  50578. + rem = length % fsg->bulk_out_maxpacket;
  50579. + if (rem > 0)
  50580. + length += fsg->bulk_out_maxpacket - rem;
  50581. + bh->outreq->length = length;
  50582. +}
  50583. +
  50584. +static struct fsg_dev *the_fsg;
  50585. +static struct usb_gadget_driver fsg_driver;
  50586. +
  50587. +
  50588. +/*-------------------------------------------------------------------------*/
  50589. +
  50590. +static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
  50591. +{
  50592. + const char *name;
  50593. +
  50594. + if (ep == fsg->bulk_in)
  50595. + name = "bulk-in";
  50596. + else if (ep == fsg->bulk_out)
  50597. + name = "bulk-out";
  50598. + else
  50599. + name = ep->name;
  50600. + DBG(fsg, "%s set halt\n", name);
  50601. + return usb_ep_set_halt(ep);
  50602. +}
  50603. +
  50604. +
  50605. +/*-------------------------------------------------------------------------*/
  50606. +
  50607. +/*
  50608. + * DESCRIPTORS ... most are static, but strings and (full) configuration
  50609. + * descriptors are built on demand. Also the (static) config and interface
  50610. + * descriptors are adjusted during fsg_bind().
  50611. + */
  50612. +
  50613. +/* There is only one configuration. */
  50614. +#define CONFIG_VALUE 1
  50615. +
  50616. +static struct usb_device_descriptor
  50617. +device_desc = {
  50618. + .bLength = sizeof device_desc,
  50619. + .bDescriptorType = USB_DT_DEVICE,
  50620. +
  50621. + .bcdUSB = cpu_to_le16(0x0200),
  50622. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  50623. +
  50624. + /* The next three values can be overridden by module parameters */
  50625. + .idVendor = cpu_to_le16(FSG_VENDOR_ID),
  50626. + .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
  50627. + .bcdDevice = cpu_to_le16(0xffff),
  50628. +
  50629. + .iManufacturer = FSG_STRING_MANUFACTURER,
  50630. + .iProduct = FSG_STRING_PRODUCT,
  50631. + .iSerialNumber = FSG_STRING_SERIAL,
  50632. + .bNumConfigurations = 1,
  50633. +};
  50634. +
  50635. +static struct usb_config_descriptor
  50636. +config_desc = {
  50637. + .bLength = sizeof config_desc,
  50638. + .bDescriptorType = USB_DT_CONFIG,
  50639. +
  50640. + /* wTotalLength computed by usb_gadget_config_buf() */
  50641. + .bNumInterfaces = 1,
  50642. + .bConfigurationValue = CONFIG_VALUE,
  50643. + .iConfiguration = FSG_STRING_CONFIG,
  50644. + .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
  50645. + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
  50646. +};
  50647. +
  50648. +
  50649. +static struct usb_qualifier_descriptor
  50650. +dev_qualifier = {
  50651. + .bLength = sizeof dev_qualifier,
  50652. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  50653. +
  50654. + .bcdUSB = cpu_to_le16(0x0200),
  50655. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  50656. +
  50657. + .bNumConfigurations = 1,
  50658. +};
  50659. +
  50660. +static int populate_bos(struct fsg_dev *fsg, u8 *buf)
  50661. +{
  50662. + memcpy(buf, &fsg_bos_desc, USB_DT_BOS_SIZE);
  50663. + buf += USB_DT_BOS_SIZE;
  50664. +
  50665. + memcpy(buf, &fsg_ext_cap_desc, USB_DT_USB_EXT_CAP_SIZE);
  50666. + buf += USB_DT_USB_EXT_CAP_SIZE;
  50667. +
  50668. + memcpy(buf, &fsg_ss_cap_desc, USB_DT_USB_SS_CAP_SIZE);
  50669. +
  50670. + return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE
  50671. + + USB_DT_USB_EXT_CAP_SIZE;
  50672. +}
  50673. +
  50674. +/*
  50675. + * Config descriptors must agree with the code that sets configurations
  50676. + * and with code managing interfaces and their altsettings. They must
  50677. + * also handle different speeds and other-speed requests.
  50678. + */
  50679. +static int populate_config_buf(struct usb_gadget *gadget,
  50680. + u8 *buf, u8 type, unsigned index)
  50681. +{
  50682. + enum usb_device_speed speed = gadget->speed;
  50683. + int len;
  50684. + const struct usb_descriptor_header **function;
  50685. +
  50686. + if (index > 0)
  50687. + return -EINVAL;
  50688. +
  50689. + if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
  50690. + speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
  50691. + function = gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH
  50692. + ? (const struct usb_descriptor_header **)fsg_hs_function
  50693. + : (const struct usb_descriptor_header **)fsg_fs_function;
  50694. +
  50695. + /* for now, don't advertise srp-only devices */
  50696. + if (!gadget_is_otg(gadget))
  50697. + function++;
  50698. +
  50699. + len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
  50700. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  50701. + return len;
  50702. +}
  50703. +
  50704. +
  50705. +/*-------------------------------------------------------------------------*/
  50706. +
  50707. +/* These routines may be called in process context or in_irq */
  50708. +
  50709. +/* Caller must hold fsg->lock */
  50710. +static void wakeup_thread(struct fsg_dev *fsg)
  50711. +{
  50712. + /* Tell the main thread that something has happened */
  50713. + fsg->thread_wakeup_needed = 1;
  50714. + if (fsg->thread_task)
  50715. + wake_up_process(fsg->thread_task);
  50716. +}
  50717. +
  50718. +
  50719. +static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state)
  50720. +{
  50721. + unsigned long flags;
  50722. +
  50723. + /* Do nothing if a higher-priority exception is already in progress.
  50724. + * If a lower-or-equal priority exception is in progress, preempt it
  50725. + * and notify the main thread by sending it a signal. */
  50726. + spin_lock_irqsave(&fsg->lock, flags);
  50727. + if (fsg->state <= new_state) {
  50728. + fsg->exception_req_tag = fsg->ep0_req_tag;
  50729. + fsg->state = new_state;
  50730. + if (fsg->thread_task)
  50731. + send_sig_info(SIGUSR1, SEND_SIG_FORCED,
  50732. + fsg->thread_task);
  50733. + }
  50734. + spin_unlock_irqrestore(&fsg->lock, flags);
  50735. +}
  50736. +
  50737. +
  50738. +/*-------------------------------------------------------------------------*/
  50739. +
  50740. +/* The disconnect callback and ep0 routines. These always run in_irq,
  50741. + * except that ep0_queue() is called in the main thread to acknowledge
  50742. + * completion of various requests: set config, set interface, and
  50743. + * Bulk-only device reset. */
  50744. +
  50745. +static void fsg_disconnect(struct usb_gadget *gadget)
  50746. +{
  50747. + struct fsg_dev *fsg = get_gadget_data(gadget);
  50748. +
  50749. + DBG(fsg, "disconnect or port reset\n");
  50750. + raise_exception(fsg, FSG_STATE_DISCONNECT);
  50751. +}
  50752. +
  50753. +
  50754. +static int ep0_queue(struct fsg_dev *fsg)
  50755. +{
  50756. + int rc;
  50757. +
  50758. + rc = usb_ep_queue(fsg->ep0, fsg->ep0req, GFP_ATOMIC);
  50759. + if (rc != 0 && rc != -ESHUTDOWN) {
  50760. +
  50761. + /* We can't do much more than wait for a reset */
  50762. + WARNING(fsg, "error in submission: %s --> %d\n",
  50763. + fsg->ep0->name, rc);
  50764. + }
  50765. + return rc;
  50766. +}
  50767. +
  50768. +static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
  50769. +{
  50770. + struct fsg_dev *fsg = ep->driver_data;
  50771. +
  50772. + if (req->actual > 0)
  50773. + dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
  50774. + if (req->status || req->actual != req->length)
  50775. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  50776. + req->status, req->actual, req->length);
  50777. + if (req->status == -ECONNRESET) // Request was cancelled
  50778. + usb_ep_fifo_flush(ep);
  50779. +
  50780. + if (req->status == 0 && req->context)
  50781. + ((fsg_routine_t) (req->context))(fsg);
  50782. +}
  50783. +
  50784. +
  50785. +/*-------------------------------------------------------------------------*/
  50786. +
  50787. +/* Bulk and interrupt endpoint completion handlers.
  50788. + * These always run in_irq. */
  50789. +
  50790. +static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
  50791. +{
  50792. + struct fsg_dev *fsg = ep->driver_data;
  50793. + struct fsg_buffhd *bh = req->context;
  50794. +
  50795. + if (req->status || req->actual != req->length)
  50796. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  50797. + req->status, req->actual, req->length);
  50798. + if (req->status == -ECONNRESET) // Request was cancelled
  50799. + usb_ep_fifo_flush(ep);
  50800. +
  50801. + /* Hold the lock while we update the request and buffer states */
  50802. + smp_wmb();
  50803. + spin_lock(&fsg->lock);
  50804. + bh->inreq_busy = 0;
  50805. + bh->state = BUF_STATE_EMPTY;
  50806. + wakeup_thread(fsg);
  50807. + spin_unlock(&fsg->lock);
  50808. +}
  50809. +
  50810. +static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
  50811. +{
  50812. + struct fsg_dev *fsg = ep->driver_data;
  50813. + struct fsg_buffhd *bh = req->context;
  50814. +
  50815. + dump_msg(fsg, "bulk-out", req->buf, req->actual);
  50816. + if (req->status || req->actual != bh->bulk_out_intended_length)
  50817. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  50818. + req->status, req->actual,
  50819. + bh->bulk_out_intended_length);
  50820. + if (req->status == -ECONNRESET) // Request was cancelled
  50821. + usb_ep_fifo_flush(ep);
  50822. +
  50823. + /* Hold the lock while we update the request and buffer states */
  50824. + smp_wmb();
  50825. + spin_lock(&fsg->lock);
  50826. + bh->outreq_busy = 0;
  50827. + bh->state = BUF_STATE_FULL;
  50828. + wakeup_thread(fsg);
  50829. + spin_unlock(&fsg->lock);
  50830. +}
  50831. +
  50832. +
  50833. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  50834. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  50835. +{
  50836. + struct fsg_dev *fsg = ep->driver_data;
  50837. + struct fsg_buffhd *bh = req->context;
  50838. +
  50839. + if (req->status || req->actual != req->length)
  50840. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  50841. + req->status, req->actual, req->length);
  50842. + if (req->status == -ECONNRESET) // Request was cancelled
  50843. + usb_ep_fifo_flush(ep);
  50844. +
  50845. + /* Hold the lock while we update the request and buffer states */
  50846. + smp_wmb();
  50847. + spin_lock(&fsg->lock);
  50848. + fsg->intreq_busy = 0;
  50849. + bh->state = BUF_STATE_EMPTY;
  50850. + wakeup_thread(fsg);
  50851. + spin_unlock(&fsg->lock);
  50852. +}
  50853. +
  50854. +#else
  50855. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  50856. +{}
  50857. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  50858. +
  50859. +
  50860. +/*-------------------------------------------------------------------------*/
  50861. +
  50862. +/* Ep0 class-specific handlers. These always run in_irq. */
  50863. +
  50864. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  50865. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  50866. +{
  50867. + struct usb_request *req = fsg->ep0req;
  50868. + static u8 cbi_reset_cmnd[6] = {
  50869. + SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
  50870. +
  50871. + /* Error in command transfer? */
  50872. + if (req->status || req->length != req->actual ||
  50873. + req->actual < 6 || req->actual > MAX_COMMAND_SIZE) {
  50874. +
  50875. + /* Not all controllers allow a protocol stall after
  50876. + * receiving control-out data, but we'll try anyway. */
  50877. + fsg_set_halt(fsg, fsg->ep0);
  50878. + return; // Wait for reset
  50879. + }
  50880. +
  50881. + /* Is it the special reset command? */
  50882. + if (req->actual >= sizeof cbi_reset_cmnd &&
  50883. + memcmp(req->buf, cbi_reset_cmnd,
  50884. + sizeof cbi_reset_cmnd) == 0) {
  50885. +
  50886. + /* Raise an exception to stop the current operation
  50887. + * and reinitialize our state. */
  50888. + DBG(fsg, "cbi reset request\n");
  50889. + raise_exception(fsg, FSG_STATE_RESET);
  50890. + return;
  50891. + }
  50892. +
  50893. + VDBG(fsg, "CB[I] accept device-specific command\n");
  50894. + spin_lock(&fsg->lock);
  50895. +
  50896. + /* Save the command for later */
  50897. + if (fsg->cbbuf_cmnd_size)
  50898. + WARNING(fsg, "CB[I] overwriting previous command\n");
  50899. + fsg->cbbuf_cmnd_size = req->actual;
  50900. + memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size);
  50901. +
  50902. + wakeup_thread(fsg);
  50903. + spin_unlock(&fsg->lock);
  50904. +}
  50905. +
  50906. +#else
  50907. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  50908. +{}
  50909. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  50910. +
  50911. +
  50912. +static int class_setup_req(struct fsg_dev *fsg,
  50913. + const struct usb_ctrlrequest *ctrl)
  50914. +{
  50915. + struct usb_request *req = fsg->ep0req;
  50916. + int value = -EOPNOTSUPP;
  50917. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  50918. + u16 w_value = le16_to_cpu(ctrl->wValue);
  50919. + u16 w_length = le16_to_cpu(ctrl->wLength);
  50920. +
  50921. + if (!fsg->config)
  50922. + return value;
  50923. +
  50924. + /* Handle Bulk-only class-specific requests */
  50925. + if (transport_is_bbb()) {
  50926. + switch (ctrl->bRequest) {
  50927. +
  50928. + case US_BULK_RESET_REQUEST:
  50929. + if (ctrl->bRequestType != (USB_DIR_OUT |
  50930. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  50931. + break;
  50932. + if (w_index != 0 || w_value != 0 || w_length != 0) {
  50933. + value = -EDOM;
  50934. + break;
  50935. + }
  50936. +
  50937. + /* Raise an exception to stop the current operation
  50938. + * and reinitialize our state. */
  50939. + DBG(fsg, "bulk reset request\n");
  50940. + raise_exception(fsg, FSG_STATE_RESET);
  50941. + value = DELAYED_STATUS;
  50942. + break;
  50943. +
  50944. + case US_BULK_GET_MAX_LUN:
  50945. + if (ctrl->bRequestType != (USB_DIR_IN |
  50946. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  50947. + break;
  50948. + if (w_index != 0 || w_value != 0 || w_length != 1) {
  50949. + value = -EDOM;
  50950. + break;
  50951. + }
  50952. + VDBG(fsg, "get max LUN\n");
  50953. + *(u8 *) req->buf = fsg->nluns - 1;
  50954. + value = 1;
  50955. + break;
  50956. + }
  50957. + }
  50958. +
  50959. + /* Handle CBI class-specific requests */
  50960. + else {
  50961. + switch (ctrl->bRequest) {
  50962. +
  50963. + case USB_CBI_ADSC_REQUEST:
  50964. + if (ctrl->bRequestType != (USB_DIR_OUT |
  50965. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  50966. + break;
  50967. + if (w_index != 0 || w_value != 0) {
  50968. + value = -EDOM;
  50969. + break;
  50970. + }
  50971. + if (w_length > MAX_COMMAND_SIZE) {
  50972. + value = -EOVERFLOW;
  50973. + break;
  50974. + }
  50975. + value = w_length;
  50976. + fsg->ep0req->context = received_cbi_adsc;
  50977. + break;
  50978. + }
  50979. + }
  50980. +
  50981. + if (value == -EOPNOTSUPP)
  50982. + VDBG(fsg,
  50983. + "unknown class-specific control req "
  50984. + "%02x.%02x v%04x i%04x l%u\n",
  50985. + ctrl->bRequestType, ctrl->bRequest,
  50986. + le16_to_cpu(ctrl->wValue), w_index, w_length);
  50987. + return value;
  50988. +}
  50989. +
  50990. +
  50991. +/*-------------------------------------------------------------------------*/
  50992. +
  50993. +/* Ep0 standard request handlers. These always run in_irq. */
  50994. +
  50995. +static int standard_setup_req(struct fsg_dev *fsg,
  50996. + const struct usb_ctrlrequest *ctrl)
  50997. +{
  50998. + struct usb_request *req = fsg->ep0req;
  50999. + int value = -EOPNOTSUPP;
  51000. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  51001. + u16 w_value = le16_to_cpu(ctrl->wValue);
  51002. +
  51003. + /* Usually this just stores reply data in the pre-allocated ep0 buffer,
  51004. + * but config change events will also reconfigure hardware. */
  51005. + switch (ctrl->bRequest) {
  51006. +
  51007. + case USB_REQ_GET_DESCRIPTOR:
  51008. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  51009. + USB_RECIP_DEVICE))
  51010. + break;
  51011. + switch (w_value >> 8) {
  51012. +
  51013. + case USB_DT_DEVICE:
  51014. + VDBG(fsg, "get device descriptor\n");
  51015. + device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
  51016. + value = sizeof device_desc;
  51017. + memcpy(req->buf, &device_desc, value);
  51018. + break;
  51019. + case USB_DT_DEVICE_QUALIFIER:
  51020. + VDBG(fsg, "get device qualifier\n");
  51021. + if (!gadget_is_dualspeed(fsg->gadget) ||
  51022. + fsg->gadget->speed == USB_SPEED_SUPER)
  51023. + break;
  51024. + /*
  51025. + * Assume ep0 uses the same maxpacket value for both
  51026. + * speeds
  51027. + */
  51028. + dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
  51029. + value = sizeof dev_qualifier;
  51030. + memcpy(req->buf, &dev_qualifier, value);
  51031. + break;
  51032. +
  51033. + case USB_DT_OTHER_SPEED_CONFIG:
  51034. + VDBG(fsg, "get other-speed config descriptor\n");
  51035. + if (!gadget_is_dualspeed(fsg->gadget) ||
  51036. + fsg->gadget->speed == USB_SPEED_SUPER)
  51037. + break;
  51038. + goto get_config;
  51039. + case USB_DT_CONFIG:
  51040. + VDBG(fsg, "get configuration descriptor\n");
  51041. +get_config:
  51042. + value = populate_config_buf(fsg->gadget,
  51043. + req->buf,
  51044. + w_value >> 8,
  51045. + w_value & 0xff);
  51046. + break;
  51047. +
  51048. + case USB_DT_STRING:
  51049. + VDBG(fsg, "get string descriptor\n");
  51050. +
  51051. + /* wIndex == language code */
  51052. + value = usb_gadget_get_string(&fsg_stringtab,
  51053. + w_value & 0xff, req->buf);
  51054. + break;
  51055. +
  51056. + case USB_DT_BOS:
  51057. + VDBG(fsg, "get bos descriptor\n");
  51058. +
  51059. + if (gadget_is_superspeed(fsg->gadget))
  51060. + value = populate_bos(fsg, req->buf);
  51061. + break;
  51062. + }
  51063. +
  51064. + break;
  51065. +
  51066. + /* One config, two speeds */
  51067. + case USB_REQ_SET_CONFIGURATION:
  51068. + if (ctrl->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD |
  51069. + USB_RECIP_DEVICE))
  51070. + break;
  51071. + VDBG(fsg, "set configuration\n");
  51072. + if (w_value == CONFIG_VALUE || w_value == 0) {
  51073. + fsg->new_config = w_value;
  51074. +
  51075. + /* Raise an exception to wipe out previous transaction
  51076. + * state (queued bufs, etc) and set the new config. */
  51077. + raise_exception(fsg, FSG_STATE_CONFIG_CHANGE);
  51078. + value = DELAYED_STATUS;
  51079. + }
  51080. + break;
  51081. + case USB_REQ_GET_CONFIGURATION:
  51082. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  51083. + USB_RECIP_DEVICE))
  51084. + break;
  51085. + VDBG(fsg, "get configuration\n");
  51086. + *(u8 *) req->buf = fsg->config;
  51087. + value = 1;
  51088. + break;
  51089. +
  51090. + case USB_REQ_SET_INTERFACE:
  51091. + if (ctrl->bRequestType != (USB_DIR_OUT| USB_TYPE_STANDARD |
  51092. + USB_RECIP_INTERFACE))
  51093. + break;
  51094. + if (fsg->config && w_index == 0) {
  51095. +
  51096. + /* Raise an exception to wipe out previous transaction
  51097. + * state (queued bufs, etc) and install the new
  51098. + * interface altsetting. */
  51099. + raise_exception(fsg, FSG_STATE_INTERFACE_CHANGE);
  51100. + value = DELAYED_STATUS;
  51101. + }
  51102. + break;
  51103. + case USB_REQ_GET_INTERFACE:
  51104. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  51105. + USB_RECIP_INTERFACE))
  51106. + break;
  51107. + if (!fsg->config)
  51108. + break;
  51109. + if (w_index != 0) {
  51110. + value = -EDOM;
  51111. + break;
  51112. + }
  51113. + VDBG(fsg, "get interface\n");
  51114. + *(u8 *) req->buf = 0;
  51115. + value = 1;
  51116. + break;
  51117. +
  51118. + default:
  51119. + VDBG(fsg,
  51120. + "unknown control req %02x.%02x v%04x i%04x l%u\n",
  51121. + ctrl->bRequestType, ctrl->bRequest,
  51122. + w_value, w_index, le16_to_cpu(ctrl->wLength));
  51123. + }
  51124. +
  51125. + return value;
  51126. +}
  51127. +
  51128. +
  51129. +static int fsg_setup(struct usb_gadget *gadget,
  51130. + const struct usb_ctrlrequest *ctrl)
  51131. +{
  51132. + struct fsg_dev *fsg = get_gadget_data(gadget);
  51133. + int rc;
  51134. + int w_length = le16_to_cpu(ctrl->wLength);
  51135. +
  51136. + ++fsg->ep0_req_tag; // Record arrival of a new request
  51137. + fsg->ep0req->context = NULL;
  51138. + fsg->ep0req->length = 0;
  51139. + dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
  51140. +
  51141. + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS)
  51142. + rc = class_setup_req(fsg, ctrl);
  51143. + else
  51144. + rc = standard_setup_req(fsg, ctrl);
  51145. +
  51146. + /* Respond with data/status or defer until later? */
  51147. + if (rc >= 0 && rc != DELAYED_STATUS) {
  51148. + rc = min(rc, w_length);
  51149. + fsg->ep0req->length = rc;
  51150. + fsg->ep0req->zero = rc < w_length;
  51151. + fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
  51152. + "ep0-in" : "ep0-out");
  51153. + rc = ep0_queue(fsg);
  51154. + }
  51155. +
  51156. + /* Device either stalls (rc < 0) or reports success */
  51157. + return rc;
  51158. +}
  51159. +
  51160. +
  51161. +/*-------------------------------------------------------------------------*/
  51162. +
  51163. +/* All the following routines run in process context */
  51164. +
  51165. +
  51166. +/* Use this for bulk or interrupt transfers, not ep0 */
  51167. +static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
  51168. + struct usb_request *req, int *pbusy,
  51169. + enum fsg_buffer_state *state)
  51170. +{
  51171. + int rc;
  51172. +
  51173. + if (ep == fsg->bulk_in)
  51174. + dump_msg(fsg, "bulk-in", req->buf, req->length);
  51175. + else if (ep == fsg->intr_in)
  51176. + dump_msg(fsg, "intr-in", req->buf, req->length);
  51177. +
  51178. + spin_lock_irq(&fsg->lock);
  51179. + *pbusy = 1;
  51180. + *state = BUF_STATE_BUSY;
  51181. + spin_unlock_irq(&fsg->lock);
  51182. + rc = usb_ep_queue(ep, req, GFP_KERNEL);
  51183. + if (rc != 0) {
  51184. + *pbusy = 0;
  51185. + *state = BUF_STATE_EMPTY;
  51186. +
  51187. + /* We can't do much more than wait for a reset */
  51188. +
  51189. + /* Note: currently the net2280 driver fails zero-length
  51190. + * submissions if DMA is enabled. */
  51191. + if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP &&
  51192. + req->length == 0))
  51193. + WARNING(fsg, "error in submission: %s --> %d\n",
  51194. + ep->name, rc);
  51195. + }
  51196. +}
  51197. +
  51198. +
  51199. +static int sleep_thread(struct fsg_dev *fsg)
  51200. +{
  51201. + int rc = 0;
  51202. +
  51203. + /* Wait until a signal arrives or we are woken up */
  51204. + for (;;) {
  51205. + try_to_freeze();
  51206. + set_current_state(TASK_INTERRUPTIBLE);
  51207. + if (signal_pending(current)) {
  51208. + rc = -EINTR;
  51209. + break;
  51210. + }
  51211. + if (fsg->thread_wakeup_needed)
  51212. + break;
  51213. + schedule();
  51214. + }
  51215. + __set_current_state(TASK_RUNNING);
  51216. + fsg->thread_wakeup_needed = 0;
  51217. + return rc;
  51218. +}
  51219. +
  51220. +
  51221. +/*-------------------------------------------------------------------------*/
  51222. +
  51223. +static int do_read(struct fsg_dev *fsg)
  51224. +{
  51225. + struct fsg_lun *curlun = fsg->curlun;
  51226. + u32 lba;
  51227. + struct fsg_buffhd *bh;
  51228. + int rc;
  51229. + u32 amount_left;
  51230. + loff_t file_offset, file_offset_tmp;
  51231. + unsigned int amount;
  51232. + ssize_t nread;
  51233. +
  51234. + /* Get the starting Logical Block Address and check that it's
  51235. + * not too big */
  51236. + if (fsg->cmnd[0] == READ_6)
  51237. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  51238. + else {
  51239. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  51240. +
  51241. + /* We allow DPO (Disable Page Out = don't save data in the
  51242. + * cache) and FUA (Force Unit Access = don't read from the
  51243. + * cache), but we don't implement them. */
  51244. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  51245. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  51246. + return -EINVAL;
  51247. + }
  51248. + }
  51249. + if (lba >= curlun->num_sectors) {
  51250. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  51251. + return -EINVAL;
  51252. + }
  51253. + file_offset = ((loff_t) lba) << curlun->blkbits;
  51254. +
  51255. + /* Carry out the file reads */
  51256. + amount_left = fsg->data_size_from_cmnd;
  51257. + if (unlikely(amount_left == 0))
  51258. + return -EIO; // No default reply
  51259. +
  51260. + for (;;) {
  51261. +
  51262. + /* Figure out how much we need to read:
  51263. + * Try to read the remaining amount.
  51264. + * But don't read more than the buffer size.
  51265. + * And don't try to read past the end of the file.
  51266. + */
  51267. + amount = min((unsigned int) amount_left, mod_data.buflen);
  51268. + amount = min((loff_t) amount,
  51269. + curlun->file_length - file_offset);
  51270. +
  51271. + /* Wait for the next buffer to become available */
  51272. + bh = fsg->next_buffhd_to_fill;
  51273. + while (bh->state != BUF_STATE_EMPTY) {
  51274. + rc = sleep_thread(fsg);
  51275. + if (rc)
  51276. + return rc;
  51277. + }
  51278. +
  51279. + /* If we were asked to read past the end of file,
  51280. + * end with an empty buffer. */
  51281. + if (amount == 0) {
  51282. + curlun->sense_data =
  51283. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  51284. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  51285. + curlun->info_valid = 1;
  51286. + bh->inreq->length = 0;
  51287. + bh->state = BUF_STATE_FULL;
  51288. + break;
  51289. + }
  51290. +
  51291. + /* Perform the read */
  51292. + file_offset_tmp = file_offset;
  51293. + nread = vfs_read(curlun->filp,
  51294. + (char __user *) bh->buf,
  51295. + amount, &file_offset_tmp);
  51296. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  51297. + (unsigned long long) file_offset,
  51298. + (int) nread);
  51299. + if (signal_pending(current))
  51300. + return -EINTR;
  51301. +
  51302. + if (nread < 0) {
  51303. + LDBG(curlun, "error in file read: %d\n",
  51304. + (int) nread);
  51305. + nread = 0;
  51306. + } else if (nread < amount) {
  51307. + LDBG(curlun, "partial file read: %d/%u\n",
  51308. + (int) nread, amount);
  51309. + nread = round_down(nread, curlun->blksize);
  51310. + }
  51311. + file_offset += nread;
  51312. + amount_left -= nread;
  51313. + fsg->residue -= nread;
  51314. +
  51315. + /* Except at the end of the transfer, nread will be
  51316. + * equal to the buffer size, which is divisible by the
  51317. + * bulk-in maxpacket size.
  51318. + */
  51319. + bh->inreq->length = nread;
  51320. + bh->state = BUF_STATE_FULL;
  51321. +
  51322. + /* If an error occurred, report it and its position */
  51323. + if (nread < amount) {
  51324. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  51325. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  51326. + curlun->info_valid = 1;
  51327. + break;
  51328. + }
  51329. +
  51330. + if (amount_left == 0)
  51331. + break; // No more left to read
  51332. +
  51333. + /* Send this buffer and go read some more */
  51334. + bh->inreq->zero = 0;
  51335. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  51336. + &bh->inreq_busy, &bh->state);
  51337. + fsg->next_buffhd_to_fill = bh->next;
  51338. + }
  51339. +
  51340. + return -EIO; // No default reply
  51341. +}
  51342. +
  51343. +
  51344. +/*-------------------------------------------------------------------------*/
  51345. +
  51346. +static int do_write(struct fsg_dev *fsg)
  51347. +{
  51348. + struct fsg_lun *curlun = fsg->curlun;
  51349. + u32 lba;
  51350. + struct fsg_buffhd *bh;
  51351. + int get_some_more;
  51352. + u32 amount_left_to_req, amount_left_to_write;
  51353. + loff_t usb_offset, file_offset, file_offset_tmp;
  51354. + unsigned int amount;
  51355. + ssize_t nwritten;
  51356. + int rc;
  51357. +
  51358. + if (curlun->ro) {
  51359. + curlun->sense_data = SS_WRITE_PROTECTED;
  51360. + return -EINVAL;
  51361. + }
  51362. + spin_lock(&curlun->filp->f_lock);
  51363. + curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait
  51364. + spin_unlock(&curlun->filp->f_lock);
  51365. +
  51366. + /* Get the starting Logical Block Address and check that it's
  51367. + * not too big */
  51368. + if (fsg->cmnd[0] == WRITE_6)
  51369. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  51370. + else {
  51371. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  51372. +
  51373. + /* We allow DPO (Disable Page Out = don't save data in the
  51374. + * cache) and FUA (Force Unit Access = write directly to the
  51375. + * medium). We don't implement DPO; we implement FUA by
  51376. + * performing synchronous output. */
  51377. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  51378. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  51379. + return -EINVAL;
  51380. + }
  51381. + /* FUA */
  51382. + if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) {
  51383. + spin_lock(&curlun->filp->f_lock);
  51384. + curlun->filp->f_flags |= O_DSYNC;
  51385. + spin_unlock(&curlun->filp->f_lock);
  51386. + }
  51387. + }
  51388. + if (lba >= curlun->num_sectors) {
  51389. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  51390. + return -EINVAL;
  51391. + }
  51392. +
  51393. + /* Carry out the file writes */
  51394. + get_some_more = 1;
  51395. + file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits;
  51396. + amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd;
  51397. +
  51398. + while (amount_left_to_write > 0) {
  51399. +
  51400. + /* Queue a request for more data from the host */
  51401. + bh = fsg->next_buffhd_to_fill;
  51402. + if (bh->state == BUF_STATE_EMPTY && get_some_more) {
  51403. +
  51404. + /* Figure out how much we want to get:
  51405. + * Try to get the remaining amount,
  51406. + * but not more than the buffer size.
  51407. + */
  51408. + amount = min(amount_left_to_req, mod_data.buflen);
  51409. +
  51410. + /* Beyond the end of the backing file? */
  51411. + if (usb_offset >= curlun->file_length) {
  51412. + get_some_more = 0;
  51413. + curlun->sense_data =
  51414. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  51415. + curlun->sense_data_info = usb_offset >> curlun->blkbits;
  51416. + curlun->info_valid = 1;
  51417. + continue;
  51418. + }
  51419. +
  51420. + /* Get the next buffer */
  51421. + usb_offset += amount;
  51422. + fsg->usb_amount_left -= amount;
  51423. + amount_left_to_req -= amount;
  51424. + if (amount_left_to_req == 0)
  51425. + get_some_more = 0;
  51426. +
  51427. + /* Except at the end of the transfer, amount will be
  51428. + * equal to the buffer size, which is divisible by
  51429. + * the bulk-out maxpacket size.
  51430. + */
  51431. + set_bulk_out_req_length(fsg, bh, amount);
  51432. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  51433. + &bh->outreq_busy, &bh->state);
  51434. + fsg->next_buffhd_to_fill = bh->next;
  51435. + continue;
  51436. + }
  51437. +
  51438. + /* Write the received data to the backing file */
  51439. + bh = fsg->next_buffhd_to_drain;
  51440. + if (bh->state == BUF_STATE_EMPTY && !get_some_more)
  51441. + break; // We stopped early
  51442. + if (bh->state == BUF_STATE_FULL) {
  51443. + smp_rmb();
  51444. + fsg->next_buffhd_to_drain = bh->next;
  51445. + bh->state = BUF_STATE_EMPTY;
  51446. +
  51447. + /* Did something go wrong with the transfer? */
  51448. + if (bh->outreq->status != 0) {
  51449. + curlun->sense_data = SS_COMMUNICATION_FAILURE;
  51450. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  51451. + curlun->info_valid = 1;
  51452. + break;
  51453. + }
  51454. +
  51455. + amount = bh->outreq->actual;
  51456. + if (curlun->file_length - file_offset < amount) {
  51457. + LERROR(curlun,
  51458. + "write %u @ %llu beyond end %llu\n",
  51459. + amount, (unsigned long long) file_offset,
  51460. + (unsigned long long) curlun->file_length);
  51461. + amount = curlun->file_length - file_offset;
  51462. + }
  51463. +
  51464. + /* Don't accept excess data. The spec doesn't say
  51465. + * what to do in this case. We'll ignore the error.
  51466. + */
  51467. + amount = min(amount, bh->bulk_out_intended_length);
  51468. +
  51469. + /* Don't write a partial block */
  51470. + amount = round_down(amount, curlun->blksize);
  51471. + if (amount == 0)
  51472. + goto empty_write;
  51473. +
  51474. + /* Perform the write */
  51475. + file_offset_tmp = file_offset;
  51476. + nwritten = vfs_write(curlun->filp,
  51477. + (char __user *) bh->buf,
  51478. + amount, &file_offset_tmp);
  51479. + VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
  51480. + (unsigned long long) file_offset,
  51481. + (int) nwritten);
  51482. + if (signal_pending(current))
  51483. + return -EINTR; // Interrupted!
  51484. +
  51485. + if (nwritten < 0) {
  51486. + LDBG(curlun, "error in file write: %d\n",
  51487. + (int) nwritten);
  51488. + nwritten = 0;
  51489. + } else if (nwritten < amount) {
  51490. + LDBG(curlun, "partial file write: %d/%u\n",
  51491. + (int) nwritten, amount);
  51492. + nwritten = round_down(nwritten, curlun->blksize);
  51493. + }
  51494. + file_offset += nwritten;
  51495. + amount_left_to_write -= nwritten;
  51496. + fsg->residue -= nwritten;
  51497. +
  51498. + /* If an error occurred, report it and its position */
  51499. + if (nwritten < amount) {
  51500. + curlun->sense_data = SS_WRITE_ERROR;
  51501. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  51502. + curlun->info_valid = 1;
  51503. + break;
  51504. + }
  51505. +
  51506. + empty_write:
  51507. + /* Did the host decide to stop early? */
  51508. + if (bh->outreq->actual < bh->bulk_out_intended_length) {
  51509. + fsg->short_packet_received = 1;
  51510. + break;
  51511. + }
  51512. + continue;
  51513. + }
  51514. +
  51515. + /* Wait for something to happen */
  51516. + rc = sleep_thread(fsg);
  51517. + if (rc)
  51518. + return rc;
  51519. + }
  51520. +
  51521. + return -EIO; // No default reply
  51522. +}
  51523. +
  51524. +
  51525. +/*-------------------------------------------------------------------------*/
  51526. +
  51527. +static int do_synchronize_cache(struct fsg_dev *fsg)
  51528. +{
  51529. + struct fsg_lun *curlun = fsg->curlun;
  51530. + int rc;
  51531. +
  51532. + /* We ignore the requested LBA and write out all file's
  51533. + * dirty data buffers. */
  51534. + rc = fsg_lun_fsync_sub(curlun);
  51535. + if (rc)
  51536. + curlun->sense_data = SS_WRITE_ERROR;
  51537. + return 0;
  51538. +}
  51539. +
  51540. +
  51541. +/*-------------------------------------------------------------------------*/
  51542. +
  51543. +static void invalidate_sub(struct fsg_lun *curlun)
  51544. +{
  51545. + struct file *filp = curlun->filp;
  51546. + struct inode *inode = filp->f_path.dentry->d_inode;
  51547. + unsigned long rc;
  51548. +
  51549. + rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
  51550. + VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
  51551. +}
  51552. +
  51553. +static int do_verify(struct fsg_dev *fsg)
  51554. +{
  51555. + struct fsg_lun *curlun = fsg->curlun;
  51556. + u32 lba;
  51557. + u32 verification_length;
  51558. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  51559. + loff_t file_offset, file_offset_tmp;
  51560. + u32 amount_left;
  51561. + unsigned int amount;
  51562. + ssize_t nread;
  51563. +
  51564. + /* Get the starting Logical Block Address and check that it's
  51565. + * not too big */
  51566. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  51567. + if (lba >= curlun->num_sectors) {
  51568. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  51569. + return -EINVAL;
  51570. + }
  51571. +
  51572. + /* We allow DPO (Disable Page Out = don't save data in the
  51573. + * cache) but we don't implement it. */
  51574. + if ((fsg->cmnd[1] & ~0x10) != 0) {
  51575. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  51576. + return -EINVAL;
  51577. + }
  51578. +
  51579. + verification_length = get_unaligned_be16(&fsg->cmnd[7]);
  51580. + if (unlikely(verification_length == 0))
  51581. + return -EIO; // No default reply
  51582. +
  51583. + /* Prepare to carry out the file verify */
  51584. + amount_left = verification_length << curlun->blkbits;
  51585. + file_offset = ((loff_t) lba) << curlun->blkbits;
  51586. +
  51587. + /* Write out all the dirty buffers before invalidating them */
  51588. + fsg_lun_fsync_sub(curlun);
  51589. + if (signal_pending(current))
  51590. + return -EINTR;
  51591. +
  51592. + invalidate_sub(curlun);
  51593. + if (signal_pending(current))
  51594. + return -EINTR;
  51595. +
  51596. + /* Just try to read the requested blocks */
  51597. + while (amount_left > 0) {
  51598. +
  51599. + /* Figure out how much we need to read:
  51600. + * Try to read the remaining amount, but not more than
  51601. + * the buffer size.
  51602. + * And don't try to read past the end of the file.
  51603. + */
  51604. + amount = min((unsigned int) amount_left, mod_data.buflen);
  51605. + amount = min((loff_t) amount,
  51606. + curlun->file_length - file_offset);
  51607. + if (amount == 0) {
  51608. + curlun->sense_data =
  51609. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  51610. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  51611. + curlun->info_valid = 1;
  51612. + break;
  51613. + }
  51614. +
  51615. + /* Perform the read */
  51616. + file_offset_tmp = file_offset;
  51617. + nread = vfs_read(curlun->filp,
  51618. + (char __user *) bh->buf,
  51619. + amount, &file_offset_tmp);
  51620. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  51621. + (unsigned long long) file_offset,
  51622. + (int) nread);
  51623. + if (signal_pending(current))
  51624. + return -EINTR;
  51625. +
  51626. + if (nread < 0) {
  51627. + LDBG(curlun, "error in file verify: %d\n",
  51628. + (int) nread);
  51629. + nread = 0;
  51630. + } else if (nread < amount) {
  51631. + LDBG(curlun, "partial file verify: %d/%u\n",
  51632. + (int) nread, amount);
  51633. + nread = round_down(nread, curlun->blksize);
  51634. + }
  51635. + if (nread == 0) {
  51636. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  51637. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  51638. + curlun->info_valid = 1;
  51639. + break;
  51640. + }
  51641. + file_offset += nread;
  51642. + amount_left -= nread;
  51643. + }
  51644. + return 0;
  51645. +}
  51646. +
  51647. +
  51648. +/*-------------------------------------------------------------------------*/
  51649. +
  51650. +static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  51651. +{
  51652. + u8 *buf = (u8 *) bh->buf;
  51653. +
  51654. + static char vendor_id[] = "Linux ";
  51655. + static char product_disk_id[] = "File-Stor Gadget";
  51656. + static char product_cdrom_id[] = "File-CD Gadget ";
  51657. +
  51658. + if (!fsg->curlun) { // Unsupported LUNs are okay
  51659. + fsg->bad_lun_okay = 1;
  51660. + memset(buf, 0, 36);
  51661. + buf[0] = 0x7f; // Unsupported, no device-type
  51662. + buf[4] = 31; // Additional length
  51663. + return 36;
  51664. + }
  51665. +
  51666. + memset(buf, 0, 8);
  51667. + buf[0] = (mod_data.cdrom ? TYPE_ROM : TYPE_DISK);
  51668. + if (mod_data.removable)
  51669. + buf[1] = 0x80;
  51670. + buf[2] = 2; // ANSI SCSI level 2
  51671. + buf[3] = 2; // SCSI-2 INQUIRY data format
  51672. + buf[4] = 31; // Additional length
  51673. + // No special options
  51674. + sprintf(buf + 8, "%-8s%-16s%04x", vendor_id,
  51675. + (mod_data.cdrom ? product_cdrom_id :
  51676. + product_disk_id),
  51677. + mod_data.release);
  51678. + return 36;
  51679. +}
  51680. +
  51681. +
  51682. +static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  51683. +{
  51684. + struct fsg_lun *curlun = fsg->curlun;
  51685. + u8 *buf = (u8 *) bh->buf;
  51686. + u32 sd, sdinfo;
  51687. + int valid;
  51688. +
  51689. + /*
  51690. + * From the SCSI-2 spec., section 7.9 (Unit attention condition):
  51691. + *
  51692. + * If a REQUEST SENSE command is received from an initiator
  51693. + * with a pending unit attention condition (before the target
  51694. + * generates the contingent allegiance condition), then the
  51695. + * target shall either:
  51696. + * a) report any pending sense data and preserve the unit
  51697. + * attention condition on the logical unit, or,
  51698. + * b) report the unit attention condition, may discard any
  51699. + * pending sense data, and clear the unit attention
  51700. + * condition on the logical unit for that initiator.
  51701. + *
  51702. + * FSG normally uses option a); enable this code to use option b).
  51703. + */
  51704. +#if 0
  51705. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE) {
  51706. + curlun->sense_data = curlun->unit_attention_data;
  51707. + curlun->unit_attention_data = SS_NO_SENSE;
  51708. + }
  51709. +#endif
  51710. +
  51711. + if (!curlun) { // Unsupported LUNs are okay
  51712. + fsg->bad_lun_okay = 1;
  51713. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  51714. + sdinfo = 0;
  51715. + valid = 0;
  51716. + } else {
  51717. + sd = curlun->sense_data;
  51718. + sdinfo = curlun->sense_data_info;
  51719. + valid = curlun->info_valid << 7;
  51720. + curlun->sense_data = SS_NO_SENSE;
  51721. + curlun->sense_data_info = 0;
  51722. + curlun->info_valid = 0;
  51723. + }
  51724. +
  51725. + memset(buf, 0, 18);
  51726. + buf[0] = valid | 0x70; // Valid, current error
  51727. + buf[2] = SK(sd);
  51728. + put_unaligned_be32(sdinfo, &buf[3]); /* Sense information */
  51729. + buf[7] = 18 - 8; // Additional sense length
  51730. + buf[12] = ASC(sd);
  51731. + buf[13] = ASCQ(sd);
  51732. + return 18;
  51733. +}
  51734. +
  51735. +
  51736. +static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  51737. +{
  51738. + struct fsg_lun *curlun = fsg->curlun;
  51739. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  51740. + int pmi = fsg->cmnd[8];
  51741. + u8 *buf = (u8 *) bh->buf;
  51742. +
  51743. + /* Check the PMI and LBA fields */
  51744. + if (pmi > 1 || (pmi == 0 && lba != 0)) {
  51745. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  51746. + return -EINVAL;
  51747. + }
  51748. +
  51749. + put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
  51750. + /* Max logical block */
  51751. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  51752. + return 8;
  51753. +}
  51754. +
  51755. +
  51756. +static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  51757. +{
  51758. + struct fsg_lun *curlun = fsg->curlun;
  51759. + int msf = fsg->cmnd[1] & 0x02;
  51760. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  51761. + u8 *buf = (u8 *) bh->buf;
  51762. +
  51763. + if ((fsg->cmnd[1] & ~0x02) != 0) { /* Mask away MSF */
  51764. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  51765. + return -EINVAL;
  51766. + }
  51767. + if (lba >= curlun->num_sectors) {
  51768. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  51769. + return -EINVAL;
  51770. + }
  51771. +
  51772. + memset(buf, 0, 8);
  51773. + buf[0] = 0x01; /* 2048 bytes of user data, rest is EC */
  51774. + store_cdrom_address(&buf[4], msf, lba);
  51775. + return 8;
  51776. +}
  51777. +
  51778. +
  51779. +static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  51780. +{
  51781. + struct fsg_lun *curlun = fsg->curlun;
  51782. + int msf = fsg->cmnd[1] & 0x02;
  51783. + int start_track = fsg->cmnd[6];
  51784. + u8 *buf = (u8 *) bh->buf;
  51785. +
  51786. + if ((fsg->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
  51787. + start_track > 1) {
  51788. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  51789. + return -EINVAL;
  51790. + }
  51791. +
  51792. + memset(buf, 0, 20);
  51793. + buf[1] = (20-2); /* TOC data length */
  51794. + buf[2] = 1; /* First track number */
  51795. + buf[3] = 1; /* Last track number */
  51796. + buf[5] = 0x16; /* Data track, copying allowed */
  51797. + buf[6] = 0x01; /* Only track is number 1 */
  51798. + store_cdrom_address(&buf[8], msf, 0);
  51799. +
  51800. + buf[13] = 0x16; /* Lead-out track is data */
  51801. + buf[14] = 0xAA; /* Lead-out track number */
  51802. + store_cdrom_address(&buf[16], msf, curlun->num_sectors);
  51803. + return 20;
  51804. +}
  51805. +
  51806. +
  51807. +static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  51808. +{
  51809. + struct fsg_lun *curlun = fsg->curlun;
  51810. + int mscmnd = fsg->cmnd[0];
  51811. + u8 *buf = (u8 *) bh->buf;
  51812. + u8 *buf0 = buf;
  51813. + int pc, page_code;
  51814. + int changeable_values, all_pages;
  51815. + int valid_page = 0;
  51816. + int len, limit;
  51817. +
  51818. + if ((fsg->cmnd[1] & ~0x08) != 0) { // Mask away DBD
  51819. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  51820. + return -EINVAL;
  51821. + }
  51822. + pc = fsg->cmnd[2] >> 6;
  51823. + page_code = fsg->cmnd[2] & 0x3f;
  51824. + if (pc == 3) {
  51825. + curlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
  51826. + return -EINVAL;
  51827. + }
  51828. + changeable_values = (pc == 1);
  51829. + all_pages = (page_code == 0x3f);
  51830. +
  51831. + /* Write the mode parameter header. Fixed values are: default
  51832. + * medium type, no cache control (DPOFUA), and no block descriptors.
  51833. + * The only variable value is the WriteProtect bit. We will fill in
  51834. + * the mode data length later. */
  51835. + memset(buf, 0, 8);
  51836. + if (mscmnd == MODE_SENSE) {
  51837. + buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  51838. + buf += 4;
  51839. + limit = 255;
  51840. + } else { // MODE_SENSE_10
  51841. + buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  51842. + buf += 8;
  51843. + limit = 65535; // Should really be mod_data.buflen
  51844. + }
  51845. +
  51846. + /* No block descriptors */
  51847. +
  51848. + /* The mode pages, in numerical order. The only page we support
  51849. + * is the Caching page. */
  51850. + if (page_code == 0x08 || all_pages) {
  51851. + valid_page = 1;
  51852. + buf[0] = 0x08; // Page code
  51853. + buf[1] = 10; // Page length
  51854. + memset(buf+2, 0, 10); // None of the fields are changeable
  51855. +
  51856. + if (!changeable_values) {
  51857. + buf[2] = 0x04; // Write cache enable,
  51858. + // Read cache not disabled
  51859. + // No cache retention priorities
  51860. + put_unaligned_be16(0xffff, &buf[4]);
  51861. + /* Don't disable prefetch */
  51862. + /* Minimum prefetch = 0 */
  51863. + put_unaligned_be16(0xffff, &buf[8]);
  51864. + /* Maximum prefetch */
  51865. + put_unaligned_be16(0xffff, &buf[10]);
  51866. + /* Maximum prefetch ceiling */
  51867. + }
  51868. + buf += 12;
  51869. + }
  51870. +
  51871. + /* Check that a valid page was requested and the mode data length
  51872. + * isn't too long. */
  51873. + len = buf - buf0;
  51874. + if (!valid_page || len > limit) {
  51875. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  51876. + return -EINVAL;
  51877. + }
  51878. +
  51879. + /* Store the mode data length */
  51880. + if (mscmnd == MODE_SENSE)
  51881. + buf0[0] = len - 1;
  51882. + else
  51883. + put_unaligned_be16(len - 2, buf0);
  51884. + return len;
  51885. +}
  51886. +
  51887. +
  51888. +static int do_start_stop(struct fsg_dev *fsg)
  51889. +{
  51890. + struct fsg_lun *curlun = fsg->curlun;
  51891. + int loej, start;
  51892. +
  51893. + if (!mod_data.removable) {
  51894. + curlun->sense_data = SS_INVALID_COMMAND;
  51895. + return -EINVAL;
  51896. + }
  51897. +
  51898. + // int immed = fsg->cmnd[1] & 0x01;
  51899. + loej = fsg->cmnd[4] & 0x02;
  51900. + start = fsg->cmnd[4] & 0x01;
  51901. +
  51902. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  51903. + if ((fsg->cmnd[1] & ~0x01) != 0 || // Mask away Immed
  51904. + (fsg->cmnd[4] & ~0x03) != 0) { // Mask LoEj, Start
  51905. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  51906. + return -EINVAL;
  51907. + }
  51908. +
  51909. + if (!start) {
  51910. +
  51911. + /* Are we allowed to unload the media? */
  51912. + if (curlun->prevent_medium_removal) {
  51913. + LDBG(curlun, "unload attempt prevented\n");
  51914. + curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
  51915. + return -EINVAL;
  51916. + }
  51917. + if (loej) { // Simulate an unload/eject
  51918. + up_read(&fsg->filesem);
  51919. + down_write(&fsg->filesem);
  51920. + fsg_lun_close(curlun);
  51921. + up_write(&fsg->filesem);
  51922. + down_read(&fsg->filesem);
  51923. + }
  51924. + } else {
  51925. +
  51926. + /* Our emulation doesn't support mounting; the medium is
  51927. + * available for use as soon as it is loaded. */
  51928. + if (!fsg_lun_is_open(curlun)) {
  51929. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  51930. + return -EINVAL;
  51931. + }
  51932. + }
  51933. +#endif
  51934. + return 0;
  51935. +}
  51936. +
  51937. +
  51938. +static int do_prevent_allow(struct fsg_dev *fsg)
  51939. +{
  51940. + struct fsg_lun *curlun = fsg->curlun;
  51941. + int prevent;
  51942. +
  51943. + if (!mod_data.removable) {
  51944. + curlun->sense_data = SS_INVALID_COMMAND;
  51945. + return -EINVAL;
  51946. + }
  51947. +
  51948. + prevent = fsg->cmnd[4] & 0x01;
  51949. + if ((fsg->cmnd[4] & ~0x01) != 0) { // Mask away Prevent
  51950. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  51951. + return -EINVAL;
  51952. + }
  51953. +
  51954. + if (curlun->prevent_medium_removal && !prevent)
  51955. + fsg_lun_fsync_sub(curlun);
  51956. + curlun->prevent_medium_removal = prevent;
  51957. + return 0;
  51958. +}
  51959. +
  51960. +
  51961. +static int do_read_format_capacities(struct fsg_dev *fsg,
  51962. + struct fsg_buffhd *bh)
  51963. +{
  51964. + struct fsg_lun *curlun = fsg->curlun;
  51965. + u8 *buf = (u8 *) bh->buf;
  51966. +
  51967. + buf[0] = buf[1] = buf[2] = 0;
  51968. + buf[3] = 8; // Only the Current/Maximum Capacity Descriptor
  51969. + buf += 4;
  51970. +
  51971. + put_unaligned_be32(curlun->num_sectors, &buf[0]);
  51972. + /* Number of blocks */
  51973. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  51974. + buf[4] = 0x02; /* Current capacity */
  51975. + return 12;
  51976. +}
  51977. +
  51978. +
  51979. +static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  51980. +{
  51981. + struct fsg_lun *curlun = fsg->curlun;
  51982. +
  51983. + /* We don't support MODE SELECT */
  51984. + curlun->sense_data = SS_INVALID_COMMAND;
  51985. + return -EINVAL;
  51986. +}
  51987. +
  51988. +
  51989. +/*-------------------------------------------------------------------------*/
  51990. +
  51991. +static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
  51992. +{
  51993. + int rc;
  51994. +
  51995. + rc = fsg_set_halt(fsg, fsg->bulk_in);
  51996. + if (rc == -EAGAIN)
  51997. + VDBG(fsg, "delayed bulk-in endpoint halt\n");
  51998. + while (rc != 0) {
  51999. + if (rc != -EAGAIN) {
  52000. + WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
  52001. + rc = 0;
  52002. + break;
  52003. + }
  52004. +
  52005. + /* Wait for a short time and then try again */
  52006. + if (msleep_interruptible(100) != 0)
  52007. + return -EINTR;
  52008. + rc = usb_ep_set_halt(fsg->bulk_in);
  52009. + }
  52010. + return rc;
  52011. +}
  52012. +
  52013. +static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
  52014. +{
  52015. + int rc;
  52016. +
  52017. + DBG(fsg, "bulk-in set wedge\n");
  52018. + rc = usb_ep_set_wedge(fsg->bulk_in);
  52019. + if (rc == -EAGAIN)
  52020. + VDBG(fsg, "delayed bulk-in endpoint wedge\n");
  52021. + while (rc != 0) {
  52022. + if (rc != -EAGAIN) {
  52023. + WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
  52024. + rc = 0;
  52025. + break;
  52026. + }
  52027. +
  52028. + /* Wait for a short time and then try again */
  52029. + if (msleep_interruptible(100) != 0)
  52030. + return -EINTR;
  52031. + rc = usb_ep_set_wedge(fsg->bulk_in);
  52032. + }
  52033. + return rc;
  52034. +}
  52035. +
  52036. +static int throw_away_data(struct fsg_dev *fsg)
  52037. +{
  52038. + struct fsg_buffhd *bh;
  52039. + u32 amount;
  52040. + int rc;
  52041. +
  52042. + while ((bh = fsg->next_buffhd_to_drain)->state != BUF_STATE_EMPTY ||
  52043. + fsg->usb_amount_left > 0) {
  52044. +
  52045. + /* Throw away the data in a filled buffer */
  52046. + if (bh->state == BUF_STATE_FULL) {
  52047. + smp_rmb();
  52048. + bh->state = BUF_STATE_EMPTY;
  52049. + fsg->next_buffhd_to_drain = bh->next;
  52050. +
  52051. + /* A short packet or an error ends everything */
  52052. + if (bh->outreq->actual < bh->bulk_out_intended_length ||
  52053. + bh->outreq->status != 0) {
  52054. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  52055. + return -EINTR;
  52056. + }
  52057. + continue;
  52058. + }
  52059. +
  52060. + /* Try to submit another request if we need one */
  52061. + bh = fsg->next_buffhd_to_fill;
  52062. + if (bh->state == BUF_STATE_EMPTY && fsg->usb_amount_left > 0) {
  52063. + amount = min(fsg->usb_amount_left,
  52064. + (u32) mod_data.buflen);
  52065. +
  52066. + /* Except at the end of the transfer, amount will be
  52067. + * equal to the buffer size, which is divisible by
  52068. + * the bulk-out maxpacket size.
  52069. + */
  52070. + set_bulk_out_req_length(fsg, bh, amount);
  52071. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  52072. + &bh->outreq_busy, &bh->state);
  52073. + fsg->next_buffhd_to_fill = bh->next;
  52074. + fsg->usb_amount_left -= amount;
  52075. + continue;
  52076. + }
  52077. +
  52078. + /* Otherwise wait for something to happen */
  52079. + rc = sleep_thread(fsg);
  52080. + if (rc)
  52081. + return rc;
  52082. + }
  52083. + return 0;
  52084. +}
  52085. +
  52086. +
  52087. +static int finish_reply(struct fsg_dev *fsg)
  52088. +{
  52089. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  52090. + int rc = 0;
  52091. +
  52092. + switch (fsg->data_dir) {
  52093. + case DATA_DIR_NONE:
  52094. + break; // Nothing to send
  52095. +
  52096. + /* If we don't know whether the host wants to read or write,
  52097. + * this must be CB or CBI with an unknown command. We mustn't
  52098. + * try to send or receive any data. So stall both bulk pipes
  52099. + * if we can and wait for a reset. */
  52100. + case DATA_DIR_UNKNOWN:
  52101. + if (mod_data.can_stall) {
  52102. + fsg_set_halt(fsg, fsg->bulk_out);
  52103. + rc = halt_bulk_in_endpoint(fsg);
  52104. + }
  52105. + break;
  52106. +
  52107. + /* All but the last buffer of data must have already been sent */
  52108. + case DATA_DIR_TO_HOST:
  52109. + if (fsg->data_size == 0)
  52110. + ; // Nothing to send
  52111. +
  52112. + /* If there's no residue, simply send the last buffer */
  52113. + else if (fsg->residue == 0) {
  52114. + bh->inreq->zero = 0;
  52115. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  52116. + &bh->inreq_busy, &bh->state);
  52117. + fsg->next_buffhd_to_fill = bh->next;
  52118. + }
  52119. +
  52120. + /* There is a residue. For CB and CBI, simply mark the end
  52121. + * of the data with a short packet. However, if we are
  52122. + * allowed to stall, there was no data at all (residue ==
  52123. + * data_size), and the command failed (invalid LUN or
  52124. + * sense data is set), then halt the bulk-in endpoint
  52125. + * instead. */
  52126. + else if (!transport_is_bbb()) {
  52127. + if (mod_data.can_stall &&
  52128. + fsg->residue == fsg->data_size &&
  52129. + (!fsg->curlun || fsg->curlun->sense_data != SS_NO_SENSE)) {
  52130. + bh->state = BUF_STATE_EMPTY;
  52131. + rc = halt_bulk_in_endpoint(fsg);
  52132. + } else {
  52133. + bh->inreq->zero = 1;
  52134. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  52135. + &bh->inreq_busy, &bh->state);
  52136. + fsg->next_buffhd_to_fill = bh->next;
  52137. + }
  52138. + }
  52139. +
  52140. + /*
  52141. + * For Bulk-only, mark the end of the data with a short
  52142. + * packet. If we are allowed to stall, halt the bulk-in
  52143. + * endpoint. (Note: This violates the Bulk-Only Transport
  52144. + * specification, which requires us to pad the data if we
  52145. + * don't halt the endpoint. Presumably nobody will mind.)
  52146. + */
  52147. + else {
  52148. + bh->inreq->zero = 1;
  52149. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  52150. + &bh->inreq_busy, &bh->state);
  52151. + fsg->next_buffhd_to_fill = bh->next;
  52152. + if (mod_data.can_stall)
  52153. + rc = halt_bulk_in_endpoint(fsg);
  52154. + }
  52155. + break;
  52156. +
  52157. + /* We have processed all we want from the data the host has sent.
  52158. + * There may still be outstanding bulk-out requests. */
  52159. + case DATA_DIR_FROM_HOST:
  52160. + if (fsg->residue == 0)
  52161. + ; // Nothing to receive
  52162. +
  52163. + /* Did the host stop sending unexpectedly early? */
  52164. + else if (fsg->short_packet_received) {
  52165. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  52166. + rc = -EINTR;
  52167. + }
  52168. +
  52169. + /* We haven't processed all the incoming data. Even though
  52170. + * we may be allowed to stall, doing so would cause a race.
  52171. + * The controller may already have ACK'ed all the remaining
  52172. + * bulk-out packets, in which case the host wouldn't see a
  52173. + * STALL. Not realizing the endpoint was halted, it wouldn't
  52174. + * clear the halt -- leading to problems later on. */
  52175. +#if 0
  52176. + else if (mod_data.can_stall) {
  52177. + fsg_set_halt(fsg, fsg->bulk_out);
  52178. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  52179. + rc = -EINTR;
  52180. + }
  52181. +#endif
  52182. +
  52183. + /* We can't stall. Read in the excess data and throw it
  52184. + * all away. */
  52185. + else
  52186. + rc = throw_away_data(fsg);
  52187. + break;
  52188. + }
  52189. + return rc;
  52190. +}
  52191. +
  52192. +
  52193. +static int send_status(struct fsg_dev *fsg)
  52194. +{
  52195. + struct fsg_lun *curlun = fsg->curlun;
  52196. + struct fsg_buffhd *bh;
  52197. + int rc;
  52198. + u8 status = US_BULK_STAT_OK;
  52199. + u32 sd, sdinfo = 0;
  52200. +
  52201. + /* Wait for the next buffer to become available */
  52202. + bh = fsg->next_buffhd_to_fill;
  52203. + while (bh->state != BUF_STATE_EMPTY) {
  52204. + rc = sleep_thread(fsg);
  52205. + if (rc)
  52206. + return rc;
  52207. + }
  52208. +
  52209. + if (curlun) {
  52210. + sd = curlun->sense_data;
  52211. + sdinfo = curlun->sense_data_info;
  52212. + } else if (fsg->bad_lun_okay)
  52213. + sd = SS_NO_SENSE;
  52214. + else
  52215. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  52216. +
  52217. + if (fsg->phase_error) {
  52218. + DBG(fsg, "sending phase-error status\n");
  52219. + status = US_BULK_STAT_PHASE;
  52220. + sd = SS_INVALID_COMMAND;
  52221. + } else if (sd != SS_NO_SENSE) {
  52222. + DBG(fsg, "sending command-failure status\n");
  52223. + status = US_BULK_STAT_FAIL;
  52224. + VDBG(fsg, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
  52225. + " info x%x\n",
  52226. + SK(sd), ASC(sd), ASCQ(sd), sdinfo);
  52227. + }
  52228. +
  52229. + if (transport_is_bbb()) {
  52230. + struct bulk_cs_wrap *csw = bh->buf;
  52231. +
  52232. + /* Store and send the Bulk-only CSW */
  52233. + csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
  52234. + csw->Tag = fsg->tag;
  52235. + csw->Residue = cpu_to_le32(fsg->residue);
  52236. + csw->Status = status;
  52237. +
  52238. + bh->inreq->length = US_BULK_CS_WRAP_LEN;
  52239. + bh->inreq->zero = 0;
  52240. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  52241. + &bh->inreq_busy, &bh->state);
  52242. +
  52243. + } else if (mod_data.transport_type == USB_PR_CB) {
  52244. +
  52245. + /* Control-Bulk transport has no status phase! */
  52246. + return 0;
  52247. +
  52248. + } else { // USB_PR_CBI
  52249. + struct interrupt_data *buf = bh->buf;
  52250. +
  52251. + /* Store and send the Interrupt data. UFI sends the ASC
  52252. + * and ASCQ bytes. Everything else sends a Type (which
  52253. + * is always 0) and the status Value. */
  52254. + if (mod_data.protocol_type == USB_SC_UFI) {
  52255. + buf->bType = ASC(sd);
  52256. + buf->bValue = ASCQ(sd);
  52257. + } else {
  52258. + buf->bType = 0;
  52259. + buf->bValue = status;
  52260. + }
  52261. + fsg->intreq->length = CBI_INTERRUPT_DATA_LEN;
  52262. +
  52263. + fsg->intr_buffhd = bh; // Point to the right buffhd
  52264. + fsg->intreq->buf = bh->inreq->buf;
  52265. + fsg->intreq->context = bh;
  52266. + start_transfer(fsg, fsg->intr_in, fsg->intreq,
  52267. + &fsg->intreq_busy, &bh->state);
  52268. + }
  52269. +
  52270. + fsg->next_buffhd_to_fill = bh->next;
  52271. + return 0;
  52272. +}
  52273. +
  52274. +
  52275. +/*-------------------------------------------------------------------------*/
  52276. +
  52277. +/* Check whether the command is properly formed and whether its data size
  52278. + * and direction agree with the values we already have. */
  52279. +static int check_command(struct fsg_dev *fsg, int cmnd_size,
  52280. + enum data_direction data_dir, unsigned int mask,
  52281. + int needs_medium, const char *name)
  52282. +{
  52283. + int i;
  52284. + int lun = fsg->cmnd[1] >> 5;
  52285. + static const char dirletter[4] = {'u', 'o', 'i', 'n'};
  52286. + char hdlen[20];
  52287. + struct fsg_lun *curlun;
  52288. +
  52289. + /* Adjust the expected cmnd_size for protocol encapsulation padding.
  52290. + * Transparent SCSI doesn't pad. */
  52291. + if (protocol_is_scsi())
  52292. + ;
  52293. +
  52294. + /* There's some disagreement as to whether RBC pads commands or not.
  52295. + * We'll play it safe and accept either form. */
  52296. + else if (mod_data.protocol_type == USB_SC_RBC) {
  52297. + if (fsg->cmnd_size == 12)
  52298. + cmnd_size = 12;
  52299. +
  52300. + /* All the other protocols pad to 12 bytes */
  52301. + } else
  52302. + cmnd_size = 12;
  52303. +
  52304. + hdlen[0] = 0;
  52305. + if (fsg->data_dir != DATA_DIR_UNKNOWN)
  52306. + sprintf(hdlen, ", H%c=%u", dirletter[(int) fsg->data_dir],
  52307. + fsg->data_size);
  52308. + VDBG(fsg, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n",
  52309. + name, cmnd_size, dirletter[(int) data_dir],
  52310. + fsg->data_size_from_cmnd, fsg->cmnd_size, hdlen);
  52311. +
  52312. + /* We can't reply at all until we know the correct data direction
  52313. + * and size. */
  52314. + if (fsg->data_size_from_cmnd == 0)
  52315. + data_dir = DATA_DIR_NONE;
  52316. + if (fsg->data_dir == DATA_DIR_UNKNOWN) { // CB or CBI
  52317. + fsg->data_dir = data_dir;
  52318. + fsg->data_size = fsg->data_size_from_cmnd;
  52319. +
  52320. + } else { // Bulk-only
  52321. + if (fsg->data_size < fsg->data_size_from_cmnd) {
  52322. +
  52323. + /* Host data size < Device data size is a phase error.
  52324. + * Carry out the command, but only transfer as much
  52325. + * as we are allowed. */
  52326. + fsg->data_size_from_cmnd = fsg->data_size;
  52327. + fsg->phase_error = 1;
  52328. + }
  52329. + }
  52330. + fsg->residue = fsg->usb_amount_left = fsg->data_size;
  52331. +
  52332. + /* Conflicting data directions is a phase error */
  52333. + if (fsg->data_dir != data_dir && fsg->data_size_from_cmnd > 0) {
  52334. + fsg->phase_error = 1;
  52335. + return -EINVAL;
  52336. + }
  52337. +
  52338. + /* Verify the length of the command itself */
  52339. + if (cmnd_size != fsg->cmnd_size) {
  52340. +
  52341. + /* Special case workaround: There are plenty of buggy SCSI
  52342. + * implementations. Many have issues with cbw->Length
  52343. + * field passing a wrong command size. For those cases we
  52344. + * always try to work around the problem by using the length
  52345. + * sent by the host side provided it is at least as large
  52346. + * as the correct command length.
  52347. + * Examples of such cases would be MS-Windows, which issues
  52348. + * REQUEST SENSE with cbw->Length == 12 where it should
  52349. + * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
  52350. + * REQUEST SENSE with cbw->Length == 10 where it should
  52351. + * be 6 as well.
  52352. + */
  52353. + if (cmnd_size <= fsg->cmnd_size) {
  52354. + DBG(fsg, "%s is buggy! Expected length %d "
  52355. + "but we got %d\n", name,
  52356. + cmnd_size, fsg->cmnd_size);
  52357. + cmnd_size = fsg->cmnd_size;
  52358. + } else {
  52359. + fsg->phase_error = 1;
  52360. + return -EINVAL;
  52361. + }
  52362. + }
  52363. +
  52364. + /* Check that the LUN values are consistent */
  52365. + if (transport_is_bbb()) {
  52366. + if (fsg->lun != lun)
  52367. + DBG(fsg, "using LUN %d from CBW, "
  52368. + "not LUN %d from CDB\n",
  52369. + fsg->lun, lun);
  52370. + }
  52371. +
  52372. + /* Check the LUN */
  52373. + curlun = fsg->curlun;
  52374. + if (curlun) {
  52375. + if (fsg->cmnd[0] != REQUEST_SENSE) {
  52376. + curlun->sense_data = SS_NO_SENSE;
  52377. + curlun->sense_data_info = 0;
  52378. + curlun->info_valid = 0;
  52379. + }
  52380. + } else {
  52381. + fsg->bad_lun_okay = 0;
  52382. +
  52383. + /* INQUIRY and REQUEST SENSE commands are explicitly allowed
  52384. + * to use unsupported LUNs; all others may not. */
  52385. + if (fsg->cmnd[0] != INQUIRY &&
  52386. + fsg->cmnd[0] != REQUEST_SENSE) {
  52387. + DBG(fsg, "unsupported LUN %d\n", fsg->lun);
  52388. + return -EINVAL;
  52389. + }
  52390. + }
  52391. +
  52392. + /* If a unit attention condition exists, only INQUIRY and
  52393. + * REQUEST SENSE commands are allowed; anything else must fail. */
  52394. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
  52395. + fsg->cmnd[0] != INQUIRY &&
  52396. + fsg->cmnd[0] != REQUEST_SENSE) {
  52397. + curlun->sense_data = curlun->unit_attention_data;
  52398. + curlun->unit_attention_data = SS_NO_SENSE;
  52399. + return -EINVAL;
  52400. + }
  52401. +
  52402. + /* Check that only command bytes listed in the mask are non-zero */
  52403. + fsg->cmnd[1] &= 0x1f; // Mask away the LUN
  52404. + for (i = 1; i < cmnd_size; ++i) {
  52405. + if (fsg->cmnd[i] && !(mask & (1 << i))) {
  52406. + if (curlun)
  52407. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  52408. + return -EINVAL;
  52409. + }
  52410. + }
  52411. +
  52412. + /* If the medium isn't mounted and the command needs to access
  52413. + * it, return an error. */
  52414. + if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
  52415. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  52416. + return -EINVAL;
  52417. + }
  52418. +
  52419. + return 0;
  52420. +}
  52421. +
  52422. +/* wrapper of check_command for data size in blocks handling */
  52423. +static int check_command_size_in_blocks(struct fsg_dev *fsg, int cmnd_size,
  52424. + enum data_direction data_dir, unsigned int mask,
  52425. + int needs_medium, const char *name)
  52426. +{
  52427. + if (fsg->curlun)
  52428. + fsg->data_size_from_cmnd <<= fsg->curlun->blkbits;
  52429. + return check_command(fsg, cmnd_size, data_dir,
  52430. + mask, needs_medium, name);
  52431. +}
  52432. +
  52433. +static int do_scsi_command(struct fsg_dev *fsg)
  52434. +{
  52435. + struct fsg_buffhd *bh;
  52436. + int rc;
  52437. + int reply = -EINVAL;
  52438. + int i;
  52439. + static char unknown[16];
  52440. +
  52441. + dump_cdb(fsg);
  52442. +
  52443. + /* Wait for the next buffer to become available for data or status */
  52444. + bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill;
  52445. + while (bh->state != BUF_STATE_EMPTY) {
  52446. + rc = sleep_thread(fsg);
  52447. + if (rc)
  52448. + return rc;
  52449. + }
  52450. + fsg->phase_error = 0;
  52451. + fsg->short_packet_received = 0;
  52452. +
  52453. + down_read(&fsg->filesem); // We're using the backing file
  52454. + switch (fsg->cmnd[0]) {
  52455. +
  52456. + case INQUIRY:
  52457. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  52458. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  52459. + (1<<4), 0,
  52460. + "INQUIRY")) == 0)
  52461. + reply = do_inquiry(fsg, bh);
  52462. + break;
  52463. +
  52464. + case MODE_SELECT:
  52465. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  52466. + if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
  52467. + (1<<1) | (1<<4), 0,
  52468. + "MODE SELECT(6)")) == 0)
  52469. + reply = do_mode_select(fsg, bh);
  52470. + break;
  52471. +
  52472. + case MODE_SELECT_10:
  52473. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  52474. + if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
  52475. + (1<<1) | (3<<7), 0,
  52476. + "MODE SELECT(10)")) == 0)
  52477. + reply = do_mode_select(fsg, bh);
  52478. + break;
  52479. +
  52480. + case MODE_SENSE:
  52481. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  52482. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  52483. + (1<<1) | (1<<2) | (1<<4), 0,
  52484. + "MODE SENSE(6)")) == 0)
  52485. + reply = do_mode_sense(fsg, bh);
  52486. + break;
  52487. +
  52488. + case MODE_SENSE_10:
  52489. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  52490. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  52491. + (1<<1) | (1<<2) | (3<<7), 0,
  52492. + "MODE SENSE(10)")) == 0)
  52493. + reply = do_mode_sense(fsg, bh);
  52494. + break;
  52495. +
  52496. + case ALLOW_MEDIUM_REMOVAL:
  52497. + fsg->data_size_from_cmnd = 0;
  52498. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  52499. + (1<<4), 0,
  52500. + "PREVENT-ALLOW MEDIUM REMOVAL")) == 0)
  52501. + reply = do_prevent_allow(fsg);
  52502. + break;
  52503. +
  52504. + case READ_6:
  52505. + i = fsg->cmnd[4];
  52506. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  52507. + if ((reply = check_command_size_in_blocks(fsg, 6,
  52508. + DATA_DIR_TO_HOST,
  52509. + (7<<1) | (1<<4), 1,
  52510. + "READ(6)")) == 0)
  52511. + reply = do_read(fsg);
  52512. + break;
  52513. +
  52514. + case READ_10:
  52515. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  52516. + if ((reply = check_command_size_in_blocks(fsg, 10,
  52517. + DATA_DIR_TO_HOST,
  52518. + (1<<1) | (0xf<<2) | (3<<7), 1,
  52519. + "READ(10)")) == 0)
  52520. + reply = do_read(fsg);
  52521. + break;
  52522. +
  52523. + case READ_12:
  52524. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  52525. + if ((reply = check_command_size_in_blocks(fsg, 12,
  52526. + DATA_DIR_TO_HOST,
  52527. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  52528. + "READ(12)")) == 0)
  52529. + reply = do_read(fsg);
  52530. + break;
  52531. +
  52532. + case READ_CAPACITY:
  52533. + fsg->data_size_from_cmnd = 8;
  52534. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  52535. + (0xf<<2) | (1<<8), 1,
  52536. + "READ CAPACITY")) == 0)
  52537. + reply = do_read_capacity(fsg, bh);
  52538. + break;
  52539. +
  52540. + case READ_HEADER:
  52541. + if (!mod_data.cdrom)
  52542. + goto unknown_cmnd;
  52543. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  52544. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  52545. + (3<<7) | (0x1f<<1), 1,
  52546. + "READ HEADER")) == 0)
  52547. + reply = do_read_header(fsg, bh);
  52548. + break;
  52549. +
  52550. + case READ_TOC:
  52551. + if (!mod_data.cdrom)
  52552. + goto unknown_cmnd;
  52553. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  52554. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  52555. + (7<<6) | (1<<1), 1,
  52556. + "READ TOC")) == 0)
  52557. + reply = do_read_toc(fsg, bh);
  52558. + break;
  52559. +
  52560. + case READ_FORMAT_CAPACITIES:
  52561. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  52562. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  52563. + (3<<7), 1,
  52564. + "READ FORMAT CAPACITIES")) == 0)
  52565. + reply = do_read_format_capacities(fsg, bh);
  52566. + break;
  52567. +
  52568. + case REQUEST_SENSE:
  52569. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  52570. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  52571. + (1<<4), 0,
  52572. + "REQUEST SENSE")) == 0)
  52573. + reply = do_request_sense(fsg, bh);
  52574. + break;
  52575. +
  52576. + case START_STOP:
  52577. + fsg->data_size_from_cmnd = 0;
  52578. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  52579. + (1<<1) | (1<<4), 0,
  52580. + "START-STOP UNIT")) == 0)
  52581. + reply = do_start_stop(fsg);
  52582. + break;
  52583. +
  52584. + case SYNCHRONIZE_CACHE:
  52585. + fsg->data_size_from_cmnd = 0;
  52586. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  52587. + (0xf<<2) | (3<<7), 1,
  52588. + "SYNCHRONIZE CACHE")) == 0)
  52589. + reply = do_synchronize_cache(fsg);
  52590. + break;
  52591. +
  52592. + case TEST_UNIT_READY:
  52593. + fsg->data_size_from_cmnd = 0;
  52594. + reply = check_command(fsg, 6, DATA_DIR_NONE,
  52595. + 0, 1,
  52596. + "TEST UNIT READY");
  52597. + break;
  52598. +
  52599. + /* Although optional, this command is used by MS-Windows. We
  52600. + * support a minimal version: BytChk must be 0. */
  52601. + case VERIFY:
  52602. + fsg->data_size_from_cmnd = 0;
  52603. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  52604. + (1<<1) | (0xf<<2) | (3<<7), 1,
  52605. + "VERIFY")) == 0)
  52606. + reply = do_verify(fsg);
  52607. + break;
  52608. +
  52609. + case WRITE_6:
  52610. + i = fsg->cmnd[4];
  52611. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  52612. + if ((reply = check_command_size_in_blocks(fsg, 6,
  52613. + DATA_DIR_FROM_HOST,
  52614. + (7<<1) | (1<<4), 1,
  52615. + "WRITE(6)")) == 0)
  52616. + reply = do_write(fsg);
  52617. + break;
  52618. +
  52619. + case WRITE_10:
  52620. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  52621. + if ((reply = check_command_size_in_blocks(fsg, 10,
  52622. + DATA_DIR_FROM_HOST,
  52623. + (1<<1) | (0xf<<2) | (3<<7), 1,
  52624. + "WRITE(10)")) == 0)
  52625. + reply = do_write(fsg);
  52626. + break;
  52627. +
  52628. + case WRITE_12:
  52629. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  52630. + if ((reply = check_command_size_in_blocks(fsg, 12,
  52631. + DATA_DIR_FROM_HOST,
  52632. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  52633. + "WRITE(12)")) == 0)
  52634. + reply = do_write(fsg);
  52635. + break;
  52636. +
  52637. + /* Some mandatory commands that we recognize but don't implement.
  52638. + * They don't mean much in this setting. It's left as an exercise
  52639. + * for anyone interested to implement RESERVE and RELEASE in terms
  52640. + * of Posix locks. */
  52641. + case FORMAT_UNIT:
  52642. + case RELEASE:
  52643. + case RESERVE:
  52644. + case SEND_DIAGNOSTIC:
  52645. + // Fall through
  52646. +
  52647. + default:
  52648. + unknown_cmnd:
  52649. + fsg->data_size_from_cmnd = 0;
  52650. + sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]);
  52651. + if ((reply = check_command(fsg, fsg->cmnd_size,
  52652. + DATA_DIR_UNKNOWN, ~0, 0, unknown)) == 0) {
  52653. + fsg->curlun->sense_data = SS_INVALID_COMMAND;
  52654. + reply = -EINVAL;
  52655. + }
  52656. + break;
  52657. + }
  52658. + up_read(&fsg->filesem);
  52659. +
  52660. + if (reply == -EINTR || signal_pending(current))
  52661. + return -EINTR;
  52662. +
  52663. + /* Set up the single reply buffer for finish_reply() */
  52664. + if (reply == -EINVAL)
  52665. + reply = 0; // Error reply length
  52666. + if (reply >= 0 && fsg->data_dir == DATA_DIR_TO_HOST) {
  52667. + reply = min((u32) reply, fsg->data_size_from_cmnd);
  52668. + bh->inreq->length = reply;
  52669. + bh->state = BUF_STATE_FULL;
  52670. + fsg->residue -= reply;
  52671. + } // Otherwise it's already set
  52672. +
  52673. + return 0;
  52674. +}
  52675. +
  52676. +
  52677. +/*-------------------------------------------------------------------------*/
  52678. +
  52679. +static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  52680. +{
  52681. + struct usb_request *req = bh->outreq;
  52682. + struct bulk_cb_wrap *cbw = req->buf;
  52683. +
  52684. + /* Was this a real packet? Should it be ignored? */
  52685. + if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  52686. + return -EINVAL;
  52687. +
  52688. + /* Is the CBW valid? */
  52689. + if (req->actual != US_BULK_CB_WRAP_LEN ||
  52690. + cbw->Signature != cpu_to_le32(
  52691. + US_BULK_CB_SIGN)) {
  52692. + DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
  52693. + req->actual,
  52694. + le32_to_cpu(cbw->Signature));
  52695. +
  52696. + /* The Bulk-only spec says we MUST stall the IN endpoint
  52697. + * (6.6.1), so it's unavoidable. It also says we must
  52698. + * retain this state until the next reset, but there's
  52699. + * no way to tell the controller driver it should ignore
  52700. + * Clear-Feature(HALT) requests.
  52701. + *
  52702. + * We aren't required to halt the OUT endpoint; instead
  52703. + * we can simply accept and discard any data received
  52704. + * until the next reset. */
  52705. + wedge_bulk_in_endpoint(fsg);
  52706. + set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  52707. + return -EINVAL;
  52708. + }
  52709. +
  52710. + /* Is the CBW meaningful? */
  52711. + if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
  52712. + cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
  52713. + DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
  52714. + "cmdlen %u\n",
  52715. + cbw->Lun, cbw->Flags, cbw->Length);
  52716. +
  52717. + /* We can do anything we want here, so let's stall the
  52718. + * bulk pipes if we are allowed to. */
  52719. + if (mod_data.can_stall) {
  52720. + fsg_set_halt(fsg, fsg->bulk_out);
  52721. + halt_bulk_in_endpoint(fsg);
  52722. + }
  52723. + return -EINVAL;
  52724. + }
  52725. +
  52726. + /* Save the command for later */
  52727. + fsg->cmnd_size = cbw->Length;
  52728. + memcpy(fsg->cmnd, cbw->CDB, fsg->cmnd_size);
  52729. + if (cbw->Flags & US_BULK_FLAG_IN)
  52730. + fsg->data_dir = DATA_DIR_TO_HOST;
  52731. + else
  52732. + fsg->data_dir = DATA_DIR_FROM_HOST;
  52733. + fsg->data_size = le32_to_cpu(cbw->DataTransferLength);
  52734. + if (fsg->data_size == 0)
  52735. + fsg->data_dir = DATA_DIR_NONE;
  52736. + fsg->lun = cbw->Lun;
  52737. + fsg->tag = cbw->Tag;
  52738. + return 0;
  52739. +}
  52740. +
  52741. +
  52742. +static int get_next_command(struct fsg_dev *fsg)
  52743. +{
  52744. + struct fsg_buffhd *bh;
  52745. + int rc = 0;
  52746. +
  52747. + if (transport_is_bbb()) {
  52748. +
  52749. + /* Wait for the next buffer to become available */
  52750. + bh = fsg->next_buffhd_to_fill;
  52751. + while (bh->state != BUF_STATE_EMPTY) {
  52752. + rc = sleep_thread(fsg);
  52753. + if (rc)
  52754. + return rc;
  52755. + }
  52756. +
  52757. + /* Queue a request to read a Bulk-only CBW */
  52758. + set_bulk_out_req_length(fsg, bh, US_BULK_CB_WRAP_LEN);
  52759. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  52760. + &bh->outreq_busy, &bh->state);
  52761. +
  52762. + /* We will drain the buffer in software, which means we
  52763. + * can reuse it for the next filling. No need to advance
  52764. + * next_buffhd_to_fill. */
  52765. +
  52766. + /* Wait for the CBW to arrive */
  52767. + while (bh->state != BUF_STATE_FULL) {
  52768. + rc = sleep_thread(fsg);
  52769. + if (rc)
  52770. + return rc;
  52771. + }
  52772. + smp_rmb();
  52773. + rc = received_cbw(fsg, bh);
  52774. + bh->state = BUF_STATE_EMPTY;
  52775. +
  52776. + } else { // USB_PR_CB or USB_PR_CBI
  52777. +
  52778. + /* Wait for the next command to arrive */
  52779. + while (fsg->cbbuf_cmnd_size == 0) {
  52780. + rc = sleep_thread(fsg);
  52781. + if (rc)
  52782. + return rc;
  52783. + }
  52784. +
  52785. + /* Is the previous status interrupt request still busy?
  52786. + * The host is allowed to skip reading the status,
  52787. + * so we must cancel it. */
  52788. + if (fsg->intreq_busy)
  52789. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  52790. +
  52791. + /* Copy the command and mark the buffer empty */
  52792. + fsg->data_dir = DATA_DIR_UNKNOWN;
  52793. + spin_lock_irq(&fsg->lock);
  52794. + fsg->cmnd_size = fsg->cbbuf_cmnd_size;
  52795. + memcpy(fsg->cmnd, fsg->cbbuf_cmnd, fsg->cmnd_size);
  52796. + fsg->cbbuf_cmnd_size = 0;
  52797. + spin_unlock_irq(&fsg->lock);
  52798. +
  52799. + /* Use LUN from the command */
  52800. + fsg->lun = fsg->cmnd[1] >> 5;
  52801. + }
  52802. +
  52803. + /* Update current lun */
  52804. + if (fsg->lun >= 0 && fsg->lun < fsg->nluns)
  52805. + fsg->curlun = &fsg->luns[fsg->lun];
  52806. + else
  52807. + fsg->curlun = NULL;
  52808. +
  52809. + return rc;
  52810. +}
  52811. +
  52812. +
  52813. +/*-------------------------------------------------------------------------*/
  52814. +
  52815. +static int enable_endpoint(struct fsg_dev *fsg, struct usb_ep *ep,
  52816. + const struct usb_endpoint_descriptor *d)
  52817. +{
  52818. + int rc;
  52819. +
  52820. + ep->driver_data = fsg;
  52821. + ep->desc = d;
  52822. + rc = usb_ep_enable(ep);
  52823. + if (rc)
  52824. + ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc);
  52825. + return rc;
  52826. +}
  52827. +
  52828. +static int alloc_request(struct fsg_dev *fsg, struct usb_ep *ep,
  52829. + struct usb_request **preq)
  52830. +{
  52831. + *preq = usb_ep_alloc_request(ep, GFP_ATOMIC);
  52832. + if (*preq)
  52833. + return 0;
  52834. + ERROR(fsg, "can't allocate request for %s\n", ep->name);
  52835. + return -ENOMEM;
  52836. +}
  52837. +
  52838. +/*
  52839. + * Reset interface setting and re-init endpoint state (toggle etc).
  52840. + * Call with altsetting < 0 to disable the interface. The only other
  52841. + * available altsetting is 0, which enables the interface.
  52842. + */
  52843. +static int do_set_interface(struct fsg_dev *fsg, int altsetting)
  52844. +{
  52845. + int rc = 0;
  52846. + int i;
  52847. + const struct usb_endpoint_descriptor *d;
  52848. +
  52849. + if (fsg->running)
  52850. + DBG(fsg, "reset interface\n");
  52851. +
  52852. +reset:
  52853. + /* Deallocate the requests */
  52854. + for (i = 0; i < fsg_num_buffers; ++i) {
  52855. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  52856. +
  52857. + if (bh->inreq) {
  52858. + usb_ep_free_request(fsg->bulk_in, bh->inreq);
  52859. + bh->inreq = NULL;
  52860. + }
  52861. + if (bh->outreq) {
  52862. + usb_ep_free_request(fsg->bulk_out, bh->outreq);
  52863. + bh->outreq = NULL;
  52864. + }
  52865. + }
  52866. + if (fsg->intreq) {
  52867. + usb_ep_free_request(fsg->intr_in, fsg->intreq);
  52868. + fsg->intreq = NULL;
  52869. + }
  52870. +
  52871. + /* Disable the endpoints */
  52872. + if (fsg->bulk_in_enabled) {
  52873. + usb_ep_disable(fsg->bulk_in);
  52874. + fsg->bulk_in_enabled = 0;
  52875. + }
  52876. + if (fsg->bulk_out_enabled) {
  52877. + usb_ep_disable(fsg->bulk_out);
  52878. + fsg->bulk_out_enabled = 0;
  52879. + }
  52880. + if (fsg->intr_in_enabled) {
  52881. + usb_ep_disable(fsg->intr_in);
  52882. + fsg->intr_in_enabled = 0;
  52883. + }
  52884. +
  52885. + fsg->running = 0;
  52886. + if (altsetting < 0 || rc != 0)
  52887. + return rc;
  52888. +
  52889. + DBG(fsg, "set interface %d\n", altsetting);
  52890. +
  52891. + /* Enable the endpoints */
  52892. + d = fsg_ep_desc(fsg->gadget,
  52893. + &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc,
  52894. + &fsg_ss_bulk_in_desc);
  52895. + if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0)
  52896. + goto reset;
  52897. + fsg->bulk_in_enabled = 1;
  52898. +
  52899. + d = fsg_ep_desc(fsg->gadget,
  52900. + &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc,
  52901. + &fsg_ss_bulk_out_desc);
  52902. + if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0)
  52903. + goto reset;
  52904. + fsg->bulk_out_enabled = 1;
  52905. + fsg->bulk_out_maxpacket = usb_endpoint_maxp(d);
  52906. + clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  52907. +
  52908. + if (transport_is_cbi()) {
  52909. + d = fsg_ep_desc(fsg->gadget,
  52910. + &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc,
  52911. + &fsg_ss_intr_in_desc);
  52912. + if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
  52913. + goto reset;
  52914. + fsg->intr_in_enabled = 1;
  52915. + }
  52916. +
  52917. + /* Allocate the requests */
  52918. + for (i = 0; i < fsg_num_buffers; ++i) {
  52919. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  52920. +
  52921. + if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
  52922. + goto reset;
  52923. + if ((rc = alloc_request(fsg, fsg->bulk_out, &bh->outreq)) != 0)
  52924. + goto reset;
  52925. + bh->inreq->buf = bh->outreq->buf = bh->buf;
  52926. + bh->inreq->context = bh->outreq->context = bh;
  52927. + bh->inreq->complete = bulk_in_complete;
  52928. + bh->outreq->complete = bulk_out_complete;
  52929. + }
  52930. + if (transport_is_cbi()) {
  52931. + if ((rc = alloc_request(fsg, fsg->intr_in, &fsg->intreq)) != 0)
  52932. + goto reset;
  52933. + fsg->intreq->complete = intr_in_complete;
  52934. + }
  52935. +
  52936. + fsg->running = 1;
  52937. + for (i = 0; i < fsg->nluns; ++i)
  52938. + fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  52939. + return rc;
  52940. +}
  52941. +
  52942. +
  52943. +/*
  52944. + * Change our operational configuration. This code must agree with the code
  52945. + * that returns config descriptors, and with interface altsetting code.
  52946. + *
  52947. + * It's also responsible for power management interactions. Some
  52948. + * configurations might not work with our current power sources.
  52949. + * For now we just assume the gadget is always self-powered.
  52950. + */
  52951. +static int do_set_config(struct fsg_dev *fsg, u8 new_config)
  52952. +{
  52953. + int rc = 0;
  52954. +
  52955. + /* Disable the single interface */
  52956. + if (fsg->config != 0) {
  52957. + DBG(fsg, "reset config\n");
  52958. + fsg->config = 0;
  52959. + rc = do_set_interface(fsg, -1);
  52960. + }
  52961. +
  52962. + /* Enable the interface */
  52963. + if (new_config != 0) {
  52964. + fsg->config = new_config;
  52965. + if ((rc = do_set_interface(fsg, 0)) != 0)
  52966. + fsg->config = 0; // Reset on errors
  52967. + else
  52968. + INFO(fsg, "%s config #%d\n",
  52969. + usb_speed_string(fsg->gadget->speed),
  52970. + fsg->config);
  52971. + }
  52972. + return rc;
  52973. +}
  52974. +
  52975. +
  52976. +/*-------------------------------------------------------------------------*/
  52977. +
  52978. +static void handle_exception(struct fsg_dev *fsg)
  52979. +{
  52980. + siginfo_t info;
  52981. + int sig;
  52982. + int i;
  52983. + int num_active;
  52984. + struct fsg_buffhd *bh;
  52985. + enum fsg_state old_state;
  52986. + u8 new_config;
  52987. + struct fsg_lun *curlun;
  52988. + unsigned int exception_req_tag;
  52989. + int rc;
  52990. +
  52991. + /* Clear the existing signals. Anything but SIGUSR1 is converted
  52992. + * into a high-priority EXIT exception. */
  52993. + for (;;) {
  52994. + sig = dequeue_signal_lock(current, &current->blocked, &info);
  52995. + if (!sig)
  52996. + break;
  52997. + if (sig != SIGUSR1) {
  52998. + if (fsg->state < FSG_STATE_EXIT)
  52999. + DBG(fsg, "Main thread exiting on signal\n");
  53000. + raise_exception(fsg, FSG_STATE_EXIT);
  53001. + }
  53002. + }
  53003. +
  53004. + /* Cancel all the pending transfers */
  53005. + if (fsg->intreq_busy)
  53006. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  53007. + for (i = 0; i < fsg_num_buffers; ++i) {
  53008. + bh = &fsg->buffhds[i];
  53009. + if (bh->inreq_busy)
  53010. + usb_ep_dequeue(fsg->bulk_in, bh->inreq);
  53011. + if (bh->outreq_busy)
  53012. + usb_ep_dequeue(fsg->bulk_out, bh->outreq);
  53013. + }
  53014. +
  53015. + /* Wait until everything is idle */
  53016. + for (;;) {
  53017. + num_active = fsg->intreq_busy;
  53018. + for (i = 0; i < fsg_num_buffers; ++i) {
  53019. + bh = &fsg->buffhds[i];
  53020. + num_active += bh->inreq_busy + bh->outreq_busy;
  53021. + }
  53022. + if (num_active == 0)
  53023. + break;
  53024. + if (sleep_thread(fsg))
  53025. + return;
  53026. + }
  53027. +
  53028. + /* Clear out the controller's fifos */
  53029. + if (fsg->bulk_in_enabled)
  53030. + usb_ep_fifo_flush(fsg->bulk_in);
  53031. + if (fsg->bulk_out_enabled)
  53032. + usb_ep_fifo_flush(fsg->bulk_out);
  53033. + if (fsg->intr_in_enabled)
  53034. + usb_ep_fifo_flush(fsg->intr_in);
  53035. +
  53036. + /* Reset the I/O buffer states and pointers, the SCSI
  53037. + * state, and the exception. Then invoke the handler. */
  53038. + spin_lock_irq(&fsg->lock);
  53039. +
  53040. + for (i = 0; i < fsg_num_buffers; ++i) {
  53041. + bh = &fsg->buffhds[i];
  53042. + bh->state = BUF_STATE_EMPTY;
  53043. + }
  53044. + fsg->next_buffhd_to_fill = fsg->next_buffhd_to_drain =
  53045. + &fsg->buffhds[0];
  53046. +
  53047. + exception_req_tag = fsg->exception_req_tag;
  53048. + new_config = fsg->new_config;
  53049. + old_state = fsg->state;
  53050. +
  53051. + if (old_state == FSG_STATE_ABORT_BULK_OUT)
  53052. + fsg->state = FSG_STATE_STATUS_PHASE;
  53053. + else {
  53054. + for (i = 0; i < fsg->nluns; ++i) {
  53055. + curlun = &fsg->luns[i];
  53056. + curlun->prevent_medium_removal = 0;
  53057. + curlun->sense_data = curlun->unit_attention_data =
  53058. + SS_NO_SENSE;
  53059. + curlun->sense_data_info = 0;
  53060. + curlun->info_valid = 0;
  53061. + }
  53062. + fsg->state = FSG_STATE_IDLE;
  53063. + }
  53064. + spin_unlock_irq(&fsg->lock);
  53065. +
  53066. + /* Carry out any extra actions required for the exception */
  53067. + switch (old_state) {
  53068. + default:
  53069. + break;
  53070. +
  53071. + case FSG_STATE_ABORT_BULK_OUT:
  53072. + send_status(fsg);
  53073. + spin_lock_irq(&fsg->lock);
  53074. + if (fsg->state == FSG_STATE_STATUS_PHASE)
  53075. + fsg->state = FSG_STATE_IDLE;
  53076. + spin_unlock_irq(&fsg->lock);
  53077. + break;
  53078. +
  53079. + case FSG_STATE_RESET:
  53080. + /* In case we were forced against our will to halt a
  53081. + * bulk endpoint, clear the halt now. (The SuperH UDC
  53082. + * requires this.) */
  53083. + if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  53084. + usb_ep_clear_halt(fsg->bulk_in);
  53085. +
  53086. + if (transport_is_bbb()) {
  53087. + if (fsg->ep0_req_tag == exception_req_tag)
  53088. + ep0_queue(fsg); // Complete the status stage
  53089. +
  53090. + } else if (transport_is_cbi())
  53091. + send_status(fsg); // Status by interrupt pipe
  53092. +
  53093. + /* Technically this should go here, but it would only be
  53094. + * a waste of time. Ditto for the INTERFACE_CHANGE and
  53095. + * CONFIG_CHANGE cases. */
  53096. + // for (i = 0; i < fsg->nluns; ++i)
  53097. + // fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  53098. + break;
  53099. +
  53100. + case FSG_STATE_INTERFACE_CHANGE:
  53101. + rc = do_set_interface(fsg, 0);
  53102. + if (fsg->ep0_req_tag != exception_req_tag)
  53103. + break;
  53104. + if (rc != 0) // STALL on errors
  53105. + fsg_set_halt(fsg, fsg->ep0);
  53106. + else // Complete the status stage
  53107. + ep0_queue(fsg);
  53108. + break;
  53109. +
  53110. + case FSG_STATE_CONFIG_CHANGE:
  53111. + rc = do_set_config(fsg, new_config);
  53112. + if (fsg->ep0_req_tag != exception_req_tag)
  53113. + break;
  53114. + if (rc != 0) // STALL on errors
  53115. + fsg_set_halt(fsg, fsg->ep0);
  53116. + else // Complete the status stage
  53117. + ep0_queue(fsg);
  53118. + break;
  53119. +
  53120. + case FSG_STATE_DISCONNECT:
  53121. + for (i = 0; i < fsg->nluns; ++i)
  53122. + fsg_lun_fsync_sub(fsg->luns + i);
  53123. + do_set_config(fsg, 0); // Unconfigured state
  53124. + break;
  53125. +
  53126. + case FSG_STATE_EXIT:
  53127. + case FSG_STATE_TERMINATED:
  53128. + do_set_config(fsg, 0); // Free resources
  53129. + spin_lock_irq(&fsg->lock);
  53130. + fsg->state = FSG_STATE_TERMINATED; // Stop the thread
  53131. + spin_unlock_irq(&fsg->lock);
  53132. + break;
  53133. + }
  53134. +}
  53135. +
  53136. +
  53137. +/*-------------------------------------------------------------------------*/
  53138. +
  53139. +static int fsg_main_thread(void *fsg_)
  53140. +{
  53141. + struct fsg_dev *fsg = fsg_;
  53142. +
  53143. + /* Allow the thread to be killed by a signal, but set the signal mask
  53144. + * to block everything but INT, TERM, KILL, and USR1. */
  53145. + allow_signal(SIGINT);
  53146. + allow_signal(SIGTERM);
  53147. + allow_signal(SIGKILL);
  53148. + allow_signal(SIGUSR1);
  53149. +
  53150. + /* Allow the thread to be frozen */
  53151. + set_freezable();
  53152. +
  53153. + /* Arrange for userspace references to be interpreted as kernel
  53154. + * pointers. That way we can pass a kernel pointer to a routine
  53155. + * that expects a __user pointer and it will work okay. */
  53156. + set_fs(get_ds());
  53157. +
  53158. + /* The main loop */
  53159. + while (fsg->state != FSG_STATE_TERMINATED) {
  53160. + if (exception_in_progress(fsg) || signal_pending(current)) {
  53161. + handle_exception(fsg);
  53162. + continue;
  53163. + }
  53164. +
  53165. + if (!fsg->running) {
  53166. + sleep_thread(fsg);
  53167. + continue;
  53168. + }
  53169. +
  53170. + if (get_next_command(fsg))
  53171. + continue;
  53172. +
  53173. + spin_lock_irq(&fsg->lock);
  53174. + if (!exception_in_progress(fsg))
  53175. + fsg->state = FSG_STATE_DATA_PHASE;
  53176. + spin_unlock_irq(&fsg->lock);
  53177. +
  53178. + if (do_scsi_command(fsg) || finish_reply(fsg))
  53179. + continue;
  53180. +
  53181. + spin_lock_irq(&fsg->lock);
  53182. + if (!exception_in_progress(fsg))
  53183. + fsg->state = FSG_STATE_STATUS_PHASE;
  53184. + spin_unlock_irq(&fsg->lock);
  53185. +
  53186. + if (send_status(fsg))
  53187. + continue;
  53188. +
  53189. + spin_lock_irq(&fsg->lock);
  53190. + if (!exception_in_progress(fsg))
  53191. + fsg->state = FSG_STATE_IDLE;
  53192. + spin_unlock_irq(&fsg->lock);
  53193. + }
  53194. +
  53195. + spin_lock_irq(&fsg->lock);
  53196. + fsg->thread_task = NULL;
  53197. + spin_unlock_irq(&fsg->lock);
  53198. +
  53199. + /* If we are exiting because of a signal, unregister the
  53200. + * gadget driver. */
  53201. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  53202. + usb_gadget_unregister_driver(&fsg_driver);
  53203. +
  53204. + /* Let the unbind and cleanup routines know the thread has exited */
  53205. + complete_and_exit(&fsg->thread_notifier, 0);
  53206. +}
  53207. +
  53208. +
  53209. +/*-------------------------------------------------------------------------*/
  53210. +
  53211. +
  53212. +/* The write permissions and store_xxx pointers are set in fsg_bind() */
  53213. +static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL);
  53214. +static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL);
  53215. +static DEVICE_ATTR(file, 0444, fsg_show_file, NULL);
  53216. +
  53217. +
  53218. +/*-------------------------------------------------------------------------*/
  53219. +
  53220. +static void fsg_release(struct kref *ref)
  53221. +{
  53222. + struct fsg_dev *fsg = container_of(ref, struct fsg_dev, ref);
  53223. +
  53224. + kfree(fsg->luns);
  53225. + kfree(fsg);
  53226. +}
  53227. +
  53228. +static void lun_release(struct device *dev)
  53229. +{
  53230. + struct rw_semaphore *filesem = dev_get_drvdata(dev);
  53231. + struct fsg_dev *fsg =
  53232. + container_of(filesem, struct fsg_dev, filesem);
  53233. +
  53234. + kref_put(&fsg->ref, fsg_release);
  53235. +}
  53236. +
  53237. +static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
  53238. +{
  53239. + struct fsg_dev *fsg = get_gadget_data(gadget);
  53240. + int i;
  53241. + struct fsg_lun *curlun;
  53242. + struct usb_request *req = fsg->ep0req;
  53243. +
  53244. + DBG(fsg, "unbind\n");
  53245. + clear_bit(REGISTERED, &fsg->atomic_bitflags);
  53246. +
  53247. + /* If the thread isn't already dead, tell it to exit now */
  53248. + if (fsg->state != FSG_STATE_TERMINATED) {
  53249. + raise_exception(fsg, FSG_STATE_EXIT);
  53250. + wait_for_completion(&fsg->thread_notifier);
  53251. +
  53252. + /* The cleanup routine waits for this completion also */
  53253. + complete(&fsg->thread_notifier);
  53254. + }
  53255. +
  53256. + /* Unregister the sysfs attribute files and the LUNs */
  53257. + for (i = 0; i < fsg->nluns; ++i) {
  53258. + curlun = &fsg->luns[i];
  53259. + if (curlun->registered) {
  53260. + device_remove_file(&curlun->dev, &dev_attr_nofua);
  53261. + device_remove_file(&curlun->dev, &dev_attr_ro);
  53262. + device_remove_file(&curlun->dev, &dev_attr_file);
  53263. + fsg_lun_close(curlun);
  53264. + device_unregister(&curlun->dev);
  53265. + curlun->registered = 0;
  53266. + }
  53267. + }
  53268. +
  53269. + /* Free the data buffers */
  53270. + for (i = 0; i < fsg_num_buffers; ++i)
  53271. + kfree(fsg->buffhds[i].buf);
  53272. +
  53273. + /* Free the request and buffer for endpoint 0 */
  53274. + if (req) {
  53275. + kfree(req->buf);
  53276. + usb_ep_free_request(fsg->ep0, req);
  53277. + }
  53278. +
  53279. + set_gadget_data(gadget, NULL);
  53280. +}
  53281. +
  53282. +
  53283. +static int __init check_parameters(struct fsg_dev *fsg)
  53284. +{
  53285. + int prot;
  53286. + int gcnum;
  53287. +
  53288. + /* Store the default values */
  53289. + mod_data.transport_type = USB_PR_BULK;
  53290. + mod_data.transport_name = "Bulk-only";
  53291. + mod_data.protocol_type = USB_SC_SCSI;
  53292. + mod_data.protocol_name = "Transparent SCSI";
  53293. +
  53294. + /* Some peripheral controllers are known not to be able to
  53295. + * halt bulk endpoints correctly. If one of them is present,
  53296. + * disable stalls.
  53297. + */
  53298. + if (gadget_is_at91(fsg->gadget))
  53299. + mod_data.can_stall = 0;
  53300. +
  53301. + if (mod_data.release == 0xffff) { // Parameter wasn't set
  53302. + gcnum = usb_gadget_controller_number(fsg->gadget);
  53303. + if (gcnum >= 0)
  53304. + mod_data.release = 0x0300 + gcnum;
  53305. + else {
  53306. + WARNING(fsg, "controller '%s' not recognized\n",
  53307. + fsg->gadget->name);
  53308. + mod_data.release = 0x0399;
  53309. + }
  53310. + }
  53311. +
  53312. + prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
  53313. +
  53314. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  53315. + if (strnicmp(mod_data.transport_parm, "BBB", 10) == 0) {
  53316. + ; // Use default setting
  53317. + } else if (strnicmp(mod_data.transport_parm, "CB", 10) == 0) {
  53318. + mod_data.transport_type = USB_PR_CB;
  53319. + mod_data.transport_name = "Control-Bulk";
  53320. + } else if (strnicmp(mod_data.transport_parm, "CBI", 10) == 0) {
  53321. + mod_data.transport_type = USB_PR_CBI;
  53322. + mod_data.transport_name = "Control-Bulk-Interrupt";
  53323. + } else {
  53324. + ERROR(fsg, "invalid transport: %s\n", mod_data.transport_parm);
  53325. + return -EINVAL;
  53326. + }
  53327. +
  53328. + if (strnicmp(mod_data.protocol_parm, "SCSI", 10) == 0 ||
  53329. + prot == USB_SC_SCSI) {
  53330. + ; // Use default setting
  53331. + } else if (strnicmp(mod_data.protocol_parm, "RBC", 10) == 0 ||
  53332. + prot == USB_SC_RBC) {
  53333. + mod_data.protocol_type = USB_SC_RBC;
  53334. + mod_data.protocol_name = "RBC";
  53335. + } else if (strnicmp(mod_data.protocol_parm, "8020", 4) == 0 ||
  53336. + strnicmp(mod_data.protocol_parm, "ATAPI", 10) == 0 ||
  53337. + prot == USB_SC_8020) {
  53338. + mod_data.protocol_type = USB_SC_8020;
  53339. + mod_data.protocol_name = "8020i (ATAPI)";
  53340. + } else if (strnicmp(mod_data.protocol_parm, "QIC", 3) == 0 ||
  53341. + prot == USB_SC_QIC) {
  53342. + mod_data.protocol_type = USB_SC_QIC;
  53343. + mod_data.protocol_name = "QIC-157";
  53344. + } else if (strnicmp(mod_data.protocol_parm, "UFI", 10) == 0 ||
  53345. + prot == USB_SC_UFI) {
  53346. + mod_data.protocol_type = USB_SC_UFI;
  53347. + mod_data.protocol_name = "UFI";
  53348. + } else if (strnicmp(mod_data.protocol_parm, "8070", 4) == 0 ||
  53349. + prot == USB_SC_8070) {
  53350. + mod_data.protocol_type = USB_SC_8070;
  53351. + mod_data.protocol_name = "8070i";
  53352. + } else {
  53353. + ERROR(fsg, "invalid protocol: %s\n", mod_data.protocol_parm);
  53354. + return -EINVAL;
  53355. + }
  53356. +
  53357. + mod_data.buflen &= PAGE_CACHE_MASK;
  53358. + if (mod_data.buflen <= 0) {
  53359. + ERROR(fsg, "invalid buflen\n");
  53360. + return -ETOOSMALL;
  53361. + }
  53362. +
  53363. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  53364. +
  53365. + /* Serial string handling.
  53366. + * On a real device, the serial string would be loaded
  53367. + * from permanent storage. */
  53368. + if (mod_data.serial) {
  53369. + const char *ch;
  53370. + unsigned len = 0;
  53371. +
  53372. + /* Sanity check :
  53373. + * The CB[I] specification limits the serial string to
  53374. + * 12 uppercase hexadecimal characters.
  53375. + * BBB need at least 12 uppercase hexadecimal characters,
  53376. + * with a maximum of 126. */
  53377. + for (ch = mod_data.serial; *ch; ++ch) {
  53378. + ++len;
  53379. + if ((*ch < '0' || *ch > '9') &&
  53380. + (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
  53381. + WARNING(fsg,
  53382. + "Invalid serial string character: %c\n",
  53383. + *ch);
  53384. + goto no_serial;
  53385. + }
  53386. + }
  53387. + if (len > 126 ||
  53388. + (mod_data.transport_type == USB_PR_BULK && len < 12) ||
  53389. + (mod_data.transport_type != USB_PR_BULK && len > 12)) {
  53390. + WARNING(fsg, "Invalid serial string length!\n");
  53391. + goto no_serial;
  53392. + }
  53393. + fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
  53394. + } else {
  53395. + WARNING(fsg, "No serial-number string provided!\n");
  53396. + no_serial:
  53397. + device_desc.iSerialNumber = 0;
  53398. + }
  53399. +
  53400. + return 0;
  53401. +}
  53402. +
  53403. +
  53404. +static int __init fsg_bind(struct usb_gadget *gadget)
  53405. +{
  53406. + struct fsg_dev *fsg = the_fsg;
  53407. + int rc;
  53408. + int i;
  53409. + struct fsg_lun *curlun;
  53410. + struct usb_ep *ep;
  53411. + struct usb_request *req;
  53412. + char *pathbuf, *p;
  53413. +
  53414. + fsg->gadget = gadget;
  53415. + set_gadget_data(gadget, fsg);
  53416. + fsg->ep0 = gadget->ep0;
  53417. + fsg->ep0->driver_data = fsg;
  53418. +
  53419. + if ((rc = check_parameters(fsg)) != 0)
  53420. + goto out;
  53421. +
  53422. + if (mod_data.removable) { // Enable the store_xxx attributes
  53423. + dev_attr_file.attr.mode = 0644;
  53424. + dev_attr_file.store = fsg_store_file;
  53425. + if (!mod_data.cdrom) {
  53426. + dev_attr_ro.attr.mode = 0644;
  53427. + dev_attr_ro.store = fsg_store_ro;
  53428. + }
  53429. + }
  53430. +
  53431. + /* Only for removable media? */
  53432. + dev_attr_nofua.attr.mode = 0644;
  53433. + dev_attr_nofua.store = fsg_store_nofua;
  53434. +
  53435. + /* Find out how many LUNs there should be */
  53436. + i = mod_data.nluns;
  53437. + if (i == 0)
  53438. + i = max(mod_data.num_filenames, 1u);
  53439. + if (i > FSG_MAX_LUNS) {
  53440. + ERROR(fsg, "invalid number of LUNs: %d\n", i);
  53441. + rc = -EINVAL;
  53442. + goto out;
  53443. + }
  53444. +
  53445. + /* Create the LUNs, open their backing files, and register the
  53446. + * LUN devices in sysfs. */
  53447. + fsg->luns = kzalloc(i * sizeof(struct fsg_lun), GFP_KERNEL);
  53448. + if (!fsg->luns) {
  53449. + rc = -ENOMEM;
  53450. + goto out;
  53451. + }
  53452. + fsg->nluns = i;
  53453. +
  53454. + for (i = 0; i < fsg->nluns; ++i) {
  53455. + curlun = &fsg->luns[i];
  53456. + curlun->cdrom = !!mod_data.cdrom;
  53457. + curlun->ro = mod_data.cdrom || mod_data.ro[i];
  53458. + curlun->initially_ro = curlun->ro;
  53459. + curlun->removable = mod_data.removable;
  53460. + curlun->nofua = mod_data.nofua[i];
  53461. + curlun->dev.release = lun_release;
  53462. + curlun->dev.parent = &gadget->dev;
  53463. + curlun->dev.driver = &fsg_driver.driver;
  53464. + dev_set_drvdata(&curlun->dev, &fsg->filesem);
  53465. + dev_set_name(&curlun->dev,"%s-lun%d",
  53466. + dev_name(&gadget->dev), i);
  53467. +
  53468. + kref_get(&fsg->ref);
  53469. + rc = device_register(&curlun->dev);
  53470. + if (rc) {
  53471. + INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
  53472. + put_device(&curlun->dev);
  53473. + goto out;
  53474. + }
  53475. + curlun->registered = 1;
  53476. +
  53477. + rc = device_create_file(&curlun->dev, &dev_attr_ro);
  53478. + if (rc)
  53479. + goto out;
  53480. + rc = device_create_file(&curlun->dev, &dev_attr_nofua);
  53481. + if (rc)
  53482. + goto out;
  53483. + rc = device_create_file(&curlun->dev, &dev_attr_file);
  53484. + if (rc)
  53485. + goto out;
  53486. +
  53487. + if (mod_data.file[i] && *mod_data.file[i]) {
  53488. + rc = fsg_lun_open(curlun, mod_data.file[i]);
  53489. + if (rc)
  53490. + goto out;
  53491. + } else if (!mod_data.removable) {
  53492. + ERROR(fsg, "no file given for LUN%d\n", i);
  53493. + rc = -EINVAL;
  53494. + goto out;
  53495. + }
  53496. + }
  53497. +
  53498. + /* Find all the endpoints we will use */
  53499. + usb_ep_autoconfig_reset(gadget);
  53500. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
  53501. + if (!ep)
  53502. + goto autoconf_fail;
  53503. + ep->driver_data = fsg; // claim the endpoint
  53504. + fsg->bulk_in = ep;
  53505. +
  53506. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
  53507. + if (!ep)
  53508. + goto autoconf_fail;
  53509. + ep->driver_data = fsg; // claim the endpoint
  53510. + fsg->bulk_out = ep;
  53511. +
  53512. + if (transport_is_cbi()) {
  53513. + ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
  53514. + if (!ep)
  53515. + goto autoconf_fail;
  53516. + ep->driver_data = fsg; // claim the endpoint
  53517. + fsg->intr_in = ep;
  53518. + }
  53519. +
  53520. + /* Fix up the descriptors */
  53521. + device_desc.idVendor = cpu_to_le16(mod_data.vendor);
  53522. + device_desc.idProduct = cpu_to_le16(mod_data.product);
  53523. + device_desc.bcdDevice = cpu_to_le16(mod_data.release);
  53524. +
  53525. + i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
  53526. + fsg_intf_desc.bNumEndpoints = i;
  53527. + fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
  53528. + fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
  53529. + fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  53530. +
  53531. + if (gadget_is_dualspeed(gadget)) {
  53532. + fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  53533. +
  53534. + /* Assume endpoint addresses are the same for both speeds */
  53535. + fsg_hs_bulk_in_desc.bEndpointAddress =
  53536. + fsg_fs_bulk_in_desc.bEndpointAddress;
  53537. + fsg_hs_bulk_out_desc.bEndpointAddress =
  53538. + fsg_fs_bulk_out_desc.bEndpointAddress;
  53539. + fsg_hs_intr_in_desc.bEndpointAddress =
  53540. + fsg_fs_intr_in_desc.bEndpointAddress;
  53541. + }
  53542. +
  53543. + if (gadget_is_superspeed(gadget)) {
  53544. + unsigned max_burst;
  53545. +
  53546. + fsg_ss_function[i + FSG_SS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  53547. +
  53548. + /* Calculate bMaxBurst, we know packet size is 1024 */
  53549. + max_burst = min_t(unsigned, mod_data.buflen / 1024, 15);
  53550. +
  53551. + /* Assume endpoint addresses are the same for both speeds */
  53552. + fsg_ss_bulk_in_desc.bEndpointAddress =
  53553. + fsg_fs_bulk_in_desc.bEndpointAddress;
  53554. + fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
  53555. +
  53556. + fsg_ss_bulk_out_desc.bEndpointAddress =
  53557. + fsg_fs_bulk_out_desc.bEndpointAddress;
  53558. + fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
  53559. + }
  53560. +
  53561. + if (gadget_is_otg(gadget))
  53562. + fsg_otg_desc.bmAttributes |= USB_OTG_HNP;
  53563. +
  53564. + rc = -ENOMEM;
  53565. +
  53566. + /* Allocate the request and buffer for endpoint 0 */
  53567. + fsg->ep0req = req = usb_ep_alloc_request(fsg->ep0, GFP_KERNEL);
  53568. + if (!req)
  53569. + goto out;
  53570. + req->buf = kmalloc(EP0_BUFSIZE, GFP_KERNEL);
  53571. + if (!req->buf)
  53572. + goto out;
  53573. + req->complete = ep0_complete;
  53574. +
  53575. + /* Allocate the data buffers */
  53576. + for (i = 0; i < fsg_num_buffers; ++i) {
  53577. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  53578. +
  53579. + /* Allocate for the bulk-in endpoint. We assume that
  53580. + * the buffer will also work with the bulk-out (and
  53581. + * interrupt-in) endpoint. */
  53582. + bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL);
  53583. + if (!bh->buf)
  53584. + goto out;
  53585. + bh->next = bh + 1;
  53586. + }
  53587. + fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0];
  53588. +
  53589. + /* This should reflect the actual gadget power source */
  53590. + usb_gadget_set_selfpowered(gadget);
  53591. +
  53592. + snprintf(fsg_string_manufacturer, sizeof fsg_string_manufacturer,
  53593. + "%s %s with %s",
  53594. + init_utsname()->sysname, init_utsname()->release,
  53595. + gadget->name);
  53596. +
  53597. + fsg->thread_task = kthread_create(fsg_main_thread, fsg,
  53598. + "file-storage-gadget");
  53599. + if (IS_ERR(fsg->thread_task)) {
  53600. + rc = PTR_ERR(fsg->thread_task);
  53601. + goto out;
  53602. + }
  53603. +
  53604. + INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
  53605. + INFO(fsg, "NOTE: This driver is deprecated. "
  53606. + "Consider using g_mass_storage instead.\n");
  53607. + INFO(fsg, "Number of LUNs=%d\n", fsg->nluns);
  53608. +
  53609. + pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
  53610. + for (i = 0; i < fsg->nluns; ++i) {
  53611. + curlun = &fsg->luns[i];
  53612. + if (fsg_lun_is_open(curlun)) {
  53613. + p = NULL;
  53614. + if (pathbuf) {
  53615. + p = d_path(&curlun->filp->f_path,
  53616. + pathbuf, PATH_MAX);
  53617. + if (IS_ERR(p))
  53618. + p = NULL;
  53619. + }
  53620. + LINFO(curlun, "ro=%d, nofua=%d, file: %s\n",
  53621. + curlun->ro, curlun->nofua, (p ? p : "(error)"));
  53622. + }
  53623. + }
  53624. + kfree(pathbuf);
  53625. +
  53626. + DBG(fsg, "transport=%s (x%02x)\n",
  53627. + mod_data.transport_name, mod_data.transport_type);
  53628. + DBG(fsg, "protocol=%s (x%02x)\n",
  53629. + mod_data.protocol_name, mod_data.protocol_type);
  53630. + DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n",
  53631. + mod_data.vendor, mod_data.product, mod_data.release);
  53632. + DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n",
  53633. + mod_data.removable, mod_data.can_stall,
  53634. + mod_data.cdrom, mod_data.buflen);
  53635. + DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task));
  53636. +
  53637. + set_bit(REGISTERED, &fsg->atomic_bitflags);
  53638. +
  53639. + /* Tell the thread to start working */
  53640. + wake_up_process(fsg->thread_task);
  53641. + return 0;
  53642. +
  53643. +autoconf_fail:
  53644. + ERROR(fsg, "unable to autoconfigure all endpoints\n");
  53645. + rc = -ENOTSUPP;
  53646. +
  53647. +out:
  53648. + fsg->state = FSG_STATE_TERMINATED; // The thread is dead
  53649. + fsg_unbind(gadget);
  53650. + complete(&fsg->thread_notifier);
  53651. + return rc;
  53652. +}
  53653. +
  53654. +
  53655. +/*-------------------------------------------------------------------------*/
  53656. +
  53657. +static void fsg_suspend(struct usb_gadget *gadget)
  53658. +{
  53659. + struct fsg_dev *fsg = get_gadget_data(gadget);
  53660. +
  53661. + DBG(fsg, "suspend\n");
  53662. + set_bit(SUSPENDED, &fsg->atomic_bitflags);
  53663. +}
  53664. +
  53665. +static void fsg_resume(struct usb_gadget *gadget)
  53666. +{
  53667. + struct fsg_dev *fsg = get_gadget_data(gadget);
  53668. +
  53669. + DBG(fsg, "resume\n");
  53670. + clear_bit(SUSPENDED, &fsg->atomic_bitflags);
  53671. +}
  53672. +
  53673. +
  53674. +/*-------------------------------------------------------------------------*/
  53675. +
  53676. +static struct usb_gadget_driver fsg_driver = {
  53677. + .max_speed = USB_SPEED_SUPER,
  53678. + .function = (char *) fsg_string_product,
  53679. + .unbind = fsg_unbind,
  53680. + .disconnect = fsg_disconnect,
  53681. + .setup = fsg_setup,
  53682. + .suspend = fsg_suspend,
  53683. + .resume = fsg_resume,
  53684. +
  53685. + .driver = {
  53686. + .name = DRIVER_NAME,
  53687. + .owner = THIS_MODULE,
  53688. + // .release = ...
  53689. + // .suspend = ...
  53690. + // .resume = ...
  53691. + },
  53692. +};
  53693. +
  53694. +
  53695. +static int __init fsg_alloc(void)
  53696. +{
  53697. + struct fsg_dev *fsg;
  53698. +
  53699. + fsg = kzalloc(sizeof *fsg +
  53700. + fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL);
  53701. +
  53702. + if (!fsg)
  53703. + return -ENOMEM;
  53704. + spin_lock_init(&fsg->lock);
  53705. + init_rwsem(&fsg->filesem);
  53706. + kref_init(&fsg->ref);
  53707. + init_completion(&fsg->thread_notifier);
  53708. +
  53709. + the_fsg = fsg;
  53710. + return 0;
  53711. +}
  53712. +
  53713. +
  53714. +static int __init fsg_init(void)
  53715. +{
  53716. + int rc;
  53717. + struct fsg_dev *fsg;
  53718. +
  53719. + rc = fsg_num_buffers_validate();
  53720. + if (rc != 0)
  53721. + return rc;
  53722. +
  53723. + if ((rc = fsg_alloc()) != 0)
  53724. + return rc;
  53725. + fsg = the_fsg;
  53726. + if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0)
  53727. + kref_put(&fsg->ref, fsg_release);
  53728. + return rc;
  53729. +}
  53730. +module_init(fsg_init);
  53731. +
  53732. +
  53733. +static void __exit fsg_cleanup(void)
  53734. +{
  53735. + struct fsg_dev *fsg = the_fsg;
  53736. +
  53737. + /* Unregister the driver iff the thread hasn't already done so */
  53738. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  53739. + usb_gadget_unregister_driver(&fsg_driver);
  53740. +
  53741. + /* Wait for the thread to finish up */
  53742. + wait_for_completion(&fsg->thread_notifier);
  53743. +
  53744. + kref_put(&fsg->ref, fsg_release);
  53745. +}
  53746. +module_exit(fsg_cleanup);
  53747. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/changes.txt linux-rpi/drivers/usb/host/dwc_common_port/changes.txt
  53748. --- linux-3.18.6/drivers/usb/host/dwc_common_port/changes.txt 1970-01-01 01:00:00.000000000 +0100
  53749. +++ linux-rpi/drivers/usb/host/dwc_common_port/changes.txt 2015-02-09 04:40:28.000000000 +0100
  53750. @@ -0,0 +1,174 @@
  53751. +
  53752. +dwc_read_reg32() and friends now take an additional parameter, a pointer to an
  53753. +IO context struct. The IO context struct should live in an os-dependent struct
  53754. +in your driver. As an example, the dwc_usb3 driver has an os-dependent struct
  53755. +named 'os_dep' embedded in the main device struct. So there these calls look
  53756. +like this:
  53757. +
  53758. + dwc_read_reg32(&usb3_dev->os_dep.ioctx, &pcd->dev_global_regs->dcfg);
  53759. +
  53760. + dwc_write_reg32(&usb3_dev->os_dep.ioctx,
  53761. + &pcd->dev_global_regs->dcfg, 0);
  53762. +
  53763. +Note that for the existing Linux driver ports, it is not necessary to actually
  53764. +define the 'ioctx' member in the os-dependent struct. Since Linux does not
  53765. +require an IO context, its macros for dwc_read_reg32() and friends do not
  53766. +use the context pointer, so it is optimized away by the compiler. But it is
  53767. +necessary to add the pointer parameter to all of the call sites, to be ready
  53768. +for any future ports (such as FreeBSD) which do require an IO context.
  53769. +
  53770. +
  53771. +Similarly, dwc_alloc(), dwc_alloc_atomic(), dwc_strdup(), and dwc_free() now
  53772. +take an additional parameter, a pointer to a memory context. Examples:
  53773. +
  53774. + addr = dwc_alloc(&usb3_dev->os_dep.memctx, size);
  53775. +
  53776. + dwc_free(&usb3_dev->os_dep.memctx, addr);
  53777. +
  53778. +Again, for the Linux ports, it is not necessary to actually define the memctx
  53779. +member, but it is necessary to add the pointer parameter to all of the call
  53780. +sites.
  53781. +
  53782. +
  53783. +Same for dwc_dma_alloc() and dwc_dma_free(). Examples:
  53784. +
  53785. + virt_addr = dwc_dma_alloc(&usb3_dev->os_dep.dmactx, size, &phys_addr);
  53786. +
  53787. + dwc_dma_free(&usb3_dev->os_dep.dmactx, size, virt_addr, phys_addr);
  53788. +
  53789. +
  53790. +Same for dwc_mutex_alloc() and dwc_mutex_free(). Examples:
  53791. +
  53792. + mutex = dwc_mutex_alloc(&usb3_dev->os_dep.mtxctx);
  53793. +
  53794. + dwc_mutex_free(&usb3_dev->os_dep.mtxctx, mutex);
  53795. +
  53796. +
  53797. +Same for dwc_spinlock_alloc() and dwc_spinlock_free(). Examples:
  53798. +
  53799. + lock = dwc_spinlock_alloc(&usb3_dev->osdep.splctx);
  53800. +
  53801. + dwc_spinlock_free(&usb3_dev->osdep.splctx, lock);
  53802. +
  53803. +
  53804. +Same for dwc_timer_alloc(). Example:
  53805. +
  53806. + timer = dwc_timer_alloc(&usb3_dev->os_dep.tmrctx, "dwc_usb3_tmr1",
  53807. + cb_func, cb_data);
  53808. +
  53809. +
  53810. +Same for dwc_waitq_alloc(). Example:
  53811. +
  53812. + waitq = dwc_waitq_alloc(&usb3_dev->os_dep.wtqctx);
  53813. +
  53814. +
  53815. +Same for dwc_thread_run(). Example:
  53816. +
  53817. + thread = dwc_thread_run(&usb3_dev->os_dep.thdctx, func,
  53818. + "dwc_usb3_thd1", data);
  53819. +
  53820. +
  53821. +Same for dwc_workq_alloc(). Example:
  53822. +
  53823. + workq = dwc_workq_alloc(&usb3_dev->osdep.wkqctx, "dwc_usb3_wkq1");
  53824. +
  53825. +
  53826. +Same for dwc_task_alloc(). Example:
  53827. +
  53828. + task = dwc_task_alloc(&usb3_dev->os_dep.tskctx, "dwc_usb3_tsk1",
  53829. + cb_func, cb_data);
  53830. +
  53831. +
  53832. +In addition to the context pointer additions, a few core functions have had
  53833. +other changes made to their parameters:
  53834. +
  53835. +The 'flags' parameter to dwc_spinlock_irqsave() and dwc_spinunlock_irqrestore()
  53836. +has been changed from a uint64_t to a dwc_irqflags_t.
  53837. +
  53838. +dwc_thread_should_stop() now takes a 'dwc_thread_t *' parameter, because the
  53839. +FreeBSD equivalent of that function requires it.
  53840. +
  53841. +And, in addition to the context pointer, dwc_task_alloc() also adds a
  53842. +'char *name' parameter, to be consistent with dwc_thread_run() and
  53843. +dwc_workq_alloc(), and because the FreeBSD equivalent of that function
  53844. +requires a unique name.
  53845. +
  53846. +
  53847. +Here is a complete list of the core functions that now take a pointer to a
  53848. +context as their first parameter:
  53849. +
  53850. + dwc_read_reg32
  53851. + dwc_read_reg64
  53852. + dwc_write_reg32
  53853. + dwc_write_reg64
  53854. + dwc_modify_reg32
  53855. + dwc_modify_reg64
  53856. + dwc_alloc
  53857. + dwc_alloc_atomic
  53858. + dwc_strdup
  53859. + dwc_free
  53860. + dwc_dma_alloc
  53861. + dwc_dma_free
  53862. + dwc_mutex_alloc
  53863. + dwc_mutex_free
  53864. + dwc_spinlock_alloc
  53865. + dwc_spinlock_free
  53866. + dwc_timer_alloc
  53867. + dwc_waitq_alloc
  53868. + dwc_thread_run
  53869. + dwc_workq_alloc
  53870. + dwc_task_alloc Also adds a 'char *name' as its 2nd parameter
  53871. +
  53872. +And here are the core functions that have other changes to their parameters:
  53873. +
  53874. + dwc_spinlock_irqsave 'flags' param is now a 'dwc_irqflags_t *'
  53875. + dwc_spinunlock_irqrestore 'flags' param is now a 'dwc_irqflags_t'
  53876. + dwc_thread_should_stop Adds a 'dwc_thread_t *' parameter
  53877. +
  53878. +
  53879. +
  53880. +The changes to the core functions also require some of the other library
  53881. +functions to change:
  53882. +
  53883. + dwc_cc_if_alloc() and dwc_cc_if_free() now take a 'void *memctx'
  53884. + (for memory allocation) as the 1st param and a 'void *mtxctx'
  53885. + (for mutex allocation) as the 2nd param.
  53886. +
  53887. + dwc_cc_clear(), dwc_cc_add(), dwc_cc_change(), dwc_cc_remove(),
  53888. + dwc_cc_data_for_save(), and dwc_cc_restore_from_data() now take a
  53889. + 'void *memctx' as the 1st param.
  53890. +
  53891. + dwc_dh_modpow(), dwc_dh_pk(), and dwc_dh_derive_keys() now take a
  53892. + 'void *memctx' as the 1st param.
  53893. +
  53894. + dwc_modpow() now takes a 'void *memctx' as the 1st param.
  53895. +
  53896. + dwc_alloc_notification_manager() now takes a 'void *memctx' as the
  53897. + 1st param and a 'void *wkqctx' (for work queue allocation) as the 2nd
  53898. + param, and also now returns an integer value that is non-zero if
  53899. + allocation of its data structures or work queue fails.
  53900. +
  53901. + dwc_register_notifier() now takes a 'void *memctx' as the 1st param.
  53902. +
  53903. + dwc_memory_debug_start() now takes a 'void *mem_ctx' as the first
  53904. + param, and also now returns an integer value that is non-zero if
  53905. + allocation of its data structures fails.
  53906. +
  53907. +
  53908. +
  53909. +Other miscellaneous changes:
  53910. +
  53911. +The DEBUG_MEMORY and DEBUG_REGS #define's have been renamed to
  53912. +DWC_DEBUG_MEMORY and DWC_DEBUG_REGS.
  53913. +
  53914. +The following #define's have been added to allow selectively compiling library
  53915. +features:
  53916. +
  53917. + DWC_CCLIB
  53918. + DWC_CRYPTOLIB
  53919. + DWC_NOTIFYLIB
  53920. + DWC_UTFLIB
  53921. +
  53922. +A DWC_LIBMODULE #define has also been added. If this is not defined, then the
  53923. +module code in dwc_common_linux.c is not compiled in. This allows linking the
  53924. +library code directly into a driver module, instead of as a standalone module.
  53925. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/doc/doxygen.cfg linux-rpi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg
  53926. --- linux-3.18.6/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  53927. +++ linux-rpi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 2015-02-09 04:40:28.000000000 +0100
  53928. @@ -0,0 +1,270 @@
  53929. +# Doxyfile 1.4.5
  53930. +
  53931. +#---------------------------------------------------------------------------
  53932. +# Project related configuration options
  53933. +#---------------------------------------------------------------------------
  53934. +PROJECT_NAME = "Synopsys DWC Portability and Common Library for UWB"
  53935. +PROJECT_NUMBER =
  53936. +OUTPUT_DIRECTORY = doc
  53937. +CREATE_SUBDIRS = NO
  53938. +OUTPUT_LANGUAGE = English
  53939. +BRIEF_MEMBER_DESC = YES
  53940. +REPEAT_BRIEF = YES
  53941. +ABBREVIATE_BRIEF = "The $name class" \
  53942. + "The $name widget" \
  53943. + "The $name file" \
  53944. + is \
  53945. + provides \
  53946. + specifies \
  53947. + contains \
  53948. + represents \
  53949. + a \
  53950. + an \
  53951. + the
  53952. +ALWAYS_DETAILED_SEC = YES
  53953. +INLINE_INHERITED_MEMB = NO
  53954. +FULL_PATH_NAMES = NO
  53955. +STRIP_FROM_PATH = ..
  53956. +STRIP_FROM_INC_PATH =
  53957. +SHORT_NAMES = NO
  53958. +JAVADOC_AUTOBRIEF = YES
  53959. +MULTILINE_CPP_IS_BRIEF = NO
  53960. +DETAILS_AT_TOP = YES
  53961. +INHERIT_DOCS = YES
  53962. +SEPARATE_MEMBER_PAGES = NO
  53963. +TAB_SIZE = 8
  53964. +ALIASES =
  53965. +OPTIMIZE_OUTPUT_FOR_C = YES
  53966. +OPTIMIZE_OUTPUT_JAVA = NO
  53967. +BUILTIN_STL_SUPPORT = NO
  53968. +DISTRIBUTE_GROUP_DOC = NO
  53969. +SUBGROUPING = NO
  53970. +#---------------------------------------------------------------------------
  53971. +# Build related configuration options
  53972. +#---------------------------------------------------------------------------
  53973. +EXTRACT_ALL = NO
  53974. +EXTRACT_PRIVATE = NO
  53975. +EXTRACT_STATIC = YES
  53976. +EXTRACT_LOCAL_CLASSES = NO
  53977. +EXTRACT_LOCAL_METHODS = NO
  53978. +HIDE_UNDOC_MEMBERS = NO
  53979. +HIDE_UNDOC_CLASSES = NO
  53980. +HIDE_FRIEND_COMPOUNDS = NO
  53981. +HIDE_IN_BODY_DOCS = NO
  53982. +INTERNAL_DOCS = NO
  53983. +CASE_SENSE_NAMES = YES
  53984. +HIDE_SCOPE_NAMES = NO
  53985. +SHOW_INCLUDE_FILES = NO
  53986. +INLINE_INFO = YES
  53987. +SORT_MEMBER_DOCS = NO
  53988. +SORT_BRIEF_DOCS = NO
  53989. +SORT_BY_SCOPE_NAME = NO
  53990. +GENERATE_TODOLIST = YES
  53991. +GENERATE_TESTLIST = YES
  53992. +GENERATE_BUGLIST = YES
  53993. +GENERATE_DEPRECATEDLIST= YES
  53994. +ENABLED_SECTIONS =
  53995. +MAX_INITIALIZER_LINES = 30
  53996. +SHOW_USED_FILES = YES
  53997. +SHOW_DIRECTORIES = YES
  53998. +FILE_VERSION_FILTER =
  53999. +#---------------------------------------------------------------------------
  54000. +# configuration options related to warning and progress messages
  54001. +#---------------------------------------------------------------------------
  54002. +QUIET = YES
  54003. +WARNINGS = YES
  54004. +WARN_IF_UNDOCUMENTED = NO
  54005. +WARN_IF_DOC_ERROR = YES
  54006. +WARN_NO_PARAMDOC = YES
  54007. +WARN_FORMAT = "$file:$line: $text"
  54008. +WARN_LOGFILE =
  54009. +#---------------------------------------------------------------------------
  54010. +# configuration options related to the input files
  54011. +#---------------------------------------------------------------------------
  54012. +INPUT = .
  54013. +FILE_PATTERNS = *.c \
  54014. + *.cc \
  54015. + *.cxx \
  54016. + *.cpp \
  54017. + *.c++ \
  54018. + *.d \
  54019. + *.java \
  54020. + *.ii \
  54021. + *.ixx \
  54022. + *.ipp \
  54023. + *.i++ \
  54024. + *.inl \
  54025. + *.h \
  54026. + *.hh \
  54027. + *.hxx \
  54028. + *.hpp \
  54029. + *.h++ \
  54030. + *.idl \
  54031. + *.odl \
  54032. + *.cs \
  54033. + *.php \
  54034. + *.php3 \
  54035. + *.inc \
  54036. + *.m \
  54037. + *.mm \
  54038. + *.dox \
  54039. + *.py \
  54040. + *.C \
  54041. + *.CC \
  54042. + *.C++ \
  54043. + *.II \
  54044. + *.I++ \
  54045. + *.H \
  54046. + *.HH \
  54047. + *.H++ \
  54048. + *.CS \
  54049. + *.PHP \
  54050. + *.PHP3 \
  54051. + *.M \
  54052. + *.MM \
  54053. + *.PY
  54054. +RECURSIVE = NO
  54055. +EXCLUDE =
  54056. +EXCLUDE_SYMLINKS = NO
  54057. +EXCLUDE_PATTERNS =
  54058. +EXAMPLE_PATH =
  54059. +EXAMPLE_PATTERNS = *
  54060. +EXAMPLE_RECURSIVE = NO
  54061. +IMAGE_PATH =
  54062. +INPUT_FILTER =
  54063. +FILTER_PATTERNS =
  54064. +FILTER_SOURCE_FILES = NO
  54065. +#---------------------------------------------------------------------------
  54066. +# configuration options related to source browsing
  54067. +#---------------------------------------------------------------------------
  54068. +SOURCE_BROWSER = NO
  54069. +INLINE_SOURCES = NO
  54070. +STRIP_CODE_COMMENTS = YES
  54071. +REFERENCED_BY_RELATION = YES
  54072. +REFERENCES_RELATION = YES
  54073. +USE_HTAGS = NO
  54074. +VERBATIM_HEADERS = NO
  54075. +#---------------------------------------------------------------------------
  54076. +# configuration options related to the alphabetical class index
  54077. +#---------------------------------------------------------------------------
  54078. +ALPHABETICAL_INDEX = NO
  54079. +COLS_IN_ALPHA_INDEX = 5
  54080. +IGNORE_PREFIX =
  54081. +#---------------------------------------------------------------------------
  54082. +# configuration options related to the HTML output
  54083. +#---------------------------------------------------------------------------
  54084. +GENERATE_HTML = YES
  54085. +HTML_OUTPUT = html
  54086. +HTML_FILE_EXTENSION = .html
  54087. +HTML_HEADER =
  54088. +HTML_FOOTER =
  54089. +HTML_STYLESHEET =
  54090. +HTML_ALIGN_MEMBERS = YES
  54091. +GENERATE_HTMLHELP = NO
  54092. +CHM_FILE =
  54093. +HHC_LOCATION =
  54094. +GENERATE_CHI = NO
  54095. +BINARY_TOC = NO
  54096. +TOC_EXPAND = NO
  54097. +DISABLE_INDEX = NO
  54098. +ENUM_VALUES_PER_LINE = 4
  54099. +GENERATE_TREEVIEW = YES
  54100. +TREEVIEW_WIDTH = 250
  54101. +#---------------------------------------------------------------------------
  54102. +# configuration options related to the LaTeX output
  54103. +#---------------------------------------------------------------------------
  54104. +GENERATE_LATEX = NO
  54105. +LATEX_OUTPUT = latex
  54106. +LATEX_CMD_NAME = latex
  54107. +MAKEINDEX_CMD_NAME = makeindex
  54108. +COMPACT_LATEX = NO
  54109. +PAPER_TYPE = a4wide
  54110. +EXTRA_PACKAGES =
  54111. +LATEX_HEADER =
  54112. +PDF_HYPERLINKS = NO
  54113. +USE_PDFLATEX = NO
  54114. +LATEX_BATCHMODE = NO
  54115. +LATEX_HIDE_INDICES = NO
  54116. +#---------------------------------------------------------------------------
  54117. +# configuration options related to the RTF output
  54118. +#---------------------------------------------------------------------------
  54119. +GENERATE_RTF = NO
  54120. +RTF_OUTPUT = rtf
  54121. +COMPACT_RTF = NO
  54122. +RTF_HYPERLINKS = NO
  54123. +RTF_STYLESHEET_FILE =
  54124. +RTF_EXTENSIONS_FILE =
  54125. +#---------------------------------------------------------------------------
  54126. +# configuration options related to the man page output
  54127. +#---------------------------------------------------------------------------
  54128. +GENERATE_MAN = NO
  54129. +MAN_OUTPUT = man
  54130. +MAN_EXTENSION = .3
  54131. +MAN_LINKS = NO
  54132. +#---------------------------------------------------------------------------
  54133. +# configuration options related to the XML output
  54134. +#---------------------------------------------------------------------------
  54135. +GENERATE_XML = NO
  54136. +XML_OUTPUT = xml
  54137. +XML_SCHEMA =
  54138. +XML_DTD =
  54139. +XML_PROGRAMLISTING = YES
  54140. +#---------------------------------------------------------------------------
  54141. +# configuration options for the AutoGen Definitions output
  54142. +#---------------------------------------------------------------------------
  54143. +GENERATE_AUTOGEN_DEF = NO
  54144. +#---------------------------------------------------------------------------
  54145. +# configuration options related to the Perl module output
  54146. +#---------------------------------------------------------------------------
  54147. +GENERATE_PERLMOD = NO
  54148. +PERLMOD_LATEX = NO
  54149. +PERLMOD_PRETTY = YES
  54150. +PERLMOD_MAKEVAR_PREFIX =
  54151. +#---------------------------------------------------------------------------
  54152. +# Configuration options related to the preprocessor
  54153. +#---------------------------------------------------------------------------
  54154. +ENABLE_PREPROCESSING = YES
  54155. +MACRO_EXPANSION = NO
  54156. +EXPAND_ONLY_PREDEF = NO
  54157. +SEARCH_INCLUDES = YES
  54158. +INCLUDE_PATH =
  54159. +INCLUDE_FILE_PATTERNS =
  54160. +PREDEFINED = DEBUG DEBUG_MEMORY
  54161. +EXPAND_AS_DEFINED =
  54162. +SKIP_FUNCTION_MACROS = YES
  54163. +#---------------------------------------------------------------------------
  54164. +# Configuration::additions related to external references
  54165. +#---------------------------------------------------------------------------
  54166. +TAGFILES =
  54167. +GENERATE_TAGFILE =
  54168. +ALLEXTERNALS = NO
  54169. +EXTERNAL_GROUPS = YES
  54170. +PERL_PATH = /usr/bin/perl
  54171. +#---------------------------------------------------------------------------
  54172. +# Configuration options related to the dot tool
  54173. +#---------------------------------------------------------------------------
  54174. +CLASS_DIAGRAMS = YES
  54175. +HIDE_UNDOC_RELATIONS = YES
  54176. +HAVE_DOT = NO
  54177. +CLASS_GRAPH = YES
  54178. +COLLABORATION_GRAPH = YES
  54179. +GROUP_GRAPHS = YES
  54180. +UML_LOOK = NO
  54181. +TEMPLATE_RELATIONS = NO
  54182. +INCLUDE_GRAPH = NO
  54183. +INCLUDED_BY_GRAPH = YES
  54184. +CALL_GRAPH = NO
  54185. +GRAPHICAL_HIERARCHY = YES
  54186. +DIRECTORY_GRAPH = YES
  54187. +DOT_IMAGE_FORMAT = png
  54188. +DOT_PATH =
  54189. +DOTFILE_DIRS =
  54190. +MAX_DOT_GRAPH_DEPTH = 1000
  54191. +DOT_TRANSPARENT = NO
  54192. +DOT_MULTI_TARGETS = NO
  54193. +GENERATE_LEGEND = YES
  54194. +DOT_CLEANUP = YES
  54195. +#---------------------------------------------------------------------------
  54196. +# Configuration::additions related to the search engine
  54197. +#---------------------------------------------------------------------------
  54198. +SEARCHENGINE = NO
  54199. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_cc.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.c
  54200. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_cc.c 1970-01-01 01:00:00.000000000 +0100
  54201. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.c 2015-02-09 04:40:28.000000000 +0100
  54202. @@ -0,0 +1,532 @@
  54203. +/* =========================================================================
  54204. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.c $
  54205. + * $Revision: #4 $
  54206. + * $Date: 2010/11/04 $
  54207. + * $Change: 1621692 $
  54208. + *
  54209. + * Synopsys Portability Library Software and documentation
  54210. + * (hereinafter, "Software") is an Unsupported proprietary work of
  54211. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  54212. + * between Synopsys and you.
  54213. + *
  54214. + * The Software IS NOT an item of Licensed Software or Licensed Product
  54215. + * under any End User Software License Agreement or Agreement for
  54216. + * Licensed Product with Synopsys or any supplement thereto. You are
  54217. + * permitted to use and redistribute this Software in source and binary
  54218. + * forms, with or without modification, provided that redistributions
  54219. + * of source code must retain this notice. You may not view, use,
  54220. + * disclose, copy or distribute this file or any information contained
  54221. + * herein except pursuant to this license grant from Synopsys. If you
  54222. + * do not agree with this notice, including the disclaimer below, then
  54223. + * you are not authorized to use the Software.
  54224. + *
  54225. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  54226. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54227. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  54228. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  54229. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  54230. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54231. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  54232. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  54233. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  54234. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  54235. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  54236. + * DAMAGE.
  54237. + * ========================================================================= */
  54238. +#ifdef DWC_CCLIB
  54239. +
  54240. +#include "dwc_cc.h"
  54241. +
  54242. +typedef struct dwc_cc
  54243. +{
  54244. + uint32_t uid;
  54245. + uint8_t chid[16];
  54246. + uint8_t cdid[16];
  54247. + uint8_t ck[16];
  54248. + uint8_t *name;
  54249. + uint8_t length;
  54250. + DWC_CIRCLEQ_ENTRY(dwc_cc) list_entry;
  54251. +} dwc_cc_t;
  54252. +
  54253. +DWC_CIRCLEQ_HEAD(context_list, dwc_cc);
  54254. +
  54255. +/** The main structure for CC management. */
  54256. +struct dwc_cc_if
  54257. +{
  54258. + dwc_mutex_t *mutex;
  54259. + char *filename;
  54260. +
  54261. + unsigned is_host:1;
  54262. +
  54263. + dwc_notifier_t *notifier;
  54264. +
  54265. + struct context_list list;
  54266. +};
  54267. +
  54268. +#ifdef DEBUG
  54269. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  54270. +{
  54271. + int i;
  54272. + DWC_PRINTF("%s: ", name);
  54273. + for (i=0; i<len; i++) {
  54274. + DWC_PRINTF("%02x ", bytes[i]);
  54275. + }
  54276. + DWC_PRINTF("\n");
  54277. +}
  54278. +#else
  54279. +#define dump_bytes(x...)
  54280. +#endif
  54281. +
  54282. +static dwc_cc_t *alloc_cc(void *mem_ctx, uint8_t *name, uint32_t length)
  54283. +{
  54284. + dwc_cc_t *cc = dwc_alloc(mem_ctx, sizeof(dwc_cc_t));
  54285. + if (!cc) {
  54286. + return NULL;
  54287. + }
  54288. + DWC_MEMSET(cc, 0, sizeof(dwc_cc_t));
  54289. +
  54290. + if (name) {
  54291. + cc->length = length;
  54292. + cc->name = dwc_alloc(mem_ctx, length);
  54293. + if (!cc->name) {
  54294. + dwc_free(mem_ctx, cc);
  54295. + return NULL;
  54296. + }
  54297. +
  54298. + DWC_MEMCPY(cc->name, name, length);
  54299. + }
  54300. +
  54301. + return cc;
  54302. +}
  54303. +
  54304. +static void free_cc(void *mem_ctx, dwc_cc_t *cc)
  54305. +{
  54306. + if (cc->name) {
  54307. + dwc_free(mem_ctx, cc->name);
  54308. + }
  54309. + dwc_free(mem_ctx, cc);
  54310. +}
  54311. +
  54312. +static uint32_t next_uid(dwc_cc_if_t *cc_if)
  54313. +{
  54314. + uint32_t uid = 0;
  54315. + dwc_cc_t *cc;
  54316. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  54317. + if (cc->uid > uid) {
  54318. + uid = cc->uid;
  54319. + }
  54320. + }
  54321. +
  54322. + if (uid == 0) {
  54323. + uid = 255;
  54324. + }
  54325. +
  54326. + return uid + 1;
  54327. +}
  54328. +
  54329. +static dwc_cc_t *cc_find(dwc_cc_if_t *cc_if, uint32_t uid)
  54330. +{
  54331. + dwc_cc_t *cc;
  54332. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  54333. + if (cc->uid == uid) {
  54334. + return cc;
  54335. + }
  54336. + }
  54337. + return NULL;
  54338. +}
  54339. +
  54340. +static unsigned int cc_data_size(dwc_cc_if_t *cc_if)
  54341. +{
  54342. + unsigned int size = 0;
  54343. + dwc_cc_t *cc;
  54344. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  54345. + size += (48 + 1);
  54346. + if (cc->name) {
  54347. + size += cc->length;
  54348. + }
  54349. + }
  54350. + return size;
  54351. +}
  54352. +
  54353. +static uint32_t cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  54354. +{
  54355. + uint32_t uid = 0;
  54356. + dwc_cc_t *cc;
  54357. +
  54358. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  54359. + if (DWC_MEMCMP(cc->chid, chid, 16) == 0) {
  54360. + uid = cc->uid;
  54361. + break;
  54362. + }
  54363. + }
  54364. + return uid;
  54365. +}
  54366. +static uint32_t cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  54367. +{
  54368. + uint32_t uid = 0;
  54369. + dwc_cc_t *cc;
  54370. +
  54371. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  54372. + if (DWC_MEMCMP(cc->cdid, cdid, 16) == 0) {
  54373. + uid = cc->uid;
  54374. + break;
  54375. + }
  54376. + }
  54377. + return uid;
  54378. +}
  54379. +
  54380. +/* Internal cc_add */
  54381. +static int32_t cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  54382. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  54383. +{
  54384. + dwc_cc_t *cc;
  54385. + uint32_t uid;
  54386. +
  54387. + if (cc_if->is_host) {
  54388. + uid = cc_match_cdid(cc_if, cdid);
  54389. + }
  54390. + else {
  54391. + uid = cc_match_chid(cc_if, chid);
  54392. + }
  54393. +
  54394. + if (uid) {
  54395. + DWC_DEBUGC("Replacing previous connection context id=%d name=%p name_len=%d", uid, name, length);
  54396. + cc = cc_find(cc_if, uid);
  54397. + }
  54398. + else {
  54399. + cc = alloc_cc(mem_ctx, name, length);
  54400. + cc->uid = next_uid(cc_if);
  54401. + DWC_CIRCLEQ_INSERT_TAIL(&cc_if->list, cc, list_entry);
  54402. + }
  54403. +
  54404. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  54405. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  54406. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  54407. +
  54408. + DWC_DEBUGC("Added connection context id=%d name=%p name_len=%d", cc->uid, name, length);
  54409. + dump_bytes("CHID", cc->chid, 16);
  54410. + dump_bytes("CDID", cc->cdid, 16);
  54411. + dump_bytes("CK", cc->ck, 16);
  54412. + return cc->uid;
  54413. +}
  54414. +
  54415. +/* Internal cc_clear */
  54416. +static void cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  54417. +{
  54418. + while (!DWC_CIRCLEQ_EMPTY(&cc_if->list)) {
  54419. + dwc_cc_t *cc = DWC_CIRCLEQ_FIRST(&cc_if->list);
  54420. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  54421. + free_cc(mem_ctx, cc);
  54422. + }
  54423. +}
  54424. +
  54425. +dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  54426. + dwc_notifier_t *notifier, unsigned is_host)
  54427. +{
  54428. + dwc_cc_if_t *cc_if = NULL;
  54429. +
  54430. + /* Allocate a common_cc_if structure */
  54431. + cc_if = dwc_alloc(mem_ctx, sizeof(dwc_cc_if_t));
  54432. +
  54433. + if (!cc_if)
  54434. + return NULL;
  54435. +
  54436. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  54437. + DWC_MUTEX_ALLOC_LINUX_DEBUG(cc_if->mutex);
  54438. +#else
  54439. + cc_if->mutex = dwc_mutex_alloc(mtx_ctx);
  54440. +#endif
  54441. + if (!cc_if->mutex) {
  54442. + dwc_free(mem_ctx, cc_if);
  54443. + return NULL;
  54444. + }
  54445. +
  54446. + DWC_CIRCLEQ_INIT(&cc_if->list);
  54447. + cc_if->is_host = is_host;
  54448. + cc_if->notifier = notifier;
  54449. + return cc_if;
  54450. +}
  54451. +
  54452. +void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if)
  54453. +{
  54454. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  54455. + DWC_MUTEX_FREE(cc_if->mutex);
  54456. +#else
  54457. + dwc_mutex_free(mtx_ctx, cc_if->mutex);
  54458. +#endif
  54459. + cc_clear(mem_ctx, cc_if);
  54460. + dwc_free(mem_ctx, cc_if);
  54461. +}
  54462. +
  54463. +static void cc_changed(dwc_cc_if_t *cc_if)
  54464. +{
  54465. + if (cc_if->notifier) {
  54466. + dwc_notify(cc_if->notifier, DWC_CC_LIST_CHANGED_NOTIFICATION, cc_if);
  54467. + }
  54468. +}
  54469. +
  54470. +void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  54471. +{
  54472. + DWC_MUTEX_LOCK(cc_if->mutex);
  54473. + cc_clear(mem_ctx, cc_if);
  54474. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54475. + cc_changed(cc_if);
  54476. +}
  54477. +
  54478. +int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  54479. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  54480. +{
  54481. + uint32_t uid;
  54482. +
  54483. + DWC_MUTEX_LOCK(cc_if->mutex);
  54484. + uid = cc_add(mem_ctx, cc_if, chid, cdid, ck, name, length);
  54485. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54486. + cc_changed(cc_if);
  54487. +
  54488. + return uid;
  54489. +}
  54490. +
  54491. +void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id, uint8_t *chid,
  54492. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  54493. +{
  54494. + dwc_cc_t* cc;
  54495. +
  54496. + DWC_DEBUGC("Change connection context %d", id);
  54497. +
  54498. + DWC_MUTEX_LOCK(cc_if->mutex);
  54499. + cc = cc_find(cc_if, id);
  54500. + if (!cc) {
  54501. + DWC_ERROR("Uid %d not found in cc list\n", id);
  54502. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54503. + return;
  54504. + }
  54505. +
  54506. + if (chid) {
  54507. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  54508. + }
  54509. + if (cdid) {
  54510. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  54511. + }
  54512. + if (ck) {
  54513. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  54514. + }
  54515. +
  54516. + if (name) {
  54517. + if (cc->name) {
  54518. + dwc_free(mem_ctx, cc->name);
  54519. + }
  54520. + cc->name = dwc_alloc(mem_ctx, length);
  54521. + if (!cc->name) {
  54522. + DWC_ERROR("Out of memory in dwc_cc_change()\n");
  54523. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54524. + return;
  54525. + }
  54526. + cc->length = length;
  54527. + DWC_MEMCPY(cc->name, name, length);
  54528. + }
  54529. +
  54530. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54531. +
  54532. + cc_changed(cc_if);
  54533. +
  54534. + DWC_DEBUGC("Changed connection context id=%d\n", id);
  54535. + dump_bytes("New CHID", cc->chid, 16);
  54536. + dump_bytes("New CDID", cc->cdid, 16);
  54537. + dump_bytes("New CK", cc->ck, 16);
  54538. +}
  54539. +
  54540. +void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id)
  54541. +{
  54542. + dwc_cc_t *cc;
  54543. +
  54544. + DWC_DEBUGC("Removing connection context %d", id);
  54545. +
  54546. + DWC_MUTEX_LOCK(cc_if->mutex);
  54547. + cc = cc_find(cc_if, id);
  54548. + if (!cc) {
  54549. + DWC_ERROR("Uid %d not found in cc list\n", id);
  54550. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54551. + return;
  54552. + }
  54553. +
  54554. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  54555. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54556. + free_cc(mem_ctx, cc);
  54557. +
  54558. + cc_changed(cc_if);
  54559. +}
  54560. +
  54561. +uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if, unsigned int *length)
  54562. +{
  54563. + uint8_t *buf, *x;
  54564. + uint8_t zero = 0;
  54565. + dwc_cc_t *cc;
  54566. +
  54567. + DWC_MUTEX_LOCK(cc_if->mutex);
  54568. + *length = cc_data_size(cc_if);
  54569. + if (!(*length)) {
  54570. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54571. + return NULL;
  54572. + }
  54573. +
  54574. + DWC_DEBUGC("Creating data for saving (length=%d)", *length);
  54575. +
  54576. + buf = dwc_alloc(mem_ctx, *length);
  54577. + if (!buf) {
  54578. + *length = 0;
  54579. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54580. + return NULL;
  54581. + }
  54582. +
  54583. + x = buf;
  54584. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  54585. + DWC_MEMCPY(x, cc->chid, 16);
  54586. + x += 16;
  54587. + DWC_MEMCPY(x, cc->cdid, 16);
  54588. + x += 16;
  54589. + DWC_MEMCPY(x, cc->ck, 16);
  54590. + x += 16;
  54591. + if (cc->name) {
  54592. + DWC_MEMCPY(x, &cc->length, 1);
  54593. + x += 1;
  54594. + DWC_MEMCPY(x, cc->name, cc->length);
  54595. + x += cc->length;
  54596. + }
  54597. + else {
  54598. + DWC_MEMCPY(x, &zero, 1);
  54599. + x += 1;
  54600. + }
  54601. + }
  54602. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54603. +
  54604. + return buf;
  54605. +}
  54606. +
  54607. +void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *data, uint32_t length)
  54608. +{
  54609. + uint8_t name_length;
  54610. + uint8_t *name;
  54611. + uint8_t *chid;
  54612. + uint8_t *cdid;
  54613. + uint8_t *ck;
  54614. + uint32_t i = 0;
  54615. +
  54616. + DWC_MUTEX_LOCK(cc_if->mutex);
  54617. + cc_clear(mem_ctx, cc_if);
  54618. +
  54619. + while (i < length) {
  54620. + chid = &data[i];
  54621. + i += 16;
  54622. + cdid = &data[i];
  54623. + i += 16;
  54624. + ck = &data[i];
  54625. + i += 16;
  54626. +
  54627. + name_length = data[i];
  54628. + i ++;
  54629. +
  54630. + if (name_length) {
  54631. + name = &data[i];
  54632. + i += name_length;
  54633. + }
  54634. + else {
  54635. + name = NULL;
  54636. + }
  54637. +
  54638. + /* check to see if we haven't overflown the buffer */
  54639. + if (i > length) {
  54640. + DWC_ERROR("Data format error while attempting to load CCs "
  54641. + "(nlen=%d, iter=%d, buflen=%d).\n", name_length, i, length);
  54642. + break;
  54643. + }
  54644. +
  54645. + cc_add(mem_ctx, cc_if, chid, cdid, ck, name, name_length);
  54646. + }
  54647. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54648. +
  54649. + cc_changed(cc_if);
  54650. +}
  54651. +
  54652. +uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  54653. +{
  54654. + uint32_t uid = 0;
  54655. +
  54656. + DWC_MUTEX_LOCK(cc_if->mutex);
  54657. + uid = cc_match_chid(cc_if, chid);
  54658. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54659. + return uid;
  54660. +}
  54661. +uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  54662. +{
  54663. + uint32_t uid = 0;
  54664. +
  54665. + DWC_MUTEX_LOCK(cc_if->mutex);
  54666. + uid = cc_match_cdid(cc_if, cdid);
  54667. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54668. + return uid;
  54669. +}
  54670. +
  54671. +uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id)
  54672. +{
  54673. + uint8_t *ck = NULL;
  54674. + dwc_cc_t *cc;
  54675. +
  54676. + DWC_MUTEX_LOCK(cc_if->mutex);
  54677. + cc = cc_find(cc_if, id);
  54678. + if (cc) {
  54679. + ck = cc->ck;
  54680. + }
  54681. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54682. +
  54683. + return ck;
  54684. +
  54685. +}
  54686. +
  54687. +uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id)
  54688. +{
  54689. + uint8_t *retval = NULL;
  54690. + dwc_cc_t *cc;
  54691. +
  54692. + DWC_MUTEX_LOCK(cc_if->mutex);
  54693. + cc = cc_find(cc_if, id);
  54694. + if (cc) {
  54695. + retval = cc->chid;
  54696. + }
  54697. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54698. +
  54699. + return retval;
  54700. +}
  54701. +
  54702. +uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id)
  54703. +{
  54704. + uint8_t *retval = NULL;
  54705. + dwc_cc_t *cc;
  54706. +
  54707. + DWC_MUTEX_LOCK(cc_if->mutex);
  54708. + cc = cc_find(cc_if, id);
  54709. + if (cc) {
  54710. + retval = cc->cdid;
  54711. + }
  54712. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54713. +
  54714. + return retval;
  54715. +}
  54716. +
  54717. +uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length)
  54718. +{
  54719. + uint8_t *retval = NULL;
  54720. + dwc_cc_t *cc;
  54721. +
  54722. + DWC_MUTEX_LOCK(cc_if->mutex);
  54723. + *length = 0;
  54724. + cc = cc_find(cc_if, id);
  54725. + if (cc) {
  54726. + *length = cc->length;
  54727. + retval = cc->name;
  54728. + }
  54729. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  54730. +
  54731. + return retval;
  54732. +}
  54733. +
  54734. +#endif /* DWC_CCLIB */
  54735. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_cc.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.h
  54736. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_cc.h 1970-01-01 01:00:00.000000000 +0100
  54737. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.h 2015-02-09 04:40:28.000000000 +0100
  54738. @@ -0,0 +1,224 @@
  54739. +/* =========================================================================
  54740. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.h $
  54741. + * $Revision: #4 $
  54742. + * $Date: 2010/09/28 $
  54743. + * $Change: 1596182 $
  54744. + *
  54745. + * Synopsys Portability Library Software and documentation
  54746. + * (hereinafter, "Software") is an Unsupported proprietary work of
  54747. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  54748. + * between Synopsys and you.
  54749. + *
  54750. + * The Software IS NOT an item of Licensed Software or Licensed Product
  54751. + * under any End User Software License Agreement or Agreement for
  54752. + * Licensed Product with Synopsys or any supplement thereto. You are
  54753. + * permitted to use and redistribute this Software in source and binary
  54754. + * forms, with or without modification, provided that redistributions
  54755. + * of source code must retain this notice. You may not view, use,
  54756. + * disclose, copy or distribute this file or any information contained
  54757. + * herein except pursuant to this license grant from Synopsys. If you
  54758. + * do not agree with this notice, including the disclaimer below, then
  54759. + * you are not authorized to use the Software.
  54760. + *
  54761. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  54762. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54763. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  54764. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  54765. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  54766. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54767. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  54768. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  54769. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  54770. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  54771. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  54772. + * DAMAGE.
  54773. + * ========================================================================= */
  54774. +#ifndef _DWC_CC_H_
  54775. +#define _DWC_CC_H_
  54776. +
  54777. +#ifdef __cplusplus
  54778. +extern "C" {
  54779. +#endif
  54780. +
  54781. +/** @file
  54782. + *
  54783. + * This file defines the Context Context library.
  54784. + *
  54785. + * The main data structure is dwc_cc_if_t which is returned by either the
  54786. + * dwc_cc_if_alloc function or returned by the module to the user via a provided
  54787. + * function. The data structure is opaque and should only be manipulated via the
  54788. + * functions provied in this API.
  54789. + *
  54790. + * It manages a list of connection contexts and operations can be performed to
  54791. + * add, remove, query, search, and change, those contexts. Additionally,
  54792. + * a dwc_notifier_t object can be requested from the manager so that
  54793. + * the user can be notified whenever the context list has changed.
  54794. + */
  54795. +
  54796. +#include "dwc_os.h"
  54797. +#include "dwc_list.h"
  54798. +#include "dwc_notifier.h"
  54799. +
  54800. +
  54801. +/* Notifications */
  54802. +#define DWC_CC_LIST_CHANGED_NOTIFICATION "DWC_CC_LIST_CHANGED_NOTIFICATION"
  54803. +
  54804. +struct dwc_cc_if;
  54805. +typedef struct dwc_cc_if dwc_cc_if_t;
  54806. +
  54807. +
  54808. +/** @name Connection Context Operations */
  54809. +/** @{ */
  54810. +
  54811. +/** This function allocates memory for a dwc_cc_if_t structure, initializes
  54812. + * fields to default values, and returns a pointer to the structure or NULL on
  54813. + * error. */
  54814. +extern dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  54815. + dwc_notifier_t *notifier, unsigned is_host);
  54816. +
  54817. +/** Frees the memory for the specified CC structure allocated from
  54818. + * dwc_cc_if_alloc(). */
  54819. +extern void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if);
  54820. +
  54821. +/** Removes all contexts from the connection context list */
  54822. +extern void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if);
  54823. +
  54824. +/** Adds a connection context (CHID, CK, CDID, Name) to the connection context list.
  54825. + * If a CHID already exists, the CK and name are overwritten. Statistics are
  54826. + * not overwritten.
  54827. + *
  54828. + * @param cc_if The cc_if structure.
  54829. + * @param chid A pointer to the 16-byte CHID. This value will be copied.
  54830. + * @param ck A pointer to the 16-byte CK. This value will be copied.
  54831. + * @param cdid A pointer to the 16-byte CDID. This value will be copied.
  54832. + * @param name An optional host friendly name as defined in the association model
  54833. + * spec. Must be a UTF16-LE unicode string. Can be NULL to indicated no name.
  54834. + * @param length The length othe unicode string.
  54835. + * @return A unique identifier used to refer to this context that is valid for
  54836. + * as long as this context is still in the list. */
  54837. +extern int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  54838. + uint8_t *cdid, uint8_t *ck, uint8_t *name,
  54839. + uint8_t length);
  54840. +
  54841. +/** Changes the CHID, CK, CDID, or Name values of a connection context in the
  54842. + * list, preserving any accumulated statistics. This would typically be called
  54843. + * if the host decideds to change the context with a SET_CONNECTION request.
  54844. + *
  54845. + * @param cc_if The cc_if structure.
  54846. + * @param id The identifier of the connection context.
  54847. + * @param chid A pointer to the 16-byte CHID. This value will be copied. NULL
  54848. + * indicates no change.
  54849. + * @param cdid A pointer to the 16-byte CDID. This value will be copied. NULL
  54850. + * indicates no change.
  54851. + * @param ck A pointer to the 16-byte CK. This value will be copied. NULL
  54852. + * indicates no change.
  54853. + * @param name Host friendly name UTF16-LE. NULL indicates no change.
  54854. + * @param length Length of name. */
  54855. +extern void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id,
  54856. + uint8_t *chid, uint8_t *cdid, uint8_t *ck,
  54857. + uint8_t *name, uint8_t length);
  54858. +
  54859. +/** Remove the specified connection context.
  54860. + * @param cc_if The cc_if structure.
  54861. + * @param id The identifier of the connection context to remove. */
  54862. +extern void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id);
  54863. +
  54864. +/** Get a binary block of data for the connection context list and attributes.
  54865. + * This data can be used by the OS specific driver to save the connection
  54866. + * context list into non-volatile memory.
  54867. + *
  54868. + * @param cc_if The cc_if structure.
  54869. + * @param length Return the length of the data buffer.
  54870. + * @return A pointer to the data buffer. The memory for this buffer should be
  54871. + * freed with DWC_FREE() after use. */
  54872. +extern uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if,
  54873. + unsigned int *length);
  54874. +
  54875. +/** Restore the connection context list from the binary data that was previously
  54876. + * returned from a call to dwc_cc_data_for_save. This can be used by the OS specific
  54877. + * driver to load a connection context list from non-volatile memory.
  54878. + *
  54879. + * @param cc_if The cc_if structure.
  54880. + * @param data The data bytes as returned from dwc_cc_data_for_save.
  54881. + * @param length The length of the data. */
  54882. +extern void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if,
  54883. + uint8_t *data, unsigned int length);
  54884. +
  54885. +/** Find the connection context from the specified CHID.
  54886. + *
  54887. + * @param cc_if The cc_if structure.
  54888. + * @param chid A pointer to the CHID data.
  54889. + * @return A non-zero identifier of the connection context if the CHID matches.
  54890. + * Otherwise returns 0. */
  54891. +extern uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid);
  54892. +
  54893. +/** Find the connection context from the specified CDID.
  54894. + *
  54895. + * @param cc_if The cc_if structure.
  54896. + * @param cdid A pointer to the CDID data.
  54897. + * @return A non-zero identifier of the connection context if the CHID matches.
  54898. + * Otherwise returns 0. */
  54899. +extern uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid);
  54900. +
  54901. +/** Retrieve the CK from the specified connection context.
  54902. + *
  54903. + * @param cc_if The cc_if structure.
  54904. + * @param id The identifier of the connection context.
  54905. + * @return A pointer to the CK data. The memory does not need to be freed. */
  54906. +extern uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id);
  54907. +
  54908. +/** Retrieve the CHID from the specified connection context.
  54909. + *
  54910. + * @param cc_if The cc_if structure.
  54911. + * @param id The identifier of the connection context.
  54912. + * @return A pointer to the CHID data. The memory does not need to be freed. */
  54913. +extern uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id);
  54914. +
  54915. +/** Retrieve the CDID from the specified connection context.
  54916. + *
  54917. + * @param cc_if The cc_if structure.
  54918. + * @param id The identifier of the connection context.
  54919. + * @return A pointer to the CDID data. The memory does not need to be freed. */
  54920. +extern uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id);
  54921. +
  54922. +extern uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length);
  54923. +
  54924. +/** Checks a buffer for non-zero.
  54925. + * @param id A pointer to a 16 byte buffer.
  54926. + * @return true if the 16 byte value is non-zero. */
  54927. +static inline unsigned dwc_assoc_is_not_zero_id(uint8_t *id) {
  54928. + int i;
  54929. + for (i=0; i<16; i++) {
  54930. + if (id[i]) return 1;
  54931. + }
  54932. + return 0;
  54933. +}
  54934. +
  54935. +/** Checks a buffer for zero.
  54936. + * @param id A pointer to a 16 byte buffer.
  54937. + * @return true if the 16 byte value is zero. */
  54938. +static inline unsigned dwc_assoc_is_zero_id(uint8_t *id) {
  54939. + return !dwc_assoc_is_not_zero_id(id);
  54940. +}
  54941. +
  54942. +/** Prints an ASCII representation for the 16-byte chid, cdid, or ck, into
  54943. + * buffer. */
  54944. +static inline int dwc_print_id_string(char *buffer, uint8_t *id) {
  54945. + char *ptr = buffer;
  54946. + int i;
  54947. + for (i=0; i<16; i++) {
  54948. + ptr += DWC_SPRINTF(ptr, "%02x", id[i]);
  54949. + if (i < 15) {
  54950. + ptr += DWC_SPRINTF(ptr, " ");
  54951. + }
  54952. + }
  54953. + return ptr - buffer;
  54954. +}
  54955. +
  54956. +/** @} */
  54957. +
  54958. +#ifdef __cplusplus
  54959. +}
  54960. +#endif
  54961. +
  54962. +#endif /* _DWC_CC_H_ */
  54963. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c
  54964. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 1970-01-01 01:00:00.000000000 +0100
  54965. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 2015-02-09 04:40:28.000000000 +0100
  54966. @@ -0,0 +1,1308 @@
  54967. +#include "dwc_os.h"
  54968. +#include "dwc_list.h"
  54969. +
  54970. +#ifdef DWC_CCLIB
  54971. +# include "dwc_cc.h"
  54972. +#endif
  54973. +
  54974. +#ifdef DWC_CRYPTOLIB
  54975. +# include "dwc_modpow.h"
  54976. +# include "dwc_dh.h"
  54977. +# include "dwc_crypto.h"
  54978. +#endif
  54979. +
  54980. +#ifdef DWC_NOTIFYLIB
  54981. +# include "dwc_notifier.h"
  54982. +#endif
  54983. +
  54984. +/* OS-Level Implementations */
  54985. +
  54986. +/* This is the FreeBSD 7.0 kernel implementation of the DWC platform library. */
  54987. +
  54988. +
  54989. +/* MISC */
  54990. +
  54991. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  54992. +{
  54993. + return memset(dest, byte, size);
  54994. +}
  54995. +
  54996. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  54997. +{
  54998. + return memcpy(dest, src, size);
  54999. +}
  55000. +
  55001. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  55002. +{
  55003. + bcopy(src, dest, size);
  55004. + return dest;
  55005. +}
  55006. +
  55007. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  55008. +{
  55009. + return memcmp(m1, m2, size);
  55010. +}
  55011. +
  55012. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  55013. +{
  55014. + return strncmp(s1, s2, size);
  55015. +}
  55016. +
  55017. +int DWC_STRCMP(void *s1, void *s2)
  55018. +{
  55019. + return strcmp(s1, s2);
  55020. +}
  55021. +
  55022. +int DWC_STRLEN(char const *str)
  55023. +{
  55024. + return strlen(str);
  55025. +}
  55026. +
  55027. +char *DWC_STRCPY(char *to, char const *from)
  55028. +{
  55029. + return strcpy(to, from);
  55030. +}
  55031. +
  55032. +char *DWC_STRDUP(char const *str)
  55033. +{
  55034. + int len = DWC_STRLEN(str) + 1;
  55035. + char *new = DWC_ALLOC_ATOMIC(len);
  55036. +
  55037. + if (!new) {
  55038. + return NULL;
  55039. + }
  55040. +
  55041. + DWC_MEMCPY(new, str, len);
  55042. + return new;
  55043. +}
  55044. +
  55045. +int DWC_ATOI(char *str, int32_t *value)
  55046. +{
  55047. + char *end = NULL;
  55048. +
  55049. + *value = strtol(str, &end, 0);
  55050. + if (*end == '\0') {
  55051. + return 0;
  55052. + }
  55053. +
  55054. + return -1;
  55055. +}
  55056. +
  55057. +int DWC_ATOUI(char *str, uint32_t *value)
  55058. +{
  55059. + char *end = NULL;
  55060. +
  55061. + *value = strtoul(str, &end, 0);
  55062. + if (*end == '\0') {
  55063. + return 0;
  55064. + }
  55065. +
  55066. + return -1;
  55067. +}
  55068. +
  55069. +
  55070. +#ifdef DWC_UTFLIB
  55071. +/* From usbstring.c */
  55072. +
  55073. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  55074. +{
  55075. + int count = 0;
  55076. + u8 c;
  55077. + u16 uchar;
  55078. +
  55079. + /* this insists on correct encodings, though not minimal ones.
  55080. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  55081. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  55082. + */
  55083. + while (len != 0 && (c = (u8) *s++) != 0) {
  55084. + if (unlikely(c & 0x80)) {
  55085. + // 2-byte sequence:
  55086. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  55087. + if ((c & 0xe0) == 0xc0) {
  55088. + uchar = (c & 0x1f) << 6;
  55089. +
  55090. + c = (u8) *s++;
  55091. + if ((c & 0xc0) != 0xc0)
  55092. + goto fail;
  55093. + c &= 0x3f;
  55094. + uchar |= c;
  55095. +
  55096. + // 3-byte sequence (most CJKV characters):
  55097. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  55098. + } else if ((c & 0xf0) == 0xe0) {
  55099. + uchar = (c & 0x0f) << 12;
  55100. +
  55101. + c = (u8) *s++;
  55102. + if ((c & 0xc0) != 0xc0)
  55103. + goto fail;
  55104. + c &= 0x3f;
  55105. + uchar |= c << 6;
  55106. +
  55107. + c = (u8) *s++;
  55108. + if ((c & 0xc0) != 0xc0)
  55109. + goto fail;
  55110. + c &= 0x3f;
  55111. + uchar |= c;
  55112. +
  55113. + /* no bogus surrogates */
  55114. + if (0xd800 <= uchar && uchar <= 0xdfff)
  55115. + goto fail;
  55116. +
  55117. + // 4-byte sequence (surrogate pairs, currently rare):
  55118. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  55119. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  55120. + // (uuuuu = wwww + 1)
  55121. + // FIXME accept the surrogate code points (only)
  55122. + } else
  55123. + goto fail;
  55124. + } else
  55125. + uchar = c;
  55126. + put_unaligned (cpu_to_le16 (uchar), cp++);
  55127. + count++;
  55128. + len--;
  55129. + }
  55130. + return count;
  55131. +fail:
  55132. + return -1;
  55133. +}
  55134. +
  55135. +#endif /* DWC_UTFLIB */
  55136. +
  55137. +
  55138. +/* dwc_debug.h */
  55139. +
  55140. +dwc_bool_t DWC_IN_IRQ(void)
  55141. +{
  55142. +// return in_irq();
  55143. + return 0;
  55144. +}
  55145. +
  55146. +dwc_bool_t DWC_IN_BH(void)
  55147. +{
  55148. +// return in_softirq();
  55149. + return 0;
  55150. +}
  55151. +
  55152. +void DWC_VPRINTF(char *format, va_list args)
  55153. +{
  55154. + vprintf(format, args);
  55155. +}
  55156. +
  55157. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  55158. +{
  55159. + return vsnprintf(str, size, format, args);
  55160. +}
  55161. +
  55162. +void DWC_PRINTF(char *format, ...)
  55163. +{
  55164. + va_list args;
  55165. +
  55166. + va_start(args, format);
  55167. + DWC_VPRINTF(format, args);
  55168. + va_end(args);
  55169. +}
  55170. +
  55171. +int DWC_SPRINTF(char *buffer, char *format, ...)
  55172. +{
  55173. + int retval;
  55174. + va_list args;
  55175. +
  55176. + va_start(args, format);
  55177. + retval = vsprintf(buffer, format, args);
  55178. + va_end(args);
  55179. + return retval;
  55180. +}
  55181. +
  55182. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  55183. +{
  55184. + int retval;
  55185. + va_list args;
  55186. +
  55187. + va_start(args, format);
  55188. + retval = vsnprintf(buffer, size, format, args);
  55189. + va_end(args);
  55190. + return retval;
  55191. +}
  55192. +
  55193. +void __DWC_WARN(char *format, ...)
  55194. +{
  55195. + va_list args;
  55196. +
  55197. + va_start(args, format);
  55198. + DWC_VPRINTF(format, args);
  55199. + va_end(args);
  55200. +}
  55201. +
  55202. +void __DWC_ERROR(char *format, ...)
  55203. +{
  55204. + va_list args;
  55205. +
  55206. + va_start(args, format);
  55207. + DWC_VPRINTF(format, args);
  55208. + va_end(args);
  55209. +}
  55210. +
  55211. +void DWC_EXCEPTION(char *format, ...)
  55212. +{
  55213. + va_list args;
  55214. +
  55215. + va_start(args, format);
  55216. + DWC_VPRINTF(format, args);
  55217. + va_end(args);
  55218. +// BUG_ON(1); ???
  55219. +}
  55220. +
  55221. +#ifdef DEBUG
  55222. +void __DWC_DEBUG(char *format, ...)
  55223. +{
  55224. + va_list args;
  55225. +
  55226. + va_start(args, format);
  55227. + DWC_VPRINTF(format, args);
  55228. + va_end(args);
  55229. +}
  55230. +#endif
  55231. +
  55232. +
  55233. +/* dwc_mem.h */
  55234. +
  55235. +#if 0
  55236. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  55237. + uint32_t align,
  55238. + uint32_t alloc)
  55239. +{
  55240. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  55241. + size, align, alloc);
  55242. + return (dwc_pool_t *)pool;
  55243. +}
  55244. +
  55245. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  55246. +{
  55247. + dma_pool_destroy((struct dma_pool *)pool);
  55248. +}
  55249. +
  55250. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  55251. +{
  55252. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  55253. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  55254. +}
  55255. +
  55256. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  55257. +{
  55258. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  55259. + memset(..);
  55260. +}
  55261. +
  55262. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  55263. +{
  55264. + dma_pool_free(pool, vaddr, daddr);
  55265. +}
  55266. +#endif
  55267. +
  55268. +static void dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
  55269. +{
  55270. + if (error)
  55271. + return;
  55272. + *(bus_addr_t *)arg = segs[0].ds_addr;
  55273. +}
  55274. +
  55275. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  55276. +{
  55277. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  55278. + int error;
  55279. +
  55280. + error = bus_dma_tag_create(
  55281. +#if __FreeBSD_version >= 700000
  55282. + bus_get_dma_tag(dma->dev), /* parent */
  55283. +#else
  55284. + NULL, /* parent */
  55285. +#endif
  55286. + 4, 0, /* alignment, bounds */
  55287. + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  55288. + BUS_SPACE_MAXADDR, /* highaddr */
  55289. + NULL, NULL, /* filter, filterarg */
  55290. + size, /* maxsize */
  55291. + 1, /* nsegments */
  55292. + size, /* maxsegsize */
  55293. + 0, /* flags */
  55294. + NULL, /* lockfunc */
  55295. + NULL, /* lockarg */
  55296. + &dma->dma_tag);
  55297. + if (error) {
  55298. + device_printf(dma->dev, "%s: bus_dma_tag_create failed: %d\n",
  55299. + __func__, error);
  55300. + goto fail_0;
  55301. + }
  55302. +
  55303. + error = bus_dmamem_alloc(dma->dma_tag, &dma->dma_vaddr,
  55304. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &dma->dma_map);
  55305. + if (error) {
  55306. + device_printf(dma->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n",
  55307. + __func__, (uintmax_t)size, error);
  55308. + goto fail_1;
  55309. + }
  55310. +
  55311. + dma->dma_paddr = 0;
  55312. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr, size,
  55313. + dmamap_cb, &dma->dma_paddr, BUS_DMA_NOWAIT);
  55314. + if (error || dma->dma_paddr == 0) {
  55315. + device_printf(dma->dev, "%s: bus_dmamap_load failed: %d\n",
  55316. + __func__, error);
  55317. + goto fail_2;
  55318. + }
  55319. +
  55320. + *dma_addr = dma->dma_paddr;
  55321. + return dma->dma_vaddr;
  55322. +
  55323. +fail_2:
  55324. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  55325. +fail_1:
  55326. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  55327. + bus_dma_tag_destroy(dma->dma_tag);
  55328. +fail_0:
  55329. + dma->dma_map = NULL;
  55330. + dma->dma_tag = NULL;
  55331. +
  55332. + return NULL;
  55333. +}
  55334. +
  55335. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  55336. +{
  55337. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  55338. +
  55339. + if (dma->dma_tag == NULL)
  55340. + return;
  55341. + if (dma->dma_map != NULL) {
  55342. + bus_dmamap_sync(dma->dma_tag, dma->dma_map,
  55343. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  55344. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  55345. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  55346. + dma->dma_map = NULL;
  55347. + }
  55348. +
  55349. + bus_dma_tag_destroy(dma->dma_tag);
  55350. + dma->dma_tag = NULL;
  55351. +}
  55352. +
  55353. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  55354. +{
  55355. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  55356. +}
  55357. +
  55358. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  55359. +{
  55360. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  55361. +}
  55362. +
  55363. +void __DWC_FREE(void *mem_ctx, void *addr)
  55364. +{
  55365. + free(addr, M_DEVBUF);
  55366. +}
  55367. +
  55368. +
  55369. +#ifdef DWC_CRYPTOLIB
  55370. +/* dwc_crypto.h */
  55371. +
  55372. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  55373. +{
  55374. + get_random_bytes(buffer, length);
  55375. +}
  55376. +
  55377. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  55378. +{
  55379. + struct crypto_blkcipher *tfm;
  55380. + struct blkcipher_desc desc;
  55381. + struct scatterlist sgd;
  55382. + struct scatterlist sgs;
  55383. +
  55384. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  55385. + if (tfm == NULL) {
  55386. + printk("failed to load transform for aes CBC\n");
  55387. + return -1;
  55388. + }
  55389. +
  55390. + crypto_blkcipher_setkey(tfm, key, keylen);
  55391. + crypto_blkcipher_set_iv(tfm, iv, 16);
  55392. +
  55393. + sg_init_one(&sgd, out, messagelen);
  55394. + sg_init_one(&sgs, message, messagelen);
  55395. +
  55396. + desc.tfm = tfm;
  55397. + desc.flags = 0;
  55398. +
  55399. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  55400. + crypto_free_blkcipher(tfm);
  55401. + DWC_ERROR("AES CBC encryption failed");
  55402. + return -1;
  55403. + }
  55404. +
  55405. + crypto_free_blkcipher(tfm);
  55406. + return 0;
  55407. +}
  55408. +
  55409. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  55410. +{
  55411. + struct crypto_hash *tfm;
  55412. + struct hash_desc desc;
  55413. + struct scatterlist sg;
  55414. +
  55415. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  55416. + if (IS_ERR(tfm)) {
  55417. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  55418. + return 0;
  55419. + }
  55420. + desc.tfm = tfm;
  55421. + desc.flags = 0;
  55422. +
  55423. + sg_init_one(&sg, message, len);
  55424. + crypto_hash_digest(&desc, &sg, len, out);
  55425. + crypto_free_hash(tfm);
  55426. +
  55427. + return 1;
  55428. +}
  55429. +
  55430. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  55431. + uint8_t *key, uint32_t keylen, uint8_t *out)
  55432. +{
  55433. + struct crypto_hash *tfm;
  55434. + struct hash_desc desc;
  55435. + struct scatterlist sg;
  55436. +
  55437. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  55438. + if (IS_ERR(tfm)) {
  55439. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  55440. + return 0;
  55441. + }
  55442. + desc.tfm = tfm;
  55443. + desc.flags = 0;
  55444. +
  55445. + sg_init_one(&sg, message, messagelen);
  55446. + crypto_hash_setkey(tfm, key, keylen);
  55447. + crypto_hash_digest(&desc, &sg, messagelen, out);
  55448. + crypto_free_hash(tfm);
  55449. +
  55450. + return 1;
  55451. +}
  55452. +
  55453. +#endif /* DWC_CRYPTOLIB */
  55454. +
  55455. +
  55456. +/* Byte Ordering Conversions */
  55457. +
  55458. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  55459. +{
  55460. +#ifdef __LITTLE_ENDIAN
  55461. + return *p;
  55462. +#else
  55463. + uint8_t *u_p = (uint8_t *)p;
  55464. +
  55465. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  55466. +#endif
  55467. +}
  55468. +
  55469. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  55470. +{
  55471. +#ifdef __BIG_ENDIAN
  55472. + return *p;
  55473. +#else
  55474. + uint8_t *u_p = (uint8_t *)p;
  55475. +
  55476. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  55477. +#endif
  55478. +}
  55479. +
  55480. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  55481. +{
  55482. +#ifdef __LITTLE_ENDIAN
  55483. + return *p;
  55484. +#else
  55485. + uint8_t *u_p = (uint8_t *)p;
  55486. +
  55487. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  55488. +#endif
  55489. +}
  55490. +
  55491. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  55492. +{
  55493. +#ifdef __BIG_ENDIAN
  55494. + return *p;
  55495. +#else
  55496. + uint8_t *u_p = (uint8_t *)p;
  55497. +
  55498. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  55499. +#endif
  55500. +}
  55501. +
  55502. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  55503. +{
  55504. +#ifdef __LITTLE_ENDIAN
  55505. + return *p;
  55506. +#else
  55507. + uint8_t *u_p = (uint8_t *)p;
  55508. + return (u_p[1] | (u_p[0] << 8));
  55509. +#endif
  55510. +}
  55511. +
  55512. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  55513. +{
  55514. +#ifdef __BIG_ENDIAN
  55515. + return *p;
  55516. +#else
  55517. + uint8_t *u_p = (uint8_t *)p;
  55518. + return (u_p[1] | (u_p[0] << 8));
  55519. +#endif
  55520. +}
  55521. +
  55522. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  55523. +{
  55524. +#ifdef __LITTLE_ENDIAN
  55525. + return *p;
  55526. +#else
  55527. + uint8_t *u_p = (uint8_t *)p;
  55528. + return (u_p[1] | (u_p[0] << 8));
  55529. +#endif
  55530. +}
  55531. +
  55532. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  55533. +{
  55534. +#ifdef __BIG_ENDIAN
  55535. + return *p;
  55536. +#else
  55537. + uint8_t *u_p = (uint8_t *)p;
  55538. + return (u_p[1] | (u_p[0] << 8));
  55539. +#endif
  55540. +}
  55541. +
  55542. +
  55543. +/* Registers */
  55544. +
  55545. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  55546. +{
  55547. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  55548. + bus_size_t ior = (bus_size_t)reg;
  55549. +
  55550. + return bus_space_read_4(io->iot, io->ioh, ior);
  55551. +}
  55552. +
  55553. +#if 0
  55554. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  55555. +{
  55556. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  55557. + bus_size_t ior = (bus_size_t)reg;
  55558. +
  55559. + return bus_space_read_8(io->iot, io->ioh, ior);
  55560. +}
  55561. +#endif
  55562. +
  55563. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  55564. +{
  55565. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  55566. + bus_size_t ior = (bus_size_t)reg;
  55567. +
  55568. + bus_space_write_4(io->iot, io->ioh, ior, value);
  55569. +}
  55570. +
  55571. +#if 0
  55572. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  55573. +{
  55574. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  55575. + bus_size_t ior = (bus_size_t)reg;
  55576. +
  55577. + bus_space_write_8(io->iot, io->ioh, ior, value);
  55578. +}
  55579. +#endif
  55580. +
  55581. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  55582. + uint32_t set_mask)
  55583. +{
  55584. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  55585. + bus_size_t ior = (bus_size_t)reg;
  55586. +
  55587. + bus_space_write_4(io->iot, io->ioh, ior,
  55588. + (bus_space_read_4(io->iot, io->ioh, ior) &
  55589. + ~clear_mask) | set_mask);
  55590. +}
  55591. +
  55592. +#if 0
  55593. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  55594. + uint64_t set_mask)
  55595. +{
  55596. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  55597. + bus_size_t ior = (bus_size_t)reg;
  55598. +
  55599. + bus_space_write_8(io->iot, io->ioh, ior,
  55600. + (bus_space_read_8(io->iot, io->ioh, ior) &
  55601. + ~clear_mask) | set_mask);
  55602. +}
  55603. +#endif
  55604. +
  55605. +
  55606. +/* Locking */
  55607. +
  55608. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  55609. +{
  55610. + struct mtx *sl = DWC_ALLOC(sizeof(*sl));
  55611. +
  55612. + if (!sl) {
  55613. + DWC_ERROR("Cannot allocate memory for spinlock");
  55614. + return NULL;
  55615. + }
  55616. +
  55617. + mtx_init(sl, "dw3spn", NULL, MTX_SPIN);
  55618. + return (dwc_spinlock_t *)sl;
  55619. +}
  55620. +
  55621. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  55622. +{
  55623. + struct mtx *sl = (struct mtx *)lock;
  55624. +
  55625. + mtx_destroy(sl);
  55626. + DWC_FREE(sl);
  55627. +}
  55628. +
  55629. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  55630. +{
  55631. + mtx_lock_spin((struct mtx *)lock); // ???
  55632. +}
  55633. +
  55634. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  55635. +{
  55636. + mtx_unlock_spin((struct mtx *)lock); // ???
  55637. +}
  55638. +
  55639. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  55640. +{
  55641. + mtx_lock_spin((struct mtx *)lock);
  55642. +}
  55643. +
  55644. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  55645. +{
  55646. + mtx_unlock_spin((struct mtx *)lock);
  55647. +}
  55648. +
  55649. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  55650. +{
  55651. + struct mtx *m;
  55652. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mtx));
  55653. +
  55654. + if (!mutex) {
  55655. + DWC_ERROR("Cannot allocate memory for mutex");
  55656. + return NULL;
  55657. + }
  55658. +
  55659. + m = (struct mtx *)mutex;
  55660. + mtx_init(m, "dw3mtx", NULL, MTX_DEF);
  55661. + return mutex;
  55662. +}
  55663. +
  55664. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  55665. +#else
  55666. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  55667. +{
  55668. + mtx_destroy((struct mtx *)mutex);
  55669. + DWC_FREE(mutex);
  55670. +}
  55671. +#endif
  55672. +
  55673. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  55674. +{
  55675. + struct mtx *m = (struct mtx *)mutex;
  55676. +
  55677. + mtx_lock(m);
  55678. +}
  55679. +
  55680. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  55681. +{
  55682. + struct mtx *m = (struct mtx *)mutex;
  55683. +
  55684. + return mtx_trylock(m);
  55685. +}
  55686. +
  55687. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  55688. +{
  55689. + struct mtx *m = (struct mtx *)mutex;
  55690. +
  55691. + mtx_unlock(m);
  55692. +}
  55693. +
  55694. +
  55695. +/* Timing */
  55696. +
  55697. +void DWC_UDELAY(uint32_t usecs)
  55698. +{
  55699. + DELAY(usecs);
  55700. +}
  55701. +
  55702. +void DWC_MDELAY(uint32_t msecs)
  55703. +{
  55704. + do {
  55705. + DELAY(1000);
  55706. + } while (--msecs);
  55707. +}
  55708. +
  55709. +void DWC_MSLEEP(uint32_t msecs)
  55710. +{
  55711. + struct timeval tv;
  55712. +
  55713. + tv.tv_sec = msecs / 1000;
  55714. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  55715. + pause("dw3slp", tvtohz(&tv));
  55716. +}
  55717. +
  55718. +uint32_t DWC_TIME(void)
  55719. +{
  55720. + struct timeval tv;
  55721. +
  55722. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  55723. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  55724. +}
  55725. +
  55726. +
  55727. +/* Timers */
  55728. +
  55729. +struct dwc_timer {
  55730. + struct callout t;
  55731. + char *name;
  55732. + dwc_spinlock_t *lock;
  55733. + dwc_timer_callback_t cb;
  55734. + void *data;
  55735. +};
  55736. +
  55737. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  55738. +{
  55739. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  55740. +
  55741. + if (!t) {
  55742. + DWC_ERROR("Cannot allocate memory for timer");
  55743. + return NULL;
  55744. + }
  55745. +
  55746. + callout_init(&t->t, 1);
  55747. +
  55748. + t->name = DWC_STRDUP(name);
  55749. + if (!t->name) {
  55750. + DWC_ERROR("Cannot allocate memory for timer->name");
  55751. + goto no_name;
  55752. + }
  55753. +
  55754. + t->lock = DWC_SPINLOCK_ALLOC();
  55755. + if (!t->lock) {
  55756. + DWC_ERROR("Cannot allocate memory for lock");
  55757. + goto no_lock;
  55758. + }
  55759. +
  55760. + t->cb = cb;
  55761. + t->data = data;
  55762. +
  55763. + return t;
  55764. +
  55765. + no_lock:
  55766. + DWC_FREE(t->name);
  55767. + no_name:
  55768. + DWC_FREE(t);
  55769. +
  55770. + return NULL;
  55771. +}
  55772. +
  55773. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  55774. +{
  55775. + callout_stop(&timer->t);
  55776. + DWC_SPINLOCK_FREE(timer->lock);
  55777. + DWC_FREE(timer->name);
  55778. + DWC_FREE(timer);
  55779. +}
  55780. +
  55781. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  55782. +{
  55783. + struct timeval tv;
  55784. +
  55785. + tv.tv_sec = time / 1000;
  55786. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  55787. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  55788. +}
  55789. +
  55790. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  55791. +{
  55792. + callout_stop(&timer->t);
  55793. +}
  55794. +
  55795. +
  55796. +/* Wait Queues */
  55797. +
  55798. +struct dwc_waitq {
  55799. + struct mtx lock;
  55800. + int abort;
  55801. +};
  55802. +
  55803. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  55804. +{
  55805. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  55806. +
  55807. + if (!wq) {
  55808. + DWC_ERROR("Cannot allocate memory for waitqueue");
  55809. + return NULL;
  55810. + }
  55811. +
  55812. + mtx_init(&wq->lock, "dw3wtq", NULL, MTX_DEF);
  55813. + wq->abort = 0;
  55814. +
  55815. + return wq;
  55816. +}
  55817. +
  55818. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  55819. +{
  55820. + mtx_destroy(&wq->lock);
  55821. + DWC_FREE(wq);
  55822. +}
  55823. +
  55824. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  55825. +{
  55826. +// intrmask_t ipl;
  55827. + int result = 0;
  55828. +
  55829. + mtx_lock(&wq->lock);
  55830. +// ipl = splbio();
  55831. +
  55832. + /* Skip the sleep if already aborted or triggered */
  55833. + if (!wq->abort && !cond(data)) {
  55834. +// splx(ipl);
  55835. + result = msleep(wq, &wq->lock, PCATCH, "dw3wat", 0); // infinite timeout
  55836. +// ipl = splbio();
  55837. + }
  55838. +
  55839. + if (result == ERESTART) { // signaled - restart
  55840. + result = -DWC_E_RESTART;
  55841. +
  55842. + } else if (result == EINTR) { // signaled - interrupt
  55843. + result = -DWC_E_ABORT;
  55844. +
  55845. + } else if (wq->abort) {
  55846. + result = -DWC_E_ABORT;
  55847. +
  55848. + } else {
  55849. + result = 0;
  55850. + }
  55851. +
  55852. + wq->abort = 0;
  55853. +// splx(ipl);
  55854. + mtx_unlock(&wq->lock);
  55855. + return result;
  55856. +}
  55857. +
  55858. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  55859. + void *data, int32_t msecs)
  55860. +{
  55861. + struct timeval tv, tv1, tv2;
  55862. +// intrmask_t ipl;
  55863. + int result = 0;
  55864. +
  55865. + tv.tv_sec = msecs / 1000;
  55866. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  55867. +
  55868. + mtx_lock(&wq->lock);
  55869. +// ipl = splbio();
  55870. +
  55871. + /* Skip the sleep if already aborted or triggered */
  55872. + if (!wq->abort && !cond(data)) {
  55873. +// splx(ipl);
  55874. + getmicrouptime(&tv1);
  55875. + result = msleep(wq, &wq->lock, PCATCH, "dw3wto", tvtohz(&tv));
  55876. + getmicrouptime(&tv2);
  55877. +// ipl = splbio();
  55878. + }
  55879. +
  55880. + if (result == 0) { // awoken
  55881. + if (wq->abort) {
  55882. + result = -DWC_E_ABORT;
  55883. + } else {
  55884. + tv2.tv_usec -= tv1.tv_usec;
  55885. + if (tv2.tv_usec < 0) {
  55886. + tv2.tv_usec += 1000000;
  55887. + tv2.tv_sec--;
  55888. + }
  55889. +
  55890. + tv2.tv_sec -= tv1.tv_sec;
  55891. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  55892. + result = msecs - result;
  55893. + if (result <= 0)
  55894. + result = 1;
  55895. + }
  55896. + } else if (result == ERESTART) { // signaled - restart
  55897. + result = -DWC_E_RESTART;
  55898. +
  55899. + } else if (result == EINTR) { // signaled - interrupt
  55900. + result = -DWC_E_ABORT;
  55901. +
  55902. + } else { // timed out
  55903. + result = -DWC_E_TIMEOUT;
  55904. + }
  55905. +
  55906. + wq->abort = 0;
  55907. +// splx(ipl);
  55908. + mtx_unlock(&wq->lock);
  55909. + return result;
  55910. +}
  55911. +
  55912. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  55913. +{
  55914. + wakeup(wq);
  55915. +}
  55916. +
  55917. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  55918. +{
  55919. +// intrmask_t ipl;
  55920. +
  55921. + mtx_lock(&wq->lock);
  55922. +// ipl = splbio();
  55923. + wq->abort = 1;
  55924. + wakeup(wq);
  55925. +// splx(ipl);
  55926. + mtx_unlock(&wq->lock);
  55927. +}
  55928. +
  55929. +
  55930. +/* Threading */
  55931. +
  55932. +struct dwc_thread {
  55933. + struct proc *proc;
  55934. + int abort;
  55935. +};
  55936. +
  55937. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  55938. +{
  55939. + int retval;
  55940. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  55941. +
  55942. + if (!thread) {
  55943. + return NULL;
  55944. + }
  55945. +
  55946. + thread->abort = 0;
  55947. + retval = kthread_create((void (*)(void *))func, data, &thread->proc,
  55948. + RFPROC | RFNOWAIT, 0, "%s", name);
  55949. + if (retval) {
  55950. + DWC_FREE(thread);
  55951. + return NULL;
  55952. + }
  55953. +
  55954. + return thread;
  55955. +}
  55956. +
  55957. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  55958. +{
  55959. + int retval;
  55960. +
  55961. + thread->abort = 1;
  55962. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  55963. +
  55964. + if (retval == 0) {
  55965. + /* DWC_THREAD_EXIT() will free the thread struct */
  55966. + return 0;
  55967. + }
  55968. +
  55969. + /* NOTE: We leak the thread struct if thread doesn't die */
  55970. +
  55971. + if (retval == EWOULDBLOCK) {
  55972. + return -DWC_E_TIMEOUT;
  55973. + }
  55974. +
  55975. + return -DWC_E_UNKNOWN;
  55976. +}
  55977. +
  55978. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  55979. +{
  55980. + return thread->abort;
  55981. +}
  55982. +
  55983. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  55984. +{
  55985. + wakeup(&thread->abort);
  55986. + DWC_FREE(thread);
  55987. + kthread_exit(0);
  55988. +}
  55989. +
  55990. +
  55991. +/* tasklets
  55992. + - Runs in interrupt context (cannot sleep)
  55993. + - Each tasklet runs on a single CPU [ How can we ensure this on FreeBSD? Does it matter? ]
  55994. + - Different tasklets can be running simultaneously on different CPUs [ shouldn't matter ]
  55995. + */
  55996. +struct dwc_tasklet {
  55997. + struct task t;
  55998. + dwc_tasklet_callback_t cb;
  55999. + void *data;
  56000. +};
  56001. +
  56002. +static void tasklet_callback(void *data, int pending) // what to do with pending ???
  56003. +{
  56004. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  56005. +
  56006. + task->cb(task->data);
  56007. +}
  56008. +
  56009. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  56010. +{
  56011. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  56012. +
  56013. + if (task) {
  56014. + task->cb = cb;
  56015. + task->data = data;
  56016. + TASK_INIT(&task->t, 0, tasklet_callback, task);
  56017. + } else {
  56018. + DWC_ERROR("Cannot allocate memory for tasklet");
  56019. + }
  56020. +
  56021. + return task;
  56022. +}
  56023. +
  56024. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  56025. +{
  56026. + taskqueue_drain(taskqueue_fast, &task->t); // ???
  56027. + DWC_FREE(task);
  56028. +}
  56029. +
  56030. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  56031. +{
  56032. + /* Uses predefined system queue */
  56033. + taskqueue_enqueue_fast(taskqueue_fast, &task->t);
  56034. +}
  56035. +
  56036. +
  56037. +/* workqueues
  56038. + - Runs in process context (can sleep)
  56039. + */
  56040. +typedef struct work_container {
  56041. + dwc_work_callback_t cb;
  56042. + void *data;
  56043. + dwc_workq_t *wq;
  56044. + char *name;
  56045. + int hz;
  56046. +
  56047. +#ifdef DEBUG
  56048. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  56049. +#endif
  56050. + struct task task;
  56051. +} work_container_t;
  56052. +
  56053. +#ifdef DEBUG
  56054. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  56055. +#endif
  56056. +
  56057. +struct dwc_workq {
  56058. + struct taskqueue *taskq;
  56059. + dwc_spinlock_t *lock;
  56060. + dwc_waitq_t *waitq;
  56061. + int pending;
  56062. +
  56063. +#ifdef DEBUG
  56064. + struct work_container_queue entries;
  56065. +#endif
  56066. +};
  56067. +
  56068. +static void do_work(void *data, int pending) // what to do with pending ???
  56069. +{
  56070. + work_container_t *container = (work_container_t *)data;
  56071. + dwc_workq_t *wq = container->wq;
  56072. + dwc_irqflags_t flags;
  56073. +
  56074. + if (container->hz) {
  56075. + pause("dw3wrk", container->hz);
  56076. + }
  56077. +
  56078. + container->cb(container->data);
  56079. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  56080. +
  56081. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  56082. +
  56083. +#ifdef DEBUG
  56084. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  56085. +#endif
  56086. + if (container->name)
  56087. + DWC_FREE(container->name);
  56088. + DWC_FREE(container);
  56089. + wq->pending--;
  56090. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  56091. + DWC_WAITQ_TRIGGER(wq->waitq);
  56092. +}
  56093. +
  56094. +static int work_done(void *data)
  56095. +{
  56096. + dwc_workq_t *workq = (dwc_workq_t *)data;
  56097. +
  56098. + return workq->pending == 0;
  56099. +}
  56100. +
  56101. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  56102. +{
  56103. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  56104. +}
  56105. +
  56106. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  56107. +{
  56108. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  56109. +
  56110. + if (!wq) {
  56111. + DWC_ERROR("Cannot allocate memory for workqueue");
  56112. + return NULL;
  56113. + }
  56114. +
  56115. + wq->taskq = taskqueue_create(name, M_NOWAIT, taskqueue_thread_enqueue, &wq->taskq);
  56116. + if (!wq->taskq) {
  56117. + DWC_ERROR("Cannot allocate memory for taskqueue");
  56118. + goto no_taskq;
  56119. + }
  56120. +
  56121. + wq->pending = 0;
  56122. +
  56123. + wq->lock = DWC_SPINLOCK_ALLOC();
  56124. + if (!wq->lock) {
  56125. + DWC_ERROR("Cannot allocate memory for spinlock");
  56126. + goto no_lock;
  56127. + }
  56128. +
  56129. + wq->waitq = DWC_WAITQ_ALLOC();
  56130. + if (!wq->waitq) {
  56131. + DWC_ERROR("Cannot allocate memory for waitqueue");
  56132. + goto no_waitq;
  56133. + }
  56134. +
  56135. + taskqueue_start_threads(&wq->taskq, 1, PWAIT, "%s taskq", "dw3tsk");
  56136. +
  56137. +#ifdef DEBUG
  56138. + DWC_CIRCLEQ_INIT(&wq->entries);
  56139. +#endif
  56140. + return wq;
  56141. +
  56142. + no_waitq:
  56143. + DWC_SPINLOCK_FREE(wq->lock);
  56144. + no_lock:
  56145. + taskqueue_free(wq->taskq);
  56146. + no_taskq:
  56147. + DWC_FREE(wq);
  56148. +
  56149. + return NULL;
  56150. +}
  56151. +
  56152. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  56153. +{
  56154. +#ifdef DEBUG
  56155. + dwc_irqflags_t flags;
  56156. +
  56157. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  56158. +
  56159. + if (wq->pending != 0) {
  56160. + struct work_container *container;
  56161. +
  56162. + DWC_ERROR("Destroying work queue with pending work");
  56163. +
  56164. + DWC_CIRCLEQ_FOREACH(container, &wq->entries, entry) {
  56165. + DWC_ERROR("Work %s still pending", container->name);
  56166. + }
  56167. + }
  56168. +
  56169. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  56170. +#endif
  56171. + DWC_WAITQ_FREE(wq->waitq);
  56172. + DWC_SPINLOCK_FREE(wq->lock);
  56173. + taskqueue_free(wq->taskq);
  56174. + DWC_FREE(wq);
  56175. +}
  56176. +
  56177. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  56178. + char *format, ...)
  56179. +{
  56180. + dwc_irqflags_t flags;
  56181. + work_container_t *container;
  56182. + static char name[128];
  56183. + va_list args;
  56184. +
  56185. + va_start(args, format);
  56186. + DWC_VSNPRINTF(name, 128, format, args);
  56187. + va_end(args);
  56188. +
  56189. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  56190. + wq->pending++;
  56191. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  56192. + DWC_WAITQ_TRIGGER(wq->waitq);
  56193. +
  56194. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  56195. + if (!container) {
  56196. + DWC_ERROR("Cannot allocate memory for container");
  56197. + return;
  56198. + }
  56199. +
  56200. + container->name = DWC_STRDUP(name);
  56201. + if (!container->name) {
  56202. + DWC_ERROR("Cannot allocate memory for container->name");
  56203. + DWC_FREE(container);
  56204. + return;
  56205. + }
  56206. +
  56207. + container->cb = cb;
  56208. + container->data = data;
  56209. + container->wq = wq;
  56210. + container->hz = 0;
  56211. +
  56212. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  56213. +
  56214. + TASK_INIT(&container->task, 0, do_work, container);
  56215. +
  56216. +#ifdef DEBUG
  56217. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  56218. +#endif
  56219. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  56220. +}
  56221. +
  56222. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  56223. + void *data, uint32_t time, char *format, ...)
  56224. +{
  56225. + dwc_irqflags_t flags;
  56226. + work_container_t *container;
  56227. + static char name[128];
  56228. + struct timeval tv;
  56229. + va_list args;
  56230. +
  56231. + va_start(args, format);
  56232. + DWC_VSNPRINTF(name, 128, format, args);
  56233. + va_end(args);
  56234. +
  56235. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  56236. + wq->pending++;
  56237. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  56238. + DWC_WAITQ_TRIGGER(wq->waitq);
  56239. +
  56240. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  56241. + if (!container) {
  56242. + DWC_ERROR("Cannot allocate memory for container");
  56243. + return;
  56244. + }
  56245. +
  56246. + container->name = DWC_STRDUP(name);
  56247. + if (!container->name) {
  56248. + DWC_ERROR("Cannot allocate memory for container->name");
  56249. + DWC_FREE(container);
  56250. + return;
  56251. + }
  56252. +
  56253. + container->cb = cb;
  56254. + container->data = data;
  56255. + container->wq = wq;
  56256. +
  56257. + tv.tv_sec = time / 1000;
  56258. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  56259. + container->hz = tvtohz(&tv);
  56260. +
  56261. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  56262. +
  56263. + TASK_INIT(&container->task, 0, do_work, container);
  56264. +
  56265. +#ifdef DEBUG
  56266. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  56267. +#endif
  56268. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  56269. +}
  56270. +
  56271. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  56272. +{
  56273. + return wq->pending;
  56274. +}
  56275. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_common_linux.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_linux.c
  56276. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_common_linux.c 1970-01-01 01:00:00.000000000 +0100
  56277. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_linux.c 2015-02-09 04:40:28.000000000 +0100
  56278. @@ -0,0 +1,1434 @@
  56279. +#include <linux/kernel.h>
  56280. +#include <linux/init.h>
  56281. +#include <linux/module.h>
  56282. +#include <linux/kthread.h>
  56283. +
  56284. +#ifdef DWC_CCLIB
  56285. +# include "dwc_cc.h"
  56286. +#endif
  56287. +
  56288. +#ifdef DWC_CRYPTOLIB
  56289. +# include "dwc_modpow.h"
  56290. +# include "dwc_dh.h"
  56291. +# include "dwc_crypto.h"
  56292. +#endif
  56293. +
  56294. +#ifdef DWC_NOTIFYLIB
  56295. +# include "dwc_notifier.h"
  56296. +#endif
  56297. +
  56298. +/* OS-Level Implementations */
  56299. +
  56300. +/* This is the Linux kernel implementation of the DWC platform library. */
  56301. +#include <linux/moduleparam.h>
  56302. +#include <linux/ctype.h>
  56303. +#include <linux/crypto.h>
  56304. +#include <linux/delay.h>
  56305. +#include <linux/device.h>
  56306. +#include <linux/dma-mapping.h>
  56307. +#include <linux/cdev.h>
  56308. +#include <linux/errno.h>
  56309. +#include <linux/interrupt.h>
  56310. +#include <linux/jiffies.h>
  56311. +#include <linux/list.h>
  56312. +#include <linux/pci.h>
  56313. +#include <linux/random.h>
  56314. +#include <linux/scatterlist.h>
  56315. +#include <linux/slab.h>
  56316. +#include <linux/stat.h>
  56317. +#include <linux/string.h>
  56318. +#include <linux/timer.h>
  56319. +#include <linux/usb.h>
  56320. +
  56321. +#include <linux/version.h>
  56322. +
  56323. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  56324. +# include <linux/usb/gadget.h>
  56325. +#else
  56326. +# include <linux/usb_gadget.h>
  56327. +#endif
  56328. +
  56329. +#include <asm/io.h>
  56330. +#include <asm/page.h>
  56331. +#include <asm/uaccess.h>
  56332. +#include <asm/unaligned.h>
  56333. +
  56334. +#include "dwc_os.h"
  56335. +#include "dwc_list.h"
  56336. +
  56337. +
  56338. +/* MISC */
  56339. +
  56340. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  56341. +{
  56342. + return memset(dest, byte, size);
  56343. +}
  56344. +
  56345. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  56346. +{
  56347. + return memcpy(dest, src, size);
  56348. +}
  56349. +
  56350. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  56351. +{
  56352. + return memmove(dest, src, size);
  56353. +}
  56354. +
  56355. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  56356. +{
  56357. + return memcmp(m1, m2, size);
  56358. +}
  56359. +
  56360. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  56361. +{
  56362. + return strncmp(s1, s2, size);
  56363. +}
  56364. +
  56365. +int DWC_STRCMP(void *s1, void *s2)
  56366. +{
  56367. + return strcmp(s1, s2);
  56368. +}
  56369. +
  56370. +int DWC_STRLEN(char const *str)
  56371. +{
  56372. + return strlen(str);
  56373. +}
  56374. +
  56375. +char *DWC_STRCPY(char *to, char const *from)
  56376. +{
  56377. + return strcpy(to, from);
  56378. +}
  56379. +
  56380. +char *DWC_STRDUP(char const *str)
  56381. +{
  56382. + int len = DWC_STRLEN(str) + 1;
  56383. + char *new = DWC_ALLOC_ATOMIC(len);
  56384. +
  56385. + if (!new) {
  56386. + return NULL;
  56387. + }
  56388. +
  56389. + DWC_MEMCPY(new, str, len);
  56390. + return new;
  56391. +}
  56392. +
  56393. +int DWC_ATOI(const char *str, int32_t *value)
  56394. +{
  56395. + char *end = NULL;
  56396. +
  56397. + *value = simple_strtol(str, &end, 0);
  56398. + if (*end == '\0') {
  56399. + return 0;
  56400. + }
  56401. +
  56402. + return -1;
  56403. +}
  56404. +
  56405. +int DWC_ATOUI(const char *str, uint32_t *value)
  56406. +{
  56407. + char *end = NULL;
  56408. +
  56409. + *value = simple_strtoul(str, &end, 0);
  56410. + if (*end == '\0') {
  56411. + return 0;
  56412. + }
  56413. +
  56414. + return -1;
  56415. +}
  56416. +
  56417. +
  56418. +#ifdef DWC_UTFLIB
  56419. +/* From usbstring.c */
  56420. +
  56421. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  56422. +{
  56423. + int count = 0;
  56424. + u8 c;
  56425. + u16 uchar;
  56426. +
  56427. + /* this insists on correct encodings, though not minimal ones.
  56428. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  56429. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  56430. + */
  56431. + while (len != 0 && (c = (u8) *s++) != 0) {
  56432. + if (unlikely(c & 0x80)) {
  56433. + // 2-byte sequence:
  56434. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  56435. + if ((c & 0xe0) == 0xc0) {
  56436. + uchar = (c & 0x1f) << 6;
  56437. +
  56438. + c = (u8) *s++;
  56439. + if ((c & 0xc0) != 0xc0)
  56440. + goto fail;
  56441. + c &= 0x3f;
  56442. + uchar |= c;
  56443. +
  56444. + // 3-byte sequence (most CJKV characters):
  56445. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  56446. + } else if ((c & 0xf0) == 0xe0) {
  56447. + uchar = (c & 0x0f) << 12;
  56448. +
  56449. + c = (u8) *s++;
  56450. + if ((c & 0xc0) != 0xc0)
  56451. + goto fail;
  56452. + c &= 0x3f;
  56453. + uchar |= c << 6;
  56454. +
  56455. + c = (u8) *s++;
  56456. + if ((c & 0xc0) != 0xc0)
  56457. + goto fail;
  56458. + c &= 0x3f;
  56459. + uchar |= c;
  56460. +
  56461. + /* no bogus surrogates */
  56462. + if (0xd800 <= uchar && uchar <= 0xdfff)
  56463. + goto fail;
  56464. +
  56465. + // 4-byte sequence (surrogate pairs, currently rare):
  56466. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  56467. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  56468. + // (uuuuu = wwww + 1)
  56469. + // FIXME accept the surrogate code points (only)
  56470. + } else
  56471. + goto fail;
  56472. + } else
  56473. + uchar = c;
  56474. + put_unaligned (cpu_to_le16 (uchar), cp++);
  56475. + count++;
  56476. + len--;
  56477. + }
  56478. + return count;
  56479. +fail:
  56480. + return -1;
  56481. +}
  56482. +#endif /* DWC_UTFLIB */
  56483. +
  56484. +
  56485. +/* dwc_debug.h */
  56486. +
  56487. +dwc_bool_t DWC_IN_IRQ(void)
  56488. +{
  56489. + return in_irq();
  56490. +}
  56491. +
  56492. +dwc_bool_t DWC_IN_BH(void)
  56493. +{
  56494. + return in_softirq();
  56495. +}
  56496. +
  56497. +void DWC_VPRINTF(char *format, va_list args)
  56498. +{
  56499. + vprintk(format, args);
  56500. +}
  56501. +
  56502. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  56503. +{
  56504. + return vsnprintf(str, size, format, args);
  56505. +}
  56506. +
  56507. +void DWC_PRINTF(char *format, ...)
  56508. +{
  56509. + va_list args;
  56510. +
  56511. + va_start(args, format);
  56512. + DWC_VPRINTF(format, args);
  56513. + va_end(args);
  56514. +}
  56515. +
  56516. +int DWC_SPRINTF(char *buffer, char *format, ...)
  56517. +{
  56518. + int retval;
  56519. + va_list args;
  56520. +
  56521. + va_start(args, format);
  56522. + retval = vsprintf(buffer, format, args);
  56523. + va_end(args);
  56524. + return retval;
  56525. +}
  56526. +
  56527. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  56528. +{
  56529. + int retval;
  56530. + va_list args;
  56531. +
  56532. + va_start(args, format);
  56533. + retval = vsnprintf(buffer, size, format, args);
  56534. + va_end(args);
  56535. + return retval;
  56536. +}
  56537. +
  56538. +void __DWC_WARN(char *format, ...)
  56539. +{
  56540. + va_list args;
  56541. +
  56542. + va_start(args, format);
  56543. + DWC_PRINTF(KERN_WARNING);
  56544. + DWC_VPRINTF(format, args);
  56545. + va_end(args);
  56546. +}
  56547. +
  56548. +void __DWC_ERROR(char *format, ...)
  56549. +{
  56550. + va_list args;
  56551. +
  56552. + va_start(args, format);
  56553. + DWC_PRINTF(KERN_ERR);
  56554. + DWC_VPRINTF(format, args);
  56555. + va_end(args);
  56556. +}
  56557. +
  56558. +void DWC_EXCEPTION(char *format, ...)
  56559. +{
  56560. + va_list args;
  56561. +
  56562. + va_start(args, format);
  56563. + DWC_PRINTF(KERN_ERR);
  56564. + DWC_VPRINTF(format, args);
  56565. + va_end(args);
  56566. + BUG_ON(1);
  56567. +}
  56568. +
  56569. +#ifdef DEBUG
  56570. +void __DWC_DEBUG(char *format, ...)
  56571. +{
  56572. + va_list args;
  56573. +
  56574. + va_start(args, format);
  56575. + DWC_PRINTF(KERN_DEBUG);
  56576. + DWC_VPRINTF(format, args);
  56577. + va_end(args);
  56578. +}
  56579. +#endif
  56580. +
  56581. +
  56582. +/* dwc_mem.h */
  56583. +
  56584. +#if 0
  56585. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  56586. + uint32_t align,
  56587. + uint32_t alloc)
  56588. +{
  56589. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  56590. + size, align, alloc);
  56591. + return (dwc_pool_t *)pool;
  56592. +}
  56593. +
  56594. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  56595. +{
  56596. + dma_pool_destroy((struct dma_pool *)pool);
  56597. +}
  56598. +
  56599. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  56600. +{
  56601. + return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  56602. +}
  56603. +
  56604. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  56605. +{
  56606. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  56607. + memset(..);
  56608. +}
  56609. +
  56610. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  56611. +{
  56612. + dma_pool_free(pool, vaddr, daddr);
  56613. +}
  56614. +#endif
  56615. +
  56616. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  56617. +{
  56618. +#ifdef xxCOSIM /* Only works for 32-bit cosim */
  56619. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL);
  56620. +#else
  56621. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL | GFP_DMA32);
  56622. +#endif
  56623. + if (!buf) {
  56624. + return NULL;
  56625. + }
  56626. +
  56627. + memset(buf, 0, (size_t)size);
  56628. + return buf;
  56629. +}
  56630. +
  56631. +void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  56632. +{
  56633. + void *buf = dma_alloc_coherent(NULL, (size_t)size, dma_addr, GFP_ATOMIC);
  56634. + if (!buf) {
  56635. + return NULL;
  56636. + }
  56637. + memset(buf, 0, (size_t)size);
  56638. + return buf;
  56639. +}
  56640. +
  56641. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  56642. +{
  56643. + dma_free_coherent(dma_ctx, size, virt_addr, dma_addr);
  56644. +}
  56645. +
  56646. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  56647. +{
  56648. + return kzalloc(size, GFP_KERNEL);
  56649. +}
  56650. +
  56651. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  56652. +{
  56653. + return kzalloc(size, GFP_ATOMIC);
  56654. +}
  56655. +
  56656. +void __DWC_FREE(void *mem_ctx, void *addr)
  56657. +{
  56658. + kfree(addr);
  56659. +}
  56660. +
  56661. +
  56662. +#ifdef DWC_CRYPTOLIB
  56663. +/* dwc_crypto.h */
  56664. +
  56665. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  56666. +{
  56667. + get_random_bytes(buffer, length);
  56668. +}
  56669. +
  56670. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  56671. +{
  56672. + struct crypto_blkcipher *tfm;
  56673. + struct blkcipher_desc desc;
  56674. + struct scatterlist sgd;
  56675. + struct scatterlist sgs;
  56676. +
  56677. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  56678. + if (tfm == NULL) {
  56679. + printk("failed to load transform for aes CBC\n");
  56680. + return -1;
  56681. + }
  56682. +
  56683. + crypto_blkcipher_setkey(tfm, key, keylen);
  56684. + crypto_blkcipher_set_iv(tfm, iv, 16);
  56685. +
  56686. + sg_init_one(&sgd, out, messagelen);
  56687. + sg_init_one(&sgs, message, messagelen);
  56688. +
  56689. + desc.tfm = tfm;
  56690. + desc.flags = 0;
  56691. +
  56692. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  56693. + crypto_free_blkcipher(tfm);
  56694. + DWC_ERROR("AES CBC encryption failed");
  56695. + return -1;
  56696. + }
  56697. +
  56698. + crypto_free_blkcipher(tfm);
  56699. + return 0;
  56700. +}
  56701. +
  56702. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  56703. +{
  56704. + struct crypto_hash *tfm;
  56705. + struct hash_desc desc;
  56706. + struct scatterlist sg;
  56707. +
  56708. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  56709. + if (IS_ERR(tfm)) {
  56710. + DWC_ERROR("Failed to load transform for sha256: %ld\n", PTR_ERR(tfm));
  56711. + return 0;
  56712. + }
  56713. + desc.tfm = tfm;
  56714. + desc.flags = 0;
  56715. +
  56716. + sg_init_one(&sg, message, len);
  56717. + crypto_hash_digest(&desc, &sg, len, out);
  56718. + crypto_free_hash(tfm);
  56719. +
  56720. + return 1;
  56721. +}
  56722. +
  56723. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  56724. + uint8_t *key, uint32_t keylen, uint8_t *out)
  56725. +{
  56726. + struct crypto_hash *tfm;
  56727. + struct hash_desc desc;
  56728. + struct scatterlist sg;
  56729. +
  56730. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  56731. + if (IS_ERR(tfm)) {
  56732. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld\n", PTR_ERR(tfm));
  56733. + return 0;
  56734. + }
  56735. + desc.tfm = tfm;
  56736. + desc.flags = 0;
  56737. +
  56738. + sg_init_one(&sg, message, messagelen);
  56739. + crypto_hash_setkey(tfm, key, keylen);
  56740. + crypto_hash_digest(&desc, &sg, messagelen, out);
  56741. + crypto_free_hash(tfm);
  56742. +
  56743. + return 1;
  56744. +}
  56745. +#endif /* DWC_CRYPTOLIB */
  56746. +
  56747. +
  56748. +/* Byte Ordering Conversions */
  56749. +
  56750. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  56751. +{
  56752. +#ifdef __LITTLE_ENDIAN
  56753. + return *p;
  56754. +#else
  56755. + uint8_t *u_p = (uint8_t *)p;
  56756. +
  56757. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  56758. +#endif
  56759. +}
  56760. +
  56761. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  56762. +{
  56763. +#ifdef __BIG_ENDIAN
  56764. + return *p;
  56765. +#else
  56766. + uint8_t *u_p = (uint8_t *)p;
  56767. +
  56768. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  56769. +#endif
  56770. +}
  56771. +
  56772. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  56773. +{
  56774. +#ifdef __LITTLE_ENDIAN
  56775. + return *p;
  56776. +#else
  56777. + uint8_t *u_p = (uint8_t *)p;
  56778. +
  56779. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  56780. +#endif
  56781. +}
  56782. +
  56783. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  56784. +{
  56785. +#ifdef __BIG_ENDIAN
  56786. + return *p;
  56787. +#else
  56788. + uint8_t *u_p = (uint8_t *)p;
  56789. +
  56790. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  56791. +#endif
  56792. +}
  56793. +
  56794. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  56795. +{
  56796. +#ifdef __LITTLE_ENDIAN
  56797. + return *p;
  56798. +#else
  56799. + uint8_t *u_p = (uint8_t *)p;
  56800. + return (u_p[1] | (u_p[0] << 8));
  56801. +#endif
  56802. +}
  56803. +
  56804. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  56805. +{
  56806. +#ifdef __BIG_ENDIAN
  56807. + return *p;
  56808. +#else
  56809. + uint8_t *u_p = (uint8_t *)p;
  56810. + return (u_p[1] | (u_p[0] << 8));
  56811. +#endif
  56812. +}
  56813. +
  56814. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  56815. +{
  56816. +#ifdef __LITTLE_ENDIAN
  56817. + return *p;
  56818. +#else
  56819. + uint8_t *u_p = (uint8_t *)p;
  56820. + return (u_p[1] | (u_p[0] << 8));
  56821. +#endif
  56822. +}
  56823. +
  56824. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  56825. +{
  56826. +#ifdef __BIG_ENDIAN
  56827. + return *p;
  56828. +#else
  56829. + uint8_t *u_p = (uint8_t *)p;
  56830. + return (u_p[1] | (u_p[0] << 8));
  56831. +#endif
  56832. +}
  56833. +
  56834. +
  56835. +/* Registers */
  56836. +
  56837. +uint32_t DWC_READ_REG32(uint32_t volatile *reg)
  56838. +{
  56839. + return readl(reg);
  56840. +}
  56841. +
  56842. +#if 0
  56843. +uint64_t DWC_READ_REG64(uint64_t volatile *reg)
  56844. +{
  56845. +}
  56846. +#endif
  56847. +
  56848. +void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value)
  56849. +{
  56850. + writel(value, reg);
  56851. +}
  56852. +
  56853. +#if 0
  56854. +void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value)
  56855. +{
  56856. +}
  56857. +#endif
  56858. +
  56859. +void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask)
  56860. +{
  56861. + writel((readl(reg) & ~clear_mask) | set_mask, reg);
  56862. +}
  56863. +
  56864. +#if 0
  56865. +void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask)
  56866. +{
  56867. +}
  56868. +#endif
  56869. +
  56870. +
  56871. +/* Locking */
  56872. +
  56873. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  56874. +{
  56875. + spinlock_t *sl = (spinlock_t *)1;
  56876. +
  56877. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  56878. + sl = DWC_ALLOC(sizeof(*sl));
  56879. + if (!sl) {
  56880. + DWC_ERROR("Cannot allocate memory for spinlock\n");
  56881. + return NULL;
  56882. + }
  56883. +
  56884. + spin_lock_init(sl);
  56885. +#endif
  56886. + return (dwc_spinlock_t *)sl;
  56887. +}
  56888. +
  56889. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  56890. +{
  56891. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  56892. + DWC_FREE(lock);
  56893. +#endif
  56894. +}
  56895. +
  56896. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  56897. +{
  56898. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  56899. + spin_lock((spinlock_t *)lock);
  56900. +#endif
  56901. +}
  56902. +
  56903. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  56904. +{
  56905. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  56906. + spin_unlock((spinlock_t *)lock);
  56907. +#endif
  56908. +}
  56909. +
  56910. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  56911. +{
  56912. + dwc_irqflags_t f;
  56913. +
  56914. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  56915. + spin_lock_irqsave((spinlock_t *)lock, f);
  56916. +#else
  56917. + local_irq_save(f);
  56918. +#endif
  56919. + *flags = f;
  56920. +}
  56921. +
  56922. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  56923. +{
  56924. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  56925. + spin_unlock_irqrestore((spinlock_t *)lock, flags);
  56926. +#else
  56927. + local_irq_restore(flags);
  56928. +#endif
  56929. +}
  56930. +
  56931. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  56932. +{
  56933. + struct mutex *m;
  56934. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex));
  56935. +
  56936. + if (!mutex) {
  56937. + DWC_ERROR("Cannot allocate memory for mutex\n");
  56938. + return NULL;
  56939. + }
  56940. +
  56941. + m = (struct mutex *)mutex;
  56942. + mutex_init(m);
  56943. + return mutex;
  56944. +}
  56945. +
  56946. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  56947. +#else
  56948. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  56949. +{
  56950. + mutex_destroy((struct mutex *)mutex);
  56951. + DWC_FREE(mutex);
  56952. +}
  56953. +#endif
  56954. +
  56955. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  56956. +{
  56957. + struct mutex *m = (struct mutex *)mutex;
  56958. + mutex_lock(m);
  56959. +}
  56960. +
  56961. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  56962. +{
  56963. + struct mutex *m = (struct mutex *)mutex;
  56964. + return mutex_trylock(m);
  56965. +}
  56966. +
  56967. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  56968. +{
  56969. + struct mutex *m = (struct mutex *)mutex;
  56970. + mutex_unlock(m);
  56971. +}
  56972. +
  56973. +
  56974. +/* Timing */
  56975. +
  56976. +void DWC_UDELAY(uint32_t usecs)
  56977. +{
  56978. + udelay(usecs);
  56979. +}
  56980. +
  56981. +void DWC_MDELAY(uint32_t msecs)
  56982. +{
  56983. + mdelay(msecs);
  56984. +}
  56985. +
  56986. +void DWC_MSLEEP(uint32_t msecs)
  56987. +{
  56988. + msleep(msecs);
  56989. +}
  56990. +
  56991. +uint32_t DWC_TIME(void)
  56992. +{
  56993. + return jiffies_to_msecs(jiffies);
  56994. +}
  56995. +
  56996. +
  56997. +/* Timers */
  56998. +
  56999. +struct dwc_timer {
  57000. + struct timer_list *t;
  57001. + char *name;
  57002. + dwc_timer_callback_t cb;
  57003. + void *data;
  57004. + uint8_t scheduled;
  57005. + dwc_spinlock_t *lock;
  57006. +};
  57007. +
  57008. +static void timer_callback(unsigned long data)
  57009. +{
  57010. + dwc_timer_t *timer = (dwc_timer_t *)data;
  57011. + dwc_irqflags_t flags;
  57012. +
  57013. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  57014. + timer->scheduled = 0;
  57015. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  57016. + DWC_DEBUGC("Timer %s callback", timer->name);
  57017. + timer->cb(timer->data);
  57018. +}
  57019. +
  57020. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  57021. +{
  57022. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  57023. +
  57024. + if (!t) {
  57025. + DWC_ERROR("Cannot allocate memory for timer");
  57026. + return NULL;
  57027. + }
  57028. +
  57029. + t->t = DWC_ALLOC(sizeof(*t->t));
  57030. + if (!t->t) {
  57031. + DWC_ERROR("Cannot allocate memory for timer->t");
  57032. + goto no_timer;
  57033. + }
  57034. +
  57035. + t->name = DWC_STRDUP(name);
  57036. + if (!t->name) {
  57037. + DWC_ERROR("Cannot allocate memory for timer->name");
  57038. + goto no_name;
  57039. + }
  57040. +
  57041. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK))
  57042. + DWC_SPINLOCK_ALLOC_LINUX_DEBUG(t->lock);
  57043. +#else
  57044. + t->lock = DWC_SPINLOCK_ALLOC();
  57045. +#endif
  57046. + if (!t->lock) {
  57047. + DWC_ERROR("Cannot allocate memory for lock");
  57048. + goto no_lock;
  57049. + }
  57050. +
  57051. + t->scheduled = 0;
  57052. + t->t->base = &boot_tvec_bases;
  57053. + t->t->expires = jiffies;
  57054. + setup_timer(t->t, timer_callback, (unsigned long)t);
  57055. +
  57056. + t->cb = cb;
  57057. + t->data = data;
  57058. +
  57059. + return t;
  57060. +
  57061. + no_lock:
  57062. + DWC_FREE(t->name);
  57063. + no_name:
  57064. + DWC_FREE(t->t);
  57065. + no_timer:
  57066. + DWC_FREE(t);
  57067. + return NULL;
  57068. +}
  57069. +
  57070. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  57071. +{
  57072. + dwc_irqflags_t flags;
  57073. +
  57074. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  57075. +
  57076. + if (timer->scheduled) {
  57077. + del_timer(timer->t);
  57078. + timer->scheduled = 0;
  57079. + }
  57080. +
  57081. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  57082. + DWC_SPINLOCK_FREE(timer->lock);
  57083. + DWC_FREE(timer->t);
  57084. + DWC_FREE(timer->name);
  57085. + DWC_FREE(timer);
  57086. +}
  57087. +
  57088. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  57089. +{
  57090. + dwc_irqflags_t flags;
  57091. +
  57092. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  57093. +
  57094. + if (!timer->scheduled) {
  57095. + timer->scheduled = 1;
  57096. + DWC_DEBUGC("Scheduling timer %s to expire in +%d msec", timer->name, time);
  57097. + timer->t->expires = jiffies + msecs_to_jiffies(time);
  57098. + add_timer(timer->t);
  57099. + } else {
  57100. + DWC_DEBUGC("Modifying timer %s to expire in +%d msec", timer->name, time);
  57101. + mod_timer(timer->t, jiffies + msecs_to_jiffies(time));
  57102. + }
  57103. +
  57104. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  57105. +}
  57106. +
  57107. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  57108. +{
  57109. + del_timer(timer->t);
  57110. +}
  57111. +
  57112. +
  57113. +/* Wait Queues */
  57114. +
  57115. +struct dwc_waitq {
  57116. + wait_queue_head_t queue;
  57117. + int abort;
  57118. +};
  57119. +
  57120. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  57121. +{
  57122. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  57123. +
  57124. + if (!wq) {
  57125. + DWC_ERROR("Cannot allocate memory for waitqueue\n");
  57126. + return NULL;
  57127. + }
  57128. +
  57129. + init_waitqueue_head(&wq->queue);
  57130. + wq->abort = 0;
  57131. + return wq;
  57132. +}
  57133. +
  57134. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  57135. +{
  57136. + DWC_FREE(wq);
  57137. +}
  57138. +
  57139. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  57140. +{
  57141. + int result = wait_event_interruptible(wq->queue,
  57142. + cond(data) || wq->abort);
  57143. + if (result == -ERESTARTSYS) {
  57144. + wq->abort = 0;
  57145. + return -DWC_E_RESTART;
  57146. + }
  57147. +
  57148. + if (wq->abort == 1) {
  57149. + wq->abort = 0;
  57150. + return -DWC_E_ABORT;
  57151. + }
  57152. +
  57153. + wq->abort = 0;
  57154. +
  57155. + if (result == 0) {
  57156. + return 0;
  57157. + }
  57158. +
  57159. + return -DWC_E_UNKNOWN;
  57160. +}
  57161. +
  57162. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  57163. + void *data, int32_t msecs)
  57164. +{
  57165. + int32_t tmsecs;
  57166. + int result = wait_event_interruptible_timeout(wq->queue,
  57167. + cond(data) || wq->abort,
  57168. + msecs_to_jiffies(msecs));
  57169. + if (result == -ERESTARTSYS) {
  57170. + wq->abort = 0;
  57171. + return -DWC_E_RESTART;
  57172. + }
  57173. +
  57174. + if (wq->abort == 1) {
  57175. + wq->abort = 0;
  57176. + return -DWC_E_ABORT;
  57177. + }
  57178. +
  57179. + wq->abort = 0;
  57180. +
  57181. + if (result > 0) {
  57182. + tmsecs = jiffies_to_msecs(result);
  57183. + if (!tmsecs) {
  57184. + return 1;
  57185. + }
  57186. +
  57187. + return tmsecs;
  57188. + }
  57189. +
  57190. + if (result == 0) {
  57191. + return -DWC_E_TIMEOUT;
  57192. + }
  57193. +
  57194. + return -DWC_E_UNKNOWN;
  57195. +}
  57196. +
  57197. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  57198. +{
  57199. + wq->abort = 0;
  57200. + wake_up_interruptible(&wq->queue);
  57201. +}
  57202. +
  57203. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  57204. +{
  57205. + wq->abort = 1;
  57206. + wake_up_interruptible(&wq->queue);
  57207. +}
  57208. +
  57209. +
  57210. +/* Threading */
  57211. +
  57212. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  57213. +{
  57214. + struct task_struct *thread = kthread_run(func, data, name);
  57215. +
  57216. + if (thread == ERR_PTR(-ENOMEM)) {
  57217. + return NULL;
  57218. + }
  57219. +
  57220. + return (dwc_thread_t *)thread;
  57221. +}
  57222. +
  57223. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  57224. +{
  57225. + return kthread_stop((struct task_struct *)thread);
  57226. +}
  57227. +
  57228. +dwc_bool_t DWC_THREAD_SHOULD_STOP(void)
  57229. +{
  57230. + return kthread_should_stop();
  57231. +}
  57232. +
  57233. +
  57234. +/* tasklets
  57235. + - run in interrupt context (cannot sleep)
  57236. + - each tasklet runs on a single CPU
  57237. + - different tasklets can be running simultaneously on different CPUs
  57238. + */
  57239. +struct dwc_tasklet {
  57240. + struct tasklet_struct t;
  57241. + dwc_tasklet_callback_t cb;
  57242. + void *data;
  57243. +};
  57244. +
  57245. +static void tasklet_callback(unsigned long data)
  57246. +{
  57247. + dwc_tasklet_t *t = (dwc_tasklet_t *)data;
  57248. + t->cb(t->data);
  57249. +}
  57250. +
  57251. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  57252. +{
  57253. + dwc_tasklet_t *t = DWC_ALLOC(sizeof(*t));
  57254. +
  57255. + if (t) {
  57256. + t->cb = cb;
  57257. + t->data = data;
  57258. + tasklet_init(&t->t, tasklet_callback, (unsigned long)t);
  57259. + } else {
  57260. + DWC_ERROR("Cannot allocate memory for tasklet\n");
  57261. + }
  57262. +
  57263. + return t;
  57264. +}
  57265. +
  57266. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  57267. +{
  57268. + DWC_FREE(task);
  57269. +}
  57270. +
  57271. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  57272. +{
  57273. + tasklet_schedule(&task->t);
  57274. +}
  57275. +
  57276. +void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task)
  57277. +{
  57278. + tasklet_hi_schedule(&task->t);
  57279. +}
  57280. +
  57281. +
  57282. +/* workqueues
  57283. + - run in process context (can sleep)
  57284. + */
  57285. +typedef struct work_container {
  57286. + dwc_work_callback_t cb;
  57287. + void *data;
  57288. + dwc_workq_t *wq;
  57289. + char *name;
  57290. +
  57291. +#ifdef DEBUG
  57292. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  57293. +#endif
  57294. + struct delayed_work work;
  57295. +} work_container_t;
  57296. +
  57297. +#ifdef DEBUG
  57298. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  57299. +#endif
  57300. +
  57301. +struct dwc_workq {
  57302. + struct workqueue_struct *wq;
  57303. + dwc_spinlock_t *lock;
  57304. + dwc_waitq_t *waitq;
  57305. + int pending;
  57306. +
  57307. +#ifdef DEBUG
  57308. + struct work_container_queue entries;
  57309. +#endif
  57310. +};
  57311. +
  57312. +static void do_work(struct work_struct *work)
  57313. +{
  57314. + dwc_irqflags_t flags;
  57315. + struct delayed_work *dw = container_of(work, struct delayed_work, work);
  57316. + work_container_t *container = container_of(dw, struct work_container, work);
  57317. + dwc_workq_t *wq = container->wq;
  57318. +
  57319. + container->cb(container->data);
  57320. +
  57321. +#ifdef DEBUG
  57322. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  57323. +#endif
  57324. + DWC_DEBUGC("Work done: %s, container=%p", container->name, container);
  57325. + if (container->name) {
  57326. + DWC_FREE(container->name);
  57327. + }
  57328. + DWC_FREE(container);
  57329. +
  57330. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  57331. + wq->pending--;
  57332. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  57333. + DWC_WAITQ_TRIGGER(wq->waitq);
  57334. +}
  57335. +
  57336. +static int work_done(void *data)
  57337. +{
  57338. + dwc_workq_t *workq = (dwc_workq_t *)data;
  57339. + return workq->pending == 0;
  57340. +}
  57341. +
  57342. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  57343. +{
  57344. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  57345. +}
  57346. +
  57347. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  57348. +{
  57349. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  57350. +
  57351. + if (!wq) {
  57352. + return NULL;
  57353. + }
  57354. +
  57355. + wq->wq = create_singlethread_workqueue(name);
  57356. + if (!wq->wq) {
  57357. + goto no_wq;
  57358. + }
  57359. +
  57360. + wq->pending = 0;
  57361. +
  57362. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK))
  57363. + DWC_SPINLOCK_ALLOC_LINUX_DEBUG(wq->lock);
  57364. +#else
  57365. + wq->lock = DWC_SPINLOCK_ALLOC();
  57366. +#endif
  57367. + if (!wq->lock) {
  57368. + goto no_lock;
  57369. + }
  57370. +
  57371. + wq->waitq = DWC_WAITQ_ALLOC();
  57372. + if (!wq->waitq) {
  57373. + goto no_waitq;
  57374. + }
  57375. +
  57376. +#ifdef DEBUG
  57377. + DWC_CIRCLEQ_INIT(&wq->entries);
  57378. +#endif
  57379. + return wq;
  57380. +
  57381. + no_waitq:
  57382. + DWC_SPINLOCK_FREE(wq->lock);
  57383. + no_lock:
  57384. + destroy_workqueue(wq->wq);
  57385. + no_wq:
  57386. + DWC_FREE(wq);
  57387. +
  57388. + return NULL;
  57389. +}
  57390. +
  57391. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  57392. +{
  57393. +#ifdef DEBUG
  57394. + if (wq->pending != 0) {
  57395. + struct work_container *wc;
  57396. + DWC_ERROR("Destroying work queue with pending work");
  57397. + DWC_CIRCLEQ_FOREACH(wc, &wq->entries, entry) {
  57398. + DWC_ERROR("Work %s still pending", wc->name);
  57399. + }
  57400. + }
  57401. +#endif
  57402. + destroy_workqueue(wq->wq);
  57403. + DWC_SPINLOCK_FREE(wq->lock);
  57404. + DWC_WAITQ_FREE(wq->waitq);
  57405. + DWC_FREE(wq);
  57406. +}
  57407. +
  57408. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  57409. + char *format, ...)
  57410. +{
  57411. + dwc_irqflags_t flags;
  57412. + work_container_t *container;
  57413. + static char name[128];
  57414. + va_list args;
  57415. +
  57416. + va_start(args, format);
  57417. + DWC_VSNPRINTF(name, 128, format, args);
  57418. + va_end(args);
  57419. +
  57420. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  57421. + wq->pending++;
  57422. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  57423. + DWC_WAITQ_TRIGGER(wq->waitq);
  57424. +
  57425. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  57426. + if (!container) {
  57427. + DWC_ERROR("Cannot allocate memory for container\n");
  57428. + return;
  57429. + }
  57430. +
  57431. + container->name = DWC_STRDUP(name);
  57432. + if (!container->name) {
  57433. + DWC_ERROR("Cannot allocate memory for container->name\n");
  57434. + DWC_FREE(container);
  57435. + return;
  57436. + }
  57437. +
  57438. + container->cb = cb;
  57439. + container->data = data;
  57440. + container->wq = wq;
  57441. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  57442. + INIT_WORK(&container->work.work, do_work);
  57443. +
  57444. +#ifdef DEBUG
  57445. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  57446. +#endif
  57447. + queue_work(wq->wq, &container->work.work);
  57448. +}
  57449. +
  57450. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  57451. + void *data, uint32_t time, char *format, ...)
  57452. +{
  57453. + dwc_irqflags_t flags;
  57454. + work_container_t *container;
  57455. + static char name[128];
  57456. + va_list args;
  57457. +
  57458. + va_start(args, format);
  57459. + DWC_VSNPRINTF(name, 128, format, args);
  57460. + va_end(args);
  57461. +
  57462. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  57463. + wq->pending++;
  57464. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  57465. + DWC_WAITQ_TRIGGER(wq->waitq);
  57466. +
  57467. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  57468. + if (!container) {
  57469. + DWC_ERROR("Cannot allocate memory for container\n");
  57470. + return;
  57471. + }
  57472. +
  57473. + container->name = DWC_STRDUP(name);
  57474. + if (!container->name) {
  57475. + DWC_ERROR("Cannot allocate memory for container->name\n");
  57476. + DWC_FREE(container);
  57477. + return;
  57478. + }
  57479. +
  57480. + container->cb = cb;
  57481. + container->data = data;
  57482. + container->wq = wq;
  57483. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  57484. + INIT_DELAYED_WORK(&container->work, do_work);
  57485. +
  57486. +#ifdef DEBUG
  57487. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  57488. +#endif
  57489. + queue_delayed_work(wq->wq, &container->work, msecs_to_jiffies(time));
  57490. +}
  57491. +
  57492. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  57493. +{
  57494. + return wq->pending;
  57495. +}
  57496. +
  57497. +
  57498. +#ifdef DWC_LIBMODULE
  57499. +
  57500. +#ifdef DWC_CCLIB
  57501. +/* CC */
  57502. +EXPORT_SYMBOL(dwc_cc_if_alloc);
  57503. +EXPORT_SYMBOL(dwc_cc_if_free);
  57504. +EXPORT_SYMBOL(dwc_cc_clear);
  57505. +EXPORT_SYMBOL(dwc_cc_add);
  57506. +EXPORT_SYMBOL(dwc_cc_remove);
  57507. +EXPORT_SYMBOL(dwc_cc_change);
  57508. +EXPORT_SYMBOL(dwc_cc_data_for_save);
  57509. +EXPORT_SYMBOL(dwc_cc_restore_from_data);
  57510. +EXPORT_SYMBOL(dwc_cc_match_chid);
  57511. +EXPORT_SYMBOL(dwc_cc_match_cdid);
  57512. +EXPORT_SYMBOL(dwc_cc_ck);
  57513. +EXPORT_SYMBOL(dwc_cc_chid);
  57514. +EXPORT_SYMBOL(dwc_cc_cdid);
  57515. +EXPORT_SYMBOL(dwc_cc_name);
  57516. +#endif /* DWC_CCLIB */
  57517. +
  57518. +#ifdef DWC_CRYPTOLIB
  57519. +# ifndef CONFIG_MACH_IPMATE
  57520. +/* Modpow */
  57521. +EXPORT_SYMBOL(dwc_modpow);
  57522. +
  57523. +/* DH */
  57524. +EXPORT_SYMBOL(dwc_dh_modpow);
  57525. +EXPORT_SYMBOL(dwc_dh_derive_keys);
  57526. +EXPORT_SYMBOL(dwc_dh_pk);
  57527. +# endif /* CONFIG_MACH_IPMATE */
  57528. +
  57529. +/* Crypto */
  57530. +EXPORT_SYMBOL(dwc_wusb_aes_encrypt);
  57531. +EXPORT_SYMBOL(dwc_wusb_cmf);
  57532. +EXPORT_SYMBOL(dwc_wusb_prf);
  57533. +EXPORT_SYMBOL(dwc_wusb_fill_ccm_nonce);
  57534. +EXPORT_SYMBOL(dwc_wusb_gen_nonce);
  57535. +EXPORT_SYMBOL(dwc_wusb_gen_key);
  57536. +EXPORT_SYMBOL(dwc_wusb_gen_mic);
  57537. +#endif /* DWC_CRYPTOLIB */
  57538. +
  57539. +/* Notification */
  57540. +#ifdef DWC_NOTIFYLIB
  57541. +EXPORT_SYMBOL(dwc_alloc_notification_manager);
  57542. +EXPORT_SYMBOL(dwc_free_notification_manager);
  57543. +EXPORT_SYMBOL(dwc_register_notifier);
  57544. +EXPORT_SYMBOL(dwc_unregister_notifier);
  57545. +EXPORT_SYMBOL(dwc_add_observer);
  57546. +EXPORT_SYMBOL(dwc_remove_observer);
  57547. +EXPORT_SYMBOL(dwc_notify);
  57548. +#endif
  57549. +
  57550. +/* Memory Debugging Routines */
  57551. +#ifdef DWC_DEBUG_MEMORY
  57552. +EXPORT_SYMBOL(dwc_alloc_debug);
  57553. +EXPORT_SYMBOL(dwc_alloc_atomic_debug);
  57554. +EXPORT_SYMBOL(dwc_free_debug);
  57555. +EXPORT_SYMBOL(dwc_dma_alloc_debug);
  57556. +EXPORT_SYMBOL(dwc_dma_free_debug);
  57557. +#endif
  57558. +
  57559. +EXPORT_SYMBOL(DWC_MEMSET);
  57560. +EXPORT_SYMBOL(DWC_MEMCPY);
  57561. +EXPORT_SYMBOL(DWC_MEMMOVE);
  57562. +EXPORT_SYMBOL(DWC_MEMCMP);
  57563. +EXPORT_SYMBOL(DWC_STRNCMP);
  57564. +EXPORT_SYMBOL(DWC_STRCMP);
  57565. +EXPORT_SYMBOL(DWC_STRLEN);
  57566. +EXPORT_SYMBOL(DWC_STRCPY);
  57567. +EXPORT_SYMBOL(DWC_STRDUP);
  57568. +EXPORT_SYMBOL(DWC_ATOI);
  57569. +EXPORT_SYMBOL(DWC_ATOUI);
  57570. +
  57571. +#ifdef DWC_UTFLIB
  57572. +EXPORT_SYMBOL(DWC_UTF8_TO_UTF16LE);
  57573. +#endif /* DWC_UTFLIB */
  57574. +
  57575. +EXPORT_SYMBOL(DWC_IN_IRQ);
  57576. +EXPORT_SYMBOL(DWC_IN_BH);
  57577. +EXPORT_SYMBOL(DWC_VPRINTF);
  57578. +EXPORT_SYMBOL(DWC_VSNPRINTF);
  57579. +EXPORT_SYMBOL(DWC_PRINTF);
  57580. +EXPORT_SYMBOL(DWC_SPRINTF);
  57581. +EXPORT_SYMBOL(DWC_SNPRINTF);
  57582. +EXPORT_SYMBOL(__DWC_WARN);
  57583. +EXPORT_SYMBOL(__DWC_ERROR);
  57584. +EXPORT_SYMBOL(DWC_EXCEPTION);
  57585. +
  57586. +#ifdef DEBUG
  57587. +EXPORT_SYMBOL(__DWC_DEBUG);
  57588. +#endif
  57589. +
  57590. +EXPORT_SYMBOL(__DWC_DMA_ALLOC);
  57591. +EXPORT_SYMBOL(__DWC_DMA_ALLOC_ATOMIC);
  57592. +EXPORT_SYMBOL(__DWC_DMA_FREE);
  57593. +EXPORT_SYMBOL(__DWC_ALLOC);
  57594. +EXPORT_SYMBOL(__DWC_ALLOC_ATOMIC);
  57595. +EXPORT_SYMBOL(__DWC_FREE);
  57596. +
  57597. +#ifdef DWC_CRYPTOLIB
  57598. +EXPORT_SYMBOL(DWC_RANDOM_BYTES);
  57599. +EXPORT_SYMBOL(DWC_AES_CBC);
  57600. +EXPORT_SYMBOL(DWC_SHA256);
  57601. +EXPORT_SYMBOL(DWC_HMAC_SHA256);
  57602. +#endif
  57603. +
  57604. +EXPORT_SYMBOL(DWC_CPU_TO_LE32);
  57605. +EXPORT_SYMBOL(DWC_CPU_TO_BE32);
  57606. +EXPORT_SYMBOL(DWC_LE32_TO_CPU);
  57607. +EXPORT_SYMBOL(DWC_BE32_TO_CPU);
  57608. +EXPORT_SYMBOL(DWC_CPU_TO_LE16);
  57609. +EXPORT_SYMBOL(DWC_CPU_TO_BE16);
  57610. +EXPORT_SYMBOL(DWC_LE16_TO_CPU);
  57611. +EXPORT_SYMBOL(DWC_BE16_TO_CPU);
  57612. +EXPORT_SYMBOL(DWC_READ_REG32);
  57613. +EXPORT_SYMBOL(DWC_WRITE_REG32);
  57614. +EXPORT_SYMBOL(DWC_MODIFY_REG32);
  57615. +
  57616. +#if 0
  57617. +EXPORT_SYMBOL(DWC_READ_REG64);
  57618. +EXPORT_SYMBOL(DWC_WRITE_REG64);
  57619. +EXPORT_SYMBOL(DWC_MODIFY_REG64);
  57620. +#endif
  57621. +
  57622. +EXPORT_SYMBOL(DWC_SPINLOCK_ALLOC);
  57623. +EXPORT_SYMBOL(DWC_SPINLOCK_FREE);
  57624. +EXPORT_SYMBOL(DWC_SPINLOCK);
  57625. +EXPORT_SYMBOL(DWC_SPINUNLOCK);
  57626. +EXPORT_SYMBOL(DWC_SPINLOCK_IRQSAVE);
  57627. +EXPORT_SYMBOL(DWC_SPINUNLOCK_IRQRESTORE);
  57628. +EXPORT_SYMBOL(DWC_MUTEX_ALLOC);
  57629. +
  57630. +#if (!defined(DWC_LINUX) || !defined(CONFIG_DEBUG_MUTEXES))
  57631. +EXPORT_SYMBOL(DWC_MUTEX_FREE);
  57632. +#endif
  57633. +
  57634. +EXPORT_SYMBOL(DWC_MUTEX_LOCK);
  57635. +EXPORT_SYMBOL(DWC_MUTEX_TRYLOCK);
  57636. +EXPORT_SYMBOL(DWC_MUTEX_UNLOCK);
  57637. +EXPORT_SYMBOL(DWC_UDELAY);
  57638. +EXPORT_SYMBOL(DWC_MDELAY);
  57639. +EXPORT_SYMBOL(DWC_MSLEEP);
  57640. +EXPORT_SYMBOL(DWC_TIME);
  57641. +EXPORT_SYMBOL(DWC_TIMER_ALLOC);
  57642. +EXPORT_SYMBOL(DWC_TIMER_FREE);
  57643. +EXPORT_SYMBOL(DWC_TIMER_SCHEDULE);
  57644. +EXPORT_SYMBOL(DWC_TIMER_CANCEL);
  57645. +EXPORT_SYMBOL(DWC_WAITQ_ALLOC);
  57646. +EXPORT_SYMBOL(DWC_WAITQ_FREE);
  57647. +EXPORT_SYMBOL(DWC_WAITQ_WAIT);
  57648. +EXPORT_SYMBOL(DWC_WAITQ_WAIT_TIMEOUT);
  57649. +EXPORT_SYMBOL(DWC_WAITQ_TRIGGER);
  57650. +EXPORT_SYMBOL(DWC_WAITQ_ABORT);
  57651. +EXPORT_SYMBOL(DWC_THREAD_RUN);
  57652. +EXPORT_SYMBOL(DWC_THREAD_STOP);
  57653. +EXPORT_SYMBOL(DWC_THREAD_SHOULD_STOP);
  57654. +EXPORT_SYMBOL(DWC_TASK_ALLOC);
  57655. +EXPORT_SYMBOL(DWC_TASK_FREE);
  57656. +EXPORT_SYMBOL(DWC_TASK_SCHEDULE);
  57657. +EXPORT_SYMBOL(DWC_WORKQ_WAIT_WORK_DONE);
  57658. +EXPORT_SYMBOL(DWC_WORKQ_ALLOC);
  57659. +EXPORT_SYMBOL(DWC_WORKQ_FREE);
  57660. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE);
  57661. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE_DELAYED);
  57662. +EXPORT_SYMBOL(DWC_WORKQ_PENDING);
  57663. +
  57664. +static int dwc_common_port_init_module(void)
  57665. +{
  57666. + int result = 0;
  57667. +
  57668. + printk(KERN_DEBUG "Module dwc_common_port init\n" );
  57669. +
  57670. +#ifdef DWC_DEBUG_MEMORY
  57671. + result = dwc_memory_debug_start(NULL);
  57672. + if (result) {
  57673. + printk(KERN_ERR
  57674. + "dwc_memory_debug_start() failed with error %d\n",
  57675. + result);
  57676. + return result;
  57677. + }
  57678. +#endif
  57679. +
  57680. +#ifdef DWC_NOTIFYLIB
  57681. + result = dwc_alloc_notification_manager(NULL, NULL);
  57682. + if (result) {
  57683. + printk(KERN_ERR
  57684. + "dwc_alloc_notification_manager() failed with error %d\n",
  57685. + result);
  57686. + return result;
  57687. + }
  57688. +#endif
  57689. + return result;
  57690. +}
  57691. +
  57692. +static void dwc_common_port_exit_module(void)
  57693. +{
  57694. + printk(KERN_DEBUG "Module dwc_common_port exit\n" );
  57695. +
  57696. +#ifdef DWC_NOTIFYLIB
  57697. + dwc_free_notification_manager();
  57698. +#endif
  57699. +
  57700. +#ifdef DWC_DEBUG_MEMORY
  57701. + dwc_memory_debug_stop();
  57702. +#endif
  57703. +}
  57704. +
  57705. +module_init(dwc_common_port_init_module);
  57706. +module_exit(dwc_common_port_exit_module);
  57707. +
  57708. +MODULE_DESCRIPTION("DWC Common Library - Portable version");
  57709. +MODULE_AUTHOR("Synopsys Inc.");
  57710. +MODULE_LICENSE ("GPL");
  57711. +
  57712. +#endif /* DWC_LIBMODULE */
  57713. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c
  57714. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 1970-01-01 01:00:00.000000000 +0100
  57715. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 2015-02-09 04:40:28.000000000 +0100
  57716. @@ -0,0 +1,1275 @@
  57717. +#include "dwc_os.h"
  57718. +#include "dwc_list.h"
  57719. +
  57720. +#ifdef DWC_CCLIB
  57721. +# include "dwc_cc.h"
  57722. +#endif
  57723. +
  57724. +#ifdef DWC_CRYPTOLIB
  57725. +# include "dwc_modpow.h"
  57726. +# include "dwc_dh.h"
  57727. +# include "dwc_crypto.h"
  57728. +#endif
  57729. +
  57730. +#ifdef DWC_NOTIFYLIB
  57731. +# include "dwc_notifier.h"
  57732. +#endif
  57733. +
  57734. +/* OS-Level Implementations */
  57735. +
  57736. +/* This is the NetBSD 4.0.1 kernel implementation of the DWC platform library. */
  57737. +
  57738. +
  57739. +/* MISC */
  57740. +
  57741. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  57742. +{
  57743. + return memset(dest, byte, size);
  57744. +}
  57745. +
  57746. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  57747. +{
  57748. + return memcpy(dest, src, size);
  57749. +}
  57750. +
  57751. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  57752. +{
  57753. + bcopy(src, dest, size);
  57754. + return dest;
  57755. +}
  57756. +
  57757. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  57758. +{
  57759. + return memcmp(m1, m2, size);
  57760. +}
  57761. +
  57762. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  57763. +{
  57764. + return strncmp(s1, s2, size);
  57765. +}
  57766. +
  57767. +int DWC_STRCMP(void *s1, void *s2)
  57768. +{
  57769. + return strcmp(s1, s2);
  57770. +}
  57771. +
  57772. +int DWC_STRLEN(char const *str)
  57773. +{
  57774. + return strlen(str);
  57775. +}
  57776. +
  57777. +char *DWC_STRCPY(char *to, char const *from)
  57778. +{
  57779. + return strcpy(to, from);
  57780. +}
  57781. +
  57782. +char *DWC_STRDUP(char const *str)
  57783. +{
  57784. + int len = DWC_STRLEN(str) + 1;
  57785. + char *new = DWC_ALLOC_ATOMIC(len);
  57786. +
  57787. + if (!new) {
  57788. + return NULL;
  57789. + }
  57790. +
  57791. + DWC_MEMCPY(new, str, len);
  57792. + return new;
  57793. +}
  57794. +
  57795. +int DWC_ATOI(char *str, int32_t *value)
  57796. +{
  57797. + char *end = NULL;
  57798. +
  57799. + /* NetBSD doesn't have 'strtol' in the kernel, but 'strtoul'
  57800. + * should be equivalent on 2's complement machines
  57801. + */
  57802. + *value = strtoul(str, &end, 0);
  57803. + if (*end == '\0') {
  57804. + return 0;
  57805. + }
  57806. +
  57807. + return -1;
  57808. +}
  57809. +
  57810. +int DWC_ATOUI(char *str, uint32_t *value)
  57811. +{
  57812. + char *end = NULL;
  57813. +
  57814. + *value = strtoul(str, &end, 0);
  57815. + if (*end == '\0') {
  57816. + return 0;
  57817. + }
  57818. +
  57819. + return -1;
  57820. +}
  57821. +
  57822. +
  57823. +#ifdef DWC_UTFLIB
  57824. +/* From usbstring.c */
  57825. +
  57826. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  57827. +{
  57828. + int count = 0;
  57829. + u8 c;
  57830. + u16 uchar;
  57831. +
  57832. + /* this insists on correct encodings, though not minimal ones.
  57833. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  57834. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  57835. + */
  57836. + while (len != 0 && (c = (u8) *s++) != 0) {
  57837. + if (unlikely(c & 0x80)) {
  57838. + // 2-byte sequence:
  57839. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  57840. + if ((c & 0xe0) == 0xc0) {
  57841. + uchar = (c & 0x1f) << 6;
  57842. +
  57843. + c = (u8) *s++;
  57844. + if ((c & 0xc0) != 0xc0)
  57845. + goto fail;
  57846. + c &= 0x3f;
  57847. + uchar |= c;
  57848. +
  57849. + // 3-byte sequence (most CJKV characters):
  57850. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  57851. + } else if ((c & 0xf0) == 0xe0) {
  57852. + uchar = (c & 0x0f) << 12;
  57853. +
  57854. + c = (u8) *s++;
  57855. + if ((c & 0xc0) != 0xc0)
  57856. + goto fail;
  57857. + c &= 0x3f;
  57858. + uchar |= c << 6;
  57859. +
  57860. + c = (u8) *s++;
  57861. + if ((c & 0xc0) != 0xc0)
  57862. + goto fail;
  57863. + c &= 0x3f;
  57864. + uchar |= c;
  57865. +
  57866. + /* no bogus surrogates */
  57867. + if (0xd800 <= uchar && uchar <= 0xdfff)
  57868. + goto fail;
  57869. +
  57870. + // 4-byte sequence (surrogate pairs, currently rare):
  57871. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  57872. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  57873. + // (uuuuu = wwww + 1)
  57874. + // FIXME accept the surrogate code points (only)
  57875. + } else
  57876. + goto fail;
  57877. + } else
  57878. + uchar = c;
  57879. + put_unaligned (cpu_to_le16 (uchar), cp++);
  57880. + count++;
  57881. + len--;
  57882. + }
  57883. + return count;
  57884. +fail:
  57885. + return -1;
  57886. +}
  57887. +
  57888. +#endif /* DWC_UTFLIB */
  57889. +
  57890. +
  57891. +/* dwc_debug.h */
  57892. +
  57893. +dwc_bool_t DWC_IN_IRQ(void)
  57894. +{
  57895. +// return in_irq();
  57896. + return 0;
  57897. +}
  57898. +
  57899. +dwc_bool_t DWC_IN_BH(void)
  57900. +{
  57901. +// return in_softirq();
  57902. + return 0;
  57903. +}
  57904. +
  57905. +void DWC_VPRINTF(char *format, va_list args)
  57906. +{
  57907. + vprintf(format, args);
  57908. +}
  57909. +
  57910. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  57911. +{
  57912. + return vsnprintf(str, size, format, args);
  57913. +}
  57914. +
  57915. +void DWC_PRINTF(char *format, ...)
  57916. +{
  57917. + va_list args;
  57918. +
  57919. + va_start(args, format);
  57920. + DWC_VPRINTF(format, args);
  57921. + va_end(args);
  57922. +}
  57923. +
  57924. +int DWC_SPRINTF(char *buffer, char *format, ...)
  57925. +{
  57926. + int retval;
  57927. + va_list args;
  57928. +
  57929. + va_start(args, format);
  57930. + retval = vsprintf(buffer, format, args);
  57931. + va_end(args);
  57932. + return retval;
  57933. +}
  57934. +
  57935. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  57936. +{
  57937. + int retval;
  57938. + va_list args;
  57939. +
  57940. + va_start(args, format);
  57941. + retval = vsnprintf(buffer, size, format, args);
  57942. + va_end(args);
  57943. + return retval;
  57944. +}
  57945. +
  57946. +void __DWC_WARN(char *format, ...)
  57947. +{
  57948. + va_list args;
  57949. +
  57950. + va_start(args, format);
  57951. + DWC_VPRINTF(format, args);
  57952. + va_end(args);
  57953. +}
  57954. +
  57955. +void __DWC_ERROR(char *format, ...)
  57956. +{
  57957. + va_list args;
  57958. +
  57959. + va_start(args, format);
  57960. + DWC_VPRINTF(format, args);
  57961. + va_end(args);
  57962. +}
  57963. +
  57964. +void DWC_EXCEPTION(char *format, ...)
  57965. +{
  57966. + va_list args;
  57967. +
  57968. + va_start(args, format);
  57969. + DWC_VPRINTF(format, args);
  57970. + va_end(args);
  57971. +// BUG_ON(1); ???
  57972. +}
  57973. +
  57974. +#ifdef DEBUG
  57975. +void __DWC_DEBUG(char *format, ...)
  57976. +{
  57977. + va_list args;
  57978. +
  57979. + va_start(args, format);
  57980. + DWC_VPRINTF(format, args);
  57981. + va_end(args);
  57982. +}
  57983. +#endif
  57984. +
  57985. +
  57986. +/* dwc_mem.h */
  57987. +
  57988. +#if 0
  57989. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  57990. + uint32_t align,
  57991. + uint32_t alloc)
  57992. +{
  57993. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  57994. + size, align, alloc);
  57995. + return (dwc_pool_t *)pool;
  57996. +}
  57997. +
  57998. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  57999. +{
  58000. + dma_pool_destroy((struct dma_pool *)pool);
  58001. +}
  58002. +
  58003. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  58004. +{
  58005. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  58006. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  58007. +}
  58008. +
  58009. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  58010. +{
  58011. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  58012. + memset(..);
  58013. +}
  58014. +
  58015. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  58016. +{
  58017. + dma_pool_free(pool, vaddr, daddr);
  58018. +}
  58019. +#endif
  58020. +
  58021. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  58022. +{
  58023. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  58024. + int error;
  58025. +
  58026. + error = bus_dmamem_alloc(dma->dma_tag, size, 1, size, dma->segs,
  58027. + sizeof(dma->segs) / sizeof(dma->segs[0]),
  58028. + &dma->nsegs, BUS_DMA_NOWAIT);
  58029. + if (error) {
  58030. + printf("%s: bus_dmamem_alloc(%ju) failed: %d\n", __func__,
  58031. + (uintmax_t)size, error);
  58032. + goto fail_0;
  58033. + }
  58034. +
  58035. + error = bus_dmamem_map(dma->dma_tag, dma->segs, dma->nsegs, size,
  58036. + (caddr_t *)&dma->dma_vaddr,
  58037. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
  58038. + if (error) {
  58039. + printf("%s: bus_dmamem_map failed: %d\n", __func__, error);
  58040. + goto fail_1;
  58041. + }
  58042. +
  58043. + error = bus_dmamap_create(dma->dma_tag, size, 1, size, 0,
  58044. + BUS_DMA_NOWAIT, &dma->dma_map);
  58045. + if (error) {
  58046. + printf("%s: bus_dmamap_create failed: %d\n", __func__, error);
  58047. + goto fail_2;
  58048. + }
  58049. +
  58050. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
  58051. + size, NULL, BUS_DMA_NOWAIT);
  58052. + if (error) {
  58053. + printf("%s: bus_dmamap_load failed: %d\n", __func__, error);
  58054. + goto fail_3;
  58055. + }
  58056. +
  58057. + dma->dma_paddr = (bus_addr_t)dma->segs[0].ds_addr;
  58058. + *dma_addr = dma->dma_paddr;
  58059. + return dma->dma_vaddr;
  58060. +
  58061. +fail_3:
  58062. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  58063. +fail_2:
  58064. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  58065. +fail_1:
  58066. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  58067. +fail_0:
  58068. + dma->dma_map = NULL;
  58069. + dma->dma_vaddr = NULL;
  58070. + dma->nsegs = 0;
  58071. +
  58072. + return NULL;
  58073. +}
  58074. +
  58075. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  58076. +{
  58077. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  58078. +
  58079. + if (dma->dma_map != NULL) {
  58080. + bus_dmamap_sync(dma->dma_tag, dma->dma_map, 0, size,
  58081. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  58082. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  58083. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  58084. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  58085. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  58086. + dma->dma_paddr = 0;
  58087. + dma->dma_map = NULL;
  58088. + dma->dma_vaddr = NULL;
  58089. + dma->nsegs = 0;
  58090. + }
  58091. +}
  58092. +
  58093. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  58094. +{
  58095. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  58096. +}
  58097. +
  58098. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  58099. +{
  58100. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  58101. +}
  58102. +
  58103. +void __DWC_FREE(void *mem_ctx, void *addr)
  58104. +{
  58105. + free(addr, M_DEVBUF);
  58106. +}
  58107. +
  58108. +
  58109. +#ifdef DWC_CRYPTOLIB
  58110. +/* dwc_crypto.h */
  58111. +
  58112. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  58113. +{
  58114. + get_random_bytes(buffer, length);
  58115. +}
  58116. +
  58117. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  58118. +{
  58119. + struct crypto_blkcipher *tfm;
  58120. + struct blkcipher_desc desc;
  58121. + struct scatterlist sgd;
  58122. + struct scatterlist sgs;
  58123. +
  58124. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  58125. + if (tfm == NULL) {
  58126. + printk("failed to load transform for aes CBC\n");
  58127. + return -1;
  58128. + }
  58129. +
  58130. + crypto_blkcipher_setkey(tfm, key, keylen);
  58131. + crypto_blkcipher_set_iv(tfm, iv, 16);
  58132. +
  58133. + sg_init_one(&sgd, out, messagelen);
  58134. + sg_init_one(&sgs, message, messagelen);
  58135. +
  58136. + desc.tfm = tfm;
  58137. + desc.flags = 0;
  58138. +
  58139. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  58140. + crypto_free_blkcipher(tfm);
  58141. + DWC_ERROR("AES CBC encryption failed");
  58142. + return -1;
  58143. + }
  58144. +
  58145. + crypto_free_blkcipher(tfm);
  58146. + return 0;
  58147. +}
  58148. +
  58149. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  58150. +{
  58151. + struct crypto_hash *tfm;
  58152. + struct hash_desc desc;
  58153. + struct scatterlist sg;
  58154. +
  58155. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  58156. + if (IS_ERR(tfm)) {
  58157. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  58158. + return 0;
  58159. + }
  58160. + desc.tfm = tfm;
  58161. + desc.flags = 0;
  58162. +
  58163. + sg_init_one(&sg, message, len);
  58164. + crypto_hash_digest(&desc, &sg, len, out);
  58165. + crypto_free_hash(tfm);
  58166. +
  58167. + return 1;
  58168. +}
  58169. +
  58170. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  58171. + uint8_t *key, uint32_t keylen, uint8_t *out)
  58172. +{
  58173. + struct crypto_hash *tfm;
  58174. + struct hash_desc desc;
  58175. + struct scatterlist sg;
  58176. +
  58177. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  58178. + if (IS_ERR(tfm)) {
  58179. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  58180. + return 0;
  58181. + }
  58182. + desc.tfm = tfm;
  58183. + desc.flags = 0;
  58184. +
  58185. + sg_init_one(&sg, message, messagelen);
  58186. + crypto_hash_setkey(tfm, key, keylen);
  58187. + crypto_hash_digest(&desc, &sg, messagelen, out);
  58188. + crypto_free_hash(tfm);
  58189. +
  58190. + return 1;
  58191. +}
  58192. +
  58193. +#endif /* DWC_CRYPTOLIB */
  58194. +
  58195. +
  58196. +/* Byte Ordering Conversions */
  58197. +
  58198. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  58199. +{
  58200. +#ifdef __LITTLE_ENDIAN
  58201. + return *p;
  58202. +#else
  58203. + uint8_t *u_p = (uint8_t *)p;
  58204. +
  58205. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  58206. +#endif
  58207. +}
  58208. +
  58209. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  58210. +{
  58211. +#ifdef __BIG_ENDIAN
  58212. + return *p;
  58213. +#else
  58214. + uint8_t *u_p = (uint8_t *)p;
  58215. +
  58216. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  58217. +#endif
  58218. +}
  58219. +
  58220. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  58221. +{
  58222. +#ifdef __LITTLE_ENDIAN
  58223. + return *p;
  58224. +#else
  58225. + uint8_t *u_p = (uint8_t *)p;
  58226. +
  58227. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  58228. +#endif
  58229. +}
  58230. +
  58231. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  58232. +{
  58233. +#ifdef __BIG_ENDIAN
  58234. + return *p;
  58235. +#else
  58236. + uint8_t *u_p = (uint8_t *)p;
  58237. +
  58238. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  58239. +#endif
  58240. +}
  58241. +
  58242. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  58243. +{
  58244. +#ifdef __LITTLE_ENDIAN
  58245. + return *p;
  58246. +#else
  58247. + uint8_t *u_p = (uint8_t *)p;
  58248. + return (u_p[1] | (u_p[0] << 8));
  58249. +#endif
  58250. +}
  58251. +
  58252. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  58253. +{
  58254. +#ifdef __BIG_ENDIAN
  58255. + return *p;
  58256. +#else
  58257. + uint8_t *u_p = (uint8_t *)p;
  58258. + return (u_p[1] | (u_p[0] << 8));
  58259. +#endif
  58260. +}
  58261. +
  58262. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  58263. +{
  58264. +#ifdef __LITTLE_ENDIAN
  58265. + return *p;
  58266. +#else
  58267. + uint8_t *u_p = (uint8_t *)p;
  58268. + return (u_p[1] | (u_p[0] << 8));
  58269. +#endif
  58270. +}
  58271. +
  58272. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  58273. +{
  58274. +#ifdef __BIG_ENDIAN
  58275. + return *p;
  58276. +#else
  58277. + uint8_t *u_p = (uint8_t *)p;
  58278. + return (u_p[1] | (u_p[0] << 8));
  58279. +#endif
  58280. +}
  58281. +
  58282. +
  58283. +/* Registers */
  58284. +
  58285. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  58286. +{
  58287. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  58288. + bus_size_t ior = (bus_size_t)reg;
  58289. +
  58290. + return bus_space_read_4(io->iot, io->ioh, ior);
  58291. +}
  58292. +
  58293. +#if 0
  58294. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  58295. +{
  58296. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  58297. + bus_size_t ior = (bus_size_t)reg;
  58298. +
  58299. + return bus_space_read_8(io->iot, io->ioh, ior);
  58300. +}
  58301. +#endif
  58302. +
  58303. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  58304. +{
  58305. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  58306. + bus_size_t ior = (bus_size_t)reg;
  58307. +
  58308. + bus_space_write_4(io->iot, io->ioh, ior, value);
  58309. +}
  58310. +
  58311. +#if 0
  58312. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  58313. +{
  58314. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  58315. + bus_size_t ior = (bus_size_t)reg;
  58316. +
  58317. + bus_space_write_8(io->iot, io->ioh, ior, value);
  58318. +}
  58319. +#endif
  58320. +
  58321. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  58322. + uint32_t set_mask)
  58323. +{
  58324. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  58325. + bus_size_t ior = (bus_size_t)reg;
  58326. +
  58327. + bus_space_write_4(io->iot, io->ioh, ior,
  58328. + (bus_space_read_4(io->iot, io->ioh, ior) &
  58329. + ~clear_mask) | set_mask);
  58330. +}
  58331. +
  58332. +#if 0
  58333. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  58334. + uint64_t set_mask)
  58335. +{
  58336. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  58337. + bus_size_t ior = (bus_size_t)reg;
  58338. +
  58339. + bus_space_write_8(io->iot, io->ioh, ior,
  58340. + (bus_space_read_8(io->iot, io->ioh, ior) &
  58341. + ~clear_mask) | set_mask);
  58342. +}
  58343. +#endif
  58344. +
  58345. +
  58346. +/* Locking */
  58347. +
  58348. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  58349. +{
  58350. + struct simplelock *sl = DWC_ALLOC(sizeof(*sl));
  58351. +
  58352. + if (!sl) {
  58353. + DWC_ERROR("Cannot allocate memory for spinlock");
  58354. + return NULL;
  58355. + }
  58356. +
  58357. + simple_lock_init(sl);
  58358. + return (dwc_spinlock_t *)sl;
  58359. +}
  58360. +
  58361. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  58362. +{
  58363. + struct simplelock *sl = (struct simplelock *)lock;
  58364. +
  58365. + DWC_FREE(sl);
  58366. +}
  58367. +
  58368. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  58369. +{
  58370. + simple_lock((struct simplelock *)lock);
  58371. +}
  58372. +
  58373. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  58374. +{
  58375. + simple_unlock((struct simplelock *)lock);
  58376. +}
  58377. +
  58378. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  58379. +{
  58380. + simple_lock((struct simplelock *)lock);
  58381. + *flags = splbio();
  58382. +}
  58383. +
  58384. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  58385. +{
  58386. + splx(flags);
  58387. + simple_unlock((struct simplelock *)lock);
  58388. +}
  58389. +
  58390. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  58391. +{
  58392. + dwc_mutex_t *mutex = DWC_ALLOC(sizeof(struct lock));
  58393. +
  58394. + if (!mutex) {
  58395. + DWC_ERROR("Cannot allocate memory for mutex");
  58396. + return NULL;
  58397. + }
  58398. +
  58399. + lockinit((struct lock *)mutex, 0, "dw3mtx", 0, 0);
  58400. + return mutex;
  58401. +}
  58402. +
  58403. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  58404. +#else
  58405. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  58406. +{
  58407. + DWC_FREE(mutex);
  58408. +}
  58409. +#endif
  58410. +
  58411. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  58412. +{
  58413. + lockmgr((struct lock *)mutex, LK_EXCLUSIVE, NULL);
  58414. +}
  58415. +
  58416. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  58417. +{
  58418. + int status;
  58419. +
  58420. + status = lockmgr((struct lock *)mutex, LK_EXCLUSIVE | LK_NOWAIT, NULL);
  58421. + return status == 0;
  58422. +}
  58423. +
  58424. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  58425. +{
  58426. + lockmgr((struct lock *)mutex, LK_RELEASE, NULL);
  58427. +}
  58428. +
  58429. +
  58430. +/* Timing */
  58431. +
  58432. +void DWC_UDELAY(uint32_t usecs)
  58433. +{
  58434. + DELAY(usecs);
  58435. +}
  58436. +
  58437. +void DWC_MDELAY(uint32_t msecs)
  58438. +{
  58439. + do {
  58440. + DELAY(1000);
  58441. + } while (--msecs);
  58442. +}
  58443. +
  58444. +void DWC_MSLEEP(uint32_t msecs)
  58445. +{
  58446. + struct timeval tv;
  58447. +
  58448. + tv.tv_sec = msecs / 1000;
  58449. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  58450. + tsleep(&tv, 0, "dw3slp", tvtohz(&tv));
  58451. +}
  58452. +
  58453. +uint32_t DWC_TIME(void)
  58454. +{
  58455. + struct timeval tv;
  58456. +
  58457. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  58458. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  58459. +}
  58460. +
  58461. +
  58462. +/* Timers */
  58463. +
  58464. +struct dwc_timer {
  58465. + struct callout t;
  58466. + char *name;
  58467. + dwc_spinlock_t *lock;
  58468. + dwc_timer_callback_t cb;
  58469. + void *data;
  58470. +};
  58471. +
  58472. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  58473. +{
  58474. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  58475. +
  58476. + if (!t) {
  58477. + DWC_ERROR("Cannot allocate memory for timer");
  58478. + return NULL;
  58479. + }
  58480. +
  58481. + callout_init(&t->t);
  58482. +
  58483. + t->name = DWC_STRDUP(name);
  58484. + if (!t->name) {
  58485. + DWC_ERROR("Cannot allocate memory for timer->name");
  58486. + goto no_name;
  58487. + }
  58488. +
  58489. + t->lock = DWC_SPINLOCK_ALLOC();
  58490. + if (!t->lock) {
  58491. + DWC_ERROR("Cannot allocate memory for timer->lock");
  58492. + goto no_lock;
  58493. + }
  58494. +
  58495. + t->cb = cb;
  58496. + t->data = data;
  58497. +
  58498. + return t;
  58499. +
  58500. + no_lock:
  58501. + DWC_FREE(t->name);
  58502. + no_name:
  58503. + DWC_FREE(t);
  58504. +
  58505. + return NULL;
  58506. +}
  58507. +
  58508. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  58509. +{
  58510. + callout_stop(&timer->t);
  58511. + DWC_SPINLOCK_FREE(timer->lock);
  58512. + DWC_FREE(timer->name);
  58513. + DWC_FREE(timer);
  58514. +}
  58515. +
  58516. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  58517. +{
  58518. + struct timeval tv;
  58519. +
  58520. + tv.tv_sec = time / 1000;
  58521. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  58522. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  58523. +}
  58524. +
  58525. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  58526. +{
  58527. + callout_stop(&timer->t);
  58528. +}
  58529. +
  58530. +
  58531. +/* Wait Queues */
  58532. +
  58533. +struct dwc_waitq {
  58534. + struct simplelock lock;
  58535. + int abort;
  58536. +};
  58537. +
  58538. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  58539. +{
  58540. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  58541. +
  58542. + if (!wq) {
  58543. + DWC_ERROR("Cannot allocate memory for waitqueue");
  58544. + return NULL;
  58545. + }
  58546. +
  58547. + simple_lock_init(&wq->lock);
  58548. + wq->abort = 0;
  58549. +
  58550. + return wq;
  58551. +}
  58552. +
  58553. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  58554. +{
  58555. + DWC_FREE(wq);
  58556. +}
  58557. +
  58558. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  58559. +{
  58560. + int ipl;
  58561. + int result = 0;
  58562. +
  58563. + simple_lock(&wq->lock);
  58564. + ipl = splbio();
  58565. +
  58566. + /* Skip the sleep if already aborted or triggered */
  58567. + if (!wq->abort && !cond(data)) {
  58568. + splx(ipl);
  58569. + result = ltsleep(wq, PCATCH, "dw3wat", 0, &wq->lock); // infinite timeout
  58570. + ipl = splbio();
  58571. + }
  58572. +
  58573. + if (result == 0) { // awoken
  58574. + if (wq->abort) {
  58575. + wq->abort = 0;
  58576. + result = -DWC_E_ABORT;
  58577. + } else {
  58578. + result = 0;
  58579. + }
  58580. +
  58581. + splx(ipl);
  58582. + simple_unlock(&wq->lock);
  58583. + } else {
  58584. + wq->abort = 0;
  58585. + splx(ipl);
  58586. + simple_unlock(&wq->lock);
  58587. +
  58588. + if (result == ERESTART) { // signaled - restart
  58589. + result = -DWC_E_RESTART;
  58590. + } else { // signaled - must be EINTR
  58591. + result = -DWC_E_ABORT;
  58592. + }
  58593. + }
  58594. +
  58595. + return result;
  58596. +}
  58597. +
  58598. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  58599. + void *data, int32_t msecs)
  58600. +{
  58601. + struct timeval tv, tv1, tv2;
  58602. + int ipl;
  58603. + int result = 0;
  58604. +
  58605. + tv.tv_sec = msecs / 1000;
  58606. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  58607. +
  58608. + simple_lock(&wq->lock);
  58609. + ipl = splbio();
  58610. +
  58611. + /* Skip the sleep if already aborted or triggered */
  58612. + if (!wq->abort && !cond(data)) {
  58613. + splx(ipl);
  58614. + getmicrouptime(&tv1);
  58615. + result = ltsleep(wq, PCATCH, "dw3wto", tvtohz(&tv), &wq->lock);
  58616. + getmicrouptime(&tv2);
  58617. + ipl = splbio();
  58618. + }
  58619. +
  58620. + if (result == 0) { // awoken
  58621. + if (wq->abort) {
  58622. + wq->abort = 0;
  58623. + splx(ipl);
  58624. + simple_unlock(&wq->lock);
  58625. + result = -DWC_E_ABORT;
  58626. + } else {
  58627. + splx(ipl);
  58628. + simple_unlock(&wq->lock);
  58629. +
  58630. + tv2.tv_usec -= tv1.tv_usec;
  58631. + if (tv2.tv_usec < 0) {
  58632. + tv2.tv_usec += 1000000;
  58633. + tv2.tv_sec--;
  58634. + }
  58635. +
  58636. + tv2.tv_sec -= tv1.tv_sec;
  58637. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  58638. + result = msecs - result;
  58639. + if (result <= 0)
  58640. + result = 1;
  58641. + }
  58642. + } else {
  58643. + wq->abort = 0;
  58644. + splx(ipl);
  58645. + simple_unlock(&wq->lock);
  58646. +
  58647. + if (result == ERESTART) { // signaled - restart
  58648. + result = -DWC_E_RESTART;
  58649. +
  58650. + } else if (result == EINTR) { // signaled - interrupt
  58651. + result = -DWC_E_ABORT;
  58652. +
  58653. + } else { // timed out
  58654. + result = -DWC_E_TIMEOUT;
  58655. + }
  58656. + }
  58657. +
  58658. + return result;
  58659. +}
  58660. +
  58661. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  58662. +{
  58663. + wakeup(wq);
  58664. +}
  58665. +
  58666. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  58667. +{
  58668. + int ipl;
  58669. +
  58670. + simple_lock(&wq->lock);
  58671. + ipl = splbio();
  58672. + wq->abort = 1;
  58673. + wakeup(wq);
  58674. + splx(ipl);
  58675. + simple_unlock(&wq->lock);
  58676. +}
  58677. +
  58678. +
  58679. +/* Threading */
  58680. +
  58681. +struct dwc_thread {
  58682. + struct proc *proc;
  58683. + int abort;
  58684. +};
  58685. +
  58686. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  58687. +{
  58688. + int retval;
  58689. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  58690. +
  58691. + if (!thread) {
  58692. + return NULL;
  58693. + }
  58694. +
  58695. + thread->abort = 0;
  58696. + retval = kthread_create1((void (*)(void *))func, data, &thread->proc,
  58697. + "%s", name);
  58698. + if (retval) {
  58699. + DWC_FREE(thread);
  58700. + return NULL;
  58701. + }
  58702. +
  58703. + return thread;
  58704. +}
  58705. +
  58706. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  58707. +{
  58708. + int retval;
  58709. +
  58710. + thread->abort = 1;
  58711. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  58712. +
  58713. + if (retval == 0) {
  58714. + /* DWC_THREAD_EXIT() will free the thread struct */
  58715. + return 0;
  58716. + }
  58717. +
  58718. + /* NOTE: We leak the thread struct if thread doesn't die */
  58719. +
  58720. + if (retval == EWOULDBLOCK) {
  58721. + return -DWC_E_TIMEOUT;
  58722. + }
  58723. +
  58724. + return -DWC_E_UNKNOWN;
  58725. +}
  58726. +
  58727. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  58728. +{
  58729. + return thread->abort;
  58730. +}
  58731. +
  58732. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  58733. +{
  58734. + wakeup(&thread->abort);
  58735. + DWC_FREE(thread);
  58736. + kthread_exit(0);
  58737. +}
  58738. +
  58739. +/* tasklets
  58740. + - Runs in interrupt context (cannot sleep)
  58741. + - Each tasklet runs on a single CPU
  58742. + - Different tasklets can be running simultaneously on different CPUs
  58743. + [ On NetBSD there is no corresponding mechanism, drivers don't have bottom-
  58744. + halves. So we just call the callback directly from DWC_TASK_SCHEDULE() ]
  58745. + */
  58746. +struct dwc_tasklet {
  58747. + dwc_tasklet_callback_t cb;
  58748. + void *data;
  58749. +};
  58750. +
  58751. +static void tasklet_callback(void *data)
  58752. +{
  58753. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  58754. +
  58755. + task->cb(task->data);
  58756. +}
  58757. +
  58758. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  58759. +{
  58760. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  58761. +
  58762. + if (task) {
  58763. + task->cb = cb;
  58764. + task->data = data;
  58765. + } else {
  58766. + DWC_ERROR("Cannot allocate memory for tasklet");
  58767. + }
  58768. +
  58769. + return task;
  58770. +}
  58771. +
  58772. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  58773. +{
  58774. + DWC_FREE(task);
  58775. +}
  58776. +
  58777. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  58778. +{
  58779. + tasklet_callback(task);
  58780. +}
  58781. +
  58782. +
  58783. +/* workqueues
  58784. + - Runs in process context (can sleep)
  58785. + */
  58786. +typedef struct work_container {
  58787. + dwc_work_callback_t cb;
  58788. + void *data;
  58789. + dwc_workq_t *wq;
  58790. + char *name;
  58791. + int hz;
  58792. + struct work task;
  58793. +} work_container_t;
  58794. +
  58795. +struct dwc_workq {
  58796. + struct workqueue *taskq;
  58797. + dwc_spinlock_t *lock;
  58798. + dwc_waitq_t *waitq;
  58799. + int pending;
  58800. + struct work_container *container;
  58801. +};
  58802. +
  58803. +static void do_work(struct work *task, void *data)
  58804. +{
  58805. + dwc_workq_t *wq = (dwc_workq_t *)data;
  58806. + work_container_t *container = wq->container;
  58807. + dwc_irqflags_t flags;
  58808. +
  58809. + if (container->hz) {
  58810. + tsleep(container, 0, "dw3wrk", container->hz);
  58811. + }
  58812. +
  58813. + container->cb(container->data);
  58814. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  58815. +
  58816. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  58817. + if (container->name)
  58818. + DWC_FREE(container->name);
  58819. + DWC_FREE(container);
  58820. + wq->pending--;
  58821. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  58822. + DWC_WAITQ_TRIGGER(wq->waitq);
  58823. +}
  58824. +
  58825. +static int work_done(void *data)
  58826. +{
  58827. + dwc_workq_t *workq = (dwc_workq_t *)data;
  58828. +
  58829. + return workq->pending == 0;
  58830. +}
  58831. +
  58832. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  58833. +{
  58834. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  58835. +}
  58836. +
  58837. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  58838. +{
  58839. + int result;
  58840. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  58841. +
  58842. + if (!wq) {
  58843. + DWC_ERROR("Cannot allocate memory for workqueue");
  58844. + return NULL;
  58845. + }
  58846. +
  58847. + result = workqueue_create(&wq->taskq, name, do_work, wq, 0 /*PWAIT*/,
  58848. + IPL_BIO, 0);
  58849. + if (result) {
  58850. + DWC_ERROR("Cannot create workqueue");
  58851. + goto no_taskq;
  58852. + }
  58853. +
  58854. + wq->pending = 0;
  58855. +
  58856. + wq->lock = DWC_SPINLOCK_ALLOC();
  58857. + if (!wq->lock) {
  58858. + DWC_ERROR("Cannot allocate memory for spinlock");
  58859. + goto no_lock;
  58860. + }
  58861. +
  58862. + wq->waitq = DWC_WAITQ_ALLOC();
  58863. + if (!wq->waitq) {
  58864. + DWC_ERROR("Cannot allocate memory for waitqueue");
  58865. + goto no_waitq;
  58866. + }
  58867. +
  58868. + return wq;
  58869. +
  58870. + no_waitq:
  58871. + DWC_SPINLOCK_FREE(wq->lock);
  58872. + no_lock:
  58873. + workqueue_destroy(wq->taskq);
  58874. + no_taskq:
  58875. + DWC_FREE(wq);
  58876. +
  58877. + return NULL;
  58878. +}
  58879. +
  58880. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  58881. +{
  58882. +#ifdef DEBUG
  58883. + dwc_irqflags_t flags;
  58884. +
  58885. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  58886. +
  58887. + if (wq->pending != 0) {
  58888. + struct work_container *container = wq->container;
  58889. +
  58890. + DWC_ERROR("Destroying work queue with pending work");
  58891. +
  58892. + if (container && container->name) {
  58893. + DWC_ERROR("Work %s still pending", container->name);
  58894. + }
  58895. + }
  58896. +
  58897. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  58898. +#endif
  58899. + DWC_WAITQ_FREE(wq->waitq);
  58900. + DWC_SPINLOCK_FREE(wq->lock);
  58901. + workqueue_destroy(wq->taskq);
  58902. + DWC_FREE(wq);
  58903. +}
  58904. +
  58905. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  58906. + char *format, ...)
  58907. +{
  58908. + dwc_irqflags_t flags;
  58909. + work_container_t *container;
  58910. + static char name[128];
  58911. + va_list args;
  58912. +
  58913. + va_start(args, format);
  58914. + DWC_VSNPRINTF(name, 128, format, args);
  58915. + va_end(args);
  58916. +
  58917. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  58918. + wq->pending++;
  58919. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  58920. + DWC_WAITQ_TRIGGER(wq->waitq);
  58921. +
  58922. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  58923. + if (!container) {
  58924. + DWC_ERROR("Cannot allocate memory for container");
  58925. + return;
  58926. + }
  58927. +
  58928. + container->name = DWC_STRDUP(name);
  58929. + if (!container->name) {
  58930. + DWC_ERROR("Cannot allocate memory for container->name");
  58931. + DWC_FREE(container);
  58932. + return;
  58933. + }
  58934. +
  58935. + container->cb = cb;
  58936. + container->data = data;
  58937. + container->wq = wq;
  58938. + container->hz = 0;
  58939. + wq->container = container;
  58940. +
  58941. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  58942. + workqueue_enqueue(wq->taskq, &container->task);
  58943. +}
  58944. +
  58945. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  58946. + void *data, uint32_t time, char *format, ...)
  58947. +{
  58948. + dwc_irqflags_t flags;
  58949. + work_container_t *container;
  58950. + static char name[128];
  58951. + struct timeval tv;
  58952. + va_list args;
  58953. +
  58954. + va_start(args, format);
  58955. + DWC_VSNPRINTF(name, 128, format, args);
  58956. + va_end(args);
  58957. +
  58958. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  58959. + wq->pending++;
  58960. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  58961. + DWC_WAITQ_TRIGGER(wq->waitq);
  58962. +
  58963. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  58964. + if (!container) {
  58965. + DWC_ERROR("Cannot allocate memory for container");
  58966. + return;
  58967. + }
  58968. +
  58969. + container->name = DWC_STRDUP(name);
  58970. + if (!container->name) {
  58971. + DWC_ERROR("Cannot allocate memory for container->name");
  58972. + DWC_FREE(container);
  58973. + return;
  58974. + }
  58975. +
  58976. + container->cb = cb;
  58977. + container->data = data;
  58978. + container->wq = wq;
  58979. + tv.tv_sec = time / 1000;
  58980. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  58981. + container->hz = tvtohz(&tv);
  58982. + wq->container = container;
  58983. +
  58984. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  58985. + workqueue_enqueue(wq->taskq, &container->task);
  58986. +}
  58987. +
  58988. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  58989. +{
  58990. + return wq->pending;
  58991. +}
  58992. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_crypto.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.c
  58993. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_crypto.c 1970-01-01 01:00:00.000000000 +0100
  58994. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.c 2015-02-09 04:40:28.000000000 +0100
  58995. @@ -0,0 +1,308 @@
  58996. +/* =========================================================================
  58997. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.c $
  58998. + * $Revision: #5 $
  58999. + * $Date: 2010/09/28 $
  59000. + * $Change: 1596182 $
  59001. + *
  59002. + * Synopsys Portability Library Software and documentation
  59003. + * (hereinafter, "Software") is an Unsupported proprietary work of
  59004. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  59005. + * between Synopsys and you.
  59006. + *
  59007. + * The Software IS NOT an item of Licensed Software or Licensed Product
  59008. + * under any End User Software License Agreement or Agreement for
  59009. + * Licensed Product with Synopsys or any supplement thereto. You are
  59010. + * permitted to use and redistribute this Software in source and binary
  59011. + * forms, with or without modification, provided that redistributions
  59012. + * of source code must retain this notice. You may not view, use,
  59013. + * disclose, copy or distribute this file or any information contained
  59014. + * herein except pursuant to this license grant from Synopsys. If you
  59015. + * do not agree with this notice, including the disclaimer below, then
  59016. + * you are not authorized to use the Software.
  59017. + *
  59018. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  59019. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  59020. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  59021. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  59022. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  59023. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  59024. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  59025. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  59026. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59027. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  59028. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  59029. + * DAMAGE.
  59030. + * ========================================================================= */
  59031. +
  59032. +/** @file
  59033. + * This file contains the WUSB cryptographic routines.
  59034. + */
  59035. +
  59036. +#ifdef DWC_CRYPTOLIB
  59037. +
  59038. +#include "dwc_crypto.h"
  59039. +#include "usb.h"
  59040. +
  59041. +#ifdef DEBUG
  59042. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  59043. +{
  59044. + int i;
  59045. + DWC_PRINTF("%s: ", name);
  59046. + for (i=0; i<len; i++) {
  59047. + DWC_PRINTF("%02x ", bytes[i]);
  59048. + }
  59049. + DWC_PRINTF("\n");
  59050. +}
  59051. +#else
  59052. +#define dump_bytes(x...)
  59053. +#endif
  59054. +
  59055. +/* Display a block */
  59056. +void show_block(const u8 *blk, const char *prefix, const char *suffix, int a)
  59057. +{
  59058. +#ifdef DWC_DEBUG_CRYPTO
  59059. + int i, blksize = 16;
  59060. +
  59061. + DWC_DEBUG("%s", prefix);
  59062. +
  59063. + if (suffix == NULL) {
  59064. + suffix = "\n";
  59065. + blksize = a;
  59066. + }
  59067. +
  59068. + for (i = 0; i < blksize; i++)
  59069. + DWC_PRINT("%02x%s", *blk++, ((i & 3) == 3) ? " " : " ");
  59070. + DWC_PRINT(suffix);
  59071. +#endif
  59072. +}
  59073. +
  59074. +/**
  59075. + * Encrypts an array of bytes using the AES encryption engine.
  59076. + * If <code>dst</code> == <code>src</code>, then the bytes will be encrypted
  59077. + * in-place.
  59078. + *
  59079. + * @return 0 on success, negative error code on error.
  59080. + */
  59081. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst)
  59082. +{
  59083. + u8 block_t[16];
  59084. + DWC_MEMSET(block_t, 0, 16);
  59085. +
  59086. + return DWC_AES_CBC(src, 16, key, 16, block_t, dst);
  59087. +}
  59088. +
  59089. +/**
  59090. + * The CCM-MAC-FUNCTION described in section 6.5 of the WUSB spec.
  59091. + * This function takes a data string and returns the encrypted CBC
  59092. + * Counter-mode MIC.
  59093. + *
  59094. + * @param key The 128-bit symmetric key.
  59095. + * @param nonce The CCM nonce.
  59096. + * @param label The unique 14-byte ASCII text label.
  59097. + * @param bytes The byte array to be encrypted.
  59098. + * @param len Length of the byte array.
  59099. + * @param result Byte array to receive the 8-byte encrypted MIC.
  59100. + */
  59101. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  59102. + char *label, u8 *bytes, int len, u8 *result)
  59103. +{
  59104. + u8 block_m[16];
  59105. + u8 block_x[16];
  59106. + u8 block_t[8];
  59107. + int idx, blkNum;
  59108. + u16 la = (u16)(len + 14);
  59109. +
  59110. + /* Set the AES-128 key */
  59111. + //dwc_aes_setkey(tfm, key, 16);
  59112. +
  59113. + /* Fill block B0 from flags = 0x59, N, and l(m) = 0 */
  59114. + block_m[0] = 0x59;
  59115. + for (idx = 0; idx < 13; idx++)
  59116. + block_m[idx + 1] = nonce[idx];
  59117. + block_m[14] = 0;
  59118. + block_m[15] = 0;
  59119. +
  59120. + /* Produce the CBC IV */
  59121. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  59122. + show_block(block_m, "CBC IV in: ", "\n", 0);
  59123. + show_block(block_x, "CBC IV out:", "\n", 0);
  59124. +
  59125. + /* Fill block B1 from l(a) = Blen + 14, and A */
  59126. + block_x[0] ^= (u8)(la >> 8);
  59127. + block_x[1] ^= (u8)la;
  59128. + for (idx = 0; idx < 14; idx++)
  59129. + block_x[idx + 2] ^= label[idx];
  59130. + show_block(block_x, "After xor: ", "b1\n", 16);
  59131. +
  59132. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  59133. + show_block(block_x, "After AES: ", "b1\n", 16);
  59134. +
  59135. + idx = 0;
  59136. + blkNum = 0;
  59137. +
  59138. + /* Fill remaining blocks with B */
  59139. + while (len-- > 0) {
  59140. + block_x[idx] ^= *bytes++;
  59141. + if (++idx >= 16) {
  59142. + idx = 0;
  59143. + show_block(block_x, "After xor: ", "\n", blkNum);
  59144. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  59145. + show_block(block_x, "After AES: ", "\n", blkNum);
  59146. + blkNum++;
  59147. + }
  59148. + }
  59149. +
  59150. + /* Handle partial last block */
  59151. + if (idx > 0) {
  59152. + show_block(block_x, "After xor: ", "\n", blkNum);
  59153. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  59154. + show_block(block_x, "After AES: ", "\n", blkNum);
  59155. + }
  59156. +
  59157. + /* Save the MIC tag */
  59158. + DWC_MEMCPY(block_t, block_x, 8);
  59159. + show_block(block_t, "MIC tag : ", NULL, 8);
  59160. +
  59161. + /* Fill block A0 from flags = 0x01, N, and counter = 0 */
  59162. + block_m[0] = 0x01;
  59163. + block_m[14] = 0;
  59164. + block_m[15] = 0;
  59165. +
  59166. + /* Encrypt the counter */
  59167. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  59168. + show_block(block_x, "CTR[MIC] : ", NULL, 8);
  59169. +
  59170. + /* XOR with MIC tag */
  59171. + for (idx = 0; idx < 8; idx++) {
  59172. + block_t[idx] ^= block_x[idx];
  59173. + }
  59174. +
  59175. + /* Return result to caller */
  59176. + DWC_MEMCPY(result, block_t, 8);
  59177. + show_block(result, "CCM-MIC : ", NULL, 8);
  59178. +
  59179. +}
  59180. +
  59181. +/**
  59182. + * The PRF function described in section 6.5 of the WUSB spec. This function
  59183. + * concatenates MIC values returned from dwc_cmf() to create a value of
  59184. + * the requested length.
  59185. + *
  59186. + * @param prf_len Length of the PRF function in bits (64, 128, or 256).
  59187. + * @param key, nonce, label, bytes, len Same as for dwc_cmf().
  59188. + * @param result Byte array to receive the result.
  59189. + */
  59190. +void dwc_wusb_prf(int prf_len, u8 *key,
  59191. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result)
  59192. +{
  59193. + int i;
  59194. +
  59195. + nonce[0] = 0;
  59196. + for (i = 0; i < prf_len >> 6; i++, nonce[0]++) {
  59197. + dwc_wusb_cmf(key, nonce, label, bytes, len, result);
  59198. + result += 8;
  59199. + }
  59200. +}
  59201. +
  59202. +/**
  59203. + * Fills in CCM Nonce per the WUSB spec.
  59204. + *
  59205. + * @param[in] haddr Host address.
  59206. + * @param[in] daddr Device address.
  59207. + * @param[in] tkid Session Key(PTK) identifier.
  59208. + * @param[out] nonce Pointer to where the CCM Nonce output is to be written.
  59209. + */
  59210. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  59211. + uint8_t *nonce)
  59212. +{
  59213. +
  59214. + DWC_DEBUG("%s %x %x\n", __func__, daddr, haddr);
  59215. +
  59216. + DWC_MEMSET(&nonce[0], 0, 16);
  59217. +
  59218. + DWC_MEMCPY(&nonce[6], tkid, 3);
  59219. + nonce[9] = daddr & 0xFF;
  59220. + nonce[10] = (daddr >> 8) & 0xFF;
  59221. + nonce[11] = haddr & 0xFF;
  59222. + nonce[12] = (haddr >> 8) & 0xFF;
  59223. +
  59224. + dump_bytes("CCM nonce", nonce, 16);
  59225. +}
  59226. +
  59227. +/**
  59228. + * Generates a 16-byte cryptographic-grade random number for the Host/Device
  59229. + * Nonce.
  59230. + */
  59231. +void dwc_wusb_gen_nonce(uint16_t addr, uint8_t *nonce)
  59232. +{
  59233. + uint8_t inonce[16];
  59234. + uint32_t temp[4];
  59235. +
  59236. + /* Fill in the Nonce */
  59237. + DWC_MEMSET(&inonce[0], 0, sizeof(inonce));
  59238. + inonce[9] = addr & 0xFF;
  59239. + inonce[10] = (addr >> 8) & 0xFF;
  59240. + inonce[11] = inonce[9];
  59241. + inonce[12] = inonce[10];
  59242. +
  59243. + /* Collect "randomness samples" */
  59244. + DWC_RANDOM_BYTES((uint8_t *)temp, 16);
  59245. +
  59246. + dwc_wusb_prf_128((uint8_t *)temp, nonce,
  59247. + "Random Numbers", (uint8_t *)temp, sizeof(temp),
  59248. + nonce);
  59249. +}
  59250. +
  59251. +/**
  59252. + * Generates the Session Key (PTK) and Key Confirmation Key (KCK) per the
  59253. + * WUSB spec.
  59254. + *
  59255. + * @param[in] ccm_nonce Pointer to CCM Nonce.
  59256. + * @param[in] mk Master Key to derive the session from
  59257. + * @param[in] hnonce Pointer to Host Nonce.
  59258. + * @param[in] dnonce Pointer to Device Nonce.
  59259. + * @param[out] kck Pointer to where the KCK output is to be written.
  59260. + * @param[out] ptk Pointer to where the PTK output is to be written.
  59261. + */
  59262. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk, uint8_t *hnonce,
  59263. + uint8_t *dnonce, uint8_t *kck, uint8_t *ptk)
  59264. +{
  59265. + uint8_t idata[32];
  59266. + uint8_t odata[32];
  59267. +
  59268. + dump_bytes("ck", mk, 16);
  59269. + dump_bytes("hnonce", hnonce, 16);
  59270. + dump_bytes("dnonce", dnonce, 16);
  59271. +
  59272. + /* The data is the HNonce and DNonce concatenated */
  59273. + DWC_MEMCPY(&idata[0], hnonce, 16);
  59274. + DWC_MEMCPY(&idata[16], dnonce, 16);
  59275. +
  59276. + dwc_wusb_prf_256(mk, ccm_nonce, "Pair-wise keys", idata, 32, odata);
  59277. +
  59278. + /* Low 16 bytes of the result is the KCK, high 16 is the PTK */
  59279. + DWC_MEMCPY(kck, &odata[0], 16);
  59280. + DWC_MEMCPY(ptk, &odata[16], 16);
  59281. +
  59282. + dump_bytes("kck", kck, 16);
  59283. + dump_bytes("ptk", ptk, 16);
  59284. +}
  59285. +
  59286. +/**
  59287. + * Generates the Message Integrity Code over the Handshake data per the
  59288. + * WUSB spec.
  59289. + *
  59290. + * @param ccm_nonce Pointer to CCM Nonce.
  59291. + * @param kck Pointer to Key Confirmation Key.
  59292. + * @param data Pointer to Handshake data to be checked.
  59293. + * @param mic Pointer to where the MIC output is to be written.
  59294. + */
  59295. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t *kck,
  59296. + uint8_t *data, uint8_t *mic)
  59297. +{
  59298. +
  59299. + dwc_wusb_prf_64(kck, ccm_nonce, "out-of-bandMIC",
  59300. + data, WUSB_HANDSHAKE_LEN_FOR_MIC, mic);
  59301. +}
  59302. +
  59303. +#endif /* DWC_CRYPTOLIB */
  59304. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_crypto.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.h
  59305. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_crypto.h 1970-01-01 01:00:00.000000000 +0100
  59306. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.h 2015-02-09 04:40:28.000000000 +0100
  59307. @@ -0,0 +1,111 @@
  59308. +/* =========================================================================
  59309. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.h $
  59310. + * $Revision: #3 $
  59311. + * $Date: 2010/09/28 $
  59312. + * $Change: 1596182 $
  59313. + *
  59314. + * Synopsys Portability Library Software and documentation
  59315. + * (hereinafter, "Software") is an Unsupported proprietary work of
  59316. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  59317. + * between Synopsys and you.
  59318. + *
  59319. + * The Software IS NOT an item of Licensed Software or Licensed Product
  59320. + * under any End User Software License Agreement or Agreement for
  59321. + * Licensed Product with Synopsys or any supplement thereto. You are
  59322. + * permitted to use and redistribute this Software in source and binary
  59323. + * forms, with or without modification, provided that redistributions
  59324. + * of source code must retain this notice. You may not view, use,
  59325. + * disclose, copy or distribute this file or any information contained
  59326. + * herein except pursuant to this license grant from Synopsys. If you
  59327. + * do not agree with this notice, including the disclaimer below, then
  59328. + * you are not authorized to use the Software.
  59329. + *
  59330. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  59331. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  59332. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  59333. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  59334. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  59335. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  59336. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  59337. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  59338. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59339. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  59340. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  59341. + * DAMAGE.
  59342. + * ========================================================================= */
  59343. +
  59344. +#ifndef _DWC_CRYPTO_H_
  59345. +#define _DWC_CRYPTO_H_
  59346. +
  59347. +#ifdef __cplusplus
  59348. +extern "C" {
  59349. +#endif
  59350. +
  59351. +/** @file
  59352. + *
  59353. + * This file contains declarations for the WUSB Cryptographic routines as
  59354. + * defined in the WUSB spec. They are only to be used internally by the DWC UWB
  59355. + * modules.
  59356. + */
  59357. +
  59358. +#include "dwc_os.h"
  59359. +
  59360. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst);
  59361. +
  59362. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  59363. + char *label, u8 *bytes, int len, u8 *result);
  59364. +void dwc_wusb_prf(int prf_len, u8 *key,
  59365. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result);
  59366. +
  59367. +/**
  59368. + * The PRF-64 function described in section 6.5 of the WUSB spec.
  59369. + *
  59370. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  59371. + */
  59372. +static inline void dwc_wusb_prf_64(u8 *key, u8 *nonce,
  59373. + char *label, u8 *bytes, int len, u8 *result)
  59374. +{
  59375. + dwc_wusb_prf(64, key, nonce, label, bytes, len, result);
  59376. +}
  59377. +
  59378. +/**
  59379. + * The PRF-128 function described in section 6.5 of the WUSB spec.
  59380. + *
  59381. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  59382. + */
  59383. +static inline void dwc_wusb_prf_128(u8 *key, u8 *nonce,
  59384. + char *label, u8 *bytes, int len, u8 *result)
  59385. +{
  59386. + dwc_wusb_prf(128, key, nonce, label, bytes, len, result);
  59387. +}
  59388. +
  59389. +/**
  59390. + * The PRF-256 function described in section 6.5 of the WUSB spec.
  59391. + *
  59392. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  59393. + */
  59394. +static inline void dwc_wusb_prf_256(u8 *key, u8 *nonce,
  59395. + char *label, u8 *bytes, int len, u8 *result)
  59396. +{
  59397. + dwc_wusb_prf(256, key, nonce, label, bytes, len, result);
  59398. +}
  59399. +
  59400. +
  59401. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  59402. + uint8_t *nonce);
  59403. +void dwc_wusb_gen_nonce(uint16_t addr,
  59404. + uint8_t *nonce);
  59405. +
  59406. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk,
  59407. + uint8_t *hnonce, uint8_t *dnonce,
  59408. + uint8_t *kck, uint8_t *ptk);
  59409. +
  59410. +
  59411. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t
  59412. + *kck, uint8_t *data, uint8_t *mic);
  59413. +
  59414. +#ifdef __cplusplus
  59415. +}
  59416. +#endif
  59417. +
  59418. +#endif /* _DWC_CRYPTO_H_ */
  59419. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_dh.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.c
  59420. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_dh.c 1970-01-01 01:00:00.000000000 +0100
  59421. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.c 2015-02-09 04:40:28.000000000 +0100
  59422. @@ -0,0 +1,291 @@
  59423. +/* =========================================================================
  59424. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.c $
  59425. + * $Revision: #3 $
  59426. + * $Date: 2010/09/28 $
  59427. + * $Change: 1596182 $
  59428. + *
  59429. + * Synopsys Portability Library Software and documentation
  59430. + * (hereinafter, "Software") is an Unsupported proprietary work of
  59431. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  59432. + * between Synopsys and you.
  59433. + *
  59434. + * The Software IS NOT an item of Licensed Software or Licensed Product
  59435. + * under any End User Software License Agreement or Agreement for
  59436. + * Licensed Product with Synopsys or any supplement thereto. You are
  59437. + * permitted to use and redistribute this Software in source and binary
  59438. + * forms, with or without modification, provided that redistributions
  59439. + * of source code must retain this notice. You may not view, use,
  59440. + * disclose, copy or distribute this file or any information contained
  59441. + * herein except pursuant to this license grant from Synopsys. If you
  59442. + * do not agree with this notice, including the disclaimer below, then
  59443. + * you are not authorized to use the Software.
  59444. + *
  59445. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  59446. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  59447. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  59448. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  59449. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  59450. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  59451. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  59452. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  59453. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59454. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  59455. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  59456. + * DAMAGE.
  59457. + * ========================================================================= */
  59458. +#ifdef DWC_CRYPTOLIB
  59459. +
  59460. +#ifndef CONFIG_MACH_IPMATE
  59461. +
  59462. +#include "dwc_dh.h"
  59463. +#include "dwc_modpow.h"
  59464. +
  59465. +#ifdef DEBUG
  59466. +/* This function prints out a buffer in the format described in the Association
  59467. + * Model specification. */
  59468. +static void dh_dump(char *str, void *_num, int len)
  59469. +{
  59470. + uint8_t *num = _num;
  59471. + int i;
  59472. + DWC_PRINTF("%s\n", str);
  59473. + for (i = 0; i < len; i ++) {
  59474. + DWC_PRINTF("%02x", num[i]);
  59475. + if (((i + 1) % 2) == 0) DWC_PRINTF(" ");
  59476. + if (((i + 1) % 26) == 0) DWC_PRINTF("\n");
  59477. + }
  59478. +
  59479. + DWC_PRINTF("\n");
  59480. +}
  59481. +#else
  59482. +#define dh_dump(_x...) do {; } while(0)
  59483. +#endif
  59484. +
  59485. +/* Constant g value */
  59486. +static __u32 dh_g[] = {
  59487. + 0x02000000,
  59488. +};
  59489. +
  59490. +/* Constant p value */
  59491. +static __u32 dh_p[] = {
  59492. + 0xFFFFFFFF, 0xFFFFFFFF, 0xA2DA0FC9, 0x34C26821, 0x8B62C6C4, 0xD11CDC80, 0x084E0229, 0x74CC678A,
  59493. + 0xA6BE0B02, 0x229B133B, 0x79084A51, 0xDD04348E, 0xB31995EF, 0x1B433ACD, 0x6D0A2B30, 0x37145FF2,
  59494. + 0x6D35E14F, 0x45C2516D, 0x76B585E4, 0xC67E5E62, 0xE9424CF4, 0x6BED37A6, 0xB65CFF0B, 0xEDB706F4,
  59495. + 0xFB6B38EE, 0xA59F895A, 0x11249FAE, 0xE61F4B7C, 0x51662849, 0x3D5BE4EC, 0xB87C00C2, 0x05BF63A1,
  59496. + 0x3648DA98, 0x9AD3551C, 0xA83F1669, 0x5FCF24FD, 0x235D6583, 0x96ADA3DC, 0x56F3621C, 0xBB528520,
  59497. + 0x0729D59E, 0x6D969670, 0x4E350C67, 0x0498BC4A, 0x086C74F1, 0x7C2118CA, 0x465E9032, 0x3BCE362E,
  59498. + 0x2C779EE3, 0x03860E18, 0xA283279B, 0x8FA207EC, 0xF05DC5B5, 0xC9524C6F, 0xF6CB2BDE, 0x18175895,
  59499. + 0x7C499539, 0xE56A95EA, 0x1826D215, 0x1005FA98, 0x5A8E7215, 0x2DC4AA8A, 0x0D1733AD, 0x337A5004,
  59500. + 0xAB2155A8, 0x64BA1CDF, 0x0485FBEC, 0x0AEFDB58, 0x5771EA8A, 0x7D0C065D, 0x850F97B3, 0xC7E4E1A6,
  59501. + 0x8CAEF5AB, 0xD73309DB, 0xE0948C1E, 0x9D61254A, 0x26D2E3CE, 0x6BEED21A, 0x06FA2FF1, 0x64088AD9,
  59502. + 0x730276D8, 0x646AC83E, 0x182B1F52, 0x0C207B17, 0x5717E1BB, 0x6C5D617A, 0xC0880977, 0xE246D9BA,
  59503. + 0xA04FE208, 0x31ABE574, 0xFC5BDB43, 0x8E10FDE0, 0x20D1824B, 0xCAD23AA9, 0xFFFFFFFF, 0xFFFFFFFF,
  59504. +};
  59505. +
  59506. +static void dh_swap_bytes(void *_in, void *_out, uint32_t len)
  59507. +{
  59508. + uint8_t *in = _in;
  59509. + uint8_t *out = _out;
  59510. + int i;
  59511. + for (i=0; i<len; i++) {
  59512. + out[i] = in[len-1-i];
  59513. + }
  59514. +}
  59515. +
  59516. +/* Computes the modular exponentiation (num^exp % mod). num, exp, and mod are
  59517. + * big endian numbers of size len, in bytes. Each len value must be a multiple
  59518. + * of 4. */
  59519. +int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  59520. + void *exp, uint32_t exp_len,
  59521. + void *mod, uint32_t mod_len,
  59522. + void *out)
  59523. +{
  59524. + /* modpow() takes little endian numbers. AM uses big-endian. This
  59525. + * function swaps bytes of numbers before passing onto modpow. */
  59526. +
  59527. + int retval = 0;
  59528. + uint32_t *result;
  59529. +
  59530. + uint32_t *bignum_num = dwc_alloc(mem_ctx, num_len + 4);
  59531. + uint32_t *bignum_exp = dwc_alloc(mem_ctx, exp_len + 4);
  59532. + uint32_t *bignum_mod = dwc_alloc(mem_ctx, mod_len + 4);
  59533. +
  59534. + dh_swap_bytes(num, &bignum_num[1], num_len);
  59535. + bignum_num[0] = num_len / 4;
  59536. +
  59537. + dh_swap_bytes(exp, &bignum_exp[1], exp_len);
  59538. + bignum_exp[0] = exp_len / 4;
  59539. +
  59540. + dh_swap_bytes(mod, &bignum_mod[1], mod_len);
  59541. + bignum_mod[0] = mod_len / 4;
  59542. +
  59543. + result = dwc_modpow(mem_ctx, bignum_num, bignum_exp, bignum_mod);
  59544. + if (!result) {
  59545. + retval = -1;
  59546. + goto dh_modpow_nomem;
  59547. + }
  59548. +
  59549. + dh_swap_bytes(&result[1], out, result[0] * 4);
  59550. + dwc_free(mem_ctx, result);
  59551. +
  59552. + dh_modpow_nomem:
  59553. + dwc_free(mem_ctx, bignum_num);
  59554. + dwc_free(mem_ctx, bignum_exp);
  59555. + dwc_free(mem_ctx, bignum_mod);
  59556. + return retval;
  59557. +}
  59558. +
  59559. +
  59560. +int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pk, uint8_t *hash)
  59561. +{
  59562. + int retval;
  59563. + uint8_t m3[385];
  59564. +
  59565. +#ifndef DH_TEST_VECTORS
  59566. + DWC_RANDOM_BYTES(exp, 32);
  59567. +#endif
  59568. +
  59569. + /* Compute the pkd */
  59570. + if ((retval = dwc_dh_modpow(mem_ctx, dh_g, 4,
  59571. + exp, 32,
  59572. + dh_p, 384, pk))) {
  59573. + return retval;
  59574. + }
  59575. +
  59576. + m3[384] = nd;
  59577. + DWC_MEMCPY(&m3[0], pk, 384);
  59578. + DWC_SHA256(m3, 385, hash);
  59579. +
  59580. + dh_dump("PK", pk, 384);
  59581. + dh_dump("SHA-256(M3)", hash, 32);
  59582. + return 0;
  59583. +}
  59584. +
  59585. +int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  59586. + uint8_t *exp, int is_host,
  59587. + char *dd, uint8_t *ck, uint8_t *kdk)
  59588. +{
  59589. + int retval;
  59590. + uint8_t mv[784];
  59591. + uint8_t sha_result[32];
  59592. + uint8_t dhkey[384];
  59593. + uint8_t shared_secret[384];
  59594. + char *message;
  59595. + uint32_t vd;
  59596. +
  59597. + uint8_t *pk;
  59598. +
  59599. + if (is_host) {
  59600. + pk = pkd;
  59601. + }
  59602. + else {
  59603. + pk = pkh;
  59604. + }
  59605. +
  59606. + if ((retval = dwc_dh_modpow(mem_ctx, pk, 384,
  59607. + exp, 32,
  59608. + dh_p, 384, shared_secret))) {
  59609. + return retval;
  59610. + }
  59611. + dh_dump("Shared Secret", shared_secret, 384);
  59612. +
  59613. + DWC_SHA256(shared_secret, 384, dhkey);
  59614. + dh_dump("DHKEY", dhkey, 384);
  59615. +
  59616. + DWC_MEMCPY(&mv[0], pkd, 384);
  59617. + DWC_MEMCPY(&mv[384], pkh, 384);
  59618. + DWC_MEMCPY(&mv[768], "displayed digest", 16);
  59619. + dh_dump("MV", mv, 784);
  59620. +
  59621. + DWC_SHA256(mv, 784, sha_result);
  59622. + dh_dump("SHA-256(MV)", sha_result, 32);
  59623. + dh_dump("First 32-bits of SHA-256(MV)", sha_result, 4);
  59624. +
  59625. + dh_swap_bytes(sha_result, &vd, 4);
  59626. +#ifdef DEBUG
  59627. + DWC_PRINTF("Vd (decimal) = %d\n", vd);
  59628. +#endif
  59629. +
  59630. + switch (nd) {
  59631. + case 2:
  59632. + vd = vd % 100;
  59633. + DWC_SPRINTF(dd, "%02d", vd);
  59634. + break;
  59635. + case 3:
  59636. + vd = vd % 1000;
  59637. + DWC_SPRINTF(dd, "%03d", vd);
  59638. + break;
  59639. + case 4:
  59640. + vd = vd % 10000;
  59641. + DWC_SPRINTF(dd, "%04d", vd);
  59642. + break;
  59643. + }
  59644. +#ifdef DEBUG
  59645. + DWC_PRINTF("Display Digits: %s\n", dd);
  59646. +#endif
  59647. +
  59648. + message = "connection key";
  59649. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  59650. + dh_dump("HMAC(SHA-256, DHKey, connection key)", sha_result, 32);
  59651. + DWC_MEMCPY(ck, sha_result, 16);
  59652. +
  59653. + message = "key derivation key";
  59654. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  59655. + dh_dump("HMAC(SHA-256, DHKey, key derivation key)", sha_result, 32);
  59656. + DWC_MEMCPY(kdk, sha_result, 32);
  59657. +
  59658. + return 0;
  59659. +}
  59660. +
  59661. +
  59662. +#ifdef DH_TEST_VECTORS
  59663. +
  59664. +static __u8 dh_a[] = {
  59665. + 0x44, 0x00, 0x51, 0xd6,
  59666. + 0xf0, 0xb5, 0x5e, 0xa9,
  59667. + 0x67, 0xab, 0x31, 0xc6,
  59668. + 0x8a, 0x8b, 0x5e, 0x37,
  59669. + 0xd9, 0x10, 0xda, 0xe0,
  59670. + 0xe2, 0xd4, 0x59, 0xa4,
  59671. + 0x86, 0x45, 0x9c, 0xaa,
  59672. + 0xdf, 0x36, 0x75, 0x16,
  59673. +};
  59674. +
  59675. +static __u8 dh_b[] = {
  59676. + 0x5d, 0xae, 0xc7, 0x86,
  59677. + 0x79, 0x80, 0xa3, 0x24,
  59678. + 0x8c, 0xe3, 0x57, 0x8f,
  59679. + 0xc7, 0x5f, 0x1b, 0x0f,
  59680. + 0x2d, 0xf8, 0x9d, 0x30,
  59681. + 0x6f, 0xa4, 0x52, 0xcd,
  59682. + 0xe0, 0x7a, 0x04, 0x8a,
  59683. + 0xde, 0xd9, 0x26, 0x56,
  59684. +};
  59685. +
  59686. +void dwc_run_dh_test_vectors(void *mem_ctx)
  59687. +{
  59688. + uint8_t pkd[384];
  59689. + uint8_t pkh[384];
  59690. + uint8_t hashd[32];
  59691. + uint8_t hashh[32];
  59692. + uint8_t ck[16];
  59693. + uint8_t kdk[32];
  59694. + char dd[5];
  59695. +
  59696. + DWC_PRINTF("\n\n\nDH_TEST_VECTORS\n\n");
  59697. +
  59698. + /* compute the PKd and SHA-256(PKd || Nd) */
  59699. + DWC_PRINTF("Computing PKd\n");
  59700. + dwc_dh_pk(mem_ctx, 2, dh_a, pkd, hashd);
  59701. +
  59702. + /* compute the PKd and SHA-256(PKh || Nd) */
  59703. + DWC_PRINTF("Computing PKh\n");
  59704. + dwc_dh_pk(mem_ctx, 2, dh_b, pkh, hashh);
  59705. +
  59706. + /* compute the dhkey */
  59707. + dwc_dh_derive_keys(mem_ctx, 2, pkh, pkd, dh_a, 0, dd, ck, kdk);
  59708. +}
  59709. +#endif /* DH_TEST_VECTORS */
  59710. +
  59711. +#endif /* !CONFIG_MACH_IPMATE */
  59712. +
  59713. +#endif /* DWC_CRYPTOLIB */
  59714. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_dh.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.h
  59715. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_dh.h 1970-01-01 01:00:00.000000000 +0100
  59716. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.h 2015-02-09 04:40:28.000000000 +0100
  59717. @@ -0,0 +1,106 @@
  59718. +/* =========================================================================
  59719. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.h $
  59720. + * $Revision: #4 $
  59721. + * $Date: 2010/09/28 $
  59722. + * $Change: 1596182 $
  59723. + *
  59724. + * Synopsys Portability Library Software and documentation
  59725. + * (hereinafter, "Software") is an Unsupported proprietary work of
  59726. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  59727. + * between Synopsys and you.
  59728. + *
  59729. + * The Software IS NOT an item of Licensed Software or Licensed Product
  59730. + * under any End User Software License Agreement or Agreement for
  59731. + * Licensed Product with Synopsys or any supplement thereto. You are
  59732. + * permitted to use and redistribute this Software in source and binary
  59733. + * forms, with or without modification, provided that redistributions
  59734. + * of source code must retain this notice. You may not view, use,
  59735. + * disclose, copy or distribute this file or any information contained
  59736. + * herein except pursuant to this license grant from Synopsys. If you
  59737. + * do not agree with this notice, including the disclaimer below, then
  59738. + * you are not authorized to use the Software.
  59739. + *
  59740. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  59741. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  59742. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  59743. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  59744. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  59745. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  59746. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  59747. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  59748. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59749. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  59750. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  59751. + * DAMAGE.
  59752. + * ========================================================================= */
  59753. +#ifndef _DWC_DH_H_
  59754. +#define _DWC_DH_H_
  59755. +
  59756. +#ifdef __cplusplus
  59757. +extern "C" {
  59758. +#endif
  59759. +
  59760. +#include "dwc_os.h"
  59761. +
  59762. +/** @file
  59763. + *
  59764. + * This file defines the common functions on device and host for performing
  59765. + * numeric association as defined in the WUSB spec. They are only to be
  59766. + * used internally by the DWC UWB modules. */
  59767. +
  59768. +extern int dwc_dh_sha256(uint8_t *message, uint32_t len, uint8_t *out);
  59769. +extern int dwc_dh_hmac_sha256(uint8_t *message, uint32_t messagelen,
  59770. + uint8_t *key, uint32_t keylen,
  59771. + uint8_t *out);
  59772. +extern int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  59773. + void *exp, uint32_t exp_len,
  59774. + void *mod, uint32_t mod_len,
  59775. + void *out);
  59776. +
  59777. +/** Computes PKD or PKH, and SHA-256(PKd || Nd)
  59778. + *
  59779. + * PK = g^exp mod p.
  59780. + *
  59781. + * Input:
  59782. + * Nd = Number of digits on the device.
  59783. + *
  59784. + * Output:
  59785. + * exp = A 32-byte buffer to be filled with a randomly generated number.
  59786. + * used as either A or B.
  59787. + * pk = A 384-byte buffer to be filled with the PKH or PKD.
  59788. + * hash = A 32-byte buffer to be filled with SHA-256(PK || ND).
  59789. + */
  59790. +extern int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pkd, uint8_t *hash);
  59791. +
  59792. +/** Computes the DHKEY, and VD.
  59793. + *
  59794. + * If called from host, then it will comput DHKEY=PKD^exp % p.
  59795. + * If called from device, then it will comput DHKEY=PKH^exp % p.
  59796. + *
  59797. + * Input:
  59798. + * pkd = The PKD value.
  59799. + * pkh = The PKH value.
  59800. + * exp = The A value (if device) or B value (if host) generated in dwc_wudev_dh_pk.
  59801. + * is_host = Set to non zero if a WUSB host is calling this function.
  59802. + *
  59803. + * Output:
  59804. +
  59805. + * dd = A pointer to an buffer to be set to the displayed digits string to be shown
  59806. + * to the user. This buffer should be at 5 bytes long to hold 4 digits plus a
  59807. + * null termination character. This buffer can be used directly for display.
  59808. + * ck = A 16-byte buffer to be filled with the CK.
  59809. + * kdk = A 32-byte buffer to be filled with the KDK.
  59810. + */
  59811. +extern int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  59812. + uint8_t *exp, int is_host,
  59813. + char *dd, uint8_t *ck, uint8_t *kdk);
  59814. +
  59815. +#ifdef DH_TEST_VECTORS
  59816. +extern void dwc_run_dh_test_vectors(void);
  59817. +#endif
  59818. +
  59819. +#ifdef __cplusplus
  59820. +}
  59821. +#endif
  59822. +
  59823. +#endif /* _DWC_DH_H_ */
  59824. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_list.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_list.h
  59825. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_list.h 1970-01-01 01:00:00.000000000 +0100
  59826. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_list.h 2015-02-09 04:40:28.000000000 +0100
  59827. @@ -0,0 +1,594 @@
  59828. +/* $OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $ */
  59829. +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
  59830. +
  59831. +/*
  59832. + * Copyright (c) 1991, 1993
  59833. + * The Regents of the University of California. All rights reserved.
  59834. + *
  59835. + * Redistribution and use in source and binary forms, with or without
  59836. + * modification, are permitted provided that the following conditions
  59837. + * are met:
  59838. + * 1. Redistributions of source code must retain the above copyright
  59839. + * notice, this list of conditions and the following disclaimer.
  59840. + * 2. Redistributions in binary form must reproduce the above copyright
  59841. + * notice, this list of conditions and the following disclaimer in the
  59842. + * documentation and/or other materials provided with the distribution.
  59843. + * 3. Neither the name of the University nor the names of its contributors
  59844. + * may be used to endorse or promote products derived from this software
  59845. + * without specific prior written permission.
  59846. + *
  59847. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  59848. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  59849. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  59850. + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  59851. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  59852. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  59853. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  59854. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  59855. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  59856. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59857. + * SUCH DAMAGE.
  59858. + *
  59859. + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  59860. + */
  59861. +
  59862. +#ifndef _DWC_LIST_H_
  59863. +#define _DWC_LIST_H_
  59864. +
  59865. +#ifdef __cplusplus
  59866. +extern "C" {
  59867. +#endif
  59868. +
  59869. +/** @file
  59870. + *
  59871. + * This file defines linked list operations. It is derived from BSD with
  59872. + * only the MACRO names being prefixed with DWC_. This is because a few of
  59873. + * these names conflict with those on Linux. For documentation on use, see the
  59874. + * inline comments in the source code. The original license for this source
  59875. + * code applies and is preserved in the dwc_list.h source file.
  59876. + */
  59877. +
  59878. +/*
  59879. + * This file defines five types of data structures: singly-linked lists,
  59880. + * lists, simple queues, tail queues, and circular queues.
  59881. + *
  59882. + *
  59883. + * A singly-linked list is headed by a single forward pointer. The elements
  59884. + * are singly linked for minimum space and pointer manipulation overhead at
  59885. + * the expense of O(n) removal for arbitrary elements. New elements can be
  59886. + * added to the list after an existing element or at the head of the list.
  59887. + * Elements being removed from the head of the list should use the explicit
  59888. + * macro for this purpose for optimum efficiency. A singly-linked list may
  59889. + * only be traversed in the forward direction. Singly-linked lists are ideal
  59890. + * for applications with large datasets and few or no removals or for
  59891. + * implementing a LIFO queue.
  59892. + *
  59893. + * A list is headed by a single forward pointer (or an array of forward
  59894. + * pointers for a hash table header). The elements are doubly linked
  59895. + * so that an arbitrary element can be removed without a need to
  59896. + * traverse the list. New elements can be added to the list before
  59897. + * or after an existing element or at the head of the list. A list
  59898. + * may only be traversed in the forward direction.
  59899. + *
  59900. + * A simple queue is headed by a pair of pointers, one the head of the
  59901. + * list and the other to the tail of the list. The elements are singly
  59902. + * linked to save space, so elements can only be removed from the
  59903. + * head of the list. New elements can be added to the list before or after
  59904. + * an existing element, at the head of the list, or at the end of the
  59905. + * list. A simple queue may only be traversed in the forward direction.
  59906. + *
  59907. + * A tail queue is headed by a pair of pointers, one to the head of the
  59908. + * list and the other to the tail of the list. The elements are doubly
  59909. + * linked so that an arbitrary element can be removed without a need to
  59910. + * traverse the list. New elements can be added to the list before or
  59911. + * after an existing element, at the head of the list, or at the end of
  59912. + * the list. A tail queue may be traversed in either direction.
  59913. + *
  59914. + * A circle queue is headed by a pair of pointers, one to the head of the
  59915. + * list and the other to the tail of the list. The elements are doubly
  59916. + * linked so that an arbitrary element can be removed without a need to
  59917. + * traverse the list. New elements can be added to the list before or after
  59918. + * an existing element, at the head of the list, or at the end of the list.
  59919. + * A circle queue may be traversed in either direction, but has a more
  59920. + * complex end of list detection.
  59921. + *
  59922. + * For details on the use of these macros, see the queue(3) manual page.
  59923. + */
  59924. +
  59925. +/*
  59926. + * Double-linked List.
  59927. + */
  59928. +
  59929. +typedef struct dwc_list_link {
  59930. + struct dwc_list_link *next;
  59931. + struct dwc_list_link *prev;
  59932. +} dwc_list_link_t;
  59933. +
  59934. +#define DWC_LIST_INIT(link) do { \
  59935. + (link)->next = (link); \
  59936. + (link)->prev = (link); \
  59937. +} while (0)
  59938. +
  59939. +#define DWC_LIST_FIRST(link) ((link)->next)
  59940. +#define DWC_LIST_LAST(link) ((link)->prev)
  59941. +#define DWC_LIST_END(link) (link)
  59942. +#define DWC_LIST_NEXT(link) ((link)->next)
  59943. +#define DWC_LIST_PREV(link) ((link)->prev)
  59944. +#define DWC_LIST_EMPTY(link) \
  59945. + (DWC_LIST_FIRST(link) == DWC_LIST_END(link))
  59946. +#define DWC_LIST_ENTRY(link, type, field) \
  59947. + (type *)((uint8_t *)(link) - (size_t)(&((type *)0)->field))
  59948. +
  59949. +#if 0
  59950. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  59951. + (link)->next = (list)->next; \
  59952. + (link)->prev = (list); \
  59953. + (list)->next->prev = (link); \
  59954. + (list)->next = (link); \
  59955. +} while (0)
  59956. +
  59957. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  59958. + (link)->next = (list); \
  59959. + (link)->prev = (list)->prev; \
  59960. + (list)->prev->next = (link); \
  59961. + (list)->prev = (link); \
  59962. +} while (0)
  59963. +#else
  59964. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  59965. + dwc_list_link_t *__next__ = (list)->next; \
  59966. + __next__->prev = (link); \
  59967. + (link)->next = __next__; \
  59968. + (link)->prev = (list); \
  59969. + (list)->next = (link); \
  59970. +} while (0)
  59971. +
  59972. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  59973. + dwc_list_link_t *__prev__ = (list)->prev; \
  59974. + (list)->prev = (link); \
  59975. + (link)->next = (list); \
  59976. + (link)->prev = __prev__; \
  59977. + __prev__->next = (link); \
  59978. +} while (0)
  59979. +#endif
  59980. +
  59981. +#if 0
  59982. +static inline void __list_add(struct list_head *new,
  59983. + struct list_head *prev,
  59984. + struct list_head *next)
  59985. +{
  59986. + next->prev = new;
  59987. + new->next = next;
  59988. + new->prev = prev;
  59989. + prev->next = new;
  59990. +}
  59991. +
  59992. +static inline void list_add(struct list_head *new, struct list_head *head)
  59993. +{
  59994. + __list_add(new, head, head->next);
  59995. +}
  59996. +
  59997. +static inline void list_add_tail(struct list_head *new, struct list_head *head)
  59998. +{
  59999. + __list_add(new, head->prev, head);
  60000. +}
  60001. +
  60002. +static inline void __list_del(struct list_head * prev, struct list_head * next)
  60003. +{
  60004. + next->prev = prev;
  60005. + prev->next = next;
  60006. +}
  60007. +
  60008. +static inline void list_del(struct list_head *entry)
  60009. +{
  60010. + __list_del(entry->prev, entry->next);
  60011. + entry->next = LIST_POISON1;
  60012. + entry->prev = LIST_POISON2;
  60013. +}
  60014. +#endif
  60015. +
  60016. +#define DWC_LIST_REMOVE(link) do { \
  60017. + (link)->next->prev = (link)->prev; \
  60018. + (link)->prev->next = (link)->next; \
  60019. +} while (0)
  60020. +
  60021. +#define DWC_LIST_REMOVE_INIT(link) do { \
  60022. + DWC_LIST_REMOVE(link); \
  60023. + DWC_LIST_INIT(link); \
  60024. +} while (0)
  60025. +
  60026. +#define DWC_LIST_MOVE_HEAD(list, link) do { \
  60027. + DWC_LIST_REMOVE(link); \
  60028. + DWC_LIST_INSERT_HEAD(list, link); \
  60029. +} while (0)
  60030. +
  60031. +#define DWC_LIST_MOVE_TAIL(list, link) do { \
  60032. + DWC_LIST_REMOVE(link); \
  60033. + DWC_LIST_INSERT_TAIL(list, link); \
  60034. +} while (0)
  60035. +
  60036. +#define DWC_LIST_FOREACH(var, list) \
  60037. + for((var) = DWC_LIST_FIRST(list); \
  60038. + (var) != DWC_LIST_END(list); \
  60039. + (var) = DWC_LIST_NEXT(var))
  60040. +
  60041. +#define DWC_LIST_FOREACH_SAFE(var, var2, list) \
  60042. + for((var) = DWC_LIST_FIRST(list), (var2) = DWC_LIST_NEXT(var); \
  60043. + (var) != DWC_LIST_END(list); \
  60044. + (var) = (var2), (var2) = DWC_LIST_NEXT(var2))
  60045. +
  60046. +#define DWC_LIST_FOREACH_REVERSE(var, list) \
  60047. + for((var) = DWC_LIST_LAST(list); \
  60048. + (var) != DWC_LIST_END(list); \
  60049. + (var) = DWC_LIST_PREV(var))
  60050. +
  60051. +/*
  60052. + * Singly-linked List definitions.
  60053. + */
  60054. +#define DWC_SLIST_HEAD(name, type) \
  60055. +struct name { \
  60056. + struct type *slh_first; /* first element */ \
  60057. +}
  60058. +
  60059. +#define DWC_SLIST_HEAD_INITIALIZER(head) \
  60060. + { NULL }
  60061. +
  60062. +#define DWC_SLIST_ENTRY(type) \
  60063. +struct { \
  60064. + struct type *sle_next; /* next element */ \
  60065. +}
  60066. +
  60067. +/*
  60068. + * Singly-linked List access methods.
  60069. + */
  60070. +#define DWC_SLIST_FIRST(head) ((head)->slh_first)
  60071. +#define DWC_SLIST_END(head) NULL
  60072. +#define DWC_SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
  60073. +#define DWC_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
  60074. +
  60075. +#define DWC_SLIST_FOREACH(var, head, field) \
  60076. + for((var) = SLIST_FIRST(head); \
  60077. + (var) != SLIST_END(head); \
  60078. + (var) = SLIST_NEXT(var, field))
  60079. +
  60080. +#define DWC_SLIST_FOREACH_PREVPTR(var, varp, head, field) \
  60081. + for((varp) = &SLIST_FIRST((head)); \
  60082. + ((var) = *(varp)) != SLIST_END(head); \
  60083. + (varp) = &SLIST_NEXT((var), field))
  60084. +
  60085. +/*
  60086. + * Singly-linked List functions.
  60087. + */
  60088. +#define DWC_SLIST_INIT(head) { \
  60089. + SLIST_FIRST(head) = SLIST_END(head); \
  60090. +}
  60091. +
  60092. +#define DWC_SLIST_INSERT_AFTER(slistelm, elm, field) do { \
  60093. + (elm)->field.sle_next = (slistelm)->field.sle_next; \
  60094. + (slistelm)->field.sle_next = (elm); \
  60095. +} while (0)
  60096. +
  60097. +#define DWC_SLIST_INSERT_HEAD(head, elm, field) do { \
  60098. + (elm)->field.sle_next = (head)->slh_first; \
  60099. + (head)->slh_first = (elm); \
  60100. +} while (0)
  60101. +
  60102. +#define DWC_SLIST_REMOVE_NEXT(head, elm, field) do { \
  60103. + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
  60104. +} while (0)
  60105. +
  60106. +#define DWC_SLIST_REMOVE_HEAD(head, field) do { \
  60107. + (head)->slh_first = (head)->slh_first->field.sle_next; \
  60108. +} while (0)
  60109. +
  60110. +#define DWC_SLIST_REMOVE(head, elm, type, field) do { \
  60111. + if ((head)->slh_first == (elm)) { \
  60112. + SLIST_REMOVE_HEAD((head), field); \
  60113. + } \
  60114. + else { \
  60115. + struct type *curelm = (head)->slh_first; \
  60116. + while( curelm->field.sle_next != (elm) ) \
  60117. + curelm = curelm->field.sle_next; \
  60118. + curelm->field.sle_next = \
  60119. + curelm->field.sle_next->field.sle_next; \
  60120. + } \
  60121. +} while (0)
  60122. +
  60123. +/*
  60124. + * Simple queue definitions.
  60125. + */
  60126. +#define DWC_SIMPLEQ_HEAD(name, type) \
  60127. +struct name { \
  60128. + struct type *sqh_first; /* first element */ \
  60129. + struct type **sqh_last; /* addr of last next element */ \
  60130. +}
  60131. +
  60132. +#define DWC_SIMPLEQ_HEAD_INITIALIZER(head) \
  60133. + { NULL, &(head).sqh_first }
  60134. +
  60135. +#define DWC_SIMPLEQ_ENTRY(type) \
  60136. +struct { \
  60137. + struct type *sqe_next; /* next element */ \
  60138. +}
  60139. +
  60140. +/*
  60141. + * Simple queue access methods.
  60142. + */
  60143. +#define DWC_SIMPLEQ_FIRST(head) ((head)->sqh_first)
  60144. +#define DWC_SIMPLEQ_END(head) NULL
  60145. +#define DWC_SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
  60146. +#define DWC_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
  60147. +
  60148. +#define DWC_SIMPLEQ_FOREACH(var, head, field) \
  60149. + for((var) = SIMPLEQ_FIRST(head); \
  60150. + (var) != SIMPLEQ_END(head); \
  60151. + (var) = SIMPLEQ_NEXT(var, field))
  60152. +
  60153. +/*
  60154. + * Simple queue functions.
  60155. + */
  60156. +#define DWC_SIMPLEQ_INIT(head) do { \
  60157. + (head)->sqh_first = NULL; \
  60158. + (head)->sqh_last = &(head)->sqh_first; \
  60159. +} while (0)
  60160. +
  60161. +#define DWC_SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
  60162. + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
  60163. + (head)->sqh_last = &(elm)->field.sqe_next; \
  60164. + (head)->sqh_first = (elm); \
  60165. +} while (0)
  60166. +
  60167. +#define DWC_SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
  60168. + (elm)->field.sqe_next = NULL; \
  60169. + *(head)->sqh_last = (elm); \
  60170. + (head)->sqh_last = &(elm)->field.sqe_next; \
  60171. +} while (0)
  60172. +
  60173. +#define DWC_SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  60174. + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  60175. + (head)->sqh_last = &(elm)->field.sqe_next; \
  60176. + (listelm)->field.sqe_next = (elm); \
  60177. +} while (0)
  60178. +
  60179. +#define DWC_SIMPLEQ_REMOVE_HEAD(head, field) do { \
  60180. + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  60181. + (head)->sqh_last = &(head)->sqh_first; \
  60182. +} while (0)
  60183. +
  60184. +/*
  60185. + * Tail queue definitions.
  60186. + */
  60187. +#define DWC_TAILQ_HEAD(name, type) \
  60188. +struct name { \
  60189. + struct type *tqh_first; /* first element */ \
  60190. + struct type **tqh_last; /* addr of last next element */ \
  60191. +}
  60192. +
  60193. +#define DWC_TAILQ_HEAD_INITIALIZER(head) \
  60194. + { NULL, &(head).tqh_first }
  60195. +
  60196. +#define DWC_TAILQ_ENTRY(type) \
  60197. +struct { \
  60198. + struct type *tqe_next; /* next element */ \
  60199. + struct type **tqe_prev; /* address of previous next element */ \
  60200. +}
  60201. +
  60202. +/*
  60203. + * tail queue access methods
  60204. + */
  60205. +#define DWC_TAILQ_FIRST(head) ((head)->tqh_first)
  60206. +#define DWC_TAILQ_END(head) NULL
  60207. +#define DWC_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  60208. +#define DWC_TAILQ_LAST(head, headname) \
  60209. + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  60210. +/* XXX */
  60211. +#define DWC_TAILQ_PREV(elm, headname, field) \
  60212. + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  60213. +#define DWC_TAILQ_EMPTY(head) \
  60214. + (DWC_TAILQ_FIRST(head) == DWC_TAILQ_END(head))
  60215. +
  60216. +#define DWC_TAILQ_FOREACH(var, head, field) \
  60217. + for ((var) = DWC_TAILQ_FIRST(head); \
  60218. + (var) != DWC_TAILQ_END(head); \
  60219. + (var) = DWC_TAILQ_NEXT(var, field))
  60220. +
  60221. +#define DWC_TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  60222. + for ((var) = DWC_TAILQ_LAST(head, headname); \
  60223. + (var) != DWC_TAILQ_END(head); \
  60224. + (var) = DWC_TAILQ_PREV(var, headname, field))
  60225. +
  60226. +/*
  60227. + * Tail queue functions.
  60228. + */
  60229. +#define DWC_TAILQ_INIT(head) do { \
  60230. + (head)->tqh_first = NULL; \
  60231. + (head)->tqh_last = &(head)->tqh_first; \
  60232. +} while (0)
  60233. +
  60234. +#define DWC_TAILQ_INSERT_HEAD(head, elm, field) do { \
  60235. + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  60236. + (head)->tqh_first->field.tqe_prev = \
  60237. + &(elm)->field.tqe_next; \
  60238. + else \
  60239. + (head)->tqh_last = &(elm)->field.tqe_next; \
  60240. + (head)->tqh_first = (elm); \
  60241. + (elm)->field.tqe_prev = &(head)->tqh_first; \
  60242. +} while (0)
  60243. +
  60244. +#define DWC_TAILQ_INSERT_TAIL(head, elm, field) do { \
  60245. + (elm)->field.tqe_next = NULL; \
  60246. + (elm)->field.tqe_prev = (head)->tqh_last; \
  60247. + *(head)->tqh_last = (elm); \
  60248. + (head)->tqh_last = &(elm)->field.tqe_next; \
  60249. +} while (0)
  60250. +
  60251. +#define DWC_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  60252. + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  60253. + (elm)->field.tqe_next->field.tqe_prev = \
  60254. + &(elm)->field.tqe_next; \
  60255. + else \
  60256. + (head)->tqh_last = &(elm)->field.tqe_next; \
  60257. + (listelm)->field.tqe_next = (elm); \
  60258. + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  60259. +} while (0)
  60260. +
  60261. +#define DWC_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  60262. + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  60263. + (elm)->field.tqe_next = (listelm); \
  60264. + *(listelm)->field.tqe_prev = (elm); \
  60265. + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  60266. +} while (0)
  60267. +
  60268. +#define DWC_TAILQ_REMOVE(head, elm, field) do { \
  60269. + if (((elm)->field.tqe_next) != NULL) \
  60270. + (elm)->field.tqe_next->field.tqe_prev = \
  60271. + (elm)->field.tqe_prev; \
  60272. + else \
  60273. + (head)->tqh_last = (elm)->field.tqe_prev; \
  60274. + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  60275. +} while (0)
  60276. +
  60277. +#define DWC_TAILQ_REPLACE(head, elm, elm2, field) do { \
  60278. + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
  60279. + (elm2)->field.tqe_next->field.tqe_prev = \
  60280. + &(elm2)->field.tqe_next; \
  60281. + else \
  60282. + (head)->tqh_last = &(elm2)->field.tqe_next; \
  60283. + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
  60284. + *(elm2)->field.tqe_prev = (elm2); \
  60285. +} while (0)
  60286. +
  60287. +/*
  60288. + * Circular queue definitions.
  60289. + */
  60290. +#define DWC_CIRCLEQ_HEAD(name, type) \
  60291. +struct name { \
  60292. + struct type *cqh_first; /* first element */ \
  60293. + struct type *cqh_last; /* last element */ \
  60294. +}
  60295. +
  60296. +#define DWC_CIRCLEQ_HEAD_INITIALIZER(head) \
  60297. + { DWC_CIRCLEQ_END(&head), DWC_CIRCLEQ_END(&head) }
  60298. +
  60299. +#define DWC_CIRCLEQ_ENTRY(type) \
  60300. +struct { \
  60301. + struct type *cqe_next; /* next element */ \
  60302. + struct type *cqe_prev; /* previous element */ \
  60303. +}
  60304. +
  60305. +/*
  60306. + * Circular queue access methods
  60307. + */
  60308. +#define DWC_CIRCLEQ_FIRST(head) ((head)->cqh_first)
  60309. +#define DWC_CIRCLEQ_LAST(head) ((head)->cqh_last)
  60310. +#define DWC_CIRCLEQ_END(head) ((void *)(head))
  60311. +#define DWC_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  60312. +#define DWC_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  60313. +#define DWC_CIRCLEQ_EMPTY(head) \
  60314. + (DWC_CIRCLEQ_FIRST(head) == DWC_CIRCLEQ_END(head))
  60315. +
  60316. +#define DWC_CIRCLEQ_EMPTY_ENTRY(elm, field) (((elm)->field.cqe_next == NULL) && ((elm)->field.cqe_prev == NULL))
  60317. +
  60318. +#define DWC_CIRCLEQ_FOREACH(var, head, field) \
  60319. + for((var) = DWC_CIRCLEQ_FIRST(head); \
  60320. + (var) != DWC_CIRCLEQ_END(head); \
  60321. + (var) = DWC_CIRCLEQ_NEXT(var, field))
  60322. +
  60323. +#define DWC_CIRCLEQ_FOREACH_SAFE(var, var2, head, field) \
  60324. + for((var) = DWC_CIRCLEQ_FIRST(head), var2 = DWC_CIRCLEQ_NEXT(var, field); \
  60325. + (var) != DWC_CIRCLEQ_END(head); \
  60326. + (var) = var2, var2 = DWC_CIRCLEQ_NEXT(var, field))
  60327. +
  60328. +#define DWC_CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  60329. + for((var) = DWC_CIRCLEQ_LAST(head); \
  60330. + (var) != DWC_CIRCLEQ_END(head); \
  60331. + (var) = DWC_CIRCLEQ_PREV(var, field))
  60332. +
  60333. +/*
  60334. + * Circular queue functions.
  60335. + */
  60336. +#define DWC_CIRCLEQ_INIT(head) do { \
  60337. + (head)->cqh_first = DWC_CIRCLEQ_END(head); \
  60338. + (head)->cqh_last = DWC_CIRCLEQ_END(head); \
  60339. +} while (0)
  60340. +
  60341. +#define DWC_CIRCLEQ_INIT_ENTRY(elm, field) do { \
  60342. + (elm)->field.cqe_next = NULL; \
  60343. + (elm)->field.cqe_prev = NULL; \
  60344. +} while (0)
  60345. +
  60346. +#define DWC_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  60347. + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  60348. + (elm)->field.cqe_prev = (listelm); \
  60349. + if ((listelm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  60350. + (head)->cqh_last = (elm); \
  60351. + else \
  60352. + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  60353. + (listelm)->field.cqe_next = (elm); \
  60354. +} while (0)
  60355. +
  60356. +#define DWC_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  60357. + (elm)->field.cqe_next = (listelm); \
  60358. + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  60359. + if ((listelm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  60360. + (head)->cqh_first = (elm); \
  60361. + else \
  60362. + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  60363. + (listelm)->field.cqe_prev = (elm); \
  60364. +} while (0)
  60365. +
  60366. +#define DWC_CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  60367. + (elm)->field.cqe_next = (head)->cqh_first; \
  60368. + (elm)->field.cqe_prev = DWC_CIRCLEQ_END(head); \
  60369. + if ((head)->cqh_last == DWC_CIRCLEQ_END(head)) \
  60370. + (head)->cqh_last = (elm); \
  60371. + else \
  60372. + (head)->cqh_first->field.cqe_prev = (elm); \
  60373. + (head)->cqh_first = (elm); \
  60374. +} while (0)
  60375. +
  60376. +#define DWC_CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  60377. + (elm)->field.cqe_next = DWC_CIRCLEQ_END(head); \
  60378. + (elm)->field.cqe_prev = (head)->cqh_last; \
  60379. + if ((head)->cqh_first == DWC_CIRCLEQ_END(head)) \
  60380. + (head)->cqh_first = (elm); \
  60381. + else \
  60382. + (head)->cqh_last->field.cqe_next = (elm); \
  60383. + (head)->cqh_last = (elm); \
  60384. +} while (0)
  60385. +
  60386. +#define DWC_CIRCLEQ_REMOVE(head, elm, field) do { \
  60387. + if ((elm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  60388. + (head)->cqh_last = (elm)->field.cqe_prev; \
  60389. + else \
  60390. + (elm)->field.cqe_next->field.cqe_prev = \
  60391. + (elm)->field.cqe_prev; \
  60392. + if ((elm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  60393. + (head)->cqh_first = (elm)->field.cqe_next; \
  60394. + else \
  60395. + (elm)->field.cqe_prev->field.cqe_next = \
  60396. + (elm)->field.cqe_next; \
  60397. +} while (0)
  60398. +
  60399. +#define DWC_CIRCLEQ_REMOVE_INIT(head, elm, field) do { \
  60400. + DWC_CIRCLEQ_REMOVE(head, elm, field); \
  60401. + DWC_CIRCLEQ_INIT_ENTRY(elm, field); \
  60402. +} while (0)
  60403. +
  60404. +#define DWC_CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
  60405. + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
  60406. + DWC_CIRCLEQ_END(head)) \
  60407. + (head).cqh_last = (elm2); \
  60408. + else \
  60409. + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
  60410. + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
  60411. + DWC_CIRCLEQ_END(head)) \
  60412. + (head).cqh_first = (elm2); \
  60413. + else \
  60414. + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
  60415. +} while (0)
  60416. +
  60417. +#ifdef __cplusplus
  60418. +}
  60419. +#endif
  60420. +
  60421. +#endif /* _DWC_LIST_H_ */
  60422. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_mem.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_mem.c
  60423. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_mem.c 1970-01-01 01:00:00.000000000 +0100
  60424. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_mem.c 2015-02-09 04:40:28.000000000 +0100
  60425. @@ -0,0 +1,245 @@
  60426. +/* Memory Debugging */
  60427. +#ifdef DWC_DEBUG_MEMORY
  60428. +
  60429. +#include "dwc_os.h"
  60430. +#include "dwc_list.h"
  60431. +
  60432. +struct allocation {
  60433. + void *addr;
  60434. + void *ctx;
  60435. + char *func;
  60436. + int line;
  60437. + uint32_t size;
  60438. + int dma;
  60439. + DWC_CIRCLEQ_ENTRY(allocation) entry;
  60440. +};
  60441. +
  60442. +DWC_CIRCLEQ_HEAD(allocation_queue, allocation);
  60443. +
  60444. +struct allocation_manager {
  60445. + void *mem_ctx;
  60446. + struct allocation_queue allocations;
  60447. +
  60448. + /* statistics */
  60449. + int num;
  60450. + int num_freed;
  60451. + int num_active;
  60452. + uint32_t total;
  60453. + uint32_t cur;
  60454. + uint32_t max;
  60455. +};
  60456. +
  60457. +static struct allocation_manager *manager = NULL;
  60458. +
  60459. +static int add_allocation(void *ctx, uint32_t size, char const *func, int line, void *addr,
  60460. + int dma)
  60461. +{
  60462. + struct allocation *a;
  60463. +
  60464. + DWC_ASSERT(manager != NULL, "manager not allocated");
  60465. +
  60466. + a = __DWC_ALLOC_ATOMIC(manager->mem_ctx, sizeof(*a));
  60467. + if (!a) {
  60468. + return -DWC_E_NO_MEMORY;
  60469. + }
  60470. +
  60471. + a->func = __DWC_ALLOC_ATOMIC(manager->mem_ctx, DWC_STRLEN(func) + 1);
  60472. + if (!a->func) {
  60473. + __DWC_FREE(manager->mem_ctx, a);
  60474. + return -DWC_E_NO_MEMORY;
  60475. + }
  60476. +
  60477. + DWC_MEMCPY(a->func, func, DWC_STRLEN(func) + 1);
  60478. + a->addr = addr;
  60479. + a->ctx = ctx;
  60480. + a->line = line;
  60481. + a->size = size;
  60482. + a->dma = dma;
  60483. + DWC_CIRCLEQ_INSERT_TAIL(&manager->allocations, a, entry);
  60484. +
  60485. + /* Update stats */
  60486. + manager->num++;
  60487. + manager->num_active++;
  60488. + manager->total += size;
  60489. + manager->cur += size;
  60490. +
  60491. + if (manager->max < manager->cur) {
  60492. + manager->max = manager->cur;
  60493. + }
  60494. +
  60495. + return 0;
  60496. +}
  60497. +
  60498. +static struct allocation *find_allocation(void *ctx, void *addr)
  60499. +{
  60500. + struct allocation *a;
  60501. +
  60502. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  60503. + if (a->ctx == ctx && a->addr == addr) {
  60504. + return a;
  60505. + }
  60506. + }
  60507. +
  60508. + return NULL;
  60509. +}
  60510. +
  60511. +static void free_allocation(void *ctx, void *addr, char const *func, int line)
  60512. +{
  60513. + struct allocation *a = find_allocation(ctx, addr);
  60514. +
  60515. + if (!a) {
  60516. + DWC_ASSERT(0,
  60517. + "Free of address %p that was never allocated or already freed %s:%d",
  60518. + addr, func, line);
  60519. + return;
  60520. + }
  60521. +
  60522. + DWC_CIRCLEQ_REMOVE(&manager->allocations, a, entry);
  60523. +
  60524. + manager->num_active--;
  60525. + manager->num_freed++;
  60526. + manager->cur -= a->size;
  60527. + __DWC_FREE(manager->mem_ctx, a->func);
  60528. + __DWC_FREE(manager->mem_ctx, a);
  60529. +}
  60530. +
  60531. +int dwc_memory_debug_start(void *mem_ctx)
  60532. +{
  60533. + DWC_ASSERT(manager == NULL, "Memory debugging has already started\n");
  60534. +
  60535. + if (manager) {
  60536. + return -DWC_E_BUSY;
  60537. + }
  60538. +
  60539. + manager = __DWC_ALLOC(mem_ctx, sizeof(*manager));
  60540. + if (!manager) {
  60541. + return -DWC_E_NO_MEMORY;
  60542. + }
  60543. +
  60544. + DWC_CIRCLEQ_INIT(&manager->allocations);
  60545. + manager->mem_ctx = mem_ctx;
  60546. + manager->num = 0;
  60547. + manager->num_freed = 0;
  60548. + manager->num_active = 0;
  60549. + manager->total = 0;
  60550. + manager->cur = 0;
  60551. + manager->max = 0;
  60552. +
  60553. + return 0;
  60554. +}
  60555. +
  60556. +void dwc_memory_debug_stop(void)
  60557. +{
  60558. + struct allocation *a;
  60559. +
  60560. + dwc_memory_debug_report();
  60561. +
  60562. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  60563. + DWC_ERROR("Memory leaked from %s:%d\n", a->func, a->line);
  60564. + free_allocation(a->ctx, a->addr, NULL, -1);
  60565. + }
  60566. +
  60567. + __DWC_FREE(manager->mem_ctx, manager);
  60568. +}
  60569. +
  60570. +void dwc_memory_debug_report(void)
  60571. +{
  60572. + struct allocation *a;
  60573. +
  60574. + DWC_PRINTF("\n\n\n----------------- Memory Debugging Report -----------------\n\n");
  60575. + DWC_PRINTF("Num Allocations = %d\n", manager->num);
  60576. + DWC_PRINTF("Freed = %d\n", manager->num_freed);
  60577. + DWC_PRINTF("Active = %d\n", manager->num_active);
  60578. + DWC_PRINTF("Current Memory Used = %d\n", manager->cur);
  60579. + DWC_PRINTF("Total Memory Used = %d\n", manager->total);
  60580. + DWC_PRINTF("Maximum Memory Used at Once = %d\n", manager->max);
  60581. + DWC_PRINTF("Unfreed allocations:\n");
  60582. +
  60583. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  60584. + DWC_PRINTF(" addr=%p, size=%d from %s:%d, DMA=%d\n",
  60585. + a->addr, a->size, a->func, a->line, a->dma);
  60586. + }
  60587. +}
  60588. +
  60589. +/* The replacement functions */
  60590. +void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line)
  60591. +{
  60592. + void *addr = __DWC_ALLOC(mem_ctx, size);
  60593. +
  60594. + if (!addr) {
  60595. + return NULL;
  60596. + }
  60597. +
  60598. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  60599. + __DWC_FREE(mem_ctx, addr);
  60600. + return NULL;
  60601. + }
  60602. +
  60603. + return addr;
  60604. +}
  60605. +
  60606. +void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func,
  60607. + int line)
  60608. +{
  60609. + void *addr = __DWC_ALLOC_ATOMIC(mem_ctx, size);
  60610. +
  60611. + if (!addr) {
  60612. + return NULL;
  60613. + }
  60614. +
  60615. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  60616. + __DWC_FREE(mem_ctx, addr);
  60617. + return NULL;
  60618. + }
  60619. +
  60620. + return addr;
  60621. +}
  60622. +
  60623. +void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line)
  60624. +{
  60625. + free_allocation(mem_ctx, addr, func, line);
  60626. + __DWC_FREE(mem_ctx, addr);
  60627. +}
  60628. +
  60629. +void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  60630. + char const *func, int line)
  60631. +{
  60632. + void *addr = __DWC_DMA_ALLOC(dma_ctx, size, dma_addr);
  60633. +
  60634. + if (!addr) {
  60635. + return NULL;
  60636. + }
  60637. +
  60638. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  60639. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  60640. + return NULL;
  60641. + }
  60642. +
  60643. + return addr;
  60644. +}
  60645. +
  60646. +void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size,
  60647. + dwc_dma_t *dma_addr, char const *func, int line)
  60648. +{
  60649. + void *addr = __DWC_DMA_ALLOC_ATOMIC(dma_ctx, size, dma_addr);
  60650. +
  60651. + if (!addr) {
  60652. + return NULL;
  60653. + }
  60654. +
  60655. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  60656. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  60657. + return NULL;
  60658. + }
  60659. +
  60660. + return addr;
  60661. +}
  60662. +
  60663. +void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  60664. + dwc_dma_t dma_addr, char const *func, int line)
  60665. +{
  60666. + free_allocation(dma_ctx, virt_addr, func, line);
  60667. + __DWC_DMA_FREE(dma_ctx, size, virt_addr, dma_addr);
  60668. +}
  60669. +
  60670. +#endif /* DWC_DEBUG_MEMORY */
  60671. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_modpow.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.c
  60672. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_modpow.c 1970-01-01 01:00:00.000000000 +0100
  60673. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.c 2015-02-09 04:40:28.000000000 +0100
  60674. @@ -0,0 +1,636 @@
  60675. +/* Bignum routines adapted from PUTTY sources. PuTTY copyright notice follows.
  60676. + *
  60677. + * PuTTY is copyright 1997-2007 Simon Tatham.
  60678. + *
  60679. + * Portions copyright Robert de Bath, Joris van Rantwijk, Delian
  60680. + * Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry,
  60681. + * Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus
  60682. + * Kuhn, and CORE SDI S.A.
  60683. + *
  60684. + * Permission is hereby granted, free of charge, to any person
  60685. + * obtaining a copy of this software and associated documentation files
  60686. + * (the "Software"), to deal in the Software without restriction,
  60687. + * including without limitation the rights to use, copy, modify, merge,
  60688. + * publish, distribute, sublicense, and/or sell copies of the Software,
  60689. + * and to permit persons to whom the Software is furnished to do so,
  60690. + * subject to the following conditions:
  60691. + *
  60692. + * The above copyright notice and this permission notice shall be
  60693. + * included in all copies or substantial portions of the Software.
  60694. +
  60695. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  60696. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  60697. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  60698. + * NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
  60699. + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  60700. + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  60701. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  60702. + *
  60703. + */
  60704. +#ifdef DWC_CRYPTOLIB
  60705. +
  60706. +#ifndef CONFIG_MACH_IPMATE
  60707. +
  60708. +#include "dwc_modpow.h"
  60709. +
  60710. +#define BIGNUM_INT_MASK 0xFFFFFFFFUL
  60711. +#define BIGNUM_TOP_BIT 0x80000000UL
  60712. +#define BIGNUM_INT_BITS 32
  60713. +
  60714. +
  60715. +static void *snmalloc(void *mem_ctx, size_t n, size_t size)
  60716. +{
  60717. + void *p;
  60718. + size *= n;
  60719. + if (size == 0) size = 1;
  60720. + p = dwc_alloc(mem_ctx, size);
  60721. + return p;
  60722. +}
  60723. +
  60724. +#define snewn(ctx, n, type) ((type *)snmalloc((ctx), (n), sizeof(type)))
  60725. +#define sfree dwc_free
  60726. +
  60727. +/*
  60728. + * Usage notes:
  60729. + * * Do not call the DIVMOD_WORD macro with expressions such as array
  60730. + * subscripts, as some implementations object to this (see below).
  60731. + * * Note that none of the division methods below will cope if the
  60732. + * quotient won't fit into BIGNUM_INT_BITS. Callers should be careful
  60733. + * to avoid this case.
  60734. + * If this condition occurs, in the case of the x86 DIV instruction,
  60735. + * an overflow exception will occur, which (according to a correspondent)
  60736. + * will manifest on Windows as something like
  60737. + * 0xC0000095: Integer overflow
  60738. + * The C variant won't give the right answer, either.
  60739. + */
  60740. +
  60741. +#define MUL_WORD(w1, w2) ((BignumDblInt)w1 * w2)
  60742. +
  60743. +#if defined __GNUC__ && defined __i386__
  60744. +#define DIVMOD_WORD(q, r, hi, lo, w) \
  60745. + __asm__("div %2" : \
  60746. + "=d" (r), "=a" (q) : \
  60747. + "r" (w), "d" (hi), "a" (lo))
  60748. +#else
  60749. +#define DIVMOD_WORD(q, r, hi, lo, w) do { \
  60750. + BignumDblInt n = (((BignumDblInt)hi) << BIGNUM_INT_BITS) | lo; \
  60751. + q = n / w; \
  60752. + r = n % w; \
  60753. +} while (0)
  60754. +#endif
  60755. +
  60756. +// q = n / w;
  60757. +// r = n % w;
  60758. +
  60759. +#define BIGNUM_INT_BYTES (BIGNUM_INT_BITS / 8)
  60760. +
  60761. +#define BIGNUM_INTERNAL
  60762. +
  60763. +static Bignum newbn(void *mem_ctx, int length)
  60764. +{
  60765. + Bignum b = snewn(mem_ctx, length + 1, BignumInt);
  60766. + //if (!b)
  60767. + //abort(); /* FIXME */
  60768. + DWC_MEMSET(b, 0, (length + 1) * sizeof(*b));
  60769. + b[0] = length;
  60770. + return b;
  60771. +}
  60772. +
  60773. +void freebn(void *mem_ctx, Bignum b)
  60774. +{
  60775. + /*
  60776. + * Burn the evidence, just in case.
  60777. + */
  60778. + DWC_MEMSET(b, 0, sizeof(b[0]) * (b[0] + 1));
  60779. + sfree(mem_ctx, b);
  60780. +}
  60781. +
  60782. +/*
  60783. + * Compute c = a * b.
  60784. + * Input is in the first len words of a and b.
  60785. + * Result is returned in the first 2*len words of c.
  60786. + */
  60787. +static void internal_mul(BignumInt *a, BignumInt *b,
  60788. + BignumInt *c, int len)
  60789. +{
  60790. + int i, j;
  60791. + BignumDblInt t;
  60792. +
  60793. + for (j = 0; j < 2 * len; j++)
  60794. + c[j] = 0;
  60795. +
  60796. + for (i = len - 1; i >= 0; i--) {
  60797. + t = 0;
  60798. + for (j = len - 1; j >= 0; j--) {
  60799. + t += MUL_WORD(a[i], (BignumDblInt) b[j]);
  60800. + t += (BignumDblInt) c[i + j + 1];
  60801. + c[i + j + 1] = (BignumInt) t;
  60802. + t = t >> BIGNUM_INT_BITS;
  60803. + }
  60804. + c[i] = (BignumInt) t;
  60805. + }
  60806. +}
  60807. +
  60808. +static void internal_add_shifted(BignumInt *number,
  60809. + unsigned n, int shift)
  60810. +{
  60811. + int word = 1 + (shift / BIGNUM_INT_BITS);
  60812. + int bshift = shift % BIGNUM_INT_BITS;
  60813. + BignumDblInt addend;
  60814. +
  60815. + addend = (BignumDblInt)n << bshift;
  60816. +
  60817. + while (addend) {
  60818. + addend += number[word];
  60819. + number[word] = (BignumInt) addend & BIGNUM_INT_MASK;
  60820. + addend >>= BIGNUM_INT_BITS;
  60821. + word++;
  60822. + }
  60823. +}
  60824. +
  60825. +/*
  60826. + * Compute a = a % m.
  60827. + * Input in first alen words of a and first mlen words of m.
  60828. + * Output in first alen words of a
  60829. + * (of which first alen-mlen words will be zero).
  60830. + * The MSW of m MUST have its high bit set.
  60831. + * Quotient is accumulated in the `quotient' array, which is a Bignum
  60832. + * rather than the internal bigendian format. Quotient parts are shifted
  60833. + * left by `qshift' before adding into quot.
  60834. + */
  60835. +static void internal_mod(BignumInt *a, int alen,
  60836. + BignumInt *m, int mlen,
  60837. + BignumInt *quot, int qshift)
  60838. +{
  60839. + BignumInt m0, m1;
  60840. + unsigned int h;
  60841. + int i, k;
  60842. +
  60843. + m0 = m[0];
  60844. + if (mlen > 1)
  60845. + m1 = m[1];
  60846. + else
  60847. + m1 = 0;
  60848. +
  60849. + for (i = 0; i <= alen - mlen; i++) {
  60850. + BignumDblInt t;
  60851. + unsigned int q, r, c, ai1;
  60852. +
  60853. + if (i == 0) {
  60854. + h = 0;
  60855. + } else {
  60856. + h = a[i - 1];
  60857. + a[i - 1] = 0;
  60858. + }
  60859. +
  60860. + if (i == alen - 1)
  60861. + ai1 = 0;
  60862. + else
  60863. + ai1 = a[i + 1];
  60864. +
  60865. + /* Find q = h:a[i] / m0 */
  60866. + if (h >= m0) {
  60867. + /*
  60868. + * Special case.
  60869. + *
  60870. + * To illustrate it, suppose a BignumInt is 8 bits, and
  60871. + * we are dividing (say) A1:23:45:67 by A1:B2:C3. Then
  60872. + * our initial division will be 0xA123 / 0xA1, which
  60873. + * will give a quotient of 0x100 and a divide overflow.
  60874. + * However, the invariants in this division algorithm
  60875. + * are not violated, since the full number A1:23:... is
  60876. + * _less_ than the quotient prefix A1:B2:... and so the
  60877. + * following correction loop would have sorted it out.
  60878. + *
  60879. + * In this situation we set q to be the largest
  60880. + * quotient we _can_ stomach (0xFF, of course).
  60881. + */
  60882. + q = BIGNUM_INT_MASK;
  60883. + } else {
  60884. + /* Macro doesn't want an array subscript expression passed
  60885. + * into it (see definition), so use a temporary. */
  60886. + BignumInt tmplo = a[i];
  60887. + DIVMOD_WORD(q, r, h, tmplo, m0);
  60888. +
  60889. + /* Refine our estimate of q by looking at
  60890. + h:a[i]:a[i+1] / m0:m1 */
  60891. + t = MUL_WORD(m1, q);
  60892. + if (t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) {
  60893. + q--;
  60894. + t -= m1;
  60895. + r = (r + m0) & BIGNUM_INT_MASK; /* overflow? */
  60896. + if (r >= (BignumDblInt) m0 &&
  60897. + t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) q--;
  60898. + }
  60899. + }
  60900. +
  60901. + /* Subtract q * m from a[i...] */
  60902. + c = 0;
  60903. + for (k = mlen - 1; k >= 0; k--) {
  60904. + t = MUL_WORD(q, m[k]);
  60905. + t += c;
  60906. + c = (unsigned)(t >> BIGNUM_INT_BITS);
  60907. + if ((BignumInt) t > a[i + k])
  60908. + c++;
  60909. + a[i + k] -= (BignumInt) t;
  60910. + }
  60911. +
  60912. + /* Add back m in case of borrow */
  60913. + if (c != h) {
  60914. + t = 0;
  60915. + for (k = mlen - 1; k >= 0; k--) {
  60916. + t += m[k];
  60917. + t += a[i + k];
  60918. + a[i + k] = (BignumInt) t;
  60919. + t = t >> BIGNUM_INT_BITS;
  60920. + }
  60921. + q--;
  60922. + }
  60923. + if (quot)
  60924. + internal_add_shifted(quot, q, qshift + BIGNUM_INT_BITS * (alen - mlen - i));
  60925. + }
  60926. +}
  60927. +
  60928. +/*
  60929. + * Compute p % mod.
  60930. + * The most significant word of mod MUST be non-zero.
  60931. + * We assume that the result array is the same size as the mod array.
  60932. + * We optionally write out a quotient if `quotient' is non-NULL.
  60933. + * We can avoid writing out the result if `result' is NULL.
  60934. + */
  60935. +void bigdivmod(void *mem_ctx, Bignum p, Bignum mod, Bignum result, Bignum quotient)
  60936. +{
  60937. + BignumInt *n, *m;
  60938. + int mshift;
  60939. + int plen, mlen, i, j;
  60940. +
  60941. + /* Allocate m of size mlen, copy mod to m */
  60942. + /* We use big endian internally */
  60943. + mlen = mod[0];
  60944. + m = snewn(mem_ctx, mlen, BignumInt);
  60945. + //if (!m)
  60946. + //abort(); /* FIXME */
  60947. + for (j = 0; j < mlen; j++)
  60948. + m[j] = mod[mod[0] - j];
  60949. +
  60950. + /* Shift m left to make msb bit set */
  60951. + for (mshift = 0; mshift < BIGNUM_INT_BITS-1; mshift++)
  60952. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  60953. + break;
  60954. + if (mshift) {
  60955. + for (i = 0; i < mlen - 1; i++)
  60956. + m[i] = (m[i] << mshift) | (m[i + 1] >> (BIGNUM_INT_BITS - mshift));
  60957. + m[mlen - 1] = m[mlen - 1] << mshift;
  60958. + }
  60959. +
  60960. + plen = p[0];
  60961. + /* Ensure plen > mlen */
  60962. + if (plen <= mlen)
  60963. + plen = mlen + 1;
  60964. +
  60965. + /* Allocate n of size plen, copy p to n */
  60966. + n = snewn(mem_ctx, plen, BignumInt);
  60967. + //if (!n)
  60968. + //abort(); /* FIXME */
  60969. + for (j = 0; j < plen; j++)
  60970. + n[j] = 0;
  60971. + for (j = 1; j <= (int)p[0]; j++)
  60972. + n[plen - j] = p[j];
  60973. +
  60974. + /* Main computation */
  60975. + internal_mod(n, plen, m, mlen, quotient, mshift);
  60976. +
  60977. + /* Fixup result in case the modulus was shifted */
  60978. + if (mshift) {
  60979. + for (i = plen - mlen - 1; i < plen - 1; i++)
  60980. + n[i] = (n[i] << mshift) | (n[i + 1] >> (BIGNUM_INT_BITS - mshift));
  60981. + n[plen - 1] = n[plen - 1] << mshift;
  60982. + internal_mod(n, plen, m, mlen, quotient, 0);
  60983. + for (i = plen - 1; i >= plen - mlen; i--)
  60984. + n[i] = (n[i] >> mshift) | (n[i - 1] << (BIGNUM_INT_BITS - mshift));
  60985. + }
  60986. +
  60987. + /* Copy result to buffer */
  60988. + if (result) {
  60989. + for (i = 1; i <= (int)result[0]; i++) {
  60990. + int j = plen - i;
  60991. + result[i] = j >= 0 ? n[j] : 0;
  60992. + }
  60993. + }
  60994. +
  60995. + /* Free temporary arrays */
  60996. + for (i = 0; i < mlen; i++)
  60997. + m[i] = 0;
  60998. + sfree(mem_ctx, m);
  60999. + for (i = 0; i < plen; i++)
  61000. + n[i] = 0;
  61001. + sfree(mem_ctx, n);
  61002. +}
  61003. +
  61004. +/*
  61005. + * Simple remainder.
  61006. + */
  61007. +Bignum bigmod(void *mem_ctx, Bignum a, Bignum b)
  61008. +{
  61009. + Bignum r = newbn(mem_ctx, b[0]);
  61010. + bigdivmod(mem_ctx, a, b, r, NULL);
  61011. + return r;
  61012. +}
  61013. +
  61014. +/*
  61015. + * Compute (base ^ exp) % mod.
  61016. + */
  61017. +Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod)
  61018. +{
  61019. + BignumInt *a, *b, *n, *m;
  61020. + int mshift;
  61021. + int mlen, i, j;
  61022. + Bignum base, result;
  61023. +
  61024. + /*
  61025. + * The most significant word of mod needs to be non-zero. It
  61026. + * should already be, but let's make sure.
  61027. + */
  61028. + //assert(mod[mod[0]] != 0);
  61029. +
  61030. + /*
  61031. + * Make sure the base is smaller than the modulus, by reducing
  61032. + * it modulo the modulus if not.
  61033. + */
  61034. + base = bigmod(mem_ctx, base_in, mod);
  61035. +
  61036. + /* Allocate m of size mlen, copy mod to m */
  61037. + /* We use big endian internally */
  61038. + mlen = mod[0];
  61039. + m = snewn(mem_ctx, mlen, BignumInt);
  61040. + //if (!m)
  61041. + //abort(); /* FIXME */
  61042. + for (j = 0; j < mlen; j++)
  61043. + m[j] = mod[mod[0] - j];
  61044. +
  61045. + /* Shift m left to make msb bit set */
  61046. + for (mshift = 0; mshift < BIGNUM_INT_BITS - 1; mshift++)
  61047. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  61048. + break;
  61049. + if (mshift) {
  61050. + for (i = 0; i < mlen - 1; i++)
  61051. + m[i] =
  61052. + (m[i] << mshift) | (m[i + 1] >>
  61053. + (BIGNUM_INT_BITS - mshift));
  61054. + m[mlen - 1] = m[mlen - 1] << mshift;
  61055. + }
  61056. +
  61057. + /* Allocate n of size mlen, copy base to n */
  61058. + n = snewn(mem_ctx, mlen, BignumInt);
  61059. + //if (!n)
  61060. + //abort(); /* FIXME */
  61061. + i = mlen - base[0];
  61062. + for (j = 0; j < i; j++)
  61063. + n[j] = 0;
  61064. + for (j = 0; j < base[0]; j++)
  61065. + n[i + j] = base[base[0] - j];
  61066. +
  61067. + /* Allocate a and b of size 2*mlen. Set a = 1 */
  61068. + a = snewn(mem_ctx, 2 * mlen, BignumInt);
  61069. + //if (!a)
  61070. + //abort(); /* FIXME */
  61071. + b = snewn(mem_ctx, 2 * mlen, BignumInt);
  61072. + //if (!b)
  61073. + //abort(); /* FIXME */
  61074. + for (i = 0; i < 2 * mlen; i++)
  61075. + a[i] = 0;
  61076. + a[2 * mlen - 1] = 1;
  61077. +
  61078. + /* Skip leading zero bits of exp. */
  61079. + i = 0;
  61080. + j = BIGNUM_INT_BITS - 1;
  61081. + while (i < exp[0] && (exp[exp[0] - i] & (1 << j)) == 0) {
  61082. + j--;
  61083. + if (j < 0) {
  61084. + i++;
  61085. + j = BIGNUM_INT_BITS - 1;
  61086. + }
  61087. + }
  61088. +
  61089. + /* Main computation */
  61090. + while (i < exp[0]) {
  61091. + while (j >= 0) {
  61092. + internal_mul(a + mlen, a + mlen, b, mlen);
  61093. + internal_mod(b, mlen * 2, m, mlen, NULL, 0);
  61094. + if ((exp[exp[0] - i] & (1 << j)) != 0) {
  61095. + internal_mul(b + mlen, n, a, mlen);
  61096. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  61097. + } else {
  61098. + BignumInt *t;
  61099. + t = a;
  61100. + a = b;
  61101. + b = t;
  61102. + }
  61103. + j--;
  61104. + }
  61105. + i++;
  61106. + j = BIGNUM_INT_BITS - 1;
  61107. + }
  61108. +
  61109. + /* Fixup result in case the modulus was shifted */
  61110. + if (mshift) {
  61111. + for (i = mlen - 1; i < 2 * mlen - 1; i++)
  61112. + a[i] =
  61113. + (a[i] << mshift) | (a[i + 1] >>
  61114. + (BIGNUM_INT_BITS - mshift));
  61115. + a[2 * mlen - 1] = a[2 * mlen - 1] << mshift;
  61116. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  61117. + for (i = 2 * mlen - 1; i >= mlen; i--)
  61118. + a[i] =
  61119. + (a[i] >> mshift) | (a[i - 1] <<
  61120. + (BIGNUM_INT_BITS - mshift));
  61121. + }
  61122. +
  61123. + /* Copy result to buffer */
  61124. + result = newbn(mem_ctx, mod[0]);
  61125. + for (i = 0; i < mlen; i++)
  61126. + result[result[0] - i] = a[i + mlen];
  61127. + while (result[0] > 1 && result[result[0]] == 0)
  61128. + result[0]--;
  61129. +
  61130. + /* Free temporary arrays */
  61131. + for (i = 0; i < 2 * mlen; i++)
  61132. + a[i] = 0;
  61133. + sfree(mem_ctx, a);
  61134. + for (i = 0; i < 2 * mlen; i++)
  61135. + b[i] = 0;
  61136. + sfree(mem_ctx, b);
  61137. + for (i = 0; i < mlen; i++)
  61138. + m[i] = 0;
  61139. + sfree(mem_ctx, m);
  61140. + for (i = 0; i < mlen; i++)
  61141. + n[i] = 0;
  61142. + sfree(mem_ctx, n);
  61143. +
  61144. + freebn(mem_ctx, base);
  61145. +
  61146. + return result;
  61147. +}
  61148. +
  61149. +
  61150. +#ifdef UNITTEST
  61151. +
  61152. +static __u32 dh_p[] = {
  61153. + 96,
  61154. + 0xFFFFFFFF,
  61155. + 0xFFFFFFFF,
  61156. + 0xA93AD2CA,
  61157. + 0x4B82D120,
  61158. + 0xE0FD108E,
  61159. + 0x43DB5BFC,
  61160. + 0x74E5AB31,
  61161. + 0x08E24FA0,
  61162. + 0xBAD946E2,
  61163. + 0x770988C0,
  61164. + 0x7A615D6C,
  61165. + 0xBBE11757,
  61166. + 0x177B200C,
  61167. + 0x521F2B18,
  61168. + 0x3EC86A64,
  61169. + 0xD8760273,
  61170. + 0xD98A0864,
  61171. + 0xF12FFA06,
  61172. + 0x1AD2EE6B,
  61173. + 0xCEE3D226,
  61174. + 0x4A25619D,
  61175. + 0x1E8C94E0,
  61176. + 0xDB0933D7,
  61177. + 0xABF5AE8C,
  61178. + 0xA6E1E4C7,
  61179. + 0xB3970F85,
  61180. + 0x5D060C7D,
  61181. + 0x8AEA7157,
  61182. + 0x58DBEF0A,
  61183. + 0xECFB8504,
  61184. + 0xDF1CBA64,
  61185. + 0xA85521AB,
  61186. + 0x04507A33,
  61187. + 0xAD33170D,
  61188. + 0x8AAAC42D,
  61189. + 0x15728E5A,
  61190. + 0x98FA0510,
  61191. + 0x15D22618,
  61192. + 0xEA956AE5,
  61193. + 0x3995497C,
  61194. + 0x95581718,
  61195. + 0xDE2BCBF6,
  61196. + 0x6F4C52C9,
  61197. + 0xB5C55DF0,
  61198. + 0xEC07A28F,
  61199. + 0x9B2783A2,
  61200. + 0x180E8603,
  61201. + 0xE39E772C,
  61202. + 0x2E36CE3B,
  61203. + 0x32905E46,
  61204. + 0xCA18217C,
  61205. + 0xF1746C08,
  61206. + 0x4ABC9804,
  61207. + 0x670C354E,
  61208. + 0x7096966D,
  61209. + 0x9ED52907,
  61210. + 0x208552BB,
  61211. + 0x1C62F356,
  61212. + 0xDCA3AD96,
  61213. + 0x83655D23,
  61214. + 0xFD24CF5F,
  61215. + 0x69163FA8,
  61216. + 0x1C55D39A,
  61217. + 0x98DA4836,
  61218. + 0xA163BF05,
  61219. + 0xC2007CB8,
  61220. + 0xECE45B3D,
  61221. + 0x49286651,
  61222. + 0x7C4B1FE6,
  61223. + 0xAE9F2411,
  61224. + 0x5A899FA5,
  61225. + 0xEE386BFB,
  61226. + 0xF406B7ED,
  61227. + 0x0BFF5CB6,
  61228. + 0xA637ED6B,
  61229. + 0xF44C42E9,
  61230. + 0x625E7EC6,
  61231. + 0xE485B576,
  61232. + 0x6D51C245,
  61233. + 0x4FE1356D,
  61234. + 0xF25F1437,
  61235. + 0x302B0A6D,
  61236. + 0xCD3A431B,
  61237. + 0xEF9519B3,
  61238. + 0x8E3404DD,
  61239. + 0x514A0879,
  61240. + 0x3B139B22,
  61241. + 0x020BBEA6,
  61242. + 0x8A67CC74,
  61243. + 0x29024E08,
  61244. + 0x80DC1CD1,
  61245. + 0xC4C6628B,
  61246. + 0x2168C234,
  61247. + 0xC90FDAA2,
  61248. + 0xFFFFFFFF,
  61249. + 0xFFFFFFFF,
  61250. +};
  61251. +
  61252. +static __u32 dh_a[] = {
  61253. + 8,
  61254. + 0xdf367516,
  61255. + 0x86459caa,
  61256. + 0xe2d459a4,
  61257. + 0xd910dae0,
  61258. + 0x8a8b5e37,
  61259. + 0x67ab31c6,
  61260. + 0xf0b55ea9,
  61261. + 0x440051d6,
  61262. +};
  61263. +
  61264. +static __u32 dh_b[] = {
  61265. + 8,
  61266. + 0xded92656,
  61267. + 0xe07a048a,
  61268. + 0x6fa452cd,
  61269. + 0x2df89d30,
  61270. + 0xc75f1b0f,
  61271. + 0x8ce3578f,
  61272. + 0x7980a324,
  61273. + 0x5daec786,
  61274. +};
  61275. +
  61276. +static __u32 dh_g[] = {
  61277. + 1,
  61278. + 2,
  61279. +};
  61280. +
  61281. +int main(void)
  61282. +{
  61283. + int i;
  61284. + __u32 *k;
  61285. + k = dwc_modpow(NULL, dh_g, dh_a, dh_p);
  61286. +
  61287. + printf("\n\n");
  61288. + for (i=0; i<k[0]; i++) {
  61289. + __u32 word32 = k[k[0] - i];
  61290. + __u16 l = word32 & 0xffff;
  61291. + __u16 m = (word32 & 0xffff0000) >> 16;
  61292. + printf("%04x %04x ", m, l);
  61293. + if (!((i + 1)%13)) printf("\n");
  61294. + }
  61295. + printf("\n\n");
  61296. +
  61297. + if ((k[0] == 0x60) && (k[1] == 0x28e490e5) && (k[0x60] == 0x5a0d3d4e)) {
  61298. + printf("PASS\n\n");
  61299. + }
  61300. + else {
  61301. + printf("FAIL\n\n");
  61302. + }
  61303. +
  61304. +}
  61305. +
  61306. +#endif /* UNITTEST */
  61307. +
  61308. +#endif /* CONFIG_MACH_IPMATE */
  61309. +
  61310. +#endif /*DWC_CRYPTOLIB */
  61311. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_modpow.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.h
  61312. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_modpow.h 1970-01-01 01:00:00.000000000 +0100
  61313. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.h 2015-02-09 04:40:28.000000000 +0100
  61314. @@ -0,0 +1,34 @@
  61315. +/*
  61316. + * dwc_modpow.h
  61317. + * See dwc_modpow.c for license and changes
  61318. + */
  61319. +#ifndef _DWC_MODPOW_H
  61320. +#define _DWC_MODPOW_H
  61321. +
  61322. +#ifdef __cplusplus
  61323. +extern "C" {
  61324. +#endif
  61325. +
  61326. +#include "dwc_os.h"
  61327. +
  61328. +/** @file
  61329. + *
  61330. + * This file defines the module exponentiation function which is only used
  61331. + * internally by the DWC UWB modules for calculation of PKs during numeric
  61332. + * association. The routine is taken from the PUTTY, an open source terminal
  61333. + * emulator. The PUTTY License is preserved in the dwc_modpow.c file.
  61334. + *
  61335. + */
  61336. +
  61337. +typedef uint32_t BignumInt;
  61338. +typedef uint64_t BignumDblInt;
  61339. +typedef BignumInt *Bignum;
  61340. +
  61341. +/* Compute modular exponentiaion */
  61342. +extern Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod);
  61343. +
  61344. +#ifdef __cplusplus
  61345. +}
  61346. +#endif
  61347. +
  61348. +#endif /* _LINUX_BIGNUM_H */
  61349. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_notifier.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.c
  61350. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_notifier.c 1970-01-01 01:00:00.000000000 +0100
  61351. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.c 2015-02-09 04:40:28.000000000 +0100
  61352. @@ -0,0 +1,319 @@
  61353. +#ifdef DWC_NOTIFYLIB
  61354. +
  61355. +#include "dwc_notifier.h"
  61356. +#include "dwc_list.h"
  61357. +
  61358. +typedef struct dwc_observer {
  61359. + void *observer;
  61360. + dwc_notifier_callback_t callback;
  61361. + void *data;
  61362. + char *notification;
  61363. + DWC_CIRCLEQ_ENTRY(dwc_observer) list_entry;
  61364. +} observer_t;
  61365. +
  61366. +DWC_CIRCLEQ_HEAD(observer_queue, dwc_observer);
  61367. +
  61368. +typedef struct dwc_notifier {
  61369. + void *mem_ctx;
  61370. + void *object;
  61371. + struct observer_queue observers;
  61372. + DWC_CIRCLEQ_ENTRY(dwc_notifier) list_entry;
  61373. +} notifier_t;
  61374. +
  61375. +DWC_CIRCLEQ_HEAD(notifier_queue, dwc_notifier);
  61376. +
  61377. +typedef struct manager {
  61378. + void *mem_ctx;
  61379. + void *wkq_ctx;
  61380. + dwc_workq_t *wq;
  61381. +// dwc_mutex_t *mutex;
  61382. + struct notifier_queue notifiers;
  61383. +} manager_t;
  61384. +
  61385. +static manager_t *manager = NULL;
  61386. +
  61387. +static int create_manager(void *mem_ctx, void *wkq_ctx)
  61388. +{
  61389. + manager = dwc_alloc(mem_ctx, sizeof(manager_t));
  61390. + if (!manager) {
  61391. + return -DWC_E_NO_MEMORY;
  61392. + }
  61393. +
  61394. + DWC_CIRCLEQ_INIT(&manager->notifiers);
  61395. +
  61396. + manager->wq = dwc_workq_alloc(wkq_ctx, "DWC Notification WorkQ");
  61397. + if (!manager->wq) {
  61398. + return -DWC_E_NO_MEMORY;
  61399. + }
  61400. +
  61401. + return 0;
  61402. +}
  61403. +
  61404. +static void free_manager(void)
  61405. +{
  61406. + dwc_workq_free(manager->wq);
  61407. +
  61408. + /* All notifiers must have unregistered themselves before this module
  61409. + * can be removed. Hitting this assertion indicates a programmer
  61410. + * error. */
  61411. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&manager->notifiers),
  61412. + "Notification manager being freed before all notifiers have been removed");
  61413. + dwc_free(manager->mem_ctx, manager);
  61414. +}
  61415. +
  61416. +#ifdef DEBUG
  61417. +static void dump_manager(void)
  61418. +{
  61419. + notifier_t *n;
  61420. + observer_t *o;
  61421. +
  61422. + DWC_ASSERT(manager, "Notification manager not found");
  61423. +
  61424. + DWC_DEBUG("List of all notifiers and observers:\n");
  61425. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  61426. + DWC_DEBUG("Notifier %p has observers:\n", n->object);
  61427. + DWC_CIRCLEQ_FOREACH(o, &n->observers, list_entry) {
  61428. + DWC_DEBUG(" %p watching %s\n", o->observer, o->notification);
  61429. + }
  61430. + }
  61431. +}
  61432. +#else
  61433. +#define dump_manager(...)
  61434. +#endif
  61435. +
  61436. +static observer_t *alloc_observer(void *mem_ctx, void *observer, char *notification,
  61437. + dwc_notifier_callback_t callback, void *data)
  61438. +{
  61439. + observer_t *new_observer = dwc_alloc(mem_ctx, sizeof(observer_t));
  61440. +
  61441. + if (!new_observer) {
  61442. + return NULL;
  61443. + }
  61444. +
  61445. + DWC_CIRCLEQ_INIT_ENTRY(new_observer, list_entry);
  61446. + new_observer->observer = observer;
  61447. + new_observer->notification = notification;
  61448. + new_observer->callback = callback;
  61449. + new_observer->data = data;
  61450. + return new_observer;
  61451. +}
  61452. +
  61453. +static void free_observer(void *mem_ctx, observer_t *observer)
  61454. +{
  61455. + dwc_free(mem_ctx, observer);
  61456. +}
  61457. +
  61458. +static notifier_t *alloc_notifier(void *mem_ctx, void *object)
  61459. +{
  61460. + notifier_t *notifier;
  61461. +
  61462. + if (!object) {
  61463. + return NULL;
  61464. + }
  61465. +
  61466. + notifier = dwc_alloc(mem_ctx, sizeof(notifier_t));
  61467. + if (!notifier) {
  61468. + return NULL;
  61469. + }
  61470. +
  61471. + DWC_CIRCLEQ_INIT(&notifier->observers);
  61472. + DWC_CIRCLEQ_INIT_ENTRY(notifier, list_entry);
  61473. +
  61474. + notifier->mem_ctx = mem_ctx;
  61475. + notifier->object = object;
  61476. + return notifier;
  61477. +}
  61478. +
  61479. +static void free_notifier(notifier_t *notifier)
  61480. +{
  61481. + observer_t *observer;
  61482. +
  61483. + DWC_CIRCLEQ_FOREACH(observer, &notifier->observers, list_entry) {
  61484. + free_observer(notifier->mem_ctx, observer);
  61485. + }
  61486. +
  61487. + dwc_free(notifier->mem_ctx, notifier);
  61488. +}
  61489. +
  61490. +static notifier_t *find_notifier(void *object)
  61491. +{
  61492. + notifier_t *notifier;
  61493. +
  61494. + DWC_ASSERT(manager, "Notification manager not found");
  61495. +
  61496. + if (!object) {
  61497. + return NULL;
  61498. + }
  61499. +
  61500. + DWC_CIRCLEQ_FOREACH(notifier, &manager->notifiers, list_entry) {
  61501. + if (notifier->object == object) {
  61502. + return notifier;
  61503. + }
  61504. + }
  61505. +
  61506. + return NULL;
  61507. +}
  61508. +
  61509. +int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx)
  61510. +{
  61511. + return create_manager(mem_ctx, wkq_ctx);
  61512. +}
  61513. +
  61514. +void dwc_free_notification_manager(void)
  61515. +{
  61516. + free_manager();
  61517. +}
  61518. +
  61519. +dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object)
  61520. +{
  61521. + notifier_t *notifier;
  61522. +
  61523. + DWC_ASSERT(manager, "Notification manager not found");
  61524. +
  61525. + notifier = find_notifier(object);
  61526. + if (notifier) {
  61527. + DWC_ERROR("Notifier %p is already registered\n", object);
  61528. + return NULL;
  61529. + }
  61530. +
  61531. + notifier = alloc_notifier(mem_ctx, object);
  61532. + if (!notifier) {
  61533. + return NULL;
  61534. + }
  61535. +
  61536. + DWC_CIRCLEQ_INSERT_TAIL(&manager->notifiers, notifier, list_entry);
  61537. +
  61538. + DWC_INFO("Notifier %p registered", object);
  61539. + dump_manager();
  61540. +
  61541. + return notifier;
  61542. +}
  61543. +
  61544. +void dwc_unregister_notifier(dwc_notifier_t *notifier)
  61545. +{
  61546. + DWC_ASSERT(manager, "Notification manager not found");
  61547. +
  61548. + if (!DWC_CIRCLEQ_EMPTY(&notifier->observers)) {
  61549. + observer_t *o;
  61550. +
  61551. + DWC_ERROR("Notifier %p has active observers when removing\n", notifier->object);
  61552. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  61553. + DWC_DEBUGC(" %p watching %s\n", o->observer, o->notification);
  61554. + }
  61555. +
  61556. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&notifier->observers),
  61557. + "Notifier %p has active observers when removing", notifier);
  61558. + }
  61559. +
  61560. + DWC_CIRCLEQ_REMOVE_INIT(&manager->notifiers, notifier, list_entry);
  61561. + free_notifier(notifier);
  61562. +
  61563. + DWC_INFO("Notifier unregistered");
  61564. + dump_manager();
  61565. +}
  61566. +
  61567. +/* Add an observer to observe the notifier for a particular state, event, or notification. */
  61568. +int dwc_add_observer(void *observer, void *object, char *notification,
  61569. + dwc_notifier_callback_t callback, void *data)
  61570. +{
  61571. + notifier_t *notifier = find_notifier(object);
  61572. + observer_t *new_observer;
  61573. +
  61574. + if (!notifier) {
  61575. + DWC_ERROR("Notifier %p is not found when adding observer\n", object);
  61576. + return -DWC_E_INVALID;
  61577. + }
  61578. +
  61579. + new_observer = alloc_observer(notifier->mem_ctx, observer, notification, callback, data);
  61580. + if (!new_observer) {
  61581. + return -DWC_E_NO_MEMORY;
  61582. + }
  61583. +
  61584. + DWC_CIRCLEQ_INSERT_TAIL(&notifier->observers, new_observer, list_entry);
  61585. +
  61586. + DWC_INFO("Added observer %p to notifier %p observing notification %s, callback=%p, data=%p",
  61587. + observer, object, notification, callback, data);
  61588. +
  61589. + dump_manager();
  61590. + return 0;
  61591. +}
  61592. +
  61593. +int dwc_remove_observer(void *observer)
  61594. +{
  61595. + notifier_t *n;
  61596. +
  61597. + DWC_ASSERT(manager, "Notification manager not found");
  61598. +
  61599. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  61600. + observer_t *o;
  61601. + observer_t *o2;
  61602. +
  61603. + DWC_CIRCLEQ_FOREACH_SAFE(o, o2, &n->observers, list_entry) {
  61604. + if (o->observer == observer) {
  61605. + DWC_CIRCLEQ_REMOVE_INIT(&n->observers, o, list_entry);
  61606. + DWC_INFO("Removing observer %p from notifier %p watching notification %s:",
  61607. + o->observer, n->object, o->notification);
  61608. + free_observer(n->mem_ctx, o);
  61609. + }
  61610. + }
  61611. + }
  61612. +
  61613. + dump_manager();
  61614. + return 0;
  61615. +}
  61616. +
  61617. +typedef struct callback_data {
  61618. + void *mem_ctx;
  61619. + dwc_notifier_callback_t cb;
  61620. + void *observer;
  61621. + void *data;
  61622. + void *object;
  61623. + char *notification;
  61624. + void *notification_data;
  61625. +} cb_data_t;
  61626. +
  61627. +static void cb_task(void *data)
  61628. +{
  61629. + cb_data_t *cb = (cb_data_t *)data;
  61630. +
  61631. + cb->cb(cb->object, cb->notification, cb->observer, cb->notification_data, cb->data);
  61632. + dwc_free(cb->mem_ctx, cb);
  61633. +}
  61634. +
  61635. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data)
  61636. +{
  61637. + observer_t *o;
  61638. +
  61639. + DWC_ASSERT(manager, "Notification manager not found");
  61640. +
  61641. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  61642. + int len = DWC_STRLEN(notification);
  61643. +
  61644. + if (DWC_STRLEN(o->notification) != len) {
  61645. + continue;
  61646. + }
  61647. +
  61648. + if (DWC_STRNCMP(o->notification, notification, len) == 0) {
  61649. + cb_data_t *cb_data = dwc_alloc(notifier->mem_ctx, sizeof(cb_data_t));
  61650. +
  61651. + if (!cb_data) {
  61652. + DWC_ERROR("Failed to allocate callback data\n");
  61653. + return;
  61654. + }
  61655. +
  61656. + cb_data->mem_ctx = notifier->mem_ctx;
  61657. + cb_data->cb = o->callback;
  61658. + cb_data->observer = o->observer;
  61659. + cb_data->data = o->data;
  61660. + cb_data->object = notifier->object;
  61661. + cb_data->notification = notification;
  61662. + cb_data->notification_data = notification_data;
  61663. + DWC_DEBUGC("Observer found %p for notification %s\n", o->observer, notification);
  61664. + DWC_WORKQ_SCHEDULE(manager->wq, cb_task, cb_data,
  61665. + "Notify callback from %p for Notification %s, to observer %p",
  61666. + cb_data->object, notification, cb_data->observer);
  61667. + }
  61668. + }
  61669. +}
  61670. +
  61671. +#endif /* DWC_NOTIFYLIB */
  61672. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_notifier.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.h
  61673. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_notifier.h 1970-01-01 01:00:00.000000000 +0100
  61674. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.h 2015-02-09 04:40:28.000000000 +0100
  61675. @@ -0,0 +1,122 @@
  61676. +
  61677. +#ifndef __DWC_NOTIFIER_H__
  61678. +#define __DWC_NOTIFIER_H__
  61679. +
  61680. +#ifdef __cplusplus
  61681. +extern "C" {
  61682. +#endif
  61683. +
  61684. +#include "dwc_os.h"
  61685. +
  61686. +/** @file
  61687. + *
  61688. + * A simple implementation of the Observer pattern. Any "module" can
  61689. + * register as an observer or notifier. The notion of "module" is abstract and
  61690. + * can mean anything used to identify either an observer or notifier. Usually
  61691. + * it will be a pointer to a data structure which contains some state, ie an
  61692. + * object.
  61693. + *
  61694. + * Before any notifiers can be added, the global notification manager must be
  61695. + * brought up with dwc_alloc_notification_manager().
  61696. + * dwc_free_notification_manager() will bring it down and free all resources.
  61697. + * These would typically be called upon module load and unload. The
  61698. + * notification manager is a single global instance that handles all registered
  61699. + * observable modules and observers so this should be done only once.
  61700. + *
  61701. + * A module can be observable by using Notifications to publicize some general
  61702. + * information about it's state or operation. It does not care who listens, or
  61703. + * even if anyone listens, or what they do with the information. The observable
  61704. + * modules do not need to know any information about it's observers or their
  61705. + * interface, or their state or data.
  61706. + *
  61707. + * Any module can register to emit Notifications. It should publish a list of
  61708. + * notifications that it can emit and their behavior, such as when they will get
  61709. + * triggered, and what information will be provided to the observer. Then it
  61710. + * should register itself as an observable module. See dwc_register_notifier().
  61711. + *
  61712. + * Any module can observe any observable, registered module, provided it has a
  61713. + * handle to the other module and knows what notifications to observe. See
  61714. + * dwc_add_observer().
  61715. + *
  61716. + * A function of type dwc_notifier_callback_t is called whenever a notification
  61717. + * is triggered with one or more observers observing it. This function is
  61718. + * called in it's own process so it may sleep or block if needed. It is
  61719. + * guaranteed to be called sometime after the notification has occurred and will
  61720. + * be called once per each time the notification is triggered. It will NOT be
  61721. + * called in the same process context used to trigger the notification.
  61722. + *
  61723. + * @section Limitiations
  61724. + *
  61725. + * Keep in mind that Notifications that can be triggered in rapid sucession may
  61726. + * schedule too many processes too handle. Be aware of this limitation when
  61727. + * designing to use notifications, and only add notifications for appropriate
  61728. + * observable information.
  61729. + *
  61730. + * Also Notification callbacks are not synchronous. If you need to synchronize
  61731. + * the behavior between module/observer you must use other means. And perhaps
  61732. + * that will mean Notifications are not the proper solution.
  61733. + */
  61734. +
  61735. +struct dwc_notifier;
  61736. +typedef struct dwc_notifier dwc_notifier_t;
  61737. +
  61738. +/** The callback function must be of this type.
  61739. + *
  61740. + * @param object This is the object that is being observed.
  61741. + * @param notification This is the notification that was triggered.
  61742. + * @param observer This is the observer
  61743. + * @param notification_data This is notification-specific data that the notifier
  61744. + * has included in this notification. The value of this should be published in
  61745. + * the documentation of the observable module with the notifications.
  61746. + * @param user_data This is any custom data that the observer provided when
  61747. + * adding itself as an observer to the notification. */
  61748. +typedef void (*dwc_notifier_callback_t)(void *object, char *notification, void *observer,
  61749. + void *notification_data, void *user_data);
  61750. +
  61751. +/** Brings up the notification manager. */
  61752. +extern int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx);
  61753. +/** Brings down the notification manager. */
  61754. +extern void dwc_free_notification_manager(void);
  61755. +
  61756. +/** This function registers an observable module. A dwc_notifier_t object is
  61757. + * returned to the observable module. This is an opaque object that is used by
  61758. + * the observable module to trigger notifications. This object should only be
  61759. + * accessible to functions that are authorized to trigger notifications for this
  61760. + * module. Observers do not need this object. */
  61761. +extern dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object);
  61762. +
  61763. +/** This function unregisters an observable module. All observers have to be
  61764. + * removed prior to unregistration. */
  61765. +extern void dwc_unregister_notifier(dwc_notifier_t *notifier);
  61766. +
  61767. +/** Add a module as an observer to the observable module. The observable module
  61768. + * needs to have previously registered with the notification manager.
  61769. + *
  61770. + * @param observer The observer module
  61771. + * @param object The module to observe
  61772. + * @param notification The notification to observe
  61773. + * @param callback The callback function to call
  61774. + * @param user_data Any additional user data to pass into the callback function */
  61775. +extern int dwc_add_observer(void *observer, void *object, char *notification,
  61776. + dwc_notifier_callback_t callback, void *user_data);
  61777. +
  61778. +/** Removes the specified observer from all notifications that it is currently
  61779. + * observing. */
  61780. +extern int dwc_remove_observer(void *observer);
  61781. +
  61782. +/** This function triggers a Notification. It should be called by the
  61783. + * observable module, or any module or library which the observable module
  61784. + * allows to trigger notification on it's behalf. Such as the dwc_cc_t.
  61785. + *
  61786. + * dwc_notify is a non-blocking function. Callbacks are scheduled called in
  61787. + * their own process context for each trigger. Callbacks can be blocking.
  61788. + * dwc_notify can be called from interrupt context if needed.
  61789. + *
  61790. + */
  61791. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data);
  61792. +
  61793. +#ifdef __cplusplus
  61794. +}
  61795. +#endif
  61796. +
  61797. +#endif /* __DWC_NOTIFIER_H__ */
  61798. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_os.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_os.h
  61799. --- linux-3.18.6/drivers/usb/host/dwc_common_port/dwc_os.h 1970-01-01 01:00:00.000000000 +0100
  61800. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_os.h 2015-02-09 04:40:28.000000000 +0100
  61801. @@ -0,0 +1,1276 @@
  61802. +/* =========================================================================
  61803. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_os.h $
  61804. + * $Revision: #14 $
  61805. + * $Date: 2010/11/04 $
  61806. + * $Change: 1621695 $
  61807. + *
  61808. + * Synopsys Portability Library Software and documentation
  61809. + * (hereinafter, "Software") is an Unsupported proprietary work of
  61810. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  61811. + * between Synopsys and you.
  61812. + *
  61813. + * The Software IS NOT an item of Licensed Software or Licensed Product
  61814. + * under any End User Software License Agreement or Agreement for
  61815. + * Licensed Product with Synopsys or any supplement thereto. You are
  61816. + * permitted to use and redistribute this Software in source and binary
  61817. + * forms, with or without modification, provided that redistributions
  61818. + * of source code must retain this notice. You may not view, use,
  61819. + * disclose, copy or distribute this file or any information contained
  61820. + * herein except pursuant to this license grant from Synopsys. If you
  61821. + * do not agree with this notice, including the disclaimer below, then
  61822. + * you are not authorized to use the Software.
  61823. + *
  61824. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  61825. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  61826. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  61827. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  61828. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  61829. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  61830. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  61831. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  61832. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  61833. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  61834. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  61835. + * DAMAGE.
  61836. + * ========================================================================= */
  61837. +#ifndef _DWC_OS_H_
  61838. +#define _DWC_OS_H_
  61839. +
  61840. +#ifdef __cplusplus
  61841. +extern "C" {
  61842. +#endif
  61843. +
  61844. +/** @file
  61845. + *
  61846. + * DWC portability library, low level os-wrapper functions
  61847. + *
  61848. + */
  61849. +
  61850. +/* These basic types need to be defined by some OS header file or custom header
  61851. + * file for your specific target architecture.
  61852. + *
  61853. + * uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
  61854. + *
  61855. + * Any custom or alternate header file must be added and enabled here.
  61856. + */
  61857. +
  61858. +#ifdef DWC_LINUX
  61859. +# include <linux/types.h>
  61860. +# ifdef CONFIG_DEBUG_MUTEXES
  61861. +# include <linux/mutex.h>
  61862. +# endif
  61863. +# include <linux/spinlock.h>
  61864. +# include <linux/errno.h>
  61865. +# include <stdarg.h>
  61866. +#endif
  61867. +
  61868. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  61869. +# include <os_dep.h>
  61870. +#endif
  61871. +
  61872. +
  61873. +/** @name Primitive Types and Values */
  61874. +
  61875. +/** We define a boolean type for consistency. Can be either YES or NO */
  61876. +typedef uint8_t dwc_bool_t;
  61877. +#define YES 1
  61878. +#define NO 0
  61879. +
  61880. +#ifdef DWC_LINUX
  61881. +
  61882. +/** @name Error Codes */
  61883. +#define DWC_E_INVALID EINVAL
  61884. +#define DWC_E_NO_MEMORY ENOMEM
  61885. +#define DWC_E_NO_DEVICE ENODEV
  61886. +#define DWC_E_NOT_SUPPORTED EOPNOTSUPP
  61887. +#define DWC_E_TIMEOUT ETIMEDOUT
  61888. +#define DWC_E_BUSY EBUSY
  61889. +#define DWC_E_AGAIN EAGAIN
  61890. +#define DWC_E_RESTART ERESTART
  61891. +#define DWC_E_ABORT ECONNABORTED
  61892. +#define DWC_E_SHUTDOWN ESHUTDOWN
  61893. +#define DWC_E_NO_DATA ENODATA
  61894. +#define DWC_E_DISCONNECT ECONNRESET
  61895. +#define DWC_E_UNKNOWN EINVAL
  61896. +#define DWC_E_NO_STREAM_RES ENOSR
  61897. +#define DWC_E_COMMUNICATION ECOMM
  61898. +#define DWC_E_OVERFLOW EOVERFLOW
  61899. +#define DWC_E_PROTOCOL EPROTO
  61900. +#define DWC_E_IN_PROGRESS EINPROGRESS
  61901. +#define DWC_E_PIPE EPIPE
  61902. +#define DWC_E_IO EIO
  61903. +#define DWC_E_NO_SPACE ENOSPC
  61904. +
  61905. +#else
  61906. +
  61907. +/** @name Error Codes */
  61908. +#define DWC_E_INVALID 1001
  61909. +#define DWC_E_NO_MEMORY 1002
  61910. +#define DWC_E_NO_DEVICE 1003
  61911. +#define DWC_E_NOT_SUPPORTED 1004
  61912. +#define DWC_E_TIMEOUT 1005
  61913. +#define DWC_E_BUSY 1006
  61914. +#define DWC_E_AGAIN 1007
  61915. +#define DWC_E_RESTART 1008
  61916. +#define DWC_E_ABORT 1009
  61917. +#define DWC_E_SHUTDOWN 1010
  61918. +#define DWC_E_NO_DATA 1011
  61919. +#define DWC_E_DISCONNECT 2000
  61920. +#define DWC_E_UNKNOWN 3000
  61921. +#define DWC_E_NO_STREAM_RES 4001
  61922. +#define DWC_E_COMMUNICATION 4002
  61923. +#define DWC_E_OVERFLOW 4003
  61924. +#define DWC_E_PROTOCOL 4004
  61925. +#define DWC_E_IN_PROGRESS 4005
  61926. +#define DWC_E_PIPE 4006
  61927. +#define DWC_E_IO 4007
  61928. +#define DWC_E_NO_SPACE 4008
  61929. +
  61930. +#endif
  61931. +
  61932. +
  61933. +/** @name Tracing/Logging Functions
  61934. + *
  61935. + * These function provide the capability to add tracing, debugging, and error
  61936. + * messages, as well exceptions as assertions. The WUDEV uses these
  61937. + * extensively. These could be logged to the main console, the serial port, an
  61938. + * internal buffer, etc. These functions could also be no-op if they are too
  61939. + * expensive on your system. By default undefining the DEBUG macro already
  61940. + * no-ops some of these functions. */
  61941. +
  61942. +/** Returns non-zero if in interrupt context. */
  61943. +extern dwc_bool_t DWC_IN_IRQ(void);
  61944. +#define dwc_in_irq DWC_IN_IRQ
  61945. +
  61946. +/** Returns "IRQ" if DWC_IN_IRQ is true. */
  61947. +static inline char *dwc_irq(void) {
  61948. + return DWC_IN_IRQ() ? "IRQ" : "";
  61949. +}
  61950. +
  61951. +/** Returns non-zero if in bottom-half context. */
  61952. +extern dwc_bool_t DWC_IN_BH(void);
  61953. +#define dwc_in_bh DWC_IN_BH
  61954. +
  61955. +/** Returns "BH" if DWC_IN_BH is true. */
  61956. +static inline char *dwc_bh(void) {
  61957. + return DWC_IN_BH() ? "BH" : "";
  61958. +}
  61959. +
  61960. +/**
  61961. + * A vprintf() clone. Just call vprintf if you've got it.
  61962. + */
  61963. +extern void DWC_VPRINTF(char *format, va_list args);
  61964. +#define dwc_vprintf DWC_VPRINTF
  61965. +
  61966. +/**
  61967. + * A vsnprintf() clone. Just call vprintf if you've got it.
  61968. + */
  61969. +extern int DWC_VSNPRINTF(char *str, int size, char *format, va_list args);
  61970. +#define dwc_vsnprintf DWC_VSNPRINTF
  61971. +
  61972. +/**
  61973. + * printf() clone. Just call printf if you've go it.
  61974. + */
  61975. +extern void DWC_PRINTF(char *format, ...)
  61976. +/* This provides compiler level static checking of the parameters if you're
  61977. + * using GCC. */
  61978. +#ifdef __GNUC__
  61979. + __attribute__ ((format(printf, 1, 2)));
  61980. +#else
  61981. + ;
  61982. +#endif
  61983. +#define dwc_printf DWC_PRINTF
  61984. +
  61985. +/**
  61986. + * sprintf() clone. Just call sprintf if you've got it.
  61987. + */
  61988. +extern int DWC_SPRINTF(char *string, char *format, ...)
  61989. +#ifdef __GNUC__
  61990. + __attribute__ ((format(printf, 2, 3)));
  61991. +#else
  61992. + ;
  61993. +#endif
  61994. +#define dwc_sprintf DWC_SPRINTF
  61995. +
  61996. +/**
  61997. + * snprintf() clone. Just call snprintf if you've got it.
  61998. + */
  61999. +extern int DWC_SNPRINTF(char *string, int size, char *format, ...)
  62000. +#ifdef __GNUC__
  62001. + __attribute__ ((format(printf, 3, 4)));
  62002. +#else
  62003. + ;
  62004. +#endif
  62005. +#define dwc_snprintf DWC_SNPRINTF
  62006. +
  62007. +/**
  62008. + * Prints a WARNING message. On systems that don't differentiate between
  62009. + * warnings and regular log messages, just print it. Indicates that something
  62010. + * may be wrong with the driver. Works like printf().
  62011. + *
  62012. + * Use the DWC_WARN macro to call this function.
  62013. + */
  62014. +extern void __DWC_WARN(char *format, ...)
  62015. +#ifdef __GNUC__
  62016. + __attribute__ ((format(printf, 1, 2)));
  62017. +#else
  62018. + ;
  62019. +#endif
  62020. +
  62021. +/**
  62022. + * Prints an error message. On systems that don't differentiate between errors
  62023. + * and regular log messages, just print it. Indicates that something went wrong
  62024. + * with the driver. Works like printf().
  62025. + *
  62026. + * Use the DWC_ERROR macro to call this function.
  62027. + */
  62028. +extern void __DWC_ERROR(char *format, ...)
  62029. +#ifdef __GNUC__
  62030. + __attribute__ ((format(printf, 1, 2)));
  62031. +#else
  62032. + ;
  62033. +#endif
  62034. +
  62035. +/**
  62036. + * Prints an exception error message and takes some user-defined action such as
  62037. + * print out a backtrace or trigger a breakpoint. Indicates that something went
  62038. + * abnormally wrong with the driver such as programmer error, or other
  62039. + * exceptional condition. It should not be ignored so even on systems without
  62040. + * printing capability, some action should be taken to notify the developer of
  62041. + * it. Works like printf().
  62042. + */
  62043. +extern void DWC_EXCEPTION(char *format, ...)
  62044. +#ifdef __GNUC__
  62045. + __attribute__ ((format(printf, 1, 2)));
  62046. +#else
  62047. + ;
  62048. +#endif
  62049. +#define dwc_exception DWC_EXCEPTION
  62050. +
  62051. +#ifndef DWC_OTG_DEBUG_LEV
  62052. +#define DWC_OTG_DEBUG_LEV 0
  62053. +#endif
  62054. +
  62055. +#ifdef DEBUG
  62056. +/**
  62057. + * Prints out a debug message. Used for logging/trace messages.
  62058. + *
  62059. + * Use the DWC_DEBUG macro to call this function
  62060. + */
  62061. +extern void __DWC_DEBUG(char *format, ...)
  62062. +#ifdef __GNUC__
  62063. + __attribute__ ((format(printf, 1, 2)));
  62064. +#else
  62065. + ;
  62066. +#endif
  62067. +#else
  62068. +#define __DWC_DEBUG printk
  62069. +#endif
  62070. +
  62071. +/**
  62072. + * Prints out a Debug message.
  62073. + */
  62074. +#define DWC_DEBUG(_format, _args...) __DWC_DEBUG("DEBUG:%s:%s: " _format "\n", \
  62075. + __func__, dwc_irq(), ## _args)
  62076. +#define dwc_debug DWC_DEBUG
  62077. +/**
  62078. + * Prints out a Debug message if enabled at compile time.
  62079. + */
  62080. +#if DWC_OTG_DEBUG_LEV > 0
  62081. +#define DWC_DEBUGC(_format, _args...) DWC_DEBUG(_format, ##_args )
  62082. +#else
  62083. +#define DWC_DEBUGC(_format, _args...)
  62084. +#endif
  62085. +#define dwc_debugc DWC_DEBUGC
  62086. +/**
  62087. + * Prints out an informative message.
  62088. + */
  62089. +#define DWC_INFO(_format, _args...) DWC_PRINTF("INFO:%s: " _format "\n", \
  62090. + dwc_irq(), ## _args)
  62091. +#define dwc_info DWC_INFO
  62092. +/**
  62093. + * Prints out an informative message if enabled at compile time.
  62094. + */
  62095. +#if DWC_OTG_DEBUG_LEV > 1
  62096. +#define DWC_INFOC(_format, _args...) DWC_INFO(_format, ##_args )
  62097. +#else
  62098. +#define DWC_INFOC(_format, _args...)
  62099. +#endif
  62100. +#define dwc_infoc DWC_INFOC
  62101. +/**
  62102. + * Prints out a warning message.
  62103. + */
  62104. +#define DWC_WARN(_format, _args...) __DWC_WARN("WARN:%s:%s:%d: " _format "\n", \
  62105. + dwc_irq(), __func__, __LINE__, ## _args)
  62106. +#define dwc_warn DWC_WARN
  62107. +/**
  62108. + * Prints out an error message.
  62109. + */
  62110. +#define DWC_ERROR(_format, _args...) __DWC_ERROR("ERROR:%s:%s:%d: " _format "\n", \
  62111. + dwc_irq(), __func__, __LINE__, ## _args)
  62112. +#define dwc_error DWC_ERROR
  62113. +
  62114. +#define DWC_PROTO_ERROR(_format, _args...) __DWC_WARN("ERROR:%s:%s:%d: " _format "\n", \
  62115. + dwc_irq(), __func__, __LINE__, ## _args)
  62116. +#define dwc_proto_error DWC_PROTO_ERROR
  62117. +
  62118. +#ifdef DEBUG
  62119. +/** Prints out a exception error message if the _expr expression fails. Disabled
  62120. + * if DEBUG is not enabled. */
  62121. +#define DWC_ASSERT(_expr, _format, _args...) do { \
  62122. + if (!(_expr)) { DWC_EXCEPTION("%s:%s:%d: " _format "\n", dwc_irq(), \
  62123. + __FILE__, __LINE__, ## _args); } \
  62124. + } while (0)
  62125. +#else
  62126. +#define DWC_ASSERT(_x...)
  62127. +#endif
  62128. +#define dwc_assert DWC_ASSERT
  62129. +
  62130. +
  62131. +/** @name Byte Ordering
  62132. + * The following functions are for conversions between processor's byte ordering
  62133. + * and specific ordering you want.
  62134. + */
  62135. +
  62136. +/** Converts 32 bit data in CPU byte ordering to little endian. */
  62137. +extern uint32_t DWC_CPU_TO_LE32(uint32_t *p);
  62138. +#define dwc_cpu_to_le32 DWC_CPU_TO_LE32
  62139. +
  62140. +/** Converts 32 bit data in CPU byte orderint to big endian. */
  62141. +extern uint32_t DWC_CPU_TO_BE32(uint32_t *p);
  62142. +#define dwc_cpu_to_be32 DWC_CPU_TO_BE32
  62143. +
  62144. +/** Converts 32 bit little endian data to CPU byte ordering. */
  62145. +extern uint32_t DWC_LE32_TO_CPU(uint32_t *p);
  62146. +#define dwc_le32_to_cpu DWC_LE32_TO_CPU
  62147. +
  62148. +/** Converts 32 bit big endian data to CPU byte ordering. */
  62149. +extern uint32_t DWC_BE32_TO_CPU(uint32_t *p);
  62150. +#define dwc_be32_to_cpu DWC_BE32_TO_CPU
  62151. +
  62152. +/** Converts 16 bit data in CPU byte ordering to little endian. */
  62153. +extern uint16_t DWC_CPU_TO_LE16(uint16_t *p);
  62154. +#define dwc_cpu_to_le16 DWC_CPU_TO_LE16
  62155. +
  62156. +/** Converts 16 bit data in CPU byte orderint to big endian. */
  62157. +extern uint16_t DWC_CPU_TO_BE16(uint16_t *p);
  62158. +#define dwc_cpu_to_be16 DWC_CPU_TO_BE16
  62159. +
  62160. +/** Converts 16 bit little endian data to CPU byte ordering. */
  62161. +extern uint16_t DWC_LE16_TO_CPU(uint16_t *p);
  62162. +#define dwc_le16_to_cpu DWC_LE16_TO_CPU
  62163. +
  62164. +/** Converts 16 bit bi endian data to CPU byte ordering. */
  62165. +extern uint16_t DWC_BE16_TO_CPU(uint16_t *p);
  62166. +#define dwc_be16_to_cpu DWC_BE16_TO_CPU
  62167. +
  62168. +
  62169. +/** @name Register Read/Write
  62170. + *
  62171. + * The following six functions should be implemented to read/write registers of
  62172. + * 32-bit and 64-bit sizes. All modules use this to read/write register values.
  62173. + * The reg value is a pointer to the register calculated from the void *base
  62174. + * variable passed into the driver when it is started. */
  62175. +
  62176. +#ifdef DWC_LINUX
  62177. +/* Linux doesn't need any extra parameters for register read/write, so we
  62178. + * just throw away the IO context parameter.
  62179. + */
  62180. +/** Reads the content of a 32-bit register. */
  62181. +extern uint32_t DWC_READ_REG32(uint32_t volatile *reg);
  62182. +#define dwc_read_reg32(_ctx_,_reg_) DWC_READ_REG32(_reg_)
  62183. +
  62184. +/** Reads the content of a 64-bit register. */
  62185. +extern uint64_t DWC_READ_REG64(uint64_t volatile *reg);
  62186. +#define dwc_read_reg64(_ctx_,_reg_) DWC_READ_REG64(_reg_)
  62187. +
  62188. +/** Writes to a 32-bit register. */
  62189. +extern void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value);
  62190. +#define dwc_write_reg32(_ctx_,_reg_,_val_) DWC_WRITE_REG32(_reg_, _val_)
  62191. +
  62192. +/** Writes to a 64-bit register. */
  62193. +extern void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value);
  62194. +#define dwc_write_reg64(_ctx_,_reg_,_val_) DWC_WRITE_REG64(_reg_, _val_)
  62195. +
  62196. +/**
  62197. + * Modify bit values in a register. Using the
  62198. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  62199. + */
  62200. +extern void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  62201. +#define dwc_modify_reg32(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG32(_reg_,_cmsk_,_smsk_)
  62202. +extern void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  62203. +#define dwc_modify_reg64(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG64(_reg_,_cmsk_,_smsk_)
  62204. +
  62205. +#endif /* DWC_LINUX */
  62206. +
  62207. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  62208. +typedef struct dwc_ioctx {
  62209. + struct device *dev;
  62210. + bus_space_tag_t iot;
  62211. + bus_space_handle_t ioh;
  62212. +} dwc_ioctx_t;
  62213. +
  62214. +/** BSD needs two extra parameters for register read/write, so we pass
  62215. + * them in using the IO context parameter.
  62216. + */
  62217. +/** Reads the content of a 32-bit register. */
  62218. +extern uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg);
  62219. +#define dwc_read_reg32 DWC_READ_REG32
  62220. +
  62221. +/** Reads the content of a 64-bit register. */
  62222. +extern uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg);
  62223. +#define dwc_read_reg64 DWC_READ_REG64
  62224. +
  62225. +/** Writes to a 32-bit register. */
  62226. +extern void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value);
  62227. +#define dwc_write_reg32 DWC_WRITE_REG32
  62228. +
  62229. +/** Writes to a 64-bit register. */
  62230. +extern void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value);
  62231. +#define dwc_write_reg64 DWC_WRITE_REG64
  62232. +
  62233. +/**
  62234. + * Modify bit values in a register. Using the
  62235. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  62236. + */
  62237. +extern void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  62238. +#define dwc_modify_reg32 DWC_MODIFY_REG32
  62239. +extern void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  62240. +#define dwc_modify_reg64 DWC_MODIFY_REG64
  62241. +
  62242. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  62243. +
  62244. +/** @cond */
  62245. +
  62246. +/** @name Some convenience MACROS used internally. Define DWC_DEBUG_REGS to log the
  62247. + * register writes. */
  62248. +
  62249. +#ifdef DWC_LINUX
  62250. +
  62251. +# ifdef DWC_DEBUG_REGS
  62252. +
  62253. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  62254. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  62255. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  62256. +} \
  62257. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  62258. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  62259. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  62260. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  62261. +}
  62262. +
  62263. +#define dwc_define_read_write_reg(_reg,_container_type) \
  62264. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  62265. + return DWC_READ_REG32(&container->regs->_reg); \
  62266. +} \
  62267. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  62268. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  62269. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  62270. +}
  62271. +
  62272. +# else /* DWC_DEBUG_REGS */
  62273. +
  62274. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  62275. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  62276. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  62277. +} \
  62278. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  62279. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  62280. +}
  62281. +
  62282. +#define dwc_define_read_write_reg(_reg,_container_type) \
  62283. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  62284. + return DWC_READ_REG32(&container->regs->_reg); \
  62285. +} \
  62286. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  62287. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  62288. +}
  62289. +
  62290. +# endif /* DWC_DEBUG_REGS */
  62291. +
  62292. +#endif /* DWC_LINUX */
  62293. +
  62294. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  62295. +
  62296. +# ifdef DWC_DEBUG_REGS
  62297. +
  62298. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  62299. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  62300. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  62301. +} \
  62302. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  62303. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  62304. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  62305. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  62306. +}
  62307. +
  62308. +#define dwc_define_read_write_reg(_reg,_container_type) \
  62309. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  62310. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  62311. +} \
  62312. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  62313. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  62314. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  62315. +}
  62316. +
  62317. +# else /* DWC_DEBUG_REGS */
  62318. +
  62319. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  62320. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  62321. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  62322. +} \
  62323. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  62324. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  62325. +}
  62326. +
  62327. +#define dwc_define_read_write_reg(_reg,_container_type) \
  62328. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  62329. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  62330. +} \
  62331. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  62332. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  62333. +}
  62334. +
  62335. +# endif /* DWC_DEBUG_REGS */
  62336. +
  62337. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  62338. +
  62339. +/** @endcond */
  62340. +
  62341. +
  62342. +#ifdef DWC_CRYPTOLIB
  62343. +/** @name Crypto Functions
  62344. + *
  62345. + * These are the low-level cryptographic functions used by the driver. */
  62346. +
  62347. +/** Perform AES CBC */
  62348. +extern int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out);
  62349. +#define dwc_aes_cbc DWC_AES_CBC
  62350. +
  62351. +/** Fill the provided buffer with random bytes. These should be cryptographic grade random numbers. */
  62352. +extern void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length);
  62353. +#define dwc_random_bytes DWC_RANDOM_BYTES
  62354. +
  62355. +/** Perform the SHA-256 hash function */
  62356. +extern int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out);
  62357. +#define dwc_sha256 DWC_SHA256
  62358. +
  62359. +/** Calculated the HMAC-SHA256 */
  62360. +extern int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t *out);
  62361. +#define dwc_hmac_sha256 DWC_HMAC_SHA256
  62362. +
  62363. +#endif /* DWC_CRYPTOLIB */
  62364. +
  62365. +
  62366. +/** @name Memory Allocation
  62367. + *
  62368. + * These function provide access to memory allocation. There are only 2 DMA
  62369. + * functions and 3 Regular memory functions that need to be implemented. None
  62370. + * of the memory debugging routines need to be implemented. The allocation
  62371. + * routines all ZERO the contents of the memory.
  62372. + *
  62373. + * Defining DWC_DEBUG_MEMORY turns on memory debugging and statistic gathering.
  62374. + * This checks for memory leaks, keeping track of alloc/free pairs. It also
  62375. + * keeps track of how much memory the driver is using at any given time. */
  62376. +
  62377. +#define DWC_PAGE_SIZE 4096
  62378. +#define DWC_PAGE_OFFSET(addr) (((uint32_t)addr) & 0xfff)
  62379. +#define DWC_PAGE_ALIGNED(addr) ((((uint32_t)addr) & 0xfff) == 0)
  62380. +
  62381. +#define DWC_INVALID_DMA_ADDR 0x0
  62382. +
  62383. +#ifdef DWC_LINUX
  62384. +/** Type for a DMA address */
  62385. +typedef dma_addr_t dwc_dma_t;
  62386. +#endif
  62387. +
  62388. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  62389. +typedef bus_addr_t dwc_dma_t;
  62390. +#endif
  62391. +
  62392. +#ifdef DWC_FREEBSD
  62393. +typedef struct dwc_dmactx {
  62394. + struct device *dev;
  62395. + bus_dma_tag_t dma_tag;
  62396. + bus_dmamap_t dma_map;
  62397. + bus_addr_t dma_paddr;
  62398. + void *dma_vaddr;
  62399. +} dwc_dmactx_t;
  62400. +#endif
  62401. +
  62402. +#ifdef DWC_NETBSD
  62403. +typedef struct dwc_dmactx {
  62404. + struct device *dev;
  62405. + bus_dma_tag_t dma_tag;
  62406. + bus_dmamap_t dma_map;
  62407. + bus_dma_segment_t segs[1];
  62408. + int nsegs;
  62409. + bus_addr_t dma_paddr;
  62410. + void *dma_vaddr;
  62411. +} dwc_dmactx_t;
  62412. +#endif
  62413. +
  62414. +/* @todo these functions will be added in the future */
  62415. +#if 0
  62416. +/**
  62417. + * Creates a DMA pool from which you can allocate DMA buffers. Buffers
  62418. + * allocated from this pool will be guaranteed to meet the size, alignment, and
  62419. + * boundary requirements specified.
  62420. + *
  62421. + * @param[in] size Specifies the size of the buffers that will be allocated from
  62422. + * this pool.
  62423. + * @param[in] align Specifies the byte alignment requirements of the buffers
  62424. + * allocated from this pool. Must be a power of 2.
  62425. + * @param[in] boundary Specifies the N-byte boundary that buffers allocated from
  62426. + * this pool must not cross.
  62427. + *
  62428. + * @returns A pointer to an internal opaque structure which is not to be
  62429. + * accessed outside of these library functions. Use this handle to specify
  62430. + * which pools to allocate/free DMA buffers from and also to destroy the pool,
  62431. + * when you are done with it.
  62432. + */
  62433. +extern dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size, uint32_t align, uint32_t boundary);
  62434. +
  62435. +/**
  62436. + * Destroy a DMA pool. All buffers allocated from that pool must be freed first.
  62437. + */
  62438. +extern void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool);
  62439. +
  62440. +/**
  62441. + * Allocate a buffer from the specified DMA pool and zeros its contents.
  62442. + */
  62443. +extern void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr);
  62444. +
  62445. +/**
  62446. + * Free a previously allocated buffer from the DMA pool.
  62447. + */
  62448. +extern void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr);
  62449. +#endif
  62450. +
  62451. +/** Allocates a DMA capable buffer and zeroes its contents. */
  62452. +extern void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  62453. +
  62454. +/** Allocates a DMA capable buffer and zeroes its contents in atomic contest */
  62455. +extern void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  62456. +
  62457. +/** Frees a previously allocated buffer. */
  62458. +extern void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr);
  62459. +
  62460. +/** Allocates a block of memory and zeroes its contents. */
  62461. +extern void *__DWC_ALLOC(void *mem_ctx, uint32_t size);
  62462. +
  62463. +/** Allocates a block of memory and zeroes its contents, in an atomic manner
  62464. + * which can be used inside interrupt context. The size should be sufficiently
  62465. + * small, a few KB at most, such that failures are not likely to occur. Can just call
  62466. + * __DWC_ALLOC if it is atomic. */
  62467. +extern void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size);
  62468. +
  62469. +/** Frees a previously allocated buffer. */
  62470. +extern void __DWC_FREE(void *mem_ctx, void *addr);
  62471. +
  62472. +#ifndef DWC_DEBUG_MEMORY
  62473. +
  62474. +#define DWC_ALLOC(_size_) __DWC_ALLOC(NULL, _size_)
  62475. +#define DWC_ALLOC_ATOMIC(_size_) __DWC_ALLOC_ATOMIC(NULL, _size_)
  62476. +#define DWC_FREE(_addr_) __DWC_FREE(NULL, _addr_)
  62477. +
  62478. +# ifdef DWC_LINUX
  62479. +#define DWC_DMA_ALLOC(_size_,_dma_) __DWC_DMA_ALLOC(NULL, _size_, _dma_)
  62480. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) __DWC_DMA_ALLOC_ATOMIC(NULL, _size_,_dma_)
  62481. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) __DWC_DMA_FREE(NULL, _size_, _virt_, _dma_)
  62482. +# endif
  62483. +
  62484. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  62485. +#define DWC_DMA_ALLOC __DWC_DMA_ALLOC
  62486. +#define DWC_DMA_FREE __DWC_DMA_FREE
  62487. +# endif
  62488. +extern void *dwc_dma_alloc_atomic_debug(uint32_t size, dwc_dma_t *dma_addr, char const *func, int line);
  62489. +
  62490. +#else /* DWC_DEBUG_MEMORY */
  62491. +
  62492. +extern void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  62493. +extern void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  62494. +extern void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line);
  62495. +extern void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  62496. + char const *func, int line);
  62497. +extern void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  62498. + char const *func, int line);
  62499. +extern void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  62500. + dwc_dma_t dma_addr, char const *func, int line);
  62501. +
  62502. +extern int dwc_memory_debug_start(void *mem_ctx);
  62503. +extern void dwc_memory_debug_stop(void);
  62504. +extern void dwc_memory_debug_report(void);
  62505. +
  62506. +#define DWC_ALLOC(_size_) dwc_alloc_debug(NULL, _size_, __func__, __LINE__)
  62507. +#define DWC_ALLOC_ATOMIC(_size_) dwc_alloc_atomic_debug(NULL, _size_, \
  62508. + __func__, __LINE__)
  62509. +#define DWC_FREE(_addr_) dwc_free_debug(NULL, _addr_, __func__, __LINE__)
  62510. +
  62511. +# ifdef DWC_LINUX
  62512. +#define DWC_DMA_ALLOC(_size_,_dma_) dwc_dma_alloc_debug(NULL, _size_, \
  62513. + _dma_, __func__, __LINE__)
  62514. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) dwc_dma_alloc_atomic_debug(NULL, _size_, \
  62515. + _dma_, __func__, __LINE__)
  62516. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) dwc_dma_free_debug(NULL, _size_, \
  62517. + _virt_, _dma_, __func__, __LINE__)
  62518. +# endif
  62519. +
  62520. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  62521. +#define DWC_DMA_ALLOC(_ctx_,_size_,_dma_) dwc_dma_alloc_debug(_ctx_, _size_, \
  62522. + _dma_, __func__, __LINE__)
  62523. +#define DWC_DMA_FREE(_ctx_,_size_,_virt_,_dma_) dwc_dma_free_debug(_ctx_, _size_, \
  62524. + _virt_, _dma_, __func__, __LINE__)
  62525. +# endif
  62526. +
  62527. +#endif /* DWC_DEBUG_MEMORY */
  62528. +
  62529. +#define dwc_alloc(_ctx_,_size_) DWC_ALLOC(_size_)
  62530. +#define dwc_alloc_atomic(_ctx_,_size_) DWC_ALLOC_ATOMIC(_size_)
  62531. +#define dwc_free(_ctx_,_addr_) DWC_FREE(_addr_)
  62532. +
  62533. +#ifdef DWC_LINUX
  62534. +/* Linux doesn't need any extra parameters for DMA buffer allocation, so we
  62535. + * just throw away the DMA context parameter.
  62536. + */
  62537. +#define dwc_dma_alloc(_ctx_,_size_,_dma_) DWC_DMA_ALLOC(_size_, _dma_)
  62538. +#define dwc_dma_alloc_atomic(_ctx_,_size_,_dma_) DWC_DMA_ALLOC_ATOMIC(_size_, _dma_)
  62539. +#define dwc_dma_free(_ctx_,_size_,_virt_,_dma_) DWC_DMA_FREE(_size_, _virt_, _dma_)
  62540. +#endif
  62541. +
  62542. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  62543. +/** BSD needs several extra parameters for DMA buffer allocation, so we pass
  62544. + * them in using the DMA context parameter.
  62545. + */
  62546. +#define dwc_dma_alloc DWC_DMA_ALLOC
  62547. +#define dwc_dma_free DWC_DMA_FREE
  62548. +#endif
  62549. +
  62550. +
  62551. +/** @name Memory and String Processing */
  62552. +
  62553. +/** memset() clone */
  62554. +extern void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size);
  62555. +#define dwc_memset DWC_MEMSET
  62556. +
  62557. +/** memcpy() clone */
  62558. +extern void *DWC_MEMCPY(void *dest, void const *src, uint32_t size);
  62559. +#define dwc_memcpy DWC_MEMCPY
  62560. +
  62561. +/** memmove() clone */
  62562. +extern void *DWC_MEMMOVE(void *dest, void *src, uint32_t size);
  62563. +#define dwc_memmove DWC_MEMMOVE
  62564. +
  62565. +/** memcmp() clone */
  62566. +extern int DWC_MEMCMP(void *m1, void *m2, uint32_t size);
  62567. +#define dwc_memcmp DWC_MEMCMP
  62568. +
  62569. +/** strcmp() clone */
  62570. +extern int DWC_STRCMP(void *s1, void *s2);
  62571. +#define dwc_strcmp DWC_STRCMP
  62572. +
  62573. +/** strncmp() clone */
  62574. +extern int DWC_STRNCMP(void *s1, void *s2, uint32_t size);
  62575. +#define dwc_strncmp DWC_STRNCMP
  62576. +
  62577. +/** strlen() clone, for NULL terminated ASCII strings */
  62578. +extern int DWC_STRLEN(char const *str);
  62579. +#define dwc_strlen DWC_STRLEN
  62580. +
  62581. +/** strcpy() clone, for NULL terminated ASCII strings */
  62582. +extern char *DWC_STRCPY(char *to, const char *from);
  62583. +#define dwc_strcpy DWC_STRCPY
  62584. +
  62585. +/** strdup() clone. If you wish to use memory allocation debugging, this
  62586. + * implementation of strdup should use the DWC_* memory routines instead of
  62587. + * calling a predefined strdup. Otherwise the memory allocated by this routine
  62588. + * will not be seen by the debugging routines. */
  62589. +extern char *DWC_STRDUP(char const *str);
  62590. +#define dwc_strdup(_ctx_,_str_) DWC_STRDUP(_str_)
  62591. +
  62592. +/** NOT an atoi() clone. Read the description carefully. Returns an integer
  62593. + * converted from the string str in base 10 unless the string begins with a "0x"
  62594. + * in which case it is base 16. String must be a NULL terminated sequence of
  62595. + * ASCII characters and may optionally begin with whitespace, a + or -, and a
  62596. + * "0x" prefix if base 16. The remaining characters must be valid digits for
  62597. + * the number and end with a NULL character. If any invalid characters are
  62598. + * encountered or it returns with a negative error code and the results of the
  62599. + * conversion are undefined. On sucess it returns 0. Overflow conditions are
  62600. + * undefined. An example implementation using atoi() can be referenced from the
  62601. + * Linux implementation. */
  62602. +extern int DWC_ATOI(const char *str, int32_t *value);
  62603. +#define dwc_atoi DWC_ATOI
  62604. +
  62605. +/** Same as above but for unsigned. */
  62606. +extern int DWC_ATOUI(const char *str, uint32_t *value);
  62607. +#define dwc_atoui DWC_ATOUI
  62608. +
  62609. +#ifdef DWC_UTFLIB
  62610. +/** This routine returns a UTF16LE unicode encoded string from a UTF8 string. */
  62611. +extern int DWC_UTF8_TO_UTF16LE(uint8_t const *utf8string, uint16_t *utf16string, unsigned len);
  62612. +#define dwc_utf8_to_utf16le DWC_UTF8_TO_UTF16LE
  62613. +#endif
  62614. +
  62615. +
  62616. +/** @name Wait queues
  62617. + *
  62618. + * Wait queues provide a means of synchronizing between threads or processes. A
  62619. + * process can block on a waitq if some condition is not true, waiting for it to
  62620. + * become true. When the waitq is triggered all waiting process will get
  62621. + * unblocked and the condition will be check again. Waitqs should be triggered
  62622. + * every time a condition can potentially change.*/
  62623. +struct dwc_waitq;
  62624. +
  62625. +/** Type for a waitq */
  62626. +typedef struct dwc_waitq dwc_waitq_t;
  62627. +
  62628. +/** The type of waitq condition callback function. This is called every time
  62629. + * condition is evaluated. */
  62630. +typedef int (*dwc_waitq_condition_t)(void *data);
  62631. +
  62632. +/** Allocate a waitq */
  62633. +extern dwc_waitq_t *DWC_WAITQ_ALLOC(void);
  62634. +#define dwc_waitq_alloc(_ctx_) DWC_WAITQ_ALLOC()
  62635. +
  62636. +/** Free a waitq */
  62637. +extern void DWC_WAITQ_FREE(dwc_waitq_t *wq);
  62638. +#define dwc_waitq_free DWC_WAITQ_FREE
  62639. +
  62640. +/** Check the condition and if it is false, block on the waitq. When unblocked, check the
  62641. + * condition again. The function returns when the condition becomes true. The return value
  62642. + * is 0 on condition true, DWC_WAITQ_ABORTED on abort or killed, or DWC_WAITQ_UNKNOWN on error. */
  62643. +extern int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data);
  62644. +#define dwc_waitq_wait DWC_WAITQ_WAIT
  62645. +
  62646. +/** Check the condition and if it is false, block on the waitq. When unblocked,
  62647. + * check the condition again. The function returns when the condition become
  62648. + * true or the timeout has passed. The return value is 0 on condition true or
  62649. + * DWC_TIMED_OUT on timeout, or DWC_WAITQ_ABORTED, or DWC_WAITQ_UNKNOWN on
  62650. + * error. */
  62651. +extern int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  62652. + void *data, int32_t msecs);
  62653. +#define dwc_waitq_wait_timeout DWC_WAITQ_WAIT_TIMEOUT
  62654. +
  62655. +/** Trigger a waitq, unblocking all processes. This should be called whenever a condition
  62656. + * has potentially changed. */
  62657. +extern void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq);
  62658. +#define dwc_waitq_trigger DWC_WAITQ_TRIGGER
  62659. +
  62660. +/** Unblock all processes waiting on the waitq with an ABORTED result. */
  62661. +extern void DWC_WAITQ_ABORT(dwc_waitq_t *wq);
  62662. +#define dwc_waitq_abort DWC_WAITQ_ABORT
  62663. +
  62664. +
  62665. +/** @name Threads
  62666. + *
  62667. + * A thread must be explicitly stopped. It must check DWC_THREAD_SHOULD_STOP
  62668. + * whenever it is woken up, and then return. The DWC_THREAD_STOP function
  62669. + * returns the value from the thread.
  62670. + */
  62671. +
  62672. +struct dwc_thread;
  62673. +
  62674. +/** Type for a thread */
  62675. +typedef struct dwc_thread dwc_thread_t;
  62676. +
  62677. +/** The thread function */
  62678. +typedef int (*dwc_thread_function_t)(void *data);
  62679. +
  62680. +/** Create a thread and start it running the thread_function. Returns a handle
  62681. + * to the thread */
  62682. +extern dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data);
  62683. +#define dwc_thread_run(_ctx_,_func_,_name_,_data_) DWC_THREAD_RUN(_func_, _name_, _data_)
  62684. +
  62685. +/** Stops a thread. Return the value returned by the thread. Or will return
  62686. + * DWC_ABORT if the thread never started. */
  62687. +extern int DWC_THREAD_STOP(dwc_thread_t *thread);
  62688. +#define dwc_thread_stop DWC_THREAD_STOP
  62689. +
  62690. +/** Signifies to the thread that it must stop. */
  62691. +#ifdef DWC_LINUX
  62692. +/* Linux doesn't need any parameters for kthread_should_stop() */
  62693. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(void);
  62694. +#define dwc_thread_should_stop(_thrd_) DWC_THREAD_SHOULD_STOP()
  62695. +
  62696. +/* No thread_exit function in Linux */
  62697. +#define dwc_thread_exit(_thrd_)
  62698. +#endif
  62699. +
  62700. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  62701. +/** BSD needs the thread pointer for kthread_suspend_check() */
  62702. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread);
  62703. +#define dwc_thread_should_stop DWC_THREAD_SHOULD_STOP
  62704. +
  62705. +/** The thread must call this to exit. */
  62706. +extern void DWC_THREAD_EXIT(dwc_thread_t *thread);
  62707. +#define dwc_thread_exit DWC_THREAD_EXIT
  62708. +#endif
  62709. +
  62710. +
  62711. +/** @name Work queues
  62712. + *
  62713. + * Workqs are used to queue a callback function to be called at some later time,
  62714. + * in another thread. */
  62715. +struct dwc_workq;
  62716. +
  62717. +/** Type for a workq */
  62718. +typedef struct dwc_workq dwc_workq_t;
  62719. +
  62720. +/** The type of the callback function to be called. */
  62721. +typedef void (*dwc_work_callback_t)(void *data);
  62722. +
  62723. +/** Allocate a workq */
  62724. +extern dwc_workq_t *DWC_WORKQ_ALLOC(char *name);
  62725. +#define dwc_workq_alloc(_ctx_,_name_) DWC_WORKQ_ALLOC(_name_)
  62726. +
  62727. +/** Free a workq. All work must be completed before being freed. */
  62728. +extern void DWC_WORKQ_FREE(dwc_workq_t *workq);
  62729. +#define dwc_workq_free DWC_WORKQ_FREE
  62730. +
  62731. +/** Schedule a callback on the workq, passing in data. The function will be
  62732. + * scheduled at some later time. */
  62733. +extern void DWC_WORKQ_SCHEDULE(dwc_workq_t *workq, dwc_work_callback_t cb,
  62734. + void *data, char *format, ...)
  62735. +#ifdef __GNUC__
  62736. + __attribute__ ((format(printf, 4, 5)));
  62737. +#else
  62738. + ;
  62739. +#endif
  62740. +#define dwc_workq_schedule DWC_WORKQ_SCHEDULE
  62741. +
  62742. +/** Schedule a callback on the workq, that will be called until at least
  62743. + * given number miliseconds have passed. */
  62744. +extern void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *workq, dwc_work_callback_t cb,
  62745. + void *data, uint32_t time, char *format, ...)
  62746. +#ifdef __GNUC__
  62747. + __attribute__ ((format(printf, 5, 6)));
  62748. +#else
  62749. + ;
  62750. +#endif
  62751. +#define dwc_workq_schedule_delayed DWC_WORKQ_SCHEDULE_DELAYED
  62752. +
  62753. +/** The number of processes in the workq */
  62754. +extern int DWC_WORKQ_PENDING(dwc_workq_t *workq);
  62755. +#define dwc_workq_pending DWC_WORKQ_PENDING
  62756. +
  62757. +/** Blocks until all the work in the workq is complete or timed out. Returns <
  62758. + * 0 on timeout. */
  62759. +extern int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout);
  62760. +#define dwc_workq_wait_work_done DWC_WORKQ_WAIT_WORK_DONE
  62761. +
  62762. +
  62763. +/** @name Tasklets
  62764. + *
  62765. + */
  62766. +struct dwc_tasklet;
  62767. +
  62768. +/** Type for a tasklet */
  62769. +typedef struct dwc_tasklet dwc_tasklet_t;
  62770. +
  62771. +/** The type of the callback function to be called */
  62772. +typedef void (*dwc_tasklet_callback_t)(void *data);
  62773. +
  62774. +/** Allocates a tasklet */
  62775. +extern dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data);
  62776. +#define dwc_task_alloc(_ctx_,_name_,_cb_,_data_) DWC_TASK_ALLOC(_name_, _cb_, _data_)
  62777. +
  62778. +/** Frees a tasklet */
  62779. +extern void DWC_TASK_FREE(dwc_tasklet_t *task);
  62780. +#define dwc_task_free DWC_TASK_FREE
  62781. +
  62782. +/** Schedules a tasklet to run */
  62783. +extern void DWC_TASK_SCHEDULE(dwc_tasklet_t *task);
  62784. +#define dwc_task_schedule DWC_TASK_SCHEDULE
  62785. +
  62786. +extern void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task);
  62787. +#define dwc_task_hi_schedule DWC_TASK_HI_SCHEDULE
  62788. +
  62789. +/** @name Timer
  62790. + *
  62791. + * Callbacks must be small and atomic.
  62792. + */
  62793. +struct dwc_timer;
  62794. +
  62795. +/** Type for a timer */
  62796. +typedef struct dwc_timer dwc_timer_t;
  62797. +
  62798. +/** The type of the callback function to be called */
  62799. +typedef void (*dwc_timer_callback_t)(void *data);
  62800. +
  62801. +/** Allocates a timer */
  62802. +extern dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data);
  62803. +#define dwc_timer_alloc(_ctx_,_name_,_cb_,_data_) DWC_TIMER_ALLOC(_name_,_cb_,_data_)
  62804. +
  62805. +/** Frees a timer */
  62806. +extern void DWC_TIMER_FREE(dwc_timer_t *timer);
  62807. +#define dwc_timer_free DWC_TIMER_FREE
  62808. +
  62809. +/** Schedules the timer to run at time ms from now. And will repeat at every
  62810. + * repeat_interval msec therafter
  62811. + *
  62812. + * Modifies a timer that is still awaiting execution to a new expiration time.
  62813. + * The mod_time is added to the old time. */
  62814. +extern void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time);
  62815. +#define dwc_timer_schedule DWC_TIMER_SCHEDULE
  62816. +
  62817. +/** Disables the timer from execution. */
  62818. +extern void DWC_TIMER_CANCEL(dwc_timer_t *timer);
  62819. +#define dwc_timer_cancel DWC_TIMER_CANCEL
  62820. +
  62821. +
  62822. +/** @name Spinlocks
  62823. + *
  62824. + * These locks are used when the work between the lock/unlock is atomic and
  62825. + * short. Interrupts are also disabled during the lock/unlock and thus they are
  62826. + * suitable to lock between interrupt/non-interrupt context. They also lock
  62827. + * between processes if you have multiple CPUs or Preemption. If you don't have
  62828. + * multiple CPUS or Preemption, then the you can simply implement the
  62829. + * DWC_SPINLOCK and DWC_SPINUNLOCK to disable and enable interrupts. Because
  62830. + * the work between the lock/unlock is atomic, the process context will never
  62831. + * change, and so you never have to lock between processes. */
  62832. +
  62833. +struct dwc_spinlock;
  62834. +
  62835. +/** Type for a spinlock */
  62836. +typedef struct dwc_spinlock dwc_spinlock_t;
  62837. +
  62838. +/** Type for the 'flags' argument to spinlock funtions */
  62839. +typedef unsigned long dwc_irqflags_t;
  62840. +
  62841. +/** Returns an initialized lock variable. This function should allocate and
  62842. + * initialize the OS-specific data structure used for locking. This data
  62843. + * structure is to be used for the DWC_LOCK and DWC_UNLOCK functions and should
  62844. + * be freed by the DWC_FREE_LOCK when it is no longer used.
  62845. + *
  62846. + * For Linux Spinlock Debugging make it macro because the debugging routines use
  62847. + * the symbol name to determine recursive locking. Using a wrapper function
  62848. + * makes it falsely think recursive locking occurs. */
  62849. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK)
  62850. +#define DWC_SPINLOCK_ALLOC_LINUX_DEBUG(lock) ({ \
  62851. + lock = DWC_ALLOC(sizeof(spinlock_t)); \
  62852. + if (lock) { \
  62853. + spin_lock_init((spinlock_t *)lock); \
  62854. + } \
  62855. +})
  62856. +#else
  62857. +extern dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void);
  62858. +#define dwc_spinlock_alloc(_ctx_) DWC_SPINLOCK_ALLOC()
  62859. +#endif
  62860. +
  62861. +/** Frees an initialized lock variable. */
  62862. +extern void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock);
  62863. +#define dwc_spinlock_free(_ctx_,_lock_) DWC_SPINLOCK_FREE(_lock_)
  62864. +
  62865. +/** Disables interrupts and blocks until it acquires the lock.
  62866. + *
  62867. + * @param lock Pointer to the spinlock.
  62868. + * @param flags Unsigned long for irq flags storage.
  62869. + */
  62870. +extern void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags);
  62871. +#define dwc_spinlock_irqsave DWC_SPINLOCK_IRQSAVE
  62872. +
  62873. +/** Re-enables the interrupt and releases the lock.
  62874. + *
  62875. + * @param lock Pointer to the spinlock.
  62876. + * @param flags Unsigned long for irq flags storage. Must be the same as was
  62877. + * passed into DWC_LOCK.
  62878. + */
  62879. +extern void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags);
  62880. +#define dwc_spinunlock_irqrestore DWC_SPINUNLOCK_IRQRESTORE
  62881. +
  62882. +/** Blocks until it acquires the lock.
  62883. + *
  62884. + * @param lock Pointer to the spinlock.
  62885. + */
  62886. +extern void DWC_SPINLOCK(dwc_spinlock_t *lock);
  62887. +#define dwc_spinlock DWC_SPINLOCK
  62888. +
  62889. +/** Releases the lock.
  62890. + *
  62891. + * @param lock Pointer to the spinlock.
  62892. + */
  62893. +extern void DWC_SPINUNLOCK(dwc_spinlock_t *lock);
  62894. +#define dwc_spinunlock DWC_SPINUNLOCK
  62895. +
  62896. +
  62897. +/** @name Mutexes
  62898. + *
  62899. + * Unlike spinlocks Mutexes lock only between processes and the work between the
  62900. + * lock/unlock CAN block, therefore it CANNOT be called from interrupt context.
  62901. + */
  62902. +
  62903. +struct dwc_mutex;
  62904. +
  62905. +/** Type for a mutex */
  62906. +typedef struct dwc_mutex dwc_mutex_t;
  62907. +
  62908. +/* For Linux Mutex Debugging make it inline because the debugging routines use
  62909. + * the symbol to determine recursive locking. This makes it falsely think
  62910. + * recursive locking occurs. */
  62911. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  62912. +#define DWC_MUTEX_ALLOC_LINUX_DEBUG(__mutexp) ({ \
  62913. + __mutexp = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex)); \
  62914. + mutex_init((struct mutex *)__mutexp); \
  62915. +})
  62916. +#endif
  62917. +
  62918. +/** Allocate a mutex */
  62919. +extern dwc_mutex_t *DWC_MUTEX_ALLOC(void);
  62920. +#define dwc_mutex_alloc(_ctx_) DWC_MUTEX_ALLOC()
  62921. +
  62922. +/* For memory leak debugging when using Linux Mutex Debugging */
  62923. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  62924. +#define DWC_MUTEX_FREE(__mutexp) do { \
  62925. + mutex_destroy((struct mutex *)__mutexp); \
  62926. + DWC_FREE(__mutexp); \
  62927. +} while(0)
  62928. +#else
  62929. +/** Free a mutex */
  62930. +extern void DWC_MUTEX_FREE(dwc_mutex_t *mutex);
  62931. +#define dwc_mutex_free(_ctx_,_mutex_) DWC_MUTEX_FREE(_mutex_)
  62932. +#endif
  62933. +
  62934. +/** Lock a mutex */
  62935. +extern void DWC_MUTEX_LOCK(dwc_mutex_t *mutex);
  62936. +#define dwc_mutex_lock DWC_MUTEX_LOCK
  62937. +
  62938. +/** Non-blocking lock returns 1 on successful lock. */
  62939. +extern int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex);
  62940. +#define dwc_mutex_trylock DWC_MUTEX_TRYLOCK
  62941. +
  62942. +/** Unlock a mutex */
  62943. +extern void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex);
  62944. +#define dwc_mutex_unlock DWC_MUTEX_UNLOCK
  62945. +
  62946. +
  62947. +/** @name Time */
  62948. +
  62949. +/** Microsecond delay.
  62950. + *
  62951. + * @param usecs Microseconds to delay.
  62952. + */
  62953. +extern void DWC_UDELAY(uint32_t usecs);
  62954. +#define dwc_udelay DWC_UDELAY
  62955. +
  62956. +/** Millisecond delay.
  62957. + *
  62958. + * @param msecs Milliseconds to delay.
  62959. + */
  62960. +extern void DWC_MDELAY(uint32_t msecs);
  62961. +#define dwc_mdelay DWC_MDELAY
  62962. +
  62963. +/** Non-busy waiting.
  62964. + * Sleeps for specified number of milliseconds.
  62965. + *
  62966. + * @param msecs Milliseconds to sleep.
  62967. + */
  62968. +extern void DWC_MSLEEP(uint32_t msecs);
  62969. +#define dwc_msleep DWC_MSLEEP
  62970. +
  62971. +/**
  62972. + * Returns number of milliseconds since boot.
  62973. + */
  62974. +extern uint32_t DWC_TIME(void);
  62975. +#define dwc_time DWC_TIME
  62976. +
  62977. +
  62978. +
  62979. +
  62980. +/* @mainpage DWC Portability and Common Library
  62981. + *
  62982. + * This is the documentation for the DWC Portability and Common Library.
  62983. + *
  62984. + * @section intro Introduction
  62985. + *
  62986. + * The DWC Portability library consists of wrapper calls and data structures to
  62987. + * all low-level functions which are typically provided by the OS. The WUDEV
  62988. + * driver uses only these functions. In order to port the WUDEV driver, only
  62989. + * the functions in this library need to be re-implemented, with the same
  62990. + * behavior as documented here.
  62991. + *
  62992. + * The Common library consists of higher level functions, which rely only on
  62993. + * calling the functions from the DWC Portability library. These common
  62994. + * routines are shared across modules. Some of the common libraries need to be
  62995. + * used directly by the driver programmer when porting WUDEV. Such as the
  62996. + * parameter and notification libraries.
  62997. + *
  62998. + * @section low Portability Library OS Wrapper Functions
  62999. + *
  63000. + * Any function starting with DWC and in all CAPS is a low-level OS-wrapper that
  63001. + * needs to be implemented when porting, for example DWC_MUTEX_ALLOC(). All of
  63002. + * these functions are included in the dwc_os.h file.
  63003. + *
  63004. + * There are many functions here covering a wide array of OS services. Please
  63005. + * see dwc_os.h for details, and implementation notes for each function.
  63006. + *
  63007. + * @section common Common Library Functions
  63008. + *
  63009. + * Any function starting with dwc and in all lowercase is a common library
  63010. + * routine. These functions have a portable implementation and do not need to
  63011. + * be reimplemented when porting. The common routines can be used by any
  63012. + * driver, and some must be used by the end user to control the drivers. For
  63013. + * example, you must use the Parameter common library in order to set the
  63014. + * parameters in the WUDEV module.
  63015. + *
  63016. + * The common libraries consist of the following:
  63017. + *
  63018. + * - Connection Contexts - Used internally and can be used by end-user. See dwc_cc.h
  63019. + * - Parameters - Used internally and can be used by end-user. See dwc_params.h
  63020. + * - Notifications - Used internally and can be used by end-user. See dwc_notifier.h
  63021. + * - Lists - Used internally and can be used by end-user. See dwc_list.h
  63022. + * - Memory Debugging - Used internally and can be used by end-user. See dwc_os.h
  63023. + * - Modpow - Used internally only. See dwc_modpow.h
  63024. + * - DH - Used internally only. See dwc_dh.h
  63025. + * - Crypto - Used internally only. See dwc_crypto.h
  63026. + *
  63027. + *
  63028. + * @section prereq Prerequistes For dwc_os.h
  63029. + * @subsection types Data Types
  63030. + *
  63031. + * The dwc_os.h file assumes that several low-level data types are pre defined for the
  63032. + * compilation environment. These data types are:
  63033. + *
  63034. + * - uint8_t - unsigned 8-bit data type
  63035. + * - int8_t - signed 8-bit data type
  63036. + * - uint16_t - unsigned 16-bit data type
  63037. + * - int16_t - signed 16-bit data type
  63038. + * - uint32_t - unsigned 32-bit data type
  63039. + * - int32_t - signed 32-bit data type
  63040. + * - uint64_t - unsigned 64-bit data type
  63041. + * - int64_t - signed 64-bit data type
  63042. + *
  63043. + * Ensure that these are defined before using dwc_os.h. The easiest way to do
  63044. + * that is to modify the top of the file to include the appropriate header.
  63045. + * This is already done for the Linux environment. If the DWC_LINUX macro is
  63046. + * defined, the correct header will be added. A standard header <stdint.h> is
  63047. + * also used for environments where standard C headers are available.
  63048. + *
  63049. + * @subsection stdarg Variable Arguments
  63050. + *
  63051. + * Variable arguments are provided by a standard C header <stdarg.h>. it is
  63052. + * available in Both the Linux and ANSI C enviornment. An equivalent must be
  63053. + * provided in your enviornment in order to use dwc_os.h with the debug and
  63054. + * tracing message functionality.
  63055. + *
  63056. + * @subsection thread Threading
  63057. + *
  63058. + * WUDEV Core must be run on an operating system that provides for multiple
  63059. + * threads/processes. Threading can be implemented in many ways, even in
  63060. + * embedded systems without an operating system. At the bare minimum, the
  63061. + * system should be able to start any number of processes at any time to handle
  63062. + * special work. It need not be a pre-emptive system. Process context can
  63063. + * change upon a call to a blocking function. The hardware interrupt context
  63064. + * that calls the module's ISR() function must be differentiable from process
  63065. + * context, even if your processes are impemented via a hardware interrupt.
  63066. + * Further locking mechanism between process must exist (or be implemented), and
  63067. + * process context must have a way to disable interrupts for a period of time to
  63068. + * lock them out. If all of this exists, the functions in dwc_os.h related to
  63069. + * threading should be able to be implemented with the defined behavior.
  63070. + *
  63071. + */
  63072. +
  63073. +#ifdef __cplusplus
  63074. +}
  63075. +#endif
  63076. +
  63077. +#endif /* _DWC_OS_H_ */
  63078. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/Makefile linux-rpi/drivers/usb/host/dwc_common_port/Makefile
  63079. --- linux-3.18.6/drivers/usb/host/dwc_common_port/Makefile 1970-01-01 01:00:00.000000000 +0100
  63080. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile 2015-02-09 04:40:28.000000000 +0100
  63081. @@ -0,0 +1,58 @@
  63082. +#
  63083. +# Makefile for DWC_common library
  63084. +#
  63085. +
  63086. +ifneq ($(KERNELRELEASE),)
  63087. +
  63088. +ccflags-y += -DDWC_LINUX
  63089. +#ccflags-y += -DDEBUG
  63090. +#ccflags-y += -DDWC_DEBUG_REGS
  63091. +#ccflags-y += -DDWC_DEBUG_MEMORY
  63092. +
  63093. +ccflags-y += -DDWC_LIBMODULE
  63094. +ccflags-y += -DDWC_CCLIB
  63095. +#ccflags-y += -DDWC_CRYPTOLIB
  63096. +ccflags-y += -DDWC_NOTIFYLIB
  63097. +ccflags-y += -DDWC_UTFLIB
  63098. +
  63099. +obj-$(CONFIG_USB_DWCOTG) += dwc_common_port_lib.o
  63100. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  63101. + dwc_crypto.o dwc_notifier.o \
  63102. + dwc_common_linux.o dwc_mem.o
  63103. +
  63104. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  63105. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  63106. +
  63107. +ifneq ($(kernrel3),2.6.20)
  63108. +# grayg - I only know that we use ccflags-y in 2.6.31 actually
  63109. +ccflags-y += $(CPPFLAGS)
  63110. +endif
  63111. +
  63112. +else
  63113. +
  63114. +#ifeq ($(KDIR),)
  63115. +#$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  63116. +#endif
  63117. +
  63118. +ifeq ($(ARCH),)
  63119. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  63120. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  63121. +endif
  63122. +
  63123. +ifeq ($(DOXYGEN),)
  63124. +DOXYGEN := doxygen
  63125. +endif
  63126. +
  63127. +default:
  63128. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  63129. +
  63130. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  63131. + $(DOXYGEN) doc/doxygen.cfg
  63132. +
  63133. +tags: $(wildcard *.[hc])
  63134. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  63135. +
  63136. +endif
  63137. +
  63138. +clean:
  63139. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  63140. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/Makefile.fbsd linux-rpi/drivers/usb/host/dwc_common_port/Makefile.fbsd
  63141. --- linux-3.18.6/drivers/usb/host/dwc_common_port/Makefile.fbsd 1970-01-01 01:00:00.000000000 +0100
  63142. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile.fbsd 2015-02-09 04:40:28.000000000 +0100
  63143. @@ -0,0 +1,17 @@
  63144. +CFLAGS += -I/sys/i386/compile/GENERIC -I/sys/i386/include -I/usr/include
  63145. +CFLAGS += -DDWC_FREEBSD
  63146. +CFLAGS += -DDEBUG
  63147. +#CFLAGS += -DDWC_DEBUG_REGS
  63148. +#CFLAGS += -DDWC_DEBUG_MEMORY
  63149. +
  63150. +#CFLAGS += -DDWC_LIBMODULE
  63151. +#CFLAGS += -DDWC_CCLIB
  63152. +#CFLAGS += -DDWC_CRYPTOLIB
  63153. +#CFLAGS += -DDWC_NOTIFYLIB
  63154. +#CFLAGS += -DDWC_UTFLIB
  63155. +
  63156. +KMOD = dwc_common_port_lib
  63157. +SRCS = dwc_cc.c dwc_modpow.c dwc_dh.c dwc_crypto.c dwc_notifier.c \
  63158. + dwc_common_fbsd.c dwc_mem.c
  63159. +
  63160. +.include <bsd.kmod.mk>
  63161. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/Makefile.linux linux-rpi/drivers/usb/host/dwc_common_port/Makefile.linux
  63162. --- linux-3.18.6/drivers/usb/host/dwc_common_port/Makefile.linux 1970-01-01 01:00:00.000000000 +0100
  63163. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile.linux 2015-02-09 04:40:28.000000000 +0100
  63164. @@ -0,0 +1,49 @@
  63165. +#
  63166. +# Makefile for DWC_common library
  63167. +#
  63168. +ifneq ($(KERNELRELEASE),)
  63169. +
  63170. +ccflags-y += -DDWC_LINUX
  63171. +#ccflags-y += -DDEBUG
  63172. +#ccflags-y += -DDWC_DEBUG_REGS
  63173. +#ccflags-y += -DDWC_DEBUG_MEMORY
  63174. +
  63175. +ccflags-y += -DDWC_LIBMODULE
  63176. +ccflags-y += -DDWC_CCLIB
  63177. +ccflags-y += -DDWC_CRYPTOLIB
  63178. +ccflags-y += -DDWC_NOTIFYLIB
  63179. +ccflags-y += -DDWC_UTFLIB
  63180. +
  63181. +obj-m := dwc_common_port_lib.o
  63182. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  63183. + dwc_crypto.o dwc_notifier.o \
  63184. + dwc_common_linux.o dwc_mem.o
  63185. +
  63186. +else
  63187. +
  63188. +ifeq ($(KDIR),)
  63189. +$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  63190. +endif
  63191. +
  63192. +ifeq ($(ARCH),)
  63193. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  63194. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  63195. +endif
  63196. +
  63197. +ifeq ($(DOXYGEN),)
  63198. +DOXYGEN := doxygen
  63199. +endif
  63200. +
  63201. +default:
  63202. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  63203. +
  63204. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  63205. + $(DOXYGEN) doc/doxygen.cfg
  63206. +
  63207. +tags: $(wildcard *.[hc])
  63208. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  63209. +
  63210. +endif
  63211. +
  63212. +clean:
  63213. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  63214. diff -Nur linux-3.18.6/drivers/usb/host/dwc_common_port/usb.h linux-rpi/drivers/usb/host/dwc_common_port/usb.h
  63215. --- linux-3.18.6/drivers/usb/host/dwc_common_port/usb.h 1970-01-01 01:00:00.000000000 +0100
  63216. +++ linux-rpi/drivers/usb/host/dwc_common_port/usb.h 2015-02-09 04:40:28.000000000 +0100
  63217. @@ -0,0 +1,946 @@
  63218. +/*
  63219. + * Copyright (c) 1998 The NetBSD Foundation, Inc.
  63220. + * All rights reserved.
  63221. + *
  63222. + * This code is derived from software contributed to The NetBSD Foundation
  63223. + * by Lennart Augustsson (lennart@augustsson.net) at
  63224. + * Carlstedt Research & Technology.
  63225. + *
  63226. + * Redistribution and use in source and binary forms, with or without
  63227. + * modification, are permitted provided that the following conditions
  63228. + * are met:
  63229. + * 1. Redistributions of source code must retain the above copyright
  63230. + * notice, this list of conditions and the following disclaimer.
  63231. + * 2. Redistributions in binary form must reproduce the above copyright
  63232. + * notice, this list of conditions and the following disclaimer in the
  63233. + * documentation and/or other materials provided with the distribution.
  63234. + * 3. All advertising materials mentioning features or use of this software
  63235. + * must display the following acknowledgement:
  63236. + * This product includes software developed by the NetBSD
  63237. + * Foundation, Inc. and its contributors.
  63238. + * 4. Neither the name of The NetBSD Foundation nor the names of its
  63239. + * contributors may be used to endorse or promote products derived
  63240. + * from this software without specific prior written permission.
  63241. + *
  63242. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  63243. + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  63244. + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  63245. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  63246. + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  63247. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  63248. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  63249. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  63250. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  63251. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  63252. + * POSSIBILITY OF SUCH DAMAGE.
  63253. + */
  63254. +
  63255. +/* Modified by Synopsys, Inc, 12/12/2007 */
  63256. +
  63257. +
  63258. +#ifndef _USB_H_
  63259. +#define _USB_H_
  63260. +
  63261. +#ifdef __cplusplus
  63262. +extern "C" {
  63263. +#endif
  63264. +
  63265. +/*
  63266. + * The USB records contain some unaligned little-endian word
  63267. + * components. The U[SG]ETW macros take care of both the alignment
  63268. + * and endian problem and should always be used to access non-byte
  63269. + * values.
  63270. + */
  63271. +typedef u_int8_t uByte;
  63272. +typedef u_int8_t uWord[2];
  63273. +typedef u_int8_t uDWord[4];
  63274. +
  63275. +#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
  63276. +#define UCONSTW(x) { (x) & 0xff, ((x) >> 8) & 0xff }
  63277. +#define UCONSTDW(x) { (x) & 0xff, ((x) >> 8) & 0xff, \
  63278. + ((x) >> 16) & 0xff, ((x) >> 24) & 0xff }
  63279. +
  63280. +#if 1
  63281. +#define UGETW(w) ((w)[0] | ((w)[1] << 8))
  63282. +#define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
  63283. +#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
  63284. +#define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
  63285. + (w)[1] = (u_int8_t)((v) >> 8), \
  63286. + (w)[2] = (u_int8_t)((v) >> 16), \
  63287. + (w)[3] = (u_int8_t)((v) >> 24))
  63288. +#else
  63289. +/*
  63290. + * On little-endian machines that can handle unanliged accesses
  63291. + * (e.g. i386) these macros can be replaced by the following.
  63292. + */
  63293. +#define UGETW(w) (*(u_int16_t *)(w))
  63294. +#define USETW(w,v) (*(u_int16_t *)(w) = (v))
  63295. +#define UGETDW(w) (*(u_int32_t *)(w))
  63296. +#define USETDW(w,v) (*(u_int32_t *)(w) = (v))
  63297. +#endif
  63298. +
  63299. +/*
  63300. + * Macros for accessing UAS IU fields, which are big-endian
  63301. + */
  63302. +#define IUSETW2(w,h,l) ((w)[0] = (u_int8_t)(h), (w)[1] = (u_int8_t)(l))
  63303. +#define IUCONSTW(x) { ((x) >> 8) & 0xff, (x) & 0xff }
  63304. +#define IUCONSTDW(x) { ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
  63305. + ((x) >> 8) & 0xff, (x) & 0xff }
  63306. +#define IUGETW(w) (((w)[0] << 8) | (w)[1])
  63307. +#define IUSETW(w,v) ((w)[0] = (u_int8_t)((v) >> 8), (w)[1] = (u_int8_t)(v))
  63308. +#define IUGETDW(w) (((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
  63309. +#define IUSETDW(w,v) ((w)[0] = (u_int8_t)((v) >> 24), \
  63310. + (w)[1] = (u_int8_t)((v) >> 16), \
  63311. + (w)[2] = (u_int8_t)((v) >> 8), \
  63312. + (w)[3] = (u_int8_t)(v))
  63313. +
  63314. +#define UPACKED __attribute__((__packed__))
  63315. +
  63316. +typedef struct {
  63317. + uByte bmRequestType;
  63318. + uByte bRequest;
  63319. + uWord wValue;
  63320. + uWord wIndex;
  63321. + uWord wLength;
  63322. +} UPACKED usb_device_request_t;
  63323. +
  63324. +#define UT_GET_DIR(a) ((a) & 0x80)
  63325. +#define UT_WRITE 0x00
  63326. +#define UT_READ 0x80
  63327. +
  63328. +#define UT_GET_TYPE(a) ((a) & 0x60)
  63329. +#define UT_STANDARD 0x00
  63330. +#define UT_CLASS 0x20
  63331. +#define UT_VENDOR 0x40
  63332. +
  63333. +#define UT_GET_RECIPIENT(a) ((a) & 0x1f)
  63334. +#define UT_DEVICE 0x00
  63335. +#define UT_INTERFACE 0x01
  63336. +#define UT_ENDPOINT 0x02
  63337. +#define UT_OTHER 0x03
  63338. +
  63339. +#define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
  63340. +#define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
  63341. +#define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
  63342. +#define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
  63343. +#define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
  63344. +#define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
  63345. +#define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
  63346. +#define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
  63347. +#define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
  63348. +#define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
  63349. +#define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
  63350. +#define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
  63351. +#define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
  63352. +#define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
  63353. +#define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
  63354. +#define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
  63355. +#define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
  63356. +#define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
  63357. +#define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
  63358. +#define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
  63359. +#define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
  63360. +#define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
  63361. +
  63362. +/* Requests */
  63363. +#define UR_GET_STATUS 0x00
  63364. +#define USTAT_STANDARD_STATUS 0x00
  63365. +#define WUSTAT_WUSB_FEATURE 0x01
  63366. +#define WUSTAT_CHANNEL_INFO 0x02
  63367. +#define WUSTAT_RECEIVED_DATA 0x03
  63368. +#define WUSTAT_MAS_AVAILABILITY 0x04
  63369. +#define WUSTAT_CURRENT_TRANSMIT_POWER 0x05
  63370. +#define UR_CLEAR_FEATURE 0x01
  63371. +#define UR_SET_FEATURE 0x03
  63372. +#define UR_SET_AND_TEST_FEATURE 0x0c
  63373. +#define UR_SET_ADDRESS 0x05
  63374. +#define UR_GET_DESCRIPTOR 0x06
  63375. +#define UDESC_DEVICE 0x01
  63376. +#define UDESC_CONFIG 0x02
  63377. +#define UDESC_STRING 0x03
  63378. +#define UDESC_INTERFACE 0x04
  63379. +#define UDESC_ENDPOINT 0x05
  63380. +#define UDESC_SS_USB_COMPANION 0x30
  63381. +#define UDESC_DEVICE_QUALIFIER 0x06
  63382. +#define UDESC_OTHER_SPEED_CONFIGURATION 0x07
  63383. +#define UDESC_INTERFACE_POWER 0x08
  63384. +#define UDESC_OTG 0x09
  63385. +#define WUDESC_SECURITY 0x0c
  63386. +#define WUDESC_KEY 0x0d
  63387. +#define WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
  63388. +#define WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
  63389. +#define WUD_KEY_TYPE_ASSOC 0x01
  63390. +#define WUD_KEY_TYPE_GTK 0x02
  63391. +#define WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
  63392. +#define WUD_KEY_ORIGIN_HOST 0x00
  63393. +#define WUD_KEY_ORIGIN_DEVICE 0x01
  63394. +#define WUDESC_ENCRYPTION_TYPE 0x0e
  63395. +#define WUDESC_BOS 0x0f
  63396. +#define WUDESC_DEVICE_CAPABILITY 0x10
  63397. +#define WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
  63398. +#define UDESC_BOS 0x0f
  63399. +#define UDESC_DEVICE_CAPABILITY 0x10
  63400. +#define UDESC_CS_DEVICE 0x21 /* class specific */
  63401. +#define UDESC_CS_CONFIG 0x22
  63402. +#define UDESC_CS_STRING 0x23
  63403. +#define UDESC_CS_INTERFACE 0x24
  63404. +#define UDESC_CS_ENDPOINT 0x25
  63405. +#define UDESC_HUB 0x29
  63406. +#define UR_SET_DESCRIPTOR 0x07
  63407. +#define UR_GET_CONFIG 0x08
  63408. +#define UR_SET_CONFIG 0x09
  63409. +#define UR_GET_INTERFACE 0x0a
  63410. +#define UR_SET_INTERFACE 0x0b
  63411. +#define UR_SYNCH_FRAME 0x0c
  63412. +#define WUR_SET_ENCRYPTION 0x0d
  63413. +#define WUR_GET_ENCRYPTION 0x0e
  63414. +#define WUR_SET_HANDSHAKE 0x0f
  63415. +#define WUR_GET_HANDSHAKE 0x10
  63416. +#define WUR_SET_CONNECTION 0x11
  63417. +#define WUR_SET_SECURITY_DATA 0x12
  63418. +#define WUR_GET_SECURITY_DATA 0x13
  63419. +#define WUR_SET_WUSB_DATA 0x14
  63420. +#define WUDATA_DRPIE_INFO 0x01
  63421. +#define WUDATA_TRANSMIT_DATA 0x02
  63422. +#define WUDATA_TRANSMIT_PARAMS 0x03
  63423. +#define WUDATA_RECEIVE_PARAMS 0x04
  63424. +#define WUDATA_TRANSMIT_POWER 0x05
  63425. +#define WUR_LOOPBACK_DATA_WRITE 0x15
  63426. +#define WUR_LOOPBACK_DATA_READ 0x16
  63427. +#define WUR_SET_INTERFACE_DS 0x17
  63428. +
  63429. +/* Feature numbers */
  63430. +#define UF_ENDPOINT_HALT 0
  63431. +#define UF_DEVICE_REMOTE_WAKEUP 1
  63432. +#define UF_TEST_MODE 2
  63433. +#define UF_DEVICE_B_HNP_ENABLE 3
  63434. +#define UF_DEVICE_A_HNP_SUPPORT 4
  63435. +#define UF_DEVICE_A_ALT_HNP_SUPPORT 5
  63436. +#define WUF_WUSB 3
  63437. +#define WUF_TX_DRPIE 0x0
  63438. +#define WUF_DEV_XMIT_PACKET 0x1
  63439. +#define WUF_COUNT_PACKETS 0x2
  63440. +#define WUF_CAPTURE_PACKETS 0x3
  63441. +#define UF_FUNCTION_SUSPEND 0
  63442. +#define UF_U1_ENABLE 48
  63443. +#define UF_U2_ENABLE 49
  63444. +#define UF_LTM_ENABLE 50
  63445. +
  63446. +/* Class requests from the USB 2.0 hub spec, table 11-15 */
  63447. +#define UCR_CLEAR_HUB_FEATURE (0x2000 | UR_CLEAR_FEATURE)
  63448. +#define UCR_CLEAR_PORT_FEATURE (0x2300 | UR_CLEAR_FEATURE)
  63449. +#define UCR_GET_HUB_DESCRIPTOR (0xa000 | UR_GET_DESCRIPTOR)
  63450. +#define UCR_GET_HUB_STATUS (0xa000 | UR_GET_STATUS)
  63451. +#define UCR_GET_PORT_STATUS (0xa300 | UR_GET_STATUS)
  63452. +#define UCR_SET_HUB_FEATURE (0x2000 | UR_SET_FEATURE)
  63453. +#define UCR_SET_PORT_FEATURE (0x2300 | UR_SET_FEATURE)
  63454. +#define UCR_SET_AND_TEST_PORT_FEATURE (0xa300 | UR_SET_AND_TEST_FEATURE)
  63455. +
  63456. +#ifdef _MSC_VER
  63457. +#include <pshpack1.h>
  63458. +#endif
  63459. +
  63460. +typedef struct {
  63461. + uByte bLength;
  63462. + uByte bDescriptorType;
  63463. + uByte bDescriptorSubtype;
  63464. +} UPACKED usb_descriptor_t;
  63465. +
  63466. +typedef struct {
  63467. + uByte bLength;
  63468. + uByte bDescriptorType;
  63469. +} UPACKED usb_descriptor_header_t;
  63470. +
  63471. +typedef struct {
  63472. + uByte bLength;
  63473. + uByte bDescriptorType;
  63474. + uWord bcdUSB;
  63475. +#define UD_USB_2_0 0x0200
  63476. +#define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
  63477. + uByte bDeviceClass;
  63478. + uByte bDeviceSubClass;
  63479. + uByte bDeviceProtocol;
  63480. + uByte bMaxPacketSize;
  63481. + /* The fields below are not part of the initial descriptor. */
  63482. + uWord idVendor;
  63483. + uWord idProduct;
  63484. + uWord bcdDevice;
  63485. + uByte iManufacturer;
  63486. + uByte iProduct;
  63487. + uByte iSerialNumber;
  63488. + uByte bNumConfigurations;
  63489. +} UPACKED usb_device_descriptor_t;
  63490. +#define USB_DEVICE_DESCRIPTOR_SIZE 18
  63491. +
  63492. +typedef struct {
  63493. + uByte bLength;
  63494. + uByte bDescriptorType;
  63495. + uWord wTotalLength;
  63496. + uByte bNumInterface;
  63497. + uByte bConfigurationValue;
  63498. + uByte iConfiguration;
  63499. +#define UC_ATT_ONE (1 << 7) /* must be set */
  63500. +#define UC_ATT_SELFPOWER (1 << 6) /* self powered */
  63501. +#define UC_ATT_WAKEUP (1 << 5) /* can wakeup */
  63502. +#define UC_ATT_BATTERY (1 << 4) /* battery powered */
  63503. + uByte bmAttributes;
  63504. +#define UC_BUS_POWERED 0x80
  63505. +#define UC_SELF_POWERED 0x40
  63506. +#define UC_REMOTE_WAKEUP 0x20
  63507. + uByte bMaxPower; /* max current in 2 mA units */
  63508. +#define UC_POWER_FACTOR 2
  63509. +} UPACKED usb_config_descriptor_t;
  63510. +#define USB_CONFIG_DESCRIPTOR_SIZE 9
  63511. +
  63512. +typedef struct {
  63513. + uByte bLength;
  63514. + uByte bDescriptorType;
  63515. + uByte bInterfaceNumber;
  63516. + uByte bAlternateSetting;
  63517. + uByte bNumEndpoints;
  63518. + uByte bInterfaceClass;
  63519. + uByte bInterfaceSubClass;
  63520. + uByte bInterfaceProtocol;
  63521. + uByte iInterface;
  63522. +} UPACKED usb_interface_descriptor_t;
  63523. +#define USB_INTERFACE_DESCRIPTOR_SIZE 9
  63524. +
  63525. +typedef struct {
  63526. + uByte bLength;
  63527. + uByte bDescriptorType;
  63528. + uByte bEndpointAddress;
  63529. +#define UE_GET_DIR(a) ((a) & 0x80)
  63530. +#define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
  63531. +#define UE_DIR_IN 0x80
  63532. +#define UE_DIR_OUT 0x00
  63533. +#define UE_ADDR 0x0f
  63534. +#define UE_GET_ADDR(a) ((a) & UE_ADDR)
  63535. + uByte bmAttributes;
  63536. +#define UE_XFERTYPE 0x03
  63537. +#define UE_CONTROL 0x00
  63538. +#define UE_ISOCHRONOUS 0x01
  63539. +#define UE_BULK 0x02
  63540. +#define UE_INTERRUPT 0x03
  63541. +#define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
  63542. +#define UE_ISO_TYPE 0x0c
  63543. +#define UE_ISO_ASYNC 0x04
  63544. +#define UE_ISO_ADAPT 0x08
  63545. +#define UE_ISO_SYNC 0x0c
  63546. +#define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
  63547. + uWord wMaxPacketSize;
  63548. + uByte bInterval;
  63549. +} UPACKED usb_endpoint_descriptor_t;
  63550. +#define USB_ENDPOINT_DESCRIPTOR_SIZE 7
  63551. +
  63552. +typedef struct ss_endpoint_companion_descriptor {
  63553. + uByte bLength;
  63554. + uByte bDescriptorType;
  63555. + uByte bMaxBurst;
  63556. +#define USSE_GET_MAX_STREAMS(a) ((a) & 0x1f)
  63557. +#define USSE_SET_MAX_STREAMS(a, b) ((a) | ((b) & 0x1f))
  63558. +#define USSE_GET_MAX_PACKET_NUM(a) ((a) & 0x03)
  63559. +#define USSE_SET_MAX_PACKET_NUM(a, b) ((a) | ((b) & 0x03))
  63560. + uByte bmAttributes;
  63561. + uWord wBytesPerInterval;
  63562. +} UPACKED ss_endpoint_companion_descriptor_t;
  63563. +#define USB_SS_ENDPOINT_COMPANION_DESCRIPTOR_SIZE 6
  63564. +
  63565. +typedef struct {
  63566. + uByte bLength;
  63567. + uByte bDescriptorType;
  63568. + uWord bString[127];
  63569. +} UPACKED usb_string_descriptor_t;
  63570. +#define USB_MAX_STRING_LEN 128
  63571. +#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
  63572. +
  63573. +/* Hub specific request */
  63574. +#define UR_GET_BUS_STATE 0x02
  63575. +#define UR_CLEAR_TT_BUFFER 0x08
  63576. +#define UR_RESET_TT 0x09
  63577. +#define UR_GET_TT_STATE 0x0a
  63578. +#define UR_STOP_TT 0x0b
  63579. +
  63580. +/* Hub features */
  63581. +#define UHF_C_HUB_LOCAL_POWER 0
  63582. +#define UHF_C_HUB_OVER_CURRENT 1
  63583. +#define UHF_PORT_CONNECTION 0
  63584. +#define UHF_PORT_ENABLE 1
  63585. +#define UHF_PORT_SUSPEND 2
  63586. +#define UHF_PORT_OVER_CURRENT 3
  63587. +#define UHF_PORT_RESET 4
  63588. +#define UHF_PORT_L1 5
  63589. +#define UHF_PORT_POWER 8
  63590. +#define UHF_PORT_LOW_SPEED 9
  63591. +#define UHF_PORT_HIGH_SPEED 10
  63592. +#define UHF_C_PORT_CONNECTION 16
  63593. +#define UHF_C_PORT_ENABLE 17
  63594. +#define UHF_C_PORT_SUSPEND 18
  63595. +#define UHF_C_PORT_OVER_CURRENT 19
  63596. +#define UHF_C_PORT_RESET 20
  63597. +#define UHF_C_PORT_L1 23
  63598. +#define UHF_PORT_TEST 21
  63599. +#define UHF_PORT_INDICATOR 22
  63600. +
  63601. +typedef struct {
  63602. + uByte bDescLength;
  63603. + uByte bDescriptorType;
  63604. + uByte bNbrPorts;
  63605. + uWord wHubCharacteristics;
  63606. +#define UHD_PWR 0x0003
  63607. +#define UHD_PWR_GANGED 0x0000
  63608. +#define UHD_PWR_INDIVIDUAL 0x0001
  63609. +#define UHD_PWR_NO_SWITCH 0x0002
  63610. +#define UHD_COMPOUND 0x0004
  63611. +#define UHD_OC 0x0018
  63612. +#define UHD_OC_GLOBAL 0x0000
  63613. +#define UHD_OC_INDIVIDUAL 0x0008
  63614. +#define UHD_OC_NONE 0x0010
  63615. +#define UHD_TT_THINK 0x0060
  63616. +#define UHD_TT_THINK_8 0x0000
  63617. +#define UHD_TT_THINK_16 0x0020
  63618. +#define UHD_TT_THINK_24 0x0040
  63619. +#define UHD_TT_THINK_32 0x0060
  63620. +#define UHD_PORT_IND 0x0080
  63621. + uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  63622. +#define UHD_PWRON_FACTOR 2
  63623. + uByte bHubContrCurrent;
  63624. + uByte DeviceRemovable[32]; /* max 255 ports */
  63625. +#define UHD_NOT_REMOV(desc, i) \
  63626. + (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
  63627. + /* deprecated */ uByte PortPowerCtrlMask[1];
  63628. +} UPACKED usb_hub_descriptor_t;
  63629. +#define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
  63630. +
  63631. +typedef struct {
  63632. + uByte bLength;
  63633. + uByte bDescriptorType;
  63634. + uWord bcdUSB;
  63635. + uByte bDeviceClass;
  63636. + uByte bDeviceSubClass;
  63637. + uByte bDeviceProtocol;
  63638. + uByte bMaxPacketSize0;
  63639. + uByte bNumConfigurations;
  63640. + uByte bReserved;
  63641. +} UPACKED usb_device_qualifier_t;
  63642. +#define USB_DEVICE_QUALIFIER_SIZE 10
  63643. +
  63644. +typedef struct {
  63645. + uByte bLength;
  63646. + uByte bDescriptorType;
  63647. + uByte bmAttributes;
  63648. +#define UOTG_SRP 0x01
  63649. +#define UOTG_HNP 0x02
  63650. +} UPACKED usb_otg_descriptor_t;
  63651. +
  63652. +/* OTG feature selectors */
  63653. +#define UOTG_B_HNP_ENABLE 3
  63654. +#define UOTG_A_HNP_SUPPORT 4
  63655. +#define UOTG_A_ALT_HNP_SUPPORT 5
  63656. +
  63657. +typedef struct {
  63658. + uWord wStatus;
  63659. +/* Device status flags */
  63660. +#define UDS_SELF_POWERED 0x0001
  63661. +#define UDS_REMOTE_WAKEUP 0x0002
  63662. +/* Endpoint status flags */
  63663. +#define UES_HALT 0x0001
  63664. +} UPACKED usb_status_t;
  63665. +
  63666. +typedef struct {
  63667. + uWord wHubStatus;
  63668. +#define UHS_LOCAL_POWER 0x0001
  63669. +#define UHS_OVER_CURRENT 0x0002
  63670. + uWord wHubChange;
  63671. +} UPACKED usb_hub_status_t;
  63672. +
  63673. +typedef struct {
  63674. + uWord wPortStatus;
  63675. +#define UPS_CURRENT_CONNECT_STATUS 0x0001
  63676. +#define UPS_PORT_ENABLED 0x0002
  63677. +#define UPS_SUSPEND 0x0004
  63678. +#define UPS_OVERCURRENT_INDICATOR 0x0008
  63679. +#define UPS_RESET 0x0010
  63680. +#define UPS_PORT_POWER 0x0100
  63681. +#define UPS_LOW_SPEED 0x0200
  63682. +#define UPS_HIGH_SPEED 0x0400
  63683. +#define UPS_PORT_TEST 0x0800
  63684. +#define UPS_PORT_INDICATOR 0x1000
  63685. + uWord wPortChange;
  63686. +#define UPS_C_CONNECT_STATUS 0x0001
  63687. +#define UPS_C_PORT_ENABLED 0x0002
  63688. +#define UPS_C_SUSPEND 0x0004
  63689. +#define UPS_C_OVERCURRENT_INDICATOR 0x0008
  63690. +#define UPS_C_PORT_RESET 0x0010
  63691. +} UPACKED usb_port_status_t;
  63692. +
  63693. +#ifdef _MSC_VER
  63694. +#include <poppack.h>
  63695. +#endif
  63696. +
  63697. +/* Device class codes */
  63698. +#define UDCLASS_IN_INTERFACE 0x00
  63699. +#define UDCLASS_COMM 0x02
  63700. +#define UDCLASS_HUB 0x09
  63701. +#define UDSUBCLASS_HUB 0x00
  63702. +#define UDPROTO_FSHUB 0x00
  63703. +#define UDPROTO_HSHUBSTT 0x01
  63704. +#define UDPROTO_HSHUBMTT 0x02
  63705. +#define UDCLASS_DIAGNOSTIC 0xdc
  63706. +#define UDCLASS_WIRELESS 0xe0
  63707. +#define UDSUBCLASS_RF 0x01
  63708. +#define UDPROTO_BLUETOOTH 0x01
  63709. +#define UDCLASS_VENDOR 0xff
  63710. +
  63711. +/* Interface class codes */
  63712. +#define UICLASS_UNSPEC 0x00
  63713. +
  63714. +#define UICLASS_AUDIO 0x01
  63715. +#define UISUBCLASS_AUDIOCONTROL 1
  63716. +#define UISUBCLASS_AUDIOSTREAM 2
  63717. +#define UISUBCLASS_MIDISTREAM 3
  63718. +
  63719. +#define UICLASS_CDC 0x02 /* communication */
  63720. +#define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
  63721. +#define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
  63722. +#define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
  63723. +#define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
  63724. +#define UISUBCLASS_CAPI_CONTROLMODEL 5
  63725. +#define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
  63726. +#define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
  63727. +#define UIPROTO_CDC_AT 1
  63728. +
  63729. +#define UICLASS_HID 0x03
  63730. +#define UISUBCLASS_BOOT 1
  63731. +#define UIPROTO_BOOT_KEYBOARD 1
  63732. +
  63733. +#define UICLASS_PHYSICAL 0x05
  63734. +
  63735. +#define UICLASS_IMAGE 0x06
  63736. +
  63737. +#define UICLASS_PRINTER 0x07
  63738. +#define UISUBCLASS_PRINTER 1
  63739. +#define UIPROTO_PRINTER_UNI 1
  63740. +#define UIPROTO_PRINTER_BI 2
  63741. +#define UIPROTO_PRINTER_1284 3
  63742. +
  63743. +#define UICLASS_MASS 0x08
  63744. +#define UISUBCLASS_RBC 1
  63745. +#define UISUBCLASS_SFF8020I 2
  63746. +#define UISUBCLASS_QIC157 3
  63747. +#define UISUBCLASS_UFI 4
  63748. +#define UISUBCLASS_SFF8070I 5
  63749. +#define UISUBCLASS_SCSI 6
  63750. +#define UIPROTO_MASS_CBI_I 0
  63751. +#define UIPROTO_MASS_CBI 1
  63752. +#define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
  63753. +#define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
  63754. +
  63755. +#define UICLASS_HUB 0x09
  63756. +#define UISUBCLASS_HUB 0
  63757. +#define UIPROTO_FSHUB 0
  63758. +#define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
  63759. +#define UIPROTO_HSHUBMTT 1
  63760. +
  63761. +#define UICLASS_CDC_DATA 0x0a
  63762. +#define UISUBCLASS_DATA 0
  63763. +#define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
  63764. +#define UIPROTO_DATA_HDLC 0x31 /* HDLC */
  63765. +#define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
  63766. +#define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
  63767. +#define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
  63768. +#define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
  63769. +#define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
  63770. +#define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
  63771. +#define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
  63772. +#define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
  63773. +#define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
  63774. +#define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
  63775. +#define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
  63776. +
  63777. +#define UICLASS_SMARTCARD 0x0b
  63778. +
  63779. +/*#define UICLASS_FIRM_UPD 0x0c*/
  63780. +
  63781. +#define UICLASS_SECURITY 0x0d
  63782. +
  63783. +#define UICLASS_DIAGNOSTIC 0xdc
  63784. +
  63785. +#define UICLASS_WIRELESS 0xe0
  63786. +#define UISUBCLASS_RF 0x01
  63787. +#define UIPROTO_BLUETOOTH 0x01
  63788. +
  63789. +#define UICLASS_APPL_SPEC 0xfe
  63790. +#define UISUBCLASS_FIRMWARE_DOWNLOAD 1
  63791. +#define UISUBCLASS_IRDA 2
  63792. +#define UIPROTO_IRDA 0
  63793. +
  63794. +#define UICLASS_VENDOR 0xff
  63795. +
  63796. +#define USB_HUB_MAX_DEPTH 5
  63797. +
  63798. +/*
  63799. + * Minimum time a device needs to be powered down to go through
  63800. + * a power cycle. XXX Are these time in the spec?
  63801. + */
  63802. +#define USB_POWER_DOWN_TIME 200 /* ms */
  63803. +#define USB_PORT_POWER_DOWN_TIME 100 /* ms */
  63804. +
  63805. +#if 0
  63806. +/* These are the values from the spec. */
  63807. +#define USB_PORT_RESET_DELAY 10 /* ms */
  63808. +#define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
  63809. +#define USB_PORT_RESET_RECOVERY 10 /* ms */
  63810. +#define USB_PORT_POWERUP_DELAY 100 /* ms */
  63811. +#define USB_SET_ADDRESS_SETTLE 2 /* ms */
  63812. +#define USB_RESUME_DELAY (20*5) /* ms */
  63813. +#define USB_RESUME_WAIT 10 /* ms */
  63814. +#define USB_RESUME_RECOVERY 10 /* ms */
  63815. +#define USB_EXTRA_POWER_UP_TIME 0 /* ms */
  63816. +#else
  63817. +/* Allow for marginal (i.e. non-conforming) devices. */
  63818. +#define USB_PORT_RESET_DELAY 50 /* ms */
  63819. +#define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
  63820. +#define USB_PORT_RESET_RECOVERY 250 /* ms */
  63821. +#define USB_PORT_POWERUP_DELAY 300 /* ms */
  63822. +#define USB_SET_ADDRESS_SETTLE 10 /* ms */
  63823. +#define USB_RESUME_DELAY (50*5) /* ms */
  63824. +#define USB_RESUME_WAIT 50 /* ms */
  63825. +#define USB_RESUME_RECOVERY 50 /* ms */
  63826. +#define USB_EXTRA_POWER_UP_TIME 20 /* ms */
  63827. +#endif
  63828. +
  63829. +#define USB_MIN_POWER 100 /* mA */
  63830. +#define USB_MAX_POWER 500 /* mA */
  63831. +
  63832. +#define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
  63833. +
  63834. +#define USB_UNCONFIG_NO 0
  63835. +#define USB_UNCONFIG_INDEX (-1)
  63836. +
  63837. +/*** ioctl() related stuff ***/
  63838. +
  63839. +struct usb_ctl_request {
  63840. + int ucr_addr;
  63841. + usb_device_request_t ucr_request;
  63842. + void *ucr_data;
  63843. + int ucr_flags;
  63844. +#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
  63845. + int ucr_actlen; /* actual length transferred */
  63846. +};
  63847. +
  63848. +struct usb_alt_interface {
  63849. + int uai_config_index;
  63850. + int uai_interface_index;
  63851. + int uai_alt_no;
  63852. +};
  63853. +
  63854. +#define USB_CURRENT_CONFIG_INDEX (-1)
  63855. +#define USB_CURRENT_ALT_INDEX (-1)
  63856. +
  63857. +struct usb_config_desc {
  63858. + int ucd_config_index;
  63859. + usb_config_descriptor_t ucd_desc;
  63860. +};
  63861. +
  63862. +struct usb_interface_desc {
  63863. + int uid_config_index;
  63864. + int uid_interface_index;
  63865. + int uid_alt_index;
  63866. + usb_interface_descriptor_t uid_desc;
  63867. +};
  63868. +
  63869. +struct usb_endpoint_desc {
  63870. + int ued_config_index;
  63871. + int ued_interface_index;
  63872. + int ued_alt_index;
  63873. + int ued_endpoint_index;
  63874. + usb_endpoint_descriptor_t ued_desc;
  63875. +};
  63876. +
  63877. +struct usb_full_desc {
  63878. + int ufd_config_index;
  63879. + u_int ufd_size;
  63880. + u_char *ufd_data;
  63881. +};
  63882. +
  63883. +struct usb_string_desc {
  63884. + int usd_string_index;
  63885. + int usd_language_id;
  63886. + usb_string_descriptor_t usd_desc;
  63887. +};
  63888. +
  63889. +struct usb_ctl_report_desc {
  63890. + int ucrd_size;
  63891. + u_char ucrd_data[1024]; /* filled data size will vary */
  63892. +};
  63893. +
  63894. +typedef struct { u_int32_t cookie; } usb_event_cookie_t;
  63895. +
  63896. +#define USB_MAX_DEVNAMES 4
  63897. +#define USB_MAX_DEVNAMELEN 16
  63898. +struct usb_device_info {
  63899. + u_int8_t udi_bus;
  63900. + u_int8_t udi_addr; /* device address */
  63901. + usb_event_cookie_t udi_cookie;
  63902. + char udi_product[USB_MAX_STRING_LEN];
  63903. + char udi_vendor[USB_MAX_STRING_LEN];
  63904. + char udi_release[8];
  63905. + u_int16_t udi_productNo;
  63906. + u_int16_t udi_vendorNo;
  63907. + u_int16_t udi_releaseNo;
  63908. + u_int8_t udi_class;
  63909. + u_int8_t udi_subclass;
  63910. + u_int8_t udi_protocol;
  63911. + u_int8_t udi_config;
  63912. + u_int8_t udi_speed;
  63913. +#define USB_SPEED_UNKNOWN 0
  63914. +#define USB_SPEED_LOW 1
  63915. +#define USB_SPEED_FULL 2
  63916. +#define USB_SPEED_HIGH 3
  63917. +#define USB_SPEED_VARIABLE 4
  63918. +#define USB_SPEED_SUPER 5
  63919. + int udi_power; /* power consumption in mA, 0 if selfpowered */
  63920. + int udi_nports;
  63921. + char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
  63922. + u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
  63923. +#define USB_PORT_ENABLED 0xff
  63924. +#define USB_PORT_SUSPENDED 0xfe
  63925. +#define USB_PORT_POWERED 0xfd
  63926. +#define USB_PORT_DISABLED 0xfc
  63927. +};
  63928. +
  63929. +struct usb_ctl_report {
  63930. + int ucr_report;
  63931. + u_char ucr_data[1024]; /* filled data size will vary */
  63932. +};
  63933. +
  63934. +struct usb_device_stats {
  63935. + u_long uds_requests[4]; /* indexed by transfer type UE_* */
  63936. +};
  63937. +
  63938. +#define WUSB_MIN_IE 0x80
  63939. +#define WUSB_WCTA_IE 0x80
  63940. +#define WUSB_WCONNECTACK_IE 0x81
  63941. +#define WUSB_WHOSTINFO_IE 0x82
  63942. +#define WUHI_GET_CA(_bmAttributes_) ((_bmAttributes_) & 0x3)
  63943. +#define WUHI_CA_RECONN 0x00
  63944. +#define WUHI_CA_LIMITED 0x01
  63945. +#define WUHI_CA_ALL 0x03
  63946. +#define WUHI_GET_MLSI(_bmAttributes_) (((_bmAttributes_) & 0x38) >> 3)
  63947. +#define WUSB_WCHCHANGEANNOUNCE_IE 0x83
  63948. +#define WUSB_WDEV_DISCONNECT_IE 0x84
  63949. +#define WUSB_WHOST_DISCONNECT_IE 0x85
  63950. +#define WUSB_WRELEASE_CHANNEL_IE 0x86
  63951. +#define WUSB_WWORK_IE 0x87
  63952. +#define WUSB_WCHANNEL_STOP_IE 0x88
  63953. +#define WUSB_WDEV_KEEPALIVE_IE 0x89
  63954. +#define WUSB_WISOCH_DISCARD_IE 0x8A
  63955. +#define WUSB_WRESETDEVICE_IE 0x8B
  63956. +#define WUSB_WXMIT_PACKET_ADJUST_IE 0x8C
  63957. +#define WUSB_MAX_IE 0x8C
  63958. +
  63959. +/* Device Notification Types */
  63960. +
  63961. +#define WUSB_DN_MIN 0x01
  63962. +#define WUSB_DN_CONNECT 0x01
  63963. +# define WUSB_DA_OLDCONN 0x00
  63964. +# define WUSB_DA_NEWCONN 0x01
  63965. +# define WUSB_DA_SELF_BEACON 0x02
  63966. +# define WUSB_DA_DIR_BEACON 0x04
  63967. +# define WUSB_DA_NO_BEACON 0x06
  63968. +#define WUSB_DN_DISCONNECT 0x02
  63969. +#define WUSB_DN_EPRDY 0x03
  63970. +#define WUSB_DN_MASAVAILCHANGED 0x04
  63971. +#define WUSB_DN_REMOTEWAKEUP 0x05
  63972. +#define WUSB_DN_SLEEP 0x06
  63973. +#define WUSB_DN_ALIVE 0x07
  63974. +#define WUSB_DN_MAX 0x07
  63975. +
  63976. +#ifdef _MSC_VER
  63977. +#include <pshpack1.h>
  63978. +#endif
  63979. +
  63980. +/* WUSB Handshake Data. Used during the SET/GET HANDSHAKE requests */
  63981. +typedef struct wusb_hndshk_data {
  63982. + uByte bMessageNumber;
  63983. + uByte bStatus;
  63984. + uByte tTKID[3];
  63985. + uByte bReserved;
  63986. + uByte CDID[16];
  63987. + uByte Nonce[16];
  63988. + uByte MIC[8];
  63989. +} UPACKED wusb_hndshk_data_t;
  63990. +#define WUSB_HANDSHAKE_LEN_FOR_MIC 38
  63991. +
  63992. +/* WUSB Connection Context */
  63993. +typedef struct wusb_conn_context {
  63994. + uByte CHID [16];
  63995. + uByte CDID [16];
  63996. + uByte CK [16];
  63997. +} UPACKED wusb_conn_context_t;
  63998. +
  63999. +/* WUSB Security Descriptor */
  64000. +typedef struct wusb_security_desc {
  64001. + uByte bLength;
  64002. + uByte bDescriptorType;
  64003. + uWord wTotalLength;
  64004. + uByte bNumEncryptionTypes;
  64005. +} UPACKED wusb_security_desc_t;
  64006. +
  64007. +/* WUSB Encryption Type Descriptor */
  64008. +typedef struct wusb_encrypt_type_desc {
  64009. + uByte bLength;
  64010. + uByte bDescriptorType;
  64011. +
  64012. + uByte bEncryptionType;
  64013. +#define WUETD_UNSECURE 0
  64014. +#define WUETD_WIRED 1
  64015. +#define WUETD_CCM_1 2
  64016. +#define WUETD_RSA_1 3
  64017. +
  64018. + uByte bEncryptionValue;
  64019. + uByte bAuthKeyIndex;
  64020. +} UPACKED wusb_encrypt_type_desc_t;
  64021. +
  64022. +/* WUSB Key Descriptor */
  64023. +typedef struct wusb_key_desc {
  64024. + uByte bLength;
  64025. + uByte bDescriptorType;
  64026. + uByte tTKID[3];
  64027. + uByte bReserved;
  64028. + uByte KeyData[1]; /* variable length */
  64029. +} UPACKED wusb_key_desc_t;
  64030. +
  64031. +/* WUSB BOS Descriptor (Binary device Object Store) */
  64032. +typedef struct wusb_bos_desc {
  64033. + uByte bLength;
  64034. + uByte bDescriptorType;
  64035. + uWord wTotalLength;
  64036. + uByte bNumDeviceCaps;
  64037. +} UPACKED wusb_bos_desc_t;
  64038. +
  64039. +#define USB_DEVICE_CAPABILITY_20_EXTENSION 0x02
  64040. +typedef struct usb_dev_cap_20_ext_desc {
  64041. + uByte bLength;
  64042. + uByte bDescriptorType;
  64043. + uByte bDevCapabilityType;
  64044. +#define USB_20_EXT_LPM 0x02
  64045. + uDWord bmAttributes;
  64046. +} UPACKED usb_dev_cap_20_ext_desc_t;
  64047. +
  64048. +#define USB_DEVICE_CAPABILITY_SS_USB 0x03
  64049. +typedef struct usb_dev_cap_ss_usb {
  64050. + uByte bLength;
  64051. + uByte bDescriptorType;
  64052. + uByte bDevCapabilityType;
  64053. +#define USB_DC_SS_USB_LTM_CAPABLE 0x02
  64054. + uByte bmAttributes;
  64055. +#define USB_DC_SS_USB_SPEED_SUPPORT_LOW 0x01
  64056. +#define USB_DC_SS_USB_SPEED_SUPPORT_FULL 0x02
  64057. +#define USB_DC_SS_USB_SPEED_SUPPORT_HIGH 0x04
  64058. +#define USB_DC_SS_USB_SPEED_SUPPORT_SS 0x08
  64059. + uWord wSpeedsSupported;
  64060. + uByte bFunctionalitySupport;
  64061. + uByte bU1DevExitLat;
  64062. + uWord wU2DevExitLat;
  64063. +} UPACKED usb_dev_cap_ss_usb_t;
  64064. +
  64065. +#define USB_DEVICE_CAPABILITY_CONTAINER_ID 0x04
  64066. +typedef struct usb_dev_cap_container_id {
  64067. + uByte bLength;
  64068. + uByte bDescriptorType;
  64069. + uByte bDevCapabilityType;
  64070. + uByte bReserved;
  64071. + uByte containerID[16];
  64072. +} UPACKED usb_dev_cap_container_id_t;
  64073. +
  64074. +/* Device Capability Type Codes */
  64075. +#define WUSB_DEVICE_CAPABILITY_WIRELESS_USB 0x01
  64076. +
  64077. +/* Device Capability Descriptor */
  64078. +typedef struct wusb_dev_cap_desc {
  64079. + uByte bLength;
  64080. + uByte bDescriptorType;
  64081. + uByte bDevCapabilityType;
  64082. + uByte caps[1]; /* Variable length */
  64083. +} UPACKED wusb_dev_cap_desc_t;
  64084. +
  64085. +/* Device Capability Descriptor */
  64086. +typedef struct wusb_dev_cap_uwb_desc {
  64087. + uByte bLength;
  64088. + uByte bDescriptorType;
  64089. + uByte bDevCapabilityType;
  64090. + uByte bmAttributes;
  64091. + uWord wPHYRates; /* Bitmap */
  64092. + uByte bmTFITXPowerInfo;
  64093. + uByte bmFFITXPowerInfo;
  64094. + uWord bmBandGroup;
  64095. + uByte bReserved;
  64096. +} UPACKED wusb_dev_cap_uwb_desc_t;
  64097. +
  64098. +/* Wireless USB Endpoint Companion Descriptor */
  64099. +typedef struct wusb_endpoint_companion_desc {
  64100. + uByte bLength;
  64101. + uByte bDescriptorType;
  64102. + uByte bMaxBurst;
  64103. + uByte bMaxSequence;
  64104. + uWord wMaxStreamDelay;
  64105. + uWord wOverTheAirPacketSize;
  64106. + uByte bOverTheAirInterval;
  64107. + uByte bmCompAttributes;
  64108. +} UPACKED wusb_endpoint_companion_desc_t;
  64109. +
  64110. +/* Wireless USB Numeric Association M1 Data Structure */
  64111. +typedef struct wusb_m1_data {
  64112. + uByte version;
  64113. + uWord langId;
  64114. + uByte deviceFriendlyNameLength;
  64115. + uByte sha_256_m3[32];
  64116. + uByte deviceFriendlyName[256];
  64117. +} UPACKED wusb_m1_data_t;
  64118. +
  64119. +typedef struct wusb_m2_data {
  64120. + uByte version;
  64121. + uWord langId;
  64122. + uByte hostFriendlyNameLength;
  64123. + uByte pkh[384];
  64124. + uByte hostFriendlyName[256];
  64125. +} UPACKED wusb_m2_data_t;
  64126. +
  64127. +typedef struct wusb_m3_data {
  64128. + uByte pkd[384];
  64129. + uByte nd;
  64130. +} UPACKED wusb_m3_data_t;
  64131. +
  64132. +typedef struct wusb_m4_data {
  64133. + uDWord _attributeTypeIdAndLength_1;
  64134. + uWord associationTypeId;
  64135. +
  64136. + uDWord _attributeTypeIdAndLength_2;
  64137. + uWord associationSubTypeId;
  64138. +
  64139. + uDWord _attributeTypeIdAndLength_3;
  64140. + uDWord length;
  64141. +
  64142. + uDWord _attributeTypeIdAndLength_4;
  64143. + uDWord associationStatus;
  64144. +
  64145. + uDWord _attributeTypeIdAndLength_5;
  64146. + uByte chid[16];
  64147. +
  64148. + uDWord _attributeTypeIdAndLength_6;
  64149. + uByte cdid[16];
  64150. +
  64151. + uDWord _attributeTypeIdAndLength_7;
  64152. + uByte bandGroups[2];
  64153. +} UPACKED wusb_m4_data_t;
  64154. +
  64155. +#ifdef _MSC_VER
  64156. +#include <poppack.h>
  64157. +#endif
  64158. +
  64159. +#ifdef __cplusplus
  64160. +}
  64161. +#endif
  64162. +
  64163. +#endif /* _USB_H_ */
  64164. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/doc/doxygen.cfg linux-rpi/drivers/usb/host/dwc_otg/doc/doxygen.cfg
  64165. --- linux-3.18.6/drivers/usb/host/dwc_otg/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  64166. +++ linux-rpi/drivers/usb/host/dwc_otg/doc/doxygen.cfg 2015-02-09 04:40:28.000000000 +0100
  64167. @@ -0,0 +1,224 @@
  64168. +# Doxyfile 1.3.9.1
  64169. +
  64170. +#---------------------------------------------------------------------------
  64171. +# Project related configuration options
  64172. +#---------------------------------------------------------------------------
  64173. +PROJECT_NAME = "DesignWare USB 2.0 OTG Controller (DWC_otg) Device Driver"
  64174. +PROJECT_NUMBER = v3.00a
  64175. +OUTPUT_DIRECTORY = ./doc/
  64176. +CREATE_SUBDIRS = NO
  64177. +OUTPUT_LANGUAGE = English
  64178. +BRIEF_MEMBER_DESC = YES
  64179. +REPEAT_BRIEF = YES
  64180. +ABBREVIATE_BRIEF = "The $name class" \
  64181. + "The $name widget" \
  64182. + "The $name file" \
  64183. + is \
  64184. + provides \
  64185. + specifies \
  64186. + contains \
  64187. + represents \
  64188. + a \
  64189. + an \
  64190. + the
  64191. +ALWAYS_DETAILED_SEC = NO
  64192. +INLINE_INHERITED_MEMB = NO
  64193. +FULL_PATH_NAMES = NO
  64194. +STRIP_FROM_PATH =
  64195. +STRIP_FROM_INC_PATH =
  64196. +SHORT_NAMES = NO
  64197. +JAVADOC_AUTOBRIEF = YES
  64198. +MULTILINE_CPP_IS_BRIEF = NO
  64199. +INHERIT_DOCS = YES
  64200. +DISTRIBUTE_GROUP_DOC = NO
  64201. +TAB_SIZE = 8
  64202. +ALIASES =
  64203. +OPTIMIZE_OUTPUT_FOR_C = YES
  64204. +OPTIMIZE_OUTPUT_JAVA = NO
  64205. +SUBGROUPING = YES
  64206. +#---------------------------------------------------------------------------
  64207. +# Build related configuration options
  64208. +#---------------------------------------------------------------------------
  64209. +EXTRACT_ALL = NO
  64210. +EXTRACT_PRIVATE = YES
  64211. +EXTRACT_STATIC = YES
  64212. +EXTRACT_LOCAL_CLASSES = YES
  64213. +EXTRACT_LOCAL_METHODS = NO
  64214. +HIDE_UNDOC_MEMBERS = NO
  64215. +HIDE_UNDOC_CLASSES = NO
  64216. +HIDE_FRIEND_COMPOUNDS = NO
  64217. +HIDE_IN_BODY_DOCS = NO
  64218. +INTERNAL_DOCS = NO
  64219. +CASE_SENSE_NAMES = NO
  64220. +HIDE_SCOPE_NAMES = NO
  64221. +SHOW_INCLUDE_FILES = YES
  64222. +INLINE_INFO = YES
  64223. +SORT_MEMBER_DOCS = NO
  64224. +SORT_BRIEF_DOCS = NO
  64225. +SORT_BY_SCOPE_NAME = NO
  64226. +GENERATE_TODOLIST = YES
  64227. +GENERATE_TESTLIST = YES
  64228. +GENERATE_BUGLIST = YES
  64229. +GENERATE_DEPRECATEDLIST= YES
  64230. +ENABLED_SECTIONS =
  64231. +MAX_INITIALIZER_LINES = 30
  64232. +SHOW_USED_FILES = YES
  64233. +SHOW_DIRECTORIES = YES
  64234. +#---------------------------------------------------------------------------
  64235. +# configuration options related to warning and progress messages
  64236. +#---------------------------------------------------------------------------
  64237. +QUIET = YES
  64238. +WARNINGS = YES
  64239. +WARN_IF_UNDOCUMENTED = NO
  64240. +WARN_IF_DOC_ERROR = YES
  64241. +WARN_FORMAT = "$file:$line: $text"
  64242. +WARN_LOGFILE =
  64243. +#---------------------------------------------------------------------------
  64244. +# configuration options related to the input files
  64245. +#---------------------------------------------------------------------------
  64246. +INPUT = .
  64247. +FILE_PATTERNS = *.c \
  64248. + *.h \
  64249. + ./linux/*.c \
  64250. + ./linux/*.h
  64251. +RECURSIVE = NO
  64252. +EXCLUDE = ./test/ \
  64253. + ./dwc_otg/.AppleDouble/
  64254. +EXCLUDE_SYMLINKS = YES
  64255. +EXCLUDE_PATTERNS = *.mod.*
  64256. +EXAMPLE_PATH =
  64257. +EXAMPLE_PATTERNS = *
  64258. +EXAMPLE_RECURSIVE = NO
  64259. +IMAGE_PATH =
  64260. +INPUT_FILTER =
  64261. +FILTER_PATTERNS =
  64262. +FILTER_SOURCE_FILES = NO
  64263. +#---------------------------------------------------------------------------
  64264. +# configuration options related to source browsing
  64265. +#---------------------------------------------------------------------------
  64266. +SOURCE_BROWSER = YES
  64267. +INLINE_SOURCES = NO
  64268. +STRIP_CODE_COMMENTS = YES
  64269. +REFERENCED_BY_RELATION = NO
  64270. +REFERENCES_RELATION = NO
  64271. +VERBATIM_HEADERS = NO
  64272. +#---------------------------------------------------------------------------
  64273. +# configuration options related to the alphabetical class index
  64274. +#---------------------------------------------------------------------------
  64275. +ALPHABETICAL_INDEX = NO
  64276. +COLS_IN_ALPHA_INDEX = 5
  64277. +IGNORE_PREFIX =
  64278. +#---------------------------------------------------------------------------
  64279. +# configuration options related to the HTML output
  64280. +#---------------------------------------------------------------------------
  64281. +GENERATE_HTML = YES
  64282. +HTML_OUTPUT = html
  64283. +HTML_FILE_EXTENSION = .html
  64284. +HTML_HEADER =
  64285. +HTML_FOOTER =
  64286. +HTML_STYLESHEET =
  64287. +HTML_ALIGN_MEMBERS = YES
  64288. +GENERATE_HTMLHELP = NO
  64289. +CHM_FILE =
  64290. +HHC_LOCATION =
  64291. +GENERATE_CHI = NO
  64292. +BINARY_TOC = NO
  64293. +TOC_EXPAND = NO
  64294. +DISABLE_INDEX = NO
  64295. +ENUM_VALUES_PER_LINE = 4
  64296. +GENERATE_TREEVIEW = YES
  64297. +TREEVIEW_WIDTH = 250
  64298. +#---------------------------------------------------------------------------
  64299. +# configuration options related to the LaTeX output
  64300. +#---------------------------------------------------------------------------
  64301. +GENERATE_LATEX = NO
  64302. +LATEX_OUTPUT = latex
  64303. +LATEX_CMD_NAME = latex
  64304. +MAKEINDEX_CMD_NAME = makeindex
  64305. +COMPACT_LATEX = NO
  64306. +PAPER_TYPE = a4wide
  64307. +EXTRA_PACKAGES =
  64308. +LATEX_HEADER =
  64309. +PDF_HYPERLINKS = NO
  64310. +USE_PDFLATEX = NO
  64311. +LATEX_BATCHMODE = NO
  64312. +LATEX_HIDE_INDICES = NO
  64313. +#---------------------------------------------------------------------------
  64314. +# configuration options related to the RTF output
  64315. +#---------------------------------------------------------------------------
  64316. +GENERATE_RTF = NO
  64317. +RTF_OUTPUT = rtf
  64318. +COMPACT_RTF = NO
  64319. +RTF_HYPERLINKS = NO
  64320. +RTF_STYLESHEET_FILE =
  64321. +RTF_EXTENSIONS_FILE =
  64322. +#---------------------------------------------------------------------------
  64323. +# configuration options related to the man page output
  64324. +#---------------------------------------------------------------------------
  64325. +GENERATE_MAN = NO
  64326. +MAN_OUTPUT = man
  64327. +MAN_EXTENSION = .3
  64328. +MAN_LINKS = NO
  64329. +#---------------------------------------------------------------------------
  64330. +# configuration options related to the XML output
  64331. +#---------------------------------------------------------------------------
  64332. +GENERATE_XML = NO
  64333. +XML_OUTPUT = xml
  64334. +XML_SCHEMA =
  64335. +XML_DTD =
  64336. +XML_PROGRAMLISTING = YES
  64337. +#---------------------------------------------------------------------------
  64338. +# configuration options for the AutoGen Definitions output
  64339. +#---------------------------------------------------------------------------
  64340. +GENERATE_AUTOGEN_DEF = NO
  64341. +#---------------------------------------------------------------------------
  64342. +# configuration options related to the Perl module output
  64343. +#---------------------------------------------------------------------------
  64344. +GENERATE_PERLMOD = NO
  64345. +PERLMOD_LATEX = NO
  64346. +PERLMOD_PRETTY = YES
  64347. +PERLMOD_MAKEVAR_PREFIX =
  64348. +#---------------------------------------------------------------------------
  64349. +# Configuration options related to the preprocessor
  64350. +#---------------------------------------------------------------------------
  64351. +ENABLE_PREPROCESSING = YES
  64352. +MACRO_EXPANSION = YES
  64353. +EXPAND_ONLY_PREDEF = YES
  64354. +SEARCH_INCLUDES = YES
  64355. +INCLUDE_PATH =
  64356. +INCLUDE_FILE_PATTERNS =
  64357. +PREDEFINED = DEVICE_ATTR DWC_EN_ISOC
  64358. +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
  64359. +SKIP_FUNCTION_MACROS = NO
  64360. +#---------------------------------------------------------------------------
  64361. +# Configuration::additions related to external references
  64362. +#---------------------------------------------------------------------------
  64363. +TAGFILES =
  64364. +GENERATE_TAGFILE =
  64365. +ALLEXTERNALS = NO
  64366. +EXTERNAL_GROUPS = YES
  64367. +PERL_PATH = /usr/bin/perl
  64368. +#---------------------------------------------------------------------------
  64369. +# Configuration options related to the dot tool
  64370. +#---------------------------------------------------------------------------
  64371. +CLASS_DIAGRAMS = YES
  64372. +HIDE_UNDOC_RELATIONS = YES
  64373. +HAVE_DOT = NO
  64374. +CLASS_GRAPH = YES
  64375. +COLLABORATION_GRAPH = YES
  64376. +UML_LOOK = NO
  64377. +TEMPLATE_RELATIONS = NO
  64378. +INCLUDE_GRAPH = YES
  64379. +INCLUDED_BY_GRAPH = YES
  64380. +CALL_GRAPH = NO
  64381. +GRAPHICAL_HIERARCHY = YES
  64382. +DOT_IMAGE_FORMAT = png
  64383. +DOT_PATH =
  64384. +DOTFILE_DIRS =
  64385. +MAX_DOT_GRAPH_DEPTH = 1000
  64386. +GENERATE_LEGEND = YES
  64387. +DOT_CLEANUP = YES
  64388. +#---------------------------------------------------------------------------
  64389. +# Configuration::additions related to the search engine
  64390. +#---------------------------------------------------------------------------
  64391. +SEARCHENGINE = NO
  64392. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dummy_audio.c linux-rpi/drivers/usb/host/dwc_otg/dummy_audio.c
  64393. --- linux-3.18.6/drivers/usb/host/dwc_otg/dummy_audio.c 1970-01-01 01:00:00.000000000 +0100
  64394. +++ linux-rpi/drivers/usb/host/dwc_otg/dummy_audio.c 2015-02-09 04:40:29.000000000 +0100
  64395. @@ -0,0 +1,1575 @@
  64396. +/*
  64397. + * zero.c -- Gadget Zero, for USB development
  64398. + *
  64399. + * Copyright (C) 2003-2004 David Brownell
  64400. + * All rights reserved.
  64401. + *
  64402. + * Redistribution and use in source and binary forms, with or without
  64403. + * modification, are permitted provided that the following conditions
  64404. + * are met:
  64405. + * 1. Redistributions of source code must retain the above copyright
  64406. + * notice, this list of conditions, and the following disclaimer,
  64407. + * without modification.
  64408. + * 2. Redistributions in binary form must reproduce the above copyright
  64409. + * notice, this list of conditions and the following disclaimer in the
  64410. + * documentation and/or other materials provided with the distribution.
  64411. + * 3. The names of the above-listed copyright holders may not be used
  64412. + * to endorse or promote products derived from this software without
  64413. + * specific prior written permission.
  64414. + *
  64415. + * ALTERNATIVELY, this software may be distributed under the terms of the
  64416. + * GNU General Public License ("GPL") as published by the Free Software
  64417. + * Foundation, either version 2 of that License or (at your option) any
  64418. + * later version.
  64419. + *
  64420. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  64421. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  64422. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  64423. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  64424. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  64425. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  64426. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  64427. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  64428. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  64429. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  64430. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  64431. + */
  64432. +
  64433. +
  64434. +/*
  64435. + * Gadget Zero only needs two bulk endpoints, and is an example of how you
  64436. + * can write a hardware-agnostic gadget driver running inside a USB device.
  64437. + *
  64438. + * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
  64439. + * affect most of the driver.
  64440. + *
  64441. + * Use it with the Linux host/master side "usbtest" driver to get a basic
  64442. + * functional test of your device-side usb stack, or with "usb-skeleton".
  64443. + *
  64444. + * It supports two similar configurations. One sinks whatever the usb host
  64445. + * writes, and in return sources zeroes. The other loops whatever the host
  64446. + * writes back, so the host can read it. Module options include:
  64447. + *
  64448. + * buflen=N default N=4096, buffer size used
  64449. + * qlen=N default N=32, how many buffers in the loopback queue
  64450. + * loopdefault default false, list loopback config first
  64451. + *
  64452. + * Many drivers will only have one configuration, letting them be much
  64453. + * simpler if they also don't support high speed operation (like this
  64454. + * driver does).
  64455. + */
  64456. +
  64457. +#include <linux/config.h>
  64458. +#include <linux/module.h>
  64459. +#include <linux/kernel.h>
  64460. +#include <linux/delay.h>
  64461. +#include <linux/ioport.h>
  64462. +#include <linux/sched.h>
  64463. +#include <linux/slab.h>
  64464. +#include <linux/smp_lock.h>
  64465. +#include <linux/errno.h>
  64466. +#include <linux/init.h>
  64467. +#include <linux/timer.h>
  64468. +#include <linux/list.h>
  64469. +#include <linux/interrupt.h>
  64470. +#include <linux/uts.h>
  64471. +#include <linux/version.h>
  64472. +#include <linux/device.h>
  64473. +#include <linux/moduleparam.h>
  64474. +#include <linux/proc_fs.h>
  64475. +
  64476. +#include <asm/byteorder.h>
  64477. +#include <asm/io.h>
  64478. +#include <asm/irq.h>
  64479. +#include <asm/system.h>
  64480. +#include <asm/unaligned.h>
  64481. +
  64482. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  64483. +# include <linux/usb/ch9.h>
  64484. +#else
  64485. +# include <linux/usb_ch9.h>
  64486. +#endif
  64487. +
  64488. +#include <linux/usb_gadget.h>
  64489. +
  64490. +
  64491. +/*-------------------------------------------------------------------------*/
  64492. +/*-------------------------------------------------------------------------*/
  64493. +
  64494. +
  64495. +static int utf8_to_utf16le(const char *s, u16 *cp, unsigned len)
  64496. +{
  64497. + int count = 0;
  64498. + u8 c;
  64499. + u16 uchar;
  64500. +
  64501. + /* this insists on correct encodings, though not minimal ones.
  64502. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  64503. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  64504. + */
  64505. + while (len != 0 && (c = (u8) *s++) != 0) {
  64506. + if (unlikely(c & 0x80)) {
  64507. + // 2-byte sequence:
  64508. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  64509. + if ((c & 0xe0) == 0xc0) {
  64510. + uchar = (c & 0x1f) << 6;
  64511. +
  64512. + c = (u8) *s++;
  64513. + if ((c & 0xc0) != 0xc0)
  64514. + goto fail;
  64515. + c &= 0x3f;
  64516. + uchar |= c;
  64517. +
  64518. + // 3-byte sequence (most CJKV characters):
  64519. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  64520. + } else if ((c & 0xf0) == 0xe0) {
  64521. + uchar = (c & 0x0f) << 12;
  64522. +
  64523. + c = (u8) *s++;
  64524. + if ((c & 0xc0) != 0xc0)
  64525. + goto fail;
  64526. + c &= 0x3f;
  64527. + uchar |= c << 6;
  64528. +
  64529. + c = (u8) *s++;
  64530. + if ((c & 0xc0) != 0xc0)
  64531. + goto fail;
  64532. + c &= 0x3f;
  64533. + uchar |= c;
  64534. +
  64535. + /* no bogus surrogates */
  64536. + if (0xd800 <= uchar && uchar <= 0xdfff)
  64537. + goto fail;
  64538. +
  64539. + // 4-byte sequence (surrogate pairs, currently rare):
  64540. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  64541. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  64542. + // (uuuuu = wwww + 1)
  64543. + // FIXME accept the surrogate code points (only)
  64544. +
  64545. + } else
  64546. + goto fail;
  64547. + } else
  64548. + uchar = c;
  64549. + put_unaligned (cpu_to_le16 (uchar), cp++);
  64550. + count++;
  64551. + len--;
  64552. + }
  64553. + return count;
  64554. +fail:
  64555. + return -1;
  64556. +}
  64557. +
  64558. +
  64559. +/**
  64560. + * usb_gadget_get_string - fill out a string descriptor
  64561. + * @table: of c strings encoded using UTF-8
  64562. + * @id: string id, from low byte of wValue in get string descriptor
  64563. + * @buf: at least 256 bytes
  64564. + *
  64565. + * Finds the UTF-8 string matching the ID, and converts it into a
  64566. + * string descriptor in utf16-le.
  64567. + * Returns length of descriptor (always even) or negative errno
  64568. + *
  64569. + * If your driver needs stings in multiple languages, you'll probably
  64570. + * "switch (wIndex) { ... }" in your ep0 string descriptor logic,
  64571. + * using this routine after choosing which set of UTF-8 strings to use.
  64572. + * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
  64573. + * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
  64574. + * characters (which are also widely used in C strings).
  64575. + */
  64576. +int
  64577. +usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
  64578. +{
  64579. + struct usb_string *s;
  64580. + int len;
  64581. +
  64582. + /* descriptor 0 has the language id */
  64583. + if (id == 0) {
  64584. + buf [0] = 4;
  64585. + buf [1] = USB_DT_STRING;
  64586. + buf [2] = (u8) table->language;
  64587. + buf [3] = (u8) (table->language >> 8);
  64588. + return 4;
  64589. + }
  64590. + for (s = table->strings; s && s->s; s++)
  64591. + if (s->id == id)
  64592. + break;
  64593. +
  64594. + /* unrecognized: stall. */
  64595. + if (!s || !s->s)
  64596. + return -EINVAL;
  64597. +
  64598. + /* string descriptors have length, tag, then UTF16-LE text */
  64599. + len = min ((size_t) 126, strlen (s->s));
  64600. + memset (buf + 2, 0, 2 * len); /* zero all the bytes */
  64601. + len = utf8_to_utf16le(s->s, (u16 *)&buf[2], len);
  64602. + if (len < 0)
  64603. + return -EINVAL;
  64604. + buf [0] = (len + 1) * 2;
  64605. + buf [1] = USB_DT_STRING;
  64606. + return buf [0];
  64607. +}
  64608. +
  64609. +
  64610. +/*-------------------------------------------------------------------------*/
  64611. +/*-------------------------------------------------------------------------*/
  64612. +
  64613. +
  64614. +/**
  64615. + * usb_descriptor_fillbuf - fill buffer with descriptors
  64616. + * @buf: Buffer to be filled
  64617. + * @buflen: Size of buf
  64618. + * @src: Array of descriptor pointers, terminated by null pointer.
  64619. + *
  64620. + * Copies descriptors into the buffer, returning the length or a
  64621. + * negative error code if they can't all be copied. Useful when
  64622. + * assembling descriptors for an associated set of interfaces used
  64623. + * as part of configuring a composite device; or in other cases where
  64624. + * sets of descriptors need to be marshaled.
  64625. + */
  64626. +int
  64627. +usb_descriptor_fillbuf(void *buf, unsigned buflen,
  64628. + const struct usb_descriptor_header **src)
  64629. +{
  64630. + u8 *dest = buf;
  64631. +
  64632. + if (!src)
  64633. + return -EINVAL;
  64634. +
  64635. + /* fill buffer from src[] until null descriptor ptr */
  64636. + for (; 0 != *src; src++) {
  64637. + unsigned len = (*src)->bLength;
  64638. +
  64639. + if (len > buflen)
  64640. + return -EINVAL;
  64641. + memcpy(dest, *src, len);
  64642. + buflen -= len;
  64643. + dest += len;
  64644. + }
  64645. + return dest - (u8 *)buf;
  64646. +}
  64647. +
  64648. +
  64649. +/**
  64650. + * usb_gadget_config_buf - builts a complete configuration descriptor
  64651. + * @config: Header for the descriptor, including characteristics such
  64652. + * as power requirements and number of interfaces.
  64653. + * @desc: Null-terminated vector of pointers to the descriptors (interface,
  64654. + * endpoint, etc) defining all functions in this device configuration.
  64655. + * @buf: Buffer for the resulting configuration descriptor.
  64656. + * @length: Length of buffer. If this is not big enough to hold the
  64657. + * entire configuration descriptor, an error code will be returned.
  64658. + *
  64659. + * This copies descriptors into the response buffer, building a descriptor
  64660. + * for that configuration. It returns the buffer length or a negative
  64661. + * status code. The config.wTotalLength field is set to match the length
  64662. + * of the result, but other descriptor fields (including power usage and
  64663. + * interface count) must be set by the caller.
  64664. + *
  64665. + * Gadget drivers could use this when constructing a config descriptor
  64666. + * in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the
  64667. + * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
  64668. + */
  64669. +int usb_gadget_config_buf(
  64670. + const struct usb_config_descriptor *config,
  64671. + void *buf,
  64672. + unsigned length,
  64673. + const struct usb_descriptor_header **desc
  64674. +)
  64675. +{
  64676. + struct usb_config_descriptor *cp = buf;
  64677. + int len;
  64678. +
  64679. + /* config descriptor first */
  64680. + if (length < USB_DT_CONFIG_SIZE || !desc)
  64681. + return -EINVAL;
  64682. + *cp = *config;
  64683. +
  64684. + /* then interface/endpoint/class/vendor/... */
  64685. + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
  64686. + length - USB_DT_CONFIG_SIZE, desc);
  64687. + if (len < 0)
  64688. + return len;
  64689. + len += USB_DT_CONFIG_SIZE;
  64690. + if (len > 0xffff)
  64691. + return -EINVAL;
  64692. +
  64693. + /* patch up the config descriptor */
  64694. + cp->bLength = USB_DT_CONFIG_SIZE;
  64695. + cp->bDescriptorType = USB_DT_CONFIG;
  64696. + cp->wTotalLength = cpu_to_le16(len);
  64697. + cp->bmAttributes |= USB_CONFIG_ATT_ONE;
  64698. + return len;
  64699. +}
  64700. +
  64701. +/*-------------------------------------------------------------------------*/
  64702. +/*-------------------------------------------------------------------------*/
  64703. +
  64704. +
  64705. +#define RBUF_LEN (1024*1024)
  64706. +static int rbuf_start;
  64707. +static int rbuf_len;
  64708. +static __u8 rbuf[RBUF_LEN];
  64709. +
  64710. +/*-------------------------------------------------------------------------*/
  64711. +
  64712. +#define DRIVER_VERSION "St Patrick's Day 2004"
  64713. +
  64714. +static const char shortname [] = "zero";
  64715. +static const char longname [] = "YAMAHA YST-MS35D USB Speaker ";
  64716. +
  64717. +static const char source_sink [] = "source and sink data";
  64718. +static const char loopback [] = "loop input to output";
  64719. +
  64720. +/*-------------------------------------------------------------------------*/
  64721. +
  64722. +/*
  64723. + * driver assumes self-powered hardware, and
  64724. + * has no way for users to trigger remote wakeup.
  64725. + *
  64726. + * this version autoconfigures as much as possible,
  64727. + * which is reasonable for most "bulk-only" drivers.
  64728. + */
  64729. +static const char *EP_IN_NAME; /* source */
  64730. +static const char *EP_OUT_NAME; /* sink */
  64731. +
  64732. +/*-------------------------------------------------------------------------*/
  64733. +
  64734. +/* big enough to hold our biggest descriptor */
  64735. +#define USB_BUFSIZ 512
  64736. +
  64737. +struct zero_dev {
  64738. + spinlock_t lock;
  64739. + struct usb_gadget *gadget;
  64740. + struct usb_request *req; /* for control responses */
  64741. +
  64742. + /* when configured, we have one of two configs:
  64743. + * - source data (in to host) and sink it (out from host)
  64744. + * - or loop it back (out from host back in to host)
  64745. + */
  64746. + u8 config;
  64747. + struct usb_ep *in_ep, *out_ep;
  64748. +
  64749. + /* autoresume timer */
  64750. + struct timer_list resume;
  64751. +};
  64752. +
  64753. +#define xprintk(d,level,fmt,args...) \
  64754. + dev_printk(level , &(d)->gadget->dev , fmt , ## args)
  64755. +
  64756. +#ifdef DEBUG
  64757. +#define DBG(dev,fmt,args...) \
  64758. + xprintk(dev , KERN_DEBUG , fmt , ## args)
  64759. +#else
  64760. +#define DBG(dev,fmt,args...) \
  64761. + do { } while (0)
  64762. +#endif /* DEBUG */
  64763. +
  64764. +#ifdef VERBOSE
  64765. +#define VDBG DBG
  64766. +#else
  64767. +#define VDBG(dev,fmt,args...) \
  64768. + do { } while (0)
  64769. +#endif /* VERBOSE */
  64770. +
  64771. +#define ERROR(dev,fmt,args...) \
  64772. + xprintk(dev , KERN_ERR , fmt , ## args)
  64773. +#define WARN(dev,fmt,args...) \
  64774. + xprintk(dev , KERN_WARNING , fmt , ## args)
  64775. +#define INFO(dev,fmt,args...) \
  64776. + xprintk(dev , KERN_INFO , fmt , ## args)
  64777. +
  64778. +/*-------------------------------------------------------------------------*/
  64779. +
  64780. +static unsigned buflen = 4096;
  64781. +static unsigned qlen = 32;
  64782. +static unsigned pattern = 0;
  64783. +
  64784. +module_param (buflen, uint, S_IRUGO|S_IWUSR);
  64785. +module_param (qlen, uint, S_IRUGO|S_IWUSR);
  64786. +module_param (pattern, uint, S_IRUGO|S_IWUSR);
  64787. +
  64788. +/*
  64789. + * if it's nonzero, autoresume says how many seconds to wait
  64790. + * before trying to wake up the host after suspend.
  64791. + */
  64792. +static unsigned autoresume = 0;
  64793. +module_param (autoresume, uint, 0);
  64794. +
  64795. +/*
  64796. + * Normally the "loopback" configuration is second (index 1) so
  64797. + * it's not the default. Here's where to change that order, to
  64798. + * work better with hosts where config changes are problematic.
  64799. + * Or controllers (like superh) that only support one config.
  64800. + */
  64801. +static int loopdefault = 0;
  64802. +
  64803. +module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
  64804. +
  64805. +/*-------------------------------------------------------------------------*/
  64806. +
  64807. +/* Thanks to NetChip Technologies for donating this product ID.
  64808. + *
  64809. + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
  64810. + * Instead: allocate your own, using normal USB-IF procedures.
  64811. + */
  64812. +#ifndef CONFIG_USB_ZERO_HNPTEST
  64813. +#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
  64814. +#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
  64815. +#else
  64816. +#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
  64817. +#define DRIVER_PRODUCT_NUM 0xbadd
  64818. +#endif
  64819. +
  64820. +/*-------------------------------------------------------------------------*/
  64821. +
  64822. +/*
  64823. + * DESCRIPTORS ... most are static, but strings and (full)
  64824. + * configuration descriptors are built on demand.
  64825. + */
  64826. +
  64827. +/*
  64828. +#define STRING_MANUFACTURER 25
  64829. +#define STRING_PRODUCT 42
  64830. +#define STRING_SERIAL 101
  64831. +*/
  64832. +#define STRING_MANUFACTURER 1
  64833. +#define STRING_PRODUCT 2
  64834. +#define STRING_SERIAL 3
  64835. +
  64836. +#define STRING_SOURCE_SINK 250
  64837. +#define STRING_LOOPBACK 251
  64838. +
  64839. +/*
  64840. + * This device advertises two configurations; these numbers work
  64841. + * on a pxa250 as well as more flexible hardware.
  64842. + */
  64843. +#define CONFIG_SOURCE_SINK 3
  64844. +#define CONFIG_LOOPBACK 2
  64845. +
  64846. +/*
  64847. +static struct usb_device_descriptor
  64848. +device_desc = {
  64849. + .bLength = sizeof device_desc,
  64850. + .bDescriptorType = USB_DT_DEVICE,
  64851. +
  64852. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  64853. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  64854. +
  64855. + .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
  64856. + .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
  64857. + .iManufacturer = STRING_MANUFACTURER,
  64858. + .iProduct = STRING_PRODUCT,
  64859. + .iSerialNumber = STRING_SERIAL,
  64860. + .bNumConfigurations = 2,
  64861. +};
  64862. +*/
  64863. +static struct usb_device_descriptor
  64864. +device_desc = {
  64865. + .bLength = sizeof device_desc,
  64866. + .bDescriptorType = USB_DT_DEVICE,
  64867. + .bcdUSB = __constant_cpu_to_le16 (0x0100),
  64868. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  64869. + .bDeviceSubClass = 0,
  64870. + .bDeviceProtocol = 0,
  64871. + .bMaxPacketSize0 = 64,
  64872. + .bcdDevice = __constant_cpu_to_le16 (0x0100),
  64873. + .idVendor = __constant_cpu_to_le16 (0x0499),
  64874. + .idProduct = __constant_cpu_to_le16 (0x3002),
  64875. + .iManufacturer = STRING_MANUFACTURER,
  64876. + .iProduct = STRING_PRODUCT,
  64877. + .iSerialNumber = STRING_SERIAL,
  64878. + .bNumConfigurations = 1,
  64879. +};
  64880. +
  64881. +static struct usb_config_descriptor
  64882. +z_config = {
  64883. + .bLength = sizeof z_config,
  64884. + .bDescriptorType = USB_DT_CONFIG,
  64885. +
  64886. + /* compute wTotalLength on the fly */
  64887. + .bNumInterfaces = 2,
  64888. + .bConfigurationValue = 1,
  64889. + .iConfiguration = 0,
  64890. + .bmAttributes = 0x40,
  64891. + .bMaxPower = 0, /* self-powered */
  64892. +};
  64893. +
  64894. +
  64895. +static struct usb_otg_descriptor
  64896. +otg_descriptor = {
  64897. + .bLength = sizeof otg_descriptor,
  64898. + .bDescriptorType = USB_DT_OTG,
  64899. +
  64900. + .bmAttributes = USB_OTG_SRP,
  64901. +};
  64902. +
  64903. +/* one interface in each configuration */
  64904. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  64905. +
  64906. +/*
  64907. + * usb 2.0 devices need to expose both high speed and full speed
  64908. + * descriptors, unless they only run at full speed.
  64909. + *
  64910. + * that means alternate endpoint descriptors (bigger packets)
  64911. + * and a "device qualifier" ... plus more construction options
  64912. + * for the config descriptor.
  64913. + */
  64914. +
  64915. +static struct usb_qualifier_descriptor
  64916. +dev_qualifier = {
  64917. + .bLength = sizeof dev_qualifier,
  64918. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  64919. +
  64920. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  64921. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  64922. +
  64923. + .bNumConfigurations = 2,
  64924. +};
  64925. +
  64926. +
  64927. +struct usb_cs_as_general_descriptor {
  64928. + __u8 bLength;
  64929. + __u8 bDescriptorType;
  64930. +
  64931. + __u8 bDescriptorSubType;
  64932. + __u8 bTerminalLink;
  64933. + __u8 bDelay;
  64934. + __u16 wFormatTag;
  64935. +} __attribute__ ((packed));
  64936. +
  64937. +struct usb_cs_as_format_descriptor {
  64938. + __u8 bLength;
  64939. + __u8 bDescriptorType;
  64940. +
  64941. + __u8 bDescriptorSubType;
  64942. + __u8 bFormatType;
  64943. + __u8 bNrChannels;
  64944. + __u8 bSubframeSize;
  64945. + __u8 bBitResolution;
  64946. + __u8 bSamfreqType;
  64947. + __u8 tLowerSamFreq[3];
  64948. + __u8 tUpperSamFreq[3];
  64949. +} __attribute__ ((packed));
  64950. +
  64951. +static const struct usb_interface_descriptor
  64952. +z_audio_control_if_desc = {
  64953. + .bLength = sizeof z_audio_control_if_desc,
  64954. + .bDescriptorType = USB_DT_INTERFACE,
  64955. + .bInterfaceNumber = 0,
  64956. + .bAlternateSetting = 0,
  64957. + .bNumEndpoints = 0,
  64958. + .bInterfaceClass = USB_CLASS_AUDIO,
  64959. + .bInterfaceSubClass = 0x1,
  64960. + .bInterfaceProtocol = 0,
  64961. + .iInterface = 0,
  64962. +};
  64963. +
  64964. +static const struct usb_interface_descriptor
  64965. +z_audio_if_desc = {
  64966. + .bLength = sizeof z_audio_if_desc,
  64967. + .bDescriptorType = USB_DT_INTERFACE,
  64968. + .bInterfaceNumber = 1,
  64969. + .bAlternateSetting = 0,
  64970. + .bNumEndpoints = 0,
  64971. + .bInterfaceClass = USB_CLASS_AUDIO,
  64972. + .bInterfaceSubClass = 0x2,
  64973. + .bInterfaceProtocol = 0,
  64974. + .iInterface = 0,
  64975. +};
  64976. +
  64977. +static const struct usb_interface_descriptor
  64978. +z_audio_if_desc2 = {
  64979. + .bLength = sizeof z_audio_if_desc,
  64980. + .bDescriptorType = USB_DT_INTERFACE,
  64981. + .bInterfaceNumber = 1,
  64982. + .bAlternateSetting = 1,
  64983. + .bNumEndpoints = 1,
  64984. + .bInterfaceClass = USB_CLASS_AUDIO,
  64985. + .bInterfaceSubClass = 0x2,
  64986. + .bInterfaceProtocol = 0,
  64987. + .iInterface = 0,
  64988. +};
  64989. +
  64990. +static const struct usb_cs_as_general_descriptor
  64991. +z_audio_cs_as_if_desc = {
  64992. + .bLength = 7,
  64993. + .bDescriptorType = 0x24,
  64994. +
  64995. + .bDescriptorSubType = 0x01,
  64996. + .bTerminalLink = 0x01,
  64997. + .bDelay = 0x0,
  64998. + .wFormatTag = __constant_cpu_to_le16 (0x0001)
  64999. +};
  65000. +
  65001. +
  65002. +static const struct usb_cs_as_format_descriptor
  65003. +z_audio_cs_as_format_desc = {
  65004. + .bLength = 0xe,
  65005. + .bDescriptorType = 0x24,
  65006. +
  65007. + .bDescriptorSubType = 2,
  65008. + .bFormatType = 1,
  65009. + .bNrChannels = 1,
  65010. + .bSubframeSize = 1,
  65011. + .bBitResolution = 8,
  65012. + .bSamfreqType = 0,
  65013. + .tLowerSamFreq = {0x7e, 0x13, 0x00},
  65014. + .tUpperSamFreq = {0xe2, 0xd6, 0x00},
  65015. +};
  65016. +
  65017. +static const struct usb_endpoint_descriptor
  65018. +z_iso_ep = {
  65019. + .bLength = 0x09,
  65020. + .bDescriptorType = 0x05,
  65021. + .bEndpointAddress = 0x04,
  65022. + .bmAttributes = 0x09,
  65023. + .wMaxPacketSize = 0x0038,
  65024. + .bInterval = 0x01,
  65025. + .bRefresh = 0x00,
  65026. + .bSynchAddress = 0x00,
  65027. +};
  65028. +
  65029. +static char z_iso_ep2[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  65030. +
  65031. +// 9 bytes
  65032. +static char z_ac_interface_header_desc[] =
  65033. +{ 0x09, 0x24, 0x01, 0x00, 0x01, 0x2b, 0x00, 0x01, 0x01 };
  65034. +
  65035. +// 12 bytes
  65036. +static char z_0[] = {0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
  65037. + 0x03, 0x00, 0x00, 0x00};
  65038. +// 13 bytes
  65039. +static char z_1[] = {0x0d, 0x24, 0x06, 0x02, 0x01, 0x02, 0x15, 0x00,
  65040. + 0x02, 0x00, 0x02, 0x00, 0x00};
  65041. +// 9 bytes
  65042. +static char z_2[] = {0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x00, 0x02,
  65043. + 0x00};
  65044. +
  65045. +static char za_0[] = {0x09, 0x04, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00,
  65046. + 0x00};
  65047. +
  65048. +static char za_1[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  65049. +
  65050. +static char za_2[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x01, 0x08, 0x00,
  65051. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  65052. +
  65053. +static char za_3[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  65054. + 0x00};
  65055. +
  65056. +static char za_4[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  65057. +
  65058. +static char za_5[] = {0x09, 0x04, 0x01, 0x03, 0x01, 0x01, 0x02, 0x00,
  65059. + 0x00};
  65060. +
  65061. +static char za_6[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  65062. +
  65063. +static char za_7[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x02, 0x10, 0x00,
  65064. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  65065. +
  65066. +static char za_8[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  65067. + 0x00};
  65068. +
  65069. +static char za_9[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  65070. +
  65071. +static char za_10[] = {0x09, 0x04, 0x01, 0x04, 0x01, 0x01, 0x02, 0x00,
  65072. + 0x00};
  65073. +
  65074. +static char za_11[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  65075. +
  65076. +static char za_12[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x00,
  65077. + 0x73, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  65078. +
  65079. +static char za_13[] = {0x09, 0x05, 0x04, 0x09, 0xe0, 0x00, 0x01, 0x00,
  65080. + 0x00};
  65081. +
  65082. +static char za_14[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  65083. +
  65084. +static char za_15[] = {0x09, 0x04, 0x01, 0x05, 0x01, 0x01, 0x02, 0x00,
  65085. + 0x00};
  65086. +
  65087. +static char za_16[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  65088. +
  65089. +static char za_17[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x03, 0x14, 0x00,
  65090. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  65091. +
  65092. +static char za_18[] = {0x09, 0x05, 0x04, 0x09, 0xa8, 0x00, 0x01, 0x00,
  65093. + 0x00};
  65094. +
  65095. +static char za_19[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  65096. +
  65097. +static char za_20[] = {0x09, 0x04, 0x01, 0x06, 0x01, 0x01, 0x02, 0x00,
  65098. + 0x00};
  65099. +
  65100. +static char za_21[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  65101. +
  65102. +static char za_22[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x03, 0x14, 0x00,
  65103. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  65104. +
  65105. +static char za_23[] = {0x09, 0x05, 0x04, 0x09, 0x50, 0x01, 0x01, 0x00,
  65106. + 0x00};
  65107. +
  65108. +static char za_24[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  65109. +
  65110. +
  65111. +
  65112. +static const struct usb_descriptor_header *z_function [] = {
  65113. + (struct usb_descriptor_header *) &z_audio_control_if_desc,
  65114. + (struct usb_descriptor_header *) &z_ac_interface_header_desc,
  65115. + (struct usb_descriptor_header *) &z_0,
  65116. + (struct usb_descriptor_header *) &z_1,
  65117. + (struct usb_descriptor_header *) &z_2,
  65118. + (struct usb_descriptor_header *) &z_audio_if_desc,
  65119. + (struct usb_descriptor_header *) &z_audio_if_desc2,
  65120. + (struct usb_descriptor_header *) &z_audio_cs_as_if_desc,
  65121. + (struct usb_descriptor_header *) &z_audio_cs_as_format_desc,
  65122. + (struct usb_descriptor_header *) &z_iso_ep,
  65123. + (struct usb_descriptor_header *) &z_iso_ep2,
  65124. + (struct usb_descriptor_header *) &za_0,
  65125. + (struct usb_descriptor_header *) &za_1,
  65126. + (struct usb_descriptor_header *) &za_2,
  65127. + (struct usb_descriptor_header *) &za_3,
  65128. + (struct usb_descriptor_header *) &za_4,
  65129. + (struct usb_descriptor_header *) &za_5,
  65130. + (struct usb_descriptor_header *) &za_6,
  65131. + (struct usb_descriptor_header *) &za_7,
  65132. + (struct usb_descriptor_header *) &za_8,
  65133. + (struct usb_descriptor_header *) &za_9,
  65134. + (struct usb_descriptor_header *) &za_10,
  65135. + (struct usb_descriptor_header *) &za_11,
  65136. + (struct usb_descriptor_header *) &za_12,
  65137. + (struct usb_descriptor_header *) &za_13,
  65138. + (struct usb_descriptor_header *) &za_14,
  65139. + (struct usb_descriptor_header *) &za_15,
  65140. + (struct usb_descriptor_header *) &za_16,
  65141. + (struct usb_descriptor_header *) &za_17,
  65142. + (struct usb_descriptor_header *) &za_18,
  65143. + (struct usb_descriptor_header *) &za_19,
  65144. + (struct usb_descriptor_header *) &za_20,
  65145. + (struct usb_descriptor_header *) &za_21,
  65146. + (struct usb_descriptor_header *) &za_22,
  65147. + (struct usb_descriptor_header *) &za_23,
  65148. + (struct usb_descriptor_header *) &za_24,
  65149. + NULL,
  65150. +};
  65151. +
  65152. +/* maxpacket and other transfer characteristics vary by speed. */
  65153. +#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
  65154. +
  65155. +#else
  65156. +
  65157. +/* if there's no high speed support, maxpacket doesn't change. */
  65158. +#define ep_desc(g,hs,fs) fs
  65159. +
  65160. +#endif /* !CONFIG_USB_GADGET_DUALSPEED */
  65161. +
  65162. +static char manufacturer [40];
  65163. +//static char serial [40];
  65164. +static char serial [] = "Ser 00 em";
  65165. +
  65166. +/* static strings, in UTF-8 */
  65167. +static struct usb_string strings [] = {
  65168. + { STRING_MANUFACTURER, manufacturer, },
  65169. + { STRING_PRODUCT, longname, },
  65170. + { STRING_SERIAL, serial, },
  65171. + { STRING_LOOPBACK, loopback, },
  65172. + { STRING_SOURCE_SINK, source_sink, },
  65173. + { } /* end of list */
  65174. +};
  65175. +
  65176. +static struct usb_gadget_strings stringtab = {
  65177. + .language = 0x0409, /* en-us */
  65178. + .strings = strings,
  65179. +};
  65180. +
  65181. +/*
  65182. + * config descriptors are also handcrafted. these must agree with code
  65183. + * that sets configurations, and with code managing interfaces and their
  65184. + * altsettings. other complexity may come from:
  65185. + *
  65186. + * - high speed support, including "other speed config" rules
  65187. + * - multiple configurations
  65188. + * - interfaces with alternate settings
  65189. + * - embedded class or vendor-specific descriptors
  65190. + *
  65191. + * this handles high speed, and has a second config that could as easily
  65192. + * have been an alternate interface setting (on most hardware).
  65193. + *
  65194. + * NOTE: to demonstrate (and test) more USB capabilities, this driver
  65195. + * should include an altsetting to test interrupt transfers, including
  65196. + * high bandwidth modes at high speed. (Maybe work like Intel's test
  65197. + * device?)
  65198. + */
  65199. +static int
  65200. +config_buf (struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
  65201. +{
  65202. + int len;
  65203. + const struct usb_descriptor_header **function;
  65204. +
  65205. + function = z_function;
  65206. + len = usb_gadget_config_buf (&z_config, buf, USB_BUFSIZ, function);
  65207. + if (len < 0)
  65208. + return len;
  65209. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  65210. + return len;
  65211. +}
  65212. +
  65213. +/*-------------------------------------------------------------------------*/
  65214. +
  65215. +static struct usb_request *
  65216. +alloc_ep_req (struct usb_ep *ep, unsigned length)
  65217. +{
  65218. + struct usb_request *req;
  65219. +
  65220. + req = usb_ep_alloc_request (ep, GFP_ATOMIC);
  65221. + if (req) {
  65222. + req->length = length;
  65223. + req->buf = usb_ep_alloc_buffer (ep, length,
  65224. + &req->dma, GFP_ATOMIC);
  65225. + if (!req->buf) {
  65226. + usb_ep_free_request (ep, req);
  65227. + req = NULL;
  65228. + }
  65229. + }
  65230. + return req;
  65231. +}
  65232. +
  65233. +static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
  65234. +{
  65235. + if (req->buf)
  65236. + usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
  65237. + usb_ep_free_request (ep, req);
  65238. +}
  65239. +
  65240. +/*-------------------------------------------------------------------------*/
  65241. +
  65242. +/* optionally require specific source/sink data patterns */
  65243. +
  65244. +static int
  65245. +check_read_data (
  65246. + struct zero_dev *dev,
  65247. + struct usb_ep *ep,
  65248. + struct usb_request *req
  65249. +)
  65250. +{
  65251. + unsigned i;
  65252. + u8 *buf = req->buf;
  65253. +
  65254. + for (i = 0; i < req->actual; i++, buf++) {
  65255. + switch (pattern) {
  65256. + /* all-zeroes has no synchronization issues */
  65257. + case 0:
  65258. + if (*buf == 0)
  65259. + continue;
  65260. + break;
  65261. + /* mod63 stays in sync with short-terminated transfers,
  65262. + * or otherwise when host and gadget agree on how large
  65263. + * each usb transfer request should be. resync is done
  65264. + * with set_interface or set_config.
  65265. + */
  65266. + case 1:
  65267. + if (*buf == (u8)(i % 63))
  65268. + continue;
  65269. + break;
  65270. + }
  65271. + ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
  65272. + usb_ep_set_halt (ep);
  65273. + return -EINVAL;
  65274. + }
  65275. + return 0;
  65276. +}
  65277. +
  65278. +/*-------------------------------------------------------------------------*/
  65279. +
  65280. +static void zero_reset_config (struct zero_dev *dev)
  65281. +{
  65282. + if (dev->config == 0)
  65283. + return;
  65284. +
  65285. + DBG (dev, "reset config\n");
  65286. +
  65287. + /* just disable endpoints, forcing completion of pending i/o.
  65288. + * all our completion handlers free their requests in this case.
  65289. + */
  65290. + if (dev->in_ep) {
  65291. + usb_ep_disable (dev->in_ep);
  65292. + dev->in_ep = NULL;
  65293. + }
  65294. + if (dev->out_ep) {
  65295. + usb_ep_disable (dev->out_ep);
  65296. + dev->out_ep = NULL;
  65297. + }
  65298. + dev->config = 0;
  65299. + del_timer (&dev->resume);
  65300. +}
  65301. +
  65302. +#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
  65303. +
  65304. +static void
  65305. +zero_isoc_complete (struct usb_ep *ep, struct usb_request *req)
  65306. +{
  65307. + struct zero_dev *dev = ep->driver_data;
  65308. + int status = req->status;
  65309. + int i, j;
  65310. +
  65311. + switch (status) {
  65312. +
  65313. + case 0: /* normal completion? */
  65314. + //printk ("\nzero ---------------> isoc normal completion %d bytes\n", req->actual);
  65315. + for (i=0, j=rbuf_start; i<req->actual; i++) {
  65316. + //printk ("%02x ", ((__u8*)req->buf)[i]);
  65317. + rbuf[j] = ((__u8*)req->buf)[i];
  65318. + j++;
  65319. + if (j >= RBUF_LEN) j=0;
  65320. + }
  65321. + rbuf_start = j;
  65322. + //printk ("\n\n");
  65323. +
  65324. + if (rbuf_len < RBUF_LEN) {
  65325. + rbuf_len += req->actual;
  65326. + if (rbuf_len > RBUF_LEN) {
  65327. + rbuf_len = RBUF_LEN;
  65328. + }
  65329. + }
  65330. +
  65331. + break;
  65332. +
  65333. + /* this endpoint is normally active while we're configured */
  65334. + case -ECONNABORTED: /* hardware forced ep reset */
  65335. + case -ECONNRESET: /* request dequeued */
  65336. + case -ESHUTDOWN: /* disconnect from host */
  65337. + VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
  65338. + req->actual, req->length);
  65339. + if (ep == dev->out_ep)
  65340. + check_read_data (dev, ep, req);
  65341. + free_ep_req (ep, req);
  65342. + return;
  65343. +
  65344. + case -EOVERFLOW: /* buffer overrun on read means that
  65345. + * we didn't provide a big enough
  65346. + * buffer.
  65347. + */
  65348. + default:
  65349. +#if 1
  65350. + DBG (dev, "%s complete --> %d, %d/%d\n", ep->name,
  65351. + status, req->actual, req->length);
  65352. +#endif
  65353. + case -EREMOTEIO: /* short read */
  65354. + break;
  65355. + }
  65356. +
  65357. + status = usb_ep_queue (ep, req, GFP_ATOMIC);
  65358. + if (status) {
  65359. + ERROR (dev, "kill %s: resubmit %d bytes --> %d\n",
  65360. + ep->name, req->length, status);
  65361. + usb_ep_set_halt (ep);
  65362. + /* FIXME recover later ... somehow */
  65363. + }
  65364. +}
  65365. +
  65366. +static struct usb_request *
  65367. +zero_start_isoc_ep (struct usb_ep *ep, int gfp_flags)
  65368. +{
  65369. + struct usb_request *req;
  65370. + int status;
  65371. +
  65372. + req = alloc_ep_req (ep, 512);
  65373. + if (!req)
  65374. + return NULL;
  65375. +
  65376. + req->complete = zero_isoc_complete;
  65377. +
  65378. + status = usb_ep_queue (ep, req, gfp_flags);
  65379. + if (status) {
  65380. + struct zero_dev *dev = ep->driver_data;
  65381. +
  65382. + ERROR (dev, "start %s --> %d\n", ep->name, status);
  65383. + free_ep_req (ep, req);
  65384. + req = NULL;
  65385. + }
  65386. +
  65387. + return req;
  65388. +}
  65389. +
  65390. +/* change our operational config. this code must agree with the code
  65391. + * that returns config descriptors, and altsetting code.
  65392. + *
  65393. + * it's also responsible for power management interactions. some
  65394. + * configurations might not work with our current power sources.
  65395. + *
  65396. + * note that some device controller hardware will constrain what this
  65397. + * code can do, perhaps by disallowing more than one configuration or
  65398. + * by limiting configuration choices (like the pxa2xx).
  65399. + */
  65400. +static int
  65401. +zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
  65402. +{
  65403. + int result = 0;
  65404. + struct usb_gadget *gadget = dev->gadget;
  65405. + const struct usb_endpoint_descriptor *d;
  65406. + struct usb_ep *ep;
  65407. +
  65408. + if (number == dev->config)
  65409. + return 0;
  65410. +
  65411. + zero_reset_config (dev);
  65412. +
  65413. + gadget_for_each_ep (ep, gadget) {
  65414. +
  65415. + if (strcmp (ep->name, "ep4") == 0) {
  65416. +
  65417. + d = (struct usb_endpoint_descripter *)&za_23; // isoc ep desc for audio i/f alt setting 6
  65418. + result = usb_ep_enable (ep, d);
  65419. +
  65420. + if (result == 0) {
  65421. + ep->driver_data = dev;
  65422. + dev->in_ep = ep;
  65423. +
  65424. + if (zero_start_isoc_ep (ep, gfp_flags) != 0) {
  65425. +
  65426. + dev->in_ep = ep;
  65427. + continue;
  65428. + }
  65429. +
  65430. + usb_ep_disable (ep);
  65431. + result = -EIO;
  65432. + }
  65433. + }
  65434. +
  65435. + }
  65436. +
  65437. + dev->config = number;
  65438. + return result;
  65439. +}
  65440. +
  65441. +/*-------------------------------------------------------------------------*/
  65442. +
  65443. +static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
  65444. +{
  65445. + if (req->status || req->actual != req->length)
  65446. + DBG ((struct zero_dev *) ep->driver_data,
  65447. + "setup complete --> %d, %d/%d\n",
  65448. + req->status, req->actual, req->length);
  65449. +}
  65450. +
  65451. +/*
  65452. + * The setup() callback implements all the ep0 functionality that's
  65453. + * not handled lower down, in hardware or the hardware driver (like
  65454. + * device and endpoint feature flags, and their status). It's all
  65455. + * housekeeping for the gadget function we're implementing. Most of
  65456. + * the work is in config-specific setup.
  65457. + */
  65458. +static int
  65459. +zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
  65460. +{
  65461. + struct zero_dev *dev = get_gadget_data (gadget);
  65462. + struct usb_request *req = dev->req;
  65463. + int value = -EOPNOTSUPP;
  65464. +
  65465. + /* usually this stores reply data in the pre-allocated ep0 buffer,
  65466. + * but config change events will reconfigure hardware.
  65467. + */
  65468. + req->zero = 0;
  65469. + switch (ctrl->bRequest) {
  65470. +
  65471. + case USB_REQ_GET_DESCRIPTOR:
  65472. +
  65473. + switch (ctrl->wValue >> 8) {
  65474. +
  65475. + case USB_DT_DEVICE:
  65476. + value = min (ctrl->wLength, (u16) sizeof device_desc);
  65477. + memcpy (req->buf, &device_desc, value);
  65478. + break;
  65479. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  65480. + case USB_DT_DEVICE_QUALIFIER:
  65481. + if (!gadget->is_dualspeed)
  65482. + break;
  65483. + value = min (ctrl->wLength, (u16) sizeof dev_qualifier);
  65484. + memcpy (req->buf, &dev_qualifier, value);
  65485. + break;
  65486. +
  65487. + case USB_DT_OTHER_SPEED_CONFIG:
  65488. + if (!gadget->is_dualspeed)
  65489. + break;
  65490. + // FALLTHROUGH
  65491. +#endif /* CONFIG_USB_GADGET_DUALSPEED */
  65492. + case USB_DT_CONFIG:
  65493. + value = config_buf (gadget, req->buf,
  65494. + ctrl->wValue >> 8,
  65495. + ctrl->wValue & 0xff);
  65496. + if (value >= 0)
  65497. + value = min (ctrl->wLength, (u16) value);
  65498. + break;
  65499. +
  65500. + case USB_DT_STRING:
  65501. + /* wIndex == language code.
  65502. + * this driver only handles one language, you can
  65503. + * add string tables for other languages, using
  65504. + * any UTF-8 characters
  65505. + */
  65506. + value = usb_gadget_get_string (&stringtab,
  65507. + ctrl->wValue & 0xff, req->buf);
  65508. + if (value >= 0) {
  65509. + value = min (ctrl->wLength, (u16) value);
  65510. + }
  65511. + break;
  65512. + }
  65513. + break;
  65514. +
  65515. + /* currently two configs, two speeds */
  65516. + case USB_REQ_SET_CONFIGURATION:
  65517. + if (ctrl->bRequestType != 0)
  65518. + goto unknown;
  65519. +
  65520. + spin_lock (&dev->lock);
  65521. + value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
  65522. + spin_unlock (&dev->lock);
  65523. + break;
  65524. + case USB_REQ_GET_CONFIGURATION:
  65525. + if (ctrl->bRequestType != USB_DIR_IN)
  65526. + goto unknown;
  65527. + *(u8 *)req->buf = dev->config;
  65528. + value = min (ctrl->wLength, (u16) 1);
  65529. + break;
  65530. +
  65531. + /* until we add altsetting support, or other interfaces,
  65532. + * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
  65533. + * and already killed pending endpoint I/O.
  65534. + */
  65535. + case USB_REQ_SET_INTERFACE:
  65536. +
  65537. + if (ctrl->bRequestType != USB_RECIP_INTERFACE)
  65538. + goto unknown;
  65539. + spin_lock (&dev->lock);
  65540. + if (dev->config) {
  65541. + u8 config = dev->config;
  65542. +
  65543. + /* resets interface configuration, forgets about
  65544. + * previous transaction state (queued bufs, etc)
  65545. + * and re-inits endpoint state (toggle etc)
  65546. + * no response queued, just zero status == success.
  65547. + * if we had more than one interface we couldn't
  65548. + * use this "reset the config" shortcut.
  65549. + */
  65550. + zero_reset_config (dev);
  65551. + zero_set_config (dev, config, GFP_ATOMIC);
  65552. + value = 0;
  65553. + }
  65554. + spin_unlock (&dev->lock);
  65555. + break;
  65556. + case USB_REQ_GET_INTERFACE:
  65557. + if ((ctrl->bRequestType == 0x21) && (ctrl->wIndex == 0x02)) {
  65558. + value = ctrl->wLength;
  65559. + break;
  65560. + }
  65561. + else {
  65562. + if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
  65563. + goto unknown;
  65564. + if (!dev->config)
  65565. + break;
  65566. + if (ctrl->wIndex != 0) {
  65567. + value = -EDOM;
  65568. + break;
  65569. + }
  65570. + *(u8 *)req->buf = 0;
  65571. + value = min (ctrl->wLength, (u16) 1);
  65572. + }
  65573. + break;
  65574. +
  65575. + /*
  65576. + * These are the same vendor-specific requests supported by
  65577. + * Intel's USB 2.0 compliance test devices. We exceed that
  65578. + * device spec by allowing multiple-packet requests.
  65579. + */
  65580. + case 0x5b: /* control WRITE test -- fill the buffer */
  65581. + if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
  65582. + goto unknown;
  65583. + if (ctrl->wValue || ctrl->wIndex)
  65584. + break;
  65585. + /* just read that many bytes into the buffer */
  65586. + if (ctrl->wLength > USB_BUFSIZ)
  65587. + break;
  65588. + value = ctrl->wLength;
  65589. + break;
  65590. + case 0x5c: /* control READ test -- return the buffer */
  65591. + if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
  65592. + goto unknown;
  65593. + if (ctrl->wValue || ctrl->wIndex)
  65594. + break;
  65595. + /* expect those bytes are still in the buffer; send back */
  65596. + if (ctrl->wLength > USB_BUFSIZ
  65597. + || ctrl->wLength != req->length)
  65598. + break;
  65599. + value = ctrl->wLength;
  65600. + break;
  65601. +
  65602. + case 0x01: // SET_CUR
  65603. + case 0x02:
  65604. + case 0x03:
  65605. + case 0x04:
  65606. + case 0x05:
  65607. + value = ctrl->wLength;
  65608. + break;
  65609. + case 0x81:
  65610. + switch (ctrl->wValue) {
  65611. + case 0x0201:
  65612. + case 0x0202:
  65613. + ((u8*)req->buf)[0] = 0x00;
  65614. + ((u8*)req->buf)[1] = 0xe3;
  65615. + break;
  65616. + case 0x0300:
  65617. + case 0x0500:
  65618. + ((u8*)req->buf)[0] = 0x00;
  65619. + break;
  65620. + }
  65621. + //((u8*)req->buf)[0] = 0x81;
  65622. + //((u8*)req->buf)[1] = 0x81;
  65623. + value = ctrl->wLength;
  65624. + break;
  65625. + case 0x82:
  65626. + switch (ctrl->wValue) {
  65627. + case 0x0201:
  65628. + case 0x0202:
  65629. + ((u8*)req->buf)[0] = 0x00;
  65630. + ((u8*)req->buf)[1] = 0xc3;
  65631. + break;
  65632. + case 0x0300:
  65633. + case 0x0500:
  65634. + ((u8*)req->buf)[0] = 0x00;
  65635. + break;
  65636. + }
  65637. + //((u8*)req->buf)[0] = 0x82;
  65638. + //((u8*)req->buf)[1] = 0x82;
  65639. + value = ctrl->wLength;
  65640. + break;
  65641. + case 0x83:
  65642. + switch (ctrl->wValue) {
  65643. + case 0x0201:
  65644. + case 0x0202:
  65645. + ((u8*)req->buf)[0] = 0x00;
  65646. + ((u8*)req->buf)[1] = 0x00;
  65647. + break;
  65648. + case 0x0300:
  65649. + ((u8*)req->buf)[0] = 0x60;
  65650. + break;
  65651. + case 0x0500:
  65652. + ((u8*)req->buf)[0] = 0x18;
  65653. + break;
  65654. + }
  65655. + //((u8*)req->buf)[0] = 0x83;
  65656. + //((u8*)req->buf)[1] = 0x83;
  65657. + value = ctrl->wLength;
  65658. + break;
  65659. + case 0x84:
  65660. + switch (ctrl->wValue) {
  65661. + case 0x0201:
  65662. + case 0x0202:
  65663. + ((u8*)req->buf)[0] = 0x00;
  65664. + ((u8*)req->buf)[1] = 0x01;
  65665. + break;
  65666. + case 0x0300:
  65667. + case 0x0500:
  65668. + ((u8*)req->buf)[0] = 0x08;
  65669. + break;
  65670. + }
  65671. + //((u8*)req->buf)[0] = 0x84;
  65672. + //((u8*)req->buf)[1] = 0x84;
  65673. + value = ctrl->wLength;
  65674. + break;
  65675. + case 0x85:
  65676. + ((u8*)req->buf)[0] = 0x85;
  65677. + ((u8*)req->buf)[1] = 0x85;
  65678. + value = ctrl->wLength;
  65679. + break;
  65680. +
  65681. +
  65682. + default:
  65683. +unknown:
  65684. + printk("unknown control req%02x.%02x v%04x i%04x l%d\n",
  65685. + ctrl->bRequestType, ctrl->bRequest,
  65686. + ctrl->wValue, ctrl->wIndex, ctrl->wLength);
  65687. + }
  65688. +
  65689. + /* respond with data transfer before status phase? */
  65690. + if (value >= 0) {
  65691. + req->length = value;
  65692. + req->zero = value < ctrl->wLength
  65693. + && (value % gadget->ep0->maxpacket) == 0;
  65694. + value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
  65695. + if (value < 0) {
  65696. + DBG (dev, "ep_queue < 0 --> %d\n", value);
  65697. + req->status = 0;
  65698. + zero_setup_complete (gadget->ep0, req);
  65699. + }
  65700. + }
  65701. +
  65702. + /* device either stalls (value < 0) or reports success */
  65703. + return value;
  65704. +}
  65705. +
  65706. +static void
  65707. +zero_disconnect (struct usb_gadget *gadget)
  65708. +{
  65709. + struct zero_dev *dev = get_gadget_data (gadget);
  65710. + unsigned long flags;
  65711. +
  65712. + spin_lock_irqsave (&dev->lock, flags);
  65713. + zero_reset_config (dev);
  65714. +
  65715. + /* a more significant application might have some non-usb
  65716. + * activities to quiesce here, saving resources like power
  65717. + * or pushing the notification up a network stack.
  65718. + */
  65719. + spin_unlock_irqrestore (&dev->lock, flags);
  65720. +
  65721. + /* next we may get setup() calls to enumerate new connections;
  65722. + * or an unbind() during shutdown (including removing module).
  65723. + */
  65724. +}
  65725. +
  65726. +static void
  65727. +zero_autoresume (unsigned long _dev)
  65728. +{
  65729. + struct zero_dev *dev = (struct zero_dev *) _dev;
  65730. + int status;
  65731. +
  65732. + /* normally the host would be woken up for something
  65733. + * more significant than just a timer firing...
  65734. + */
  65735. + if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
  65736. + status = usb_gadget_wakeup (dev->gadget);
  65737. + DBG (dev, "wakeup --> %d\n", status);
  65738. + }
  65739. +}
  65740. +
  65741. +/*-------------------------------------------------------------------------*/
  65742. +
  65743. +static void
  65744. +zero_unbind (struct usb_gadget *gadget)
  65745. +{
  65746. + struct zero_dev *dev = get_gadget_data (gadget);
  65747. +
  65748. + DBG (dev, "unbind\n");
  65749. +
  65750. + /* we've already been disconnected ... no i/o is active */
  65751. + if (dev->req)
  65752. + free_ep_req (gadget->ep0, dev->req);
  65753. + del_timer_sync (&dev->resume);
  65754. + kfree (dev);
  65755. + set_gadget_data (gadget, NULL);
  65756. +}
  65757. +
  65758. +static int
  65759. +zero_bind (struct usb_gadget *gadget)
  65760. +{
  65761. + struct zero_dev *dev;
  65762. + //struct usb_ep *ep;
  65763. +
  65764. + printk("binding\n");
  65765. + /*
  65766. + * DRIVER POLICY CHOICE: you may want to do this differently.
  65767. + * One thing to avoid is reusing a bcdDevice revision code
  65768. + * with different host-visible configurations or behavior
  65769. + * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
  65770. + */
  65771. + //device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
  65772. +
  65773. +
  65774. + /* ok, we made sense of the hardware ... */
  65775. + dev = kmalloc (sizeof *dev, SLAB_KERNEL);
  65776. + if (!dev)
  65777. + return -ENOMEM;
  65778. + memset (dev, 0, sizeof *dev);
  65779. + spin_lock_init (&dev->lock);
  65780. + dev->gadget = gadget;
  65781. + set_gadget_data (gadget, dev);
  65782. +
  65783. + /* preallocate control response and buffer */
  65784. + dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
  65785. + if (!dev->req)
  65786. + goto enomem;
  65787. + dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ,
  65788. + &dev->req->dma, GFP_KERNEL);
  65789. + if (!dev->req->buf)
  65790. + goto enomem;
  65791. +
  65792. + dev->req->complete = zero_setup_complete;
  65793. +
  65794. + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
  65795. +
  65796. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  65797. + /* assume ep0 uses the same value for both speeds ... */
  65798. + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
  65799. +
  65800. + /* and that all endpoints are dual-speed */
  65801. + //hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
  65802. + //hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
  65803. +#endif
  65804. +
  65805. + usb_gadget_set_selfpowered (gadget);
  65806. +
  65807. + init_timer (&dev->resume);
  65808. + dev->resume.function = zero_autoresume;
  65809. + dev->resume.data = (unsigned long) dev;
  65810. +
  65811. + gadget->ep0->driver_data = dev;
  65812. +
  65813. + INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
  65814. + INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
  65815. + EP_OUT_NAME, EP_IN_NAME);
  65816. +
  65817. + snprintf (manufacturer, sizeof manufacturer,
  65818. + UTS_SYSNAME " " UTS_RELEASE " with %s",
  65819. + gadget->name);
  65820. +
  65821. + return 0;
  65822. +
  65823. +enomem:
  65824. + zero_unbind (gadget);
  65825. + return -ENOMEM;
  65826. +}
  65827. +
  65828. +/*-------------------------------------------------------------------------*/
  65829. +
  65830. +static void
  65831. +zero_suspend (struct usb_gadget *gadget)
  65832. +{
  65833. + struct zero_dev *dev = get_gadget_data (gadget);
  65834. +
  65835. + if (gadget->speed == USB_SPEED_UNKNOWN)
  65836. + return;
  65837. +
  65838. + if (autoresume) {
  65839. + mod_timer (&dev->resume, jiffies + (HZ * autoresume));
  65840. + DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
  65841. + } else
  65842. + DBG (dev, "suspend\n");
  65843. +}
  65844. +
  65845. +static void
  65846. +zero_resume (struct usb_gadget *gadget)
  65847. +{
  65848. + struct zero_dev *dev = get_gadget_data (gadget);
  65849. +
  65850. + DBG (dev, "resume\n");
  65851. + del_timer (&dev->resume);
  65852. +}
  65853. +
  65854. +
  65855. +/*-------------------------------------------------------------------------*/
  65856. +
  65857. +static struct usb_gadget_driver zero_driver = {
  65858. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  65859. + .speed = USB_SPEED_HIGH,
  65860. +#else
  65861. + .speed = USB_SPEED_FULL,
  65862. +#endif
  65863. + .function = (char *) longname,
  65864. + .bind = zero_bind,
  65865. + .unbind = zero_unbind,
  65866. +
  65867. + .setup = zero_setup,
  65868. + .disconnect = zero_disconnect,
  65869. +
  65870. + .suspend = zero_suspend,
  65871. + .resume = zero_resume,
  65872. +
  65873. + .driver = {
  65874. + .name = (char *) shortname,
  65875. + // .shutdown = ...
  65876. + // .suspend = ...
  65877. + // .resume = ...
  65878. + },
  65879. +};
  65880. +
  65881. +MODULE_AUTHOR ("David Brownell");
  65882. +MODULE_LICENSE ("Dual BSD/GPL");
  65883. +
  65884. +static struct proc_dir_entry *pdir, *pfile;
  65885. +
  65886. +static int isoc_read_data (char *page, char **start,
  65887. + off_t off, int count,
  65888. + int *eof, void *data)
  65889. +{
  65890. + int i;
  65891. + static int c = 0;
  65892. + static int done = 0;
  65893. + static int s = 0;
  65894. +
  65895. +/*
  65896. + printk ("\ncount: %d\n", count);
  65897. + printk ("rbuf_start: %d\n", rbuf_start);
  65898. + printk ("rbuf_len: %d\n", rbuf_len);
  65899. + printk ("off: %d\n", off);
  65900. + printk ("start: %p\n\n", *start);
  65901. +*/
  65902. + if (done) {
  65903. + c = 0;
  65904. + done = 0;
  65905. + *eof = 1;
  65906. + return 0;
  65907. + }
  65908. +
  65909. + if (c == 0) {
  65910. + if (rbuf_len == RBUF_LEN)
  65911. + s = rbuf_start;
  65912. + else s = 0;
  65913. + }
  65914. +
  65915. + for (i=0; i<count && c<rbuf_len; i++, c++) {
  65916. + page[i] = rbuf[(c+s) % RBUF_LEN];
  65917. + }
  65918. + *start = page;
  65919. +
  65920. + if (c >= rbuf_len) {
  65921. + *eof = 1;
  65922. + done = 1;
  65923. + }
  65924. +
  65925. +
  65926. + return i;
  65927. +}
  65928. +
  65929. +static int __init init (void)
  65930. +{
  65931. +
  65932. + int retval = 0;
  65933. +
  65934. + pdir = proc_mkdir("isoc_test", NULL);
  65935. + if(pdir == NULL) {
  65936. + retval = -ENOMEM;
  65937. + printk("Error creating dir\n");
  65938. + goto done;
  65939. + }
  65940. + pdir->owner = THIS_MODULE;
  65941. +
  65942. + pfile = create_proc_read_entry("isoc_data",
  65943. + 0444, pdir,
  65944. + isoc_read_data,
  65945. + NULL);
  65946. + if (pfile == NULL) {
  65947. + retval = -ENOMEM;
  65948. + printk("Error creating file\n");
  65949. + goto no_file;
  65950. + }
  65951. + pfile->owner = THIS_MODULE;
  65952. +
  65953. + return usb_gadget_register_driver (&zero_driver);
  65954. +
  65955. + no_file:
  65956. + remove_proc_entry("isoc_data", NULL);
  65957. + done:
  65958. + return retval;
  65959. +}
  65960. +module_init (init);
  65961. +
  65962. +static void __exit cleanup (void)
  65963. +{
  65964. +
  65965. + usb_gadget_unregister_driver (&zero_driver);
  65966. +
  65967. + remove_proc_entry("isoc_data", pdir);
  65968. + remove_proc_entry("isoc_test", NULL);
  65969. +}
  65970. +module_exit (cleanup);
  65971. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_cfi_common.h linux-rpi/drivers/usb/host/dwc_otg/dwc_cfi_common.h
  65972. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_cfi_common.h 1970-01-01 01:00:00.000000000 +0100
  65973. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_cfi_common.h 2015-02-09 04:40:29.000000000 +0100
  65974. @@ -0,0 +1,142 @@
  65975. +/* ==========================================================================
  65976. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  65977. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  65978. + * otherwise expressly agreed to in writing between Synopsys and you.
  65979. + *
  65980. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  65981. + * any End User Software License Agreement or Agreement for Licensed Product
  65982. + * with Synopsys or any supplement thereto. You are permitted to use and
  65983. + * redistribute this Software in source and binary forms, with or without
  65984. + * modification, provided that redistributions of source code must retain this
  65985. + * notice. You may not view, use, disclose, copy or distribute this file or
  65986. + * any information contained herein except pursuant to this license grant from
  65987. + * Synopsys. If you do not agree with this notice, including the disclaimer
  65988. + * below, then you are not authorized to use the Software.
  65989. + *
  65990. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  65991. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  65992. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  65993. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  65994. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  65995. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  65996. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  65997. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  65998. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  65999. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66000. + * DAMAGE.
  66001. + * ========================================================================== */
  66002. +
  66003. +#if !defined(__DWC_CFI_COMMON_H__)
  66004. +#define __DWC_CFI_COMMON_H__
  66005. +
  66006. +//#include <linux/types.h>
  66007. +
  66008. +/**
  66009. + * @file
  66010. + *
  66011. + * This file contains the CFI specific common constants, interfaces
  66012. + * (functions and macros) and structures for Linux. No PCD specific
  66013. + * data structure or definition is to be included in this file.
  66014. + *
  66015. + */
  66016. +
  66017. +/** This is a request for all Core Features */
  66018. +#define VEN_CORE_GET_FEATURES 0xB1
  66019. +
  66020. +/** This is a request to get the value of a specific Core Feature */
  66021. +#define VEN_CORE_GET_FEATURE 0xB2
  66022. +
  66023. +/** This command allows the host to set the value of a specific Core Feature */
  66024. +#define VEN_CORE_SET_FEATURE 0xB3
  66025. +
  66026. +/** This command allows the host to set the default values of
  66027. + * either all or any specific Core Feature
  66028. + */
  66029. +#define VEN_CORE_RESET_FEATURES 0xB4
  66030. +
  66031. +/** This command forces the PCD to write the deferred values of a Core Features */
  66032. +#define VEN_CORE_ACTIVATE_FEATURES 0xB5
  66033. +
  66034. +/** This request reads a DWORD value from a register at the specified offset */
  66035. +#define VEN_CORE_READ_REGISTER 0xB6
  66036. +
  66037. +/** This request writes a DWORD value into a register at the specified offset */
  66038. +#define VEN_CORE_WRITE_REGISTER 0xB7
  66039. +
  66040. +/** This structure is the header of the Core Features dataset returned to
  66041. + * the Host
  66042. + */
  66043. +struct cfi_all_features_header {
  66044. +/** The features header structure length is */
  66045. +#define CFI_ALL_FEATURES_HDR_LEN 8
  66046. + /**
  66047. + * The total length of the features dataset returned to the Host
  66048. + */
  66049. + uint16_t wTotalLen;
  66050. +
  66051. + /**
  66052. + * CFI version number inBinary-Coded Decimal (i.e., 1.00 is 100H).
  66053. + * This field identifies the version of the CFI Specification with which
  66054. + * the device is compliant.
  66055. + */
  66056. + uint16_t wVersion;
  66057. +
  66058. + /** The ID of the Core */
  66059. + uint16_t wCoreID;
  66060. +#define CFI_CORE_ID_UDC 1
  66061. +#define CFI_CORE_ID_OTG 2
  66062. +#define CFI_CORE_ID_WUDEV 3
  66063. +
  66064. + /** Number of features returned by VEN_CORE_GET_FEATURES request */
  66065. + uint16_t wNumFeatures;
  66066. +} UPACKED;
  66067. +
  66068. +typedef struct cfi_all_features_header cfi_all_features_header_t;
  66069. +
  66070. +/** This structure is a header of the Core Feature descriptor dataset returned to
  66071. + * the Host after the VEN_CORE_GET_FEATURES request
  66072. + */
  66073. +struct cfi_feature_desc_header {
  66074. +#define CFI_FEATURE_DESC_HDR_LEN 8
  66075. +
  66076. + /** The feature ID */
  66077. + uint16_t wFeatureID;
  66078. +
  66079. + /** Length of this feature descriptor in bytes - including the
  66080. + * length of the feature name string
  66081. + */
  66082. + uint16_t wLength;
  66083. +
  66084. + /** The data length of this feature in bytes */
  66085. + uint16_t wDataLength;
  66086. +
  66087. + /**
  66088. + * Attributes of this features
  66089. + * D0: Access rights
  66090. + * 0 - Read/Write
  66091. + * 1 - Read only
  66092. + */
  66093. + uint8_t bmAttributes;
  66094. +#define CFI_FEATURE_ATTR_RO 1
  66095. +#define CFI_FEATURE_ATTR_RW 0
  66096. +
  66097. + /** Length of the feature name in bytes */
  66098. + uint8_t bNameLen;
  66099. +
  66100. + /** The feature name buffer */
  66101. + //uint8_t *name;
  66102. +} UPACKED;
  66103. +
  66104. +typedef struct cfi_feature_desc_header cfi_feature_desc_header_t;
  66105. +
  66106. +/**
  66107. + * This structure describes a NULL terminated string referenced by its id field.
  66108. + * It is very similar to usb_string structure but has the id field type set to 16-bit.
  66109. + */
  66110. +struct cfi_string {
  66111. + uint16_t id;
  66112. + const uint8_t *s;
  66113. +};
  66114. +typedef struct cfi_string cfi_string_t;
  66115. +
  66116. +#endif
  66117. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_adp.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.c
  66118. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_adp.c 1970-01-01 01:00:00.000000000 +0100
  66119. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.c 2015-02-09 04:40:29.000000000 +0100
  66120. @@ -0,0 +1,854 @@
  66121. +/* ==========================================================================
  66122. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.c $
  66123. + * $Revision: #12 $
  66124. + * $Date: 2011/10/26 $
  66125. + * $Change: 1873028 $
  66126. + *
  66127. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66128. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66129. + * otherwise expressly agreed to in writing between Synopsys and you.
  66130. + *
  66131. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66132. + * any End User Software License Agreement or Agreement for Licensed Product
  66133. + * with Synopsys or any supplement thereto. You are permitted to use and
  66134. + * redistribute this Software in source and binary forms, with or without
  66135. + * modification, provided that redistributions of source code must retain this
  66136. + * notice. You may not view, use, disclose, copy or distribute this file or
  66137. + * any information contained herein except pursuant to this license grant from
  66138. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66139. + * below, then you are not authorized to use the Software.
  66140. + *
  66141. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66142. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66143. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66144. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66145. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66146. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66147. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66148. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66149. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66150. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66151. + * DAMAGE.
  66152. + * ========================================================================== */
  66153. +
  66154. +#include "dwc_os.h"
  66155. +#include "dwc_otg_regs.h"
  66156. +#include "dwc_otg_cil.h"
  66157. +#include "dwc_otg_adp.h"
  66158. +
  66159. +/** @file
  66160. + *
  66161. + * This file contains the most of the Attach Detect Protocol implementation for
  66162. + * the driver to support OTG Rev2.0.
  66163. + *
  66164. + */
  66165. +
  66166. +void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value)
  66167. +{
  66168. + adpctl_data_t adpctl;
  66169. +
  66170. + adpctl.d32 = value;
  66171. + adpctl.b.ar = 0x2;
  66172. +
  66173. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  66174. +
  66175. + while (adpctl.b.ar) {
  66176. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  66177. + }
  66178. +
  66179. +}
  66180. +
  66181. +/**
  66182. + * Function is called to read ADP registers
  66183. + */
  66184. +uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if)
  66185. +{
  66186. + adpctl_data_t adpctl;
  66187. +
  66188. + adpctl.d32 = 0;
  66189. + adpctl.b.ar = 0x1;
  66190. +
  66191. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  66192. +
  66193. + while (adpctl.b.ar) {
  66194. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  66195. + }
  66196. +
  66197. + return adpctl.d32;
  66198. +}
  66199. +
  66200. +/**
  66201. + * Function is called to read ADPCTL register and filter Write-clear bits
  66202. + */
  66203. +uint32_t dwc_otg_adp_read_reg_filter(dwc_otg_core_if_t * core_if)
  66204. +{
  66205. + adpctl_data_t adpctl;
  66206. +
  66207. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  66208. + adpctl.b.adp_tmout_int = 0;
  66209. + adpctl.b.adp_prb_int = 0;
  66210. + adpctl.b.adp_tmout_int = 0;
  66211. +
  66212. + return adpctl.d32;
  66213. +}
  66214. +
  66215. +/**
  66216. + * Function is called to write ADP registers
  66217. + */
  66218. +void dwc_otg_adp_modify_reg(dwc_otg_core_if_t * core_if, uint32_t clr,
  66219. + uint32_t set)
  66220. +{
  66221. + dwc_otg_adp_write_reg(core_if,
  66222. + (dwc_otg_adp_read_reg(core_if) & (~clr)) | set);
  66223. +}
  66224. +
  66225. +static void adp_sense_timeout(void *ptr)
  66226. +{
  66227. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  66228. + core_if->adp.sense_timer_started = 0;
  66229. + DWC_PRINTF("ADP SENSE TIMEOUT\n");
  66230. + if (core_if->adp_enable) {
  66231. + dwc_otg_adp_sense_stop(core_if);
  66232. + dwc_otg_adp_probe_start(core_if);
  66233. + }
  66234. +}
  66235. +
  66236. +/**
  66237. + * This function is called when the ADP vbus timer expires. Timeout is 1.1s.
  66238. + */
  66239. +static void adp_vbuson_timeout(void *ptr)
  66240. +{
  66241. + gpwrdn_data_t gpwrdn;
  66242. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  66243. + hprt0_data_t hprt0 = {.d32 = 0 };
  66244. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  66245. + DWC_PRINTF("%s: 1.1 seconds expire after turning on VBUS\n",__FUNCTION__);
  66246. + if (core_if) {
  66247. + core_if->adp.vbuson_timer_started = 0;
  66248. + /* Turn off vbus */
  66249. + hprt0.b.prtpwr = 1;
  66250. + DWC_MODIFY_REG32(core_if->host_if->hprt0, hprt0.d32, 0);
  66251. + gpwrdn.d32 = 0;
  66252. +
  66253. + /* Power off the core */
  66254. + if (core_if->power_down == 2) {
  66255. + /* Enable Wakeup Logic */
  66256. +// gpwrdn.b.wkupactiv = 1;
  66257. + gpwrdn.b.pmuactv = 0;
  66258. + gpwrdn.b.pwrdnrstn = 1;
  66259. + gpwrdn.b.pwrdnclmp = 1;
  66260. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  66261. + gpwrdn.d32);
  66262. +
  66263. + /* Suspend the Phy Clock */
  66264. + pcgcctl.b.stoppclk = 1;
  66265. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  66266. +
  66267. + /* Switch on VDD */
  66268. +// gpwrdn.b.wkupactiv = 1;
  66269. + gpwrdn.b.pmuactv = 1;
  66270. + gpwrdn.b.pwrdnrstn = 1;
  66271. + gpwrdn.b.pwrdnclmp = 1;
  66272. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  66273. + gpwrdn.d32);
  66274. + } else {
  66275. + /* Enable Power Down Logic */
  66276. + gpwrdn.b.pmuintsel = 1;
  66277. + gpwrdn.b.pmuactv = 1;
  66278. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  66279. + }
  66280. +
  66281. + /* Power off the core */
  66282. + if (core_if->power_down == 2) {
  66283. + gpwrdn.d32 = 0;
  66284. + gpwrdn.b.pwrdnswtch = 1;
  66285. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn,
  66286. + gpwrdn.d32, 0);
  66287. + }
  66288. +
  66289. + /* Unmask SRP detected interrupt from Power Down Logic */
  66290. + gpwrdn.d32 = 0;
  66291. + gpwrdn.b.srp_det_msk = 1;
  66292. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  66293. +
  66294. + dwc_otg_adp_probe_start(core_if);
  66295. + dwc_otg_dump_global_registers(core_if);
  66296. + dwc_otg_dump_host_registers(core_if);
  66297. + }
  66298. +
  66299. +}
  66300. +
  66301. +/**
  66302. + * Start the ADP Initial Probe timer to detect if Port Connected interrupt is
  66303. + * not asserted within 1.1 seconds.
  66304. + *
  66305. + * @param core_if the pointer to core_if strucure.
  66306. + */
  66307. +void dwc_otg_adp_vbuson_timer_start(dwc_otg_core_if_t * core_if)
  66308. +{
  66309. + core_if->adp.vbuson_timer_started = 1;
  66310. + if (core_if->adp.vbuson_timer)
  66311. + {
  66312. + DWC_PRINTF("SCHEDULING VBUSON TIMER\n");
  66313. + /* 1.1 secs + 60ms necessary for cil_hcd_start*/
  66314. + DWC_TIMER_SCHEDULE(core_if->adp.vbuson_timer, 1160);
  66315. + } else {
  66316. + DWC_WARN("VBUSON_TIMER = %p\n",core_if->adp.vbuson_timer);
  66317. + }
  66318. +}
  66319. +
  66320. +#if 0
  66321. +/**
  66322. + * Masks all DWC OTG core interrupts
  66323. + *
  66324. + */
  66325. +static void mask_all_interrupts(dwc_otg_core_if_t * core_if)
  66326. +{
  66327. + int i;
  66328. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  66329. +
  66330. + /* Mask Host Interrupts */
  66331. +
  66332. + /* Clear and disable HCINTs */
  66333. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  66334. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk, 0);
  66335. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcint, 0xFFFFFFFF);
  66336. +
  66337. + }
  66338. +
  66339. + /* Clear and disable HAINT */
  66340. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk, 0x0000);
  66341. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haint, 0xFFFFFFFF);
  66342. +
  66343. + /* Mask Device Interrupts */
  66344. + if (!core_if->multiproc_int_enable) {
  66345. + /* Clear and disable IN Endpoint interrupts */
  66346. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, 0);
  66347. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  66348. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  66349. + diepint, 0xFFFFFFFF);
  66350. + }
  66351. +
  66352. + /* Clear and disable OUT Endpoint interrupts */
  66353. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, 0);
  66354. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  66355. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  66356. + doepint, 0xFFFFFFFF);
  66357. + }
  66358. +
  66359. + /* Clear and disable DAINT */
  66360. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daint,
  66361. + 0xFFFFFFFF);
  66362. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, 0);
  66363. + } else {
  66364. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  66365. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  66366. + diepeachintmsk[i], 0);
  66367. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  66368. + diepint, 0xFFFFFFFF);
  66369. + }
  66370. +
  66371. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  66372. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  66373. + doepeachintmsk[i], 0);
  66374. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  66375. + doepint, 0xFFFFFFFF);
  66376. + }
  66377. +
  66378. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  66379. + 0);
  66380. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachint,
  66381. + 0xFFFFFFFF);
  66382. +
  66383. + }
  66384. +
  66385. + /* Disable interrupts */
  66386. + ahbcfg.b.glblintrmsk = 1;
  66387. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  66388. +
  66389. + /* Disable all interrupts. */
  66390. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  66391. +
  66392. + /* Clear any pending interrupts */
  66393. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  66394. +
  66395. + /* Clear any pending OTG Interrupts */
  66396. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, 0xFFFFFFFF);
  66397. +}
  66398. +
  66399. +/**
  66400. + * Unmask Port Connection Detected interrupt
  66401. + *
  66402. + */
  66403. +static void unmask_conn_det_intr(dwc_otg_core_if_t * core_if)
  66404. +{
  66405. + gintmsk_data_t gintmsk = {.d32 = 0,.b.portintr = 1 };
  66406. +
  66407. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  66408. +}
  66409. +#endif
  66410. +
  66411. +/**
  66412. + * Starts the ADP Probing
  66413. + *
  66414. + * @param core_if the pointer to core_if structure.
  66415. + */
  66416. +uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if)
  66417. +{
  66418. +
  66419. + adpctl_data_t adpctl = {.d32 = 0};
  66420. + gpwrdn_data_t gpwrdn;
  66421. +#if 0
  66422. + adpctl_data_t adpctl_int = {.d32 = 0, .b.adp_prb_int = 1,
  66423. + .b.adp_sns_int = 1, b.adp_tmout_int};
  66424. +#endif
  66425. + dwc_otg_disable_global_interrupts(core_if);
  66426. + DWC_PRINTF("ADP Probe Start\n");
  66427. + core_if->adp.probe_enabled = 1;
  66428. +
  66429. + adpctl.b.adpres = 1;
  66430. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  66431. +
  66432. + while (adpctl.b.adpres) {
  66433. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  66434. + }
  66435. +
  66436. + adpctl.d32 = 0;
  66437. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  66438. +
  66439. + /* In Host mode unmask SRP detected interrupt */
  66440. + gpwrdn.d32 = 0;
  66441. + gpwrdn.b.sts_chngint_msk = 1;
  66442. + if (!gpwrdn.b.idsts) {
  66443. + gpwrdn.b.srp_det_msk = 1;
  66444. + }
  66445. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  66446. +
  66447. + adpctl.b.adp_tmout_int_msk = 1;
  66448. + adpctl.b.adp_prb_int_msk = 1;
  66449. + adpctl.b.prb_dschg = 1;
  66450. + adpctl.b.prb_delta = 1;
  66451. + adpctl.b.prb_per = 1;
  66452. + adpctl.b.adpen = 1;
  66453. + adpctl.b.enaprb = 1;
  66454. +
  66455. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  66456. + DWC_PRINTF("ADP Probe Finish\n");
  66457. + return 0;
  66458. +}
  66459. +
  66460. +/**
  66461. + * Starts the ADP Sense timer to detect if ADP Sense interrupt is not asserted
  66462. + * within 3 seconds.
  66463. + *
  66464. + * @param core_if the pointer to core_if strucure.
  66465. + */
  66466. +void dwc_otg_adp_sense_timer_start(dwc_otg_core_if_t * core_if)
  66467. +{
  66468. + core_if->adp.sense_timer_started = 1;
  66469. + DWC_TIMER_SCHEDULE(core_if->adp.sense_timer, 3000 /* 3 secs */ );
  66470. +}
  66471. +
  66472. +/**
  66473. + * Starts the ADP Sense
  66474. + *
  66475. + * @param core_if the pointer to core_if strucure.
  66476. + */
  66477. +uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if)
  66478. +{
  66479. + adpctl_data_t adpctl;
  66480. +
  66481. + DWC_PRINTF("ADP Sense Start\n");
  66482. +
  66483. + /* Unmask ADP sense interrupt and mask all other from the core */
  66484. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  66485. + adpctl.b.adp_sns_int_msk = 1;
  66486. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  66487. + dwc_otg_disable_global_interrupts(core_if); // vahrama
  66488. +
  66489. + /* Set ADP reset bit*/
  66490. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  66491. + adpctl.b.adpres = 1;
  66492. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  66493. +
  66494. + while (adpctl.b.adpres) {
  66495. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  66496. + }
  66497. +
  66498. + adpctl.b.adpres = 0;
  66499. + adpctl.b.adpen = 1;
  66500. + adpctl.b.enasns = 1;
  66501. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  66502. +
  66503. + dwc_otg_adp_sense_timer_start(core_if);
  66504. +
  66505. + return 0;
  66506. +}
  66507. +
  66508. +/**
  66509. + * Stops the ADP Probing
  66510. + *
  66511. + * @param core_if the pointer to core_if strucure.
  66512. + */
  66513. +uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if)
  66514. +{
  66515. +
  66516. + adpctl_data_t adpctl;
  66517. + DWC_PRINTF("Stop ADP probe\n");
  66518. + core_if->adp.probe_enabled = 0;
  66519. + core_if->adp.probe_counter = 0;
  66520. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  66521. +
  66522. + adpctl.b.adpen = 0;
  66523. + adpctl.b.adp_prb_int = 1;
  66524. + adpctl.b.adp_tmout_int = 1;
  66525. + adpctl.b.adp_sns_int = 1;
  66526. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  66527. +
  66528. + return 0;
  66529. +}
  66530. +
  66531. +/**
  66532. + * Stops the ADP Sensing
  66533. + *
  66534. + * @param core_if the pointer to core_if strucure.
  66535. + */
  66536. +uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if)
  66537. +{
  66538. + adpctl_data_t adpctl;
  66539. +
  66540. + core_if->adp.sense_enabled = 0;
  66541. +
  66542. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  66543. + adpctl.b.enasns = 0;
  66544. + adpctl.b.adp_sns_int = 1;
  66545. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  66546. +
  66547. + return 0;
  66548. +}
  66549. +
  66550. +/**
  66551. + * Called to turn on the VBUS after initial ADP probe in host mode.
  66552. + * If port power was already enabled in cil_hcd_start function then
  66553. + * only schedule a timer.
  66554. + *
  66555. + * @param core_if the pointer to core_if structure.
  66556. + */
  66557. +void dwc_otg_adp_turnon_vbus(dwc_otg_core_if_t * core_if)
  66558. +{
  66559. + hprt0_data_t hprt0 = {.d32 = 0 };
  66560. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  66561. + DWC_PRINTF("Turn on VBUS for 1.1s, port power is %d\n", hprt0.b.prtpwr);
  66562. +
  66563. + if (hprt0.b.prtpwr == 0) {
  66564. + hprt0.b.prtpwr = 1;
  66565. + //DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  66566. + }
  66567. +
  66568. + dwc_otg_adp_vbuson_timer_start(core_if);
  66569. +}
  66570. +
  66571. +/**
  66572. + * Called right after driver is loaded
  66573. + * to perform initial actions for ADP
  66574. + *
  66575. + * @param core_if the pointer to core_if structure.
  66576. + * @param is_host - flag for current mode of operation either from GINTSTS or GPWRDN
  66577. + */
  66578. +void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host)
  66579. +{
  66580. + gpwrdn_data_t gpwrdn;
  66581. +
  66582. + DWC_PRINTF("ADP Initial Start\n");
  66583. + core_if->adp.adp_started = 1;
  66584. +
  66585. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  66586. + dwc_otg_disable_global_interrupts(core_if);
  66587. + if (is_host) {
  66588. + DWC_PRINTF("HOST MODE\n");
  66589. + /* Enable Power Down Logic Interrupt*/
  66590. + gpwrdn.d32 = 0;
  66591. + gpwrdn.b.pmuintsel = 1;
  66592. + gpwrdn.b.pmuactv = 1;
  66593. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  66594. + /* Initialize first ADP probe to obtain Ramp Time value */
  66595. + core_if->adp.initial_probe = 1;
  66596. + dwc_otg_adp_probe_start(core_if);
  66597. + } else {
  66598. + gotgctl_data_t gotgctl;
  66599. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  66600. + DWC_PRINTF("DEVICE MODE\n");
  66601. + if (gotgctl.b.bsesvld == 0) {
  66602. + /* Enable Power Down Logic Interrupt*/
  66603. + gpwrdn.d32 = 0;
  66604. + DWC_PRINTF("VBUS is not valid - start ADP probe\n");
  66605. + gpwrdn.b.pmuintsel = 1;
  66606. + gpwrdn.b.pmuactv = 1;
  66607. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  66608. + core_if->adp.initial_probe = 1;
  66609. + dwc_otg_adp_probe_start(core_if);
  66610. + } else {
  66611. + DWC_PRINTF("VBUS is valid - initialize core as a Device\n");
  66612. + core_if->op_state = B_PERIPHERAL;
  66613. + dwc_otg_core_init(core_if);
  66614. + dwc_otg_enable_global_interrupts(core_if);
  66615. + cil_pcd_start(core_if);
  66616. + dwc_otg_dump_global_registers(core_if);
  66617. + dwc_otg_dump_dev_registers(core_if);
  66618. + }
  66619. + }
  66620. +}
  66621. +
  66622. +void dwc_otg_adp_init(dwc_otg_core_if_t * core_if)
  66623. +{
  66624. + core_if->adp.adp_started = 0;
  66625. + core_if->adp.initial_probe = 0;
  66626. + core_if->adp.probe_timer_values[0] = -1;
  66627. + core_if->adp.probe_timer_values[1] = -1;
  66628. + core_if->adp.probe_enabled = 0;
  66629. + core_if->adp.sense_enabled = 0;
  66630. + core_if->adp.sense_timer_started = 0;
  66631. + core_if->adp.vbuson_timer_started = 0;
  66632. + core_if->adp.probe_counter = 0;
  66633. + core_if->adp.gpwrdn = 0;
  66634. + core_if->adp.attached = DWC_OTG_ADP_UNKOWN;
  66635. + /* Initialize timers */
  66636. + core_if->adp.sense_timer =
  66637. + DWC_TIMER_ALLOC("ADP SENSE TIMER", adp_sense_timeout, core_if);
  66638. + core_if->adp.vbuson_timer =
  66639. + DWC_TIMER_ALLOC("ADP VBUS ON TIMER", adp_vbuson_timeout, core_if);
  66640. + if (!core_if->adp.sense_timer || !core_if->adp.vbuson_timer)
  66641. + {
  66642. + DWC_ERROR("Could not allocate memory for ADP timers\n");
  66643. + }
  66644. +}
  66645. +
  66646. +void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if)
  66647. +{
  66648. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  66649. + gpwrdn.b.pmuintsel = 1;
  66650. + gpwrdn.b.pmuactv = 1;
  66651. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66652. +
  66653. + if (core_if->adp.probe_enabled)
  66654. + dwc_otg_adp_probe_stop(core_if);
  66655. + if (core_if->adp.sense_enabled)
  66656. + dwc_otg_adp_sense_stop(core_if);
  66657. + if (core_if->adp.sense_timer_started)
  66658. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  66659. + if (core_if->adp.vbuson_timer_started)
  66660. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  66661. + DWC_TIMER_FREE(core_if->adp.sense_timer);
  66662. + DWC_TIMER_FREE(core_if->adp.vbuson_timer);
  66663. +}
  66664. +
  66665. +/////////////////////////////////////////////////////////////////////
  66666. +////////////// ADP Interrupt Handlers ///////////////////////////////
  66667. +/////////////////////////////////////////////////////////////////////
  66668. +/**
  66669. + * This function sets Ramp Timer values
  66670. + */
  66671. +static uint32_t set_timer_value(dwc_otg_core_if_t * core_if, uint32_t val)
  66672. +{
  66673. + if (core_if->adp.probe_timer_values[0] == -1) {
  66674. + core_if->adp.probe_timer_values[0] = val;
  66675. + core_if->adp.probe_timer_values[1] = -1;
  66676. + return 1;
  66677. + } else {
  66678. + core_if->adp.probe_timer_values[1] =
  66679. + core_if->adp.probe_timer_values[0];
  66680. + core_if->adp.probe_timer_values[0] = val;
  66681. + return 0;
  66682. + }
  66683. +}
  66684. +
  66685. +/**
  66686. + * This function compares Ramp Timer values
  66687. + */
  66688. +static uint32_t compare_timer_values(dwc_otg_core_if_t * core_if)
  66689. +{
  66690. + uint32_t diff;
  66691. + if (core_if->adp.probe_timer_values[0]>=core_if->adp.probe_timer_values[1])
  66692. + diff = core_if->adp.probe_timer_values[0]-core_if->adp.probe_timer_values[1];
  66693. + else
  66694. + diff = core_if->adp.probe_timer_values[1]-core_if->adp.probe_timer_values[0];
  66695. + if(diff < 2) {
  66696. + return 0;
  66697. + } else {
  66698. + return 1;
  66699. + }
  66700. +}
  66701. +
  66702. +/**
  66703. + * This function handles ADP Probe Interrupts
  66704. + */
  66705. +static int32_t dwc_otg_adp_handle_prb_intr(dwc_otg_core_if_t * core_if,
  66706. + uint32_t val)
  66707. +{
  66708. + adpctl_data_t adpctl = {.d32 = 0 };
  66709. + gpwrdn_data_t gpwrdn, temp;
  66710. + adpctl.d32 = val;
  66711. +
  66712. + temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  66713. + core_if->adp.probe_counter++;
  66714. + core_if->adp.gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  66715. + if (adpctl.b.rtim == 0 && !temp.b.idsts){
  66716. + DWC_PRINTF("RTIM value is 0\n");
  66717. + goto exit;
  66718. + }
  66719. + if (set_timer_value(core_if, adpctl.b.rtim) &&
  66720. + core_if->adp.initial_probe) {
  66721. + core_if->adp.initial_probe = 0;
  66722. + dwc_otg_adp_probe_stop(core_if);
  66723. + gpwrdn.d32 = 0;
  66724. + gpwrdn.b.pmuactv = 1;
  66725. + gpwrdn.b.pmuintsel = 1;
  66726. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66727. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  66728. +
  66729. + /* check which value is for device mode and which for Host mode */
  66730. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  66731. + /*
  66732. + * Turn on VBUS after initial ADP probe.
  66733. + */
  66734. + core_if->op_state = A_HOST;
  66735. + dwc_otg_enable_global_interrupts(core_if);
  66736. + DWC_SPINUNLOCK(core_if->lock);
  66737. + cil_hcd_start(core_if);
  66738. + dwc_otg_adp_turnon_vbus(core_if);
  66739. + DWC_SPINLOCK(core_if->lock);
  66740. + } else {
  66741. + /*
  66742. + * Initiate SRP after initial ADP probe.
  66743. + */
  66744. + dwc_otg_enable_global_interrupts(core_if);
  66745. + dwc_otg_initiate_srp(core_if);
  66746. + }
  66747. + } else if (core_if->adp.probe_counter > 2){
  66748. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  66749. + if (compare_timer_values(core_if)) {
  66750. + DWC_PRINTF("Difference in timer values !!! \n");
  66751. +// core_if->adp.attached = DWC_OTG_ADP_ATTACHED;
  66752. + dwc_otg_adp_probe_stop(core_if);
  66753. +
  66754. + /* Power on the core */
  66755. + if (core_if->power_down == 2) {
  66756. + gpwrdn.b.pwrdnswtch = 1;
  66757. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  66758. + gpwrdn, 0, gpwrdn.d32);
  66759. + }
  66760. +
  66761. + /* check which value is for device mode and which for Host mode */
  66762. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  66763. + /* Disable Interrupt from Power Down Logic */
  66764. + gpwrdn.d32 = 0;
  66765. + gpwrdn.b.pmuintsel = 1;
  66766. + gpwrdn.b.pmuactv = 1;
  66767. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  66768. + gpwrdn, gpwrdn.d32, 0);
  66769. +
  66770. + /*
  66771. + * Initialize the Core for Host mode.
  66772. + */
  66773. + core_if->op_state = A_HOST;
  66774. + dwc_otg_core_init(core_if);
  66775. + dwc_otg_enable_global_interrupts(core_if);
  66776. + cil_hcd_start(core_if);
  66777. + } else {
  66778. + gotgctl_data_t gotgctl;
  66779. + /* Mask SRP detected interrupt from Power Down Logic */
  66780. + gpwrdn.d32 = 0;
  66781. + gpwrdn.b.srp_det_msk = 1;
  66782. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  66783. + gpwrdn, gpwrdn.d32, 0);
  66784. +
  66785. + /* Disable Power Down Logic */
  66786. + gpwrdn.d32 = 0;
  66787. + gpwrdn.b.pmuintsel = 1;
  66788. + gpwrdn.b.pmuactv = 1;
  66789. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  66790. + gpwrdn, gpwrdn.d32, 0);
  66791. +
  66792. + /*
  66793. + * Initialize the Core for Device mode.
  66794. + */
  66795. + core_if->op_state = B_PERIPHERAL;
  66796. + dwc_otg_core_init(core_if);
  66797. + dwc_otg_enable_global_interrupts(core_if);
  66798. + cil_pcd_start(core_if);
  66799. +
  66800. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  66801. + if (!gotgctl.b.bsesvld) {
  66802. + dwc_otg_initiate_srp(core_if);
  66803. + }
  66804. + }
  66805. + }
  66806. + if (core_if->power_down == 2) {
  66807. + if (gpwrdn.b.bsessvld) {
  66808. + /* Mask SRP detected interrupt from Power Down Logic */
  66809. + gpwrdn.d32 = 0;
  66810. + gpwrdn.b.srp_det_msk = 1;
  66811. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66812. +
  66813. + /* Disable Power Down Logic */
  66814. + gpwrdn.d32 = 0;
  66815. + gpwrdn.b.pmuactv = 1;
  66816. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66817. +
  66818. + /*
  66819. + * Initialize the Core for Device mode.
  66820. + */
  66821. + core_if->op_state = B_PERIPHERAL;
  66822. + dwc_otg_core_init(core_if);
  66823. + dwc_otg_enable_global_interrupts(core_if);
  66824. + cil_pcd_start(core_if);
  66825. + }
  66826. + }
  66827. + }
  66828. +exit:
  66829. + /* Clear interrupt */
  66830. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  66831. + adpctl.b.adp_prb_int = 1;
  66832. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  66833. +
  66834. + return 0;
  66835. +}
  66836. +
  66837. +/**
  66838. + * This function hadles ADP Sense Interrupt
  66839. + */
  66840. +static int32_t dwc_otg_adp_handle_sns_intr(dwc_otg_core_if_t * core_if)
  66841. +{
  66842. + adpctl_data_t adpctl;
  66843. + /* Stop ADP Sense timer */
  66844. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  66845. +
  66846. + /* Restart ADP Sense timer */
  66847. + dwc_otg_adp_sense_timer_start(core_if);
  66848. +
  66849. + /* Clear interrupt */
  66850. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  66851. + adpctl.b.adp_sns_int = 1;
  66852. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  66853. +
  66854. + return 0;
  66855. +}
  66856. +
  66857. +/**
  66858. + * This function handles ADP Probe Interrupts
  66859. + */
  66860. +static int32_t dwc_otg_adp_handle_prb_tmout_intr(dwc_otg_core_if_t * core_if,
  66861. + uint32_t val)
  66862. +{
  66863. + adpctl_data_t adpctl = {.d32 = 0 };
  66864. + adpctl.d32 = val;
  66865. + set_timer_value(core_if, adpctl.b.rtim);
  66866. +
  66867. + /* Clear interrupt */
  66868. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  66869. + adpctl.b.adp_tmout_int = 1;
  66870. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  66871. +
  66872. + return 0;
  66873. +}
  66874. +
  66875. +/**
  66876. + * ADP Interrupt handler.
  66877. + *
  66878. + */
  66879. +int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if)
  66880. +{
  66881. + int retval = 0;
  66882. + adpctl_data_t adpctl = {.d32 = 0};
  66883. +
  66884. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  66885. + DWC_PRINTF("ADPCTL = %08x\n",adpctl.d32);
  66886. +
  66887. + if (adpctl.b.adp_sns_int & adpctl.b.adp_sns_int_msk) {
  66888. + DWC_PRINTF("ADP Sense interrupt\n");
  66889. + retval |= dwc_otg_adp_handle_sns_intr(core_if);
  66890. + }
  66891. + if (adpctl.b.adp_tmout_int & adpctl.b.adp_tmout_int_msk) {
  66892. + DWC_PRINTF("ADP timeout interrupt\n");
  66893. + retval |= dwc_otg_adp_handle_prb_tmout_intr(core_if, adpctl.d32);
  66894. + }
  66895. + if (adpctl.b.adp_prb_int & adpctl.b.adp_prb_int_msk) {
  66896. + DWC_PRINTF("ADP Probe interrupt\n");
  66897. + adpctl.b.adp_prb_int = 1;
  66898. + retval |= dwc_otg_adp_handle_prb_intr(core_if, adpctl.d32);
  66899. + }
  66900. +
  66901. +// dwc_otg_adp_modify_reg(core_if, adpctl.d32, 0);
  66902. + //dwc_otg_adp_write_reg(core_if, adpctl.d32);
  66903. + DWC_PRINTF("RETURN FROM ADP ISR\n");
  66904. +
  66905. + return retval;
  66906. +}
  66907. +
  66908. +/**
  66909. + *
  66910. + * @param core_if Programming view of DWC_otg controller.
  66911. + */
  66912. +int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if)
  66913. +{
  66914. +
  66915. +#ifndef DWC_HOST_ONLY
  66916. + hprt0_data_t hprt0;
  66917. + gpwrdn_data_t gpwrdn;
  66918. + DWC_DEBUGPL(DBG_ANY, "++ Power Down Logic Session Request Interrupt++\n");
  66919. +
  66920. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  66921. + /* check which value is for device mode and which for Host mode */
  66922. + if (!gpwrdn.b.idsts) { /* considered host mode value is 0 */
  66923. + DWC_PRINTF("SRP: Host mode\n");
  66924. +
  66925. + if (core_if->adp_enable) {
  66926. + dwc_otg_adp_probe_stop(core_if);
  66927. +
  66928. + /* Power on the core */
  66929. + if (core_if->power_down == 2) {
  66930. + gpwrdn.b.pwrdnswtch = 1;
  66931. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  66932. + gpwrdn, 0, gpwrdn.d32);
  66933. + }
  66934. +
  66935. + core_if->op_state = A_HOST;
  66936. + dwc_otg_core_init(core_if);
  66937. + dwc_otg_enable_global_interrupts(core_if);
  66938. + cil_hcd_start(core_if);
  66939. + }
  66940. +
  66941. + /* Turn on the port power bit. */
  66942. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  66943. + hprt0.b.prtpwr = 1;
  66944. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  66945. +
  66946. + /* Start the Connection timer. So a message can be displayed
  66947. + * if connect does not occur within 10 seconds. */
  66948. + cil_hcd_session_start(core_if);
  66949. + } else {
  66950. + DWC_PRINTF("SRP: Device mode %s\n", __FUNCTION__);
  66951. + if (core_if->adp_enable) {
  66952. + dwc_otg_adp_probe_stop(core_if);
  66953. +
  66954. + /* Power on the core */
  66955. + if (core_if->power_down == 2) {
  66956. + gpwrdn.b.pwrdnswtch = 1;
  66957. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  66958. + gpwrdn, 0, gpwrdn.d32);
  66959. + }
  66960. +
  66961. + gpwrdn.d32 = 0;
  66962. + gpwrdn.b.pmuactv = 0;
  66963. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  66964. + gpwrdn.d32);
  66965. +
  66966. + core_if->op_state = B_PERIPHERAL;
  66967. + dwc_otg_core_init(core_if);
  66968. + dwc_otg_enable_global_interrupts(core_if);
  66969. + cil_pcd_start(core_if);
  66970. + }
  66971. + }
  66972. +#endif
  66973. + return 1;
  66974. +}
  66975. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_adp.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.h
  66976. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_adp.h 1970-01-01 01:00:00.000000000 +0100
  66977. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.h 2015-02-09 04:40:29.000000000 +0100
  66978. @@ -0,0 +1,80 @@
  66979. +/* ==========================================================================
  66980. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.h $
  66981. + * $Revision: #7 $
  66982. + * $Date: 2011/10/24 $
  66983. + * $Change: 1871159 $
  66984. + *
  66985. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66986. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66987. + * otherwise expressly agreed to in writing between Synopsys and you.
  66988. + *
  66989. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66990. + * any End User Software License Agreement or Agreement for Licensed Product
  66991. + * with Synopsys or any supplement thereto. You are permitted to use and
  66992. + * redistribute this Software in source and binary forms, with or without
  66993. + * modification, provided that redistributions of source code must retain this
  66994. + * notice. You may not view, use, disclose, copy or distribute this file or
  66995. + * any information contained herein except pursuant to this license grant from
  66996. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66997. + * below, then you are not authorized to use the Software.
  66998. + *
  66999. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67000. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67001. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67002. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67003. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67004. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67005. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67006. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67007. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67008. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67009. + * DAMAGE.
  67010. + * ========================================================================== */
  67011. +
  67012. +#ifndef __DWC_OTG_ADP_H__
  67013. +#define __DWC_OTG_ADP_H__
  67014. +
  67015. +/**
  67016. + * @file
  67017. + *
  67018. + * This file contains the Attach Detect Protocol interfaces and defines
  67019. + * (functions) and structures for Linux.
  67020. + *
  67021. + */
  67022. +
  67023. +#define DWC_OTG_ADP_UNATTACHED 0
  67024. +#define DWC_OTG_ADP_ATTACHED 1
  67025. +#define DWC_OTG_ADP_UNKOWN 2
  67026. +
  67027. +typedef struct dwc_otg_adp {
  67028. + uint32_t adp_started;
  67029. + uint32_t initial_probe;
  67030. + int32_t probe_timer_values[2];
  67031. + uint32_t probe_enabled;
  67032. + uint32_t sense_enabled;
  67033. + dwc_timer_t *sense_timer;
  67034. + uint32_t sense_timer_started;
  67035. + dwc_timer_t *vbuson_timer;
  67036. + uint32_t vbuson_timer_started;
  67037. + uint32_t attached;
  67038. + uint32_t probe_counter;
  67039. + uint32_t gpwrdn;
  67040. +} dwc_otg_adp_t;
  67041. +
  67042. +/**
  67043. + * Attach Detect Protocol functions
  67044. + */
  67045. +
  67046. +extern void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value);
  67047. +extern uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if);
  67048. +extern uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if);
  67049. +extern uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if);
  67050. +extern uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if);
  67051. +extern uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if);
  67052. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  67053. +extern void dwc_otg_adp_init(dwc_otg_core_if_t * core_if);
  67054. +extern void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if);
  67055. +extern int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if);
  67056. +extern int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if);
  67057. +
  67058. +#endif //__DWC_OTG_ADP_H__
  67059. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_attr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.c
  67060. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_attr.c 1970-01-01 01:00:00.000000000 +0100
  67061. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.c 2015-02-09 04:40:29.000000000 +0100
  67062. @@ -0,0 +1,1210 @@
  67063. +/* ==========================================================================
  67064. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
  67065. + * $Revision: #44 $
  67066. + * $Date: 2010/11/29 $
  67067. + * $Change: 1636033 $
  67068. + *
  67069. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  67070. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  67071. + * otherwise expressly agreed to in writing between Synopsys and you.
  67072. + *
  67073. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  67074. + * any End User Software License Agreement or Agreement for Licensed Product
  67075. + * with Synopsys or any supplement thereto. You are permitted to use and
  67076. + * redistribute this Software in source and binary forms, with or without
  67077. + * modification, provided that redistributions of source code must retain this
  67078. + * notice. You may not view, use, disclose, copy or distribute this file or
  67079. + * any information contained herein except pursuant to this license grant from
  67080. + * Synopsys. If you do not agree with this notice, including the disclaimer
  67081. + * below, then you are not authorized to use the Software.
  67082. + *
  67083. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67084. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67085. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67086. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67087. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67088. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67089. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67090. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67091. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67092. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67093. + * DAMAGE.
  67094. + * ========================================================================== */
  67095. +
  67096. +/** @file
  67097. + *
  67098. + * The diagnostic interface will provide access to the controller for
  67099. + * bringing up the hardware and testing. The Linux driver attributes
  67100. + * feature will be used to provide the Linux Diagnostic
  67101. + * Interface. These attributes are accessed through sysfs.
  67102. + */
  67103. +
  67104. +/** @page "Linux Module Attributes"
  67105. + *
  67106. + * The Linux module attributes feature is used to provide the Linux
  67107. + * Diagnostic Interface. These attributes are accessed through sysfs.
  67108. + * The diagnostic interface will provide access to the controller for
  67109. + * bringing up the hardware and testing.
  67110. +
  67111. + The following table shows the attributes.
  67112. + <table>
  67113. + <tr>
  67114. + <td><b> Name</b></td>
  67115. + <td><b> Description</b></td>
  67116. + <td><b> Access</b></td>
  67117. + </tr>
  67118. +
  67119. + <tr>
  67120. + <td> mode </td>
  67121. + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
  67122. + <td> Read</td>
  67123. + </tr>
  67124. +
  67125. + <tr>
  67126. + <td> hnpcapable </td>
  67127. + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
  67128. + Read returns the current value.</td>
  67129. + <td> Read/Write</td>
  67130. + </tr>
  67131. +
  67132. + <tr>
  67133. + <td> srpcapable </td>
  67134. + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
  67135. + Read returns the current value.</td>
  67136. + <td> Read/Write</td>
  67137. + </tr>
  67138. +
  67139. + <tr>
  67140. + <td> hsic_connect </td>
  67141. + <td> Gets or sets the "HSIC-Connect" bit in the GLPMCFG Register.
  67142. + Read returns the current value.</td>
  67143. + <td> Read/Write</td>
  67144. + </tr>
  67145. +
  67146. + <tr>
  67147. + <td> inv_sel_hsic </td>
  67148. + <td> Gets or sets the "Invert Select HSIC" bit in the GLPMFG Register.
  67149. + Read returns the current value.</td>
  67150. + <td> Read/Write</td>
  67151. + </tr>
  67152. +
  67153. + <tr>
  67154. + <td> hnp </td>
  67155. + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
  67156. + <td> Read/Write</td>
  67157. + </tr>
  67158. +
  67159. + <tr>
  67160. + <td> srp </td>
  67161. + <td> Initiates the Session Request Protocol. Read returns the status.</td>
  67162. + <td> Read/Write</td>
  67163. + </tr>
  67164. +
  67165. + <tr>
  67166. + <td> buspower </td>
  67167. + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
  67168. + <td> Read/Write</td>
  67169. + </tr>
  67170. +
  67171. + <tr>
  67172. + <td> bussuspend </td>
  67173. + <td> Suspends the USB bus.</td>
  67174. + <td> Read/Write</td>
  67175. + </tr>
  67176. +
  67177. + <tr>
  67178. + <td> busconnected </td>
  67179. + <td> Gets the connection status of the bus</td>
  67180. + <td> Read</td>
  67181. + </tr>
  67182. +
  67183. + <tr>
  67184. + <td> gotgctl </td>
  67185. + <td> Gets or sets the Core Control Status Register.</td>
  67186. + <td> Read/Write</td>
  67187. + </tr>
  67188. +
  67189. + <tr>
  67190. + <td> gusbcfg </td>
  67191. + <td> Gets or sets the Core USB Configuration Register</td>
  67192. + <td> Read/Write</td>
  67193. + </tr>
  67194. +
  67195. + <tr>
  67196. + <td> grxfsiz </td>
  67197. + <td> Gets or sets the Receive FIFO Size Register</td>
  67198. + <td> Read/Write</td>
  67199. + </tr>
  67200. +
  67201. + <tr>
  67202. + <td> gnptxfsiz </td>
  67203. + <td> Gets or sets the non-periodic Transmit Size Register</td>
  67204. + <td> Read/Write</td>
  67205. + </tr>
  67206. +
  67207. + <tr>
  67208. + <td> gpvndctl </td>
  67209. + <td> Gets or sets the PHY Vendor Control Register</td>
  67210. + <td> Read/Write</td>
  67211. + </tr>
  67212. +
  67213. + <tr>
  67214. + <td> ggpio </td>
  67215. + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
  67216. + or sets the upper 16 bits.</td>
  67217. + <td> Read/Write</td>
  67218. + </tr>
  67219. +
  67220. + <tr>
  67221. + <td> guid </td>
  67222. + <td> Gets or sets the value of the User ID Register</td>
  67223. + <td> Read/Write</td>
  67224. + </tr>
  67225. +
  67226. + <tr>
  67227. + <td> gsnpsid </td>
  67228. + <td> Gets the value of the Synopsys ID Regester</td>
  67229. + <td> Read</td>
  67230. + </tr>
  67231. +
  67232. + <tr>
  67233. + <td> devspeed </td>
  67234. + <td> Gets or sets the device speed setting in the DCFG register</td>
  67235. + <td> Read/Write</td>
  67236. + </tr>
  67237. +
  67238. + <tr>
  67239. + <td> enumspeed </td>
  67240. + <td> Gets the device enumeration Speed.</td>
  67241. + <td> Read</td>
  67242. + </tr>
  67243. +
  67244. + <tr>
  67245. + <td> hptxfsiz </td>
  67246. + <td> Gets the value of the Host Periodic Transmit FIFO</td>
  67247. + <td> Read</td>
  67248. + </tr>
  67249. +
  67250. + <tr>
  67251. + <td> hprt0 </td>
  67252. + <td> Gets or sets the value in the Host Port Control and Status Register</td>
  67253. + <td> Read/Write</td>
  67254. + </tr>
  67255. +
  67256. + <tr>
  67257. + <td> regoffset </td>
  67258. + <td> Sets the register offset for the next Register Access</td>
  67259. + <td> Read/Write</td>
  67260. + </tr>
  67261. +
  67262. + <tr>
  67263. + <td> regvalue </td>
  67264. + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
  67265. + <td> Read/Write</td>
  67266. + </tr>
  67267. +
  67268. + <tr>
  67269. + <td> remote_wakeup </td>
  67270. + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
  67271. + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
  67272. + Wakeup signalling bit in the Device Control Register is set for 1
  67273. + milli-second.</td>
  67274. + <td> Read/Write</td>
  67275. + </tr>
  67276. +
  67277. + <tr>
  67278. + <td> rem_wakeup_pwrdn </td>
  67279. + <td> On read, shows the status core - hibernated or not. On write, initiates
  67280. + a remote wakeup of the device from Hibernation. </td>
  67281. + <td> Read/Write</td>
  67282. + </tr>
  67283. +
  67284. + <tr>
  67285. + <td> mode_ch_tim_en </td>
  67286. + <td> This bit is used to enable or disable the host core to wait for 200 PHY
  67287. + clock cycles at the end of Resume to change the opmode signal to the PHY to 00
  67288. + after Suspend or LPM. </td>
  67289. + <td> Read/Write</td>
  67290. + </tr>
  67291. +
  67292. + <tr>
  67293. + <td> fr_interval </td>
  67294. + <td> On read, shows the value of HFIR Frame Interval. On write, dynamically
  67295. + reload HFIR register during runtime. The application can write a value to this
  67296. + register only after the Port Enable bit of the Host Port Control and Status
  67297. + register (HPRT.PrtEnaPort) has been set </td>
  67298. + <td> Read/Write</td>
  67299. + </tr>
  67300. +
  67301. + <tr>
  67302. + <td> disconnect_us </td>
  67303. + <td> On read, shows the status of disconnect_device_us. On write, sets disconnect_us
  67304. + which causes soft disconnect for 100us. Applicable only for device mode of operation.</td>
  67305. + <td> Read/Write</td>
  67306. + </tr>
  67307. +
  67308. + <tr>
  67309. + <td> regdump </td>
  67310. + <td> Dumps the contents of core registers.</td>
  67311. + <td> Read</td>
  67312. + </tr>
  67313. +
  67314. + <tr>
  67315. + <td> spramdump </td>
  67316. + <td> Dumps the contents of core registers.</td>
  67317. + <td> Read</td>
  67318. + </tr>
  67319. +
  67320. + <tr>
  67321. + <td> hcddump </td>
  67322. + <td> Dumps the current HCD state.</td>
  67323. + <td> Read</td>
  67324. + </tr>
  67325. +
  67326. + <tr>
  67327. + <td> hcd_frrem </td>
  67328. + <td> Shows the average value of the Frame Remaining
  67329. + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
  67330. + occurs. This can be used to determine the average interrupt latency. Also
  67331. + shows the average Frame Remaining value for start_transfer and the "a" and
  67332. + "b" sample points. The "a" and "b" sample points may be used during debugging
  67333. + bto determine how long it takes to execute a section of the HCD code.</td>
  67334. + <td> Read</td>
  67335. + </tr>
  67336. +
  67337. + <tr>
  67338. + <td> rd_reg_test </td>
  67339. + <td> Displays the time required to read the GNPTXFSIZ register many times
  67340. + (the output shows the number of times the register is read).
  67341. + <td> Read</td>
  67342. + </tr>
  67343. +
  67344. + <tr>
  67345. + <td> wr_reg_test </td>
  67346. + <td> Displays the time required to write the GNPTXFSIZ register many times
  67347. + (the output shows the number of times the register is written).
  67348. + <td> Read</td>
  67349. + </tr>
  67350. +
  67351. + <tr>
  67352. + <td> lpm_response </td>
  67353. + <td> Gets or sets lpm_response mode. Applicable only in device mode.
  67354. + <td> Write</td>
  67355. + </tr>
  67356. +
  67357. + <tr>
  67358. + <td> sleep_status </td>
  67359. + <td> Shows sleep status of device.
  67360. + <td> Read</td>
  67361. + </tr>
  67362. +
  67363. + </table>
  67364. +
  67365. + Example usage:
  67366. + To get the current mode:
  67367. + cat /sys/devices/lm0/mode
  67368. +
  67369. + To power down the USB:
  67370. + echo 0 > /sys/devices/lm0/buspower
  67371. + */
  67372. +
  67373. +#include "dwc_otg_os_dep.h"
  67374. +#include "dwc_os.h"
  67375. +#include "dwc_otg_driver.h"
  67376. +#include "dwc_otg_attr.h"
  67377. +#include "dwc_otg_core_if.h"
  67378. +#include "dwc_otg_pcd_if.h"
  67379. +#include "dwc_otg_hcd_if.h"
  67380. +
  67381. +/*
  67382. + * MACROs for defining sysfs attribute
  67383. + */
  67384. +#ifdef LM_INTERFACE
  67385. +
  67386. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  67387. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  67388. +{ \
  67389. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  67390. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  67391. + uint32_t val; \
  67392. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  67393. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  67394. +}
  67395. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  67396. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  67397. + const char *buf, size_t count) \
  67398. +{ \
  67399. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  67400. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  67401. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  67402. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  67403. + return count; \
  67404. +}
  67405. +
  67406. +#elif defined(PCI_INTERFACE)
  67407. +
  67408. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  67409. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  67410. +{ \
  67411. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  67412. + uint32_t val; \
  67413. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  67414. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  67415. +}
  67416. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  67417. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  67418. + const char *buf, size_t count) \
  67419. +{ \
  67420. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  67421. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  67422. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  67423. + return count; \
  67424. +}
  67425. +
  67426. +#elif defined(PLATFORM_INTERFACE)
  67427. +
  67428. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  67429. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  67430. +{ \
  67431. + struct platform_device *platform_dev = \
  67432. + container_of(_dev, struct platform_device, dev); \
  67433. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  67434. + uint32_t val; \
  67435. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  67436. + __func__, _dev, platform_dev, otg_dev); \
  67437. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  67438. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  67439. +}
  67440. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  67441. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  67442. + const char *buf, size_t count) \
  67443. +{ \
  67444. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  67445. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  67446. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  67447. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  67448. + return count; \
  67449. +}
  67450. +#endif
  67451. +
  67452. +/*
  67453. + * MACROs for defining sysfs attribute for 32-bit registers
  67454. + */
  67455. +#ifdef LM_INTERFACE
  67456. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  67457. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  67458. +{ \
  67459. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  67460. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  67461. + uint32_t val; \
  67462. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  67463. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  67464. +}
  67465. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  67466. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  67467. + const char *buf, size_t count) \
  67468. +{ \
  67469. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  67470. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  67471. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  67472. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  67473. + return count; \
  67474. +}
  67475. +#elif defined(PCI_INTERFACE)
  67476. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  67477. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  67478. +{ \
  67479. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  67480. + uint32_t val; \
  67481. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  67482. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  67483. +}
  67484. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  67485. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  67486. + const char *buf, size_t count) \
  67487. +{ \
  67488. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  67489. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  67490. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  67491. + return count; \
  67492. +}
  67493. +
  67494. +#elif defined(PLATFORM_INTERFACE)
  67495. +#include "dwc_otg_dbg.h"
  67496. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  67497. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  67498. +{ \
  67499. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  67500. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  67501. + uint32_t val; \
  67502. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  67503. + __func__, _dev, platform_dev, otg_dev); \
  67504. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  67505. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  67506. +}
  67507. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  67508. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  67509. + const char *buf, size_t count) \
  67510. +{ \
  67511. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  67512. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  67513. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  67514. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  67515. + return count; \
  67516. +}
  67517. +
  67518. +#endif
  67519. +
  67520. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
  67521. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  67522. +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  67523. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  67524. +
  67525. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
  67526. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  67527. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  67528. +
  67529. +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
  67530. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  67531. +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  67532. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  67533. +
  67534. +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
  67535. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  67536. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  67537. +
  67538. +/** @name Functions for Show/Store of Attributes */
  67539. +/**@{*/
  67540. +
  67541. +/**
  67542. + * Helper function returning the otg_device structure of the given device
  67543. + */
  67544. +static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  67545. +{
  67546. + dwc_otg_device_t *otg_dev;
  67547. + DWC_OTG_GETDRVDEV(otg_dev, _dev);
  67548. + return otg_dev;
  67549. +}
  67550. +
  67551. +/**
  67552. + * Show the register offset of the Register Access.
  67553. + */
  67554. +static ssize_t regoffset_show(struct device *_dev,
  67555. + struct device_attribute *attr, char *buf)
  67556. +{
  67557. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67558. + return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
  67559. + otg_dev->os_dep.reg_offset);
  67560. +}
  67561. +
  67562. +/**
  67563. + * Set the register offset for the next Register Access Read/Write
  67564. + */
  67565. +static ssize_t regoffset_store(struct device *_dev,
  67566. + struct device_attribute *attr,
  67567. + const char *buf, size_t count)
  67568. +{
  67569. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67570. + uint32_t offset = simple_strtoul(buf, NULL, 16);
  67571. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  67572. + if (offset < SZ_256K) {
  67573. +#elif defined(PCI_INTERFACE)
  67574. + if (offset < 0x00040000) {
  67575. +#endif
  67576. + otg_dev->os_dep.reg_offset = offset;
  67577. + } else {
  67578. + dev_err(_dev, "invalid offset\n");
  67579. + }
  67580. +
  67581. + return count;
  67582. +}
  67583. +
  67584. +DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
  67585. +
  67586. +/**
  67587. + * Show the value of the register at the offset in the reg_offset
  67588. + * attribute.
  67589. + */
  67590. +static ssize_t regvalue_show(struct device *_dev,
  67591. + struct device_attribute *attr, char *buf)
  67592. +{
  67593. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67594. + uint32_t val;
  67595. + volatile uint32_t *addr;
  67596. +
  67597. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  67598. + /* Calculate the address */
  67599. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  67600. + (uint8_t *) otg_dev->os_dep.base);
  67601. + val = DWC_READ_REG32(addr);
  67602. + return snprintf(buf,
  67603. + sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
  67604. + "Reg@0x%06x = 0x%08x\n", otg_dev->os_dep.reg_offset,
  67605. + val);
  67606. + } else {
  67607. + dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->os_dep.reg_offset);
  67608. + return sprintf(buf, "invalid offset\n");
  67609. + }
  67610. +}
  67611. +
  67612. +/**
  67613. + * Store the value in the register at the offset in the reg_offset
  67614. + * attribute.
  67615. + *
  67616. + */
  67617. +static ssize_t regvalue_store(struct device *_dev,
  67618. + struct device_attribute *attr,
  67619. + const char *buf, size_t count)
  67620. +{
  67621. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67622. + volatile uint32_t *addr;
  67623. + uint32_t val = simple_strtoul(buf, NULL, 16);
  67624. + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
  67625. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  67626. + /* Calculate the address */
  67627. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  67628. + (uint8_t *) otg_dev->os_dep.base);
  67629. + DWC_WRITE_REG32(addr, val);
  67630. + } else {
  67631. + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
  67632. + otg_dev->os_dep.reg_offset);
  67633. + }
  67634. + return count;
  67635. +}
  67636. +
  67637. +DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
  67638. +
  67639. +/*
  67640. + * Attributes
  67641. + */
  67642. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
  67643. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
  67644. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
  67645. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
  67646. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
  67647. +
  67648. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  67649. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  67650. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
  67651. +
  67652. +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
  67653. +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
  67654. + &(otg_dev->core_if->core_global_regs->gusbcfg),
  67655. + "GUSBCFG");
  67656. +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
  67657. + &(otg_dev->core_if->core_global_regs->grxfsiz),
  67658. + "GRXFSIZ");
  67659. +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
  67660. + &(otg_dev->core_if->core_global_regs->gnptxfsiz),
  67661. + "GNPTXFSIZ");
  67662. +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
  67663. + &(otg_dev->core_if->core_global_regs->gpvndctl),
  67664. + "GPVNDCTL");
  67665. +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
  67666. + &(otg_dev->core_if->core_global_regs->ggpio),
  67667. + "GGPIO");
  67668. +DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
  67669. + "GUID");
  67670. +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
  67671. + &(otg_dev->core_if->core_global_regs->gsnpsid),
  67672. + "GSNPSID");
  67673. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
  67674. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
  67675. +
  67676. +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
  67677. + &(otg_dev->core_if->core_global_regs->hptxfsiz),
  67678. + "HPTXFSIZ");
  67679. +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
  67680. +
  67681. +/**
  67682. + * @todo Add code to initiate the HNP.
  67683. + */
  67684. +/**
  67685. + * Show the HNP status bit
  67686. + */
  67687. +static ssize_t hnp_show(struct device *_dev,
  67688. + struct device_attribute *attr, char *buf)
  67689. +{
  67690. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67691. + return sprintf(buf, "HstNegScs = 0x%x\n",
  67692. + dwc_otg_get_hnpstatus(otg_dev->core_if));
  67693. +}
  67694. +
  67695. +/**
  67696. + * Set the HNP Request bit
  67697. + */
  67698. +static ssize_t hnp_store(struct device *_dev,
  67699. + struct device_attribute *attr,
  67700. + const char *buf, size_t count)
  67701. +{
  67702. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67703. + uint32_t in = simple_strtoul(buf, NULL, 16);
  67704. + dwc_otg_set_hnpreq(otg_dev->core_if, in);
  67705. + return count;
  67706. +}
  67707. +
  67708. +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
  67709. +
  67710. +/**
  67711. + * @todo Add code to initiate the SRP.
  67712. + */
  67713. +/**
  67714. + * Show the SRP status bit
  67715. + */
  67716. +static ssize_t srp_show(struct device *_dev,
  67717. + struct device_attribute *attr, char *buf)
  67718. +{
  67719. +#ifndef DWC_HOST_ONLY
  67720. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67721. + return sprintf(buf, "SesReqScs = 0x%x\n",
  67722. + dwc_otg_get_srpstatus(otg_dev->core_if));
  67723. +#else
  67724. + return sprintf(buf, "Host Only Mode!\n");
  67725. +#endif
  67726. +}
  67727. +
  67728. +/**
  67729. + * Set the SRP Request bit
  67730. + */
  67731. +static ssize_t srp_store(struct device *_dev,
  67732. + struct device_attribute *attr,
  67733. + const char *buf, size_t count)
  67734. +{
  67735. +#ifndef DWC_HOST_ONLY
  67736. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67737. + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
  67738. +#endif
  67739. + return count;
  67740. +}
  67741. +
  67742. +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
  67743. +
  67744. +/**
  67745. + * @todo Need to do more for power on/off?
  67746. + */
  67747. +/**
  67748. + * Show the Bus Power status
  67749. + */
  67750. +static ssize_t buspower_show(struct device *_dev,
  67751. + struct device_attribute *attr, char *buf)
  67752. +{
  67753. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67754. + return sprintf(buf, "Bus Power = 0x%x\n",
  67755. + dwc_otg_get_prtpower(otg_dev->core_if));
  67756. +}
  67757. +
  67758. +/**
  67759. + * Set the Bus Power status
  67760. + */
  67761. +static ssize_t buspower_store(struct device *_dev,
  67762. + struct device_attribute *attr,
  67763. + const char *buf, size_t count)
  67764. +{
  67765. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67766. + uint32_t on = simple_strtoul(buf, NULL, 16);
  67767. + dwc_otg_set_prtpower(otg_dev->core_if, on);
  67768. + return count;
  67769. +}
  67770. +
  67771. +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
  67772. +
  67773. +/**
  67774. + * @todo Need to do more for suspend?
  67775. + */
  67776. +/**
  67777. + * Show the Bus Suspend status
  67778. + */
  67779. +static ssize_t bussuspend_show(struct device *_dev,
  67780. + struct device_attribute *attr, char *buf)
  67781. +{
  67782. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67783. + return sprintf(buf, "Bus Suspend = 0x%x\n",
  67784. + dwc_otg_get_prtsuspend(otg_dev->core_if));
  67785. +}
  67786. +
  67787. +/**
  67788. + * Set the Bus Suspend status
  67789. + */
  67790. +static ssize_t bussuspend_store(struct device *_dev,
  67791. + struct device_attribute *attr,
  67792. + const char *buf, size_t count)
  67793. +{
  67794. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67795. + uint32_t in = simple_strtoul(buf, NULL, 16);
  67796. + dwc_otg_set_prtsuspend(otg_dev->core_if, in);
  67797. + return count;
  67798. +}
  67799. +
  67800. +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
  67801. +
  67802. +/**
  67803. + * Show the Mode Change Ready Timer status
  67804. + */
  67805. +static ssize_t mode_ch_tim_en_show(struct device *_dev,
  67806. + struct device_attribute *attr, char *buf)
  67807. +{
  67808. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67809. + return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
  67810. + dwc_otg_get_mode_ch_tim(otg_dev->core_if));
  67811. +}
  67812. +
  67813. +/**
  67814. + * Set the Mode Change Ready Timer status
  67815. + */
  67816. +static ssize_t mode_ch_tim_en_store(struct device *_dev,
  67817. + struct device_attribute *attr,
  67818. + const char *buf, size_t count)
  67819. +{
  67820. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67821. + uint32_t in = simple_strtoul(buf, NULL, 16);
  67822. + dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
  67823. + return count;
  67824. +}
  67825. +
  67826. +DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
  67827. +
  67828. +/**
  67829. + * Show the value of HFIR Frame Interval bitfield
  67830. + */
  67831. +static ssize_t fr_interval_show(struct device *_dev,
  67832. + struct device_attribute *attr, char *buf)
  67833. +{
  67834. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67835. + return sprintf(buf, "Frame Interval = 0x%x\n",
  67836. + dwc_otg_get_fr_interval(otg_dev->core_if));
  67837. +}
  67838. +
  67839. +/**
  67840. + * Set the HFIR Frame Interval value
  67841. + */
  67842. +static ssize_t fr_interval_store(struct device *_dev,
  67843. + struct device_attribute *attr,
  67844. + const char *buf, size_t count)
  67845. +{
  67846. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67847. + uint32_t in = simple_strtoul(buf, NULL, 10);
  67848. + dwc_otg_set_fr_interval(otg_dev->core_if, in);
  67849. + return count;
  67850. +}
  67851. +
  67852. +DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
  67853. +
  67854. +/**
  67855. + * Show the status of Remote Wakeup.
  67856. + */
  67857. +static ssize_t remote_wakeup_show(struct device *_dev,
  67858. + struct device_attribute *attr, char *buf)
  67859. +{
  67860. +#ifndef DWC_HOST_ONLY
  67861. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67862. +
  67863. + return sprintf(buf,
  67864. + "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
  67865. + dwc_otg_get_remotewakesig(otg_dev->core_if),
  67866. + dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
  67867. + dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
  67868. +#else
  67869. + return sprintf(buf, "Host Only Mode!\n");
  67870. +#endif /* DWC_HOST_ONLY */
  67871. +}
  67872. +
  67873. +/**
  67874. + * Initiate a remote wakeup of the host. The Device control register
  67875. + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
  67876. + * flag is set.
  67877. + *
  67878. + */
  67879. +static ssize_t remote_wakeup_store(struct device *_dev,
  67880. + struct device_attribute *attr,
  67881. + const char *buf, size_t count)
  67882. +{
  67883. +#ifndef DWC_HOST_ONLY
  67884. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67885. + uint32_t val = simple_strtoul(buf, NULL, 16);
  67886. +
  67887. + if (val & 1) {
  67888. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
  67889. + } else {
  67890. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
  67891. + }
  67892. +#endif /* DWC_HOST_ONLY */
  67893. + return count;
  67894. +}
  67895. +
  67896. +DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
  67897. + remote_wakeup_store);
  67898. +
  67899. +/**
  67900. + * Show the whether core is hibernated or not.
  67901. + */
  67902. +static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
  67903. + struct device_attribute *attr, char *buf)
  67904. +{
  67905. +#ifndef DWC_HOST_ONLY
  67906. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67907. +
  67908. + if (dwc_otg_get_core_state(otg_dev->core_if)) {
  67909. + DWC_PRINTF("Core is in hibernation\n");
  67910. + } else {
  67911. + DWC_PRINTF("Core is not in hibernation\n");
  67912. + }
  67913. +#endif /* DWC_HOST_ONLY */
  67914. + return 0;
  67915. +}
  67916. +
  67917. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  67918. + int rem_wakeup, int reset);
  67919. +
  67920. +/**
  67921. + * Initiate a remote wakeup of the device to exit from hibernation.
  67922. + */
  67923. +static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
  67924. + struct device_attribute *attr,
  67925. + const char *buf, size_t count)
  67926. +{
  67927. +#ifndef DWC_HOST_ONLY
  67928. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67929. + dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
  67930. +#endif
  67931. + return count;
  67932. +}
  67933. +
  67934. +DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
  67935. + rem_wakeup_pwrdn_store);
  67936. +
  67937. +static ssize_t disconnect_us(struct device *_dev,
  67938. + struct device_attribute *attr,
  67939. + const char *buf, size_t count)
  67940. +{
  67941. +
  67942. +#ifndef DWC_HOST_ONLY
  67943. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67944. + uint32_t val = simple_strtoul(buf, NULL, 16);
  67945. + DWC_PRINTF("The Passed value is %04x\n", val);
  67946. +
  67947. + dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
  67948. +
  67949. +#endif /* DWC_HOST_ONLY */
  67950. + return count;
  67951. +}
  67952. +
  67953. +DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
  67954. +
  67955. +/**
  67956. + * Dump global registers and either host or device registers (depending on the
  67957. + * current mode of the core).
  67958. + */
  67959. +static ssize_t regdump_show(struct device *_dev,
  67960. + struct device_attribute *attr, char *buf)
  67961. +{
  67962. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67963. +
  67964. + dwc_otg_dump_global_registers(otg_dev->core_if);
  67965. + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
  67966. + dwc_otg_dump_host_registers(otg_dev->core_if);
  67967. + } else {
  67968. + dwc_otg_dump_dev_registers(otg_dev->core_if);
  67969. +
  67970. + }
  67971. + return sprintf(buf, "Register Dump\n");
  67972. +}
  67973. +
  67974. +DEVICE_ATTR(regdump, S_IRUGO, regdump_show, 0);
  67975. +
  67976. +/**
  67977. + * Dump global registers and either host or device registers (depending on the
  67978. + * current mode of the core).
  67979. + */
  67980. +static ssize_t spramdump_show(struct device *_dev,
  67981. + struct device_attribute *attr, char *buf)
  67982. +{
  67983. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  67984. +
  67985. + //dwc_otg_dump_spram(otg_dev->core_if);
  67986. +
  67987. + return sprintf(buf, "SPRAM Dump\n");
  67988. +}
  67989. +
  67990. +DEVICE_ATTR(spramdump, S_IRUGO, spramdump_show, 0);
  67991. +
  67992. +/**
  67993. + * Dump the current hcd state.
  67994. + */
  67995. +static ssize_t hcddump_show(struct device *_dev,
  67996. + struct device_attribute *attr, char *buf)
  67997. +{
  67998. +#ifndef DWC_DEVICE_ONLY
  67999. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68000. + dwc_otg_hcd_dump_state(otg_dev->hcd);
  68001. +#endif /* DWC_DEVICE_ONLY */
  68002. + return sprintf(buf, "HCD Dump\n");
  68003. +}
  68004. +
  68005. +DEVICE_ATTR(hcddump, S_IRUGO, hcddump_show, 0);
  68006. +
  68007. +/**
  68008. + * Dump the average frame remaining at SOF. This can be used to
  68009. + * determine average interrupt latency. Frame remaining is also shown for
  68010. + * start transfer and two additional sample points.
  68011. + */
  68012. +static ssize_t hcd_frrem_show(struct device *_dev,
  68013. + struct device_attribute *attr, char *buf)
  68014. +{
  68015. +#ifndef DWC_DEVICE_ONLY
  68016. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68017. +
  68018. + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
  68019. +#endif /* DWC_DEVICE_ONLY */
  68020. + return sprintf(buf, "HCD Dump Frame Remaining\n");
  68021. +}
  68022. +
  68023. +DEVICE_ATTR(hcd_frrem, S_IRUGO, hcd_frrem_show, 0);
  68024. +
  68025. +/**
  68026. + * Displays the time required to read the GNPTXFSIZ register many times (the
  68027. + * output shows the number of times the register is read).
  68028. + */
  68029. +#define RW_REG_COUNT 10000000
  68030. +#define MSEC_PER_JIFFIE 1000/HZ
  68031. +static ssize_t rd_reg_test_show(struct device *_dev,
  68032. + struct device_attribute *attr, char *buf)
  68033. +{
  68034. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68035. + int i;
  68036. + int time;
  68037. + int start_jiffies;
  68038. +
  68039. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  68040. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  68041. + start_jiffies = jiffies;
  68042. + for (i = 0; i < RW_REG_COUNT; i++) {
  68043. + dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  68044. + }
  68045. + time = jiffies - start_jiffies;
  68046. + return sprintf(buf,
  68047. + "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  68048. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  68049. +}
  68050. +
  68051. +DEVICE_ATTR(rd_reg_test, S_IRUGO, rd_reg_test_show, 0);
  68052. +
  68053. +/**
  68054. + * Displays the time required to write the GNPTXFSIZ register many times (the
  68055. + * output shows the number of times the register is written).
  68056. + */
  68057. +static ssize_t wr_reg_test_show(struct device *_dev,
  68058. + struct device_attribute *attr, char *buf)
  68059. +{
  68060. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68061. + uint32_t reg_val;
  68062. + int i;
  68063. + int time;
  68064. + int start_jiffies;
  68065. +
  68066. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  68067. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  68068. + reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  68069. + start_jiffies = jiffies;
  68070. + for (i = 0; i < RW_REG_COUNT; i++) {
  68071. + dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
  68072. + }
  68073. + time = jiffies - start_jiffies;
  68074. + return sprintf(buf,
  68075. + "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  68076. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  68077. +}
  68078. +
  68079. +DEVICE_ATTR(wr_reg_test, S_IRUGO, wr_reg_test_show, 0);
  68080. +
  68081. +#ifdef CONFIG_USB_DWC_OTG_LPM
  68082. +
  68083. +/**
  68084. +* Show the lpm_response attribute.
  68085. +*/
  68086. +static ssize_t lpmresp_show(struct device *_dev,
  68087. + struct device_attribute *attr, char *buf)
  68088. +{
  68089. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68090. +
  68091. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
  68092. + return sprintf(buf, "** LPM is DISABLED **\n");
  68093. +
  68094. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  68095. + return sprintf(buf, "** Current mode is not device mode\n");
  68096. + }
  68097. + return sprintf(buf, "lpm_response = %d\n",
  68098. + dwc_otg_get_lpmresponse(otg_dev->core_if));
  68099. +}
  68100. +
  68101. +/**
  68102. +* Store the lpm_response attribute.
  68103. +*/
  68104. +static ssize_t lpmresp_store(struct device *_dev,
  68105. + struct device_attribute *attr,
  68106. + const char *buf, size_t count)
  68107. +{
  68108. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68109. + uint32_t val = simple_strtoul(buf, NULL, 16);
  68110. +
  68111. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
  68112. + return 0;
  68113. + }
  68114. +
  68115. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  68116. + return 0;
  68117. + }
  68118. +
  68119. + dwc_otg_set_lpmresponse(otg_dev->core_if, val);
  68120. + return count;
  68121. +}
  68122. +
  68123. +DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
  68124. +
  68125. +/**
  68126. +* Show the sleep_status attribute.
  68127. +*/
  68128. +static ssize_t sleepstatus_show(struct device *_dev,
  68129. + struct device_attribute *attr, char *buf)
  68130. +{
  68131. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68132. + return sprintf(buf, "Sleep Status = %d\n",
  68133. + dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
  68134. +}
  68135. +
  68136. +/**
  68137. + * Store the sleep_status attribure.
  68138. + */
  68139. +static ssize_t sleepstatus_store(struct device *_dev,
  68140. + struct device_attribute *attr,
  68141. + const char *buf, size_t count)
  68142. +{
  68143. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68144. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  68145. +
  68146. + if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
  68147. + if (dwc_otg_is_host_mode(core_if)) {
  68148. +
  68149. + DWC_PRINTF("Host initiated resume\n");
  68150. + dwc_otg_set_prtresume(otg_dev->core_if, 1);
  68151. + }
  68152. + }
  68153. +
  68154. + return count;
  68155. +}
  68156. +
  68157. +DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
  68158. + sleepstatus_store);
  68159. +
  68160. +#endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
  68161. +
  68162. +/**@}*/
  68163. +
  68164. +/**
  68165. + * Create the device files
  68166. + */
  68167. +void dwc_otg_attr_create(
  68168. +#ifdef LM_INTERFACE
  68169. + struct lm_device *dev
  68170. +#elif defined(PCI_INTERFACE)
  68171. + struct pci_dev *dev
  68172. +#elif defined(PLATFORM_INTERFACE)
  68173. + struct platform_device *dev
  68174. +#endif
  68175. + )
  68176. +{
  68177. + int error;
  68178. +
  68179. + error = device_create_file(&dev->dev, &dev_attr_regoffset);
  68180. + error = device_create_file(&dev->dev, &dev_attr_regvalue);
  68181. + error = device_create_file(&dev->dev, &dev_attr_mode);
  68182. + error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
  68183. + error = device_create_file(&dev->dev, &dev_attr_srpcapable);
  68184. + error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
  68185. + error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
  68186. + error = device_create_file(&dev->dev, &dev_attr_hnp);
  68187. + error = device_create_file(&dev->dev, &dev_attr_srp);
  68188. + error = device_create_file(&dev->dev, &dev_attr_buspower);
  68189. + error = device_create_file(&dev->dev, &dev_attr_bussuspend);
  68190. + error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  68191. + error = device_create_file(&dev->dev, &dev_attr_fr_interval);
  68192. + error = device_create_file(&dev->dev, &dev_attr_busconnected);
  68193. + error = device_create_file(&dev->dev, &dev_attr_gotgctl);
  68194. + error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
  68195. + error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
  68196. + error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
  68197. + error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
  68198. + error = device_create_file(&dev->dev, &dev_attr_ggpio);
  68199. + error = device_create_file(&dev->dev, &dev_attr_guid);
  68200. + error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
  68201. + error = device_create_file(&dev->dev, &dev_attr_devspeed);
  68202. + error = device_create_file(&dev->dev, &dev_attr_enumspeed);
  68203. + error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
  68204. + error = device_create_file(&dev->dev, &dev_attr_hprt0);
  68205. + error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
  68206. + error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  68207. + error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
  68208. + error = device_create_file(&dev->dev, &dev_attr_regdump);
  68209. + error = device_create_file(&dev->dev, &dev_attr_spramdump);
  68210. + error = device_create_file(&dev->dev, &dev_attr_hcddump);
  68211. + error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
  68212. + error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
  68213. + error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
  68214. +#ifdef CONFIG_USB_DWC_OTG_LPM
  68215. + error = device_create_file(&dev->dev, &dev_attr_lpm_response);
  68216. + error = device_create_file(&dev->dev, &dev_attr_sleep_status);
  68217. +#endif
  68218. +}
  68219. +
  68220. +/**
  68221. + * Remove the device files
  68222. + */
  68223. +void dwc_otg_attr_remove(
  68224. +#ifdef LM_INTERFACE
  68225. + struct lm_device *dev
  68226. +#elif defined(PCI_INTERFACE)
  68227. + struct pci_dev *dev
  68228. +#elif defined(PLATFORM_INTERFACE)
  68229. + struct platform_device *dev
  68230. +#endif
  68231. + )
  68232. +{
  68233. + device_remove_file(&dev->dev, &dev_attr_regoffset);
  68234. + device_remove_file(&dev->dev, &dev_attr_regvalue);
  68235. + device_remove_file(&dev->dev, &dev_attr_mode);
  68236. + device_remove_file(&dev->dev, &dev_attr_hnpcapable);
  68237. + device_remove_file(&dev->dev, &dev_attr_srpcapable);
  68238. + device_remove_file(&dev->dev, &dev_attr_hsic_connect);
  68239. + device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
  68240. + device_remove_file(&dev->dev, &dev_attr_hnp);
  68241. + device_remove_file(&dev->dev, &dev_attr_srp);
  68242. + device_remove_file(&dev->dev, &dev_attr_buspower);
  68243. + device_remove_file(&dev->dev, &dev_attr_bussuspend);
  68244. + device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  68245. + device_remove_file(&dev->dev, &dev_attr_fr_interval);
  68246. + device_remove_file(&dev->dev, &dev_attr_busconnected);
  68247. + device_remove_file(&dev->dev, &dev_attr_gotgctl);
  68248. + device_remove_file(&dev->dev, &dev_attr_gusbcfg);
  68249. + device_remove_file(&dev->dev, &dev_attr_grxfsiz);
  68250. + device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
  68251. + device_remove_file(&dev->dev, &dev_attr_gpvndctl);
  68252. + device_remove_file(&dev->dev, &dev_attr_ggpio);
  68253. + device_remove_file(&dev->dev, &dev_attr_guid);
  68254. + device_remove_file(&dev->dev, &dev_attr_gsnpsid);
  68255. + device_remove_file(&dev->dev, &dev_attr_devspeed);
  68256. + device_remove_file(&dev->dev, &dev_attr_enumspeed);
  68257. + device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
  68258. + device_remove_file(&dev->dev, &dev_attr_hprt0);
  68259. + device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
  68260. + device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  68261. + device_remove_file(&dev->dev, &dev_attr_disconnect_us);
  68262. + device_remove_file(&dev->dev, &dev_attr_regdump);
  68263. + device_remove_file(&dev->dev, &dev_attr_spramdump);
  68264. + device_remove_file(&dev->dev, &dev_attr_hcddump);
  68265. + device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
  68266. + device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
  68267. + device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
  68268. +#ifdef CONFIG_USB_DWC_OTG_LPM
  68269. + device_remove_file(&dev->dev, &dev_attr_lpm_response);
  68270. + device_remove_file(&dev->dev, &dev_attr_sleep_status);
  68271. +#endif
  68272. +}
  68273. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_attr.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.h
  68274. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_attr.h 1970-01-01 01:00:00.000000000 +0100
  68275. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.h 2015-02-09 04:40:29.000000000 +0100
  68276. @@ -0,0 +1,89 @@
  68277. +/* ==========================================================================
  68278. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.h $
  68279. + * $Revision: #13 $
  68280. + * $Date: 2010/06/21 $
  68281. + * $Change: 1532021 $
  68282. + *
  68283. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  68284. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  68285. + * otherwise expressly agreed to in writing between Synopsys and you.
  68286. + *
  68287. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  68288. + * any End User Software License Agreement or Agreement for Licensed Product
  68289. + * with Synopsys or any supplement thereto. You are permitted to use and
  68290. + * redistribute this Software in source and binary forms, with or without
  68291. + * modification, provided that redistributions of source code must retain this
  68292. + * notice. You may not view, use, disclose, copy or distribute this file or
  68293. + * any information contained herein except pursuant to this license grant from
  68294. + * Synopsys. If you do not agree with this notice, including the disclaimer
  68295. + * below, then you are not authorized to use the Software.
  68296. + *
  68297. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  68298. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  68299. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  68300. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  68301. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  68302. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  68303. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  68304. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68305. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  68306. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  68307. + * DAMAGE.
  68308. + * ========================================================================== */
  68309. +
  68310. +#if !defined(__DWC_OTG_ATTR_H__)
  68311. +#define __DWC_OTG_ATTR_H__
  68312. +
  68313. +/** @file
  68314. + * This file contains the interface to the Linux device attributes.
  68315. + */
  68316. +extern struct device_attribute dev_attr_regoffset;
  68317. +extern struct device_attribute dev_attr_regvalue;
  68318. +
  68319. +extern struct device_attribute dev_attr_mode;
  68320. +extern struct device_attribute dev_attr_hnpcapable;
  68321. +extern struct device_attribute dev_attr_srpcapable;
  68322. +extern struct device_attribute dev_attr_hnp;
  68323. +extern struct device_attribute dev_attr_srp;
  68324. +extern struct device_attribute dev_attr_buspower;
  68325. +extern struct device_attribute dev_attr_bussuspend;
  68326. +extern struct device_attribute dev_attr_mode_ch_tim_en;
  68327. +extern struct device_attribute dev_attr_fr_interval;
  68328. +extern struct device_attribute dev_attr_busconnected;
  68329. +extern struct device_attribute dev_attr_gotgctl;
  68330. +extern struct device_attribute dev_attr_gusbcfg;
  68331. +extern struct device_attribute dev_attr_grxfsiz;
  68332. +extern struct device_attribute dev_attr_gnptxfsiz;
  68333. +extern struct device_attribute dev_attr_gpvndctl;
  68334. +extern struct device_attribute dev_attr_ggpio;
  68335. +extern struct device_attribute dev_attr_guid;
  68336. +extern struct device_attribute dev_attr_gsnpsid;
  68337. +extern struct device_attribute dev_attr_devspeed;
  68338. +extern struct device_attribute dev_attr_enumspeed;
  68339. +extern struct device_attribute dev_attr_hptxfsiz;
  68340. +extern struct device_attribute dev_attr_hprt0;
  68341. +#ifdef CONFIG_USB_DWC_OTG_LPM
  68342. +extern struct device_attribute dev_attr_lpm_response;
  68343. +extern struct device_attribute devi_attr_sleep_status;
  68344. +#endif
  68345. +
  68346. +void dwc_otg_attr_create(
  68347. +#ifdef LM_INTERFACE
  68348. + struct lm_device *dev
  68349. +#elif defined(PCI_INTERFACE)
  68350. + struct pci_dev *dev
  68351. +#elif defined(PLATFORM_INTERFACE)
  68352. + struct platform_device *dev
  68353. +#endif
  68354. + );
  68355. +
  68356. +void dwc_otg_attr_remove(
  68357. +#ifdef LM_INTERFACE
  68358. + struct lm_device *dev
  68359. +#elif defined(PCI_INTERFACE)
  68360. + struct pci_dev *dev
  68361. +#elif defined(PLATFORM_INTERFACE)
  68362. + struct platform_device *dev
  68363. +#endif
  68364. + );
  68365. +#endif
  68366. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_cfi.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c
  68367. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 1970-01-01 01:00:00.000000000 +0100
  68368. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 2015-02-09 04:40:29.000000000 +0100
  68369. @@ -0,0 +1,1876 @@
  68370. +/* ==========================================================================
  68371. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  68372. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  68373. + * otherwise expressly agreed to in writing between Synopsys and you.
  68374. + *
  68375. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  68376. + * any End User Software License Agreement or Agreement for Licensed Product
  68377. + * with Synopsys or any supplement thereto. You are permitted to use and
  68378. + * redistribute this Software in source and binary forms, with or without
  68379. + * modification, provided that redistributions of source code must retain this
  68380. + * notice. You may not view, use, disclose, copy or distribute this file or
  68381. + * any information contained herein except pursuant to this license grant from
  68382. + * Synopsys. If you do not agree with this notice, including the disclaimer
  68383. + * below, then you are not authorized to use the Software.
  68384. + *
  68385. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  68386. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  68387. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  68388. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  68389. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  68390. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  68391. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  68392. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68393. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  68394. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  68395. + * DAMAGE.
  68396. + * ========================================================================== */
  68397. +
  68398. +/** @file
  68399. + *
  68400. + * This file contains the most of the CFI(Core Feature Interface)
  68401. + * implementation for the OTG.
  68402. + */
  68403. +
  68404. +#ifdef DWC_UTE_CFI
  68405. +
  68406. +#include "dwc_otg_pcd.h"
  68407. +#include "dwc_otg_cfi.h"
  68408. +
  68409. +/** This definition should actually migrate to the Portability Library */
  68410. +#define DWC_CONSTANT_CPU_TO_LE16(x) (x)
  68411. +
  68412. +extern dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex);
  68413. +
  68414. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen);
  68415. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  68416. + struct dwc_otg_pcd *pcd,
  68417. + struct cfi_usb_ctrlrequest *ctrl_req);
  68418. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd);
  68419. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  68420. + struct cfi_usb_ctrlrequest *req);
  68421. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  68422. + struct cfi_usb_ctrlrequest *req);
  68423. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  68424. + struct cfi_usb_ctrlrequest *req);
  68425. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  68426. + struct cfi_usb_ctrlrequest *req);
  68427. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep);
  68428. +
  68429. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if);
  68430. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue);
  68431. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue);
  68432. +
  68433. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if);
  68434. +
  68435. +/** This is the header of the all features descriptor */
  68436. +static cfi_all_features_header_t all_props_desc_header = {
  68437. + .wVersion = DWC_CONSTANT_CPU_TO_LE16(0x100),
  68438. + .wCoreID = DWC_CONSTANT_CPU_TO_LE16(CFI_CORE_ID_OTG),
  68439. + .wNumFeatures = DWC_CONSTANT_CPU_TO_LE16(9),
  68440. +};
  68441. +
  68442. +/** This is an array of statically allocated feature descriptors */
  68443. +static cfi_feature_desc_header_t prop_descs[] = {
  68444. +
  68445. + /* FT_ID_DMA_MODE */
  68446. + {
  68447. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_MODE),
  68448. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  68449. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(1),
  68450. + },
  68451. +
  68452. + /* FT_ID_DMA_BUFFER_SETUP */
  68453. + {
  68454. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFFER_SETUP),
  68455. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  68456. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  68457. + },
  68458. +
  68459. + /* FT_ID_DMA_BUFF_ALIGN */
  68460. + {
  68461. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFF_ALIGN),
  68462. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  68463. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  68464. + },
  68465. +
  68466. + /* FT_ID_DMA_CONCAT_SETUP */
  68467. + {
  68468. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CONCAT_SETUP),
  68469. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  68470. + //.wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  68471. + },
  68472. +
  68473. + /* FT_ID_DMA_CIRCULAR */
  68474. + {
  68475. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CIRCULAR),
  68476. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  68477. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  68478. + },
  68479. +
  68480. + /* FT_ID_THRESHOLD_SETUP */
  68481. + {
  68482. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_THRESHOLD_SETUP),
  68483. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  68484. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  68485. + },
  68486. +
  68487. + /* FT_ID_DFIFO_DEPTH */
  68488. + {
  68489. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DFIFO_DEPTH),
  68490. + .bmAttributes = CFI_FEATURE_ATTR_RO,
  68491. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  68492. + },
  68493. +
  68494. + /* FT_ID_TX_FIFO_DEPTH */
  68495. + {
  68496. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_TX_FIFO_DEPTH),
  68497. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  68498. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  68499. + },
  68500. +
  68501. + /* FT_ID_RX_FIFO_DEPTH */
  68502. + {
  68503. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_RX_FIFO_DEPTH),
  68504. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  68505. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  68506. + }
  68507. +};
  68508. +
  68509. +/** The table of feature names */
  68510. +cfi_string_t prop_name_table[] = {
  68511. + {FT_ID_DMA_MODE, "dma_mode"},
  68512. + {FT_ID_DMA_BUFFER_SETUP, "buffer_setup"},
  68513. + {FT_ID_DMA_BUFF_ALIGN, "buffer_align"},
  68514. + {FT_ID_DMA_CONCAT_SETUP, "concat_setup"},
  68515. + {FT_ID_DMA_CIRCULAR, "buffer_circular"},
  68516. + {FT_ID_THRESHOLD_SETUP, "threshold_setup"},
  68517. + {FT_ID_DFIFO_DEPTH, "dfifo_depth"},
  68518. + {FT_ID_TX_FIFO_DEPTH, "txfifo_depth"},
  68519. + {FT_ID_RX_FIFO_DEPTH, "rxfifo_depth"},
  68520. + {}
  68521. +};
  68522. +
  68523. +/************************************************************************/
  68524. +
  68525. +/**
  68526. + * Returns the name of the feature by its ID
  68527. + * or NULL if no featute ID matches.
  68528. + *
  68529. + */
  68530. +const uint8_t *get_prop_name(uint16_t prop_id, int *len)
  68531. +{
  68532. + cfi_string_t *pstr;
  68533. + *len = 0;
  68534. +
  68535. + for (pstr = prop_name_table; pstr && pstr->s; pstr++) {
  68536. + if (pstr->id == prop_id) {
  68537. + *len = DWC_STRLEN(pstr->s);
  68538. + return pstr->s;
  68539. + }
  68540. + }
  68541. + return NULL;
  68542. +}
  68543. +
  68544. +/**
  68545. + * This function handles all CFI specific control requests.
  68546. + *
  68547. + * Return a negative value to stall the DCE.
  68548. + */
  68549. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl)
  68550. +{
  68551. + int retval = 0;
  68552. + dwc_otg_pcd_ep_t *ep = NULL;
  68553. + cfiobject_t *cfi = pcd->cfi;
  68554. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  68555. + uint16_t wLen = DWC_LE16_TO_CPU(&ctrl->wLength);
  68556. + uint16_t wValue = DWC_LE16_TO_CPU(&ctrl->wValue);
  68557. + uint16_t wIndex = DWC_LE16_TO_CPU(&ctrl->wIndex);
  68558. + uint32_t regaddr = 0;
  68559. + uint32_t regval = 0;
  68560. +
  68561. + /* Save this Control Request in the CFI object.
  68562. + * The data field will be assigned in the data stage completion CB function.
  68563. + */
  68564. + cfi->ctrl_req = *ctrl;
  68565. + cfi->ctrl_req.data = NULL;
  68566. +
  68567. + cfi->need_gadget_att = 0;
  68568. + cfi->need_status_in_complete = 0;
  68569. +
  68570. + switch (ctrl->bRequest) {
  68571. + case VEN_CORE_GET_FEATURES:
  68572. + retval = cfi_core_features_buf(cfi->buf_in.buf, CFI_IN_BUF_LEN);
  68573. + if (retval >= 0) {
  68574. + //dump_msg(cfi->buf_in.buf, retval);
  68575. + ep = &pcd->ep0;
  68576. +
  68577. + retval = min((uint16_t) retval, wLen);
  68578. + /* Transfer this buffer to the host through the EP0-IN EP */
  68579. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  68580. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  68581. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  68582. + ep->dwc_ep.xfer_len = retval;
  68583. + ep->dwc_ep.xfer_count = 0;
  68584. + ep->dwc_ep.sent_zlp = 0;
  68585. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  68586. +
  68587. + pcd->ep0_pending = 1;
  68588. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  68589. + }
  68590. + retval = 0;
  68591. + break;
  68592. +
  68593. + case VEN_CORE_GET_FEATURE:
  68594. + CFI_INFO("VEN_CORE_GET_FEATURE\n");
  68595. + retval = cfi_get_feature_value(cfi->buf_in.buf, CFI_IN_BUF_LEN,
  68596. + pcd, ctrl);
  68597. + if (retval >= 0) {
  68598. + ep = &pcd->ep0;
  68599. +
  68600. + retval = min((uint16_t) retval, wLen);
  68601. + /* Transfer this buffer to the host through the EP0-IN EP */
  68602. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  68603. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  68604. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  68605. + ep->dwc_ep.xfer_len = retval;
  68606. + ep->dwc_ep.xfer_count = 0;
  68607. + ep->dwc_ep.sent_zlp = 0;
  68608. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  68609. +
  68610. + pcd->ep0_pending = 1;
  68611. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  68612. + }
  68613. + CFI_INFO("VEN_CORE_GET_FEATURE=%d\n", retval);
  68614. + dump_msg(cfi->buf_in.buf, retval);
  68615. + break;
  68616. +
  68617. + case VEN_CORE_SET_FEATURE:
  68618. + CFI_INFO("VEN_CORE_SET_FEATURE\n");
  68619. + /* Set up an XFER to get the data stage of the control request,
  68620. + * which is the new value of the feature to be modified.
  68621. + */
  68622. + ep = &pcd->ep0;
  68623. + ep->dwc_ep.is_in = 0;
  68624. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  68625. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  68626. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  68627. + ep->dwc_ep.xfer_len = wLen;
  68628. + ep->dwc_ep.xfer_count = 0;
  68629. + ep->dwc_ep.sent_zlp = 0;
  68630. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  68631. +
  68632. + pcd->ep0_pending = 1;
  68633. + /* Read the control write's data stage */
  68634. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  68635. + retval = 0;
  68636. + break;
  68637. +
  68638. + case VEN_CORE_RESET_FEATURES:
  68639. + CFI_INFO("VEN_CORE_RESET_FEATURES\n");
  68640. + cfi->need_gadget_att = 1;
  68641. + cfi->need_status_in_complete = 1;
  68642. + retval = cfi_preproc_reset(pcd, ctrl);
  68643. + CFI_INFO("VEN_CORE_RESET_FEATURES = (%d)\n", retval);
  68644. + break;
  68645. +
  68646. + case VEN_CORE_ACTIVATE_FEATURES:
  68647. + CFI_INFO("VEN_CORE_ACTIVATE_FEATURES\n");
  68648. + break;
  68649. +
  68650. + case VEN_CORE_READ_REGISTER:
  68651. + CFI_INFO("VEN_CORE_READ_REGISTER\n");
  68652. + /* wValue optionally contains the HI WORD of the register offset and
  68653. + * wIndex contains the LOW WORD of the register offset
  68654. + */
  68655. + if (wValue == 0) {
  68656. + /* @TODO - MAS - fix the access to the base field */
  68657. + regaddr = 0;
  68658. + //regaddr = (uint32_t) pcd->otg_dev->os_dep.base;
  68659. + //GET_CORE_IF(pcd)->co
  68660. + regaddr |= wIndex;
  68661. + } else {
  68662. + regaddr = (wValue << 16) | wIndex;
  68663. + }
  68664. +
  68665. + /* Read a 32-bit value of the memory at the regaddr */
  68666. + regval = DWC_READ_REG32((uint32_t *) regaddr);
  68667. +
  68668. + ep = &pcd->ep0;
  68669. + dwc_memcpy(cfi->buf_in.buf, &regval, sizeof(uint32_t));
  68670. + ep->dwc_ep.is_in = 1;
  68671. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  68672. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  68673. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  68674. + ep->dwc_ep.xfer_len = wLen;
  68675. + ep->dwc_ep.xfer_count = 0;
  68676. + ep->dwc_ep.sent_zlp = 0;
  68677. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  68678. +
  68679. + pcd->ep0_pending = 1;
  68680. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  68681. + cfi->need_gadget_att = 0;
  68682. + retval = 0;
  68683. + break;
  68684. +
  68685. + case VEN_CORE_WRITE_REGISTER:
  68686. + CFI_INFO("VEN_CORE_WRITE_REGISTER\n");
  68687. + /* Set up an XFER to get the data stage of the control request,
  68688. + * which is the new value of the register to be modified.
  68689. + */
  68690. + ep = &pcd->ep0;
  68691. + ep->dwc_ep.is_in = 0;
  68692. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  68693. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  68694. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  68695. + ep->dwc_ep.xfer_len = wLen;
  68696. + ep->dwc_ep.xfer_count = 0;
  68697. + ep->dwc_ep.sent_zlp = 0;
  68698. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  68699. +
  68700. + pcd->ep0_pending = 1;
  68701. + /* Read the control write's data stage */
  68702. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  68703. + retval = 0;
  68704. + break;
  68705. +
  68706. + default:
  68707. + retval = -DWC_E_NOT_SUPPORTED;
  68708. + break;
  68709. + }
  68710. +
  68711. + return retval;
  68712. +}
  68713. +
  68714. +/**
  68715. + * This function prepares the core features descriptors and copies its
  68716. + * raw representation into the buffer <buf>.
  68717. + *
  68718. + * The buffer structure is as follows:
  68719. + * all_features_header (8 bytes)
  68720. + * features_#1 (8 bytes + feature name string length)
  68721. + * features_#2 (8 bytes + feature name string length)
  68722. + * .....
  68723. + * features_#n - where n=the total count of feature descriptors
  68724. + */
  68725. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen)
  68726. +{
  68727. + cfi_feature_desc_header_t *prop_hdr = prop_descs;
  68728. + cfi_feature_desc_header_t *prop;
  68729. + cfi_all_features_header_t *all_props_hdr = &all_props_desc_header;
  68730. + cfi_all_features_header_t *tmp;
  68731. + uint8_t *tmpbuf = buf;
  68732. + const uint8_t *pname = NULL;
  68733. + int i, j, namelen = 0, totlen;
  68734. +
  68735. + /* Prepare and copy the core features into the buffer */
  68736. + CFI_INFO("%s:\n", __func__);
  68737. +
  68738. + tmp = (cfi_all_features_header_t *) tmpbuf;
  68739. + *tmp = *all_props_hdr;
  68740. + tmpbuf += CFI_ALL_FEATURES_HDR_LEN;
  68741. +
  68742. + j = sizeof(prop_descs) / sizeof(cfi_all_features_header_t);
  68743. + for (i = 0; i < j; i++, prop_hdr++) {
  68744. + pname = get_prop_name(prop_hdr->wFeatureID, &namelen);
  68745. + prop = (cfi_feature_desc_header_t *) tmpbuf;
  68746. + *prop = *prop_hdr;
  68747. +
  68748. + prop->bNameLen = namelen;
  68749. + prop->wLength =
  68750. + DWC_CONSTANT_CPU_TO_LE16(CFI_FEATURE_DESC_HDR_LEN +
  68751. + namelen);
  68752. +
  68753. + tmpbuf += CFI_FEATURE_DESC_HDR_LEN;
  68754. + dwc_memcpy(tmpbuf, pname, namelen);
  68755. + tmpbuf += namelen;
  68756. + }
  68757. +
  68758. + totlen = tmpbuf - buf;
  68759. +
  68760. + if (totlen > 0) {
  68761. + tmp = (cfi_all_features_header_t *) buf;
  68762. + tmp->wTotalLen = DWC_CONSTANT_CPU_TO_LE16(totlen);
  68763. + }
  68764. +
  68765. + return totlen;
  68766. +}
  68767. +
  68768. +/**
  68769. + * This function releases all the dynamic memory in the CFI object.
  68770. + */
  68771. +static void cfi_release(cfiobject_t * cfiobj)
  68772. +{
  68773. + cfi_ep_t *cfiep;
  68774. + dwc_list_link_t *tmp;
  68775. +
  68776. + CFI_INFO("%s\n", __func__);
  68777. +
  68778. + if (cfiobj->buf_in.buf) {
  68779. + DWC_DMA_FREE(CFI_IN_BUF_LEN, cfiobj->buf_in.buf,
  68780. + cfiobj->buf_in.addr);
  68781. + cfiobj->buf_in.buf = NULL;
  68782. + }
  68783. +
  68784. + if (cfiobj->buf_out.buf) {
  68785. + DWC_DMA_FREE(CFI_OUT_BUF_LEN, cfiobj->buf_out.buf,
  68786. + cfiobj->buf_out.addr);
  68787. + cfiobj->buf_out.buf = NULL;
  68788. + }
  68789. +
  68790. + /* Free the Buffer Setup values for each EP */
  68791. + //list_for_each_entry(cfiep, &cfiobj->active_eps, lh) {
  68792. + DWC_LIST_FOREACH(tmp, &cfiobj->active_eps) {
  68793. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  68794. + cfi_free_ep_bs_dyn_data(cfiep);
  68795. + }
  68796. +}
  68797. +
  68798. +/**
  68799. + * This function frees the dynamically allocated EP buffer setup data.
  68800. + */
  68801. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep)
  68802. +{
  68803. + if (cfiep->bm_sg) {
  68804. + DWC_FREE(cfiep->bm_sg);
  68805. + cfiep->bm_sg = NULL;
  68806. + }
  68807. +
  68808. + if (cfiep->bm_align) {
  68809. + DWC_FREE(cfiep->bm_align);
  68810. + cfiep->bm_align = NULL;
  68811. + }
  68812. +
  68813. + if (cfiep->bm_concat) {
  68814. + if (NULL != cfiep->bm_concat->wTxBytes) {
  68815. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  68816. + cfiep->bm_concat->wTxBytes = NULL;
  68817. + }
  68818. + DWC_FREE(cfiep->bm_concat);
  68819. + cfiep->bm_concat = NULL;
  68820. + }
  68821. +}
  68822. +
  68823. +/**
  68824. + * This function initializes the default values of the features
  68825. + * for a specific endpoint and should be called only once when
  68826. + * the EP is enabled first time.
  68827. + */
  68828. +static int cfi_ep_init_defaults(struct dwc_otg_pcd *pcd, cfi_ep_t * cfiep)
  68829. +{
  68830. + int retval = 0;
  68831. +
  68832. + cfiep->bm_sg = DWC_ALLOC(sizeof(ddma_sg_buffer_setup_t));
  68833. + if (NULL == cfiep->bm_sg) {
  68834. + CFI_INFO("Failed to allocate memory for SG feature value\n");
  68835. + return -DWC_E_NO_MEMORY;
  68836. + }
  68837. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  68838. +
  68839. + /* For the Concatenation feature's default value we do not allocate
  68840. + * memory for the wTxBytes field - it will be done in the set_feature_value
  68841. + * request handler.
  68842. + */
  68843. + cfiep->bm_concat = DWC_ALLOC(sizeof(ddma_concat_buffer_setup_t));
  68844. + if (NULL == cfiep->bm_concat) {
  68845. + CFI_INFO
  68846. + ("Failed to allocate memory for CONCATENATION feature value\n");
  68847. + DWC_FREE(cfiep->bm_sg);
  68848. + return -DWC_E_NO_MEMORY;
  68849. + }
  68850. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  68851. +
  68852. + cfiep->bm_align = DWC_ALLOC(sizeof(ddma_align_buffer_setup_t));
  68853. + if (NULL == cfiep->bm_align) {
  68854. + CFI_INFO
  68855. + ("Failed to allocate memory for Alignment feature value\n");
  68856. + DWC_FREE(cfiep->bm_sg);
  68857. + DWC_FREE(cfiep->bm_concat);
  68858. + return -DWC_E_NO_MEMORY;
  68859. + }
  68860. + dwc_memset(cfiep->bm_align, 0, sizeof(ddma_align_buffer_setup_t));
  68861. +
  68862. + return retval;
  68863. +}
  68864. +
  68865. +/**
  68866. + * The callback function that notifies the CFI on the activation of
  68867. + * an endpoint in the PCD. The following steps are done in this function:
  68868. + *
  68869. + * Create a dynamically allocated cfi_ep_t object (a CFI wrapper to the PCD's
  68870. + * active endpoint)
  68871. + * Create MAX_DMA_DESCS_PER_EP count DMA Descriptors for the EP
  68872. + * Set the Buffer Mode to standard
  68873. + * Initialize the default values for all EP modes (SG, Circular, Concat, Align)
  68874. + * Add the cfi_ep_t object to the list of active endpoints in the CFI object
  68875. + */
  68876. +static int cfi_ep_enable(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  68877. + struct dwc_otg_pcd_ep *ep)
  68878. +{
  68879. + cfi_ep_t *cfiep;
  68880. + int retval = -DWC_E_NOT_SUPPORTED;
  68881. +
  68882. + CFI_INFO("%s: epname=%s; epnum=0x%02x\n", __func__,
  68883. + "EP_" /*ep->ep.name */ , ep->desc->bEndpointAddress);
  68884. + /* MAS - Check whether this endpoint already is in the list */
  68885. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  68886. +
  68887. + if (NULL == cfiep) {
  68888. + /* Allocate a cfi_ep_t object */
  68889. + cfiep = DWC_ALLOC(sizeof(cfi_ep_t));
  68890. + if (NULL == cfiep) {
  68891. + CFI_INFO
  68892. + ("Unable to allocate memory for <cfiep> in function %s\n",
  68893. + __func__);
  68894. + return -DWC_E_NO_MEMORY;
  68895. + }
  68896. + dwc_memset(cfiep, 0, sizeof(cfi_ep_t));
  68897. +
  68898. + /* Save the dwc_otg_pcd_ep pointer in the cfiep object */
  68899. + cfiep->ep = ep;
  68900. +
  68901. + /* Allocate the DMA Descriptors chain of MAX_DMA_DESCS_PER_EP count */
  68902. + ep->dwc_ep.descs =
  68903. + DWC_DMA_ALLOC(MAX_DMA_DESCS_PER_EP *
  68904. + sizeof(dwc_otg_dma_desc_t),
  68905. + &ep->dwc_ep.descs_dma_addr);
  68906. +
  68907. + if (NULL == ep->dwc_ep.descs) {
  68908. + DWC_FREE(cfiep);
  68909. + return -DWC_E_NO_MEMORY;
  68910. + }
  68911. +
  68912. + DWC_LIST_INIT(&cfiep->lh);
  68913. +
  68914. + /* Set the buffer mode to BM_STANDARD. It will be modified
  68915. + * when building descriptors for a specific buffer mode */
  68916. + ep->dwc_ep.buff_mode = BM_STANDARD;
  68917. +
  68918. + /* Create and initialize the default values for this EP's Buffer modes */
  68919. + if ((retval = cfi_ep_init_defaults(pcd, cfiep)) < 0)
  68920. + return retval;
  68921. +
  68922. + /* Add the cfi_ep_t object to the CFI object's list of active endpoints */
  68923. + DWC_LIST_INSERT_TAIL(&cfi->active_eps, &cfiep->lh);
  68924. + retval = 0;
  68925. + } else { /* The sought EP already is in the list */
  68926. + CFI_INFO("%s: The sought EP already is in the list\n",
  68927. + __func__);
  68928. + }
  68929. +
  68930. + return retval;
  68931. +}
  68932. +
  68933. +/**
  68934. + * This function is called when the data stage of a 3-stage Control Write request
  68935. + * is complete.
  68936. + *
  68937. + */
  68938. +static int cfi_ctrl_write_complete(struct cfiobject *cfi,
  68939. + struct dwc_otg_pcd *pcd)
  68940. +{
  68941. + uint32_t addr, reg_value;
  68942. + uint16_t wIndex, wValue;
  68943. + uint8_t bRequest;
  68944. + uint8_t *buf = cfi->buf_out.buf;
  68945. + //struct usb_ctrlrequest *ctrl_req = &cfi->ctrl_req_saved;
  68946. + struct cfi_usb_ctrlrequest *ctrl_req = &cfi->ctrl_req;
  68947. + int retval = -DWC_E_NOT_SUPPORTED;
  68948. +
  68949. + CFI_INFO("%s\n", __func__);
  68950. +
  68951. + bRequest = ctrl_req->bRequest;
  68952. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  68953. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  68954. +
  68955. + /*
  68956. + * Save the pointer to the data stage in the ctrl_req's <data> field.
  68957. + * The request should be already saved in the command stage by now.
  68958. + */
  68959. + ctrl_req->data = cfi->buf_out.buf;
  68960. + cfi->need_status_in_complete = 0;
  68961. + cfi->need_gadget_att = 0;
  68962. +
  68963. + switch (bRequest) {
  68964. + case VEN_CORE_WRITE_REGISTER:
  68965. + /* The buffer contains raw data of the new value for the register */
  68966. + reg_value = *((uint32_t *) buf);
  68967. + if (wValue == 0) {
  68968. + addr = 0;
  68969. + //addr = (uint32_t) pcd->otg_dev->os_dep.base;
  68970. + addr += wIndex;
  68971. + } else {
  68972. + addr = (wValue << 16) | wIndex;
  68973. + }
  68974. +
  68975. + //writel(reg_value, addr);
  68976. +
  68977. + retval = 0;
  68978. + cfi->need_status_in_complete = 1;
  68979. + break;
  68980. +
  68981. + case VEN_CORE_SET_FEATURE:
  68982. + /* The buffer contains raw data of the new value of the feature */
  68983. + retval = cfi_set_feature_value(pcd);
  68984. + if (retval < 0)
  68985. + return retval;
  68986. +
  68987. + cfi->need_status_in_complete = 1;
  68988. + break;
  68989. +
  68990. + default:
  68991. + break;
  68992. + }
  68993. +
  68994. + return retval;
  68995. +}
  68996. +
  68997. +/**
  68998. + * This function builds the DMA descriptors for the SG buffer mode.
  68999. + */
  69000. +static void cfi_build_sg_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  69001. + dwc_otg_pcd_request_t * req)
  69002. +{
  69003. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  69004. + ddma_sg_buffer_setup_t *sgval = cfiep->bm_sg;
  69005. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  69006. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  69007. + dma_addr_t buff_addr = req->dma;
  69008. + int i;
  69009. + uint32_t txsize, off;
  69010. +
  69011. + txsize = sgval->wSize;
  69012. + off = sgval->bOffset;
  69013. +
  69014. +// CFI_INFO("%s: %s TXSIZE=0x%08x; OFFSET=0x%08x\n",
  69015. +// __func__, cfiep->ep->ep.name, txsize, off);
  69016. +
  69017. + for (i = 0; i < sgval->bCount; i++) {
  69018. + desc->status.b.bs = BS_HOST_BUSY;
  69019. + desc->buf = buff_addr;
  69020. + desc->status.b.l = 0;
  69021. + desc->status.b.ioc = 0;
  69022. + desc->status.b.sp = 0;
  69023. + desc->status.b.bytes = txsize;
  69024. + desc->status.b.bs = BS_HOST_READY;
  69025. +
  69026. + /* Set the next address of the buffer */
  69027. + buff_addr += txsize + off;
  69028. + desc_last = desc;
  69029. + desc++;
  69030. + }
  69031. +
  69032. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  69033. + desc_last->status.b.l = 1;
  69034. + desc_last->status.b.ioc = 1;
  69035. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  69036. + /* Save the last DMA descriptor pointer */
  69037. + cfiep->dma_desc_last = desc_last;
  69038. + cfiep->desc_count = sgval->bCount;
  69039. +}
  69040. +
  69041. +/**
  69042. + * This function builds the DMA descriptors for the Concatenation buffer mode.
  69043. + */
  69044. +static void cfi_build_concat_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  69045. + dwc_otg_pcd_request_t * req)
  69046. +{
  69047. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  69048. + ddma_concat_buffer_setup_t *concatval = cfiep->bm_concat;
  69049. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  69050. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  69051. + dma_addr_t buff_addr = req->dma;
  69052. + int i;
  69053. + uint16_t *txsize;
  69054. +
  69055. + txsize = concatval->wTxBytes;
  69056. +
  69057. + for (i = 0; i < concatval->hdr.bDescCount; i++) {
  69058. + desc->buf = buff_addr;
  69059. + desc->status.b.bs = BS_HOST_BUSY;
  69060. + desc->status.b.l = 0;
  69061. + desc->status.b.ioc = 0;
  69062. + desc->status.b.sp = 0;
  69063. + desc->status.b.bytes = *txsize;
  69064. + desc->status.b.bs = BS_HOST_READY;
  69065. +
  69066. + txsize++;
  69067. + /* Set the next address of the buffer */
  69068. + buff_addr += UGETW(ep->desc->wMaxPacketSize);
  69069. + desc_last = desc;
  69070. + desc++;
  69071. + }
  69072. +
  69073. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  69074. + desc_last->status.b.l = 1;
  69075. + desc_last->status.b.ioc = 1;
  69076. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  69077. + cfiep->dma_desc_last = desc_last;
  69078. + cfiep->desc_count = concatval->hdr.bDescCount;
  69079. +}
  69080. +
  69081. +/**
  69082. + * This function builds the DMA descriptors for the Circular buffer mode
  69083. + */
  69084. +static void cfi_build_circ_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  69085. + dwc_otg_pcd_request_t * req)
  69086. +{
  69087. + /* @todo: MAS - add implementation when this feature needs to be tested */
  69088. +}
  69089. +
  69090. +/**
  69091. + * This function builds the DMA descriptors for the Alignment buffer mode
  69092. + */
  69093. +static void cfi_build_align_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  69094. + dwc_otg_pcd_request_t * req)
  69095. +{
  69096. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  69097. + ddma_align_buffer_setup_t *alignval = cfiep->bm_align;
  69098. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  69099. + dma_addr_t buff_addr = req->dma;
  69100. +
  69101. + desc->status.b.bs = BS_HOST_BUSY;
  69102. + desc->status.b.l = 1;
  69103. + desc->status.b.ioc = 1;
  69104. + desc->status.b.sp = ep->dwc_ep.sent_zlp;
  69105. + desc->status.b.bytes = req->length;
  69106. + /* Adjust the buffer alignment */
  69107. + desc->buf = (buff_addr + alignval->bAlign);
  69108. + desc->status.b.bs = BS_HOST_READY;
  69109. + cfiep->dma_desc_last = desc;
  69110. + cfiep->desc_count = 1;
  69111. +}
  69112. +
  69113. +/**
  69114. + * This function builds the DMA descriptors chain for different modes of the
  69115. + * buffer setup of an endpoint.
  69116. + */
  69117. +static void cfi_build_descriptors(struct cfiobject *cfi,
  69118. + struct dwc_otg_pcd *pcd,
  69119. + struct dwc_otg_pcd_ep *ep,
  69120. + dwc_otg_pcd_request_t * req)
  69121. +{
  69122. + cfi_ep_t *cfiep;
  69123. +
  69124. + /* Get the cfiep by the dwc_otg_pcd_ep */
  69125. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  69126. + if (NULL == cfiep) {
  69127. + CFI_INFO("%s: Unable to find a matching active endpoint\n",
  69128. + __func__);
  69129. + return;
  69130. + }
  69131. +
  69132. + cfiep->xfer_len = req->length;
  69133. +
  69134. + /* Iterate through all the DMA descriptors */
  69135. + switch (cfiep->ep->dwc_ep.buff_mode) {
  69136. + case BM_SG:
  69137. + cfi_build_sg_descs(cfi, cfiep, req);
  69138. + break;
  69139. +
  69140. + case BM_CONCAT:
  69141. + cfi_build_concat_descs(cfi, cfiep, req);
  69142. + break;
  69143. +
  69144. + case BM_CIRCULAR:
  69145. + cfi_build_circ_descs(cfi, cfiep, req);
  69146. + break;
  69147. +
  69148. + case BM_ALIGN:
  69149. + cfi_build_align_descs(cfi, cfiep, req);
  69150. + break;
  69151. +
  69152. + default:
  69153. + break;
  69154. + }
  69155. +}
  69156. +
  69157. +/**
  69158. + * Allocate DMA buffer for different Buffer modes.
  69159. + */
  69160. +static void *cfi_ep_alloc_buf(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  69161. + struct dwc_otg_pcd_ep *ep, dma_addr_t * dma,
  69162. + unsigned size, gfp_t flags)
  69163. +{
  69164. + return DWC_DMA_ALLOC(size, dma);
  69165. +}
  69166. +
  69167. +/**
  69168. + * This function initializes the CFI object.
  69169. + */
  69170. +int init_cfi(cfiobject_t * cfiobj)
  69171. +{
  69172. + CFI_INFO("%s\n", __func__);
  69173. +
  69174. + /* Allocate a buffer for IN XFERs */
  69175. + cfiobj->buf_in.buf =
  69176. + DWC_DMA_ALLOC(CFI_IN_BUF_LEN, &cfiobj->buf_in.addr);
  69177. + if (NULL == cfiobj->buf_in.buf) {
  69178. + CFI_INFO("Unable to allocate buffer for INs\n");
  69179. + return -DWC_E_NO_MEMORY;
  69180. + }
  69181. +
  69182. + /* Allocate a buffer for OUT XFERs */
  69183. + cfiobj->buf_out.buf =
  69184. + DWC_DMA_ALLOC(CFI_OUT_BUF_LEN, &cfiobj->buf_out.addr);
  69185. + if (NULL == cfiobj->buf_out.buf) {
  69186. + CFI_INFO("Unable to allocate buffer for OUT\n");
  69187. + return -DWC_E_NO_MEMORY;
  69188. + }
  69189. +
  69190. + /* Initialize the callback function pointers */
  69191. + cfiobj->ops.release = cfi_release;
  69192. + cfiobj->ops.ep_enable = cfi_ep_enable;
  69193. + cfiobj->ops.ctrl_write_complete = cfi_ctrl_write_complete;
  69194. + cfiobj->ops.build_descriptors = cfi_build_descriptors;
  69195. + cfiobj->ops.ep_alloc_buf = cfi_ep_alloc_buf;
  69196. +
  69197. + /* Initialize the list of active endpoints in the CFI object */
  69198. + DWC_LIST_INIT(&cfiobj->active_eps);
  69199. +
  69200. + return 0;
  69201. +}
  69202. +
  69203. +/**
  69204. + * This function reads the required feature's current value into the buffer
  69205. + *
  69206. + * @retval: Returns negative as error, or the data length of the feature
  69207. + */
  69208. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  69209. + struct dwc_otg_pcd *pcd,
  69210. + struct cfi_usb_ctrlrequest *ctrl_req)
  69211. +{
  69212. + int retval = -DWC_E_NOT_SUPPORTED;
  69213. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  69214. + uint16_t dfifo, rxfifo, txfifo;
  69215. +
  69216. + switch (ctrl_req->wIndex) {
  69217. + /* Whether the DDMA is enabled or not */
  69218. + case FT_ID_DMA_MODE:
  69219. + *buf = (coreif->dma_enable && coreif->dma_desc_enable) ? 1 : 0;
  69220. + retval = 1;
  69221. + break;
  69222. +
  69223. + case FT_ID_DMA_BUFFER_SETUP:
  69224. + retval = cfi_ep_get_sg_val(buf, pcd, ctrl_req);
  69225. + break;
  69226. +
  69227. + case FT_ID_DMA_BUFF_ALIGN:
  69228. + retval = cfi_ep_get_align_val(buf, pcd, ctrl_req);
  69229. + break;
  69230. +
  69231. + case FT_ID_DMA_CONCAT_SETUP:
  69232. + retval = cfi_ep_get_concat_val(buf, pcd, ctrl_req);
  69233. + break;
  69234. +
  69235. + case FT_ID_DMA_CIRCULAR:
  69236. + CFI_INFO("GetFeature value (FT_ID_DMA_CIRCULAR)\n");
  69237. + break;
  69238. +
  69239. + case FT_ID_THRESHOLD_SETUP:
  69240. + CFI_INFO("GetFeature value (FT_ID_THRESHOLD_SETUP)\n");
  69241. + break;
  69242. +
  69243. + case FT_ID_DFIFO_DEPTH:
  69244. + dfifo = get_dfifo_size(coreif);
  69245. + *((uint16_t *) buf) = dfifo;
  69246. + retval = sizeof(uint16_t);
  69247. + break;
  69248. +
  69249. + case FT_ID_TX_FIFO_DEPTH:
  69250. + retval = get_txfifo_size(pcd, ctrl_req->wValue);
  69251. + if (retval >= 0) {
  69252. + txfifo = retval;
  69253. + *((uint16_t *) buf) = txfifo;
  69254. + retval = sizeof(uint16_t);
  69255. + }
  69256. + break;
  69257. +
  69258. + case FT_ID_RX_FIFO_DEPTH:
  69259. + retval = get_rxfifo_size(coreif, ctrl_req->wValue);
  69260. + if (retval >= 0) {
  69261. + rxfifo = retval;
  69262. + *((uint16_t *) buf) = rxfifo;
  69263. + retval = sizeof(uint16_t);
  69264. + }
  69265. + break;
  69266. + }
  69267. +
  69268. + return retval;
  69269. +}
  69270. +
  69271. +/**
  69272. + * This function resets the SG for the specified EP to its default value
  69273. + */
  69274. +static int cfi_reset_sg_val(cfi_ep_t * cfiep)
  69275. +{
  69276. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  69277. + return 0;
  69278. +}
  69279. +
  69280. +/**
  69281. + * This function resets the Alignment for the specified EP to its default value
  69282. + */
  69283. +static int cfi_reset_align_val(cfi_ep_t * cfiep)
  69284. +{
  69285. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  69286. + return 0;
  69287. +}
  69288. +
  69289. +/**
  69290. + * This function resets the Concatenation for the specified EP to its default value
  69291. + * This function will also set the value of the wTxBytes field to NULL after
  69292. + * freeing the memory previously allocated for this field.
  69293. + */
  69294. +static int cfi_reset_concat_val(cfi_ep_t * cfiep)
  69295. +{
  69296. + /* First we need to free the wTxBytes field */
  69297. + if (cfiep->bm_concat->wTxBytes) {
  69298. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  69299. + cfiep->bm_concat->wTxBytes = NULL;
  69300. + }
  69301. +
  69302. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  69303. + return 0;
  69304. +}
  69305. +
  69306. +/**
  69307. + * This function resets all the buffer setups of the specified endpoint
  69308. + */
  69309. +static int cfi_ep_reset_all_setup_vals(cfi_ep_t * cfiep)
  69310. +{
  69311. + cfi_reset_sg_val(cfiep);
  69312. + cfi_reset_align_val(cfiep);
  69313. + cfi_reset_concat_val(cfiep);
  69314. + return 0;
  69315. +}
  69316. +
  69317. +static int cfi_handle_reset_fifo_val(struct dwc_otg_pcd *pcd, uint8_t ep_addr,
  69318. + uint8_t rx_rst, uint8_t tx_rst)
  69319. +{
  69320. + int retval = -DWC_E_INVALID;
  69321. + uint16_t tx_siz[15];
  69322. + uint16_t rx_siz = 0;
  69323. + dwc_otg_pcd_ep_t *ep = NULL;
  69324. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  69325. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  69326. +
  69327. + if (rx_rst) {
  69328. + rx_siz = params->dev_rx_fifo_size;
  69329. + params->dev_rx_fifo_size = GET_CORE_IF(pcd)->init_rxfsiz;
  69330. + }
  69331. +
  69332. + if (tx_rst) {
  69333. + if (ep_addr == 0) {
  69334. + int i;
  69335. +
  69336. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  69337. + tx_siz[i] =
  69338. + core_if->core_params->dev_tx_fifo_size[i];
  69339. + core_if->core_params->dev_tx_fifo_size[i] =
  69340. + core_if->init_txfsiz[i];
  69341. + }
  69342. + } else {
  69343. +
  69344. + ep = get_ep_by_addr(pcd, ep_addr);
  69345. +
  69346. + if (NULL == ep) {
  69347. + CFI_INFO
  69348. + ("%s: Unable to get the endpoint addr=0x%02x\n",
  69349. + __func__, ep_addr);
  69350. + return -DWC_E_INVALID;
  69351. + }
  69352. +
  69353. + tx_siz[0] =
  69354. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num -
  69355. + 1];
  69356. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] =
  69357. + GET_CORE_IF(pcd)->init_txfsiz[ep->
  69358. + dwc_ep.tx_fifo_num -
  69359. + 1];
  69360. + }
  69361. + }
  69362. +
  69363. + if (resize_fifos(GET_CORE_IF(pcd))) {
  69364. + retval = 0;
  69365. + } else {
  69366. + CFI_INFO
  69367. + ("%s: Error resetting the feature Reset All(FIFO size)\n",
  69368. + __func__);
  69369. + if (rx_rst) {
  69370. + params->dev_rx_fifo_size = rx_siz;
  69371. + }
  69372. +
  69373. + if (tx_rst) {
  69374. + if (ep_addr == 0) {
  69375. + int i;
  69376. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps;
  69377. + i++) {
  69378. + core_if->
  69379. + core_params->dev_tx_fifo_size[i] =
  69380. + tx_siz[i];
  69381. + }
  69382. + } else {
  69383. + params->dev_tx_fifo_size[ep->
  69384. + dwc_ep.tx_fifo_num -
  69385. + 1] = tx_siz[0];
  69386. + }
  69387. + }
  69388. + retval = -DWC_E_INVALID;
  69389. + }
  69390. + return retval;
  69391. +}
  69392. +
  69393. +static int cfi_handle_reset_all(struct dwc_otg_pcd *pcd, uint8_t addr)
  69394. +{
  69395. + int retval = 0;
  69396. + cfi_ep_t *cfiep;
  69397. + cfiobject_t *cfi = pcd->cfi;
  69398. + dwc_list_link_t *tmp;
  69399. +
  69400. + retval = cfi_handle_reset_fifo_val(pcd, addr, 1, 1);
  69401. + if (retval < 0) {
  69402. + return retval;
  69403. + }
  69404. +
  69405. + /* If the EP address is known then reset the features for only that EP */
  69406. + if (addr) {
  69407. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  69408. + if (NULL == cfiep) {
  69409. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  69410. + __func__, addr);
  69411. + return -DWC_E_INVALID;
  69412. + }
  69413. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  69414. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  69415. + }
  69416. + /* Otherwise (wValue == 0), reset all features of all EP's */
  69417. + else {
  69418. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  69419. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  69420. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  69421. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  69422. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  69423. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  69424. + if (retval < 0) {
  69425. + CFI_INFO
  69426. + ("%s: Error resetting the feature Reset All\n",
  69427. + __func__);
  69428. + return retval;
  69429. + }
  69430. + }
  69431. + }
  69432. + return retval;
  69433. +}
  69434. +
  69435. +static int cfi_handle_reset_dma_buff_setup(struct dwc_otg_pcd *pcd,
  69436. + uint8_t addr)
  69437. +{
  69438. + int retval = 0;
  69439. + cfi_ep_t *cfiep;
  69440. + cfiobject_t *cfi = pcd->cfi;
  69441. + dwc_list_link_t *tmp;
  69442. +
  69443. + /* If the EP address is known then reset the features for only that EP */
  69444. + if (addr) {
  69445. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  69446. + if (NULL == cfiep) {
  69447. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  69448. + __func__, addr);
  69449. + return -DWC_E_INVALID;
  69450. + }
  69451. + retval = cfi_reset_sg_val(cfiep);
  69452. + }
  69453. + /* Otherwise (wValue == 0), reset all features of all EP's */
  69454. + else {
  69455. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  69456. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  69457. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  69458. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  69459. + retval = cfi_reset_sg_val(cfiep);
  69460. + if (retval < 0) {
  69461. + CFI_INFO
  69462. + ("%s: Error resetting the feature Buffer Setup\n",
  69463. + __func__);
  69464. + return retval;
  69465. + }
  69466. + }
  69467. + }
  69468. + return retval;
  69469. +}
  69470. +
  69471. +static int cfi_handle_reset_concat_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  69472. +{
  69473. + int retval = 0;
  69474. + cfi_ep_t *cfiep;
  69475. + cfiobject_t *cfi = pcd->cfi;
  69476. + dwc_list_link_t *tmp;
  69477. +
  69478. + /* If the EP address is known then reset the features for only that EP */
  69479. + if (addr) {
  69480. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  69481. + if (NULL == cfiep) {
  69482. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  69483. + __func__, addr);
  69484. + return -DWC_E_INVALID;
  69485. + }
  69486. + retval = cfi_reset_concat_val(cfiep);
  69487. + }
  69488. + /* Otherwise (wValue == 0), reset all features of all EP's */
  69489. + else {
  69490. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  69491. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  69492. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  69493. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  69494. + retval = cfi_reset_concat_val(cfiep);
  69495. + if (retval < 0) {
  69496. + CFI_INFO
  69497. + ("%s: Error resetting the feature Concatenation Value\n",
  69498. + __func__);
  69499. + return retval;
  69500. + }
  69501. + }
  69502. + }
  69503. + return retval;
  69504. +}
  69505. +
  69506. +static int cfi_handle_reset_align_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  69507. +{
  69508. + int retval = 0;
  69509. + cfi_ep_t *cfiep;
  69510. + cfiobject_t *cfi = pcd->cfi;
  69511. + dwc_list_link_t *tmp;
  69512. +
  69513. + /* If the EP address is known then reset the features for only that EP */
  69514. + if (addr) {
  69515. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  69516. + if (NULL == cfiep) {
  69517. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  69518. + __func__, addr);
  69519. + return -DWC_E_INVALID;
  69520. + }
  69521. + retval = cfi_reset_align_val(cfiep);
  69522. + }
  69523. + /* Otherwise (wValue == 0), reset all features of all EP's */
  69524. + else {
  69525. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  69526. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  69527. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  69528. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  69529. + retval = cfi_reset_align_val(cfiep);
  69530. + if (retval < 0) {
  69531. + CFI_INFO
  69532. + ("%s: Error resetting the feature Aliignment Value\n",
  69533. + __func__);
  69534. + return retval;
  69535. + }
  69536. + }
  69537. + }
  69538. + return retval;
  69539. +
  69540. +}
  69541. +
  69542. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  69543. + struct cfi_usb_ctrlrequest *req)
  69544. +{
  69545. + int retval = 0;
  69546. +
  69547. + switch (req->wIndex) {
  69548. + case 0:
  69549. + /* Reset all features */
  69550. + retval = cfi_handle_reset_all(pcd, req->wValue & 0xff);
  69551. + break;
  69552. +
  69553. + case FT_ID_DMA_BUFFER_SETUP:
  69554. + /* Reset the SG buffer setup */
  69555. + retval =
  69556. + cfi_handle_reset_dma_buff_setup(pcd, req->wValue & 0xff);
  69557. + break;
  69558. +
  69559. + case FT_ID_DMA_CONCAT_SETUP:
  69560. + /* Reset the Concatenation buffer setup */
  69561. + retval = cfi_handle_reset_concat_val(pcd, req->wValue & 0xff);
  69562. + break;
  69563. +
  69564. + case FT_ID_DMA_BUFF_ALIGN:
  69565. + /* Reset the Alignment buffer setup */
  69566. + retval = cfi_handle_reset_align_val(pcd, req->wValue & 0xff);
  69567. + break;
  69568. +
  69569. + case FT_ID_TX_FIFO_DEPTH:
  69570. + retval =
  69571. + cfi_handle_reset_fifo_val(pcd, req->wValue & 0xff, 0, 1);
  69572. + pcd->cfi->need_gadget_att = 0;
  69573. + break;
  69574. +
  69575. + case FT_ID_RX_FIFO_DEPTH:
  69576. + retval = cfi_handle_reset_fifo_val(pcd, 0, 1, 0);
  69577. + pcd->cfi->need_gadget_att = 0;
  69578. + break;
  69579. + default:
  69580. + break;
  69581. + }
  69582. + return retval;
  69583. +}
  69584. +
  69585. +/**
  69586. + * This function sets a new value for the SG buffer setup.
  69587. + */
  69588. +static int cfi_ep_set_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  69589. +{
  69590. + uint8_t inaddr, outaddr;
  69591. + cfi_ep_t *epin, *epout;
  69592. + ddma_sg_buffer_setup_t *psgval;
  69593. + uint32_t desccount, size;
  69594. +
  69595. + CFI_INFO("%s\n", __func__);
  69596. +
  69597. + psgval = (ddma_sg_buffer_setup_t *) buf;
  69598. + desccount = (uint32_t) psgval->bCount;
  69599. + size = (uint32_t) psgval->wSize;
  69600. +
  69601. + /* Check the DMA descriptor count */
  69602. + if ((desccount > MAX_DMA_DESCS_PER_EP) || (desccount == 0)) {
  69603. + CFI_INFO
  69604. + ("%s: The count of DMA Descriptors should be between 1 and %d\n",
  69605. + __func__, MAX_DMA_DESCS_PER_EP);
  69606. + return -DWC_E_INVALID;
  69607. + }
  69608. +
  69609. + /* Check the DMA descriptor count */
  69610. +
  69611. + if (size == 0) {
  69612. +
  69613. + CFI_INFO("%s: The transfer size should be at least 1 byte\n",
  69614. + __func__);
  69615. +
  69616. + return -DWC_E_INVALID;
  69617. +
  69618. + }
  69619. +
  69620. + inaddr = psgval->bInEndpointAddress;
  69621. + outaddr = psgval->bOutEndpointAddress;
  69622. +
  69623. + epin = get_cfi_ep_by_addr(pcd->cfi, inaddr);
  69624. + epout = get_cfi_ep_by_addr(pcd->cfi, outaddr);
  69625. +
  69626. + if (NULL == epin || NULL == epout) {
  69627. + CFI_INFO
  69628. + ("%s: Unable to get the endpoints inaddr=0x%02x outaddr=0x%02x\n",
  69629. + __func__, inaddr, outaddr);
  69630. + return -DWC_E_INVALID;
  69631. + }
  69632. +
  69633. + epin->ep->dwc_ep.buff_mode = BM_SG;
  69634. + dwc_memcpy(epin->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  69635. +
  69636. + epout->ep->dwc_ep.buff_mode = BM_SG;
  69637. + dwc_memcpy(epout->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  69638. +
  69639. + return 0;
  69640. +}
  69641. +
  69642. +/**
  69643. + * This function sets a new value for the buffer Alignment setup.
  69644. + */
  69645. +static int cfi_ep_set_alignment_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  69646. +{
  69647. + cfi_ep_t *ep;
  69648. + uint8_t addr;
  69649. + ddma_align_buffer_setup_t *palignval;
  69650. +
  69651. + palignval = (ddma_align_buffer_setup_t *) buf;
  69652. + addr = palignval->bEndpointAddress;
  69653. +
  69654. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  69655. +
  69656. + if (NULL == ep) {
  69657. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  69658. + __func__, addr);
  69659. + return -DWC_E_INVALID;
  69660. + }
  69661. +
  69662. + ep->ep->dwc_ep.buff_mode = BM_ALIGN;
  69663. + dwc_memcpy(ep->bm_align, palignval, sizeof(ddma_align_buffer_setup_t));
  69664. +
  69665. + return 0;
  69666. +}
  69667. +
  69668. +/**
  69669. + * This function sets a new value for the Concatenation buffer setup.
  69670. + */
  69671. +static int cfi_ep_set_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  69672. +{
  69673. + uint8_t addr;
  69674. + cfi_ep_t *ep;
  69675. + struct _ddma_concat_buffer_setup_hdr *pConcatValHdr;
  69676. + uint16_t *pVals;
  69677. + uint32_t desccount;
  69678. + int i;
  69679. + uint16_t mps;
  69680. +
  69681. + pConcatValHdr = (struct _ddma_concat_buffer_setup_hdr *)buf;
  69682. + desccount = (uint32_t) pConcatValHdr->bDescCount;
  69683. + pVals = (uint16_t *) (buf + BS_CONCAT_VAL_HDR_LEN);
  69684. +
  69685. + /* Check the DMA descriptor count */
  69686. + if (desccount > MAX_DMA_DESCS_PER_EP) {
  69687. + CFI_INFO("%s: Maximum DMA Descriptor count should be %d\n",
  69688. + __func__, MAX_DMA_DESCS_PER_EP);
  69689. + return -DWC_E_INVALID;
  69690. + }
  69691. +
  69692. + addr = pConcatValHdr->bEndpointAddress;
  69693. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  69694. + if (NULL == ep) {
  69695. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  69696. + __func__, addr);
  69697. + return -DWC_E_INVALID;
  69698. + }
  69699. +
  69700. + mps = UGETW(ep->ep->desc->wMaxPacketSize);
  69701. +
  69702. +#if 0
  69703. + for (i = 0; i < desccount; i++) {
  69704. + CFI_INFO("%s: wTxSize[%d]=0x%04x\n", __func__, i, pVals[i]);
  69705. + }
  69706. + CFI_INFO("%s: epname=%s; mps=%d\n", __func__, ep->ep->ep.name, mps);
  69707. +#endif
  69708. +
  69709. + /* Check the wTxSizes to be less than or equal to the mps */
  69710. + for (i = 0; i < desccount; i++) {
  69711. + if (pVals[i] > mps) {
  69712. + CFI_INFO
  69713. + ("%s: ERROR - the wTxSize[%d] should be <= MPS (wTxSize=%d)\n",
  69714. + __func__, i, pVals[i]);
  69715. + return -DWC_E_INVALID;
  69716. + }
  69717. + }
  69718. +
  69719. + ep->ep->dwc_ep.buff_mode = BM_CONCAT;
  69720. + dwc_memcpy(ep->bm_concat, pConcatValHdr, BS_CONCAT_VAL_HDR_LEN);
  69721. +
  69722. + /* Free the previously allocated storage for the wTxBytes */
  69723. + if (ep->bm_concat->wTxBytes) {
  69724. + DWC_FREE(ep->bm_concat->wTxBytes);
  69725. + }
  69726. +
  69727. + /* Allocate a new storage for the wTxBytes field */
  69728. + ep->bm_concat->wTxBytes =
  69729. + DWC_ALLOC(sizeof(uint16_t) * pConcatValHdr->bDescCount);
  69730. + if (NULL == ep->bm_concat->wTxBytes) {
  69731. + CFI_INFO("%s: Unable to allocate memory\n", __func__);
  69732. + return -DWC_E_NO_MEMORY;
  69733. + }
  69734. +
  69735. + /* Copy the new values into the wTxBytes filed */
  69736. + dwc_memcpy(ep->bm_concat->wTxBytes, buf + BS_CONCAT_VAL_HDR_LEN,
  69737. + sizeof(uint16_t) * pConcatValHdr->bDescCount);
  69738. +
  69739. + return 0;
  69740. +}
  69741. +
  69742. +/**
  69743. + * This function calculates the total of all FIFO sizes
  69744. + *
  69745. + * @param core_if Programming view of DWC_otg controller
  69746. + *
  69747. + * @return The total of data FIFO sizes.
  69748. + *
  69749. + */
  69750. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if)
  69751. +{
  69752. + dwc_otg_core_params_t *params = core_if->core_params;
  69753. + uint16_t dfifo_total = 0;
  69754. + int i;
  69755. +
  69756. + /* The shared RxFIFO size */
  69757. + dfifo_total =
  69758. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  69759. +
  69760. + /* Add up each TxFIFO size to the total */
  69761. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  69762. + dfifo_total += params->dev_tx_fifo_size[i];
  69763. + }
  69764. +
  69765. + return dfifo_total;
  69766. +}
  69767. +
  69768. +/**
  69769. + * This function returns Rx FIFO size
  69770. + *
  69771. + * @param core_if Programming view of DWC_otg controller
  69772. + *
  69773. + * @return The total of data FIFO sizes.
  69774. + *
  69775. + */
  69776. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue)
  69777. +{
  69778. + switch (wValue >> 8) {
  69779. + case 0:
  69780. + return (core_if->pwron_rxfsiz <
  69781. + 32768) ? core_if->pwron_rxfsiz : 32768;
  69782. + break;
  69783. + case 1:
  69784. + return core_if->core_params->dev_rx_fifo_size;
  69785. + break;
  69786. + default:
  69787. + return -DWC_E_INVALID;
  69788. + break;
  69789. + }
  69790. +}
  69791. +
  69792. +/**
  69793. + * This function returns Tx FIFO size for IN EP
  69794. + *
  69795. + * @param core_if Programming view of DWC_otg controller
  69796. + *
  69797. + * @return The total of data FIFO sizes.
  69798. + *
  69799. + */
  69800. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue)
  69801. +{
  69802. + dwc_otg_pcd_ep_t *ep;
  69803. +
  69804. + ep = get_ep_by_addr(pcd, wValue & 0xff);
  69805. +
  69806. + if (NULL == ep) {
  69807. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  69808. + __func__, wValue & 0xff);
  69809. + return -DWC_E_INVALID;
  69810. + }
  69811. +
  69812. + if (!ep->dwc_ep.is_in) {
  69813. + CFI_INFO
  69814. + ("%s: No Tx FIFO assingned to the Out endpoint addr=0x%02x\n",
  69815. + __func__, wValue & 0xff);
  69816. + return -DWC_E_INVALID;
  69817. + }
  69818. +
  69819. + switch (wValue >> 8) {
  69820. + case 0:
  69821. + return (GET_CORE_IF(pcd)->pwron_txfsiz
  69822. + [ep->dwc_ep.tx_fifo_num - 1] <
  69823. + 768) ? GET_CORE_IF(pcd)->pwron_txfsiz[ep->
  69824. + dwc_ep.tx_fifo_num
  69825. + - 1] : 32768;
  69826. + break;
  69827. + case 1:
  69828. + return GET_CORE_IF(pcd)->core_params->
  69829. + dev_tx_fifo_size[ep->dwc_ep.num - 1];
  69830. + break;
  69831. + default:
  69832. + return -DWC_E_INVALID;
  69833. + break;
  69834. + }
  69835. +}
  69836. +
  69837. +/**
  69838. + * This function checks if the submitted combination of
  69839. + * device mode FIFO sizes is possible or not.
  69840. + *
  69841. + * @param core_if Programming view of DWC_otg controller
  69842. + *
  69843. + * @return 1 if possible, 0 otherwise.
  69844. + *
  69845. + */
  69846. +static uint8_t check_fifo_sizes(dwc_otg_core_if_t * core_if)
  69847. +{
  69848. + uint16_t dfifo_actual = 0;
  69849. + dwc_otg_core_params_t *params = core_if->core_params;
  69850. + uint16_t start_addr = 0;
  69851. + int i;
  69852. +
  69853. + dfifo_actual =
  69854. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  69855. +
  69856. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  69857. + dfifo_actual += params->dev_tx_fifo_size[i];
  69858. + }
  69859. +
  69860. + if (dfifo_actual > core_if->total_fifo_size) {
  69861. + return 0;
  69862. + }
  69863. +
  69864. + if (params->dev_rx_fifo_size > 32768 || params->dev_rx_fifo_size < 16)
  69865. + return 0;
  69866. +
  69867. + if (params->dev_nperio_tx_fifo_size > 32768
  69868. + || params->dev_nperio_tx_fifo_size < 16)
  69869. + return 0;
  69870. +
  69871. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  69872. +
  69873. + if (params->dev_tx_fifo_size[i] > 768
  69874. + || params->dev_tx_fifo_size[i] < 4)
  69875. + return 0;
  69876. + }
  69877. +
  69878. + if (params->dev_rx_fifo_size > core_if->pwron_rxfsiz)
  69879. + return 0;
  69880. + start_addr = params->dev_rx_fifo_size;
  69881. +
  69882. + if (params->dev_nperio_tx_fifo_size > core_if->pwron_gnptxfsiz)
  69883. + return 0;
  69884. + start_addr += params->dev_nperio_tx_fifo_size;
  69885. +
  69886. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  69887. +
  69888. + if (params->dev_tx_fifo_size[i] > core_if->pwron_txfsiz[i])
  69889. + return 0;
  69890. + start_addr += params->dev_tx_fifo_size[i];
  69891. + }
  69892. +
  69893. + return 1;
  69894. +}
  69895. +
  69896. +/**
  69897. + * This function resizes Device mode FIFOs
  69898. + *
  69899. + * @param core_if Programming view of DWC_otg controller
  69900. + *
  69901. + * @return 1 if successful, 0 otherwise
  69902. + *
  69903. + */
  69904. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if)
  69905. +{
  69906. + int i = 0;
  69907. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  69908. + dwc_otg_core_params_t *params = core_if->core_params;
  69909. + uint32_t rx_fifo_size;
  69910. + fifosize_data_t nptxfifosize;
  69911. + fifosize_data_t txfifosize[15];
  69912. +
  69913. + uint32_t rx_fsz_bak;
  69914. + uint32_t nptxfsz_bak;
  69915. + uint32_t txfsz_bak[15];
  69916. +
  69917. + uint16_t start_address;
  69918. + uint8_t retval = 1;
  69919. +
  69920. + if (!check_fifo_sizes(core_if)) {
  69921. + return 0;
  69922. + }
  69923. +
  69924. + /* Configure data FIFO sizes */
  69925. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  69926. + rx_fsz_bak = DWC_READ_REG32(&global_regs->grxfsiz);
  69927. + rx_fifo_size = params->dev_rx_fifo_size;
  69928. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  69929. +
  69930. + /*
  69931. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  69932. + * Indexes of the FIFO size module parameters in the
  69933. + * dev_tx_fifo_size array and the FIFO size registers in
  69934. + * the dtxfsiz array run from 0 to 14.
  69935. + */
  69936. +
  69937. + /* Non-periodic Tx FIFO */
  69938. + nptxfsz_bak = DWC_READ_REG32(&global_regs->gnptxfsiz);
  69939. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  69940. + start_address = params->dev_rx_fifo_size;
  69941. + nptxfifosize.b.startaddr = start_address;
  69942. +
  69943. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  69944. +
  69945. + start_address += nptxfifosize.b.depth;
  69946. +
  69947. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  69948. + txfsz_bak[i] = DWC_READ_REG32(&global_regs->dtxfsiz[i]);
  69949. +
  69950. + txfifosize[i].b.depth = params->dev_tx_fifo_size[i];
  69951. + txfifosize[i].b.startaddr = start_address;
  69952. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  69953. + txfifosize[i].d32);
  69954. +
  69955. + start_address += txfifosize[i].b.depth;
  69956. + }
  69957. +
  69958. + /** Check if register values are set correctly */
  69959. + if (rx_fifo_size != DWC_READ_REG32(&global_regs->grxfsiz)) {
  69960. + retval = 0;
  69961. + }
  69962. +
  69963. + if (nptxfifosize.d32 != DWC_READ_REG32(&global_regs->gnptxfsiz)) {
  69964. + retval = 0;
  69965. + }
  69966. +
  69967. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  69968. + if (txfifosize[i].d32 !=
  69969. + DWC_READ_REG32(&global_regs->dtxfsiz[i])) {
  69970. + retval = 0;
  69971. + }
  69972. + }
  69973. +
  69974. + /** If register values are not set correctly, reset old values */
  69975. + if (retval == 0) {
  69976. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fsz_bak);
  69977. +
  69978. + /* Non-periodic Tx FIFO */
  69979. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfsz_bak);
  69980. +
  69981. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  69982. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  69983. + txfsz_bak[i]);
  69984. + }
  69985. + }
  69986. + } else {
  69987. + return 0;
  69988. + }
  69989. +
  69990. + /* Flush the FIFOs */
  69991. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  69992. + dwc_otg_flush_rx_fifo(core_if);
  69993. +
  69994. + return retval;
  69995. +}
  69996. +
  69997. +/**
  69998. + * This function sets a new value for the buffer Alignment setup.
  69999. + */
  70000. +static int cfi_ep_set_tx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  70001. +{
  70002. + int retval;
  70003. + uint32_t fsiz;
  70004. + uint16_t size;
  70005. + uint16_t ep_addr;
  70006. + dwc_otg_pcd_ep_t *ep;
  70007. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  70008. + tx_fifo_size_setup_t *ptxfifoval;
  70009. +
  70010. + ptxfifoval = (tx_fifo_size_setup_t *) buf;
  70011. + ep_addr = ptxfifoval->bEndpointAddress;
  70012. + size = ptxfifoval->wDepth;
  70013. +
  70014. + ep = get_ep_by_addr(pcd, ep_addr);
  70015. +
  70016. + CFI_INFO
  70017. + ("%s: Set Tx FIFO size: endpoint addr=0x%02x, depth=%d, FIFO Num=%d\n",
  70018. + __func__, ep_addr, size, ep->dwc_ep.tx_fifo_num);
  70019. +
  70020. + if (NULL == ep) {
  70021. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  70022. + __func__, ep_addr);
  70023. + return -DWC_E_INVALID;
  70024. + }
  70025. +
  70026. + fsiz = params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1];
  70027. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = size;
  70028. +
  70029. + if (resize_fifos(GET_CORE_IF(pcd))) {
  70030. + retval = 0;
  70031. + } else {
  70032. + CFI_INFO
  70033. + ("%s: Error setting the feature Tx FIFO Size for EP%d\n",
  70034. + __func__, ep_addr);
  70035. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = fsiz;
  70036. + retval = -DWC_E_INVALID;
  70037. + }
  70038. +
  70039. + return retval;
  70040. +}
  70041. +
  70042. +/**
  70043. + * This function sets a new value for the buffer Alignment setup.
  70044. + */
  70045. +static int cfi_set_rx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  70046. +{
  70047. + int retval;
  70048. + uint32_t fsiz;
  70049. + uint16_t size;
  70050. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  70051. + rx_fifo_size_setup_t *prxfifoval;
  70052. +
  70053. + prxfifoval = (rx_fifo_size_setup_t *) buf;
  70054. + size = prxfifoval->wDepth;
  70055. +
  70056. + fsiz = params->dev_rx_fifo_size;
  70057. + params->dev_rx_fifo_size = size;
  70058. +
  70059. + if (resize_fifos(GET_CORE_IF(pcd))) {
  70060. + retval = 0;
  70061. + } else {
  70062. + CFI_INFO("%s: Error setting the feature Rx FIFO Size\n",
  70063. + __func__);
  70064. + params->dev_rx_fifo_size = fsiz;
  70065. + retval = -DWC_E_INVALID;
  70066. + }
  70067. +
  70068. + return retval;
  70069. +}
  70070. +
  70071. +/**
  70072. + * This function reads the SG of an EP's buffer setup into the buffer buf
  70073. + */
  70074. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  70075. + struct cfi_usb_ctrlrequest *req)
  70076. +{
  70077. + int retval = -DWC_E_INVALID;
  70078. + uint8_t addr;
  70079. + cfi_ep_t *ep;
  70080. +
  70081. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  70082. + addr = req->wValue & 0xFF;
  70083. + if (addr == 0) /* The address should be non-zero */
  70084. + return retval;
  70085. +
  70086. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  70087. + if (NULL == ep) {
  70088. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  70089. + __func__, addr);
  70090. + return retval;
  70091. + }
  70092. +
  70093. + dwc_memcpy(buf, ep->bm_sg, BS_SG_VAL_DESC_LEN);
  70094. + retval = BS_SG_VAL_DESC_LEN;
  70095. + return retval;
  70096. +}
  70097. +
  70098. +/**
  70099. + * This function reads the Concatenation value of an EP's buffer mode into
  70100. + * the buffer buf
  70101. + */
  70102. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  70103. + struct cfi_usb_ctrlrequest *req)
  70104. +{
  70105. + int retval = -DWC_E_INVALID;
  70106. + uint8_t addr;
  70107. + cfi_ep_t *ep;
  70108. + uint8_t desc_count;
  70109. +
  70110. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  70111. + addr = req->wValue & 0xFF;
  70112. + if (addr == 0) /* The address should be non-zero */
  70113. + return retval;
  70114. +
  70115. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  70116. + if (NULL == ep) {
  70117. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  70118. + __func__, addr);
  70119. + return retval;
  70120. + }
  70121. +
  70122. + /* Copy the header to the buffer */
  70123. + dwc_memcpy(buf, ep->bm_concat, BS_CONCAT_VAL_HDR_LEN);
  70124. + /* Advance the buffer pointer by the header size */
  70125. + buf += BS_CONCAT_VAL_HDR_LEN;
  70126. +
  70127. + desc_count = ep->bm_concat->hdr.bDescCount;
  70128. + /* Copy alll the wTxBytes to the buffer */
  70129. + dwc_memcpy(buf, ep->bm_concat->wTxBytes, sizeof(uid16_t) * desc_count);
  70130. +
  70131. + retval = BS_CONCAT_VAL_HDR_LEN + sizeof(uid16_t) * desc_count;
  70132. + return retval;
  70133. +}
  70134. +
  70135. +/**
  70136. + * This function reads the buffer Alignment value of an EP's buffer mode into
  70137. + * the buffer buf
  70138. + *
  70139. + * @return The total number of bytes copied to the buffer or negative error code.
  70140. + */
  70141. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  70142. + struct cfi_usb_ctrlrequest *req)
  70143. +{
  70144. + int retval = -DWC_E_INVALID;
  70145. + uint8_t addr;
  70146. + cfi_ep_t *ep;
  70147. +
  70148. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  70149. + addr = req->wValue & 0xFF;
  70150. + if (addr == 0) /* The address should be non-zero */
  70151. + return retval;
  70152. +
  70153. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  70154. + if (NULL == ep) {
  70155. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  70156. + __func__, addr);
  70157. + return retval;
  70158. + }
  70159. +
  70160. + dwc_memcpy(buf, ep->bm_align, BS_ALIGN_VAL_HDR_LEN);
  70161. + retval = BS_ALIGN_VAL_HDR_LEN;
  70162. +
  70163. + return retval;
  70164. +}
  70165. +
  70166. +/**
  70167. + * This function sets a new value for the specified feature
  70168. + *
  70169. + * @param pcd A pointer to the PCD object
  70170. + *
  70171. + * @return 0 if successful, negative error code otherwise to stall the DCE.
  70172. + */
  70173. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd)
  70174. +{
  70175. + int retval = -DWC_E_NOT_SUPPORTED;
  70176. + uint16_t wIndex, wValue;
  70177. + uint8_t bRequest;
  70178. + struct dwc_otg_core_if *coreif;
  70179. + cfiobject_t *cfi = pcd->cfi;
  70180. + struct cfi_usb_ctrlrequest *ctrl_req;
  70181. + uint8_t *buf;
  70182. + ctrl_req = &cfi->ctrl_req;
  70183. +
  70184. + buf = pcd->cfi->ctrl_req.data;
  70185. +
  70186. + coreif = GET_CORE_IF(pcd);
  70187. + bRequest = ctrl_req->bRequest;
  70188. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  70189. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  70190. +
  70191. + /* See which feature is to be modified */
  70192. + switch (wIndex) {
  70193. + case FT_ID_DMA_BUFFER_SETUP:
  70194. + /* Modify the feature */
  70195. + if ((retval = cfi_ep_set_sg_val(buf, pcd)) < 0)
  70196. + return retval;
  70197. +
  70198. + /* And send this request to the gadget */
  70199. + cfi->need_gadget_att = 1;
  70200. + break;
  70201. +
  70202. + case FT_ID_DMA_BUFF_ALIGN:
  70203. + if ((retval = cfi_ep_set_alignment_val(buf, pcd)) < 0)
  70204. + return retval;
  70205. + cfi->need_gadget_att = 1;
  70206. + break;
  70207. +
  70208. + case FT_ID_DMA_CONCAT_SETUP:
  70209. + /* Modify the feature */
  70210. + if ((retval = cfi_ep_set_concat_val(buf, pcd)) < 0)
  70211. + return retval;
  70212. + cfi->need_gadget_att = 1;
  70213. + break;
  70214. +
  70215. + case FT_ID_DMA_CIRCULAR:
  70216. + CFI_INFO("FT_ID_DMA_CIRCULAR\n");
  70217. + break;
  70218. +
  70219. + case FT_ID_THRESHOLD_SETUP:
  70220. + CFI_INFO("FT_ID_THRESHOLD_SETUP\n");
  70221. + break;
  70222. +
  70223. + case FT_ID_DFIFO_DEPTH:
  70224. + CFI_INFO("FT_ID_DFIFO_DEPTH\n");
  70225. + break;
  70226. +
  70227. + case FT_ID_TX_FIFO_DEPTH:
  70228. + CFI_INFO("FT_ID_TX_FIFO_DEPTH\n");
  70229. + if ((retval = cfi_ep_set_tx_fifo_val(buf, pcd)) < 0)
  70230. + return retval;
  70231. + cfi->need_gadget_att = 0;
  70232. + break;
  70233. +
  70234. + case FT_ID_RX_FIFO_DEPTH:
  70235. + CFI_INFO("FT_ID_RX_FIFO_DEPTH\n");
  70236. + if ((retval = cfi_set_rx_fifo_val(buf, pcd)) < 0)
  70237. + return retval;
  70238. + cfi->need_gadget_att = 0;
  70239. + break;
  70240. + }
  70241. +
  70242. + return retval;
  70243. +}
  70244. +
  70245. +#endif //DWC_UTE_CFI
  70246. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_cfi.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h
  70247. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 1970-01-01 01:00:00.000000000 +0100
  70248. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 2015-02-09 04:40:29.000000000 +0100
  70249. @@ -0,0 +1,320 @@
  70250. +/* ==========================================================================
  70251. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  70252. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  70253. + * otherwise expressly agreed to in writing between Synopsys and you.
  70254. + *
  70255. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  70256. + * any End User Software License Agreement or Agreement for Licensed Product
  70257. + * with Synopsys or any supplement thereto. You are permitted to use and
  70258. + * redistribute this Software in source and binary forms, with or without
  70259. + * modification, provided that redistributions of source code must retain this
  70260. + * notice. You may not view, use, disclose, copy or distribute this file or
  70261. + * any information contained herein except pursuant to this license grant from
  70262. + * Synopsys. If you do not agree with this notice, including the disclaimer
  70263. + * below, then you are not authorized to use the Software.
  70264. + *
  70265. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  70266. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  70267. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  70268. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  70269. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  70270. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  70271. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  70272. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  70273. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  70274. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  70275. + * DAMAGE.
  70276. + * ========================================================================== */
  70277. +
  70278. +#if !defined(__DWC_OTG_CFI_H__)
  70279. +#define __DWC_OTG_CFI_H__
  70280. +
  70281. +#include "dwc_otg_pcd.h"
  70282. +#include "dwc_cfi_common.h"
  70283. +
  70284. +/**
  70285. + * @file
  70286. + * This file contains the CFI related OTG PCD specific common constants,
  70287. + * interfaces(functions and macros) and data structures.The CFI Protocol is an
  70288. + * optional interface for internal testing purposes that a DUT may implement to
  70289. + * support testing of configurable features.
  70290. + *
  70291. + */
  70292. +
  70293. +struct dwc_otg_pcd;
  70294. +struct dwc_otg_pcd_ep;
  70295. +
  70296. +/** OTG CFI Features (properties) ID constants */
  70297. +/** This is a request for all Core Features */
  70298. +#define FT_ID_DMA_MODE 0x0001
  70299. +#define FT_ID_DMA_BUFFER_SETUP 0x0002
  70300. +#define FT_ID_DMA_BUFF_ALIGN 0x0003
  70301. +#define FT_ID_DMA_CONCAT_SETUP 0x0004
  70302. +#define FT_ID_DMA_CIRCULAR 0x0005
  70303. +#define FT_ID_THRESHOLD_SETUP 0x0006
  70304. +#define FT_ID_DFIFO_DEPTH 0x0007
  70305. +#define FT_ID_TX_FIFO_DEPTH 0x0008
  70306. +#define FT_ID_RX_FIFO_DEPTH 0x0009
  70307. +
  70308. +/**********************************************************/
  70309. +#define CFI_INFO_DEF
  70310. +
  70311. +#ifdef CFI_INFO_DEF
  70312. +#define CFI_INFO(fmt...) DWC_PRINTF("CFI: " fmt);
  70313. +#else
  70314. +#define CFI_INFO(fmt...)
  70315. +#endif
  70316. +
  70317. +#define min(x,y) ({ \
  70318. + x < y ? x : y; })
  70319. +
  70320. +#define max(x,y) ({ \
  70321. + x > y ? x : y; })
  70322. +
  70323. +/**
  70324. + * Descriptor DMA SG Buffer setup structure (SG buffer). This structure is
  70325. + * also used for setting up a buffer for Circular DDMA.
  70326. + */
  70327. +struct _ddma_sg_buffer_setup {
  70328. +#define BS_SG_VAL_DESC_LEN 6
  70329. + /* The OUT EP address */
  70330. + uint8_t bOutEndpointAddress;
  70331. + /* The IN EP address */
  70332. + uint8_t bInEndpointAddress;
  70333. + /* Number of bytes to put between transfer segments (must be DWORD boundaries) */
  70334. + uint8_t bOffset;
  70335. + /* The number of transfer segments (a DMA descriptors per each segment) */
  70336. + uint8_t bCount;
  70337. + /* Size (in byte) of each transfer segment */
  70338. + uint16_t wSize;
  70339. +} __attribute__ ((packed));
  70340. +typedef struct _ddma_sg_buffer_setup ddma_sg_buffer_setup_t;
  70341. +
  70342. +/** Descriptor DMA Concatenation Buffer setup structure */
  70343. +struct _ddma_concat_buffer_setup_hdr {
  70344. +#define BS_CONCAT_VAL_HDR_LEN 4
  70345. + /* The endpoint for which the buffer is to be set up */
  70346. + uint8_t bEndpointAddress;
  70347. + /* The count of descriptors to be used */
  70348. + uint8_t bDescCount;
  70349. + /* The total size of the transfer */
  70350. + uint16_t wSize;
  70351. +} __attribute__ ((packed));
  70352. +typedef struct _ddma_concat_buffer_setup_hdr ddma_concat_buffer_setup_hdr_t;
  70353. +
  70354. +/** Descriptor DMA Concatenation Buffer setup structure */
  70355. +struct _ddma_concat_buffer_setup {
  70356. + /* The SG header */
  70357. + ddma_concat_buffer_setup_hdr_t hdr;
  70358. +
  70359. + /* The XFER sizes pointer (allocated dynamically) */
  70360. + uint16_t *wTxBytes;
  70361. +} __attribute__ ((packed));
  70362. +typedef struct _ddma_concat_buffer_setup ddma_concat_buffer_setup_t;
  70363. +
  70364. +/** Descriptor DMA Alignment Buffer setup structure */
  70365. +struct _ddma_align_buffer_setup {
  70366. +#define BS_ALIGN_VAL_HDR_LEN 2
  70367. + uint8_t bEndpointAddress;
  70368. + uint8_t bAlign;
  70369. +} __attribute__ ((packed));
  70370. +typedef struct _ddma_align_buffer_setup ddma_align_buffer_setup_t;
  70371. +
  70372. +/** Transmit FIFO Size setup structure */
  70373. +struct _tx_fifo_size_setup {
  70374. + uint8_t bEndpointAddress;
  70375. + uint16_t wDepth;
  70376. +} __attribute__ ((packed));
  70377. +typedef struct _tx_fifo_size_setup tx_fifo_size_setup_t;
  70378. +
  70379. +/** Transmit FIFO Size setup structure */
  70380. +struct _rx_fifo_size_setup {
  70381. + uint16_t wDepth;
  70382. +} __attribute__ ((packed));
  70383. +typedef struct _rx_fifo_size_setup rx_fifo_size_setup_t;
  70384. +
  70385. +/**
  70386. + * struct cfi_usb_ctrlrequest - the CFI implementation of the struct usb_ctrlrequest
  70387. + * This structure encapsulates the standard usb_ctrlrequest and adds a pointer
  70388. + * to the data returned in the data stage of a 3-stage Control Write requests.
  70389. + */
  70390. +struct cfi_usb_ctrlrequest {
  70391. + uint8_t bRequestType;
  70392. + uint8_t bRequest;
  70393. + uint16_t wValue;
  70394. + uint16_t wIndex;
  70395. + uint16_t wLength;
  70396. + uint8_t *data;
  70397. +} UPACKED;
  70398. +
  70399. +/*---------------------------------------------------------------------------*/
  70400. +
  70401. +/**
  70402. + * The CFI wrapper of the enabled and activated dwc_otg_pcd_ep structures.
  70403. + * This structure is used to store the buffer setup data for any
  70404. + * enabled endpoint in the PCD.
  70405. + */
  70406. +struct cfi_ep {
  70407. + /* Entry for the list container */
  70408. + dwc_list_link_t lh;
  70409. + /* Pointer to the active PCD endpoint structure */
  70410. + struct dwc_otg_pcd_ep *ep;
  70411. + /* The last descriptor in the chain of DMA descriptors of the endpoint */
  70412. + struct dwc_otg_dma_desc *dma_desc_last;
  70413. + /* The SG feature value */
  70414. + ddma_sg_buffer_setup_t *bm_sg;
  70415. + /* The Circular feature value */
  70416. + ddma_sg_buffer_setup_t *bm_circ;
  70417. + /* The Concatenation feature value */
  70418. + ddma_concat_buffer_setup_t *bm_concat;
  70419. + /* The Alignment feature value */
  70420. + ddma_align_buffer_setup_t *bm_align;
  70421. + /* XFER length */
  70422. + uint32_t xfer_len;
  70423. + /*
  70424. + * Count of DMA descriptors currently used.
  70425. + * The total should not exceed the MAX_DMA_DESCS_PER_EP value
  70426. + * defined in the dwc_otg_cil.h
  70427. + */
  70428. + uint32_t desc_count;
  70429. +};
  70430. +typedef struct cfi_ep cfi_ep_t;
  70431. +
  70432. +typedef struct cfi_dma_buff {
  70433. +#define CFI_IN_BUF_LEN 1024
  70434. +#define CFI_OUT_BUF_LEN 1024
  70435. + dma_addr_t addr;
  70436. + uint8_t *buf;
  70437. +} cfi_dma_buff_t;
  70438. +
  70439. +struct cfiobject;
  70440. +
  70441. +/**
  70442. + * This is the interface for the CFI operations.
  70443. + *
  70444. + * @param ep_enable Called when any endpoint is enabled and activated.
  70445. + * @param release Called when the CFI object is released and it needs to correctly
  70446. + * deallocate the dynamic memory
  70447. + * @param ctrl_write_complete Called when the data stage of the request is complete
  70448. + */
  70449. +typedef struct cfi_ops {
  70450. + int (*ep_enable) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  70451. + struct dwc_otg_pcd_ep * ep);
  70452. + void *(*ep_alloc_buf) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  70453. + struct dwc_otg_pcd_ep * ep, dma_addr_t * dma,
  70454. + unsigned size, gfp_t flags);
  70455. + void (*release) (struct cfiobject * cfi);
  70456. + int (*ctrl_write_complete) (struct cfiobject * cfi,
  70457. + struct dwc_otg_pcd * pcd);
  70458. + void (*build_descriptors) (struct cfiobject * cfi,
  70459. + struct dwc_otg_pcd * pcd,
  70460. + struct dwc_otg_pcd_ep * ep,
  70461. + dwc_otg_pcd_request_t * req);
  70462. +} cfi_ops_t;
  70463. +
  70464. +struct cfiobject {
  70465. + cfi_ops_t ops;
  70466. + struct dwc_otg_pcd *pcd;
  70467. + struct usb_gadget *gadget;
  70468. +
  70469. + /* Buffers used to send/receive CFI-related request data */
  70470. + cfi_dma_buff_t buf_in;
  70471. + cfi_dma_buff_t buf_out;
  70472. +
  70473. + /* CFI specific Control request wrapper */
  70474. + struct cfi_usb_ctrlrequest ctrl_req;
  70475. +
  70476. + /* The list of active EP's in the PCD of type cfi_ep_t */
  70477. + dwc_list_link_t active_eps;
  70478. +
  70479. + /* This flag shall control the propagation of a specific request
  70480. + * to the gadget's processing routines.
  70481. + * 0 - no gadget handling
  70482. + * 1 - the gadget needs to know about this request (w/o completing a status
  70483. + * phase - just return a 0 to the _setup callback)
  70484. + */
  70485. + uint8_t need_gadget_att;
  70486. +
  70487. + /* Flag indicating whether the status IN phase needs to be
  70488. + * completed by the PCD
  70489. + */
  70490. + uint8_t need_status_in_complete;
  70491. +};
  70492. +typedef struct cfiobject cfiobject_t;
  70493. +
  70494. +#define DUMP_MSG
  70495. +
  70496. +#if defined(DUMP_MSG)
  70497. +static inline void dump_msg(const u8 * buf, unsigned int length)
  70498. +{
  70499. + unsigned int start, num, i;
  70500. + char line[52], *p;
  70501. +
  70502. + if (length >= 512)
  70503. + return;
  70504. +
  70505. + start = 0;
  70506. + while (length > 0) {
  70507. + num = min(length, 16u);
  70508. + p = line;
  70509. + for (i = 0; i < num; ++i) {
  70510. + if (i == 8)
  70511. + *p++ = ' ';
  70512. + DWC_SPRINTF(p, " %02x", buf[i]);
  70513. + p += 3;
  70514. + }
  70515. + *p = 0;
  70516. + DWC_DEBUG("%6x: %s\n", start, line);
  70517. + buf += num;
  70518. + start += num;
  70519. + length -= num;
  70520. + }
  70521. +}
  70522. +#else
  70523. +static inline void dump_msg(const u8 * buf, unsigned int length)
  70524. +{
  70525. +}
  70526. +#endif
  70527. +
  70528. +/**
  70529. + * This function returns a pointer to cfi_ep_t object with the addr address.
  70530. + */
  70531. +static inline struct cfi_ep *get_cfi_ep_by_addr(struct cfiobject *cfi,
  70532. + uint8_t addr)
  70533. +{
  70534. + struct cfi_ep *pcfiep;
  70535. + dwc_list_link_t *tmp;
  70536. +
  70537. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  70538. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  70539. +
  70540. + if (pcfiep->ep->desc->bEndpointAddress == addr) {
  70541. + return pcfiep;
  70542. + }
  70543. + }
  70544. +
  70545. + return NULL;
  70546. +}
  70547. +
  70548. +/**
  70549. + * This function returns a pointer to cfi_ep_t object that matches
  70550. + * the dwc_otg_pcd_ep object.
  70551. + */
  70552. +static inline struct cfi_ep *get_cfi_ep_by_pcd_ep(struct cfiobject *cfi,
  70553. + struct dwc_otg_pcd_ep *ep)
  70554. +{
  70555. + struct cfi_ep *pcfiep = NULL;
  70556. + dwc_list_link_t *tmp;
  70557. +
  70558. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  70559. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  70560. + if (pcfiep->ep == ep) {
  70561. + return pcfiep;
  70562. + }
  70563. + }
  70564. + return NULL;
  70565. +}
  70566. +
  70567. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl);
  70568. +
  70569. +#endif /* (__DWC_OTG_CFI_H__) */
  70570. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_cil.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.c
  70571. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_cil.c 1970-01-01 01:00:00.000000000 +0100
  70572. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.c 2015-02-09 04:40:29.000000000 +0100
  70573. @@ -0,0 +1,7141 @@
  70574. +/* ==========================================================================
  70575. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
  70576. + * $Revision: #191 $
  70577. + * $Date: 2012/08/10 $
  70578. + * $Change: 2047372 $
  70579. + *
  70580. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  70581. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  70582. + * otherwise expressly agreed to in writing between Synopsys and you.
  70583. + *
  70584. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  70585. + * any End User Software License Agreement or Agreement for Licensed Product
  70586. + * with Synopsys or any supplement thereto. You are permitted to use and
  70587. + * redistribute this Software in source and binary forms, with or without
  70588. + * modification, provided that redistributions of source code must retain this
  70589. + * notice. You may not view, use, disclose, copy or distribute this file or
  70590. + * any information contained herein except pursuant to this license grant from
  70591. + * Synopsys. If you do not agree with this notice, including the disclaimer
  70592. + * below, then you are not authorized to use the Software.
  70593. + *
  70594. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  70595. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  70596. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  70597. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  70598. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  70599. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  70600. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  70601. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  70602. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  70603. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  70604. + * DAMAGE.
  70605. + * ========================================================================== */
  70606. +
  70607. +/** @file
  70608. + *
  70609. + * The Core Interface Layer provides basic services for accessing and
  70610. + * managing the DWC_otg hardware. These services are used by both the
  70611. + * Host Controller Driver and the Peripheral Controller Driver.
  70612. + *
  70613. + * The CIL manages the memory map for the core so that the HCD and PCD
  70614. + * don't have to do this separately. It also handles basic tasks like
  70615. + * reading/writing the registers and data FIFOs in the controller.
  70616. + * Some of the data access functions provide encapsulation of several
  70617. + * operations required to perform a task, such as writing multiple
  70618. + * registers to start a transfer. Finally, the CIL performs basic
  70619. + * services that are not specific to either the host or device modes
  70620. + * of operation. These services include management of the OTG Host
  70621. + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
  70622. + * Diagnostic API is also provided to allow testing of the controller
  70623. + * hardware.
  70624. + *
  70625. + * The Core Interface Layer has the following requirements:
  70626. + * - Provides basic controller operations.
  70627. + * - Minimal use of OS services.
  70628. + * - The OS services used will be abstracted by using inline functions
  70629. + * or macros.
  70630. + *
  70631. + */
  70632. +
  70633. +#include "dwc_os.h"
  70634. +#include "dwc_otg_regs.h"
  70635. +#include "dwc_otg_cil.h"
  70636. +
  70637. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if);
  70638. +
  70639. +/**
  70640. + * This function is called to initialize the DWC_otg CSR data
  70641. + * structures. The register addresses in the device and host
  70642. + * structures are initialized from the base address supplied by the
  70643. + * caller. The calling function must make the OS calls to get the
  70644. + * base address of the DWC_otg controller registers. The core_params
  70645. + * argument holds the parameters that specify how the core should be
  70646. + * configured.
  70647. + *
  70648. + * @param reg_base_addr Base address of DWC_otg core registers
  70649. + *
  70650. + */
  70651. +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * reg_base_addr)
  70652. +{
  70653. + dwc_otg_core_if_t *core_if = 0;
  70654. + dwc_otg_dev_if_t *dev_if = 0;
  70655. + dwc_otg_host_if_t *host_if = 0;
  70656. + uint8_t *reg_base = (uint8_t *) reg_base_addr;
  70657. + int i = 0;
  70658. +
  70659. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, reg_base_addr);
  70660. +
  70661. + core_if = DWC_ALLOC(sizeof(dwc_otg_core_if_t));
  70662. +
  70663. + if (core_if == NULL) {
  70664. + DWC_DEBUGPL(DBG_CIL,
  70665. + "Allocation of dwc_otg_core_if_t failed\n");
  70666. + return 0;
  70667. + }
  70668. + core_if->core_global_regs = (dwc_otg_core_global_regs_t *) reg_base;
  70669. +
  70670. + /*
  70671. + * Allocate the Device Mode structures.
  70672. + */
  70673. + dev_if = DWC_ALLOC(sizeof(dwc_otg_dev_if_t));
  70674. +
  70675. + if (dev_if == NULL) {
  70676. + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
  70677. + DWC_FREE(core_if);
  70678. + return 0;
  70679. + }
  70680. +
  70681. + dev_if->dev_global_regs =
  70682. + (dwc_otg_device_global_regs_t *) (reg_base +
  70683. + DWC_DEV_GLOBAL_REG_OFFSET);
  70684. +
  70685. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  70686. + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
  70687. + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
  70688. + (i * DWC_EP_REG_OFFSET));
  70689. +
  70690. + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
  70691. + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
  70692. + (i * DWC_EP_REG_OFFSET));
  70693. + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
  70694. + i, &dev_if->in_ep_regs[i]->diepctl);
  70695. + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
  70696. + i, &dev_if->out_ep_regs[i]->doepctl);
  70697. + }
  70698. +
  70699. + dev_if->speed = 0; // unknown
  70700. +
  70701. + core_if->dev_if = dev_if;
  70702. +
  70703. + /*
  70704. + * Allocate the Host Mode structures.
  70705. + */
  70706. + host_if = DWC_ALLOC(sizeof(dwc_otg_host_if_t));
  70707. +
  70708. + if (host_if == NULL) {
  70709. + DWC_DEBUGPL(DBG_CIL,
  70710. + "Allocation of dwc_otg_host_if_t failed\n");
  70711. + DWC_FREE(dev_if);
  70712. + DWC_FREE(core_if);
  70713. + return 0;
  70714. + }
  70715. +
  70716. + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
  70717. + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
  70718. +
  70719. + host_if->hprt0 =
  70720. + (uint32_t *) (reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
  70721. +
  70722. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  70723. + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
  70724. + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
  70725. + (i * DWC_OTG_CHAN_REGS_OFFSET));
  70726. + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
  70727. + i, &host_if->hc_regs[i]->hcchar);
  70728. + }
  70729. +
  70730. + host_if->num_host_channels = MAX_EPS_CHANNELS;
  70731. + core_if->host_if = host_if;
  70732. +
  70733. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  70734. + core_if->data_fifo[i] =
  70735. + (uint32_t *) (reg_base + DWC_OTG_DATA_FIFO_OFFSET +
  70736. + (i * DWC_OTG_DATA_FIFO_SIZE));
  70737. + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08lx\n",
  70738. + i, (unsigned long)core_if->data_fifo[i]);
  70739. + }
  70740. +
  70741. + core_if->pcgcctl = (uint32_t *) (reg_base + DWC_OTG_PCGCCTL_OFFSET);
  70742. +
  70743. + /* Initiate lx_state to L3 disconnected state */
  70744. + core_if->lx_state = DWC_OTG_L3;
  70745. + /*
  70746. + * Store the contents of the hardware configuration registers here for
  70747. + * easy access later.
  70748. + */
  70749. + core_if->hwcfg1.d32 =
  70750. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg1);
  70751. + core_if->hwcfg2.d32 =
  70752. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  70753. + core_if->hwcfg3.d32 =
  70754. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg3);
  70755. + core_if->hwcfg4.d32 =
  70756. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  70757. +
  70758. + /* Force host mode to get HPTXFSIZ exact power on value */
  70759. + {
  70760. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  70761. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  70762. + gusbcfg.b.force_host_mode = 1;
  70763. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  70764. + dwc_mdelay(100);
  70765. + core_if->hptxfsiz.d32 =
  70766. + DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  70767. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  70768. + gusbcfg.b.force_host_mode = 0;
  70769. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  70770. + dwc_mdelay(100);
  70771. + }
  70772. +
  70773. + DWC_DEBUGPL(DBG_CILV, "hwcfg1=%08x\n", core_if->hwcfg1.d32);
  70774. + DWC_DEBUGPL(DBG_CILV, "hwcfg2=%08x\n", core_if->hwcfg2.d32);
  70775. + DWC_DEBUGPL(DBG_CILV, "hwcfg3=%08x\n", core_if->hwcfg3.d32);
  70776. + DWC_DEBUGPL(DBG_CILV, "hwcfg4=%08x\n", core_if->hwcfg4.d32);
  70777. +
  70778. + core_if->hcfg.d32 =
  70779. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  70780. + core_if->dcfg.d32 =
  70781. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  70782. +
  70783. + DWC_DEBUGPL(DBG_CILV, "hcfg=%08x\n", core_if->hcfg.d32);
  70784. + DWC_DEBUGPL(DBG_CILV, "dcfg=%08x\n", core_if->dcfg.d32);
  70785. +
  70786. + DWC_DEBUGPL(DBG_CILV, "op_mode=%0x\n", core_if->hwcfg2.b.op_mode);
  70787. + DWC_DEBUGPL(DBG_CILV, "arch=%0x\n", core_if->hwcfg2.b.architecture);
  70788. + DWC_DEBUGPL(DBG_CILV, "num_dev_ep=%d\n", core_if->hwcfg2.b.num_dev_ep);
  70789. + DWC_DEBUGPL(DBG_CILV, "num_host_chan=%d\n",
  70790. + core_if->hwcfg2.b.num_host_chan);
  70791. + DWC_DEBUGPL(DBG_CILV, "nonperio_tx_q_depth=0x%0x\n",
  70792. + core_if->hwcfg2.b.nonperio_tx_q_depth);
  70793. + DWC_DEBUGPL(DBG_CILV, "host_perio_tx_q_depth=0x%0x\n",
  70794. + core_if->hwcfg2.b.host_perio_tx_q_depth);
  70795. + DWC_DEBUGPL(DBG_CILV, "dev_token_q_depth=0x%0x\n",
  70796. + core_if->hwcfg2.b.dev_token_q_depth);
  70797. +
  70798. + DWC_DEBUGPL(DBG_CILV, "Total FIFO SZ=%d\n",
  70799. + core_if->hwcfg3.b.dfifo_depth);
  70800. + DWC_DEBUGPL(DBG_CILV, "xfer_size_cntr_width=%0x\n",
  70801. + core_if->hwcfg3.b.xfer_size_cntr_width);
  70802. +
  70803. + /*
  70804. + * Set the SRP sucess bit for FS-I2c
  70805. + */
  70806. + core_if->srp_success = 0;
  70807. + core_if->srp_timer_started = 0;
  70808. +
  70809. + /*
  70810. + * Create new workqueue and init works
  70811. + */
  70812. + core_if->wq_otg = DWC_WORKQ_ALLOC("dwc_otg");
  70813. + if (core_if->wq_otg == 0) {
  70814. + DWC_WARN("DWC_WORKQ_ALLOC failed\n");
  70815. + DWC_FREE(host_if);
  70816. + DWC_FREE(dev_if);
  70817. + DWC_FREE(core_if);
  70818. + return 0;
  70819. + }
  70820. +
  70821. + core_if->snpsid = DWC_READ_REG32(&core_if->core_global_regs->gsnpsid);
  70822. +
  70823. + DWC_PRINTF("Core Release: %x.%x%x%x\n",
  70824. + (core_if->snpsid >> 12 & 0xF),
  70825. + (core_if->snpsid >> 8 & 0xF),
  70826. + (core_if->snpsid >> 4 & 0xF), (core_if->snpsid & 0xF));
  70827. +
  70828. + core_if->wkp_timer = DWC_TIMER_ALLOC("Wake Up Timer",
  70829. + w_wakeup_detected, core_if);
  70830. + if (core_if->wkp_timer == 0) {
  70831. + DWC_WARN("DWC_TIMER_ALLOC failed\n");
  70832. + DWC_FREE(host_if);
  70833. + DWC_FREE(dev_if);
  70834. + DWC_WORKQ_FREE(core_if->wq_otg);
  70835. + DWC_FREE(core_if);
  70836. + return 0;
  70837. + }
  70838. +
  70839. + if (dwc_otg_setup_params(core_if)) {
  70840. + DWC_WARN("Error while setting core params\n");
  70841. + }
  70842. +
  70843. + core_if->hibernation_suspend = 0;
  70844. +
  70845. + /** ADP initialization */
  70846. + dwc_otg_adp_init(core_if);
  70847. +
  70848. + return core_if;
  70849. +}
  70850. +
  70851. +/**
  70852. + * This function frees the structures allocated by dwc_otg_cil_init().
  70853. + *
  70854. + * @param core_if The core interface pointer returned from
  70855. + * dwc_otg_cil_init().
  70856. + *
  70857. + */
  70858. +void dwc_otg_cil_remove(dwc_otg_core_if_t * core_if)
  70859. +{
  70860. + dctl_data_t dctl = {.d32 = 0 };
  70861. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  70862. +
  70863. + /* Disable all interrupts */
  70864. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 1, 0);
  70865. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  70866. +
  70867. + dctl.b.sftdiscon = 1;
  70868. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  70869. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0,
  70870. + dctl.d32);
  70871. + }
  70872. +
  70873. + if (core_if->wq_otg) {
  70874. + DWC_WORKQ_WAIT_WORK_DONE(core_if->wq_otg, 500);
  70875. + DWC_WORKQ_FREE(core_if->wq_otg);
  70876. + }
  70877. + if (core_if->dev_if) {
  70878. + DWC_FREE(core_if->dev_if);
  70879. + }
  70880. + if (core_if->host_if) {
  70881. + DWC_FREE(core_if->host_if);
  70882. + }
  70883. +
  70884. + /** Remove ADP Stuff */
  70885. + dwc_otg_adp_remove(core_if);
  70886. + if (core_if->core_params) {
  70887. + DWC_FREE(core_if->core_params);
  70888. + }
  70889. + if (core_if->wkp_timer) {
  70890. + DWC_TIMER_FREE(core_if->wkp_timer);
  70891. + }
  70892. + if (core_if->srp_timer) {
  70893. + DWC_TIMER_FREE(core_if->srp_timer);
  70894. + }
  70895. + DWC_FREE(core_if);
  70896. +}
  70897. +
  70898. +/**
  70899. + * This function enables the controller's Global Interrupt in the AHB Config
  70900. + * register.
  70901. + *
  70902. + * @param core_if Programming view of DWC_otg controller.
  70903. + */
  70904. +void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * core_if)
  70905. +{
  70906. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  70907. + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
  70908. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
  70909. +}
  70910. +
  70911. +/**
  70912. + * This function disables the controller's Global Interrupt in the AHB Config
  70913. + * register.
  70914. + *
  70915. + * @param core_if Programming view of DWC_otg controller.
  70916. + */
  70917. +void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * core_if)
  70918. +{
  70919. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  70920. + ahbcfg.b.glblintrmsk = 1; /* Disable interrupts */
  70921. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  70922. +}
  70923. +
  70924. +/**
  70925. + * This function initializes the commmon interrupts, used in both
  70926. + * device and host modes.
  70927. + *
  70928. + * @param core_if Programming view of the DWC_otg controller
  70929. + *
  70930. + */
  70931. +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t * core_if)
  70932. +{
  70933. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  70934. + gintmsk_data_t intr_mask = {.d32 = 0 };
  70935. +
  70936. + /* Clear any pending OTG Interrupts */
  70937. + DWC_WRITE_REG32(&global_regs->gotgint, 0xFFFFFFFF);
  70938. +
  70939. + /* Clear any pending interrupts */
  70940. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  70941. +
  70942. + /*
  70943. + * Enable the interrupts in the GINTMSK.
  70944. + */
  70945. + intr_mask.b.modemismatch = 1;
  70946. + intr_mask.b.otgintr = 1;
  70947. +
  70948. + if (!core_if->dma_enable) {
  70949. + intr_mask.b.rxstsqlvl = 1;
  70950. + }
  70951. +
  70952. + intr_mask.b.conidstschng = 1;
  70953. + intr_mask.b.wkupintr = 1;
  70954. + intr_mask.b.disconnect = 0;
  70955. + intr_mask.b.usbsuspend = 1;
  70956. + intr_mask.b.sessreqintr = 1;
  70957. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70958. + if (core_if->core_params->lpm_enable) {
  70959. + intr_mask.b.lpmtranrcvd = 1;
  70960. + }
  70961. +#endif
  70962. + DWC_WRITE_REG32(&global_regs->gintmsk, intr_mask.d32);
  70963. +}
  70964. +
  70965. +/*
  70966. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  70967. + * Hibernation. This function is for exiting from Device mode hibernation by
  70968. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  70969. + * @param core_if Programming view of DWC_otg controller.
  70970. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  70971. + * @param reset - indicates whether resume is initiated by Reset.
  70972. + */
  70973. +int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  70974. + int rem_wakeup, int reset)
  70975. +{
  70976. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  70977. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  70978. + dctl_data_t dctl = {.d32 = 0 };
  70979. +
  70980. + int timeout = 2000;
  70981. +
  70982. + if (!core_if->hibernation_suspend) {
  70983. + DWC_PRINTF("Already exited from Hibernation\n");
  70984. + return 1;
  70985. + }
  70986. +
  70987. + DWC_DEBUGPL(DBG_PCD, "%s called\n", __FUNCTION__);
  70988. + /* Switch-on voltage to the core */
  70989. + gpwrdn.b.pwrdnswtch = 1;
  70990. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  70991. + dwc_udelay(10);
  70992. +
  70993. + /* Reset core */
  70994. + gpwrdn.d32 = 0;
  70995. + gpwrdn.b.pwrdnrstn = 1;
  70996. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  70997. + dwc_udelay(10);
  70998. +
  70999. + /* Assert Restore signal */
  71000. + gpwrdn.d32 = 0;
  71001. + gpwrdn.b.restore = 1;
  71002. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  71003. + dwc_udelay(10);
  71004. +
  71005. + /* Disable power clamps */
  71006. + gpwrdn.d32 = 0;
  71007. + gpwrdn.b.pwrdnclmp = 1;
  71008. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71009. +
  71010. + if (rem_wakeup) {
  71011. + dwc_udelay(70);
  71012. + }
  71013. +
  71014. + /* Deassert Reset core */
  71015. + gpwrdn.d32 = 0;
  71016. + gpwrdn.b.pwrdnrstn = 1;
  71017. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  71018. + dwc_udelay(10);
  71019. +
  71020. + /* Disable PMU interrupt */
  71021. + gpwrdn.d32 = 0;
  71022. + gpwrdn.b.pmuintsel = 1;
  71023. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71024. +
  71025. + /* Mask interrupts from gpwrdn */
  71026. + gpwrdn.d32 = 0;
  71027. + gpwrdn.b.connect_det_msk = 1;
  71028. + gpwrdn.b.srp_det_msk = 1;
  71029. + gpwrdn.b.disconn_det_msk = 1;
  71030. + gpwrdn.b.rst_det_msk = 1;
  71031. + gpwrdn.b.lnstchng_msk = 1;
  71032. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71033. +
  71034. + /* Indicates that we are going out from hibernation */
  71035. + core_if->hibernation_suspend = 0;
  71036. +
  71037. + /*
  71038. + * Set Restore Essential Regs bit in PCGCCTL register, restore_mode = 1
  71039. + * indicates restore from remote_wakeup
  71040. + */
  71041. + restore_essential_regs(core_if, rem_wakeup, 0);
  71042. +
  71043. + /*
  71044. + * Wait a little for seeing new value of variable hibernation_suspend if
  71045. + * Restore done interrupt received before polling
  71046. + */
  71047. + dwc_udelay(10);
  71048. +
  71049. + if (core_if->hibernation_suspend == 0) {
  71050. + /*
  71051. + * Wait For Restore_done Interrupt. This mechanism of polling the
  71052. + * interrupt is introduced to avoid any possible race conditions
  71053. + */
  71054. + do {
  71055. + gintsts_data_t gintsts;
  71056. + gintsts.d32 =
  71057. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  71058. + if (gintsts.b.restoredone) {
  71059. + gintsts.d32 = 0;
  71060. + gintsts.b.restoredone = 1;
  71061. + DWC_WRITE_REG32(&core_if->core_global_regs->
  71062. + gintsts, gintsts.d32);
  71063. + DWC_PRINTF("Restore Done Interrupt seen\n");
  71064. + break;
  71065. + }
  71066. + dwc_udelay(10);
  71067. + } while (--timeout);
  71068. + if (!timeout) {
  71069. + DWC_PRINTF("Restore Done interrupt wasn't generated here\n");
  71070. + }
  71071. + }
  71072. + /* Clear all pending interupts */
  71073. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  71074. +
  71075. + /* De-assert Restore */
  71076. + gpwrdn.d32 = 0;
  71077. + gpwrdn.b.restore = 1;
  71078. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71079. + dwc_udelay(10);
  71080. +
  71081. + if (!rem_wakeup) {
  71082. + pcgcctl.d32 = 0;
  71083. + pcgcctl.b.rstpdwnmodule = 1;
  71084. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  71085. + }
  71086. +
  71087. + /* Restore GUSBCFG and DCFG */
  71088. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  71089. + core_if->gr_backup->gusbcfg_local);
  71090. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  71091. + core_if->dr_backup->dcfg);
  71092. +
  71093. + /* De-assert Wakeup Logic */
  71094. + gpwrdn.d32 = 0;
  71095. + gpwrdn.b.pmuactv = 1;
  71096. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71097. + dwc_udelay(10);
  71098. +
  71099. + if (!rem_wakeup) {
  71100. + /* Set Device programming done bit */
  71101. + dctl.b.pwronprgdone = 1;
  71102. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  71103. + } else {
  71104. + /* Start Remote Wakeup Signaling */
  71105. + dctl.d32 = core_if->dr_backup->dctl;
  71106. + dctl.b.rmtwkupsig = 1;
  71107. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  71108. + }
  71109. +
  71110. + dwc_mdelay(2);
  71111. + /* Clear all pending interupts */
  71112. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  71113. +
  71114. + /* Restore global registers */
  71115. + dwc_otg_restore_global_regs(core_if);
  71116. + /* Restore device global registers */
  71117. + dwc_otg_restore_dev_regs(core_if, rem_wakeup);
  71118. +
  71119. + if (rem_wakeup) {
  71120. + dwc_mdelay(7);
  71121. + dctl.d32 = 0;
  71122. + dctl.b.rmtwkupsig = 1;
  71123. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  71124. + }
  71125. +
  71126. + core_if->hibernation_suspend = 0;
  71127. + /* The core will be in ON STATE */
  71128. + core_if->lx_state = DWC_OTG_L0;
  71129. + DWC_PRINTF("Hibernation recovery completes here\n");
  71130. +
  71131. + return 1;
  71132. +}
  71133. +
  71134. +/*
  71135. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  71136. + * Hibernation. This function is for exiting from Host mode hibernation by
  71137. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  71138. + * @param core_if Programming view of DWC_otg controller.
  71139. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  71140. + * @param reset - indicates whether resume is initiated by Reset.
  71141. + */
  71142. +int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  71143. + int rem_wakeup, int reset)
  71144. +{
  71145. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  71146. + hprt0_data_t hprt0 = {.d32 = 0 };
  71147. +
  71148. + int timeout = 2000;
  71149. +
  71150. + DWC_DEBUGPL(DBG_HCD, "%s called\n", __FUNCTION__);
  71151. + /* Switch-on voltage to the core */
  71152. + gpwrdn.b.pwrdnswtch = 1;
  71153. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71154. + dwc_udelay(10);
  71155. +
  71156. + /* Reset core */
  71157. + gpwrdn.d32 = 0;
  71158. + gpwrdn.b.pwrdnrstn = 1;
  71159. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71160. + dwc_udelay(10);
  71161. +
  71162. + /* Assert Restore signal */
  71163. + gpwrdn.d32 = 0;
  71164. + gpwrdn.b.restore = 1;
  71165. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  71166. + dwc_udelay(10);
  71167. +
  71168. + /* Disable power clamps */
  71169. + gpwrdn.d32 = 0;
  71170. + gpwrdn.b.pwrdnclmp = 1;
  71171. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71172. +
  71173. + if (!rem_wakeup) {
  71174. + dwc_udelay(50);
  71175. + }
  71176. +
  71177. + /* Deassert Reset core */
  71178. + gpwrdn.d32 = 0;
  71179. + gpwrdn.b.pwrdnrstn = 1;
  71180. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  71181. + dwc_udelay(10);
  71182. +
  71183. + /* Disable PMU interrupt */
  71184. + gpwrdn.d32 = 0;
  71185. + gpwrdn.b.pmuintsel = 1;
  71186. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71187. +
  71188. + gpwrdn.d32 = 0;
  71189. + gpwrdn.b.connect_det_msk = 1;
  71190. + gpwrdn.b.srp_det_msk = 1;
  71191. + gpwrdn.b.disconn_det_msk = 1;
  71192. + gpwrdn.b.rst_det_msk = 1;
  71193. + gpwrdn.b.lnstchng_msk = 1;
  71194. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71195. +
  71196. + /* Indicates that we are going out from hibernation */
  71197. + core_if->hibernation_suspend = 0;
  71198. +
  71199. + /* Set Restore Essential Regs bit in PCGCCTL register */
  71200. + restore_essential_regs(core_if, rem_wakeup, 1);
  71201. +
  71202. + /* Wait a little for seeing new value of variable hibernation_suspend if
  71203. + * Restore done interrupt received before polling */
  71204. + dwc_udelay(10);
  71205. +
  71206. + if (core_if->hibernation_suspend == 0) {
  71207. + /* Wait For Restore_done Interrupt. This mechanism of polling the
  71208. + * interrupt is introduced to avoid any possible race conditions
  71209. + */
  71210. + do {
  71211. + gintsts_data_t gintsts;
  71212. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  71213. + if (gintsts.b.restoredone) {
  71214. + gintsts.d32 = 0;
  71215. + gintsts.b.restoredone = 1;
  71216. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  71217. + DWC_DEBUGPL(DBG_HCD,"Restore Done Interrupt seen\n");
  71218. + break;
  71219. + }
  71220. + dwc_udelay(10);
  71221. + } while (--timeout);
  71222. + if (!timeout) {
  71223. + DWC_WARN("Restore Done interrupt wasn't generated\n");
  71224. + }
  71225. + }
  71226. +
  71227. + /* Set the flag's value to 0 again after receiving restore done interrupt */
  71228. + core_if->hibernation_suspend = 0;
  71229. +
  71230. + /* This step is not described in functional spec but if not wait for this
  71231. + * delay, mismatch interrupts occurred because just after restore core is
  71232. + * in Device mode(gintsts.curmode == 0) */
  71233. + dwc_mdelay(100);
  71234. +
  71235. + /* Clear all pending interrupts */
  71236. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  71237. +
  71238. + /* De-assert Restore */
  71239. + gpwrdn.d32 = 0;
  71240. + gpwrdn.b.restore = 1;
  71241. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71242. + dwc_udelay(10);
  71243. +
  71244. + /* Restore GUSBCFG and HCFG */
  71245. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  71246. + core_if->gr_backup->gusbcfg_local);
  71247. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  71248. + core_if->hr_backup->hcfg_local);
  71249. +
  71250. + /* De-assert Wakeup Logic */
  71251. + gpwrdn.d32 = 0;
  71252. + gpwrdn.b.pmuactv = 1;
  71253. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71254. + dwc_udelay(10);
  71255. +
  71256. + /* Start the Resume operation by programming HPRT0 */
  71257. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  71258. + hprt0.b.prtpwr = 1;
  71259. + hprt0.b.prtena = 0;
  71260. + hprt0.b.prtsusp = 0;
  71261. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71262. +
  71263. + DWC_PRINTF("Resume Starts Now\n");
  71264. + if (!reset) { // Indicates it is Resume Operation
  71265. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  71266. + hprt0.b.prtres = 1;
  71267. + hprt0.b.prtpwr = 1;
  71268. + hprt0.b.prtena = 0;
  71269. + hprt0.b.prtsusp = 0;
  71270. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71271. +
  71272. + if (!rem_wakeup)
  71273. + hprt0.b.prtres = 0;
  71274. + /* Wait for Resume time and then program HPRT again */
  71275. + dwc_mdelay(100);
  71276. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71277. +
  71278. + } else { // Indicates it is Reset Operation
  71279. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  71280. + hprt0.b.prtrst = 1;
  71281. + hprt0.b.prtpwr = 1;
  71282. + hprt0.b.prtena = 0;
  71283. + hprt0.b.prtsusp = 0;
  71284. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71285. + /* Wait for Reset time and then program HPRT again */
  71286. + dwc_mdelay(60);
  71287. + hprt0.b.prtrst = 0;
  71288. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71289. + }
  71290. + /* Clear all interrupt status */
  71291. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71292. + hprt0.b.prtconndet = 1;
  71293. + hprt0.b.prtenchng = 1;
  71294. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71295. +
  71296. + /* Clear all pending interupts */
  71297. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  71298. +
  71299. + /* Restore global registers */
  71300. + dwc_otg_restore_global_regs(core_if);
  71301. + /* Restore host global registers */
  71302. + dwc_otg_restore_host_regs(core_if, reset);
  71303. +
  71304. + /* The core will be in ON STATE */
  71305. + core_if->lx_state = DWC_OTG_L0;
  71306. + DWC_PRINTF("Hibernation recovery is complete here\n");
  71307. + return 0;
  71308. +}
  71309. +
  71310. +/** Saves some register values into system memory. */
  71311. +int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if)
  71312. +{
  71313. + struct dwc_otg_global_regs_backup *gr;
  71314. + int i;
  71315. +
  71316. + gr = core_if->gr_backup;
  71317. + if (!gr) {
  71318. + gr = DWC_ALLOC(sizeof(*gr));
  71319. + if (!gr) {
  71320. + return -DWC_E_NO_MEMORY;
  71321. + }
  71322. + core_if->gr_backup = gr;
  71323. + }
  71324. +
  71325. + gr->gotgctl_local = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  71326. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  71327. + gr->gahbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  71328. + gr->gusbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  71329. + gr->grxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  71330. + gr->gnptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  71331. + gr->hptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  71332. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71333. + gr->glpmcfg_local = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  71334. +#endif
  71335. + gr->gi2cctl_local = DWC_READ_REG32(&core_if->core_global_regs->gi2cctl);
  71336. + gr->pcgcctl_local = DWC_READ_REG32(core_if->pcgcctl);
  71337. + gr->gdfifocfg_local =
  71338. + DWC_READ_REG32(&core_if->core_global_regs->gdfifocfg);
  71339. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  71340. + gr->dtxfsiz_local[i] =
  71341. + DWC_READ_REG32(&(core_if->core_global_regs->dtxfsiz[i]));
  71342. + }
  71343. +
  71344. + DWC_DEBUGPL(DBG_ANY, "===========Backing Global registers==========\n");
  71345. + DWC_DEBUGPL(DBG_ANY, "Backed up gotgctl = %08x\n", gr->gotgctl_local);
  71346. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  71347. + DWC_DEBUGPL(DBG_ANY, "Backed up gahbcfg = %08x\n", gr->gahbcfg_local);
  71348. + DWC_DEBUGPL(DBG_ANY, "Backed up gusbcfg = %08x\n", gr->gusbcfg_local);
  71349. + DWC_DEBUGPL(DBG_ANY, "Backed up grxfsiz = %08x\n", gr->grxfsiz_local);
  71350. + DWC_DEBUGPL(DBG_ANY, "Backed up gnptxfsiz = %08x\n",
  71351. + gr->gnptxfsiz_local);
  71352. + DWC_DEBUGPL(DBG_ANY, "Backed up hptxfsiz = %08x\n",
  71353. + gr->hptxfsiz_local);
  71354. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71355. + DWC_DEBUGPL(DBG_ANY, "Backed up glpmcfg = %08x\n", gr->glpmcfg_local);
  71356. +#endif
  71357. + DWC_DEBUGPL(DBG_ANY, "Backed up gi2cctl = %08x\n", gr->gi2cctl_local);
  71358. + DWC_DEBUGPL(DBG_ANY, "Backed up pcgcctl = %08x\n", gr->pcgcctl_local);
  71359. + DWC_DEBUGPL(DBG_ANY,"Backed up gdfifocfg = %08x\n",gr->gdfifocfg_local);
  71360. +
  71361. + return 0;
  71362. +}
  71363. +
  71364. +/** Saves GINTMSK register before setting the msk bits. */
  71365. +int dwc_otg_save_gintmsk_reg(dwc_otg_core_if_t * core_if)
  71366. +{
  71367. + struct dwc_otg_global_regs_backup *gr;
  71368. +
  71369. + gr = core_if->gr_backup;
  71370. + if (!gr) {
  71371. + gr = DWC_ALLOC(sizeof(*gr));
  71372. + if (!gr) {
  71373. + return -DWC_E_NO_MEMORY;
  71374. + }
  71375. + core_if->gr_backup = gr;
  71376. + }
  71377. +
  71378. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  71379. +
  71380. + DWC_DEBUGPL(DBG_ANY,"=============Backing GINTMSK registers============\n");
  71381. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  71382. +
  71383. + return 0;
  71384. +}
  71385. +
  71386. +int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if)
  71387. +{
  71388. + struct dwc_otg_dev_regs_backup *dr;
  71389. + int i;
  71390. +
  71391. + dr = core_if->dr_backup;
  71392. + if (!dr) {
  71393. + dr = DWC_ALLOC(sizeof(*dr));
  71394. + if (!dr) {
  71395. + return -DWC_E_NO_MEMORY;
  71396. + }
  71397. + core_if->dr_backup = dr;
  71398. + }
  71399. +
  71400. + dr->dcfg = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  71401. + dr->dctl = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  71402. + dr->daintmsk =
  71403. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  71404. + dr->diepmsk =
  71405. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->diepmsk);
  71406. + dr->doepmsk =
  71407. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->doepmsk);
  71408. +
  71409. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  71410. + dr->diepctl[i] =
  71411. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  71412. + dr->dieptsiz[i] =
  71413. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz);
  71414. + dr->diepdma[i] =
  71415. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma);
  71416. + }
  71417. +
  71418. + DWC_DEBUGPL(DBG_ANY,
  71419. + "=============Backing Host registers==============\n");
  71420. + DWC_DEBUGPL(DBG_ANY, "Backed up dcfg = %08x\n", dr->dcfg);
  71421. + DWC_DEBUGPL(DBG_ANY, "Backed up dctl = %08x\n", dr->dctl);
  71422. + DWC_DEBUGPL(DBG_ANY, "Backed up daintmsk = %08x\n",
  71423. + dr->daintmsk);
  71424. + DWC_DEBUGPL(DBG_ANY, "Backed up diepmsk = %08x\n", dr->diepmsk);
  71425. + DWC_DEBUGPL(DBG_ANY, "Backed up doepmsk = %08x\n", dr->doepmsk);
  71426. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  71427. + DWC_DEBUGPL(DBG_ANY, "Backed up diepctl[%d] = %08x\n", i,
  71428. + dr->diepctl[i]);
  71429. + DWC_DEBUGPL(DBG_ANY, "Backed up dieptsiz[%d] = %08x\n",
  71430. + i, dr->dieptsiz[i]);
  71431. + DWC_DEBUGPL(DBG_ANY, "Backed up diepdma[%d] = %08x\n", i,
  71432. + dr->diepdma[i]);
  71433. + }
  71434. +
  71435. + return 0;
  71436. +}
  71437. +
  71438. +int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if)
  71439. +{
  71440. + struct dwc_otg_host_regs_backup *hr;
  71441. + int i;
  71442. +
  71443. + hr = core_if->hr_backup;
  71444. + if (!hr) {
  71445. + hr = DWC_ALLOC(sizeof(*hr));
  71446. + if (!hr) {
  71447. + return -DWC_E_NO_MEMORY;
  71448. + }
  71449. + core_if->hr_backup = hr;
  71450. + }
  71451. +
  71452. + hr->hcfg_local =
  71453. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  71454. + hr->haintmsk_local =
  71455. + DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  71456. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  71457. + hr->hcintmsk_local[i] =
  71458. + DWC_READ_REG32(&core_if->host_if->hc_regs[i]->hcintmsk);
  71459. + }
  71460. + hr->hprt0_local = DWC_READ_REG32(core_if->host_if->hprt0);
  71461. + hr->hfir_local =
  71462. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  71463. +
  71464. + DWC_DEBUGPL(DBG_ANY,
  71465. + "=============Backing Host registers===============\n");
  71466. + DWC_DEBUGPL(DBG_ANY, "Backed up hcfg = %08x\n",
  71467. + hr->hcfg_local);
  71468. + DWC_DEBUGPL(DBG_ANY, "Backed up haintmsk = %08x\n", hr->haintmsk_local);
  71469. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  71470. + DWC_DEBUGPL(DBG_ANY, "Backed up hcintmsk[%02d]=%08x\n", i,
  71471. + hr->hcintmsk_local[i]);
  71472. + }
  71473. + DWC_DEBUGPL(DBG_ANY, "Backed up hprt0 = %08x\n",
  71474. + hr->hprt0_local);
  71475. + DWC_DEBUGPL(DBG_ANY, "Backed up hfir = %08x\n",
  71476. + hr->hfir_local);
  71477. +
  71478. + return 0;
  71479. +}
  71480. +
  71481. +int dwc_otg_restore_global_regs(dwc_otg_core_if_t *core_if)
  71482. +{
  71483. + struct dwc_otg_global_regs_backup *gr;
  71484. + int i;
  71485. +
  71486. + gr = core_if->gr_backup;
  71487. + if (!gr) {
  71488. + return -DWC_E_INVALID;
  71489. + }
  71490. +
  71491. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, gr->gotgctl_local);
  71492. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gr->gintmsk_local);
  71493. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gr->gusbcfg_local);
  71494. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gr->gahbcfg_local);
  71495. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, gr->grxfsiz_local);
  71496. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz,
  71497. + gr->gnptxfsiz_local);
  71498. + DWC_WRITE_REG32(&core_if->core_global_regs->hptxfsiz,
  71499. + gr->hptxfsiz_local);
  71500. + DWC_WRITE_REG32(&core_if->core_global_regs->gdfifocfg,
  71501. + gr->gdfifocfg_local);
  71502. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  71503. + DWC_WRITE_REG32(&core_if->core_global_regs->dtxfsiz[i],
  71504. + gr->dtxfsiz_local[i]);
  71505. + }
  71506. +
  71507. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  71508. + DWC_WRITE_REG32(core_if->host_if->hprt0, 0x0000100A);
  71509. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg,
  71510. + (gr->gahbcfg_local));
  71511. + return 0;
  71512. +}
  71513. +
  71514. +int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if, int rem_wakeup)
  71515. +{
  71516. + struct dwc_otg_dev_regs_backup *dr;
  71517. + int i;
  71518. +
  71519. + dr = core_if->dr_backup;
  71520. +
  71521. + if (!dr) {
  71522. + return -DWC_E_INVALID;
  71523. + }
  71524. +
  71525. + if (!rem_wakeup) {
  71526. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  71527. + dr->dctl);
  71528. + }
  71529. +
  71530. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, dr->daintmsk);
  71531. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, dr->diepmsk);
  71532. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, dr->doepmsk);
  71533. +
  71534. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  71535. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz, dr->dieptsiz[i]);
  71536. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma, dr->diepdma[i]);
  71537. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl, dr->diepctl[i]);
  71538. + }
  71539. +
  71540. + return 0;
  71541. +}
  71542. +
  71543. +int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset)
  71544. +{
  71545. + struct dwc_otg_host_regs_backup *hr;
  71546. + int i;
  71547. + hr = core_if->hr_backup;
  71548. +
  71549. + if (!hr) {
  71550. + return -DWC_E_INVALID;
  71551. + }
  71552. +
  71553. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hr->hcfg_local);
  71554. + //if (!reset)
  71555. + //{
  71556. + // DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hr->hfir_local);
  71557. + //}
  71558. +
  71559. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk,
  71560. + hr->haintmsk_local);
  71561. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  71562. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk,
  71563. + hr->hcintmsk_local[i]);
  71564. + }
  71565. +
  71566. + return 0;
  71567. +}
  71568. +
  71569. +int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if)
  71570. +{
  71571. + struct dwc_otg_global_regs_backup *gr;
  71572. +
  71573. + gr = core_if->gr_backup;
  71574. +
  71575. + /* Restore values for LPM and I2C */
  71576. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71577. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, gr->glpmcfg_local);
  71578. +#endif
  71579. + DWC_WRITE_REG32(&core_if->core_global_regs->gi2cctl, gr->gi2cctl_local);
  71580. +
  71581. + return 0;
  71582. +}
  71583. +
  71584. +int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode, int is_host)
  71585. +{
  71586. + struct dwc_otg_global_regs_backup *gr;
  71587. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  71588. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  71589. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  71590. + gintmsk_data_t gintmsk = {.d32 = 0 };
  71591. +
  71592. + /* Restore LPM and I2C registers */
  71593. + restore_lpm_i2c_regs(core_if);
  71594. +
  71595. + /* Set PCGCCTL to 0 */
  71596. + DWC_WRITE_REG32(core_if->pcgcctl, 0x00000000);
  71597. +
  71598. + gr = core_if->gr_backup;
  71599. + /* Load restore values for [31:14] bits */
  71600. + DWC_WRITE_REG32(core_if->pcgcctl,
  71601. + ((gr->pcgcctl_local & 0xffffc000) | 0x00020000));
  71602. +
  71603. + /* Umnask global Interrupt in GAHBCFG and restore it */
  71604. + gahbcfg.d32 = gr->gahbcfg_local;
  71605. + gahbcfg.b.glblintrmsk = 1;
  71606. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  71607. +
  71608. + /* Clear all pending interupts */
  71609. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  71610. +
  71611. + /* Unmask restore done interrupt */
  71612. + gintmsk.b.restoredone = 1;
  71613. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  71614. +
  71615. + /* Restore GUSBCFG and HCFG/DCFG */
  71616. + gusbcfg.d32 = core_if->gr_backup->gusbcfg_local;
  71617. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  71618. +
  71619. + if (is_host) {
  71620. + hcfg_data_t hcfg = {.d32 = 0 };
  71621. + hcfg.d32 = core_if->hr_backup->hcfg_local;
  71622. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  71623. + hcfg.d32);
  71624. +
  71625. + /* Load restore values for [31:14] bits */
  71626. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  71627. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  71628. +
  71629. + if (rmode)
  71630. + pcgcctl.b.restoremode = 1;
  71631. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  71632. + dwc_udelay(10);
  71633. +
  71634. + /* Load restore values for [31:14] bits and set EssRegRestored bit */
  71635. + pcgcctl.d32 = gr->pcgcctl_local | 0xffffc000;
  71636. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  71637. + pcgcctl.b.ess_reg_restored = 1;
  71638. + if (rmode)
  71639. + pcgcctl.b.restoremode = 1;
  71640. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  71641. + } else {
  71642. + dcfg_data_t dcfg = {.d32 = 0 };
  71643. + dcfg.d32 = core_if->dr_backup->dcfg;
  71644. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  71645. +
  71646. + /* Load restore values for [31:14] bits */
  71647. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  71648. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  71649. + if (!rmode) {
  71650. + pcgcctl.d32 |= 0x208;
  71651. + }
  71652. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  71653. + dwc_udelay(10);
  71654. +
  71655. + /* Load restore values for [31:14] bits */
  71656. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  71657. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  71658. + pcgcctl.b.ess_reg_restored = 1;
  71659. + if (!rmode)
  71660. + pcgcctl.d32 |= 0x208;
  71661. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  71662. + }
  71663. +
  71664. + return 0;
  71665. +}
  71666. +
  71667. +/**
  71668. + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
  71669. + * type.
  71670. + */
  71671. +static void init_fslspclksel(dwc_otg_core_if_t * core_if)
  71672. +{
  71673. + uint32_t val;
  71674. + hcfg_data_t hcfg;
  71675. +
  71676. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  71677. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  71678. + (core_if->core_params->ulpi_fs_ls)) ||
  71679. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  71680. + /* Full speed PHY */
  71681. + val = DWC_HCFG_48_MHZ;
  71682. + } else {
  71683. + /* High speed PHY running at full speed or high speed */
  71684. + val = DWC_HCFG_30_60_MHZ;
  71685. + }
  71686. +
  71687. + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
  71688. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  71689. + hcfg.b.fslspclksel = val;
  71690. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  71691. +}
  71692. +
  71693. +/**
  71694. + * Initializes the DevSpd field of the DCFG register depending on the PHY type
  71695. + * and the enumeration speed of the device.
  71696. + */
  71697. +static void init_devspd(dwc_otg_core_if_t * core_if)
  71698. +{
  71699. + uint32_t val;
  71700. + dcfg_data_t dcfg;
  71701. +
  71702. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  71703. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  71704. + (core_if->core_params->ulpi_fs_ls)) ||
  71705. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  71706. + /* Full speed PHY */
  71707. + val = 0x3;
  71708. + } else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  71709. + /* High speed PHY running at full speed */
  71710. + val = 0x1;
  71711. + } else {
  71712. + /* High speed PHY running at high speed */
  71713. + val = 0x0;
  71714. + }
  71715. +
  71716. + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
  71717. +
  71718. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  71719. + dcfg.b.devspd = val;
  71720. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  71721. +}
  71722. +
  71723. +/**
  71724. + * This function calculates the number of IN EPS
  71725. + * using GHWCFG1 and GHWCFG2 registers values
  71726. + *
  71727. + * @param core_if Programming view of the DWC_otg controller
  71728. + */
  71729. +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * core_if)
  71730. +{
  71731. + uint32_t num_in_eps = 0;
  71732. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  71733. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
  71734. + uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
  71735. + int i;
  71736. +
  71737. + for (i = 0; i < num_eps; ++i) {
  71738. + if (!(hwcfg1 & 0x1))
  71739. + num_in_eps++;
  71740. +
  71741. + hwcfg1 >>= 2;
  71742. + }
  71743. +
  71744. + if (core_if->hwcfg4.b.ded_fifo_en) {
  71745. + num_in_eps =
  71746. + (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
  71747. + }
  71748. +
  71749. + return num_in_eps;
  71750. +}
  71751. +
  71752. +/**
  71753. + * This function calculates the number of OUT EPS
  71754. + * using GHWCFG1 and GHWCFG2 registers values
  71755. + *
  71756. + * @param core_if Programming view of the DWC_otg controller
  71757. + */
  71758. +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * core_if)
  71759. +{
  71760. + uint32_t num_out_eps = 0;
  71761. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  71762. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
  71763. + int i;
  71764. +
  71765. + for (i = 0; i < num_eps; ++i) {
  71766. + if (!(hwcfg1 & 0x1))
  71767. + num_out_eps++;
  71768. +
  71769. + hwcfg1 >>= 2;
  71770. + }
  71771. + return num_out_eps;
  71772. +}
  71773. +
  71774. +/**
  71775. + * This function initializes the DWC_otg controller registers and
  71776. + * prepares the core for device mode or host mode operation.
  71777. + *
  71778. + * @param core_if Programming view of the DWC_otg controller
  71779. + *
  71780. + */
  71781. +void dwc_otg_core_init(dwc_otg_core_if_t * core_if)
  71782. +{
  71783. + int i = 0;
  71784. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  71785. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  71786. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  71787. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  71788. + gi2cctl_data_t i2cctl = {.d32 = 0 };
  71789. +
  71790. + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p) regs at %p\n",
  71791. + core_if, global_regs);
  71792. +
  71793. + /* Common Initialization */
  71794. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  71795. +
  71796. + /* Program the ULPI External VBUS bit if needed */
  71797. + usbcfg.b.ulpi_ext_vbus_drv =
  71798. + (core_if->core_params->phy_ulpi_ext_vbus ==
  71799. + DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
  71800. +
  71801. + /* Set external TS Dline pulsing */
  71802. + usbcfg.b.term_sel_dl_pulse =
  71803. + (core_if->core_params->ts_dline == 1) ? 1 : 0;
  71804. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  71805. +
  71806. + /* Reset the Controller */
  71807. + dwc_otg_core_reset(core_if);
  71808. +
  71809. + core_if->adp_enable = core_if->core_params->adp_supp_enable;
  71810. + core_if->power_down = core_if->core_params->power_down;
  71811. + core_if->otg_sts = 0;
  71812. +
  71813. + /* Initialize parameters from Hardware configuration registers. */
  71814. + dev_if->num_in_eps = calc_num_in_eps(core_if);
  71815. + dev_if->num_out_eps = calc_num_out_eps(core_if);
  71816. +
  71817. + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
  71818. + core_if->hwcfg4.b.num_dev_perio_in_ep);
  71819. +
  71820. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  71821. + dev_if->perio_tx_fifo_size[i] =
  71822. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  71823. + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
  71824. + i, dev_if->perio_tx_fifo_size[i]);
  71825. + }
  71826. +
  71827. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  71828. + dev_if->tx_fifo_size[i] =
  71829. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  71830. + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
  71831. + i, dev_if->tx_fifo_size[i]);
  71832. + }
  71833. +
  71834. + core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
  71835. + core_if->rx_fifo_size = DWC_READ_REG32(&global_regs->grxfsiz);
  71836. + core_if->nperio_tx_fifo_size =
  71837. + DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16;
  71838. +
  71839. + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
  71840. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
  71841. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n",
  71842. + core_if->nperio_tx_fifo_size);
  71843. +
  71844. + /* This programming sequence needs to happen in FS mode before any other
  71845. + * programming occurs */
  71846. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
  71847. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  71848. + /* If FS mode with FS PHY */
  71849. +
  71850. + /* core_init() is now called on every switch so only call the
  71851. + * following for the first time through. */
  71852. + if (!core_if->phy_init_done) {
  71853. + core_if->phy_init_done = 1;
  71854. + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
  71855. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  71856. + usbcfg.b.physel = 1;
  71857. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  71858. +
  71859. + /* Reset after a PHY select */
  71860. + dwc_otg_core_reset(core_if);
  71861. + }
  71862. +
  71863. + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
  71864. + * do this on HNP Dev/Host mode switches (done in dev_init and
  71865. + * host_init). */
  71866. + if (dwc_otg_is_host_mode(core_if)) {
  71867. + init_fslspclksel(core_if);
  71868. + } else {
  71869. + init_devspd(core_if);
  71870. + }
  71871. +
  71872. + if (core_if->core_params->i2c_enable) {
  71873. + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
  71874. + /* Program GUSBCFG.OtgUtmifsSel to I2C */
  71875. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  71876. + usbcfg.b.otgutmifssel = 1;
  71877. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  71878. +
  71879. + /* Program GI2CCTL.I2CEn */
  71880. + i2cctl.d32 = DWC_READ_REG32(&global_regs->gi2cctl);
  71881. + i2cctl.b.i2cdevaddr = 1;
  71882. + i2cctl.b.i2cen = 0;
  71883. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  71884. + i2cctl.b.i2cen = 1;
  71885. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  71886. + }
  71887. +
  71888. + } /* endif speed == DWC_SPEED_PARAM_FULL */
  71889. + else {
  71890. + /* High speed PHY. */
  71891. + if (!core_if->phy_init_done) {
  71892. + core_if->phy_init_done = 1;
  71893. + /* HS PHY parameters. These parameters are preserved
  71894. + * during soft reset so only program the first time. Do
  71895. + * a soft reset immediately after setting phyif. */
  71896. +
  71897. + if (core_if->core_params->phy_type == 2) {
  71898. + /* ULPI interface */
  71899. + usbcfg.b.ulpi_utmi_sel = 1;
  71900. + usbcfg.b.phyif = 0;
  71901. + usbcfg.b.ddrsel =
  71902. + core_if->core_params->phy_ulpi_ddr;
  71903. + } else if (core_if->core_params->phy_type == 1) {
  71904. + /* UTMI+ interface */
  71905. + usbcfg.b.ulpi_utmi_sel = 0;
  71906. + if (core_if->core_params->phy_utmi_width == 16) {
  71907. + usbcfg.b.phyif = 1;
  71908. +
  71909. + } else {
  71910. + usbcfg.b.phyif = 0;
  71911. + }
  71912. + } else {
  71913. + DWC_ERROR("FS PHY TYPE\n");
  71914. + }
  71915. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  71916. + /* Reset after setting the PHY parameters */
  71917. + dwc_otg_core_reset(core_if);
  71918. + }
  71919. + }
  71920. +
  71921. + if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  71922. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  71923. + (core_if->core_params->ulpi_fs_ls)) {
  71924. + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
  71925. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  71926. + usbcfg.b.ulpi_fsls = 1;
  71927. + usbcfg.b.ulpi_clk_sus_m = 1;
  71928. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  71929. + } else {
  71930. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  71931. + usbcfg.b.ulpi_fsls = 0;
  71932. + usbcfg.b.ulpi_clk_sus_m = 0;
  71933. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  71934. + }
  71935. +
  71936. + /* Program the GAHBCFG Register. */
  71937. + switch (core_if->hwcfg2.b.architecture) {
  71938. +
  71939. + case DWC_SLAVE_ONLY_ARCH:
  71940. + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
  71941. + ahbcfg.b.nptxfemplvl_txfemplvl =
  71942. + DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  71943. + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  71944. + core_if->dma_enable = 0;
  71945. + core_if->dma_desc_enable = 0;
  71946. + break;
  71947. +
  71948. + case DWC_EXT_DMA_ARCH:
  71949. + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
  71950. + {
  71951. + uint8_t brst_sz = core_if->core_params->dma_burst_size;
  71952. + ahbcfg.b.hburstlen = 0;
  71953. + while (brst_sz > 1) {
  71954. + ahbcfg.b.hburstlen++;
  71955. + brst_sz >>= 1;
  71956. + }
  71957. + }
  71958. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  71959. + core_if->dma_desc_enable =
  71960. + (core_if->core_params->dma_desc_enable != 0);
  71961. + break;
  71962. +
  71963. + case DWC_INT_DMA_ARCH:
  71964. + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
  71965. + /* Old value was DWC_GAHBCFG_INT_DMA_BURST_INCR - done for
  71966. + Host mode ISOC in issue fix - vahrama */
  71967. + /* Broadcom had altered to (1<<3)|(0<<0) - WRESP=1, max 4 beats */
  71968. + ahbcfg.b.hburstlen = (1<<3)|(0<<0);//DWC_GAHBCFG_INT_DMA_BURST_INCR4;
  71969. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  71970. + core_if->dma_desc_enable =
  71971. + (core_if->core_params->dma_desc_enable != 0);
  71972. + break;
  71973. +
  71974. + }
  71975. + if (core_if->dma_enable) {
  71976. + if (core_if->dma_desc_enable) {
  71977. + DWC_PRINTF("Using Descriptor DMA mode\n");
  71978. + } else {
  71979. + DWC_PRINTF("Using Buffer DMA mode\n");
  71980. +
  71981. + }
  71982. + } else {
  71983. + DWC_PRINTF("Using Slave mode\n");
  71984. + core_if->dma_desc_enable = 0;
  71985. + }
  71986. +
  71987. + if (core_if->core_params->ahb_single) {
  71988. + ahbcfg.b.ahbsingle = 1;
  71989. + }
  71990. +
  71991. + ahbcfg.b.dmaenable = core_if->dma_enable;
  71992. + DWC_WRITE_REG32(&global_regs->gahbcfg, ahbcfg.d32);
  71993. +
  71994. + core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
  71995. +
  71996. + core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
  71997. + core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
  71998. + DWC_PRINTF("Periodic Transfer Interrupt Enhancement - %s\n",
  71999. + ((core_if->pti_enh_enable) ? "enabled" : "disabled"));
  72000. + DWC_PRINTF("Multiprocessor Interrupt Enhancement - %s\n",
  72001. + ((core_if->multiproc_int_enable) ? "enabled" : "disabled"));
  72002. +
  72003. + /*
  72004. + * Program the GUSBCFG register.
  72005. + */
  72006. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  72007. +
  72008. + switch (core_if->hwcfg2.b.op_mode) {
  72009. + case DWC_MODE_HNP_SRP_CAPABLE:
  72010. + usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
  72011. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  72012. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  72013. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  72014. + break;
  72015. +
  72016. + case DWC_MODE_SRP_ONLY_CAPABLE:
  72017. + usbcfg.b.hnpcap = 0;
  72018. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  72019. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  72020. + break;
  72021. +
  72022. + case DWC_MODE_NO_HNP_SRP_CAPABLE:
  72023. + usbcfg.b.hnpcap = 0;
  72024. + usbcfg.b.srpcap = 0;
  72025. + break;
  72026. +
  72027. + case DWC_MODE_SRP_CAPABLE_DEVICE:
  72028. + usbcfg.b.hnpcap = 0;
  72029. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  72030. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  72031. + break;
  72032. +
  72033. + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
  72034. + usbcfg.b.hnpcap = 0;
  72035. + usbcfg.b.srpcap = 0;
  72036. + break;
  72037. +
  72038. + case DWC_MODE_SRP_CAPABLE_HOST:
  72039. + usbcfg.b.hnpcap = 0;
  72040. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  72041. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  72042. + break;
  72043. +
  72044. + case DWC_MODE_NO_SRP_CAPABLE_HOST:
  72045. + usbcfg.b.hnpcap = 0;
  72046. + usbcfg.b.srpcap = 0;
  72047. + break;
  72048. + }
  72049. +
  72050. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  72051. +
  72052. +#ifdef CONFIG_USB_DWC_OTG_LPM
  72053. + if (core_if->core_params->lpm_enable) {
  72054. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  72055. +
  72056. + /* To enable LPM support set lpm_cap_en bit */
  72057. + lpmcfg.b.lpm_cap_en = 1;
  72058. +
  72059. + /* Make AppL1Res ACK */
  72060. + lpmcfg.b.appl_resp = 1;
  72061. +
  72062. + /* Retry 3 times */
  72063. + lpmcfg.b.retry_count = 3;
  72064. +
  72065. + DWC_MODIFY_REG32(&core_if->core_global_regs->glpmcfg,
  72066. + 0, lpmcfg.d32);
  72067. +
  72068. + }
  72069. +#endif
  72070. + if (core_if->core_params->ic_usb_cap) {
  72071. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  72072. + gusbcfg.b.ic_usb_cap = 1;
  72073. + DWC_MODIFY_REG32(&core_if->core_global_regs->gusbcfg,
  72074. + 0, gusbcfg.d32);
  72075. + }
  72076. + {
  72077. + gotgctl_data_t gotgctl = {.d32 = 0 };
  72078. + gotgctl.b.otgver = core_if->core_params->otg_ver;
  72079. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl, 0,
  72080. + gotgctl.d32);
  72081. + /* Set OTG version supported */
  72082. + core_if->otg_ver = core_if->core_params->otg_ver;
  72083. + DWC_PRINTF("OTG VER PARAM: %d, OTG VER FLAG: %d\n",
  72084. + core_if->core_params->otg_ver, core_if->otg_ver);
  72085. + }
  72086. +
  72087. +
  72088. + /* Enable common interrupts */
  72089. + dwc_otg_enable_common_interrupts(core_if);
  72090. +
  72091. + /* Do device or host intialization based on mode during PCD
  72092. + * and HCD initialization */
  72093. + if (dwc_otg_is_host_mode(core_if)) {
  72094. + DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
  72095. + core_if->op_state = A_HOST;
  72096. + } else {
  72097. + DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
  72098. + core_if->op_state = B_PERIPHERAL;
  72099. +#ifdef DWC_DEVICE_ONLY
  72100. + dwc_otg_core_dev_init(core_if);
  72101. +#endif
  72102. + }
  72103. +}
  72104. +
  72105. +/**
  72106. + * This function enables the Device mode interrupts.
  72107. + *
  72108. + * @param core_if Programming view of DWC_otg controller
  72109. + */
  72110. +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * core_if)
  72111. +{
  72112. + gintmsk_data_t intr_mask = {.d32 = 0 };
  72113. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  72114. +
  72115. + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  72116. +
  72117. + /* Disable all interrupts. */
  72118. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  72119. +
  72120. + /* Clear any pending interrupts */
  72121. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  72122. +
  72123. + /* Enable the common interrupts */
  72124. + dwc_otg_enable_common_interrupts(core_if);
  72125. +
  72126. + /* Enable interrupts */
  72127. + intr_mask.b.usbreset = 1;
  72128. + intr_mask.b.enumdone = 1;
  72129. + /* Disable Disconnect interrupt in Device mode */
  72130. + intr_mask.b.disconnect = 0;
  72131. +
  72132. + if (!core_if->multiproc_int_enable) {
  72133. + intr_mask.b.inepintr = 1;
  72134. + intr_mask.b.outepintr = 1;
  72135. + }
  72136. +
  72137. + intr_mask.b.erlysuspend = 1;
  72138. +
  72139. + if (core_if->en_multiple_tx_fifo == 0) {
  72140. + intr_mask.b.epmismatch = 1;
  72141. + }
  72142. +
  72143. + //intr_mask.b.incomplisoout = 1;
  72144. + intr_mask.b.incomplisoin = 1;
  72145. +
  72146. +/* Enable the ignore frame number for ISOC xfers - MAS */
  72147. +/* Disable to support high bandwith ISOC transfers - manukz */
  72148. +#if 0
  72149. +#ifdef DWC_UTE_PER_IO
  72150. + if (core_if->dma_enable) {
  72151. + if (core_if->dma_desc_enable) {
  72152. + dctl_data_t dctl1 = {.d32 = 0 };
  72153. + dctl1.b.ifrmnum = 1;
  72154. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  72155. + dctl, 0, dctl1.d32);
  72156. + DWC_DEBUG("----Enabled Ignore frame number (0x%08x)",
  72157. + DWC_READ_REG32(&core_if->dev_if->
  72158. + dev_global_regs->dctl));
  72159. + }
  72160. + }
  72161. +#endif
  72162. +#endif
  72163. +#ifdef DWC_EN_ISOC
  72164. + if (core_if->dma_enable) {
  72165. + if (core_if->dma_desc_enable == 0) {
  72166. + if (core_if->pti_enh_enable) {
  72167. + dctl_data_t dctl = {.d32 = 0 };
  72168. + dctl.b.ifrmnum = 1;
  72169. + DWC_MODIFY_REG32(&core_if->
  72170. + dev_if->dev_global_regs->dctl,
  72171. + 0, dctl.d32);
  72172. + } else {
  72173. + intr_mask.b.incomplisoin = 1;
  72174. + intr_mask.b.incomplisoout = 1;
  72175. + }
  72176. + }
  72177. + } else {
  72178. + intr_mask.b.incomplisoin = 1;
  72179. + intr_mask.b.incomplisoout = 1;
  72180. + }
  72181. +#endif /* DWC_EN_ISOC */
  72182. +
  72183. + /** @todo NGS: Should this be a module parameter? */
  72184. +#ifdef USE_PERIODIC_EP
  72185. + intr_mask.b.isooutdrop = 1;
  72186. + intr_mask.b.eopframe = 1;
  72187. + intr_mask.b.incomplisoin = 1;
  72188. + intr_mask.b.incomplisoout = 1;
  72189. +#endif
  72190. +
  72191. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  72192. +
  72193. + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
  72194. + DWC_READ_REG32(&global_regs->gintmsk));
  72195. +}
  72196. +
  72197. +/**
  72198. + * This function initializes the DWC_otg controller registers for
  72199. + * device mode.
  72200. + *
  72201. + * @param core_if Programming view of DWC_otg controller
  72202. + *
  72203. + */
  72204. +void dwc_otg_core_dev_init(dwc_otg_core_if_t * core_if)
  72205. +{
  72206. + int i;
  72207. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  72208. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  72209. + dwc_otg_core_params_t *params = core_if->core_params;
  72210. + dcfg_data_t dcfg = {.d32 = 0 };
  72211. + depctl_data_t diepctl = {.d32 = 0 };
  72212. + grstctl_t resetctl = {.d32 = 0 };
  72213. + uint32_t rx_fifo_size;
  72214. + fifosize_data_t nptxfifosize;
  72215. + fifosize_data_t txfifosize;
  72216. + dthrctl_data_t dthrctl;
  72217. + fifosize_data_t ptxfifosize;
  72218. + uint16_t rxfsiz, nptxfsiz;
  72219. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  72220. + hwcfg3_data_t hwcfg3 = {.d32 = 0 };
  72221. +
  72222. + /* Restart the Phy Clock */
  72223. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  72224. +
  72225. + /* Device configuration register */
  72226. + init_devspd(core_if);
  72227. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  72228. + dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
  72229. + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
  72230. + /* Enable Device OUT NAK in case of DDMA mode*/
  72231. + if (core_if->core_params->dev_out_nak) {
  72232. + dcfg.b.endevoutnak = 1;
  72233. + }
  72234. +
  72235. + if (core_if->core_params->cont_on_bna) {
  72236. + dctl_data_t dctl = {.d32 = 0 };
  72237. + dctl.b.encontonbna = 1;
  72238. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  72239. + }
  72240. +
  72241. +
  72242. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  72243. +
  72244. + /* Configure data FIFO sizes */
  72245. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  72246. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  72247. + core_if->total_fifo_size);
  72248. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  72249. + params->dev_rx_fifo_size);
  72250. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  72251. + params->dev_nperio_tx_fifo_size);
  72252. +
  72253. + /* Rx FIFO */
  72254. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  72255. + DWC_READ_REG32(&global_regs->grxfsiz));
  72256. +
  72257. +#ifdef DWC_UTE_CFI
  72258. + core_if->pwron_rxfsiz = DWC_READ_REG32(&global_regs->grxfsiz);
  72259. + core_if->init_rxfsiz = params->dev_rx_fifo_size;
  72260. +#endif
  72261. + rx_fifo_size = params->dev_rx_fifo_size;
  72262. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  72263. +
  72264. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  72265. + DWC_READ_REG32(&global_regs->grxfsiz));
  72266. +
  72267. + /** Set Periodic Tx FIFO Mask all bits 0 */
  72268. + core_if->p_tx_msk = 0;
  72269. +
  72270. + /** Set Tx FIFO Mask all bits 0 */
  72271. + core_if->tx_msk = 0;
  72272. +
  72273. + if (core_if->en_multiple_tx_fifo == 0) {
  72274. + /* Non-periodic Tx FIFO */
  72275. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  72276. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  72277. +
  72278. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  72279. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  72280. +
  72281. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  72282. + nptxfifosize.d32);
  72283. +
  72284. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  72285. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  72286. +
  72287. + /**@todo NGS: Fix Periodic FIFO Sizing! */
  72288. + /*
  72289. + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
  72290. + * Indexes of the FIFO size module parameters in the
  72291. + * dev_perio_tx_fifo_size array and the FIFO size registers in
  72292. + * the dptxfsiz array run from 0 to 14.
  72293. + */
  72294. + /** @todo Finish debug of this */
  72295. + ptxfifosize.b.startaddr =
  72296. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  72297. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  72298. + ptxfifosize.b.depth =
  72299. + params->dev_perio_tx_fifo_size[i];
  72300. + DWC_DEBUGPL(DBG_CIL,
  72301. + "initial dtxfsiz[%d]=%08x\n", i,
  72302. + DWC_READ_REG32(&global_regs->dtxfsiz
  72303. + [i]));
  72304. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  72305. + ptxfifosize.d32);
  72306. + DWC_DEBUGPL(DBG_CIL, "new dtxfsiz[%d]=%08x\n",
  72307. + i,
  72308. + DWC_READ_REG32(&global_regs->dtxfsiz
  72309. + [i]));
  72310. + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
  72311. + }
  72312. + } else {
  72313. + /*
  72314. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  72315. + * Indexes of the FIFO size module parameters in the
  72316. + * dev_tx_fifo_size array and the FIFO size registers in
  72317. + * the dtxfsiz array run from 0 to 14.
  72318. + */
  72319. +
  72320. + /* Non-periodic Tx FIFO */
  72321. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  72322. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  72323. +
  72324. +#ifdef DWC_UTE_CFI
  72325. + core_if->pwron_gnptxfsiz =
  72326. + (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  72327. + core_if->init_gnptxfsiz =
  72328. + params->dev_nperio_tx_fifo_size;
  72329. +#endif
  72330. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  72331. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  72332. +
  72333. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  72334. + nptxfifosize.d32);
  72335. +
  72336. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  72337. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  72338. +
  72339. + txfifosize.b.startaddr =
  72340. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  72341. +
  72342. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  72343. +
  72344. + txfifosize.b.depth =
  72345. + params->dev_tx_fifo_size[i];
  72346. +
  72347. + DWC_DEBUGPL(DBG_CIL,
  72348. + "initial dtxfsiz[%d]=%08x\n",
  72349. + i,
  72350. + DWC_READ_REG32(&global_regs->dtxfsiz
  72351. + [i]));
  72352. +
  72353. +#ifdef DWC_UTE_CFI
  72354. + core_if->pwron_txfsiz[i] =
  72355. + (DWC_READ_REG32
  72356. + (&global_regs->dtxfsiz[i]) >> 16);
  72357. + core_if->init_txfsiz[i] =
  72358. + params->dev_tx_fifo_size[i];
  72359. +#endif
  72360. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  72361. + txfifosize.d32);
  72362. +
  72363. + DWC_DEBUGPL(DBG_CIL,
  72364. + "new dtxfsiz[%d]=%08x\n",
  72365. + i,
  72366. + DWC_READ_REG32(&global_regs->dtxfsiz
  72367. + [i]));
  72368. +
  72369. + txfifosize.b.startaddr += txfifosize.b.depth;
  72370. + }
  72371. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  72372. + /* Calculating DFIFOCFG for Device mode to include RxFIFO and NPTXFIFO */
  72373. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  72374. + hwcfg3.d32 = DWC_READ_REG32(&global_regs->ghwcfg3);
  72375. + gdfifocfg.b.gdfifocfg = (DWC_READ_REG32(&global_regs->ghwcfg3) >> 16);
  72376. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  72377. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  72378. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  72379. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz;
  72380. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  72381. + }
  72382. + }
  72383. +
  72384. + /* Flush the FIFOs */
  72385. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  72386. + dwc_otg_flush_rx_fifo(core_if);
  72387. +
  72388. + /* Flush the Learning Queue. */
  72389. + resetctl.b.intknqflsh = 1;
  72390. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  72391. +
  72392. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  72393. + core_if->start_predict = 0;
  72394. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  72395. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  72396. + }
  72397. + core_if->nextep_seq[0] = 0;
  72398. + core_if->first_in_nextep_seq = 0;
  72399. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  72400. + diepctl.b.nextep = 0;
  72401. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  72402. +
  72403. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  72404. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  72405. + dcfg.b.epmscnt = 2;
  72406. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  72407. +
  72408. + DWC_DEBUGPL(DBG_CILV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  72409. + __func__, core_if->first_in_nextep_seq);
  72410. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  72411. + DWC_DEBUGPL(DBG_CILV, "%2d ", core_if->nextep_seq[i]);
  72412. + }
  72413. + DWC_DEBUGPL(DBG_CILV,"\n");
  72414. + }
  72415. +
  72416. + /* Clear all pending Device Interrupts */
  72417. + /** @todo - if the condition needed to be checked
  72418. + * or in any case all pending interrutps should be cleared?
  72419. + */
  72420. + if (core_if->multiproc_int_enable) {
  72421. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  72422. + DWC_WRITE_REG32(&dev_if->
  72423. + dev_global_regs->diepeachintmsk[i], 0);
  72424. + }
  72425. + }
  72426. +
  72427. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  72428. + DWC_WRITE_REG32(&dev_if->
  72429. + dev_global_regs->doepeachintmsk[i], 0);
  72430. + }
  72431. +
  72432. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
  72433. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk, 0);
  72434. + } else {
  72435. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, 0);
  72436. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, 0);
  72437. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
  72438. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk, 0);
  72439. + }
  72440. +
  72441. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  72442. + depctl_data_t depctl;
  72443. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  72444. + if (depctl.b.epena) {
  72445. + depctl.d32 = 0;
  72446. + depctl.b.epdis = 1;
  72447. + depctl.b.snak = 1;
  72448. + } else {
  72449. + depctl.d32 = 0;
  72450. + }
  72451. +
  72452. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  72453. +
  72454. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
  72455. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, 0);
  72456. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
  72457. + }
  72458. +
  72459. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  72460. + depctl_data_t depctl;
  72461. + depctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  72462. + if (depctl.b.epena) {
  72463. + dctl_data_t dctl = {.d32 = 0 };
  72464. + gintmsk_data_t gintsts = {.d32 = 0 };
  72465. + doepint_data_t doepint = {.d32 = 0 };
  72466. + dctl.b.sgoutnak = 1;
  72467. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  72468. + do {
  72469. + dwc_udelay(10);
  72470. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  72471. + } while (!gintsts.b.goutnakeff);
  72472. + gintsts.d32 = 0;
  72473. + gintsts.b.goutnakeff = 1;
  72474. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  72475. +
  72476. + depctl.d32 = 0;
  72477. + depctl.b.epdis = 1;
  72478. + depctl.b.snak = 1;
  72479. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  72480. + do {
  72481. + dwc_udelay(10);
  72482. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  72483. + out_ep_regs[i]->doepint);
  72484. + } while (!doepint.b.epdisabled);
  72485. +
  72486. + doepint.b.epdisabled = 1;
  72487. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepint, doepint.d32);
  72488. +
  72489. + dctl.d32 = 0;
  72490. + dctl.b.cgoutnak = 1;
  72491. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  72492. + } else {
  72493. + depctl.d32 = 0;
  72494. + }
  72495. +
  72496. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  72497. +
  72498. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
  72499. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepdma, 0);
  72500. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
  72501. + }
  72502. +
  72503. + if (core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  72504. + dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
  72505. + dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
  72506. + dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
  72507. +
  72508. + dev_if->rx_thr_length = params->rx_thr_length;
  72509. + dev_if->tx_thr_length = params->tx_thr_length;
  72510. +
  72511. + dev_if->setup_desc_index = 0;
  72512. +
  72513. + dthrctl.d32 = 0;
  72514. + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
  72515. + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
  72516. + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
  72517. + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
  72518. + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
  72519. + dthrctl.b.ahb_thr_ratio = params->ahb_thr_ratio;
  72520. +
  72521. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dtknqr3_dthrctl,
  72522. + dthrctl.d32);
  72523. +
  72524. + DWC_DEBUGPL(DBG_CIL,
  72525. + "Non ISO Tx Thr - %d\nISO Tx Thr - %d\nRx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
  72526. + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
  72527. + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
  72528. + dthrctl.b.rx_thr_len);
  72529. +
  72530. + }
  72531. +
  72532. + dwc_otg_enable_device_interrupts(core_if);
  72533. +
  72534. + {
  72535. + diepmsk_data_t msk = {.d32 = 0 };
  72536. + msk.b.txfifoundrn = 1;
  72537. + if (core_if->multiproc_int_enable) {
  72538. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->
  72539. + diepeachintmsk[0], msk.d32, msk.d32);
  72540. + } else {
  72541. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk,
  72542. + msk.d32, msk.d32);
  72543. + }
  72544. + }
  72545. +
  72546. + if (core_if->multiproc_int_enable) {
  72547. + /* Set NAK on Babble */
  72548. + dctl_data_t dctl = {.d32 = 0 };
  72549. + dctl.b.nakonbble = 1;
  72550. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  72551. + }
  72552. +
  72553. + if (core_if->snpsid >= OTG_CORE_REV_2_94a) {
  72554. + dctl_data_t dctl = {.d32 = 0 };
  72555. + dctl.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  72556. + dctl.b.sftdiscon = 0;
  72557. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl, dctl.d32);
  72558. + }
  72559. +}
  72560. +
  72561. +/**
  72562. + * This function enables the Host mode interrupts.
  72563. + *
  72564. + * @param core_if Programming view of DWC_otg controller
  72565. + */
  72566. +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * core_if)
  72567. +{
  72568. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  72569. + gintmsk_data_t intr_mask = {.d32 = 0 };
  72570. +
  72571. + DWC_DEBUGPL(DBG_CIL, "%s(%p)\n", __func__, core_if);
  72572. +
  72573. + /* Disable all interrupts. */
  72574. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  72575. +
  72576. + /* Clear any pending interrupts. */
  72577. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  72578. +
  72579. + /* Enable the common interrupts */
  72580. + dwc_otg_enable_common_interrupts(core_if);
  72581. +
  72582. + /*
  72583. + * Enable host mode interrupts without disturbing common
  72584. + * interrupts.
  72585. + */
  72586. +
  72587. + intr_mask.b.disconnect = 1;
  72588. + intr_mask.b.portintr = 1;
  72589. + intr_mask.b.hcintr = 1;
  72590. +
  72591. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  72592. +}
  72593. +
  72594. +/**
  72595. + * This function disables the Host Mode interrupts.
  72596. + *
  72597. + * @param core_if Programming view of DWC_otg controller
  72598. + */
  72599. +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * core_if)
  72600. +{
  72601. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  72602. + gintmsk_data_t intr_mask = {.d32 = 0 };
  72603. +
  72604. + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
  72605. +
  72606. + /*
  72607. + * Disable host mode interrupts without disturbing common
  72608. + * interrupts.
  72609. + */
  72610. + intr_mask.b.sofintr = 1;
  72611. + intr_mask.b.portintr = 1;
  72612. + intr_mask.b.hcintr = 1;
  72613. + intr_mask.b.ptxfempty = 1;
  72614. + intr_mask.b.nptxfempty = 1;
  72615. +
  72616. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, 0);
  72617. +}
  72618. +
  72619. +/**
  72620. + * This function initializes the DWC_otg controller registers for
  72621. + * host mode.
  72622. + *
  72623. + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
  72624. + * request queues. Host channels are reset to ensure that they are ready for
  72625. + * performing transfers.
  72626. + *
  72627. + * @param core_if Programming view of DWC_otg controller
  72628. + *
  72629. + */
  72630. +void dwc_otg_core_host_init(dwc_otg_core_if_t * core_if)
  72631. +{
  72632. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  72633. + dwc_otg_host_if_t *host_if = core_if->host_if;
  72634. + dwc_otg_core_params_t *params = core_if->core_params;
  72635. + hprt0_data_t hprt0 = {.d32 = 0 };
  72636. + fifosize_data_t nptxfifosize;
  72637. + fifosize_data_t ptxfifosize;
  72638. + uint16_t rxfsiz, nptxfsiz, hptxfsiz;
  72639. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  72640. + int i;
  72641. + hcchar_data_t hcchar;
  72642. + hcfg_data_t hcfg;
  72643. + hfir_data_t hfir;
  72644. + dwc_otg_hc_regs_t *hc_regs;
  72645. + int num_channels;
  72646. + gotgctl_data_t gotgctl = {.d32 = 0 };
  72647. +
  72648. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  72649. +
  72650. + /* Restart the Phy Clock */
  72651. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  72652. +
  72653. + /* Initialize Host Configuration Register */
  72654. + init_fslspclksel(core_if);
  72655. + if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  72656. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  72657. + hcfg.b.fslssupp = 1;
  72658. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  72659. +
  72660. + }
  72661. +
  72662. + /* This bit allows dynamic reloading of the HFIR register
  72663. + * during runtime. This bit needs to be programmed during
  72664. + * initial configuration and its value must not be changed
  72665. + * during runtime.*/
  72666. + if (core_if->core_params->reload_ctl == 1) {
  72667. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  72668. + hfir.b.hfirrldctrl = 1;
  72669. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  72670. + }
  72671. +
  72672. + if (core_if->core_params->dma_desc_enable) {
  72673. + uint8_t op_mode = core_if->hwcfg2.b.op_mode;
  72674. + if (!
  72675. + (core_if->hwcfg4.b.desc_dma
  72676. + && (core_if->snpsid >= OTG_CORE_REV_2_90a)
  72677. + && ((op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  72678. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  72679. + || (op_mode ==
  72680. + DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG)
  72681. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)
  72682. + || (op_mode ==
  72683. + DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST)))) {
  72684. +
  72685. + DWC_ERROR("Host can't operate in Descriptor DMA mode.\n"
  72686. + "Either core version is below 2.90a or "
  72687. + "GHWCFG2, GHWCFG4 registers' values do not allow Descriptor DMA in host mode.\n"
  72688. + "To run the driver in Buffer DMA host mode set dma_desc_enable "
  72689. + "module parameter to 0.\n");
  72690. + return;
  72691. + }
  72692. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  72693. + hcfg.b.descdma = 1;
  72694. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  72695. + }
  72696. +
  72697. + /* Configure data FIFO sizes */
  72698. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  72699. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  72700. + core_if->total_fifo_size);
  72701. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  72702. + params->host_rx_fifo_size);
  72703. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  72704. + params->host_nperio_tx_fifo_size);
  72705. + DWC_DEBUGPL(DBG_CIL, "P Tx FIFO Size=%d\n",
  72706. + params->host_perio_tx_fifo_size);
  72707. +
  72708. + /* Rx FIFO */
  72709. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  72710. + DWC_READ_REG32(&global_regs->grxfsiz));
  72711. + DWC_WRITE_REG32(&global_regs->grxfsiz,
  72712. + params->host_rx_fifo_size);
  72713. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  72714. + DWC_READ_REG32(&global_regs->grxfsiz));
  72715. +
  72716. + /* Non-periodic Tx FIFO */
  72717. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  72718. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  72719. + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
  72720. + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
  72721. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  72722. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  72723. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  72724. +
  72725. + /* Periodic Tx FIFO */
  72726. + DWC_DEBUGPL(DBG_CIL, "initial hptxfsiz=%08x\n",
  72727. + DWC_READ_REG32(&global_regs->hptxfsiz));
  72728. + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
  72729. + ptxfifosize.b.startaddr =
  72730. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  72731. + DWC_WRITE_REG32(&global_regs->hptxfsiz, ptxfifosize.d32);
  72732. + DWC_DEBUGPL(DBG_CIL, "new hptxfsiz=%08x\n",
  72733. + DWC_READ_REG32(&global_regs->hptxfsiz));
  72734. +
  72735. + if (core_if->en_multiple_tx_fifo
  72736. + && core_if->snpsid <= OTG_CORE_REV_2_94a) {
  72737. + /* Global DFIFOCFG calculation for Host mode - include RxFIFO, NPTXFIFO and HPTXFIFO */
  72738. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  72739. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  72740. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  72741. + hptxfsiz = (DWC_READ_REG32(&global_regs->hptxfsiz) >> 16);
  72742. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz + hptxfsiz;
  72743. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  72744. + }
  72745. + }
  72746. +
  72747. + /* TODO - check this */
  72748. + /* Clear Host Set HNP Enable in the OTG Control Register */
  72749. + gotgctl.b.hstsethnpen = 1;
  72750. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  72751. + /* Make sure the FIFOs are flushed. */
  72752. + dwc_otg_flush_tx_fifo(core_if, 0x10 /* all TX FIFOs */ );
  72753. + dwc_otg_flush_rx_fifo(core_if);
  72754. +
  72755. + /* Clear Host Set HNP Enable in the OTG Control Register */
  72756. + gotgctl.b.hstsethnpen = 1;
  72757. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  72758. +
  72759. + if (!core_if->core_params->dma_desc_enable) {
  72760. + /* Flush out any leftover queued requests. */
  72761. + num_channels = core_if->core_params->host_channels;
  72762. +
  72763. + for (i = 0; i < num_channels; i++) {
  72764. + hc_regs = core_if->host_if->hc_regs[i];
  72765. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72766. + hcchar.b.chen = 0;
  72767. + hcchar.b.chdis = 1;
  72768. + hcchar.b.epdir = 0;
  72769. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  72770. + }
  72771. +
  72772. + /* Halt all channels to put them into a known state. */
  72773. + for (i = 0; i < num_channels; i++) {
  72774. + int count = 0;
  72775. + hc_regs = core_if->host_if->hc_regs[i];
  72776. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72777. + hcchar.b.chen = 1;
  72778. + hcchar.b.chdis = 1;
  72779. + hcchar.b.epdir = 0;
  72780. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  72781. + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d regs %p\n", __func__, i, hc_regs);
  72782. + do {
  72783. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72784. + if (++count > 1000) {
  72785. + DWC_ERROR
  72786. + ("%s: Unable to clear halt on channel %d (timeout HCCHAR 0x%X @%p)\n",
  72787. + __func__, i, hcchar.d32, &hc_regs->hcchar);
  72788. + break;
  72789. + }
  72790. + dwc_udelay(1);
  72791. + } while (hcchar.b.chen);
  72792. + }
  72793. + }
  72794. +
  72795. + /* Turn on the vbus power. */
  72796. + DWC_PRINTF("Init: Port Power? op_state=%d\n", core_if->op_state);
  72797. + if (core_if->op_state == A_HOST) {
  72798. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72799. + DWC_PRINTF("Init: Power Port (%d)\n", hprt0.b.prtpwr);
  72800. + if (hprt0.b.prtpwr == 0) {
  72801. + hprt0.b.prtpwr = 1;
  72802. + DWC_WRITE_REG32(host_if->hprt0, hprt0.d32);
  72803. + }
  72804. + }
  72805. +
  72806. + dwc_otg_enable_host_interrupts(core_if);
  72807. +}
  72808. +
  72809. +/**
  72810. + * Prepares a host channel for transferring packets to/from a specific
  72811. + * endpoint. The HCCHARn register is set up with the characteristics specified
  72812. + * in _hc. Host channel interrupts that may need to be serviced while this
  72813. + * transfer is in progress are enabled.
  72814. + *
  72815. + * @param core_if Programming view of DWC_otg controller
  72816. + * @param hc Information needed to initialize the host channel
  72817. + */
  72818. +void dwc_otg_hc_init(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  72819. +{
  72820. + hcintmsk_data_t hc_intr_mask;
  72821. + hcchar_data_t hcchar;
  72822. + hcsplt_data_t hcsplt;
  72823. +
  72824. + uint8_t hc_num = hc->hc_num;
  72825. + dwc_otg_host_if_t *host_if = core_if->host_if;
  72826. + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
  72827. +
  72828. + /* Clear old interrupt conditions for this host channel. */
  72829. + hc_intr_mask.d32 = 0xFFFFFFFF;
  72830. + hc_intr_mask.b.reserved14_31 = 0;
  72831. + DWC_WRITE_REG32(&hc_regs->hcint, hc_intr_mask.d32);
  72832. +
  72833. + /* Enable channel interrupts required for this transfer. */
  72834. + hc_intr_mask.d32 = 0;
  72835. + hc_intr_mask.b.chhltd = 1;
  72836. + if (core_if->dma_enable) {
  72837. + /* For Descriptor DMA mode core halts the channel on AHB error. Interrupt is not required */
  72838. + if (!core_if->dma_desc_enable)
  72839. + hc_intr_mask.b.ahberr = 1;
  72840. + else {
  72841. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  72842. + hc_intr_mask.b.xfercompl = 1;
  72843. + }
  72844. +
  72845. + if (hc->error_state && !hc->do_split &&
  72846. + hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  72847. + hc_intr_mask.b.ack = 1;
  72848. + if (hc->ep_is_in) {
  72849. + hc_intr_mask.b.datatglerr = 1;
  72850. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  72851. + hc_intr_mask.b.nak = 1;
  72852. + }
  72853. + }
  72854. + }
  72855. + } else {
  72856. + switch (hc->ep_type) {
  72857. + case DWC_OTG_EP_TYPE_CONTROL:
  72858. + case DWC_OTG_EP_TYPE_BULK:
  72859. + hc_intr_mask.b.xfercompl = 1;
  72860. + hc_intr_mask.b.stall = 1;
  72861. + hc_intr_mask.b.xacterr = 1;
  72862. + hc_intr_mask.b.datatglerr = 1;
  72863. + if (hc->ep_is_in) {
  72864. + hc_intr_mask.b.bblerr = 1;
  72865. + } else {
  72866. + hc_intr_mask.b.nak = 1;
  72867. + hc_intr_mask.b.nyet = 1;
  72868. + if (hc->do_ping) {
  72869. + hc_intr_mask.b.ack = 1;
  72870. + }
  72871. + }
  72872. +
  72873. + if (hc->do_split) {
  72874. + hc_intr_mask.b.nak = 1;
  72875. + if (hc->complete_split) {
  72876. + hc_intr_mask.b.nyet = 1;
  72877. + } else {
  72878. + hc_intr_mask.b.ack = 1;
  72879. + }
  72880. + }
  72881. +
  72882. + if (hc->error_state) {
  72883. + hc_intr_mask.b.ack = 1;
  72884. + }
  72885. + break;
  72886. + case DWC_OTG_EP_TYPE_INTR:
  72887. + hc_intr_mask.b.xfercompl = 1;
  72888. + hc_intr_mask.b.nak = 1;
  72889. + hc_intr_mask.b.stall = 1;
  72890. + hc_intr_mask.b.xacterr = 1;
  72891. + hc_intr_mask.b.datatglerr = 1;
  72892. + hc_intr_mask.b.frmovrun = 1;
  72893. +
  72894. + if (hc->ep_is_in) {
  72895. + hc_intr_mask.b.bblerr = 1;
  72896. + }
  72897. + if (hc->error_state) {
  72898. + hc_intr_mask.b.ack = 1;
  72899. + }
  72900. + if (hc->do_split) {
  72901. + if (hc->complete_split) {
  72902. + hc_intr_mask.b.nyet = 1;
  72903. + } else {
  72904. + hc_intr_mask.b.ack = 1;
  72905. + }
  72906. + }
  72907. + break;
  72908. + case DWC_OTG_EP_TYPE_ISOC:
  72909. + hc_intr_mask.b.xfercompl = 1;
  72910. + hc_intr_mask.b.frmovrun = 1;
  72911. + hc_intr_mask.b.ack = 1;
  72912. +
  72913. + if (hc->ep_is_in) {
  72914. + hc_intr_mask.b.xacterr = 1;
  72915. + hc_intr_mask.b.bblerr = 1;
  72916. + }
  72917. + break;
  72918. + }
  72919. + }
  72920. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hc_intr_mask.d32);
  72921. +
  72922. + /*
  72923. + * Program the HCCHARn register with the endpoint characteristics for
  72924. + * the current transfer.
  72925. + */
  72926. + hcchar.d32 = 0;
  72927. + hcchar.b.devaddr = hc->dev_addr;
  72928. + hcchar.b.epnum = hc->ep_num;
  72929. + hcchar.b.epdir = hc->ep_is_in;
  72930. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  72931. + hcchar.b.eptype = hc->ep_type;
  72932. + hcchar.b.mps = hc->max_packet;
  72933. +
  72934. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
  72935. +
  72936. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d, Dev Addr %d, EP #%d\n",
  72937. + __func__, hc->hc_num, hcchar.b.devaddr, hcchar.b.epnum);
  72938. + DWC_DEBUGPL(DBG_HCDV, " Is In %d, Is Low Speed %d, EP Type %d, "
  72939. + "Max Pkt %d, Multi Cnt %d\n",
  72940. + hcchar.b.epdir, hcchar.b.lspddev, hcchar.b.eptype,
  72941. + hcchar.b.mps, hcchar.b.multicnt);
  72942. +
  72943. + /*
  72944. + * Program the HCSPLIT register for SPLITs
  72945. + */
  72946. + hcsplt.d32 = 0;
  72947. + if (hc->do_split) {
  72948. + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n",
  72949. + hc->hc_num,
  72950. + hc->complete_split ? "CSPLIT" : "SSPLIT");
  72951. + hcsplt.b.compsplt = hc->complete_split;
  72952. + hcsplt.b.xactpos = hc->xact_pos;
  72953. + hcsplt.b.hubaddr = hc->hub_addr;
  72954. + hcsplt.b.prtaddr = hc->port_addr;
  72955. + DWC_DEBUGPL(DBG_HCDV, "\t comp split %d\n", hc->complete_split);
  72956. + DWC_DEBUGPL(DBG_HCDV, "\t xact pos %d\n", hc->xact_pos);
  72957. + DWC_DEBUGPL(DBG_HCDV, "\t hub addr %d\n", hc->hub_addr);
  72958. + DWC_DEBUGPL(DBG_HCDV, "\t port addr %d\n", hc->port_addr);
  72959. + DWC_DEBUGPL(DBG_HCDV, "\t is_in %d\n", hc->ep_is_in);
  72960. + DWC_DEBUGPL(DBG_HCDV, "\t Max Pkt: %d\n", hcchar.b.mps);
  72961. + DWC_DEBUGPL(DBG_HCDV, "\t xferlen: %d\n", hc->xfer_len);
  72962. + }
  72963. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
  72964. +
  72965. +}
  72966. +
  72967. +/**
  72968. + * Attempts to halt a host channel. This function should only be called in
  72969. + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
  72970. + * normal circumstances in DMA mode, the controller halts the channel when the
  72971. + * transfer is complete or a condition occurs that requires application
  72972. + * intervention.
  72973. + *
  72974. + * In slave mode, checks for a free request queue entry, then sets the Channel
  72975. + * Enable and Channel Disable bits of the Host Channel Characteristics
  72976. + * register of the specified channel to intiate the halt. If there is no free
  72977. + * request queue entry, sets only the Channel Disable bit of the HCCHARn
  72978. + * register to flush requests for this channel. In the latter case, sets a
  72979. + * flag to indicate that the host channel needs to be halted when a request
  72980. + * queue slot is open.
  72981. + *
  72982. + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
  72983. + * HCCHARn register. The controller ensures there is space in the request
  72984. + * queue before submitting the halt request.
  72985. + *
  72986. + * Some time may elapse before the core flushes any posted requests for this
  72987. + * host channel and halts. The Channel Halted interrupt handler completes the
  72988. + * deactivation of the host channel.
  72989. + *
  72990. + * @param core_if Controller register interface.
  72991. + * @param hc Host channel to halt.
  72992. + * @param halt_status Reason for halting the channel.
  72993. + */
  72994. +void dwc_otg_hc_halt(dwc_otg_core_if_t * core_if,
  72995. + dwc_hc_t * hc, dwc_otg_halt_status_e halt_status)
  72996. +{
  72997. + gnptxsts_data_t nptxsts;
  72998. + hptxsts_data_t hptxsts;
  72999. + hcchar_data_t hcchar;
  73000. + dwc_otg_hc_regs_t *hc_regs;
  73001. + dwc_otg_core_global_regs_t *global_regs;
  73002. + dwc_otg_host_global_regs_t *host_global_regs;
  73003. +
  73004. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  73005. + global_regs = core_if->core_global_regs;
  73006. + host_global_regs = core_if->host_if->host_global_regs;
  73007. +
  73008. + DWC_ASSERT(!(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS),
  73009. + "halt_status = %d\n", halt_status);
  73010. +
  73011. + if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  73012. + halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  73013. + /*
  73014. + * Disable all channel interrupts except Ch Halted. The QTD
  73015. + * and QH state associated with this transfer has been cleared
  73016. + * (in the case of URB_DEQUEUE), so the channel needs to be
  73017. + * shut down carefully to prevent crashes.
  73018. + */
  73019. + hcintmsk_data_t hcintmsk;
  73020. + hcintmsk.d32 = 0;
  73021. + hcintmsk.b.chhltd = 1;
  73022. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hcintmsk.d32);
  73023. +
  73024. + /*
  73025. + * Make sure no other interrupts besides halt are currently
  73026. + * pending. Handling another interrupt could cause a crash due
  73027. + * to the QTD and QH state.
  73028. + */
  73029. + DWC_WRITE_REG32(&hc_regs->hcint, ~hcintmsk.d32);
  73030. +
  73031. + /*
  73032. + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
  73033. + * even if the channel was already halted for some other
  73034. + * reason.
  73035. + */
  73036. + hc->halt_status = halt_status;
  73037. +
  73038. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73039. + if (hcchar.b.chen == 0) {
  73040. + /*
  73041. + * The channel is either already halted or it hasn't
  73042. + * started yet. In DMA mode, the transfer may halt if
  73043. + * it finishes normally or a condition occurs that
  73044. + * requires driver intervention. Don't want to halt
  73045. + * the channel again. In either Slave or DMA mode,
  73046. + * it's possible that the transfer has been assigned
  73047. + * to a channel, but not started yet when an URB is
  73048. + * dequeued. Don't want to halt a channel that hasn't
  73049. + * started yet.
  73050. + */
  73051. + return;
  73052. + }
  73053. + }
  73054. + if (hc->halt_pending) {
  73055. + /*
  73056. + * A halt has already been issued for this channel. This might
  73057. + * happen when a transfer is aborted by a higher level in
  73058. + * the stack.
  73059. + */
  73060. +#ifdef DEBUG
  73061. + DWC_PRINTF
  73062. + ("*** %s: Channel %d, _hc->halt_pending already set ***\n",
  73063. + __func__, hc->hc_num);
  73064. +
  73065. +#endif
  73066. + return;
  73067. + }
  73068. +
  73069. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73070. +
  73071. + /* No need to set the bit in DDMA for disabling the channel */
  73072. + //TODO check it everywhere channel is disabled
  73073. + if (!core_if->core_params->dma_desc_enable)
  73074. + hcchar.b.chen = 1;
  73075. + hcchar.b.chdis = 1;
  73076. +
  73077. + if (!core_if->dma_enable) {
  73078. + /* Check for space in the request queue to issue the halt. */
  73079. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  73080. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  73081. + nptxsts.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  73082. + if (nptxsts.b.nptxqspcavail == 0) {
  73083. + hcchar.b.chen = 0;
  73084. + }
  73085. + } else {
  73086. + hptxsts.d32 =
  73087. + DWC_READ_REG32(&host_global_regs->hptxsts);
  73088. + if ((hptxsts.b.ptxqspcavail == 0)
  73089. + || (core_if->queuing_high_bandwidth)) {
  73090. + hcchar.b.chen = 0;
  73091. + }
  73092. + }
  73093. + }
  73094. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73095. +
  73096. + hc->halt_status = halt_status;
  73097. +
  73098. + if (hcchar.b.chen) {
  73099. + hc->halt_pending = 1;
  73100. + hc->halt_on_queue = 0;
  73101. + } else {
  73102. + hc->halt_on_queue = 1;
  73103. + }
  73104. +
  73105. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  73106. + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
  73107. + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
  73108. + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
  73109. + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
  73110. +
  73111. + return;
  73112. +}
  73113. +
  73114. +/**
  73115. + * Clears the transfer state for a host channel. This function is normally
  73116. + * called after a transfer is done and the host channel is being released.
  73117. + *
  73118. + * @param core_if Programming view of DWC_otg controller.
  73119. + * @param hc Identifies the host channel to clean up.
  73120. + */
  73121. +void dwc_otg_hc_cleanup(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  73122. +{
  73123. + dwc_otg_hc_regs_t *hc_regs;
  73124. +
  73125. + hc->xfer_started = 0;
  73126. +
  73127. + /*
  73128. + * Clear channel interrupt enables and any unhandled channel interrupt
  73129. + * conditions.
  73130. + */
  73131. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  73132. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0);
  73133. + DWC_WRITE_REG32(&hc_regs->hcint, 0xFFFFFFFF);
  73134. +#ifdef DEBUG
  73135. + DWC_TIMER_CANCEL(core_if->hc_xfer_timer[hc->hc_num]);
  73136. +#endif
  73137. +}
  73138. +
  73139. +/**
  73140. + * Sets the channel property that indicates in which frame a periodic transfer
  73141. + * should occur. This is always set to the _next_ frame. This function has no
  73142. + * effect on non-periodic transfers.
  73143. + *
  73144. + * @param core_if Programming view of DWC_otg controller.
  73145. + * @param hc Identifies the host channel to set up and its properties.
  73146. + * @param hcchar Current value of the HCCHAR register for the specified host
  73147. + * channel.
  73148. + */
  73149. +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t * core_if,
  73150. + dwc_hc_t * hc, hcchar_data_t * hcchar)
  73151. +{
  73152. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  73153. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  73154. + hfnum_data_t hfnum;
  73155. + hfnum.d32 =
  73156. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfnum);
  73157. +
  73158. + /* 1 if _next_ frame is odd, 0 if it's even */
  73159. + hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  73160. +#ifdef DEBUG
  73161. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split
  73162. + && !hc->complete_split) {
  73163. + switch (hfnum.b.frnum & 0x7) {
  73164. + case 7:
  73165. + core_if->hfnum_7_samples++;
  73166. + core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
  73167. + break;
  73168. + case 0:
  73169. + core_if->hfnum_0_samples++;
  73170. + core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
  73171. + break;
  73172. + default:
  73173. + core_if->hfnum_other_samples++;
  73174. + core_if->hfnum_other_frrem_accum +=
  73175. + hfnum.b.frrem;
  73176. + break;
  73177. + }
  73178. + }
  73179. +#endif
  73180. + }
  73181. +}
  73182. +
  73183. +#ifdef DEBUG
  73184. +void hc_xfer_timeout(void *ptr)
  73185. +{
  73186. + hc_xfer_info_t *xfer_info = NULL;
  73187. + int hc_num = 0;
  73188. +
  73189. + if (ptr)
  73190. + xfer_info = (hc_xfer_info_t *) ptr;
  73191. +
  73192. + if (!xfer_info->hc) {
  73193. + DWC_ERROR("xfer_info->hc = %p\n", xfer_info->hc);
  73194. + return;
  73195. + }
  73196. +
  73197. + hc_num = xfer_info->hc->hc_num;
  73198. + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
  73199. + DWC_WARN(" start_hcchar_val 0x%08x\n",
  73200. + xfer_info->core_if->start_hcchar_val[hc_num]);
  73201. +}
  73202. +#endif
  73203. +
  73204. +void ep_xfer_timeout(void *ptr)
  73205. +{
  73206. + ep_xfer_info_t *xfer_info = NULL;
  73207. + int ep_num = 0;
  73208. + dctl_data_t dctl = {.d32 = 0 };
  73209. + gintsts_data_t gintsts = {.d32 = 0 };
  73210. + gintmsk_data_t gintmsk = {.d32 = 0 };
  73211. +
  73212. + if (ptr)
  73213. + xfer_info = (ep_xfer_info_t *) ptr;
  73214. +
  73215. + if (!xfer_info->ep) {
  73216. + DWC_ERROR("xfer_info->ep = %p\n", xfer_info->ep);
  73217. + return;
  73218. + }
  73219. +
  73220. + ep_num = xfer_info->ep->num;
  73221. + DWC_WARN("%s: timeout on endpoit %d\n", __func__, ep_num);
  73222. + /* Put the sate to 2 as it was time outed */
  73223. + xfer_info->state = 2;
  73224. +
  73225. + dctl.d32 =
  73226. + DWC_READ_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl);
  73227. + gintsts.d32 =
  73228. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintsts);
  73229. + gintmsk.d32 =
  73230. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintmsk);
  73231. +
  73232. + if (!gintmsk.b.goutnakeff) {
  73233. + /* Unmask it */
  73234. + gintmsk.b.goutnakeff = 1;
  73235. + DWC_WRITE_REG32(&xfer_info->core_if->core_global_regs->gintmsk,
  73236. + gintmsk.d32);
  73237. +
  73238. + }
  73239. +
  73240. + if (!gintsts.b.goutnakeff) {
  73241. + dctl.b.sgoutnak = 1;
  73242. + }
  73243. + DWC_WRITE_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl,
  73244. + dctl.d32);
  73245. +
  73246. +}
  73247. +
  73248. +void set_pid_isoc(dwc_hc_t * hc)
  73249. +{
  73250. + /* Set up the initial PID for the transfer. */
  73251. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  73252. + if (hc->ep_is_in) {
  73253. + if (hc->multi_count == 1) {
  73254. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  73255. + } else if (hc->multi_count == 2) {
  73256. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  73257. + } else {
  73258. + hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
  73259. + }
  73260. + } else {
  73261. + if (hc->multi_count == 1) {
  73262. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  73263. + } else {
  73264. + hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
  73265. + }
  73266. + }
  73267. + } else {
  73268. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  73269. + }
  73270. +}
  73271. +
  73272. +/**
  73273. + * This function does the setup for a data transfer for a host channel and
  73274. + * starts the transfer. May be called in either Slave mode or DMA mode. In
  73275. + * Slave mode, the caller must ensure that there is sufficient space in the
  73276. + * request queue and Tx Data FIFO.
  73277. + *
  73278. + * For an OUT transfer in Slave mode, it loads a data packet into the
  73279. + * appropriate FIFO. If necessary, additional data packets will be loaded in
  73280. + * the Host ISR.
  73281. + *
  73282. + * For an IN transfer in Slave mode, a data packet is requested. The data
  73283. + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
  73284. + * additional data packets are requested in the Host ISR.
  73285. + *
  73286. + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
  73287. + * register along with a packet count of 1 and the channel is enabled. This
  73288. + * causes a single PING transaction to occur. Other fields in HCTSIZ are
  73289. + * simply set to 0 since no data transfer occurs in this case.
  73290. + *
  73291. + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
  73292. + * all the information required to perform the subsequent data transfer. In
  73293. + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
  73294. + * controller performs the entire PING protocol, then starts the data
  73295. + * transfer.
  73296. + *
  73297. + * @param core_if Programming view of DWC_otg controller.
  73298. + * @param hc Information needed to initialize the host channel. The xfer_len
  73299. + * value may be reduced to accommodate the max widths of the XferSize and
  73300. + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
  73301. + * to reflect the final xfer_len value.
  73302. + */
  73303. +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  73304. +{
  73305. + hcchar_data_t hcchar;
  73306. + hctsiz_data_t hctsiz;
  73307. + uint16_t num_packets;
  73308. + uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
  73309. + uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
  73310. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  73311. +
  73312. + hctsiz.d32 = 0;
  73313. +
  73314. + if (hc->do_ping) {
  73315. + if (!core_if->dma_enable) {
  73316. + dwc_otg_hc_do_ping(core_if, hc);
  73317. + hc->xfer_started = 1;
  73318. + return;
  73319. + } else {
  73320. + hctsiz.b.dopng = 1;
  73321. + }
  73322. + }
  73323. +
  73324. + if (hc->do_split) {
  73325. + num_packets = 1;
  73326. +
  73327. + if (hc->complete_split && !hc->ep_is_in) {
  73328. + /* For CSPLIT OUT Transfer, set the size to 0 so the
  73329. + * core doesn't expect any data written to the FIFO */
  73330. + hc->xfer_len = 0;
  73331. + } else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  73332. + hc->xfer_len = hc->max_packet;
  73333. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  73334. + hc->xfer_len = 188;
  73335. + }
  73336. +
  73337. + hctsiz.b.xfersize = hc->xfer_len;
  73338. + } else {
  73339. + /*
  73340. + * Ensure that the transfer length and packet count will fit
  73341. + * in the widths allocated for them in the HCTSIZn register.
  73342. + */
  73343. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  73344. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  73345. + /*
  73346. + * Make sure the transfer size is no larger than one
  73347. + * (micro)frame's worth of data. (A check was done
  73348. + * when the periodic transfer was accepted to ensure
  73349. + * that a (micro)frame's worth of data can be
  73350. + * programmed into a channel.)
  73351. + */
  73352. + uint32_t max_periodic_len =
  73353. + hc->multi_count * hc->max_packet;
  73354. + if (hc->xfer_len > max_periodic_len) {
  73355. + hc->xfer_len = max_periodic_len;
  73356. + } else {
  73357. + }
  73358. + } else if (hc->xfer_len > max_hc_xfer_size) {
  73359. + /* Make sure that xfer_len is a multiple of max packet size. */
  73360. + hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
  73361. + }
  73362. +
  73363. + if (hc->xfer_len > 0) {
  73364. + num_packets =
  73365. + (hc->xfer_len + hc->max_packet -
  73366. + 1) / hc->max_packet;
  73367. + if (num_packets > max_hc_pkt_count) {
  73368. + num_packets = max_hc_pkt_count;
  73369. + hc->xfer_len = num_packets * hc->max_packet;
  73370. + }
  73371. + } else {
  73372. + /* Need 1 packet for transfer length of 0. */
  73373. + num_packets = 1;
  73374. + }
  73375. +
  73376. + if (hc->ep_is_in) {
  73377. + /* Always program an integral # of max packets for IN transfers. */
  73378. + hc->xfer_len = num_packets * hc->max_packet;
  73379. + }
  73380. +
  73381. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  73382. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  73383. + /*
  73384. + * Make sure that the multi_count field matches the
  73385. + * actual transfer length.
  73386. + */
  73387. + hc->multi_count = num_packets;
  73388. + }
  73389. +
  73390. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  73391. + set_pid_isoc(hc);
  73392. +
  73393. + hctsiz.b.xfersize = hc->xfer_len;
  73394. + }
  73395. +
  73396. + hc->start_pkt_count = num_packets;
  73397. + hctsiz.b.pktcnt = num_packets;
  73398. + hctsiz.b.pid = hc->data_pid_start;
  73399. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  73400. +
  73401. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  73402. + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
  73403. + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
  73404. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  73405. +
  73406. + if (core_if->dma_enable) {
  73407. + dwc_dma_t dma_addr;
  73408. + if (hc->align_buff) {
  73409. + dma_addr = hc->align_buff;
  73410. + } else {
  73411. + dma_addr = ((unsigned long)hc->xfer_buff & 0xffffffff);
  73412. + }
  73413. + DWC_WRITE_REG32(&hc_regs->hcdma, dma_addr);
  73414. + }
  73415. +
  73416. + /* Start the split */
  73417. + if (hc->do_split) {
  73418. + hcsplt_data_t hcsplt;
  73419. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  73420. + hcsplt.b.spltena = 1;
  73421. + DWC_WRITE_REG32(&hc_regs->hcsplt, hcsplt.d32);
  73422. + }
  73423. +
  73424. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73425. + hcchar.b.multicnt = hc->multi_count;
  73426. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  73427. +#ifdef DEBUG
  73428. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  73429. + if (hcchar.b.chdis) {
  73430. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  73431. + __func__, hc->hc_num, hcchar.d32);
  73432. + }
  73433. +#endif
  73434. +
  73435. + /* Set host channel enable after all other setup is complete. */
  73436. + hcchar.b.chen = 1;
  73437. + hcchar.b.chdis = 0;
  73438. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73439. +
  73440. + hc->xfer_started = 1;
  73441. + hc->requests++;
  73442. +
  73443. + if (!core_if->dma_enable && !hc->ep_is_in && hc->xfer_len > 0) {
  73444. + /* Load OUT packet into the appropriate Tx FIFO. */
  73445. + dwc_otg_hc_write_packet(core_if, hc);
  73446. + }
  73447. +#ifdef DEBUG
  73448. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  73449. + DWC_DEBUGPL(DBG_HCDV, "transfer %d from core_if %p\n",
  73450. + hc->hc_num, core_if);//GRAYG
  73451. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  73452. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  73453. +
  73454. + /* Start a timer for this transfer. */
  73455. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  73456. + }
  73457. +#endif
  73458. +}
  73459. +
  73460. +/**
  73461. + * This function does the setup for a data transfer for a host channel
  73462. + * and starts the transfer in Descriptor DMA mode.
  73463. + *
  73464. + * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
  73465. + * Sets PID and NTD values. For periodic transfers
  73466. + * initializes SCHED_INFO field with micro-frame bitmap.
  73467. + *
  73468. + * Initializes HCDMA register with descriptor list address and CTD value
  73469. + * then starts the transfer via enabling the channel.
  73470. + *
  73471. + * @param core_if Programming view of DWC_otg controller.
  73472. + * @param hc Information needed to initialize the host channel.
  73473. + */
  73474. +void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  73475. +{
  73476. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  73477. + hcchar_data_t hcchar;
  73478. + hctsiz_data_t hctsiz;
  73479. + hcdma_data_t hcdma;
  73480. +
  73481. + hctsiz.d32 = 0;
  73482. +
  73483. + if (hc->do_ping)
  73484. + hctsiz.b_ddma.dopng = 1;
  73485. +
  73486. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  73487. + set_pid_isoc(hc);
  73488. +
  73489. + /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
  73490. + hctsiz.b_ddma.pid = hc->data_pid_start;
  73491. + hctsiz.b_ddma.ntd = hc->ntd - 1; /* 0 - 1 descriptor, 1 - 2 descriptors, etc. */
  73492. + hctsiz.b_ddma.schinfo = hc->schinfo; /* Non-zero only for high-speed interrupt endpoints */
  73493. +
  73494. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  73495. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  73496. + DWC_DEBUGPL(DBG_HCDV, " NTD: %d\n", hctsiz.b_ddma.ntd);
  73497. +
  73498. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  73499. +
  73500. + hcdma.d32 = 0;
  73501. + hcdma.b.dma_addr = ((uint32_t) hc->desc_list_addr) >> 11;
  73502. +
  73503. + /* Always start from first descriptor. */
  73504. + hcdma.b.ctd = 0;
  73505. + DWC_WRITE_REG32(&hc_regs->hcdma, hcdma.d32);
  73506. +
  73507. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73508. + hcchar.b.multicnt = hc->multi_count;
  73509. +
  73510. +#ifdef DEBUG
  73511. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  73512. + if (hcchar.b.chdis) {
  73513. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  73514. + __func__, hc->hc_num, hcchar.d32);
  73515. + }
  73516. +#endif
  73517. +
  73518. + /* Set host channel enable after all other setup is complete. */
  73519. + hcchar.b.chen = 1;
  73520. + hcchar.b.chdis = 0;
  73521. +
  73522. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73523. +
  73524. + hc->xfer_started = 1;
  73525. + hc->requests++;
  73526. +
  73527. +#ifdef DEBUG
  73528. + if ((hc->ep_type != DWC_OTG_EP_TYPE_INTR)
  73529. + && (hc->ep_type != DWC_OTG_EP_TYPE_ISOC)) {
  73530. + DWC_DEBUGPL(DBG_HCDV, "DMA transfer %d from core_if %p\n",
  73531. + hc->hc_num, core_if);//GRAYG
  73532. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  73533. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  73534. + /* Start a timer for this transfer. */
  73535. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  73536. + }
  73537. +#endif
  73538. +
  73539. +}
  73540. +
  73541. +/**
  73542. + * This function continues a data transfer that was started by previous call
  73543. + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
  73544. + * sufficient space in the request queue and Tx Data FIFO. This function
  73545. + * should only be called in Slave mode. In DMA mode, the controller acts
  73546. + * autonomously to complete transfers programmed to a host channel.
  73547. + *
  73548. + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
  73549. + * if there is any data remaining to be queued. For an IN transfer, another
  73550. + * data packet is always requested. For the SETUP phase of a control transfer,
  73551. + * this function does nothing.
  73552. + *
  73553. + * @return 1 if a new request is queued, 0 if no more requests are required
  73554. + * for this transfer.
  73555. + */
  73556. +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  73557. +{
  73558. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  73559. +
  73560. + if (hc->do_split) {
  73561. + /* SPLITs always queue just once per channel */
  73562. + return 0;
  73563. + } else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  73564. + /* SETUPs are queued only once since they can't be NAKed. */
  73565. + return 0;
  73566. + } else if (hc->ep_is_in) {
  73567. + /*
  73568. + * Always queue another request for other IN transfers. If
  73569. + * back-to-back INs are issued and NAKs are received for both,
  73570. + * the driver may still be processing the first NAK when the
  73571. + * second NAK is received. When the interrupt handler clears
  73572. + * the NAK interrupt for the first NAK, the second NAK will
  73573. + * not be seen. So we can't depend on the NAK interrupt
  73574. + * handler to requeue a NAKed request. Instead, IN requests
  73575. + * are issued each time this function is called. When the
  73576. + * transfer completes, the extra requests for the channel will
  73577. + * be flushed.
  73578. + */
  73579. + hcchar_data_t hcchar;
  73580. + dwc_otg_hc_regs_t *hc_regs =
  73581. + core_if->host_if->hc_regs[hc->hc_num];
  73582. +
  73583. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73584. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  73585. + hcchar.b.chen = 1;
  73586. + hcchar.b.chdis = 0;
  73587. + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n",
  73588. + hcchar.d32);
  73589. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73590. + hc->requests++;
  73591. + return 1;
  73592. + } else {
  73593. + /* OUT transfers. */
  73594. + if (hc->xfer_count < hc->xfer_len) {
  73595. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  73596. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  73597. + hcchar_data_t hcchar;
  73598. + dwc_otg_hc_regs_t *hc_regs;
  73599. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  73600. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73601. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  73602. + }
  73603. +
  73604. + /* Load OUT packet into the appropriate Tx FIFO. */
  73605. + dwc_otg_hc_write_packet(core_if, hc);
  73606. + hc->requests++;
  73607. + return 1;
  73608. + } else {
  73609. + return 0;
  73610. + }
  73611. + }
  73612. +}
  73613. +
  73614. +/**
  73615. + * Starts a PING transfer. This function should only be called in Slave mode.
  73616. + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
  73617. + */
  73618. +void dwc_otg_hc_do_ping(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  73619. +{
  73620. + hcchar_data_t hcchar;
  73621. + hctsiz_data_t hctsiz;
  73622. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  73623. +
  73624. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  73625. +
  73626. + hctsiz.d32 = 0;
  73627. + hctsiz.b.dopng = 1;
  73628. + hctsiz.b.pktcnt = 1;
  73629. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  73630. +
  73631. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73632. + hcchar.b.chen = 1;
  73633. + hcchar.b.chdis = 0;
  73634. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73635. +}
  73636. +
  73637. +/*
  73638. + * This function writes a packet into the Tx FIFO associated with the Host
  73639. + * Channel. For a channel associated with a non-periodic EP, the non-periodic
  73640. + * Tx FIFO is written. For a channel associated with a periodic EP, the
  73641. + * periodic Tx FIFO is written. This function should only be called in Slave
  73642. + * mode.
  73643. + *
  73644. + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
  73645. + * then number of bytes written to the Tx FIFO.
  73646. + */
  73647. +void dwc_otg_hc_write_packet(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  73648. +{
  73649. + uint32_t i;
  73650. + uint32_t remaining_count;
  73651. + uint32_t byte_count;
  73652. + uint32_t dword_count;
  73653. +
  73654. + uint32_t *data_buff = (uint32_t *) (hc->xfer_buff);
  73655. + uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
  73656. +
  73657. + remaining_count = hc->xfer_len - hc->xfer_count;
  73658. + if (remaining_count > hc->max_packet) {
  73659. + byte_count = hc->max_packet;
  73660. + } else {
  73661. + byte_count = remaining_count;
  73662. + }
  73663. +
  73664. + dword_count = (byte_count + 3) / 4;
  73665. +
  73666. + if ((((unsigned long)data_buff) & 0x3) == 0) {
  73667. + /* xfer_buff is DWORD aligned. */
  73668. + for (i = 0; i < dword_count; i++, data_buff++) {
  73669. + DWC_WRITE_REG32(data_fifo, *data_buff);
  73670. + }
  73671. + } else {
  73672. + /* xfer_buff is not DWORD aligned. */
  73673. + for (i = 0; i < dword_count; i++, data_buff++) {
  73674. + uint32_t data;
  73675. + data =
  73676. + (data_buff[0] | data_buff[1] << 8 | data_buff[2] <<
  73677. + 16 | data_buff[3] << 24);
  73678. + DWC_WRITE_REG32(data_fifo, data);
  73679. + }
  73680. + }
  73681. +
  73682. + hc->xfer_count += byte_count;
  73683. + hc->xfer_buff += byte_count;
  73684. +}
  73685. +
  73686. +/**
  73687. + * Gets the current USB frame number. This is the frame number from the last
  73688. + * SOF packet.
  73689. + */
  73690. +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * core_if)
  73691. +{
  73692. + dsts_data_t dsts;
  73693. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  73694. +
  73695. + /* read current frame/microframe number from DSTS register */
  73696. + return dsts.b.soffn;
  73697. +}
  73698. +
  73699. +/**
  73700. + * Calculates and gets the frame Interval value of HFIR register according PHY
  73701. + * type and speed.The application can modify a value of HFIR register only after
  73702. + * the Port Enable bit of the Host Port Control and Status register
  73703. + * (HPRT.PrtEnaPort) has been set.
  73704. +*/
  73705. +
  73706. +uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if)
  73707. +{
  73708. + gusbcfg_data_t usbcfg;
  73709. + hwcfg2_data_t hwcfg2;
  73710. + hprt0_data_t hprt0;
  73711. + int clock = 60; // default value
  73712. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  73713. + hwcfg2.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  73714. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  73715. + if (!usbcfg.b.physel && usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  73716. + clock = 60;
  73717. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 3)
  73718. + clock = 48;
  73719. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  73720. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  73721. + clock = 30;
  73722. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  73723. + !usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  73724. + clock = 60;
  73725. + if (usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  73726. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  73727. + clock = 48;
  73728. + if (usbcfg.b.physel && !usbcfg.b.phyif && hwcfg2.b.fs_phy_type == 2)
  73729. + clock = 48;
  73730. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 1)
  73731. + clock = 48;
  73732. + if (hprt0.b.prtspd == 0)
  73733. + /* High speed case */
  73734. + return 125 * clock;
  73735. + else
  73736. + /* FS/LS case */
  73737. + return 1000 * clock;
  73738. +}
  73739. +
  73740. +/**
  73741. + * This function reads a setup packet from the Rx FIFO into the destination
  73742. + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
  73743. + * Interrupt routine when a SETUP packet has been received in Slave mode.
  73744. + *
  73745. + * @param core_if Programming view of DWC_otg controller.
  73746. + * @param dest Destination buffer for packet data.
  73747. + */
  73748. +void dwc_otg_read_setup_packet(dwc_otg_core_if_t * core_if, uint32_t * dest)
  73749. +{
  73750. + device_grxsts_data_t status;
  73751. + /* Get the 8 bytes of a setup transaction data */
  73752. +
  73753. + /* Pop 2 DWORDS off the receive data FIFO into memory */
  73754. + dest[0] = DWC_READ_REG32(core_if->data_fifo[0]);
  73755. + dest[1] = DWC_READ_REG32(core_if->data_fifo[0]);
  73756. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  73757. + status.d32 =
  73758. + DWC_READ_REG32(&core_if->core_global_regs->grxstsp);
  73759. + DWC_DEBUGPL(DBG_ANY,
  73760. + "EP:%d BCnt:%d " "pktsts:%x Frame:%d(0x%0x)\n",
  73761. + status.b.epnum, status.b.bcnt, status.b.pktsts,
  73762. + status.b.fn, status.b.fn);
  73763. + }
  73764. +}
  73765. +
  73766. +/**
  73767. + * This function enables EP0 OUT to receive SETUP packets and configures EP0
  73768. + * IN for transmitting packets. It is normally called when the
  73769. + * "Enumeration Done" interrupt occurs.
  73770. + *
  73771. + * @param core_if Programming view of DWC_otg controller.
  73772. + * @param ep The EP0 data.
  73773. + */
  73774. +void dwc_otg_ep0_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  73775. +{
  73776. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  73777. + dsts_data_t dsts;
  73778. + depctl_data_t diepctl;
  73779. + depctl_data_t doepctl;
  73780. + dctl_data_t dctl = {.d32 = 0 };
  73781. +
  73782. + ep->stp_rollover = 0;
  73783. + /* Read the Device Status and Endpoint 0 Control registers */
  73784. + dsts.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dsts);
  73785. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  73786. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  73787. +
  73788. + /* Set the MPS of the IN EP based on the enumeration speed */
  73789. + switch (dsts.b.enumspd) {
  73790. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  73791. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  73792. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  73793. + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
  73794. + break;
  73795. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  73796. + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
  73797. + break;
  73798. + }
  73799. +
  73800. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  73801. +
  73802. + /* Enable OUT EP for receive */
  73803. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  73804. + doepctl.b.epena = 1;
  73805. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  73806. + }
  73807. +#ifdef VERBOSE
  73808. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  73809. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  73810. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  73811. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  73812. +#endif
  73813. + dctl.b.cgnpinnak = 1;
  73814. +
  73815. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  73816. + DWC_DEBUGPL(DBG_PCDV, "dctl=%0x\n",
  73817. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl));
  73818. +
  73819. +}
  73820. +
  73821. +/**
  73822. + * This function activates an EP. The Device EP control register for
  73823. + * the EP is configured as defined in the ep structure. Note: This
  73824. + * function is not used for EP0.
  73825. + *
  73826. + * @param core_if Programming view of DWC_otg controller.
  73827. + * @param ep The EP to activate.
  73828. + */
  73829. +void dwc_otg_ep_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  73830. +{
  73831. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  73832. + depctl_data_t depctl;
  73833. + volatile uint32_t *addr;
  73834. + daint_data_t daintmsk = {.d32 = 0 };
  73835. + dcfg_data_t dcfg;
  73836. + uint8_t i;
  73837. +
  73838. + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
  73839. + (ep->is_in ? "IN" : "OUT"));
  73840. +
  73841. +#ifdef DWC_UTE_PER_IO
  73842. + ep->xiso_frame_num = 0xFFFFFFFF;
  73843. + ep->xiso_active_xfers = 0;
  73844. + ep->xiso_queued_xfers = 0;
  73845. +#endif
  73846. + /* Read DEPCTLn register */
  73847. + if (ep->is_in == 1) {
  73848. + addr = &dev_if->in_ep_regs[ep->num]->diepctl;
  73849. + daintmsk.ep.in = 1 << ep->num;
  73850. + } else {
  73851. + addr = &dev_if->out_ep_regs[ep->num]->doepctl;
  73852. + daintmsk.ep.out = 1 << ep->num;
  73853. + }
  73854. +
  73855. + /* If the EP is already active don't change the EP Control
  73856. + * register. */
  73857. + depctl.d32 = DWC_READ_REG32(addr);
  73858. + if (!depctl.b.usbactep) {
  73859. + depctl.b.mps = ep->maxpacket;
  73860. + depctl.b.eptype = ep->type;
  73861. + depctl.b.txfnum = ep->tx_fifo_num;
  73862. +
  73863. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  73864. + depctl.b.setd0pid = 1; // ???
  73865. + } else {
  73866. + depctl.b.setd0pid = 1;
  73867. + }
  73868. + depctl.b.usbactep = 1;
  73869. +
  73870. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  73871. + if (!(depctl.b.eptype & 1) && (ep->is_in == 1)) { // NP IN EP
  73872. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  73873. + if (core_if->nextep_seq[i] == core_if->first_in_nextep_seq)
  73874. + break;
  73875. + }
  73876. + core_if->nextep_seq[i] = ep->num;
  73877. + core_if->nextep_seq[ep->num] = core_if->first_in_nextep_seq;
  73878. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  73879. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  73880. + dcfg.b.epmscnt++;
  73881. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  73882. +
  73883. + DWC_DEBUGPL(DBG_PCDV,
  73884. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  73885. + __func__, core_if->first_in_nextep_seq);
  73886. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  73887. + DWC_DEBUGPL(DBG_PCDV, "%2d\n",
  73888. + core_if->nextep_seq[i]);
  73889. + }
  73890. +
  73891. + }
  73892. +
  73893. +
  73894. + DWC_WRITE_REG32(addr, depctl.d32);
  73895. + DWC_DEBUGPL(DBG_PCDV, "DEPCTL=%08x\n", DWC_READ_REG32(addr));
  73896. + }
  73897. +
  73898. + /* Enable the Interrupt for this EP */
  73899. + if (core_if->multiproc_int_enable) {
  73900. + if (ep->is_in == 1) {
  73901. + diepmsk_data_t diepmsk = {.d32 = 0 };
  73902. + diepmsk.b.xfercompl = 1;
  73903. + diepmsk.b.timeout = 1;
  73904. + diepmsk.b.epdisabled = 1;
  73905. + diepmsk.b.ahberr = 1;
  73906. + diepmsk.b.intknepmis = 1;
  73907. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  73908. + diepmsk.b.intknepmis = 0;
  73909. + diepmsk.b.txfifoundrn = 1; //?????
  73910. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  73911. + diepmsk.b.nak = 1;
  73912. + }
  73913. +
  73914. +
  73915. +
  73916. +/*
  73917. + if (core_if->dma_desc_enable) {
  73918. + diepmsk.b.bna = 1;
  73919. + }
  73920. +*/
  73921. +/*
  73922. + if (core_if->dma_enable) {
  73923. + doepmsk.b.nak = 1;
  73924. + }
  73925. +*/
  73926. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  73927. + diepeachintmsk[ep->num], diepmsk.d32);
  73928. +
  73929. + } else {
  73930. + doepmsk_data_t doepmsk = {.d32 = 0 };
  73931. + doepmsk.b.xfercompl = 1;
  73932. + doepmsk.b.ahberr = 1;
  73933. + doepmsk.b.epdisabled = 1;
  73934. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  73935. + doepmsk.b.outtknepdis = 1;
  73936. +
  73937. +/*
  73938. +
  73939. + if (core_if->dma_desc_enable) {
  73940. + doepmsk.b.bna = 1;
  73941. + }
  73942. +*/
  73943. +/*
  73944. + doepmsk.b.babble = 1;
  73945. + doepmsk.b.nyet = 1;
  73946. + doepmsk.b.nak = 1;
  73947. +*/
  73948. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  73949. + doepeachintmsk[ep->num], doepmsk.d32);
  73950. + }
  73951. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->deachintmsk,
  73952. + 0, daintmsk.d32);
  73953. + } else {
  73954. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  73955. + if (ep->is_in) {
  73956. + diepmsk_data_t diepmsk = {.d32 = 0 };
  73957. + diepmsk.b.nak = 1;
  73958. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
  73959. + } else {
  73960. + doepmsk_data_t doepmsk = {.d32 = 0 };
  73961. + doepmsk.b.outtknepdis = 1;
  73962. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->doepmsk, 0, doepmsk.d32);
  73963. + }
  73964. + }
  73965. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->daintmsk,
  73966. + 0, daintmsk.d32);
  73967. + }
  73968. +
  73969. + DWC_DEBUGPL(DBG_PCDV, "DAINTMSK=%0x\n",
  73970. + DWC_READ_REG32(&dev_if->dev_global_regs->daintmsk));
  73971. +
  73972. + ep->stall_clear_flag = 0;
  73973. +
  73974. + return;
  73975. +}
  73976. +
  73977. +/**
  73978. + * This function deactivates an EP. This is done by clearing the USB Active
  73979. + * EP bit in the Device EP control register. Note: This function is not used
  73980. + * for EP0. EP0 cannot be deactivated.
  73981. + *
  73982. + * @param core_if Programming view of DWC_otg controller.
  73983. + * @param ep The EP to deactivate.
  73984. + */
  73985. +void dwc_otg_ep_deactivate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  73986. +{
  73987. + depctl_data_t depctl = {.d32 = 0 };
  73988. + volatile uint32_t *addr;
  73989. + daint_data_t daintmsk = {.d32 = 0 };
  73990. + dcfg_data_t dcfg;
  73991. + uint8_t i = 0;
  73992. +
  73993. +#ifdef DWC_UTE_PER_IO
  73994. + ep->xiso_frame_num = 0xFFFFFFFF;
  73995. + ep->xiso_active_xfers = 0;
  73996. + ep->xiso_queued_xfers = 0;
  73997. +#endif
  73998. +
  73999. + /* Read DEPCTLn register */
  74000. + if (ep->is_in == 1) {
  74001. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  74002. + daintmsk.ep.in = 1 << ep->num;
  74003. + } else {
  74004. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  74005. + daintmsk.ep.out = 1 << ep->num;
  74006. + }
  74007. +
  74008. + depctl.d32 = DWC_READ_REG32(addr);
  74009. +
  74010. + depctl.b.usbactep = 0;
  74011. +
  74012. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  74013. + if (!(depctl.b.eptype & 1) && ep->is_in == 1) { // NP EP IN
  74014. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  74015. + if (core_if->nextep_seq[i] == ep->num)
  74016. + break;
  74017. + }
  74018. + core_if->nextep_seq[i] = core_if->nextep_seq[ep->num];
  74019. + if (core_if->first_in_nextep_seq == ep->num)
  74020. + core_if->first_in_nextep_seq = i;
  74021. + core_if->nextep_seq[ep->num] = 0xff;
  74022. + depctl.b.nextep = 0;
  74023. + dcfg.d32 =
  74024. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  74025. + dcfg.b.epmscnt--;
  74026. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  74027. + dcfg.d32);
  74028. +
  74029. + DWC_DEBUGPL(DBG_PCDV,
  74030. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  74031. + __func__, core_if->first_in_nextep_seq);
  74032. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  74033. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  74034. + }
  74035. + }
  74036. +
  74037. + if (ep->is_in == 1)
  74038. + depctl.b.txfnum = 0;
  74039. +
  74040. + if (core_if->dma_desc_enable)
  74041. + depctl.b.epdis = 1;
  74042. +
  74043. + DWC_WRITE_REG32(addr, depctl.d32);
  74044. + depctl.d32 = DWC_READ_REG32(addr);
  74045. + if (core_if->dma_enable && ep->type == DWC_OTG_EP_TYPE_ISOC
  74046. + && depctl.b.epena) {
  74047. + depctl_data_t depctl = {.d32 = 0};
  74048. + if (ep->is_in) {
  74049. + diepint_data_t diepint = {.d32 = 0};
  74050. +
  74051. + depctl.b.snak = 1;
  74052. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  74053. + diepctl, depctl.d32);
  74054. + do {
  74055. + dwc_udelay(10);
  74056. + diepint.d32 =
  74057. + DWC_READ_REG32(&core_if->
  74058. + dev_if->in_ep_regs[ep->num]->
  74059. + diepint);
  74060. + } while (!diepint.b.inepnakeff);
  74061. + diepint.b.inepnakeff = 1;
  74062. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  74063. + diepint, diepint.d32);
  74064. + depctl.d32 = 0;
  74065. + depctl.b.epdis = 1;
  74066. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  74067. + diepctl, depctl.d32);
  74068. + do {
  74069. + dwc_udelay(10);
  74070. + diepint.d32 =
  74071. + DWC_READ_REG32(&core_if->
  74072. + dev_if->in_ep_regs[ep->num]->
  74073. + diepint);
  74074. + } while (!diepint.b.epdisabled);
  74075. + diepint.b.epdisabled = 1;
  74076. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  74077. + diepint, diepint.d32);
  74078. + } else {
  74079. + dctl_data_t dctl = {.d32 = 0};
  74080. + gintmsk_data_t gintsts = {.d32 = 0};
  74081. + doepint_data_t doepint = {.d32 = 0};
  74082. + dctl.b.sgoutnak = 1;
  74083. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  74084. + dctl, 0, dctl.d32);
  74085. + do {
  74086. + dwc_udelay(10);
  74087. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  74088. + } while (!gintsts.b.goutnakeff);
  74089. + gintsts.d32 = 0;
  74090. + gintsts.b.goutnakeff = 1;
  74091. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  74092. +
  74093. + depctl.d32 = 0;
  74094. + depctl.b.epdis = 1;
  74095. + depctl.b.snak = 1;
  74096. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepctl, depctl.d32);
  74097. + do
  74098. + {
  74099. + dwc_udelay(10);
  74100. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  74101. + out_ep_regs[ep->num]->doepint);
  74102. + } while (!doepint.b.epdisabled);
  74103. +
  74104. + doepint.b.epdisabled = 1;
  74105. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepint, doepint.d32);
  74106. +
  74107. + dctl.d32 = 0;
  74108. + dctl.b.cgoutnak = 1;
  74109. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  74110. + }
  74111. + }
  74112. +
  74113. + /* Disable the Interrupt for this EP */
  74114. + if (core_if->multiproc_int_enable) {
  74115. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  74116. + daintmsk.d32, 0);
  74117. +
  74118. + if (ep->is_in == 1) {
  74119. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  74120. + diepeachintmsk[ep->num], 0);
  74121. + } else {
  74122. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  74123. + doepeachintmsk[ep->num], 0);
  74124. + }
  74125. + } else {
  74126. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->daintmsk,
  74127. + daintmsk.d32, 0);
  74128. + }
  74129. +
  74130. +}
  74131. +
  74132. +/**
  74133. + * This function initializes dma descriptor chain.
  74134. + *
  74135. + * @param core_if Programming view of DWC_otg controller.
  74136. + * @param ep The EP to start the transfer on.
  74137. + */
  74138. +static void init_dma_desc_chain(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  74139. +{
  74140. + dwc_otg_dev_dma_desc_t *dma_desc;
  74141. + uint32_t offset;
  74142. + uint32_t xfer_est;
  74143. + int i;
  74144. + unsigned maxxfer_local, total_len;
  74145. +
  74146. + if (!ep->is_in && ep->type == DWC_OTG_EP_TYPE_INTR &&
  74147. + (ep->maxpacket%4)) {
  74148. + maxxfer_local = ep->maxpacket;
  74149. + total_len = ep->xfer_len;
  74150. + } else {
  74151. + maxxfer_local = ep->maxxfer;
  74152. + total_len = ep->total_len;
  74153. + }
  74154. +
  74155. + ep->desc_cnt = (total_len / maxxfer_local) +
  74156. + ((total_len % maxxfer_local) ? 1 : 0);
  74157. +
  74158. + if (!ep->desc_cnt)
  74159. + ep->desc_cnt = 1;
  74160. +
  74161. + if (ep->desc_cnt > MAX_DMA_DESC_CNT)
  74162. + ep->desc_cnt = MAX_DMA_DESC_CNT;
  74163. +
  74164. + dma_desc = ep->desc_addr;
  74165. + if (maxxfer_local == ep->maxpacket) {
  74166. + if ((total_len % maxxfer_local) &&
  74167. + (total_len/maxxfer_local < MAX_DMA_DESC_CNT)) {
  74168. + xfer_est = (ep->desc_cnt - 1) * maxxfer_local +
  74169. + (total_len % maxxfer_local);
  74170. + } else
  74171. + xfer_est = ep->desc_cnt * maxxfer_local;
  74172. + } else
  74173. + xfer_est = total_len;
  74174. + offset = 0;
  74175. + for (i = 0; i < ep->desc_cnt; ++i) {
  74176. + /** DMA Descriptor Setup */
  74177. + if (xfer_est > maxxfer_local) {
  74178. + dma_desc->status.b.bs = BS_HOST_BUSY;
  74179. + dma_desc->status.b.l = 0;
  74180. + dma_desc->status.b.ioc = 0;
  74181. + dma_desc->status.b.sp = 0;
  74182. + dma_desc->status.b.bytes = maxxfer_local;
  74183. + dma_desc->buf = ep->dma_addr + offset;
  74184. + dma_desc->status.b.sts = 0;
  74185. + dma_desc->status.b.bs = BS_HOST_READY;
  74186. +
  74187. + xfer_est -= maxxfer_local;
  74188. + offset += maxxfer_local;
  74189. + } else {
  74190. + dma_desc->status.b.bs = BS_HOST_BUSY;
  74191. + dma_desc->status.b.l = 1;
  74192. + dma_desc->status.b.ioc = 1;
  74193. + if (ep->is_in) {
  74194. + dma_desc->status.b.sp =
  74195. + (xfer_est %
  74196. + ep->maxpacket) ? 1 : ((ep->
  74197. + sent_zlp) ? 1 : 0);
  74198. + dma_desc->status.b.bytes = xfer_est;
  74199. + } else {
  74200. + if (maxxfer_local == ep->maxpacket)
  74201. + dma_desc->status.b.bytes = xfer_est;
  74202. + else
  74203. + dma_desc->status.b.bytes =
  74204. + xfer_est + ((4 - (xfer_est & 0x3)) & 0x3);
  74205. + }
  74206. +
  74207. + dma_desc->buf = ep->dma_addr + offset;
  74208. + dma_desc->status.b.sts = 0;
  74209. + dma_desc->status.b.bs = BS_HOST_READY;
  74210. + }
  74211. + dma_desc++;
  74212. + }
  74213. +}
  74214. +/**
  74215. + * This function is called when to write ISOC data into appropriate dedicated
  74216. + * periodic FIFO.
  74217. + */
  74218. +static int32_t write_isoc_tx_fifo(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  74219. +{
  74220. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  74221. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  74222. + dtxfsts_data_t txstatus = {.d32 = 0 };
  74223. + uint32_t len = 0;
  74224. + int epnum = dwc_ep->num;
  74225. + int dwords;
  74226. +
  74227. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  74228. +
  74229. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  74230. +
  74231. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  74232. +
  74233. + if (len > dwc_ep->maxpacket) {
  74234. + len = dwc_ep->maxpacket;
  74235. + }
  74236. +
  74237. + dwords = (len + 3) / 4;
  74238. +
  74239. + /* While there is space in the queue and space in the FIFO and
  74240. + * More data to tranfer, Write packets to the Tx FIFO */
  74241. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  74242. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  74243. +
  74244. + while (txstatus.b.txfspcavail > dwords &&
  74245. + dwc_ep->xfer_count < dwc_ep->xfer_len && dwc_ep->xfer_len != 0) {
  74246. + /* Write the FIFO */
  74247. + dwc_otg_ep_write_packet(core_if, dwc_ep, 0);
  74248. +
  74249. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  74250. + if (len > dwc_ep->maxpacket) {
  74251. + len = dwc_ep->maxpacket;
  74252. + }
  74253. +
  74254. + dwords = (len + 3) / 4;
  74255. + txstatus.d32 =
  74256. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  74257. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  74258. + txstatus.d32);
  74259. + }
  74260. +
  74261. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  74262. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  74263. +
  74264. + return 1;
  74265. +}
  74266. +/**
  74267. + * This function does the setup for a data transfer for an EP and
  74268. + * starts the transfer. For an IN transfer, the packets will be
  74269. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  74270. + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
  74271. + *
  74272. + * @param core_if Programming view of DWC_otg controller.
  74273. + * @param ep The EP to start the transfer on.
  74274. + */
  74275. +
  74276. +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  74277. +{
  74278. + depctl_data_t depctl;
  74279. + deptsiz_data_t deptsiz;
  74280. + gintmsk_data_t intr_mask = {.d32 = 0 };
  74281. +
  74282. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  74283. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  74284. + "xfer_buff=%p start_xfer_buff=%p, total_len = %d\n",
  74285. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  74286. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff,
  74287. + ep->total_len);
  74288. + /* IN endpoint */
  74289. + if (ep->is_in == 1) {
  74290. + dwc_otg_dev_in_ep_regs_t *in_regs =
  74291. + core_if->dev_if->in_ep_regs[ep->num];
  74292. +
  74293. + gnptxsts_data_t gtxstatus;
  74294. +
  74295. + gtxstatus.d32 =
  74296. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  74297. +
  74298. + if (core_if->en_multiple_tx_fifo == 0
  74299. + && gtxstatus.b.nptxqspcavail == 0 && !core_if->dma_enable) {
  74300. +#ifdef DEBUG
  74301. + DWC_PRINTF("TX Queue Full (0x%0x)\n", gtxstatus.d32);
  74302. +#endif
  74303. + return;
  74304. + }
  74305. +
  74306. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  74307. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  74308. +
  74309. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  74310. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  74311. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  74312. + else
  74313. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len - ep->xfer_len)) ?
  74314. + MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  74315. +
  74316. +
  74317. + /* Zero Length Packet? */
  74318. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  74319. + deptsiz.b.xfersize = 0;
  74320. + deptsiz.b.pktcnt = 1;
  74321. + } else {
  74322. + /* Program the transfer size and packet count
  74323. + * as follows: xfersize = N * maxpacket +
  74324. + * short_packet pktcnt = N + (short_packet
  74325. + * exist ? 1 : 0)
  74326. + */
  74327. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  74328. + deptsiz.b.pktcnt =
  74329. + (ep->xfer_len - ep->xfer_count - 1 +
  74330. + ep->maxpacket) / ep->maxpacket;
  74331. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  74332. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  74333. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  74334. + }
  74335. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  74336. + deptsiz.b.mc = deptsiz.b.pktcnt;
  74337. + }
  74338. +
  74339. + /* Write the DMA register */
  74340. + if (core_if->dma_enable) {
  74341. + if (core_if->dma_desc_enable == 0) {
  74342. + if (ep->type != DWC_OTG_EP_TYPE_ISOC)
  74343. + deptsiz.b.mc = 1;
  74344. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  74345. + deptsiz.d32);
  74346. + DWC_WRITE_REG32(&(in_regs->diepdma),
  74347. + (uint32_t) ep->dma_addr);
  74348. + } else {
  74349. +#ifdef DWC_UTE_CFI
  74350. + /* The descriptor chain should be already initialized by now */
  74351. + if (ep->buff_mode != BM_STANDARD) {
  74352. + DWC_WRITE_REG32(&in_regs->diepdma,
  74353. + ep->descs_dma_addr);
  74354. + } else {
  74355. +#endif
  74356. + init_dma_desc_chain(core_if, ep);
  74357. + /** DIEPDMAn Register write */
  74358. + DWC_WRITE_REG32(&in_regs->diepdma,
  74359. + ep->dma_desc_addr);
  74360. +#ifdef DWC_UTE_CFI
  74361. + }
  74362. +#endif
  74363. + }
  74364. + } else {
  74365. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  74366. + if (ep->type != DWC_OTG_EP_TYPE_ISOC) {
  74367. + /**
  74368. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  74369. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  74370. + * the data will be written into the fifo by the ISR.
  74371. + */
  74372. + if (core_if->en_multiple_tx_fifo == 0) {
  74373. + intr_mask.b.nptxfempty = 1;
  74374. + DWC_MODIFY_REG32
  74375. + (&core_if->core_global_regs->gintmsk,
  74376. + intr_mask.d32, intr_mask.d32);
  74377. + } else {
  74378. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  74379. + if (ep->xfer_len > 0) {
  74380. + uint32_t fifoemptymsk = 0;
  74381. + fifoemptymsk = 1 << ep->num;
  74382. + DWC_MODIFY_REG32
  74383. + (&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  74384. + 0, fifoemptymsk);
  74385. +
  74386. + }
  74387. + }
  74388. + } else {
  74389. + write_isoc_tx_fifo(core_if, ep);
  74390. + }
  74391. + }
  74392. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  74393. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  74394. +
  74395. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  74396. + dsts_data_t dsts = {.d32 = 0};
  74397. + if (ep->bInterval == 1) {
  74398. + dsts.d32 =
  74399. + DWC_READ_REG32(&core_if->dev_if->
  74400. + dev_global_regs->dsts);
  74401. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  74402. + if (ep->frame_num > 0x3FFF) {
  74403. + ep->frm_overrun = 1;
  74404. + ep->frame_num &= 0x3FFF;
  74405. + } else
  74406. + ep->frm_overrun = 0;
  74407. + if (ep->frame_num & 0x1) {
  74408. + depctl.b.setd1pid = 1;
  74409. + } else {
  74410. + depctl.b.setd0pid = 1;
  74411. + }
  74412. + }
  74413. + }
  74414. + /* EP enable, IN data in FIFO */
  74415. + depctl.b.cnak = 1;
  74416. + depctl.b.epena = 1;
  74417. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  74418. +
  74419. + } else {
  74420. + /* OUT endpoint */
  74421. + dwc_otg_dev_out_ep_regs_t *out_regs =
  74422. + core_if->dev_if->out_ep_regs[ep->num];
  74423. +
  74424. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  74425. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  74426. +
  74427. + if (!core_if->dma_desc_enable) {
  74428. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  74429. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  74430. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  74431. + else
  74432. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len
  74433. + - ep->xfer_len)) ? MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  74434. + }
  74435. +
  74436. + /* Program the transfer size and packet count as follows:
  74437. + *
  74438. + * pktcnt = N
  74439. + * xfersize = N * maxpacket
  74440. + */
  74441. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  74442. + /* Zero Length Packet */
  74443. + deptsiz.b.xfersize = ep->maxpacket;
  74444. + deptsiz.b.pktcnt = 1;
  74445. + } else {
  74446. + deptsiz.b.pktcnt =
  74447. + (ep->xfer_len - ep->xfer_count +
  74448. + (ep->maxpacket - 1)) / ep->maxpacket;
  74449. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  74450. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  74451. + }
  74452. + if (!core_if->dma_desc_enable) {
  74453. + ep->xfer_len =
  74454. + deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
  74455. + }
  74456. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  74457. + }
  74458. +
  74459. + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
  74460. + ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  74461. +
  74462. + if (core_if->dma_enable) {
  74463. + if (!core_if->dma_desc_enable) {
  74464. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  74465. + deptsiz.d32);
  74466. +
  74467. + DWC_WRITE_REG32(&(out_regs->doepdma),
  74468. + (uint32_t) ep->dma_addr);
  74469. + } else {
  74470. +#ifdef DWC_UTE_CFI
  74471. + /* The descriptor chain should be already initialized by now */
  74472. + if (ep->buff_mode != BM_STANDARD) {
  74473. + DWC_WRITE_REG32(&out_regs->doepdma,
  74474. + ep->descs_dma_addr);
  74475. + } else {
  74476. +#endif
  74477. + /** This is used for interrupt out transfers*/
  74478. + if (!ep->xfer_len)
  74479. + ep->xfer_len = ep->total_len;
  74480. + init_dma_desc_chain(core_if, ep);
  74481. +
  74482. + if (core_if->core_params->dev_out_nak) {
  74483. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  74484. + deptsiz.b.pktcnt = (ep->total_len +
  74485. + (ep->maxpacket - 1)) / ep->maxpacket;
  74486. + deptsiz.b.xfersize = ep->total_len;
  74487. + /* Remember initial value of doeptsiz */
  74488. + core_if->start_doeptsiz_val[ep->num] = deptsiz.d32;
  74489. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  74490. + deptsiz.d32);
  74491. + }
  74492. + }
  74493. + /** DOEPDMAn Register write */
  74494. + DWC_WRITE_REG32(&out_regs->doepdma,
  74495. + ep->dma_desc_addr);
  74496. +#ifdef DWC_UTE_CFI
  74497. + }
  74498. +#endif
  74499. + }
  74500. + } else {
  74501. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  74502. + }
  74503. +
  74504. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  74505. + dsts_data_t dsts = {.d32 = 0};
  74506. + if (ep->bInterval == 1) {
  74507. + dsts.d32 =
  74508. + DWC_READ_REG32(&core_if->dev_if->
  74509. + dev_global_regs->dsts);
  74510. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  74511. + if (ep->frame_num > 0x3FFF) {
  74512. + ep->frm_overrun = 1;
  74513. + ep->frame_num &= 0x3FFF;
  74514. + } else
  74515. + ep->frm_overrun = 0;
  74516. +
  74517. + if (ep->frame_num & 0x1) {
  74518. + depctl.b.setd1pid = 1;
  74519. + } else {
  74520. + depctl.b.setd0pid = 1;
  74521. + }
  74522. + }
  74523. + }
  74524. +
  74525. + /* EP enable */
  74526. + depctl.b.cnak = 1;
  74527. + depctl.b.epena = 1;
  74528. +
  74529. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  74530. +
  74531. + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
  74532. + DWC_READ_REG32(&out_regs->doepctl),
  74533. + DWC_READ_REG32(&out_regs->doeptsiz));
  74534. + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
  74535. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  74536. + daintmsk),
  74537. + DWC_READ_REG32(&core_if->core_global_regs->
  74538. + gintmsk));
  74539. +
  74540. + /* Timer is scheduling only for out bulk transfers for
  74541. + * "Device DDMA OUT NAK Enhancement" feature to inform user
  74542. + * about received data payload in case of timeout
  74543. + */
  74544. + if (core_if->core_params->dev_out_nak) {
  74545. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  74546. + core_if->ep_xfer_info[ep->num].core_if = core_if;
  74547. + core_if->ep_xfer_info[ep->num].ep = ep;
  74548. + core_if->ep_xfer_info[ep->num].state = 1;
  74549. +
  74550. + /* Start a timer for this transfer. */
  74551. + DWC_TIMER_SCHEDULE(core_if->ep_xfer_timer[ep->num], 10000);
  74552. + }
  74553. + }
  74554. + }
  74555. +}
  74556. +
  74557. +/**
  74558. + * This function setup a zero length transfer in Buffer DMA and
  74559. + * Slave modes for usb requests with zero field set
  74560. + *
  74561. + * @param core_if Programming view of DWC_otg controller.
  74562. + * @param ep The EP to start the transfer on.
  74563. + *
  74564. + */
  74565. +void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  74566. +{
  74567. +
  74568. + depctl_data_t depctl;
  74569. + deptsiz_data_t deptsiz;
  74570. + gintmsk_data_t intr_mask = {.d32 = 0 };
  74571. +
  74572. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  74573. + DWC_PRINTF("zero length transfer is called\n");
  74574. +
  74575. + /* IN endpoint */
  74576. + if (ep->is_in == 1) {
  74577. + dwc_otg_dev_in_ep_regs_t *in_regs =
  74578. + core_if->dev_if->in_ep_regs[ep->num];
  74579. +
  74580. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  74581. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  74582. +
  74583. + deptsiz.b.xfersize = 0;
  74584. + deptsiz.b.pktcnt = 1;
  74585. +
  74586. + /* Write the DMA register */
  74587. + if (core_if->dma_enable) {
  74588. + if (core_if->dma_desc_enable == 0) {
  74589. + deptsiz.b.mc = 1;
  74590. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  74591. + deptsiz.d32);
  74592. + DWC_WRITE_REG32(&(in_regs->diepdma),
  74593. + (uint32_t) ep->dma_addr);
  74594. + }
  74595. + } else {
  74596. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  74597. + /**
  74598. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  74599. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  74600. + * the data will be written into the fifo by the ISR.
  74601. + */
  74602. + if (core_if->en_multiple_tx_fifo == 0) {
  74603. + intr_mask.b.nptxfempty = 1;
  74604. + DWC_MODIFY_REG32(&core_if->
  74605. + core_global_regs->gintmsk,
  74606. + intr_mask.d32, intr_mask.d32);
  74607. + } else {
  74608. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  74609. + if (ep->xfer_len > 0) {
  74610. + uint32_t fifoemptymsk = 0;
  74611. + fifoemptymsk = 1 << ep->num;
  74612. + DWC_MODIFY_REG32(&core_if->
  74613. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  74614. + 0, fifoemptymsk);
  74615. + }
  74616. + }
  74617. + }
  74618. +
  74619. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  74620. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  74621. + /* EP enable, IN data in FIFO */
  74622. + depctl.b.cnak = 1;
  74623. + depctl.b.epena = 1;
  74624. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  74625. +
  74626. + } else {
  74627. + /* OUT endpoint */
  74628. + dwc_otg_dev_out_ep_regs_t *out_regs =
  74629. + core_if->dev_if->out_ep_regs[ep->num];
  74630. +
  74631. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  74632. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  74633. +
  74634. + /* Zero Length Packet */
  74635. + deptsiz.b.xfersize = ep->maxpacket;
  74636. + deptsiz.b.pktcnt = 1;
  74637. +
  74638. + if (core_if->dma_enable) {
  74639. + if (!core_if->dma_desc_enable) {
  74640. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  74641. + deptsiz.d32);
  74642. +
  74643. + DWC_WRITE_REG32(&(out_regs->doepdma),
  74644. + (uint32_t) ep->dma_addr);
  74645. + }
  74646. + } else {
  74647. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  74648. + }
  74649. +
  74650. + /* EP enable */
  74651. + depctl.b.cnak = 1;
  74652. + depctl.b.epena = 1;
  74653. +
  74654. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  74655. +
  74656. + }
  74657. +}
  74658. +
  74659. +/**
  74660. + * This function does the setup for a data transfer for EP0 and starts
  74661. + * the transfer. For an IN transfer, the packets will be loaded into
  74662. + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
  74663. + * unloaded from the Rx FIFO in the ISR.
  74664. + *
  74665. + * @param core_if Programming view of DWC_otg controller.
  74666. + * @param ep The EP0 data.
  74667. + */
  74668. +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  74669. +{
  74670. + depctl_data_t depctl;
  74671. + deptsiz0_data_t deptsiz;
  74672. + gintmsk_data_t intr_mask = {.d32 = 0 };
  74673. + dwc_otg_dev_dma_desc_t *dma_desc;
  74674. +
  74675. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  74676. + "xfer_buff=%p start_xfer_buff=%p \n",
  74677. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  74678. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
  74679. +
  74680. + ep->total_len = ep->xfer_len;
  74681. +
  74682. + /* IN endpoint */
  74683. + if (ep->is_in == 1) {
  74684. + dwc_otg_dev_in_ep_regs_t *in_regs =
  74685. + core_if->dev_if->in_ep_regs[0];
  74686. +
  74687. + gnptxsts_data_t gtxstatus;
  74688. +
  74689. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  74690. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  74691. + if (depctl.b.epena)
  74692. + return;
  74693. + }
  74694. +
  74695. + gtxstatus.d32 =
  74696. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  74697. +
  74698. + /* If dedicated FIFO every time flush fifo before enable ep*/
  74699. + if (core_if->en_multiple_tx_fifo && core_if->snpsid >= OTG_CORE_REV_3_00a)
  74700. + dwc_otg_flush_tx_fifo(core_if, ep->tx_fifo_num);
  74701. +
  74702. + if (core_if->en_multiple_tx_fifo == 0
  74703. + && gtxstatus.b.nptxqspcavail == 0
  74704. + && !core_if->dma_enable) {
  74705. +#ifdef DEBUG
  74706. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  74707. + DWC_DEBUGPL(DBG_PCD, "DIEPCTL0=%0x\n",
  74708. + DWC_READ_REG32(&in_regs->diepctl));
  74709. + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
  74710. + deptsiz.d32,
  74711. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  74712. + DWC_PRINTF("TX Queue or FIFO Full (0x%0x)\n",
  74713. + gtxstatus.d32);
  74714. +#endif
  74715. + return;
  74716. + }
  74717. +
  74718. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  74719. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  74720. +
  74721. + /* Zero Length Packet? */
  74722. + if (ep->xfer_len == 0) {
  74723. + deptsiz.b.xfersize = 0;
  74724. + deptsiz.b.pktcnt = 1;
  74725. + } else {
  74726. + /* Program the transfer size and packet count
  74727. + * as follows: xfersize = N * maxpacket +
  74728. + * short_packet pktcnt = N + (short_packet
  74729. + * exist ? 1 : 0)
  74730. + */
  74731. + if (ep->xfer_len > ep->maxpacket) {
  74732. + ep->xfer_len = ep->maxpacket;
  74733. + deptsiz.b.xfersize = ep->maxpacket;
  74734. + } else {
  74735. + deptsiz.b.xfersize = ep->xfer_len;
  74736. + }
  74737. + deptsiz.b.pktcnt = 1;
  74738. +
  74739. + }
  74740. + DWC_DEBUGPL(DBG_PCDV,
  74741. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  74742. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  74743. + deptsiz.d32);
  74744. +
  74745. + /* Write the DMA register */
  74746. + if (core_if->dma_enable) {
  74747. + if (core_if->dma_desc_enable == 0) {
  74748. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  74749. + deptsiz.d32);
  74750. +
  74751. + DWC_WRITE_REG32(&(in_regs->diepdma),
  74752. + (uint32_t) ep->dma_addr);
  74753. + } else {
  74754. + dma_desc = core_if->dev_if->in_desc_addr;
  74755. +
  74756. + /** DMA Descriptor Setup */
  74757. + dma_desc->status.b.bs = BS_HOST_BUSY;
  74758. + dma_desc->status.b.l = 1;
  74759. + dma_desc->status.b.ioc = 1;
  74760. + dma_desc->status.b.sp =
  74761. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  74762. + dma_desc->status.b.bytes = ep->xfer_len;
  74763. + dma_desc->buf = ep->dma_addr;
  74764. + dma_desc->status.b.sts = 0;
  74765. + dma_desc->status.b.bs = BS_HOST_READY;
  74766. +
  74767. + /** DIEPDMA0 Register write */
  74768. + DWC_WRITE_REG32(&in_regs->diepdma,
  74769. + core_if->
  74770. + dev_if->dma_in_desc_addr);
  74771. + }
  74772. + } else {
  74773. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  74774. + }
  74775. +
  74776. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  74777. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  74778. + /* EP enable, IN data in FIFO */
  74779. + depctl.b.cnak = 1;
  74780. + depctl.b.epena = 1;
  74781. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  74782. +
  74783. + /**
  74784. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  74785. + * data will be written into the fifo by the ISR.
  74786. + */
  74787. + if (!core_if->dma_enable) {
  74788. + if (core_if->en_multiple_tx_fifo == 0) {
  74789. + intr_mask.b.nptxfempty = 1;
  74790. + DWC_MODIFY_REG32(&core_if->
  74791. + core_global_regs->gintmsk,
  74792. + intr_mask.d32, intr_mask.d32);
  74793. + } else {
  74794. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  74795. + if (ep->xfer_len > 0) {
  74796. + uint32_t fifoemptymsk = 0;
  74797. + fifoemptymsk |= 1 << ep->num;
  74798. + DWC_MODIFY_REG32(&core_if->
  74799. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  74800. + 0, fifoemptymsk);
  74801. + }
  74802. + }
  74803. + }
  74804. + } else {
  74805. + /* OUT endpoint */
  74806. + dwc_otg_dev_out_ep_regs_t *out_regs =
  74807. + core_if->dev_if->out_ep_regs[0];
  74808. +
  74809. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  74810. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  74811. +
  74812. + /* Program the transfer size and packet count as follows:
  74813. + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
  74814. + * pktcnt = N */
  74815. + /* Zero Length Packet */
  74816. + deptsiz.b.xfersize = ep->maxpacket;
  74817. + deptsiz.b.pktcnt = 1;
  74818. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  74819. + deptsiz.b.supcnt = 3;
  74820. +
  74821. + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
  74822. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  74823. +
  74824. + if (core_if->dma_enable) {
  74825. + if (!core_if->dma_desc_enable) {
  74826. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  74827. + deptsiz.d32);
  74828. +
  74829. + DWC_WRITE_REG32(&(out_regs->doepdma),
  74830. + (uint32_t) ep->dma_addr);
  74831. + } else {
  74832. + dma_desc = core_if->dev_if->out_desc_addr;
  74833. +
  74834. + /** DMA Descriptor Setup */
  74835. + dma_desc->status.b.bs = BS_HOST_BUSY;
  74836. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  74837. + dma_desc->status.b.mtrf = 0;
  74838. + dma_desc->status.b.sr = 0;
  74839. + }
  74840. + dma_desc->status.b.l = 1;
  74841. + dma_desc->status.b.ioc = 1;
  74842. + dma_desc->status.b.bytes = ep->maxpacket;
  74843. + dma_desc->buf = ep->dma_addr;
  74844. + dma_desc->status.b.sts = 0;
  74845. + dma_desc->status.b.bs = BS_HOST_READY;
  74846. +
  74847. + /** DOEPDMA0 Register write */
  74848. + DWC_WRITE_REG32(&out_regs->doepdma,
  74849. + core_if->dev_if->
  74850. + dma_out_desc_addr);
  74851. + }
  74852. + } else {
  74853. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  74854. + }
  74855. +
  74856. + /* EP enable */
  74857. + depctl.b.cnak = 1;
  74858. + depctl.b.epena = 1;
  74859. + DWC_WRITE_REG32(&(out_regs->doepctl), depctl.d32);
  74860. + }
  74861. +}
  74862. +
  74863. +/**
  74864. + * This function continues control IN transfers started by
  74865. + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
  74866. + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
  74867. + * bit for the packet count.
  74868. + *
  74869. + * @param core_if Programming view of DWC_otg controller.
  74870. + * @param ep The EP0 data.
  74871. + */
  74872. +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  74873. +{
  74874. + depctl_data_t depctl;
  74875. + deptsiz0_data_t deptsiz;
  74876. + gintmsk_data_t intr_mask = {.d32 = 0 };
  74877. + dwc_otg_dev_dma_desc_t *dma_desc;
  74878. +
  74879. + if (ep->is_in == 1) {
  74880. + dwc_otg_dev_in_ep_regs_t *in_regs =
  74881. + core_if->dev_if->in_ep_regs[0];
  74882. + gnptxsts_data_t tx_status = {.d32 = 0 };
  74883. +
  74884. + tx_status.d32 =
  74885. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  74886. + /** @todo Should there be check for room in the Tx
  74887. + * Status Queue. If not remove the code above this comment. */
  74888. +
  74889. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  74890. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  74891. +
  74892. + /* Program the transfer size and packet count
  74893. + * as follows: xfersize = N * maxpacket +
  74894. + * short_packet pktcnt = N + (short_packet
  74895. + * exist ? 1 : 0)
  74896. + */
  74897. +
  74898. + if (core_if->dma_desc_enable == 0) {
  74899. + deptsiz.b.xfersize =
  74900. + (ep->total_len - ep->xfer_count) >
  74901. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  74902. + ep->xfer_count);
  74903. + deptsiz.b.pktcnt = 1;
  74904. + if (core_if->dma_enable == 0) {
  74905. + ep->xfer_len += deptsiz.b.xfersize;
  74906. + } else {
  74907. + ep->xfer_len = deptsiz.b.xfersize;
  74908. + }
  74909. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  74910. + } else {
  74911. + ep->xfer_len =
  74912. + (ep->total_len - ep->xfer_count) >
  74913. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  74914. + ep->xfer_count);
  74915. +
  74916. + dma_desc = core_if->dev_if->in_desc_addr;
  74917. +
  74918. + /** DMA Descriptor Setup */
  74919. + dma_desc->status.b.bs = BS_HOST_BUSY;
  74920. + dma_desc->status.b.l = 1;
  74921. + dma_desc->status.b.ioc = 1;
  74922. + dma_desc->status.b.sp =
  74923. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  74924. + dma_desc->status.b.bytes = ep->xfer_len;
  74925. + dma_desc->buf = ep->dma_addr;
  74926. + dma_desc->status.b.sts = 0;
  74927. + dma_desc->status.b.bs = BS_HOST_READY;
  74928. +
  74929. + /** DIEPDMA0 Register write */
  74930. + DWC_WRITE_REG32(&in_regs->diepdma,
  74931. + core_if->dev_if->dma_in_desc_addr);
  74932. + }
  74933. +
  74934. + DWC_DEBUGPL(DBG_PCDV,
  74935. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  74936. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  74937. + deptsiz.d32);
  74938. +
  74939. + /* Write the DMA register */
  74940. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  74941. + if (core_if->dma_desc_enable == 0)
  74942. + DWC_WRITE_REG32(&(in_regs->diepdma),
  74943. + (uint32_t) ep->dma_addr);
  74944. + }
  74945. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  74946. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  74947. + /* EP enable, IN data in FIFO */
  74948. + depctl.b.cnak = 1;
  74949. + depctl.b.epena = 1;
  74950. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  74951. +
  74952. + /**
  74953. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  74954. + * data will be written into the fifo by the ISR.
  74955. + */
  74956. + if (!core_if->dma_enable) {
  74957. + if (core_if->en_multiple_tx_fifo == 0) {
  74958. + /* First clear it from GINTSTS */
  74959. + intr_mask.b.nptxfempty = 1;
  74960. + DWC_MODIFY_REG32(&core_if->
  74961. + core_global_regs->gintmsk,
  74962. + intr_mask.d32, intr_mask.d32);
  74963. +
  74964. + } else {
  74965. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  74966. + if (ep->xfer_len > 0) {
  74967. + uint32_t fifoemptymsk = 0;
  74968. + fifoemptymsk |= 1 << ep->num;
  74969. + DWC_MODIFY_REG32(&core_if->
  74970. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  74971. + 0, fifoemptymsk);
  74972. + }
  74973. + }
  74974. + }
  74975. + } else {
  74976. + dwc_otg_dev_out_ep_regs_t *out_regs =
  74977. + core_if->dev_if->out_ep_regs[0];
  74978. +
  74979. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  74980. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  74981. +
  74982. + /* Program the transfer size and packet count
  74983. + * as follows: xfersize = N * maxpacket +
  74984. + * short_packet pktcnt = N + (short_packet
  74985. + * exist ? 1 : 0)
  74986. + */
  74987. + deptsiz.b.xfersize = ep->maxpacket;
  74988. + deptsiz.b.pktcnt = 1;
  74989. +
  74990. + if (core_if->dma_desc_enable == 0) {
  74991. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  74992. + } else {
  74993. + dma_desc = core_if->dev_if->out_desc_addr;
  74994. +
  74995. + /** DMA Descriptor Setup */
  74996. + dma_desc->status.b.bs = BS_HOST_BUSY;
  74997. + dma_desc->status.b.l = 1;
  74998. + dma_desc->status.b.ioc = 1;
  74999. + dma_desc->status.b.bytes = ep->maxpacket;
  75000. + dma_desc->buf = ep->dma_addr;
  75001. + dma_desc->status.b.sts = 0;
  75002. + dma_desc->status.b.bs = BS_HOST_READY;
  75003. +
  75004. + /** DOEPDMA0 Register write */
  75005. + DWC_WRITE_REG32(&out_regs->doepdma,
  75006. + core_if->dev_if->dma_out_desc_addr);
  75007. + }
  75008. +
  75009. + DWC_DEBUGPL(DBG_PCDV,
  75010. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  75011. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  75012. + deptsiz.d32);
  75013. +
  75014. + /* Write the DMA register */
  75015. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  75016. + if (core_if->dma_desc_enable == 0)
  75017. + DWC_WRITE_REG32(&(out_regs->doepdma),
  75018. + (uint32_t) ep->dma_addr);
  75019. +
  75020. + }
  75021. +
  75022. + /* EP enable, IN data in FIFO */
  75023. + depctl.b.cnak = 1;
  75024. + depctl.b.epena = 1;
  75025. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  75026. +
  75027. + }
  75028. +}
  75029. +
  75030. +#ifdef DEBUG
  75031. +void dump_msg(const u8 * buf, unsigned int length)
  75032. +{
  75033. + unsigned int start, num, i;
  75034. + char line[52], *p;
  75035. +
  75036. + if (length >= 512)
  75037. + return;
  75038. + start = 0;
  75039. + while (length > 0) {
  75040. + num = length < 16u ? length : 16u;
  75041. + p = line;
  75042. + for (i = 0; i < num; ++i) {
  75043. + if (i == 8)
  75044. + *p++ = ' ';
  75045. + DWC_SPRINTF(p, " %02x", buf[i]);
  75046. + p += 3;
  75047. + }
  75048. + *p = 0;
  75049. + DWC_PRINTF("%6x: %s\n", start, line);
  75050. + buf += num;
  75051. + start += num;
  75052. + length -= num;
  75053. + }
  75054. +}
  75055. +#else
  75056. +static inline void dump_msg(const u8 * buf, unsigned int length)
  75057. +{
  75058. +}
  75059. +#endif
  75060. +
  75061. +/**
  75062. + * This function writes a packet into the Tx FIFO associated with the
  75063. + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
  75064. + * periodic EPs the periodic Tx FIFO associated with the EP is written
  75065. + * with all packets for the next micro-frame.
  75066. + *
  75067. + * @param core_if Programming view of DWC_otg controller.
  75068. + * @param ep The EP to write packet for.
  75069. + * @param dma Indicates if DMA is being used.
  75070. + */
  75071. +void dwc_otg_ep_write_packet(dwc_otg_core_if_t * core_if, dwc_ep_t * ep,
  75072. + int dma)
  75073. +{
  75074. + /**
  75075. + * The buffer is padded to DWORD on a per packet basis in
  75076. + * slave/dma mode if the MPS is not DWORD aligned. The last
  75077. + * packet, if short, is also padded to a multiple of DWORD.
  75078. + *
  75079. + * ep->xfer_buff always starts DWORD aligned in memory and is a
  75080. + * multiple of DWORD in length
  75081. + *
  75082. + * ep->xfer_len can be any number of bytes
  75083. + *
  75084. + * ep->xfer_count is a multiple of ep->maxpacket until the last
  75085. + * packet
  75086. + *
  75087. + * FIFO access is DWORD */
  75088. +
  75089. + uint32_t i;
  75090. + uint32_t byte_count;
  75091. + uint32_t dword_count;
  75092. + uint32_t *fifo;
  75093. + uint32_t *data_buff = (uint32_t *) ep->xfer_buff;
  75094. +
  75095. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if,
  75096. + ep);
  75097. + if (ep->xfer_count >= ep->xfer_len) {
  75098. + DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
  75099. + return;
  75100. + }
  75101. +
  75102. + /* Find the byte length of the packet either short packet or MPS */
  75103. + if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
  75104. + byte_count = ep->xfer_len - ep->xfer_count;
  75105. + } else {
  75106. + byte_count = ep->maxpacket;
  75107. + }
  75108. +
  75109. + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
  75110. + * is not a multiple of DWORD */
  75111. + dword_count = (byte_count + 3) / 4;
  75112. +
  75113. +#ifdef VERBOSE
  75114. + dump_msg(ep->xfer_buff, byte_count);
  75115. +#endif
  75116. +
  75117. + /**@todo NGS Where are the Periodic Tx FIFO addresses
  75118. + * intialized? What should this be? */
  75119. +
  75120. + fifo = core_if->data_fifo[ep->num];
  75121. +
  75122. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
  75123. + fifo, data_buff, *data_buff, byte_count);
  75124. +
  75125. + if (!dma) {
  75126. + for (i = 0; i < dword_count; i++, data_buff++) {
  75127. + DWC_WRITE_REG32(fifo, *data_buff);
  75128. + }
  75129. + }
  75130. +
  75131. + ep->xfer_count += byte_count;
  75132. + ep->xfer_buff += byte_count;
  75133. + ep->dma_addr += byte_count;
  75134. +}
  75135. +
  75136. +/**
  75137. + * Set the EP STALL.
  75138. + *
  75139. + * @param core_if Programming view of DWC_otg controller.
  75140. + * @param ep The EP to set the stall on.
  75141. + */
  75142. +void dwc_otg_ep_set_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  75143. +{
  75144. + depctl_data_t depctl;
  75145. + volatile uint32_t *depctl_addr;
  75146. +
  75147. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  75148. + (ep->is_in ? "IN" : "OUT"));
  75149. +
  75150. + if (ep->is_in == 1) {
  75151. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  75152. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  75153. +
  75154. + /* set the disable and stall bits */
  75155. + if (depctl.b.epena) {
  75156. + depctl.b.epdis = 1;
  75157. + }
  75158. + depctl.b.stall = 1;
  75159. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  75160. + } else {
  75161. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  75162. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  75163. +
  75164. + /* set the stall bit */
  75165. + depctl.b.stall = 1;
  75166. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  75167. + }
  75168. +
  75169. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  75170. +
  75171. + return;
  75172. +}
  75173. +
  75174. +/**
  75175. + * Clear the EP STALL.
  75176. + *
  75177. + * @param core_if Programming view of DWC_otg controller.
  75178. + * @param ep The EP to clear stall from.
  75179. + */
  75180. +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  75181. +{
  75182. + depctl_data_t depctl;
  75183. + volatile uint32_t *depctl_addr;
  75184. +
  75185. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  75186. + (ep->is_in ? "IN" : "OUT"));
  75187. +
  75188. + if (ep->is_in == 1) {
  75189. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  75190. + } else {
  75191. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  75192. + }
  75193. +
  75194. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  75195. +
  75196. + /* clear the stall bits */
  75197. + depctl.b.stall = 0;
  75198. +
  75199. + /*
  75200. + * USB Spec 9.4.5: For endpoints using data toggle, regardless
  75201. + * of whether an endpoint has the Halt feature set, a
  75202. + * ClearFeature(ENDPOINT_HALT) request always results in the
  75203. + * data toggle being reinitialized to DATA0.
  75204. + */
  75205. + if (ep->type == DWC_OTG_EP_TYPE_INTR ||
  75206. + ep->type == DWC_OTG_EP_TYPE_BULK) {
  75207. + depctl.b.setd0pid = 1; /* DATA0 */
  75208. + }
  75209. +
  75210. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  75211. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  75212. + return;
  75213. +}
  75214. +
  75215. +/**
  75216. + * This function reads a packet from the Rx FIFO into the destination
  75217. + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
  75218. + *
  75219. + * @param core_if Programming view of DWC_otg controller.
  75220. + * @param dest Destination buffer for the packet.
  75221. + * @param bytes Number of bytes to copy to the destination.
  75222. + */
  75223. +void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  75224. + uint8_t * dest, uint16_t bytes)
  75225. +{
  75226. + int i;
  75227. + int word_count = (bytes + 3) / 4;
  75228. +
  75229. + volatile uint32_t *fifo = core_if->data_fifo[0];
  75230. + uint32_t *data_buff = (uint32_t *) dest;
  75231. +
  75232. + /**
  75233. + * @todo Account for the case where _dest is not dword aligned. This
  75234. + * requires reading data from the FIFO into a uint32_t temp buffer,
  75235. + * then moving it into the data buffer.
  75236. + */
  75237. +
  75238. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
  75239. + core_if, dest, bytes);
  75240. +
  75241. + for (i = 0; i < word_count; i++, data_buff++) {
  75242. + *data_buff = DWC_READ_REG32(fifo);
  75243. + }
  75244. +
  75245. + return;
  75246. +}
  75247. +
  75248. +/**
  75249. + * This functions reads the device registers and prints them
  75250. + *
  75251. + * @param core_if Programming view of DWC_otg controller.
  75252. + */
  75253. +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * core_if)
  75254. +{
  75255. + int i;
  75256. + volatile uint32_t *addr;
  75257. +
  75258. + DWC_PRINTF("Device Global Registers\n");
  75259. + addr = &core_if->dev_if->dev_global_regs->dcfg;
  75260. + DWC_PRINTF("DCFG @0x%08lX : 0x%08X\n",
  75261. + (unsigned long)addr, DWC_READ_REG32(addr));
  75262. + addr = &core_if->dev_if->dev_global_regs->dctl;
  75263. + DWC_PRINTF("DCTL @0x%08lX : 0x%08X\n",
  75264. + (unsigned long)addr, DWC_READ_REG32(addr));
  75265. + addr = &core_if->dev_if->dev_global_regs->dsts;
  75266. + DWC_PRINTF("DSTS @0x%08lX : 0x%08X\n",
  75267. + (unsigned long)addr, DWC_READ_REG32(addr));
  75268. + addr = &core_if->dev_if->dev_global_regs->diepmsk;
  75269. + DWC_PRINTF("DIEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75270. + DWC_READ_REG32(addr));
  75271. + addr = &core_if->dev_if->dev_global_regs->doepmsk;
  75272. + DWC_PRINTF("DOEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75273. + DWC_READ_REG32(addr));
  75274. + addr = &core_if->dev_if->dev_global_regs->daint;
  75275. + DWC_PRINTF("DAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75276. + DWC_READ_REG32(addr));
  75277. + addr = &core_if->dev_if->dev_global_regs->daintmsk;
  75278. + DWC_PRINTF("DAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75279. + DWC_READ_REG32(addr));
  75280. + addr = &core_if->dev_if->dev_global_regs->dtknqr1;
  75281. + DWC_PRINTF("DTKNQR1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75282. + DWC_READ_REG32(addr));
  75283. + if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
  75284. + addr = &core_if->dev_if->dev_global_regs->dtknqr2;
  75285. + DWC_PRINTF("DTKNQR2 @0x%08lX : 0x%08X\n",
  75286. + (unsigned long)addr, DWC_READ_REG32(addr));
  75287. + }
  75288. +
  75289. + addr = &core_if->dev_if->dev_global_regs->dvbusdis;
  75290. + DWC_PRINTF("DVBUSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75291. + DWC_READ_REG32(addr));
  75292. +
  75293. + addr = &core_if->dev_if->dev_global_regs->dvbuspulse;
  75294. + DWC_PRINTF("DVBUSPULSE @0x%08lX : 0x%08X\n",
  75295. + (unsigned long)addr, DWC_READ_REG32(addr));
  75296. +
  75297. + addr = &core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
  75298. + DWC_PRINTF("DTKNQR3_DTHRCTL @0x%08lX : 0x%08X\n",
  75299. + (unsigned long)addr, DWC_READ_REG32(addr));
  75300. +
  75301. + if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
  75302. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  75303. + DWC_PRINTF("DTKNQR4 @0x%08lX : 0x%08X\n",
  75304. + (unsigned long)addr, DWC_READ_REG32(addr));
  75305. + }
  75306. +
  75307. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  75308. + DWC_PRINTF("FIFOEMPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75309. + DWC_READ_REG32(addr));
  75310. +
  75311. + if (core_if->hwcfg2.b.multi_proc_int) {
  75312. +
  75313. + addr = &core_if->dev_if->dev_global_regs->deachint;
  75314. + DWC_PRINTF("DEACHINT @0x%08lX : 0x%08X\n",
  75315. + (unsigned long)addr, DWC_READ_REG32(addr));
  75316. + addr = &core_if->dev_if->dev_global_regs->deachintmsk;
  75317. + DWC_PRINTF("DEACHINTMSK @0x%08lX : 0x%08X\n",
  75318. + (unsigned long)addr, DWC_READ_REG32(addr));
  75319. +
  75320. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  75321. + addr =
  75322. + &core_if->dev_if->
  75323. + dev_global_regs->diepeachintmsk[i];
  75324. + DWC_PRINTF("DIEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  75325. + i, (unsigned long)addr,
  75326. + DWC_READ_REG32(addr));
  75327. + }
  75328. +
  75329. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  75330. + addr =
  75331. + &core_if->dev_if->
  75332. + dev_global_regs->doepeachintmsk[i];
  75333. + DWC_PRINTF("DOEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  75334. + i, (unsigned long)addr,
  75335. + DWC_READ_REG32(addr));
  75336. + }
  75337. + }
  75338. +
  75339. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  75340. + DWC_PRINTF("Device IN EP %d Registers\n", i);
  75341. + addr = &core_if->dev_if->in_ep_regs[i]->diepctl;
  75342. + DWC_PRINTF("DIEPCTL @0x%08lX : 0x%08X\n",
  75343. + (unsigned long)addr, DWC_READ_REG32(addr));
  75344. + addr = &core_if->dev_if->in_ep_regs[i]->diepint;
  75345. + DWC_PRINTF("DIEPINT @0x%08lX : 0x%08X\n",
  75346. + (unsigned long)addr, DWC_READ_REG32(addr));
  75347. + addr = &core_if->dev_if->in_ep_regs[i]->dieptsiz;
  75348. + DWC_PRINTF("DIETSIZ @0x%08lX : 0x%08X\n",
  75349. + (unsigned long)addr, DWC_READ_REG32(addr));
  75350. + addr = &core_if->dev_if->in_ep_regs[i]->diepdma;
  75351. + DWC_PRINTF("DIEPDMA @0x%08lX : 0x%08X\n",
  75352. + (unsigned long)addr, DWC_READ_REG32(addr));
  75353. + addr = &core_if->dev_if->in_ep_regs[i]->dtxfsts;
  75354. + DWC_PRINTF("DTXFSTS @0x%08lX : 0x%08X\n",
  75355. + (unsigned long)addr, DWC_READ_REG32(addr));
  75356. + addr = &core_if->dev_if->in_ep_regs[i]->diepdmab;
  75357. + DWC_PRINTF("DIEPDMAB @0x%08lX : 0x%08X\n",
  75358. + (unsigned long)addr, 0 /*DWC_READ_REG32(addr) */ );
  75359. + }
  75360. +
  75361. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  75362. + DWC_PRINTF("Device OUT EP %d Registers\n", i);
  75363. + addr = &core_if->dev_if->out_ep_regs[i]->doepctl;
  75364. + DWC_PRINTF("DOEPCTL @0x%08lX : 0x%08X\n",
  75365. + (unsigned long)addr, DWC_READ_REG32(addr));
  75366. + addr = &core_if->dev_if->out_ep_regs[i]->doepint;
  75367. + DWC_PRINTF("DOEPINT @0x%08lX : 0x%08X\n",
  75368. + (unsigned long)addr, DWC_READ_REG32(addr));
  75369. + addr = &core_if->dev_if->out_ep_regs[i]->doeptsiz;
  75370. + DWC_PRINTF("DOETSIZ @0x%08lX : 0x%08X\n",
  75371. + (unsigned long)addr, DWC_READ_REG32(addr));
  75372. + addr = &core_if->dev_if->out_ep_regs[i]->doepdma;
  75373. + DWC_PRINTF("DOEPDMA @0x%08lX : 0x%08X\n",
  75374. + (unsigned long)addr, DWC_READ_REG32(addr));
  75375. + if (core_if->dma_enable) { /* Don't access this register in SLAVE mode */
  75376. + addr = &core_if->dev_if->out_ep_regs[i]->doepdmab;
  75377. + DWC_PRINTF("DOEPDMAB @0x%08lX : 0x%08X\n",
  75378. + (unsigned long)addr, DWC_READ_REG32(addr));
  75379. + }
  75380. +
  75381. + }
  75382. +}
  75383. +
  75384. +/**
  75385. + * This functions reads the SPRAM and prints its content
  75386. + *
  75387. + * @param core_if Programming view of DWC_otg controller.
  75388. + */
  75389. +void dwc_otg_dump_spram(dwc_otg_core_if_t * core_if)
  75390. +{
  75391. + volatile uint8_t *addr, *start_addr, *end_addr;
  75392. +
  75393. + DWC_PRINTF("SPRAM Data:\n");
  75394. + start_addr = (void *)core_if->core_global_regs;
  75395. + DWC_PRINTF("Base Address: 0x%8lX\n", (unsigned long)start_addr);
  75396. + start_addr += 0x00028000;
  75397. + end_addr = (void *)core_if->core_global_regs;
  75398. + end_addr += 0x000280e0;
  75399. +
  75400. + for (addr = start_addr; addr < end_addr; addr += 16) {
  75401. + DWC_PRINTF
  75402. + ("0x%8lX:\t%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n",
  75403. + (unsigned long)addr, addr[0], addr[1], addr[2], addr[3],
  75404. + addr[4], addr[5], addr[6], addr[7], addr[8], addr[9],
  75405. + addr[10], addr[11], addr[12], addr[13], addr[14], addr[15]
  75406. + );
  75407. + }
  75408. +
  75409. + return;
  75410. +}
  75411. +
  75412. +/**
  75413. + * This function reads the host registers and prints them
  75414. + *
  75415. + * @param core_if Programming view of DWC_otg controller.
  75416. + */
  75417. +void dwc_otg_dump_host_registers(dwc_otg_core_if_t * core_if)
  75418. +{
  75419. + int i;
  75420. + volatile uint32_t *addr;
  75421. +
  75422. + DWC_PRINTF("Host Global Registers\n");
  75423. + addr = &core_if->host_if->host_global_regs->hcfg;
  75424. + DWC_PRINTF("HCFG @0x%08lX : 0x%08X\n",
  75425. + (unsigned long)addr, DWC_READ_REG32(addr));
  75426. + addr = &core_if->host_if->host_global_regs->hfir;
  75427. + DWC_PRINTF("HFIR @0x%08lX : 0x%08X\n",
  75428. + (unsigned long)addr, DWC_READ_REG32(addr));
  75429. + addr = &core_if->host_if->host_global_regs->hfnum;
  75430. + DWC_PRINTF("HFNUM @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75431. + DWC_READ_REG32(addr));
  75432. + addr = &core_if->host_if->host_global_regs->hptxsts;
  75433. + DWC_PRINTF("HPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75434. + DWC_READ_REG32(addr));
  75435. + addr = &core_if->host_if->host_global_regs->haint;
  75436. + DWC_PRINTF("HAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75437. + DWC_READ_REG32(addr));
  75438. + addr = &core_if->host_if->host_global_regs->haintmsk;
  75439. + DWC_PRINTF("HAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75440. + DWC_READ_REG32(addr));
  75441. + if (core_if->dma_desc_enable) {
  75442. + addr = &core_if->host_if->host_global_regs->hflbaddr;
  75443. + DWC_PRINTF("HFLBADDR @0x%08lX : 0x%08X\n",
  75444. + (unsigned long)addr, DWC_READ_REG32(addr));
  75445. + }
  75446. +
  75447. + addr = core_if->host_if->hprt0;
  75448. + DWC_PRINTF("HPRT0 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75449. + DWC_READ_REG32(addr));
  75450. +
  75451. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  75452. + DWC_PRINTF("Host Channel %d Specific Registers\n", i);
  75453. + addr = &core_if->host_if->hc_regs[i]->hcchar;
  75454. + DWC_PRINTF("HCCHAR @0x%08lX : 0x%08X\n",
  75455. + (unsigned long)addr, DWC_READ_REG32(addr));
  75456. + addr = &core_if->host_if->hc_regs[i]->hcsplt;
  75457. + DWC_PRINTF("HCSPLT @0x%08lX : 0x%08X\n",
  75458. + (unsigned long)addr, DWC_READ_REG32(addr));
  75459. + addr = &core_if->host_if->hc_regs[i]->hcint;
  75460. + DWC_PRINTF("HCINT @0x%08lX : 0x%08X\n",
  75461. + (unsigned long)addr, DWC_READ_REG32(addr));
  75462. + addr = &core_if->host_if->hc_regs[i]->hcintmsk;
  75463. + DWC_PRINTF("HCINTMSK @0x%08lX : 0x%08X\n",
  75464. + (unsigned long)addr, DWC_READ_REG32(addr));
  75465. + addr = &core_if->host_if->hc_regs[i]->hctsiz;
  75466. + DWC_PRINTF("HCTSIZ @0x%08lX : 0x%08X\n",
  75467. + (unsigned long)addr, DWC_READ_REG32(addr));
  75468. + addr = &core_if->host_if->hc_regs[i]->hcdma;
  75469. + DWC_PRINTF("HCDMA @0x%08lX : 0x%08X\n",
  75470. + (unsigned long)addr, DWC_READ_REG32(addr));
  75471. + if (core_if->dma_desc_enable) {
  75472. + addr = &core_if->host_if->hc_regs[i]->hcdmab;
  75473. + DWC_PRINTF("HCDMAB @0x%08lX : 0x%08X\n",
  75474. + (unsigned long)addr, DWC_READ_REG32(addr));
  75475. + }
  75476. +
  75477. + }
  75478. + return;
  75479. +}
  75480. +
  75481. +/**
  75482. + * This function reads the core global registers and prints them
  75483. + *
  75484. + * @param core_if Programming view of DWC_otg controller.
  75485. + */
  75486. +void dwc_otg_dump_global_registers(dwc_otg_core_if_t * core_if)
  75487. +{
  75488. + int i, ep_num;
  75489. + volatile uint32_t *addr;
  75490. + char *txfsiz;
  75491. +
  75492. + DWC_PRINTF("Core Global Registers\n");
  75493. + addr = &core_if->core_global_regs->gotgctl;
  75494. + DWC_PRINTF("GOTGCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75495. + DWC_READ_REG32(addr));
  75496. + addr = &core_if->core_global_regs->gotgint;
  75497. + DWC_PRINTF("GOTGINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75498. + DWC_READ_REG32(addr));
  75499. + addr = &core_if->core_global_regs->gahbcfg;
  75500. + DWC_PRINTF("GAHBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75501. + DWC_READ_REG32(addr));
  75502. + addr = &core_if->core_global_regs->gusbcfg;
  75503. + DWC_PRINTF("GUSBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75504. + DWC_READ_REG32(addr));
  75505. + addr = &core_if->core_global_regs->grstctl;
  75506. + DWC_PRINTF("GRSTCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75507. + DWC_READ_REG32(addr));
  75508. + addr = &core_if->core_global_regs->gintsts;
  75509. + DWC_PRINTF("GINTSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75510. + DWC_READ_REG32(addr));
  75511. + addr = &core_if->core_global_regs->gintmsk;
  75512. + DWC_PRINTF("GINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75513. + DWC_READ_REG32(addr));
  75514. + addr = &core_if->core_global_regs->grxstsr;
  75515. + DWC_PRINTF("GRXSTSR @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75516. + DWC_READ_REG32(addr));
  75517. + addr = &core_if->core_global_regs->grxfsiz;
  75518. + DWC_PRINTF("GRXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75519. + DWC_READ_REG32(addr));
  75520. + addr = &core_if->core_global_regs->gnptxfsiz;
  75521. + DWC_PRINTF("GNPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75522. + DWC_READ_REG32(addr));
  75523. + addr = &core_if->core_global_regs->gnptxsts;
  75524. + DWC_PRINTF("GNPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75525. + DWC_READ_REG32(addr));
  75526. + addr = &core_if->core_global_regs->gi2cctl;
  75527. + DWC_PRINTF("GI2CCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75528. + DWC_READ_REG32(addr));
  75529. + addr = &core_if->core_global_regs->gpvndctl;
  75530. + DWC_PRINTF("GPVNDCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75531. + DWC_READ_REG32(addr));
  75532. + addr = &core_if->core_global_regs->ggpio;
  75533. + DWC_PRINTF("GGPIO @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75534. + DWC_READ_REG32(addr));
  75535. + addr = &core_if->core_global_regs->guid;
  75536. + DWC_PRINTF("GUID @0x%08lX : 0x%08X\n",
  75537. + (unsigned long)addr, DWC_READ_REG32(addr));
  75538. + addr = &core_if->core_global_regs->gsnpsid;
  75539. + DWC_PRINTF("GSNPSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75540. + DWC_READ_REG32(addr));
  75541. + addr = &core_if->core_global_regs->ghwcfg1;
  75542. + DWC_PRINTF("GHWCFG1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75543. + DWC_READ_REG32(addr));
  75544. + addr = &core_if->core_global_regs->ghwcfg2;
  75545. + DWC_PRINTF("GHWCFG2 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75546. + DWC_READ_REG32(addr));
  75547. + addr = &core_if->core_global_regs->ghwcfg3;
  75548. + DWC_PRINTF("GHWCFG3 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75549. + DWC_READ_REG32(addr));
  75550. + addr = &core_if->core_global_regs->ghwcfg4;
  75551. + DWC_PRINTF("GHWCFG4 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75552. + DWC_READ_REG32(addr));
  75553. + addr = &core_if->core_global_regs->glpmcfg;
  75554. + DWC_PRINTF("GLPMCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75555. + DWC_READ_REG32(addr));
  75556. + addr = &core_if->core_global_regs->gpwrdn;
  75557. + DWC_PRINTF("GPWRDN @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75558. + DWC_READ_REG32(addr));
  75559. + addr = &core_if->core_global_regs->gdfifocfg;
  75560. + DWC_PRINTF("GDFIFOCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75561. + DWC_READ_REG32(addr));
  75562. + addr = &core_if->core_global_regs->adpctl;
  75563. + DWC_PRINTF("ADPCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75564. + dwc_otg_adp_read_reg(core_if));
  75565. + addr = &core_if->core_global_regs->hptxfsiz;
  75566. + DWC_PRINTF("HPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75567. + DWC_READ_REG32(addr));
  75568. +
  75569. + if (core_if->en_multiple_tx_fifo == 0) {
  75570. + ep_num = core_if->hwcfg4.b.num_dev_perio_in_ep;
  75571. + txfsiz = "DPTXFSIZ";
  75572. + } else {
  75573. + ep_num = core_if->hwcfg4.b.num_in_eps;
  75574. + txfsiz = "DIENPTXF";
  75575. + }
  75576. + for (i = 0; i < ep_num; i++) {
  75577. + addr = &core_if->core_global_regs->dtxfsiz[i];
  75578. + DWC_PRINTF("%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1,
  75579. + (unsigned long)addr, DWC_READ_REG32(addr));
  75580. + }
  75581. + addr = core_if->pcgcctl;
  75582. + DWC_PRINTF("PCGCCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75583. + DWC_READ_REG32(addr));
  75584. +}
  75585. +
  75586. +/**
  75587. + * Flush a Tx FIFO.
  75588. + *
  75589. + * @param core_if Programming view of DWC_otg controller.
  75590. + * @param num Tx FIFO to flush.
  75591. + */
  75592. +void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * core_if, const int num)
  75593. +{
  75594. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  75595. + volatile grstctl_t greset = {.d32 = 0 };
  75596. + int count = 0;
  75597. +
  75598. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "Flush Tx FIFO %d\n", num);
  75599. +
  75600. + greset.b.txfflsh = 1;
  75601. + greset.b.txfnum = num;
  75602. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  75603. +
  75604. + do {
  75605. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  75606. + if (++count > 10000) {
  75607. + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
  75608. + __func__, greset.d32,
  75609. + DWC_READ_REG32(&global_regs->gnptxsts));
  75610. + break;
  75611. + }
  75612. + dwc_udelay(1);
  75613. + } while (greset.b.txfflsh == 1);
  75614. +
  75615. + /* Wait for 3 PHY Clocks */
  75616. + dwc_udelay(1);
  75617. +}
  75618. +
  75619. +/**
  75620. + * Flush Rx FIFO.
  75621. + *
  75622. + * @param core_if Programming view of DWC_otg controller.
  75623. + */
  75624. +void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * core_if)
  75625. +{
  75626. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  75627. + volatile grstctl_t greset = {.d32 = 0 };
  75628. + int count = 0;
  75629. +
  75630. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "%s\n", __func__);
  75631. + /*
  75632. + *
  75633. + */
  75634. + greset.b.rxfflsh = 1;
  75635. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  75636. +
  75637. + do {
  75638. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  75639. + if (++count > 10000) {
  75640. + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
  75641. + greset.d32);
  75642. + break;
  75643. + }
  75644. + dwc_udelay(1);
  75645. + } while (greset.b.rxfflsh == 1);
  75646. +
  75647. + /* Wait for 3 PHY Clocks */
  75648. + dwc_udelay(1);
  75649. +}
  75650. +
  75651. +/**
  75652. + * Do core a soft reset of the core. Be careful with this because it
  75653. + * resets all the internal state machines of the core.
  75654. + */
  75655. +void dwc_otg_core_reset(dwc_otg_core_if_t * core_if)
  75656. +{
  75657. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  75658. + volatile grstctl_t greset = {.d32 = 0 };
  75659. + int count = 0;
  75660. +
  75661. + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
  75662. + /* Wait for AHB master IDLE state. */
  75663. + do {
  75664. + dwc_udelay(10);
  75665. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  75666. + if (++count > 100000) {
  75667. + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
  75668. + greset.d32);
  75669. + return;
  75670. + }
  75671. + }
  75672. + while (greset.b.ahbidle == 0);
  75673. +
  75674. + /* Core Soft Reset */
  75675. + count = 0;
  75676. + greset.b.csftrst = 1;
  75677. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  75678. + do {
  75679. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  75680. + if (++count > 10000) {
  75681. + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n",
  75682. + __func__, greset.d32);
  75683. + break;
  75684. + }
  75685. + dwc_udelay(1);
  75686. + }
  75687. + while (greset.b.csftrst == 1);
  75688. +
  75689. + /* Wait for 3 PHY Clocks */
  75690. + dwc_mdelay(100);
  75691. +}
  75692. +
  75693. +uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if)
  75694. +{
  75695. + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
  75696. +}
  75697. +
  75698. +uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if)
  75699. +{
  75700. + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
  75701. +}
  75702. +
  75703. +/**
  75704. + * Register HCD callbacks. The callbacks are used to start and stop
  75705. + * the HCD for interrupt processing.
  75706. + *
  75707. + * @param core_if Programming view of DWC_otg controller.
  75708. + * @param cb the HCD callback structure.
  75709. + * @param p pointer to be passed to callback function (usb_hcd*).
  75710. + */
  75711. +void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * core_if,
  75712. + dwc_otg_cil_callbacks_t * cb, void *p)
  75713. +{
  75714. + core_if->hcd_cb = cb;
  75715. + cb->p = p;
  75716. +}
  75717. +
  75718. +/**
  75719. + * Register PCD callbacks. The callbacks are used to start and stop
  75720. + * the PCD for interrupt processing.
  75721. + *
  75722. + * @param core_if Programming view of DWC_otg controller.
  75723. + * @param cb the PCD callback structure.
  75724. + * @param p pointer to be passed to callback function (pcd*).
  75725. + */
  75726. +void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * core_if,
  75727. + dwc_otg_cil_callbacks_t * cb, void *p)
  75728. +{
  75729. + core_if->pcd_cb = cb;
  75730. + cb->p = p;
  75731. +}
  75732. +
  75733. +#ifdef DWC_EN_ISOC
  75734. +
  75735. +/**
  75736. + * This function writes isoc data per 1 (micro)frame into tx fifo
  75737. + *
  75738. + * @param core_if Programming view of DWC_otg controller.
  75739. + * @param ep The EP to start the transfer on.
  75740. + *
  75741. + */
  75742. +void write_isoc_frame_data(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  75743. +{
  75744. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  75745. + dtxfsts_data_t txstatus = {.d32 = 0 };
  75746. + uint32_t len = 0;
  75747. + uint32_t dwords;
  75748. +
  75749. + ep->xfer_len = ep->data_per_frame;
  75750. + ep->xfer_count = 0;
  75751. +
  75752. + ep_regs = core_if->dev_if->in_ep_regs[ep->num];
  75753. +
  75754. + len = ep->xfer_len - ep->xfer_count;
  75755. +
  75756. + if (len > ep->maxpacket) {
  75757. + len = ep->maxpacket;
  75758. + }
  75759. +
  75760. + dwords = (len + 3) / 4;
  75761. +
  75762. + /* While there is space in the queue and space in the FIFO and
  75763. + * More data to tranfer, Write packets to the Tx FIFO */
  75764. + txstatus.d32 =
  75765. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
  75766. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
  75767. +
  75768. + while (txstatus.b.txfspcavail > dwords &&
  75769. + ep->xfer_count < ep->xfer_len && ep->xfer_len != 0) {
  75770. + /* Write the FIFO */
  75771. + dwc_otg_ep_write_packet(core_if, ep, 0);
  75772. +
  75773. + len = ep->xfer_len - ep->xfer_count;
  75774. + if (len > ep->maxpacket) {
  75775. + len = ep->maxpacket;
  75776. + }
  75777. +
  75778. + dwords = (len + 3) / 4;
  75779. + txstatus.d32 =
  75780. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  75781. + dtxfsts);
  75782. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", ep->num,
  75783. + txstatus.d32);
  75784. + }
  75785. +}
  75786. +
  75787. +/**
  75788. + * This function initializes a descriptor chain for Isochronous transfer
  75789. + *
  75790. + * @param core_if Programming view of DWC_otg controller.
  75791. + * @param ep The EP to start the transfer on.
  75792. + *
  75793. + */
  75794. +void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  75795. + dwc_ep_t * ep)
  75796. +{
  75797. + deptsiz_data_t deptsiz = {.d32 = 0 };
  75798. + depctl_data_t depctl = {.d32 = 0 };
  75799. + dsts_data_t dsts = {.d32 = 0 };
  75800. + volatile uint32_t *addr;
  75801. +
  75802. + if (ep->is_in) {
  75803. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  75804. + } else {
  75805. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  75806. + }
  75807. +
  75808. + ep->xfer_len = ep->data_per_frame;
  75809. + ep->xfer_count = 0;
  75810. + ep->xfer_buff = ep->cur_pkt_addr;
  75811. + ep->dma_addr = ep->cur_pkt_dma_addr;
  75812. +
  75813. + if (ep->is_in) {
  75814. + /* Program the transfer size and packet count
  75815. + * as follows: xfersize = N * maxpacket +
  75816. + * short_packet pktcnt = N + (short_packet
  75817. + * exist ? 1 : 0)
  75818. + */
  75819. + deptsiz.b.xfersize = ep->xfer_len;
  75820. + deptsiz.b.pktcnt =
  75821. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  75822. + deptsiz.b.mc = deptsiz.b.pktcnt;
  75823. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz,
  75824. + deptsiz.d32);
  75825. +
  75826. + /* Write the DMA register */
  75827. + if (core_if->dma_enable) {
  75828. + DWC_WRITE_REG32(&
  75829. + (core_if->dev_if->in_ep_regs[ep->num]->
  75830. + diepdma), (uint32_t) ep->dma_addr);
  75831. + }
  75832. + } else {
  75833. + deptsiz.b.pktcnt =
  75834. + (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket;
  75835. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  75836. +
  75837. + DWC_WRITE_REG32(&core_if->dev_if->
  75838. + out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
  75839. +
  75840. + if (core_if->dma_enable) {
  75841. + DWC_WRITE_REG32(&
  75842. + (core_if->dev_if->
  75843. + out_ep_regs[ep->num]->doepdma),
  75844. + (uint32_t) ep->dma_addr);
  75845. + }
  75846. + }
  75847. +
  75848. + /** Enable endpoint, clear nak */
  75849. +
  75850. + depctl.d32 = 0;
  75851. + if (ep->bInterval == 1) {
  75852. + dsts.d32 =
  75853. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  75854. + ep->next_frame = dsts.b.soffn + ep->bInterval;
  75855. +
  75856. + if (ep->next_frame & 0x1) {
  75857. + depctl.b.setd1pid = 1;
  75858. + } else {
  75859. + depctl.b.setd0pid = 1;
  75860. + }
  75861. + } else {
  75862. + ep->next_frame += ep->bInterval;
  75863. +
  75864. + if (ep->next_frame & 0x1) {
  75865. + depctl.b.setd1pid = 1;
  75866. + } else {
  75867. + depctl.b.setd0pid = 1;
  75868. + }
  75869. + }
  75870. + depctl.b.epena = 1;
  75871. + depctl.b.cnak = 1;
  75872. +
  75873. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  75874. + depctl.d32 = DWC_READ_REG32(addr);
  75875. +
  75876. + if (ep->is_in && core_if->dma_enable == 0) {
  75877. + write_isoc_frame_data(core_if, ep);
  75878. + }
  75879. +
  75880. +}
  75881. +#endif /* DWC_EN_ISOC */
  75882. +
  75883. +static void dwc_otg_set_uninitialized(int32_t * p, int size)
  75884. +{
  75885. + int i;
  75886. + for (i = 0; i < size; i++) {
  75887. + p[i] = -1;
  75888. + }
  75889. +}
  75890. +
  75891. +static int dwc_otg_param_initialized(int32_t val)
  75892. +{
  75893. + return val != -1;
  75894. +}
  75895. +
  75896. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if)
  75897. +{
  75898. + int i;
  75899. + core_if->core_params = DWC_ALLOC(sizeof(*core_if->core_params));
  75900. + if (!core_if->core_params) {
  75901. + return -DWC_E_NO_MEMORY;
  75902. + }
  75903. + dwc_otg_set_uninitialized((int32_t *) core_if->core_params,
  75904. + sizeof(*core_if->core_params) /
  75905. + sizeof(int32_t));
  75906. + DWC_PRINTF("Setting default values for core params\n");
  75907. + dwc_otg_set_param_otg_cap(core_if, dwc_param_otg_cap_default);
  75908. + dwc_otg_set_param_dma_enable(core_if, dwc_param_dma_enable_default);
  75909. + dwc_otg_set_param_dma_desc_enable(core_if,
  75910. + dwc_param_dma_desc_enable_default);
  75911. + dwc_otg_set_param_opt(core_if, dwc_param_opt_default);
  75912. + dwc_otg_set_param_dma_burst_size(core_if,
  75913. + dwc_param_dma_burst_size_default);
  75914. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  75915. + dwc_param_host_support_fs_ls_low_power_default);
  75916. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  75917. + dwc_param_enable_dynamic_fifo_default);
  75918. + dwc_otg_set_param_data_fifo_size(core_if,
  75919. + dwc_param_data_fifo_size_default);
  75920. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  75921. + dwc_param_dev_rx_fifo_size_default);
  75922. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  75923. + dwc_param_dev_nperio_tx_fifo_size_default);
  75924. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  75925. + dwc_param_host_rx_fifo_size_default);
  75926. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  75927. + dwc_param_host_nperio_tx_fifo_size_default);
  75928. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  75929. + dwc_param_host_perio_tx_fifo_size_default);
  75930. + dwc_otg_set_param_max_transfer_size(core_if,
  75931. + dwc_param_max_transfer_size_default);
  75932. + dwc_otg_set_param_max_packet_count(core_if,
  75933. + dwc_param_max_packet_count_default);
  75934. + dwc_otg_set_param_host_channels(core_if,
  75935. + dwc_param_host_channels_default);
  75936. + dwc_otg_set_param_dev_endpoints(core_if,
  75937. + dwc_param_dev_endpoints_default);
  75938. + dwc_otg_set_param_phy_type(core_if, dwc_param_phy_type_default);
  75939. + dwc_otg_set_param_speed(core_if, dwc_param_speed_default);
  75940. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  75941. + dwc_param_host_ls_low_power_phy_clk_default);
  75942. + dwc_otg_set_param_phy_ulpi_ddr(core_if, dwc_param_phy_ulpi_ddr_default);
  75943. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  75944. + dwc_param_phy_ulpi_ext_vbus_default);
  75945. + dwc_otg_set_param_phy_utmi_width(core_if,
  75946. + dwc_param_phy_utmi_width_default);
  75947. + dwc_otg_set_param_ts_dline(core_if, dwc_param_ts_dline_default);
  75948. + dwc_otg_set_param_i2c_enable(core_if, dwc_param_i2c_enable_default);
  75949. + dwc_otg_set_param_ulpi_fs_ls(core_if, dwc_param_ulpi_fs_ls_default);
  75950. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  75951. + dwc_param_en_multiple_tx_fifo_default);
  75952. + for (i = 0; i < 15; i++) {
  75953. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  75954. + dwc_param_dev_perio_tx_fifo_size_default,
  75955. + i);
  75956. + }
  75957. +
  75958. + for (i = 0; i < 15; i++) {
  75959. + dwc_otg_set_param_dev_tx_fifo_size(core_if,
  75960. + dwc_param_dev_tx_fifo_size_default,
  75961. + i);
  75962. + }
  75963. + dwc_otg_set_param_thr_ctl(core_if, dwc_param_thr_ctl_default);
  75964. + dwc_otg_set_param_mpi_enable(core_if, dwc_param_mpi_enable_default);
  75965. + dwc_otg_set_param_pti_enable(core_if, dwc_param_pti_enable_default);
  75966. + dwc_otg_set_param_lpm_enable(core_if, dwc_param_lpm_enable_default);
  75967. + dwc_otg_set_param_ic_usb_cap(core_if, dwc_param_ic_usb_cap_default);
  75968. + dwc_otg_set_param_tx_thr_length(core_if,
  75969. + dwc_param_tx_thr_length_default);
  75970. + dwc_otg_set_param_rx_thr_length(core_if,
  75971. + dwc_param_rx_thr_length_default);
  75972. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  75973. + dwc_param_ahb_thr_ratio_default);
  75974. + dwc_otg_set_param_power_down(core_if, dwc_param_power_down_default);
  75975. + dwc_otg_set_param_reload_ctl(core_if, dwc_param_reload_ctl_default);
  75976. + dwc_otg_set_param_dev_out_nak(core_if, dwc_param_dev_out_nak_default);
  75977. + dwc_otg_set_param_cont_on_bna(core_if, dwc_param_cont_on_bna_default);
  75978. + dwc_otg_set_param_ahb_single(core_if, dwc_param_ahb_single_default);
  75979. + dwc_otg_set_param_otg_ver(core_if, dwc_param_otg_ver_default);
  75980. + dwc_otg_set_param_adp_enable(core_if, dwc_param_adp_enable_default);
  75981. + DWC_PRINTF("Finished setting default values for core params\n");
  75982. +
  75983. + return 0;
  75984. +}
  75985. +
  75986. +uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if)
  75987. +{
  75988. + return core_if->dma_enable;
  75989. +}
  75990. +
  75991. +/* Checks if the parameter is outside of its valid range of values */
  75992. +#define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
  75993. + (((_param_) < (_low_)) || \
  75994. + ((_param_) > (_high_)))
  75995. +
  75996. +/* Parameter access functions */
  75997. +int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val)
  75998. +{
  75999. + int valid;
  76000. + int retval = 0;
  76001. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  76002. + DWC_WARN("Wrong value for otg_cap parameter\n");
  76003. + DWC_WARN("otg_cap parameter must be 0,1 or 2\n");
  76004. + retval = -DWC_E_INVALID;
  76005. + goto out;
  76006. + }
  76007. +
  76008. + valid = 1;
  76009. + switch (val) {
  76010. + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
  76011. + if (core_if->hwcfg2.b.op_mode !=
  76012. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  76013. + valid = 0;
  76014. + break;
  76015. + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
  76016. + if ((core_if->hwcfg2.b.op_mode !=
  76017. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  76018. + && (core_if->hwcfg2.b.op_mode !=
  76019. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  76020. + && (core_if->hwcfg2.b.op_mode !=
  76021. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  76022. + && (core_if->hwcfg2.b.op_mode !=
  76023. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
  76024. + valid = 0;
  76025. + }
  76026. + break;
  76027. + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
  76028. + /* always valid */
  76029. + break;
  76030. + }
  76031. + if (!valid) {
  76032. + if (dwc_otg_param_initialized(core_if->core_params->otg_cap)) {
  76033. + DWC_ERROR
  76034. + ("%d invalid for otg_cap paremter. Check HW configuration.\n",
  76035. + val);
  76036. + }
  76037. + val =
  76038. + (((core_if->hwcfg2.b.op_mode ==
  76039. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  76040. + || (core_if->hwcfg2.b.op_mode ==
  76041. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  76042. + || (core_if->hwcfg2.b.op_mode ==
  76043. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  76044. + || (core_if->hwcfg2.b.op_mode ==
  76045. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
  76046. + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
  76047. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  76048. + retval = -DWC_E_INVALID;
  76049. + }
  76050. +
  76051. + core_if->core_params->otg_cap = val;
  76052. +out:
  76053. + return retval;
  76054. +}
  76055. +
  76056. +int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if)
  76057. +{
  76058. + return core_if->core_params->otg_cap;
  76059. +}
  76060. +
  76061. +int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val)
  76062. +{
  76063. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76064. + DWC_WARN("Wrong value for opt parameter\n");
  76065. + return -DWC_E_INVALID;
  76066. + }
  76067. + core_if->core_params->opt = val;
  76068. + return 0;
  76069. +}
  76070. +
  76071. +int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if)
  76072. +{
  76073. + return core_if->core_params->opt;
  76074. +}
  76075. +
  76076. +int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if, int32_t val)
  76077. +{
  76078. + int retval = 0;
  76079. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76080. + DWC_WARN("Wrong value for dma enable\n");
  76081. + return -DWC_E_INVALID;
  76082. + }
  76083. +
  76084. + if ((val == 1) && (core_if->hwcfg2.b.architecture == 0)) {
  76085. + if (dwc_otg_param_initialized(core_if->core_params->dma_enable)) {
  76086. + DWC_ERROR
  76087. + ("%d invalid for dma_enable paremter. Check HW configuration.\n",
  76088. + val);
  76089. + }
  76090. + val = 0;
  76091. + retval = -DWC_E_INVALID;
  76092. + }
  76093. +
  76094. + core_if->core_params->dma_enable = val;
  76095. + if (val == 0) {
  76096. + dwc_otg_set_param_dma_desc_enable(core_if, 0);
  76097. + }
  76098. + return retval;
  76099. +}
  76100. +
  76101. +int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if)
  76102. +{
  76103. + return core_if->core_params->dma_enable;
  76104. +}
  76105. +
  76106. +int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if, int32_t val)
  76107. +{
  76108. + int retval = 0;
  76109. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76110. + DWC_WARN("Wrong value for dma_enable\n");
  76111. + DWC_WARN("dma_desc_enable must be 0 or 1\n");
  76112. + return -DWC_E_INVALID;
  76113. + }
  76114. +
  76115. + if ((val == 1)
  76116. + && ((dwc_otg_get_param_dma_enable(core_if) == 0)
  76117. + || (core_if->hwcfg4.b.desc_dma == 0))) {
  76118. + if (dwc_otg_param_initialized
  76119. + (core_if->core_params->dma_desc_enable)) {
  76120. + DWC_ERROR
  76121. + ("%d invalid for dma_desc_enable paremter. Check HW configuration.\n",
  76122. + val);
  76123. + }
  76124. + val = 0;
  76125. + retval = -DWC_E_INVALID;
  76126. + }
  76127. + core_if->core_params->dma_desc_enable = val;
  76128. + return retval;
  76129. +}
  76130. +
  76131. +int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if)
  76132. +{
  76133. + return core_if->core_params->dma_desc_enable;
  76134. +}
  76135. +
  76136. +int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t * core_if,
  76137. + int32_t val)
  76138. +{
  76139. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76140. + DWC_WARN("Wrong value for host_support_fs_low_power\n");
  76141. + DWC_WARN("host_support_fs_low_power must be 0 or 1\n");
  76142. + return -DWC_E_INVALID;
  76143. + }
  76144. + core_if->core_params->host_support_fs_ls_low_power = val;
  76145. + return 0;
  76146. +}
  76147. +
  76148. +int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  76149. + core_if)
  76150. +{
  76151. + return core_if->core_params->host_support_fs_ls_low_power;
  76152. +}
  76153. +
  76154. +int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  76155. + int32_t val)
  76156. +{
  76157. + int retval = 0;
  76158. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76159. + DWC_WARN("Wrong value for enable_dynamic_fifo\n");
  76160. + DWC_WARN("enable_dynamic_fifo must be 0 or 1\n");
  76161. + return -DWC_E_INVALID;
  76162. + }
  76163. +
  76164. + if ((val == 1) && (core_if->hwcfg2.b.dynamic_fifo == 0)) {
  76165. + if (dwc_otg_param_initialized
  76166. + (core_if->core_params->enable_dynamic_fifo)) {
  76167. + DWC_ERROR
  76168. + ("%d invalid for enable_dynamic_fifo paremter. Check HW configuration.\n",
  76169. + val);
  76170. + }
  76171. + val = 0;
  76172. + retval = -DWC_E_INVALID;
  76173. + }
  76174. + core_if->core_params->enable_dynamic_fifo = val;
  76175. + return retval;
  76176. +}
  76177. +
  76178. +int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if)
  76179. +{
  76180. + return core_if->core_params->enable_dynamic_fifo;
  76181. +}
  76182. +
  76183. +int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  76184. +{
  76185. + int retval = 0;
  76186. + if (DWC_OTG_PARAM_TEST(val, 32, 32768)) {
  76187. + DWC_WARN("Wrong value for data_fifo_size\n");
  76188. + DWC_WARN("data_fifo_size must be 32-32768\n");
  76189. + return -DWC_E_INVALID;
  76190. + }
  76191. +
  76192. + if (val > core_if->hwcfg3.b.dfifo_depth) {
  76193. + if (dwc_otg_param_initialized
  76194. + (core_if->core_params->data_fifo_size)) {
  76195. + DWC_ERROR
  76196. + ("%d invalid for data_fifo_size parameter. Check HW configuration.\n",
  76197. + val);
  76198. + }
  76199. + val = core_if->hwcfg3.b.dfifo_depth;
  76200. + retval = -DWC_E_INVALID;
  76201. + }
  76202. +
  76203. + core_if->core_params->data_fifo_size = val;
  76204. + return retval;
  76205. +}
  76206. +
  76207. +int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if)
  76208. +{
  76209. + return core_if->core_params->data_fifo_size;
  76210. +}
  76211. +
  76212. +int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  76213. +{
  76214. + int retval = 0;
  76215. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  76216. + DWC_WARN("Wrong value for dev_rx_fifo_size\n");
  76217. + DWC_WARN("dev_rx_fifo_size must be 16-32768\n");
  76218. + return -DWC_E_INVALID;
  76219. + }
  76220. +
  76221. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  76222. + if (dwc_otg_param_initialized(core_if->core_params->dev_rx_fifo_size)) {
  76223. + DWC_WARN("%d invalid for dev_rx_fifo_size parameter\n", val);
  76224. + }
  76225. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  76226. + retval = -DWC_E_INVALID;
  76227. + }
  76228. +
  76229. + core_if->core_params->dev_rx_fifo_size = val;
  76230. + return retval;
  76231. +}
  76232. +
  76233. +int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if)
  76234. +{
  76235. + return core_if->core_params->dev_rx_fifo_size;
  76236. +}
  76237. +
  76238. +int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  76239. + int32_t val)
  76240. +{
  76241. + int retval = 0;
  76242. +
  76243. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  76244. + DWC_WARN("Wrong value for dev_nperio_tx_fifo\n");
  76245. + DWC_WARN("dev_nperio_tx_fifo must be 16-32768\n");
  76246. + return -DWC_E_INVALID;
  76247. + }
  76248. +
  76249. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  76250. + if (dwc_otg_param_initialized
  76251. + (core_if->core_params->dev_nperio_tx_fifo_size)) {
  76252. + DWC_ERROR
  76253. + ("%d invalid for dev_nperio_tx_fifo_size. Check HW configuration.\n",
  76254. + val);
  76255. + }
  76256. + val =
  76257. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  76258. + 16);
  76259. + retval = -DWC_E_INVALID;
  76260. + }
  76261. +
  76262. + core_if->core_params->dev_nperio_tx_fifo_size = val;
  76263. + return retval;
  76264. +}
  76265. +
  76266. +int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  76267. +{
  76268. + return core_if->core_params->dev_nperio_tx_fifo_size;
  76269. +}
  76270. +
  76271. +int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  76272. + int32_t val)
  76273. +{
  76274. + int retval = 0;
  76275. +
  76276. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  76277. + DWC_WARN("Wrong value for host_rx_fifo_size\n");
  76278. + DWC_WARN("host_rx_fifo_size must be 16-32768\n");
  76279. + return -DWC_E_INVALID;
  76280. + }
  76281. +
  76282. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  76283. + if (dwc_otg_param_initialized
  76284. + (core_if->core_params->host_rx_fifo_size)) {
  76285. + DWC_ERROR
  76286. + ("%d invalid for host_rx_fifo_size. Check HW configuration.\n",
  76287. + val);
  76288. + }
  76289. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  76290. + retval = -DWC_E_INVALID;
  76291. + }
  76292. +
  76293. + core_if->core_params->host_rx_fifo_size = val;
  76294. + return retval;
  76295. +
  76296. +}
  76297. +
  76298. +int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if)
  76299. +{
  76300. + return core_if->core_params->host_rx_fifo_size;
  76301. +}
  76302. +
  76303. +int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  76304. + int32_t val)
  76305. +{
  76306. + int retval = 0;
  76307. +
  76308. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  76309. + DWC_WARN("Wrong value for host_nperio_tx_fifo_size\n");
  76310. + DWC_WARN("host_nperio_tx_fifo_size must be 16-32768\n");
  76311. + return -DWC_E_INVALID;
  76312. + }
  76313. +
  76314. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  76315. + if (dwc_otg_param_initialized
  76316. + (core_if->core_params->host_nperio_tx_fifo_size)) {
  76317. + DWC_ERROR
  76318. + ("%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
  76319. + val);
  76320. + }
  76321. + val =
  76322. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  76323. + 16);
  76324. + retval = -DWC_E_INVALID;
  76325. + }
  76326. +
  76327. + core_if->core_params->host_nperio_tx_fifo_size = val;
  76328. + return retval;
  76329. +}
  76330. +
  76331. +int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  76332. +{
  76333. + return core_if->core_params->host_nperio_tx_fifo_size;
  76334. +}
  76335. +
  76336. +int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  76337. + int32_t val)
  76338. +{
  76339. + int retval = 0;
  76340. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  76341. + DWC_WARN("Wrong value for host_perio_tx_fifo_size\n");
  76342. + DWC_WARN("host_perio_tx_fifo_size must be 16-32768\n");
  76343. + return -DWC_E_INVALID;
  76344. + }
  76345. +
  76346. + if (val > ((core_if->hptxfsiz.d32) >> 16)) {
  76347. + if (dwc_otg_param_initialized
  76348. + (core_if->core_params->host_perio_tx_fifo_size)) {
  76349. + DWC_ERROR
  76350. + ("%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
  76351. + val);
  76352. + }
  76353. + val = (core_if->hptxfsiz.d32) >> 16;
  76354. + retval = -DWC_E_INVALID;
  76355. + }
  76356. +
  76357. + core_if->core_params->host_perio_tx_fifo_size = val;
  76358. + return retval;
  76359. +}
  76360. +
  76361. +int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  76362. +{
  76363. + return core_if->core_params->host_perio_tx_fifo_size;
  76364. +}
  76365. +
  76366. +int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  76367. + int32_t val)
  76368. +{
  76369. + int retval = 0;
  76370. +
  76371. + if (DWC_OTG_PARAM_TEST(val, 2047, 524288)) {
  76372. + DWC_WARN("Wrong value for max_transfer_size\n");
  76373. + DWC_WARN("max_transfer_size must be 2047-524288\n");
  76374. + return -DWC_E_INVALID;
  76375. + }
  76376. +
  76377. + if (val >= (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))) {
  76378. + if (dwc_otg_param_initialized
  76379. + (core_if->core_params->max_transfer_size)) {
  76380. + DWC_ERROR
  76381. + ("%d invalid for max_transfer_size. Check HW configuration.\n",
  76382. + val);
  76383. + }
  76384. + val =
  76385. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 11)) -
  76386. + 1);
  76387. + retval = -DWC_E_INVALID;
  76388. + }
  76389. +
  76390. + core_if->core_params->max_transfer_size = val;
  76391. + return retval;
  76392. +}
  76393. +
  76394. +int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if)
  76395. +{
  76396. + return core_if->core_params->max_transfer_size;
  76397. +}
  76398. +
  76399. +int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if, int32_t val)
  76400. +{
  76401. + int retval = 0;
  76402. +
  76403. + if (DWC_OTG_PARAM_TEST(val, 15, 511)) {
  76404. + DWC_WARN("Wrong value for max_packet_count\n");
  76405. + DWC_WARN("max_packet_count must be 15-511\n");
  76406. + return -DWC_E_INVALID;
  76407. + }
  76408. +
  76409. + if (val > (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))) {
  76410. + if (dwc_otg_param_initialized
  76411. + (core_if->core_params->max_packet_count)) {
  76412. + DWC_ERROR
  76413. + ("%d invalid for max_packet_count. Check HW configuration.\n",
  76414. + val);
  76415. + }
  76416. + val =
  76417. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1);
  76418. + retval = -DWC_E_INVALID;
  76419. + }
  76420. +
  76421. + core_if->core_params->max_packet_count = val;
  76422. + return retval;
  76423. +}
  76424. +
  76425. +int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if)
  76426. +{
  76427. + return core_if->core_params->max_packet_count;
  76428. +}
  76429. +
  76430. +int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if, int32_t val)
  76431. +{
  76432. + int retval = 0;
  76433. +
  76434. + if (DWC_OTG_PARAM_TEST(val, 1, 16)) {
  76435. + DWC_WARN("Wrong value for host_channels\n");
  76436. + DWC_WARN("host_channels must be 1-16\n");
  76437. + return -DWC_E_INVALID;
  76438. + }
  76439. +
  76440. + if (val > (core_if->hwcfg2.b.num_host_chan + 1)) {
  76441. + if (dwc_otg_param_initialized
  76442. + (core_if->core_params->host_channels)) {
  76443. + DWC_ERROR
  76444. + ("%d invalid for host_channels. Check HW configurations.\n",
  76445. + val);
  76446. + }
  76447. + val = (core_if->hwcfg2.b.num_host_chan + 1);
  76448. + retval = -DWC_E_INVALID;
  76449. + }
  76450. +
  76451. + core_if->core_params->host_channels = val;
  76452. + return retval;
  76453. +}
  76454. +
  76455. +int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if)
  76456. +{
  76457. + return core_if->core_params->host_channels;
  76458. +}
  76459. +
  76460. +int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if, int32_t val)
  76461. +{
  76462. + int retval = 0;
  76463. +
  76464. + if (DWC_OTG_PARAM_TEST(val, 1, 15)) {
  76465. + DWC_WARN("Wrong value for dev_endpoints\n");
  76466. + DWC_WARN("dev_endpoints must be 1-15\n");
  76467. + return -DWC_E_INVALID;
  76468. + }
  76469. +
  76470. + if (val > (core_if->hwcfg2.b.num_dev_ep)) {
  76471. + if (dwc_otg_param_initialized
  76472. + (core_if->core_params->dev_endpoints)) {
  76473. + DWC_ERROR
  76474. + ("%d invalid for dev_endpoints. Check HW configurations.\n",
  76475. + val);
  76476. + }
  76477. + val = core_if->hwcfg2.b.num_dev_ep;
  76478. + retval = -DWC_E_INVALID;
  76479. + }
  76480. +
  76481. + core_if->core_params->dev_endpoints = val;
  76482. + return retval;
  76483. +}
  76484. +
  76485. +int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if)
  76486. +{
  76487. + return core_if->core_params->dev_endpoints;
  76488. +}
  76489. +
  76490. +int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val)
  76491. +{
  76492. + int retval = 0;
  76493. + int valid = 0;
  76494. +
  76495. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  76496. + DWC_WARN("Wrong value for phy_type\n");
  76497. + DWC_WARN("phy_type must be 0,1 or 2\n");
  76498. + return -DWC_E_INVALID;
  76499. + }
  76500. +#ifndef NO_FS_PHY_HW_CHECKS
  76501. + if ((val == DWC_PHY_TYPE_PARAM_UTMI) &&
  76502. + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
  76503. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  76504. + valid = 1;
  76505. + } else if ((val == DWC_PHY_TYPE_PARAM_ULPI) &&
  76506. + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
  76507. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  76508. + valid = 1;
  76509. + } else if ((val == DWC_PHY_TYPE_PARAM_FS) &&
  76510. + (core_if->hwcfg2.b.fs_phy_type == 1)) {
  76511. + valid = 1;
  76512. + }
  76513. + if (!valid) {
  76514. + if (dwc_otg_param_initialized(core_if->core_params->phy_type)) {
  76515. + DWC_ERROR
  76516. + ("%d invalid for phy_type. Check HW configurations.\n",
  76517. + val);
  76518. + }
  76519. + if (core_if->hwcfg2.b.hs_phy_type) {
  76520. + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
  76521. + (core_if->hwcfg2.b.hs_phy_type == 1)) {
  76522. + val = DWC_PHY_TYPE_PARAM_UTMI;
  76523. + } else {
  76524. + val = DWC_PHY_TYPE_PARAM_ULPI;
  76525. + }
  76526. + }
  76527. + retval = -DWC_E_INVALID;
  76528. + }
  76529. +#endif
  76530. + core_if->core_params->phy_type = val;
  76531. + return retval;
  76532. +}
  76533. +
  76534. +int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if)
  76535. +{
  76536. + return core_if->core_params->phy_type;
  76537. +}
  76538. +
  76539. +int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val)
  76540. +{
  76541. + int retval = 0;
  76542. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76543. + DWC_WARN("Wrong value for speed parameter\n");
  76544. + DWC_WARN("max_speed parameter must be 0 or 1\n");
  76545. + return -DWC_E_INVALID;
  76546. + }
  76547. + if ((val == 0)
  76548. + && dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS) {
  76549. + if (dwc_otg_param_initialized(core_if->core_params->speed)) {
  76550. + DWC_ERROR
  76551. + ("%d invalid for speed paremter. Check HW configuration.\n",
  76552. + val);
  76553. + }
  76554. + val =
  76555. + (dwc_otg_get_param_phy_type(core_if) ==
  76556. + DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
  76557. + retval = -DWC_E_INVALID;
  76558. + }
  76559. + core_if->core_params->speed = val;
  76560. + return retval;
  76561. +}
  76562. +
  76563. +int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if)
  76564. +{
  76565. + return core_if->core_params->speed;
  76566. +}
  76567. +
  76568. +int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if,
  76569. + int32_t val)
  76570. +{
  76571. + int retval = 0;
  76572. +
  76573. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76574. + DWC_WARN
  76575. + ("Wrong value for host_ls_low_power_phy_clk parameter\n");
  76576. + DWC_WARN("host_ls_low_power_phy_clk must be 0 or 1\n");
  76577. + return -DWC_E_INVALID;
  76578. + }
  76579. +
  76580. + if ((val == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ)
  76581. + && (dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS)) {
  76582. + if (dwc_otg_param_initialized
  76583. + (core_if->core_params->host_ls_low_power_phy_clk)) {
  76584. + DWC_ERROR
  76585. + ("%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
  76586. + val);
  76587. + }
  76588. + val =
  76589. + (dwc_otg_get_param_phy_type(core_if) ==
  76590. + DWC_PHY_TYPE_PARAM_FS) ?
  76591. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ :
  76592. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
  76593. + retval = -DWC_E_INVALID;
  76594. + }
  76595. +
  76596. + core_if->core_params->host_ls_low_power_phy_clk = val;
  76597. + return retval;
  76598. +}
  76599. +
  76600. +int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if)
  76601. +{
  76602. + return core_if->core_params->host_ls_low_power_phy_clk;
  76603. +}
  76604. +
  76605. +int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if, int32_t val)
  76606. +{
  76607. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76608. + DWC_WARN("Wrong value for phy_ulpi_ddr\n");
  76609. + DWC_WARN("phy_upli_ddr must be 0 or 1\n");
  76610. + return -DWC_E_INVALID;
  76611. + }
  76612. +
  76613. + core_if->core_params->phy_ulpi_ddr = val;
  76614. + return 0;
  76615. +}
  76616. +
  76617. +int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if)
  76618. +{
  76619. + return core_if->core_params->phy_ulpi_ddr;
  76620. +}
  76621. +
  76622. +int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  76623. + int32_t val)
  76624. +{
  76625. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76626. + DWC_WARN("Wrong valaue for phy_ulpi_ext_vbus\n");
  76627. + DWC_WARN("phy_ulpi_ext_vbus must be 0 or 1\n");
  76628. + return -DWC_E_INVALID;
  76629. + }
  76630. +
  76631. + core_if->core_params->phy_ulpi_ext_vbus = val;
  76632. + return 0;
  76633. +}
  76634. +
  76635. +int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if)
  76636. +{
  76637. + return core_if->core_params->phy_ulpi_ext_vbus;
  76638. +}
  76639. +
  76640. +int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if, int32_t val)
  76641. +{
  76642. + if (DWC_OTG_PARAM_TEST(val, 8, 8) && DWC_OTG_PARAM_TEST(val, 16, 16)) {
  76643. + DWC_WARN("Wrong valaue for phy_utmi_width\n");
  76644. + DWC_WARN("phy_utmi_width must be 8 or 16\n");
  76645. + return -DWC_E_INVALID;
  76646. + }
  76647. +
  76648. + core_if->core_params->phy_utmi_width = val;
  76649. + return 0;
  76650. +}
  76651. +
  76652. +int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if)
  76653. +{
  76654. + return core_if->core_params->phy_utmi_width;
  76655. +}
  76656. +
  76657. +int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if, int32_t val)
  76658. +{
  76659. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76660. + DWC_WARN("Wrong valaue for ulpi_fs_ls\n");
  76661. + DWC_WARN("ulpi_fs_ls must be 0 or 1\n");
  76662. + return -DWC_E_INVALID;
  76663. + }
  76664. +
  76665. + core_if->core_params->ulpi_fs_ls = val;
  76666. + return 0;
  76667. +}
  76668. +
  76669. +int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if)
  76670. +{
  76671. + return core_if->core_params->ulpi_fs_ls;
  76672. +}
  76673. +
  76674. +int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val)
  76675. +{
  76676. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76677. + DWC_WARN("Wrong valaue for ts_dline\n");
  76678. + DWC_WARN("ts_dline must be 0 or 1\n");
  76679. + return -DWC_E_INVALID;
  76680. + }
  76681. +
  76682. + core_if->core_params->ts_dline = val;
  76683. + return 0;
  76684. +}
  76685. +
  76686. +int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if)
  76687. +{
  76688. + return core_if->core_params->ts_dline;
  76689. +}
  76690. +
  76691. +int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if, int32_t val)
  76692. +{
  76693. + int retval = 0;
  76694. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76695. + DWC_WARN("Wrong valaue for i2c_enable\n");
  76696. + DWC_WARN("i2c_enable must be 0 or 1\n");
  76697. + return -DWC_E_INVALID;
  76698. + }
  76699. +#ifndef NO_FS_PHY_HW_CHECK
  76700. + if (val == 1 && core_if->hwcfg3.b.i2c == 0) {
  76701. + if (dwc_otg_param_initialized(core_if->core_params->i2c_enable)) {
  76702. + DWC_ERROR
  76703. + ("%d invalid for i2c_enable. Check HW configuration.\n",
  76704. + val);
  76705. + }
  76706. + val = 0;
  76707. + retval = -DWC_E_INVALID;
  76708. + }
  76709. +#endif
  76710. +
  76711. + core_if->core_params->i2c_enable = val;
  76712. + return retval;
  76713. +}
  76714. +
  76715. +int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if)
  76716. +{
  76717. + return core_if->core_params->i2c_enable;
  76718. +}
  76719. +
  76720. +int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  76721. + int32_t val, int fifo_num)
  76722. +{
  76723. + int retval = 0;
  76724. +
  76725. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  76726. + DWC_WARN("Wrong value for dev_perio_tx_fifo_size\n");
  76727. + DWC_WARN("dev_perio_tx_fifo_size must be 4-768\n");
  76728. + return -DWC_E_INVALID;
  76729. + }
  76730. +
  76731. + if (val >
  76732. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  76733. + if (dwc_otg_param_initialized
  76734. + (core_if->core_params->dev_perio_tx_fifo_size[fifo_num])) {
  76735. + DWC_ERROR
  76736. + ("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n",
  76737. + val, fifo_num);
  76738. + }
  76739. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  76740. + retval = -DWC_E_INVALID;
  76741. + }
  76742. +
  76743. + core_if->core_params->dev_perio_tx_fifo_size[fifo_num] = val;
  76744. + return retval;
  76745. +}
  76746. +
  76747. +int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  76748. + int fifo_num)
  76749. +{
  76750. + return core_if->core_params->dev_perio_tx_fifo_size[fifo_num];
  76751. +}
  76752. +
  76753. +int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  76754. + int32_t val)
  76755. +{
  76756. + int retval = 0;
  76757. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76758. + DWC_WARN("Wrong valaue for en_multiple_tx_fifo,\n");
  76759. + DWC_WARN("en_multiple_tx_fifo must be 0 or 1\n");
  76760. + return -DWC_E_INVALID;
  76761. + }
  76762. +
  76763. + if (val == 1 && core_if->hwcfg4.b.ded_fifo_en == 0) {
  76764. + if (dwc_otg_param_initialized
  76765. + (core_if->core_params->en_multiple_tx_fifo)) {
  76766. + DWC_ERROR
  76767. + ("%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
  76768. + val);
  76769. + }
  76770. + val = 0;
  76771. + retval = -DWC_E_INVALID;
  76772. + }
  76773. +
  76774. + core_if->core_params->en_multiple_tx_fifo = val;
  76775. + return retval;
  76776. +}
  76777. +
  76778. +int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if)
  76779. +{
  76780. + return core_if->core_params->en_multiple_tx_fifo;
  76781. +}
  76782. +
  76783. +int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val,
  76784. + int fifo_num)
  76785. +{
  76786. + int retval = 0;
  76787. +
  76788. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  76789. + DWC_WARN("Wrong value for dev_tx_fifo_size\n");
  76790. + DWC_WARN("dev_tx_fifo_size must be 4-768\n");
  76791. + return -DWC_E_INVALID;
  76792. + }
  76793. +
  76794. + if (val >
  76795. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  76796. + if (dwc_otg_param_initialized
  76797. + (core_if->core_params->dev_tx_fifo_size[fifo_num])) {
  76798. + DWC_ERROR
  76799. + ("`%d' invalid for parameter `dev_tx_fifo_size_%d'. Check HW configuration.\n",
  76800. + val, fifo_num);
  76801. + }
  76802. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  76803. + retval = -DWC_E_INVALID;
  76804. + }
  76805. +
  76806. + core_if->core_params->dev_tx_fifo_size[fifo_num] = val;
  76807. + return retval;
  76808. +}
  76809. +
  76810. +int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  76811. + int fifo_num)
  76812. +{
  76813. + return core_if->core_params->dev_tx_fifo_size[fifo_num];
  76814. +}
  76815. +
  76816. +int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  76817. +{
  76818. + int retval = 0;
  76819. +
  76820. + if (DWC_OTG_PARAM_TEST(val, 0, 7)) {
  76821. + DWC_WARN("Wrong value for thr_ctl\n");
  76822. + DWC_WARN("thr_ctl must be 0-7\n");
  76823. + return -DWC_E_INVALID;
  76824. + }
  76825. +
  76826. + if ((val != 0) &&
  76827. + (!dwc_otg_get_param_dma_enable(core_if) ||
  76828. + !core_if->hwcfg4.b.ded_fifo_en)) {
  76829. + if (dwc_otg_param_initialized(core_if->core_params->thr_ctl)) {
  76830. + DWC_ERROR
  76831. + ("%d invalid for parameter thr_ctl. Check HW configuration.\n",
  76832. + val);
  76833. + }
  76834. + val = 0;
  76835. + retval = -DWC_E_INVALID;
  76836. + }
  76837. +
  76838. + core_if->core_params->thr_ctl = val;
  76839. + return retval;
  76840. +}
  76841. +
  76842. +int32_t dwc_otg_get_param_thr_ctl(dwc_otg_core_if_t * core_if)
  76843. +{
  76844. + return core_if->core_params->thr_ctl;
  76845. +}
  76846. +
  76847. +int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if, int32_t val)
  76848. +{
  76849. + int retval = 0;
  76850. +
  76851. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76852. + DWC_WARN("Wrong value for lpm_enable\n");
  76853. + DWC_WARN("lpm_enable must be 0 or 1\n");
  76854. + return -DWC_E_INVALID;
  76855. + }
  76856. +
  76857. + if (val && !core_if->hwcfg3.b.otg_lpm_en) {
  76858. + if (dwc_otg_param_initialized(core_if->core_params->lpm_enable)) {
  76859. + DWC_ERROR
  76860. + ("%d invalid for parameter lpm_enable. Check HW configuration.\n",
  76861. + val);
  76862. + }
  76863. + val = 0;
  76864. + retval = -DWC_E_INVALID;
  76865. + }
  76866. +
  76867. + core_if->core_params->lpm_enable = val;
  76868. + return retval;
  76869. +}
  76870. +
  76871. +int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if)
  76872. +{
  76873. + return core_if->core_params->lpm_enable;
  76874. +}
  76875. +
  76876. +int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  76877. +{
  76878. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  76879. + DWC_WARN("Wrong valaue for tx_thr_length\n");
  76880. + DWC_WARN("tx_thr_length must be 8 - 128\n");
  76881. + return -DWC_E_INVALID;
  76882. + }
  76883. +
  76884. + core_if->core_params->tx_thr_length = val;
  76885. + return 0;
  76886. +}
  76887. +
  76888. +int32_t dwc_otg_get_param_tx_thr_length(dwc_otg_core_if_t * core_if)
  76889. +{
  76890. + return core_if->core_params->tx_thr_length;
  76891. +}
  76892. +
  76893. +int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  76894. +{
  76895. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  76896. + DWC_WARN("Wrong valaue for rx_thr_length\n");
  76897. + DWC_WARN("rx_thr_length must be 8 - 128\n");
  76898. + return -DWC_E_INVALID;
  76899. + }
  76900. +
  76901. + core_if->core_params->rx_thr_length = val;
  76902. + return 0;
  76903. +}
  76904. +
  76905. +int32_t dwc_otg_get_param_rx_thr_length(dwc_otg_core_if_t * core_if)
  76906. +{
  76907. + return core_if->core_params->rx_thr_length;
  76908. +}
  76909. +
  76910. +int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if, int32_t val)
  76911. +{
  76912. + if (DWC_OTG_PARAM_TEST(val, 1, 1) &&
  76913. + DWC_OTG_PARAM_TEST(val, 4, 4) &&
  76914. + DWC_OTG_PARAM_TEST(val, 8, 8) &&
  76915. + DWC_OTG_PARAM_TEST(val, 16, 16) &&
  76916. + DWC_OTG_PARAM_TEST(val, 32, 32) &&
  76917. + DWC_OTG_PARAM_TEST(val, 64, 64) &&
  76918. + DWC_OTG_PARAM_TEST(val, 128, 128) &&
  76919. + DWC_OTG_PARAM_TEST(val, 256, 256)) {
  76920. + DWC_WARN("`%d' invalid for parameter `dma_burst_size'\n", val);
  76921. + return -DWC_E_INVALID;
  76922. + }
  76923. + core_if->core_params->dma_burst_size = val;
  76924. + return 0;
  76925. +}
  76926. +
  76927. +int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if)
  76928. +{
  76929. + return core_if->core_params->dma_burst_size;
  76930. +}
  76931. +
  76932. +int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if, int32_t val)
  76933. +{
  76934. + int retval = 0;
  76935. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76936. + DWC_WARN("`%d' invalid for parameter `pti_enable'\n", val);
  76937. + return -DWC_E_INVALID;
  76938. + }
  76939. + if (val && (core_if->snpsid < OTG_CORE_REV_2_72a)) {
  76940. + if (dwc_otg_param_initialized(core_if->core_params->pti_enable)) {
  76941. + DWC_ERROR
  76942. + ("%d invalid for parameter pti_enable. Check HW configuration.\n",
  76943. + val);
  76944. + }
  76945. + retval = -DWC_E_INVALID;
  76946. + val = 0;
  76947. + }
  76948. + core_if->core_params->pti_enable = val;
  76949. + return retval;
  76950. +}
  76951. +
  76952. +int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if)
  76953. +{
  76954. + return core_if->core_params->pti_enable;
  76955. +}
  76956. +
  76957. +int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if, int32_t val)
  76958. +{
  76959. + int retval = 0;
  76960. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76961. + DWC_WARN("`%d' invalid for parameter `mpi_enable'\n", val);
  76962. + return -DWC_E_INVALID;
  76963. + }
  76964. + if (val && (core_if->hwcfg2.b.multi_proc_int == 0)) {
  76965. + if (dwc_otg_param_initialized(core_if->core_params->mpi_enable)) {
  76966. + DWC_ERROR
  76967. + ("%d invalid for parameter mpi_enable. Check HW configuration.\n",
  76968. + val);
  76969. + }
  76970. + retval = -DWC_E_INVALID;
  76971. + val = 0;
  76972. + }
  76973. + core_if->core_params->mpi_enable = val;
  76974. + return retval;
  76975. +}
  76976. +
  76977. +int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if)
  76978. +{
  76979. + return core_if->core_params->mpi_enable;
  76980. +}
  76981. +
  76982. +int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if, int32_t val)
  76983. +{
  76984. + int retval = 0;
  76985. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76986. + DWC_WARN("`%d' invalid for parameter `adp_enable'\n", val);
  76987. + return -DWC_E_INVALID;
  76988. + }
  76989. + if (val && (core_if->hwcfg3.b.adp_supp == 0)) {
  76990. + if (dwc_otg_param_initialized
  76991. + (core_if->core_params->adp_supp_enable)) {
  76992. + DWC_ERROR
  76993. + ("%d invalid for parameter adp_enable. Check HW configuration.\n",
  76994. + val);
  76995. + }
  76996. + retval = -DWC_E_INVALID;
  76997. + val = 0;
  76998. + }
  76999. + core_if->core_params->adp_supp_enable = val;
  77000. + /*Set OTG version 2.0 in case of enabling ADP*/
  77001. + if (val)
  77002. + dwc_otg_set_param_otg_ver(core_if, 1);
  77003. +
  77004. + return retval;
  77005. +}
  77006. +
  77007. +int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if)
  77008. +{
  77009. + return core_if->core_params->adp_supp_enable;
  77010. +}
  77011. +
  77012. +int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if, int32_t val)
  77013. +{
  77014. + int retval = 0;
  77015. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77016. + DWC_WARN("`%d' invalid for parameter `ic_usb_cap'\n", val);
  77017. + DWC_WARN("ic_usb_cap must be 0 or 1\n");
  77018. + return -DWC_E_INVALID;
  77019. + }
  77020. +
  77021. + if (val && (core_if->hwcfg2.b.otg_enable_ic_usb == 0)) {
  77022. + if (dwc_otg_param_initialized(core_if->core_params->ic_usb_cap)) {
  77023. + DWC_ERROR
  77024. + ("%d invalid for parameter ic_usb_cap. Check HW configuration.\n",
  77025. + val);
  77026. + }
  77027. + retval = -DWC_E_INVALID;
  77028. + val = 0;
  77029. + }
  77030. + core_if->core_params->ic_usb_cap = val;
  77031. + return retval;
  77032. +}
  77033. +
  77034. +int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if)
  77035. +{
  77036. + return core_if->core_params->ic_usb_cap;
  77037. +}
  77038. +
  77039. +int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if, int32_t val)
  77040. +{
  77041. + int retval = 0;
  77042. + int valid = 1;
  77043. +
  77044. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  77045. + DWC_WARN("`%d' invalid for parameter `ahb_thr_ratio'\n", val);
  77046. + DWC_WARN("ahb_thr_ratio must be 0 - 3\n");
  77047. + return -DWC_E_INVALID;
  77048. + }
  77049. +
  77050. + if (val
  77051. + && (core_if->snpsid < OTG_CORE_REV_2_81a
  77052. + || !dwc_otg_get_param_thr_ctl(core_if))) {
  77053. + valid = 0;
  77054. + } else if (val
  77055. + && ((dwc_otg_get_param_tx_thr_length(core_if) / (1 << val)) <
  77056. + 4)) {
  77057. + valid = 0;
  77058. + }
  77059. + if (valid == 0) {
  77060. + if (dwc_otg_param_initialized
  77061. + (core_if->core_params->ahb_thr_ratio)) {
  77062. + DWC_ERROR
  77063. + ("%d invalid for parameter ahb_thr_ratio. Check HW configuration.\n",
  77064. + val);
  77065. + }
  77066. + retval = -DWC_E_INVALID;
  77067. + val = 0;
  77068. + }
  77069. +
  77070. + core_if->core_params->ahb_thr_ratio = val;
  77071. + return retval;
  77072. +}
  77073. +
  77074. +int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if)
  77075. +{
  77076. + return core_if->core_params->ahb_thr_ratio;
  77077. +}
  77078. +
  77079. +int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if, int32_t val)
  77080. +{
  77081. + int retval = 0;
  77082. + int valid = 1;
  77083. + hwcfg4_data_t hwcfg4 = {.d32 = 0 };
  77084. + hwcfg4.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  77085. +
  77086. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  77087. + DWC_WARN("`%d' invalid for parameter `power_down'\n", val);
  77088. + DWC_WARN("power_down must be 0 - 2\n");
  77089. + return -DWC_E_INVALID;
  77090. + }
  77091. +
  77092. + if ((val == 2) && (core_if->snpsid < OTG_CORE_REV_2_91a)) {
  77093. + valid = 0;
  77094. + }
  77095. + if ((val == 3)
  77096. + && ((core_if->snpsid < OTG_CORE_REV_3_00a)
  77097. + || (hwcfg4.b.xhiber == 0))) {
  77098. + valid = 0;
  77099. + }
  77100. + if (valid == 0) {
  77101. + if (dwc_otg_param_initialized(core_if->core_params->power_down)) {
  77102. + DWC_ERROR
  77103. + ("%d invalid for parameter power_down. Check HW configuration.\n",
  77104. + val);
  77105. + }
  77106. + retval = -DWC_E_INVALID;
  77107. + val = 0;
  77108. + }
  77109. + core_if->core_params->power_down = val;
  77110. + return retval;
  77111. +}
  77112. +
  77113. +int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if)
  77114. +{
  77115. + return core_if->core_params->power_down;
  77116. +}
  77117. +
  77118. +int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  77119. +{
  77120. + int retval = 0;
  77121. + int valid = 1;
  77122. +
  77123. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77124. + DWC_WARN("`%d' invalid for parameter `reload_ctl'\n", val);
  77125. + DWC_WARN("reload_ctl must be 0 or 1\n");
  77126. + return -DWC_E_INVALID;
  77127. + }
  77128. +
  77129. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_92a)) {
  77130. + valid = 0;
  77131. + }
  77132. + if (valid == 0) {
  77133. + if (dwc_otg_param_initialized(core_if->core_params->reload_ctl)) {
  77134. + DWC_ERROR("%d invalid for parameter reload_ctl."
  77135. + "Check HW configuration.\n", val);
  77136. + }
  77137. + retval = -DWC_E_INVALID;
  77138. + val = 0;
  77139. + }
  77140. + core_if->core_params->reload_ctl = val;
  77141. + return retval;
  77142. +}
  77143. +
  77144. +int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if)
  77145. +{
  77146. + return core_if->core_params->reload_ctl;
  77147. +}
  77148. +
  77149. +int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if, int32_t val)
  77150. +{
  77151. + int retval = 0;
  77152. + int valid = 1;
  77153. +
  77154. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77155. + DWC_WARN("`%d' invalid for parameter `dev_out_nak'\n", val);
  77156. + DWC_WARN("dev_out_nak must be 0 or 1\n");
  77157. + return -DWC_E_INVALID;
  77158. + }
  77159. +
  77160. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_93a) ||
  77161. + !(core_if->core_params->dma_desc_enable))) {
  77162. + valid = 0;
  77163. + }
  77164. + if (valid == 0) {
  77165. + if (dwc_otg_param_initialized(core_if->core_params->dev_out_nak)) {
  77166. + DWC_ERROR("%d invalid for parameter dev_out_nak."
  77167. + "Check HW configuration.\n", val);
  77168. + }
  77169. + retval = -DWC_E_INVALID;
  77170. + val = 0;
  77171. + }
  77172. + core_if->core_params->dev_out_nak = val;
  77173. + return retval;
  77174. +}
  77175. +
  77176. +int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if)
  77177. +{
  77178. + return core_if->core_params->dev_out_nak;
  77179. +}
  77180. +
  77181. +int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if, int32_t val)
  77182. +{
  77183. + int retval = 0;
  77184. + int valid = 1;
  77185. +
  77186. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77187. + DWC_WARN("`%d' invalid for parameter `cont_on_bna'\n", val);
  77188. + DWC_WARN("cont_on_bna must be 0 or 1\n");
  77189. + return -DWC_E_INVALID;
  77190. + }
  77191. +
  77192. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_94a) ||
  77193. + !(core_if->core_params->dma_desc_enable))) {
  77194. + valid = 0;
  77195. + }
  77196. + if (valid == 0) {
  77197. + if (dwc_otg_param_initialized(core_if->core_params->cont_on_bna)) {
  77198. + DWC_ERROR("%d invalid for parameter cont_on_bna."
  77199. + "Check HW configuration.\n", val);
  77200. + }
  77201. + retval = -DWC_E_INVALID;
  77202. + val = 0;
  77203. + }
  77204. + core_if->core_params->cont_on_bna = val;
  77205. + return retval;
  77206. +}
  77207. +
  77208. +int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if)
  77209. +{
  77210. + return core_if->core_params->cont_on_bna;
  77211. +}
  77212. +
  77213. +int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if, int32_t val)
  77214. +{
  77215. + int retval = 0;
  77216. + int valid = 1;
  77217. +
  77218. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77219. + DWC_WARN("`%d' invalid for parameter `ahb_single'\n", val);
  77220. + DWC_WARN("ahb_single must be 0 or 1\n");
  77221. + return -DWC_E_INVALID;
  77222. + }
  77223. +
  77224. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  77225. + valid = 0;
  77226. + }
  77227. + if (valid == 0) {
  77228. + if (dwc_otg_param_initialized(core_if->core_params->ahb_single)) {
  77229. + DWC_ERROR("%d invalid for parameter ahb_single."
  77230. + "Check HW configuration.\n", val);
  77231. + }
  77232. + retval = -DWC_E_INVALID;
  77233. + val = 0;
  77234. + }
  77235. + core_if->core_params->ahb_single = val;
  77236. + return retval;
  77237. +}
  77238. +
  77239. +int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if)
  77240. +{
  77241. + return core_if->core_params->ahb_single;
  77242. +}
  77243. +
  77244. +int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val)
  77245. +{
  77246. + int retval = 0;
  77247. +
  77248. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77249. + DWC_WARN("`%d' invalid for parameter `otg_ver'\n", val);
  77250. + DWC_WARN
  77251. + ("otg_ver must be 0(for OTG 1.3 support) or 1(for OTG 2.0 support)\n");
  77252. + return -DWC_E_INVALID;
  77253. + }
  77254. +
  77255. + core_if->core_params->otg_ver = val;
  77256. + return retval;
  77257. +}
  77258. +
  77259. +int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if)
  77260. +{
  77261. + return core_if->core_params->otg_ver;
  77262. +}
  77263. +
  77264. +uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if)
  77265. +{
  77266. + gotgctl_data_t otgctl;
  77267. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  77268. + return otgctl.b.hstnegscs;
  77269. +}
  77270. +
  77271. +uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if)
  77272. +{
  77273. + gotgctl_data_t otgctl;
  77274. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  77275. + return otgctl.b.sesreqscs;
  77276. +}
  77277. +
  77278. +void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val)
  77279. +{
  77280. + if(core_if->otg_ver == 0) {
  77281. + gotgctl_data_t otgctl;
  77282. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  77283. + otgctl.b.hnpreq = val;
  77284. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, otgctl.d32);
  77285. + } else {
  77286. + core_if->otg_sts = val;
  77287. + }
  77288. +}
  77289. +
  77290. +uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if)
  77291. +{
  77292. + return core_if->snpsid;
  77293. +}
  77294. +
  77295. +uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if)
  77296. +{
  77297. + gintsts_data_t gintsts;
  77298. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  77299. + return gintsts.b.curmode;
  77300. +}
  77301. +
  77302. +uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if)
  77303. +{
  77304. + gusbcfg_data_t usbcfg;
  77305. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  77306. + return usbcfg.b.hnpcap;
  77307. +}
  77308. +
  77309. +void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  77310. +{
  77311. + gusbcfg_data_t usbcfg;
  77312. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  77313. + usbcfg.b.hnpcap = val;
  77314. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  77315. +}
  77316. +
  77317. +uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if)
  77318. +{
  77319. + gusbcfg_data_t usbcfg;
  77320. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  77321. + return usbcfg.b.srpcap;
  77322. +}
  77323. +
  77324. +void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  77325. +{
  77326. + gusbcfg_data_t usbcfg;
  77327. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  77328. + usbcfg.b.srpcap = val;
  77329. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  77330. +}
  77331. +
  77332. +uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if)
  77333. +{
  77334. + dcfg_data_t dcfg;
  77335. + /* originally: dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg); */
  77336. +
  77337. + dcfg.d32 = -1; //GRAYG
  77338. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)\n", __func__, core_if);
  77339. + if (NULL == core_if)
  77340. + DWC_ERROR("reg request with NULL core_if\n");
  77341. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)\n", __func__,
  77342. + core_if, core_if->dev_if);
  77343. + if (NULL == core_if->dev_if)
  77344. + DWC_ERROR("reg request with NULL dev_if\n");
  77345. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)->"
  77346. + "dev_global_regs(%p)\n", __func__,
  77347. + core_if, core_if->dev_if,
  77348. + core_if->dev_if->dev_global_regs);
  77349. + if (NULL == core_if->dev_if->dev_global_regs)
  77350. + DWC_ERROR("reg request with NULL dev_global_regs\n");
  77351. + else {
  77352. + DWC_DEBUGPL(DBG_CILV, "%s - &core_if(%p)->dev_if(%p)->"
  77353. + "dev_global_regs(%p)->dcfg = %p\n", __func__,
  77354. + core_if, core_if->dev_if,
  77355. + core_if->dev_if->dev_global_regs,
  77356. + &core_if->dev_if->dev_global_regs->dcfg);
  77357. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  77358. + }
  77359. + return dcfg.b.devspd;
  77360. +}
  77361. +
  77362. +void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val)
  77363. +{
  77364. + dcfg_data_t dcfg;
  77365. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  77366. + dcfg.b.devspd = val;
  77367. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  77368. +}
  77369. +
  77370. +uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if)
  77371. +{
  77372. + hprt0_data_t hprt0;
  77373. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  77374. + return hprt0.b.prtconnsts;
  77375. +}
  77376. +
  77377. +uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if)
  77378. +{
  77379. + dsts_data_t dsts;
  77380. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  77381. + return dsts.b.enumspd;
  77382. +}
  77383. +
  77384. +uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if)
  77385. +{
  77386. + hprt0_data_t hprt0;
  77387. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  77388. + return hprt0.b.prtpwr;
  77389. +
  77390. +}
  77391. +
  77392. +uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if)
  77393. +{
  77394. + return core_if->hibernation_suspend;
  77395. +}
  77396. +
  77397. +void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val)
  77398. +{
  77399. + hprt0_data_t hprt0;
  77400. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  77401. + hprt0.b.prtpwr = val;
  77402. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  77403. +}
  77404. +
  77405. +uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if)
  77406. +{
  77407. + hprt0_data_t hprt0;
  77408. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  77409. + return hprt0.b.prtsusp;
  77410. +
  77411. +}
  77412. +
  77413. +void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val)
  77414. +{
  77415. + hprt0_data_t hprt0;
  77416. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  77417. + hprt0.b.prtsusp = val;
  77418. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  77419. +}
  77420. +
  77421. +uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if)
  77422. +{
  77423. + hfir_data_t hfir;
  77424. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  77425. + return hfir.b.frint;
  77426. +
  77427. +}
  77428. +
  77429. +void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val)
  77430. +{
  77431. + hfir_data_t hfir;
  77432. + uint32_t fram_int;
  77433. + fram_int = calc_frame_interval(core_if);
  77434. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  77435. + if (!core_if->core_params->reload_ctl) {
  77436. + DWC_WARN("\nCannot reload HFIR register.HFIR.HFIRRldCtrl bit is"
  77437. + "not set to 1.\nShould load driver with reload_ctl=1"
  77438. + " module parameter\n");
  77439. + return;
  77440. + }
  77441. + switch (fram_int) {
  77442. + case 3750:
  77443. + if ((val < 3350) || (val > 4150)) {
  77444. + DWC_WARN("HFIR interval for HS core and 30 MHz"
  77445. + "clock freq should be from 3350 to 4150\n");
  77446. + return;
  77447. + }
  77448. + break;
  77449. + case 30000:
  77450. + if ((val < 26820) || (val > 33180)) {
  77451. + DWC_WARN("HFIR interval for FS/LS core and 30 MHz"
  77452. + "clock freq should be from 26820 to 33180\n");
  77453. + return;
  77454. + }
  77455. + break;
  77456. + case 6000:
  77457. + if ((val < 5360) || (val > 6640)) {
  77458. + DWC_WARN("HFIR interval for HS core and 48 MHz"
  77459. + "clock freq should be from 5360 to 6640\n");
  77460. + return;
  77461. + }
  77462. + break;
  77463. + case 48000:
  77464. + if ((val < 42912) || (val > 53088)) {
  77465. + DWC_WARN("HFIR interval for FS/LS core and 48 MHz"
  77466. + "clock freq should be from 42912 to 53088\n");
  77467. + return;
  77468. + }
  77469. + break;
  77470. + case 7500:
  77471. + if ((val < 6700) || (val > 8300)) {
  77472. + DWC_WARN("HFIR interval for HS core and 60 MHz"
  77473. + "clock freq should be from 6700 to 8300\n");
  77474. + return;
  77475. + }
  77476. + break;
  77477. + case 60000:
  77478. + if ((val < 53640) || (val > 65536)) {
  77479. + DWC_WARN("HFIR interval for FS/LS core and 60 MHz"
  77480. + "clock freq should be from 53640 to 65536\n");
  77481. + return;
  77482. + }
  77483. + break;
  77484. + default:
  77485. + DWC_WARN("Unknown frame interval\n");
  77486. + return;
  77487. + break;
  77488. +
  77489. + }
  77490. + hfir.b.frint = val;
  77491. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hfir.d32);
  77492. +}
  77493. +
  77494. +uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if)
  77495. +{
  77496. + hcfg_data_t hcfg;
  77497. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  77498. + return hcfg.b.modechtimen;
  77499. +
  77500. +}
  77501. +
  77502. +void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val)
  77503. +{
  77504. + hcfg_data_t hcfg;
  77505. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  77506. + hcfg.b.modechtimen = val;
  77507. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  77508. +}
  77509. +
  77510. +void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val)
  77511. +{
  77512. + hprt0_data_t hprt0;
  77513. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  77514. + hprt0.b.prtres = val;
  77515. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  77516. +}
  77517. +
  77518. +uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if)
  77519. +{
  77520. + dctl_data_t dctl;
  77521. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  77522. + return dctl.b.rmtwkupsig;
  77523. +}
  77524. +
  77525. +uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if)
  77526. +{
  77527. + glpmcfg_data_t lpmcfg;
  77528. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  77529. +
  77530. + DWC_ASSERT(!
  77531. + ((core_if->lx_state == DWC_OTG_L1) ^ lpmcfg.b.prt_sleep_sts),
  77532. + "lx_state = %d, lmpcfg.prt_sleep_sts = %d\n",
  77533. + core_if->lx_state, lpmcfg.b.prt_sleep_sts);
  77534. +
  77535. + return lpmcfg.b.prt_sleep_sts;
  77536. +}
  77537. +
  77538. +uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if)
  77539. +{
  77540. + glpmcfg_data_t lpmcfg;
  77541. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  77542. + return lpmcfg.b.rem_wkup_en;
  77543. +}
  77544. +
  77545. +uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if)
  77546. +{
  77547. + glpmcfg_data_t lpmcfg;
  77548. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  77549. + return lpmcfg.b.appl_resp;
  77550. +}
  77551. +
  77552. +void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val)
  77553. +{
  77554. + glpmcfg_data_t lpmcfg;
  77555. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  77556. + lpmcfg.b.appl_resp = val;
  77557. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  77558. +}
  77559. +
  77560. +uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if)
  77561. +{
  77562. + glpmcfg_data_t lpmcfg;
  77563. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  77564. + return lpmcfg.b.hsic_connect;
  77565. +}
  77566. +
  77567. +void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val)
  77568. +{
  77569. + glpmcfg_data_t lpmcfg;
  77570. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  77571. + lpmcfg.b.hsic_connect = val;
  77572. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  77573. +}
  77574. +
  77575. +uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if)
  77576. +{
  77577. + glpmcfg_data_t lpmcfg;
  77578. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  77579. + return lpmcfg.b.inv_sel_hsic;
  77580. +
  77581. +}
  77582. +
  77583. +void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val)
  77584. +{
  77585. + glpmcfg_data_t lpmcfg;
  77586. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  77587. + lpmcfg.b.inv_sel_hsic = val;
  77588. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  77589. +}
  77590. +
  77591. +uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if)
  77592. +{
  77593. + return DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  77594. +}
  77595. +
  77596. +void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val)
  77597. +{
  77598. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, val);
  77599. +}
  77600. +
  77601. +uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if)
  77602. +{
  77603. + return DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  77604. +}
  77605. +
  77606. +void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val)
  77607. +{
  77608. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, val);
  77609. +}
  77610. +
  77611. +uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if)
  77612. +{
  77613. + return DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  77614. +}
  77615. +
  77616. +void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  77617. +{
  77618. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, val);
  77619. +}
  77620. +
  77621. +uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if)
  77622. +{
  77623. + return DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  77624. +}
  77625. +
  77626. +void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  77627. +{
  77628. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz, val);
  77629. +}
  77630. +
  77631. +uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if)
  77632. +{
  77633. + return DWC_READ_REG32(&core_if->core_global_regs->gpvndctl);
  77634. +}
  77635. +
  77636. +void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val)
  77637. +{
  77638. + DWC_WRITE_REG32(&core_if->core_global_regs->gpvndctl, val);
  77639. +}
  77640. +
  77641. +uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if)
  77642. +{
  77643. + return DWC_READ_REG32(&core_if->core_global_regs->ggpio);
  77644. +}
  77645. +
  77646. +void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val)
  77647. +{
  77648. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, val);
  77649. +}
  77650. +
  77651. +uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if)
  77652. +{
  77653. + return DWC_READ_REG32(core_if->host_if->hprt0);
  77654. +
  77655. +}
  77656. +
  77657. +void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val)
  77658. +{
  77659. + DWC_WRITE_REG32(core_if->host_if->hprt0, val);
  77660. +}
  77661. +
  77662. +uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if)
  77663. +{
  77664. + return DWC_READ_REG32(&core_if->core_global_regs->guid);
  77665. +}
  77666. +
  77667. +void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val)
  77668. +{
  77669. + DWC_WRITE_REG32(&core_if->core_global_regs->guid, val);
  77670. +}
  77671. +
  77672. +uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if)
  77673. +{
  77674. + return DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  77675. +}
  77676. +
  77677. +uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if)
  77678. +{
  77679. + return ((core_if->otg_ver == 1) ? (uint16_t)0x0200 : (uint16_t)0x0103);
  77680. +}
  77681. +
  77682. +/**
  77683. + * Start the SRP timer to detect when the SRP does not complete within
  77684. + * 6 seconds.
  77685. + *
  77686. + * @param core_if the pointer to core_if strucure.
  77687. + */
  77688. +void dwc_otg_pcd_start_srp_timer(dwc_otg_core_if_t * core_if)
  77689. +{
  77690. + core_if->srp_timer_started = 1;
  77691. + DWC_TIMER_SCHEDULE(core_if->srp_timer, 6000 /* 6 secs */ );
  77692. +}
  77693. +
  77694. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if)
  77695. +{
  77696. + uint32_t *addr = (uint32_t *) & (core_if->core_global_regs->gotgctl);
  77697. + gotgctl_data_t mem;
  77698. + gotgctl_data_t val;
  77699. +
  77700. + val.d32 = DWC_READ_REG32(addr);
  77701. + if (val.b.sesreq) {
  77702. + DWC_ERROR("Session Request Already active!\n");
  77703. + return;
  77704. + }
  77705. +
  77706. + DWC_INFO("Session Request Initated\n"); //NOTICE
  77707. + mem.d32 = DWC_READ_REG32(addr);
  77708. + mem.b.sesreq = 1;
  77709. + DWC_WRITE_REG32(addr, mem.d32);
  77710. +
  77711. + /* Start the SRP timer */
  77712. + dwc_otg_pcd_start_srp_timer(core_if);
  77713. + return;
  77714. +}
  77715. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_cil.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.h
  77716. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_cil.h 1970-01-01 01:00:00.000000000 +0100
  77717. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.h 2015-02-09 04:40:29.000000000 +0100
  77718. @@ -0,0 +1,1464 @@
  77719. +/* ==========================================================================
  77720. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
  77721. + * $Revision: #123 $
  77722. + * $Date: 2012/08/10 $
  77723. + * $Change: 2047372 $
  77724. + *
  77725. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  77726. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  77727. + * otherwise expressly agreed to in writing between Synopsys and you.
  77728. + *
  77729. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  77730. + * any End User Software License Agreement or Agreement for Licensed Product
  77731. + * with Synopsys or any supplement thereto. You are permitted to use and
  77732. + * redistribute this Software in source and binary forms, with or without
  77733. + * modification, provided that redistributions of source code must retain this
  77734. + * notice. You may not view, use, disclose, copy or distribute this file or
  77735. + * any information contained herein except pursuant to this license grant from
  77736. + * Synopsys. If you do not agree with this notice, including the disclaimer
  77737. + * below, then you are not authorized to use the Software.
  77738. + *
  77739. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  77740. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  77741. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  77742. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  77743. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  77744. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  77745. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  77746. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  77747. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  77748. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  77749. + * DAMAGE.
  77750. + * ========================================================================== */
  77751. +
  77752. +#if !defined(__DWC_CIL_H__)
  77753. +#define __DWC_CIL_H__
  77754. +
  77755. +#include "dwc_list.h"
  77756. +#include "dwc_otg_dbg.h"
  77757. +#include "dwc_otg_regs.h"
  77758. +
  77759. +#include "dwc_otg_core_if.h"
  77760. +#include "dwc_otg_adp.h"
  77761. +
  77762. +/**
  77763. + * @file
  77764. + * This file contains the interface to the Core Interface Layer.
  77765. + */
  77766. +
  77767. +#ifdef DWC_UTE_CFI
  77768. +
  77769. +#define MAX_DMA_DESCS_PER_EP 256
  77770. +
  77771. +/**
  77772. + * Enumeration for the data buffer mode
  77773. + */
  77774. +typedef enum _data_buffer_mode {
  77775. + BM_STANDARD = 0, /* data buffer is in normal mode */
  77776. + BM_SG = 1, /* data buffer uses the scatter/gather mode */
  77777. + BM_CONCAT = 2, /* data buffer uses the concatenation mode */
  77778. + BM_CIRCULAR = 3, /* data buffer uses the circular DMA mode */
  77779. + BM_ALIGN = 4 /* data buffer is in buffer alignment mode */
  77780. +} data_buffer_mode_e;
  77781. +#endif //DWC_UTE_CFI
  77782. +
  77783. +/** Macros defined for DWC OTG HW Release version */
  77784. +
  77785. +#define OTG_CORE_REV_2_60a 0x4F54260A
  77786. +#define OTG_CORE_REV_2_71a 0x4F54271A
  77787. +#define OTG_CORE_REV_2_72a 0x4F54272A
  77788. +#define OTG_CORE_REV_2_80a 0x4F54280A
  77789. +#define OTG_CORE_REV_2_81a 0x4F54281A
  77790. +#define OTG_CORE_REV_2_90a 0x4F54290A
  77791. +#define OTG_CORE_REV_2_91a 0x4F54291A
  77792. +#define OTG_CORE_REV_2_92a 0x4F54292A
  77793. +#define OTG_CORE_REV_2_93a 0x4F54293A
  77794. +#define OTG_CORE_REV_2_94a 0x4F54294A
  77795. +#define OTG_CORE_REV_3_00a 0x4F54300A
  77796. +
  77797. +/**
  77798. + * Information for each ISOC packet.
  77799. + */
  77800. +typedef struct iso_pkt_info {
  77801. + uint32_t offset;
  77802. + uint32_t length;
  77803. + int32_t status;
  77804. +} iso_pkt_info_t;
  77805. +
  77806. +/**
  77807. + * The <code>dwc_ep</code> structure represents the state of a single
  77808. + * endpoint when acting in device mode. It contains the data items
  77809. + * needed for an endpoint to be activated and transfer packets.
  77810. + */
  77811. +typedef struct dwc_ep {
  77812. + /** EP number used for register address lookup */
  77813. + uint8_t num;
  77814. + /** EP direction 0 = OUT */
  77815. + unsigned is_in:1;
  77816. + /** EP active. */
  77817. + unsigned active:1;
  77818. +
  77819. + /**
  77820. + * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
  77821. + * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
  77822. + unsigned tx_fifo_num:4;
  77823. + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
  77824. + unsigned type:2;
  77825. +#define DWC_OTG_EP_TYPE_CONTROL 0
  77826. +#define DWC_OTG_EP_TYPE_ISOC 1
  77827. +#define DWC_OTG_EP_TYPE_BULK 2
  77828. +#define DWC_OTG_EP_TYPE_INTR 3
  77829. +
  77830. + /** DATA start PID for INTR and BULK EP */
  77831. + unsigned data_pid_start:1;
  77832. + /** Frame (even/odd) for ISOC EP */
  77833. + unsigned even_odd_frame:1;
  77834. + /** Max Packet bytes */
  77835. + unsigned maxpacket:11;
  77836. +
  77837. + /** Max Transfer size */
  77838. + uint32_t maxxfer;
  77839. +
  77840. + /** @name Transfer state */
  77841. + /** @{ */
  77842. +
  77843. + /**
  77844. + * Pointer to the beginning of the transfer buffer -- do not modify
  77845. + * during transfer.
  77846. + */
  77847. +
  77848. + dwc_dma_t dma_addr;
  77849. +
  77850. + dwc_dma_t dma_desc_addr;
  77851. + dwc_otg_dev_dma_desc_t *desc_addr;
  77852. +
  77853. + uint8_t *start_xfer_buff;
  77854. + /** pointer to the transfer buffer */
  77855. + uint8_t *xfer_buff;
  77856. + /** Number of bytes to transfer */
  77857. + unsigned xfer_len:19;
  77858. + /** Number of bytes transferred. */
  77859. + unsigned xfer_count:19;
  77860. + /** Sent ZLP */
  77861. + unsigned sent_zlp:1;
  77862. + /** Total len for control transfer */
  77863. + unsigned total_len:19;
  77864. +
  77865. + /** stall clear flag */
  77866. + unsigned stall_clear_flag:1;
  77867. +
  77868. + /** SETUP pkt cnt rollover flag for EP0 out*/
  77869. + unsigned stp_rollover;
  77870. +
  77871. +#ifdef DWC_UTE_CFI
  77872. + /* The buffer mode */
  77873. + data_buffer_mode_e buff_mode;
  77874. +
  77875. + /* The chain of DMA descriptors.
  77876. + * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
  77877. + */
  77878. + dwc_otg_dma_desc_t *descs;
  77879. +
  77880. + /* The DMA address of the descriptors chain start */
  77881. + dma_addr_t descs_dma_addr;
  77882. + /** This variable stores the length of the last enqueued request */
  77883. + uint32_t cfi_req_len;
  77884. +#endif //DWC_UTE_CFI
  77885. +
  77886. +/** Max DMA Descriptor count for any EP */
  77887. +#define MAX_DMA_DESC_CNT 256
  77888. + /** Allocated DMA Desc count */
  77889. + uint32_t desc_cnt;
  77890. +
  77891. + /** bInterval */
  77892. + uint32_t bInterval;
  77893. + /** Next frame num to setup next ISOC transfer */
  77894. + uint32_t frame_num;
  77895. + /** Indicates SOF number overrun in DSTS */
  77896. + uint8_t frm_overrun;
  77897. +
  77898. +#ifdef DWC_UTE_PER_IO
  77899. + /** Next frame num for which will be setup DMA Desc */
  77900. + uint32_t xiso_frame_num;
  77901. + /** bInterval */
  77902. + uint32_t xiso_bInterval;
  77903. + /** Count of currently active transfers - shall be either 0 or 1 */
  77904. + int xiso_active_xfers;
  77905. + int xiso_queued_xfers;
  77906. +#endif
  77907. +#ifdef DWC_EN_ISOC
  77908. + /**
  77909. + * Variables specific for ISOC EPs
  77910. + *
  77911. + */
  77912. + /** DMA addresses of ISOC buffers */
  77913. + dwc_dma_t dma_addr0;
  77914. + dwc_dma_t dma_addr1;
  77915. +
  77916. + dwc_dma_t iso_dma_desc_addr;
  77917. + dwc_otg_dev_dma_desc_t *iso_desc_addr;
  77918. +
  77919. + /** pointer to the transfer buffers */
  77920. + uint8_t *xfer_buff0;
  77921. + uint8_t *xfer_buff1;
  77922. +
  77923. + /** number of ISOC Buffer is processing */
  77924. + uint32_t proc_buf_num;
  77925. + /** Interval of ISOC Buffer processing */
  77926. + uint32_t buf_proc_intrvl;
  77927. + /** Data size for regular frame */
  77928. + uint32_t data_per_frame;
  77929. +
  77930. + /* todo - pattern data support is to be implemented in the future */
  77931. + /** Data size for pattern frame */
  77932. + uint32_t data_pattern_frame;
  77933. + /** Frame number of pattern data */
  77934. + uint32_t sync_frame;
  77935. +
  77936. + /** bInterval */
  77937. + uint32_t bInterval;
  77938. + /** ISO Packet number per frame */
  77939. + uint32_t pkt_per_frm;
  77940. + /** Next frame num for which will be setup DMA Desc */
  77941. + uint32_t next_frame;
  77942. + /** Number of packets per buffer processing */
  77943. + uint32_t pkt_cnt;
  77944. + /** Info for all isoc packets */
  77945. + iso_pkt_info_t *pkt_info;
  77946. + /** current pkt number */
  77947. + uint32_t cur_pkt;
  77948. + /** current pkt number */
  77949. + uint8_t *cur_pkt_addr;
  77950. + /** current pkt number */
  77951. + uint32_t cur_pkt_dma_addr;
  77952. +#endif /* DWC_EN_ISOC */
  77953. +
  77954. +/** @} */
  77955. +} dwc_ep_t;
  77956. +
  77957. +/*
  77958. + * Reasons for halting a host channel.
  77959. + */
  77960. +typedef enum dwc_otg_halt_status {
  77961. + DWC_OTG_HC_XFER_NO_HALT_STATUS,
  77962. + DWC_OTG_HC_XFER_COMPLETE,
  77963. + DWC_OTG_HC_XFER_URB_COMPLETE,
  77964. + DWC_OTG_HC_XFER_ACK,
  77965. + DWC_OTG_HC_XFER_NAK,
  77966. + DWC_OTG_HC_XFER_NYET,
  77967. + DWC_OTG_HC_XFER_STALL,
  77968. + DWC_OTG_HC_XFER_XACT_ERR,
  77969. + DWC_OTG_HC_XFER_FRAME_OVERRUN,
  77970. + DWC_OTG_HC_XFER_BABBLE_ERR,
  77971. + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
  77972. + DWC_OTG_HC_XFER_AHB_ERR,
  77973. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
  77974. + DWC_OTG_HC_XFER_URB_DEQUEUE
  77975. +} dwc_otg_halt_status_e;
  77976. +
  77977. +/**
  77978. + * Host channel descriptor. This structure represents the state of a single
  77979. + * host channel when acting in host mode. It contains the data items needed to
  77980. + * transfer packets to an endpoint via a host channel.
  77981. + */
  77982. +typedef struct dwc_hc {
  77983. + /** Host channel number used for register address lookup */
  77984. + uint8_t hc_num;
  77985. +
  77986. + /** Device to access */
  77987. + unsigned dev_addr:7;
  77988. +
  77989. + /** EP to access */
  77990. + unsigned ep_num:4;
  77991. +
  77992. + /** EP direction. 0: OUT, 1: IN */
  77993. + unsigned ep_is_in:1;
  77994. +
  77995. + /**
  77996. + * EP speed.
  77997. + * One of the following values:
  77998. + * - DWC_OTG_EP_SPEED_LOW
  77999. + * - DWC_OTG_EP_SPEED_FULL
  78000. + * - DWC_OTG_EP_SPEED_HIGH
  78001. + */
  78002. + unsigned speed:2;
  78003. +#define DWC_OTG_EP_SPEED_LOW 0
  78004. +#define DWC_OTG_EP_SPEED_FULL 1
  78005. +#define DWC_OTG_EP_SPEED_HIGH 2
  78006. +
  78007. + /**
  78008. + * Endpoint type.
  78009. + * One of the following values:
  78010. + * - DWC_OTG_EP_TYPE_CONTROL: 0
  78011. + * - DWC_OTG_EP_TYPE_ISOC: 1
  78012. + * - DWC_OTG_EP_TYPE_BULK: 2
  78013. + * - DWC_OTG_EP_TYPE_INTR: 3
  78014. + */
  78015. + unsigned ep_type:2;
  78016. +
  78017. + /** Max packet size in bytes */
  78018. + unsigned max_packet:11;
  78019. +
  78020. + /**
  78021. + * PID for initial transaction.
  78022. + * 0: DATA0,<br>
  78023. + * 1: DATA2,<br>
  78024. + * 2: DATA1,<br>
  78025. + * 3: MDATA (non-Control EP),
  78026. + * SETUP (Control EP)
  78027. + */
  78028. + unsigned data_pid_start:2;
  78029. +#define DWC_OTG_HC_PID_DATA0 0
  78030. +#define DWC_OTG_HC_PID_DATA2 1
  78031. +#define DWC_OTG_HC_PID_DATA1 2
  78032. +#define DWC_OTG_HC_PID_MDATA 3
  78033. +#define DWC_OTG_HC_PID_SETUP 3
  78034. +
  78035. + /** Number of periodic transactions per (micro)frame */
  78036. + unsigned multi_count:2;
  78037. +
  78038. + /** @name Transfer State */
  78039. + /** @{ */
  78040. +
  78041. + /** Pointer to the current transfer buffer position. */
  78042. + uint8_t *xfer_buff;
  78043. + /**
  78044. + * In Buffer DMA mode this buffer will be used
  78045. + * if xfer_buff is not DWORD aligned.
  78046. + */
  78047. + dwc_dma_t align_buff;
  78048. + /** Total number of bytes to transfer. */
  78049. + uint32_t xfer_len;
  78050. + /** Number of bytes transferred so far. */
  78051. + uint32_t xfer_count;
  78052. + /** Packet count at start of transfer.*/
  78053. + uint16_t start_pkt_count;
  78054. +
  78055. + /**
  78056. + * Flag to indicate whether the transfer has been started. Set to 1 if
  78057. + * it has been started, 0 otherwise.
  78058. + */
  78059. + uint8_t xfer_started;
  78060. +
  78061. + /**
  78062. + * Set to 1 to indicate that a PING request should be issued on this
  78063. + * channel. If 0, process normally.
  78064. + */
  78065. + uint8_t do_ping;
  78066. +
  78067. + /**
  78068. + * Set to 1 to indicate that the error count for this transaction is
  78069. + * non-zero. Set to 0 if the error count is 0.
  78070. + */
  78071. + uint8_t error_state;
  78072. +
  78073. + /**
  78074. + * Set to 1 to indicate that this channel should be halted the next
  78075. + * time a request is queued for the channel. This is necessary in
  78076. + * slave mode if no request queue space is available when an attempt
  78077. + * is made to halt the channel.
  78078. + */
  78079. + uint8_t halt_on_queue;
  78080. +
  78081. + /**
  78082. + * Set to 1 if the host channel has been halted, but the core is not
  78083. + * finished flushing queued requests. Otherwise 0.
  78084. + */
  78085. + uint8_t halt_pending;
  78086. +
  78087. + /**
  78088. + * Reason for halting the host channel.
  78089. + */
  78090. + dwc_otg_halt_status_e halt_status;
  78091. +
  78092. + /*
  78093. + * Split settings for the host channel
  78094. + */
  78095. + uint8_t do_split; /**< Enable split for the channel */
  78096. + uint8_t complete_split; /**< Enable complete split */
  78097. + uint8_t hub_addr; /**< Address of high speed hub */
  78098. +
  78099. + uint8_t port_addr; /**< Port of the low/full speed device */
  78100. + /** Split transaction position
  78101. + * One of the following values:
  78102. + * - DWC_HCSPLIT_XACTPOS_MID
  78103. + * - DWC_HCSPLIT_XACTPOS_BEGIN
  78104. + * - DWC_HCSPLIT_XACTPOS_END
  78105. + * - DWC_HCSPLIT_XACTPOS_ALL */
  78106. + uint8_t xact_pos;
  78107. +
  78108. + /** Set when the host channel does a short read. */
  78109. + uint8_t short_read;
  78110. +
  78111. + /**
  78112. + * Number of requests issued for this channel since it was assigned to
  78113. + * the current transfer (not counting PINGs).
  78114. + */
  78115. + uint8_t requests;
  78116. +
  78117. + /**
  78118. + * Queue Head for the transfer being processed by this channel.
  78119. + */
  78120. + struct dwc_otg_qh *qh;
  78121. +
  78122. + /** @} */
  78123. +
  78124. + /** Entry in list of host channels. */
  78125. + DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
  78126. +
  78127. + /** @name Descriptor DMA support */
  78128. + /** @{ */
  78129. +
  78130. + /** Number of Transfer Descriptors */
  78131. + uint16_t ntd;
  78132. +
  78133. + /** Descriptor List DMA address */
  78134. + dwc_dma_t desc_list_addr;
  78135. +
  78136. + /** Scheduling micro-frame bitmap. */
  78137. + uint8_t schinfo;
  78138. +
  78139. + /** @} */
  78140. +} dwc_hc_t;
  78141. +
  78142. +/**
  78143. + * The following parameters may be specified when starting the module. These
  78144. + * parameters define how the DWC_otg controller should be configured.
  78145. + */
  78146. +typedef struct dwc_otg_core_params {
  78147. + int32_t opt;
  78148. +
  78149. + /**
  78150. + * Specifies the OTG capabilities. The driver will automatically
  78151. + * detect the value for this parameter if none is specified.
  78152. + * 0 - HNP and SRP capable (default)
  78153. + * 1 - SRP Only capable
  78154. + * 2 - No HNP/SRP capable
  78155. + */
  78156. + int32_t otg_cap;
  78157. +
  78158. + /**
  78159. + * Specifies whether to use slave or DMA mode for accessing the data
  78160. + * FIFOs. The driver will automatically detect the value for this
  78161. + * parameter if none is specified.
  78162. + * 0 - Slave
  78163. + * 1 - DMA (default, if available)
  78164. + */
  78165. + int32_t dma_enable;
  78166. +
  78167. + /**
  78168. + * When DMA mode is enabled specifies whether to use address DMA or DMA
  78169. + * Descriptor mode for accessing the data FIFOs in device mode. The driver
  78170. + * will automatically detect the value for this if none is specified.
  78171. + * 0 - address DMA
  78172. + * 1 - DMA Descriptor(default, if available)
  78173. + */
  78174. + int32_t dma_desc_enable;
  78175. + /** The DMA Burst size (applicable only for External DMA
  78176. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  78177. + */
  78178. + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
  78179. +
  78180. + /**
  78181. + * Specifies the maximum speed of operation in host and device mode.
  78182. + * The actual speed depends on the speed of the attached device and
  78183. + * the value of phy_type. The actual speed depends on the speed of the
  78184. + * attached device.
  78185. + * 0 - High Speed (default)
  78186. + * 1 - Full Speed
  78187. + */
  78188. + int32_t speed;
  78189. + /** Specifies whether low power mode is supported when attached
  78190. + * to a Full Speed or Low Speed device in host mode.
  78191. + * 0 - Don't support low power mode (default)
  78192. + * 1 - Support low power mode
  78193. + */
  78194. + int32_t host_support_fs_ls_low_power;
  78195. +
  78196. + /** Specifies the PHY clock rate in low power mode when connected to a
  78197. + * Low Speed device in host mode. This parameter is applicable only if
  78198. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  78199. + * then defaults to 6 MHZ otherwise 48 MHZ.
  78200. + *
  78201. + * 0 - 48 MHz
  78202. + * 1 - 6 MHz
  78203. + */
  78204. + int32_t host_ls_low_power_phy_clk;
  78205. +
  78206. + /**
  78207. + * 0 - Use cC FIFO size parameters
  78208. + * 1 - Allow dynamic FIFO sizing (default)
  78209. + */
  78210. + int32_t enable_dynamic_fifo;
  78211. +
  78212. + /** Total number of 4-byte words in the data FIFO memory. This
  78213. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  78214. + * Tx FIFOs.
  78215. + * 32 to 32768 (default 8192)
  78216. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  78217. + */
  78218. + int32_t data_fifo_size;
  78219. +
  78220. + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  78221. + * FIFO sizing is enabled.
  78222. + * 16 to 32768 (default 1064)
  78223. + */
  78224. + int32_t dev_rx_fifo_size;
  78225. +
  78226. + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  78227. + * when dynamic FIFO sizing is enabled.
  78228. + * 16 to 32768 (default 1024)
  78229. + */
  78230. + int32_t dev_nperio_tx_fifo_size;
  78231. +
  78232. + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
  78233. + * mode when dynamic FIFO sizing is enabled.
  78234. + * 4 to 768 (default 256)
  78235. + */
  78236. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  78237. +
  78238. + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  78239. + * FIFO sizing is enabled.
  78240. + * 16 to 32768 (default 1024)
  78241. + */
  78242. + int32_t host_rx_fifo_size;
  78243. +
  78244. + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  78245. + * when Dynamic FIFO sizing is enabled in the core.
  78246. + * 16 to 32768 (default 1024)
  78247. + */
  78248. + int32_t host_nperio_tx_fifo_size;
  78249. +
  78250. + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  78251. + * FIFO sizing is enabled.
  78252. + * 16 to 32768 (default 1024)
  78253. + */
  78254. + int32_t host_perio_tx_fifo_size;
  78255. +
  78256. + /** The maximum transfer size supported in bytes.
  78257. + * 2047 to 65,535 (default 65,535)
  78258. + */
  78259. + int32_t max_transfer_size;
  78260. +
  78261. + /** The maximum number of packets in a transfer.
  78262. + * 15 to 511 (default 511)
  78263. + */
  78264. + int32_t max_packet_count;
  78265. +
  78266. + /** The number of host channel registers to use.
  78267. + * 1 to 16 (default 12)
  78268. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  78269. + */
  78270. + int32_t host_channels;
  78271. +
  78272. + /** The number of endpoints in addition to EP0 available for device
  78273. + * mode operations.
  78274. + * 1 to 15 (default 6 IN and OUT)
  78275. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  78276. + * endpoints in addition to EP0.
  78277. + */
  78278. + int32_t dev_endpoints;
  78279. +
  78280. + /**
  78281. + * Specifies the type of PHY interface to use. By default, the driver
  78282. + * will automatically detect the phy_type.
  78283. + *
  78284. + * 0 - Full Speed PHY
  78285. + * 1 - UTMI+ (default)
  78286. + * 2 - ULPI
  78287. + */
  78288. + int32_t phy_type;
  78289. +
  78290. + /**
  78291. + * Specifies the UTMI+ Data Width. This parameter is
  78292. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  78293. + * PHY_TYPE, this parameter indicates the data width between
  78294. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  78295. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  78296. + * to "8 and 16 bits", meaning that the core has been
  78297. + * configured to work at either data path width.
  78298. + *
  78299. + * 8 or 16 bits (default 16)
  78300. + */
  78301. + int32_t phy_utmi_width;
  78302. +
  78303. + /**
  78304. + * Specifies whether the ULPI operates at double or single
  78305. + * data rate. This parameter is only applicable if PHY_TYPE is
  78306. + * ULPI.
  78307. + *
  78308. + * 0 - single data rate ULPI interface with 8 bit wide data
  78309. + * bus (default)
  78310. + * 1 - double data rate ULPI interface with 4 bit wide data
  78311. + * bus
  78312. + */
  78313. + int32_t phy_ulpi_ddr;
  78314. +
  78315. + /**
  78316. + * Specifies whether to use the internal or external supply to
  78317. + * drive the vbus with a ULPI phy.
  78318. + */
  78319. + int32_t phy_ulpi_ext_vbus;
  78320. +
  78321. + /**
  78322. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  78323. + * parameter is only applicable if PHY_TYPE is FS.
  78324. + * 0 - No (default)
  78325. + * 1 - Yes
  78326. + */
  78327. + int32_t i2c_enable;
  78328. +
  78329. + int32_t ulpi_fs_ls;
  78330. +
  78331. + int32_t ts_dline;
  78332. +
  78333. + /**
  78334. + * Specifies whether dedicated transmit FIFOs are
  78335. + * enabled for non periodic IN endpoints in device mode
  78336. + * 0 - No
  78337. + * 1 - Yes
  78338. + */
  78339. + int32_t en_multiple_tx_fifo;
  78340. +
  78341. + /** Number of 4-byte words in each of the Tx FIFOs in device
  78342. + * mode when dynamic FIFO sizing is enabled.
  78343. + * 4 to 768 (default 256)
  78344. + */
  78345. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  78346. +
  78347. + /** Thresholding enable flag-
  78348. + * bit 0 - enable non-ISO Tx thresholding
  78349. + * bit 1 - enable ISO Tx thresholding
  78350. + * bit 2 - enable Rx thresholding
  78351. + */
  78352. + uint32_t thr_ctl;
  78353. +
  78354. + /** Thresholding length for Tx
  78355. + * FIFOs in 32 bit DWORDs
  78356. + */
  78357. + uint32_t tx_thr_length;
  78358. +
  78359. + /** Thresholding length for Rx
  78360. + * FIFOs in 32 bit DWORDs
  78361. + */
  78362. + uint32_t rx_thr_length;
  78363. +
  78364. + /**
  78365. + * Specifies whether LPM (Link Power Management) support is enabled
  78366. + */
  78367. + int32_t lpm_enable;
  78368. +
  78369. + /** Per Transfer Interrupt
  78370. + * mode enable flag
  78371. + * 1 - Enabled
  78372. + * 0 - Disabled
  78373. + */
  78374. + int32_t pti_enable;
  78375. +
  78376. + /** Multi Processor Interrupt
  78377. + * mode enable flag
  78378. + * 1 - Enabled
  78379. + * 0 - Disabled
  78380. + */
  78381. + int32_t mpi_enable;
  78382. +
  78383. + /** IS_USB Capability
  78384. + * 1 - Enabled
  78385. + * 0 - Disabled
  78386. + */
  78387. + int32_t ic_usb_cap;
  78388. +
  78389. + /** AHB Threshold Ratio
  78390. + * 2'b00 AHB Threshold = MAC Threshold
  78391. + * 2'b01 AHB Threshold = 1/2 MAC Threshold
  78392. + * 2'b10 AHB Threshold = 1/4 MAC Threshold
  78393. + * 2'b11 AHB Threshold = 1/8 MAC Threshold
  78394. + */
  78395. + int32_t ahb_thr_ratio;
  78396. +
  78397. + /** ADP Support
  78398. + * 1 - Enabled
  78399. + * 0 - Disabled
  78400. + */
  78401. + int32_t adp_supp_enable;
  78402. +
  78403. + /** HFIR Reload Control
  78404. + * 0 - The HFIR cannot be reloaded dynamically.
  78405. + * 1 - Allow dynamic reloading of the HFIR register during runtime.
  78406. + */
  78407. + int32_t reload_ctl;
  78408. +
  78409. + /** DCFG: Enable device Out NAK
  78410. + * 0 - The core does not set NAK after Bulk Out transfer complete.
  78411. + * 1 - The core sets NAK after Bulk OUT transfer complete.
  78412. + */
  78413. + int32_t dev_out_nak;
  78414. +
  78415. + /** DCFG: Enable Continue on BNA
  78416. + * After receiving BNA interrupt the core disables the endpoint,when the
  78417. + * endpoint is re-enabled by the application the core starts processing
  78418. + * 0 - from the DOEPDMA descriptor
  78419. + * 1 - from the descriptor which received the BNA.
  78420. + */
  78421. + int32_t cont_on_bna;
  78422. +
  78423. + /** GAHBCFG: AHB Single Support
  78424. + * This bit when programmed supports SINGLE transfers for remainder
  78425. + * data in a transfer for DMA mode of operation.
  78426. + * 0 - in this case the remainder data will be sent using INCR burst size.
  78427. + * 1 - in this case the remainder data will be sent using SINGLE burst size.
  78428. + */
  78429. + int32_t ahb_single;
  78430. +
  78431. + /** Core Power down mode
  78432. + * 0 - No Power Down is enabled
  78433. + * 1 - Reserved
  78434. + * 2 - Complete Power Down (Hibernation)
  78435. + */
  78436. + int32_t power_down;
  78437. +
  78438. + /** OTG revision supported
  78439. + * 0 - OTG 1.3 revision
  78440. + * 1 - OTG 2.0 revision
  78441. + */
  78442. + int32_t otg_ver;
  78443. +
  78444. +} dwc_otg_core_params_t;
  78445. +
  78446. +#ifdef DEBUG
  78447. +struct dwc_otg_core_if;
  78448. +typedef struct hc_xfer_info {
  78449. + struct dwc_otg_core_if *core_if;
  78450. + dwc_hc_t *hc;
  78451. +} hc_xfer_info_t;
  78452. +#endif
  78453. +
  78454. +typedef struct ep_xfer_info {
  78455. + struct dwc_otg_core_if *core_if;
  78456. + dwc_ep_t *ep;
  78457. + uint8_t state;
  78458. +} ep_xfer_info_t;
  78459. +/*
  78460. + * Device States
  78461. + */
  78462. +typedef enum dwc_otg_lx_state {
  78463. + /** On state */
  78464. + DWC_OTG_L0,
  78465. + /** LPM sleep state*/
  78466. + DWC_OTG_L1,
  78467. + /** USB suspend state*/
  78468. + DWC_OTG_L2,
  78469. + /** Off state*/
  78470. + DWC_OTG_L3
  78471. +} dwc_otg_lx_state_e;
  78472. +
  78473. +struct dwc_otg_global_regs_backup {
  78474. + uint32_t gotgctl_local;
  78475. + uint32_t gintmsk_local;
  78476. + uint32_t gahbcfg_local;
  78477. + uint32_t gusbcfg_local;
  78478. + uint32_t grxfsiz_local;
  78479. + uint32_t gnptxfsiz_local;
  78480. +#ifdef CONFIG_USB_DWC_OTG_LPM
  78481. + uint32_t glpmcfg_local;
  78482. +#endif
  78483. + uint32_t gi2cctl_local;
  78484. + uint32_t hptxfsiz_local;
  78485. + uint32_t pcgcctl_local;
  78486. + uint32_t gdfifocfg_local;
  78487. + uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
  78488. + uint32_t gpwrdn_local;
  78489. + uint32_t xhib_pcgcctl;
  78490. + uint32_t xhib_gpwrdn;
  78491. +};
  78492. +
  78493. +struct dwc_otg_host_regs_backup {
  78494. + uint32_t hcfg_local;
  78495. + uint32_t haintmsk_local;
  78496. + uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
  78497. + uint32_t hprt0_local;
  78498. + uint32_t hfir_local;
  78499. +};
  78500. +
  78501. +struct dwc_otg_dev_regs_backup {
  78502. + uint32_t dcfg;
  78503. + uint32_t dctl;
  78504. + uint32_t daintmsk;
  78505. + uint32_t diepmsk;
  78506. + uint32_t doepmsk;
  78507. + uint32_t diepctl[MAX_EPS_CHANNELS];
  78508. + uint32_t dieptsiz[MAX_EPS_CHANNELS];
  78509. + uint32_t diepdma[MAX_EPS_CHANNELS];
  78510. +};
  78511. +/**
  78512. + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
  78513. + * the DWC_otg controller acting in either host or device mode. It
  78514. + * represents the programming view of the controller as a whole.
  78515. + */
  78516. +struct dwc_otg_core_if {
  78517. + /** Parameters that define how the core should be configured.*/
  78518. + dwc_otg_core_params_t *core_params;
  78519. +
  78520. + /** Core Global registers starting at offset 000h. */
  78521. + dwc_otg_core_global_regs_t *core_global_regs;
  78522. +
  78523. + /** Device-specific information */
  78524. + dwc_otg_dev_if_t *dev_if;
  78525. + /** Host-specific information */
  78526. + dwc_otg_host_if_t *host_if;
  78527. +
  78528. + /** Value from SNPSID register */
  78529. + uint32_t snpsid;
  78530. +
  78531. + /*
  78532. + * Set to 1 if the core PHY interface bits in USBCFG have been
  78533. + * initialized.
  78534. + */
  78535. + uint8_t phy_init_done;
  78536. +
  78537. + /*
  78538. + * SRP Success flag, set by srp success interrupt in FS I2C mode
  78539. + */
  78540. + uint8_t srp_success;
  78541. + uint8_t srp_timer_started;
  78542. + /** Timer for SRP. If it expires before SRP is successful
  78543. + * clear the SRP. */
  78544. + dwc_timer_t *srp_timer;
  78545. +
  78546. +#ifdef DWC_DEV_SRPCAP
  78547. + /* This timer is needed to power on the hibernated host core if SRP is not
  78548. + * initiated on connected SRP capable device for limited period of time
  78549. + */
  78550. + uint8_t pwron_timer_started;
  78551. + dwc_timer_t *pwron_timer;
  78552. +#endif
  78553. + /* Common configuration information */
  78554. + /** Power and Clock Gating Control Register */
  78555. + volatile uint32_t *pcgcctl;
  78556. +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
  78557. +
  78558. + /** Push/pop addresses for endpoints or host channels.*/
  78559. + uint32_t *data_fifo[MAX_EPS_CHANNELS];
  78560. +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
  78561. +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
  78562. +
  78563. + /** Total RAM for FIFOs (Bytes) */
  78564. + uint16_t total_fifo_size;
  78565. + /** Size of Rx FIFO (Bytes) */
  78566. + uint16_t rx_fifo_size;
  78567. + /** Size of Non-periodic Tx FIFO (Bytes) */
  78568. + uint16_t nperio_tx_fifo_size;
  78569. +
  78570. + /** 1 if DMA is enabled, 0 otherwise. */
  78571. + uint8_t dma_enable;
  78572. +
  78573. + /** 1 if DMA descriptor is enabled, 0 otherwise. */
  78574. + uint8_t dma_desc_enable;
  78575. +
  78576. + /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
  78577. + uint8_t pti_enh_enable;
  78578. +
  78579. + /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
  78580. + uint8_t multiproc_int_enable;
  78581. +
  78582. + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
  78583. + uint8_t en_multiple_tx_fifo;
  78584. +
  78585. + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
  78586. + * process of being queued */
  78587. + uint8_t queuing_high_bandwidth;
  78588. +
  78589. + /** Hardware Configuration -- stored here for convenience.*/
  78590. + hwcfg1_data_t hwcfg1;
  78591. + hwcfg2_data_t hwcfg2;
  78592. + hwcfg3_data_t hwcfg3;
  78593. + hwcfg4_data_t hwcfg4;
  78594. + fifosize_data_t hptxfsiz;
  78595. +
  78596. + /** Host and Device Configuration -- stored here for convenience.*/
  78597. + hcfg_data_t hcfg;
  78598. + dcfg_data_t dcfg;
  78599. +
  78600. + /** The operational State, during transations
  78601. + * (a_host>>a_peripherial and b_device=>b_host) this may not
  78602. + * match the core but allows the software to determine
  78603. + * transitions.
  78604. + */
  78605. + uint8_t op_state;
  78606. +
  78607. + /**
  78608. + * Set to 1 if the HCD needs to be restarted on a session request
  78609. + * interrupt. This is required if no connector ID status change has
  78610. + * occurred since the HCD was last disconnected.
  78611. + */
  78612. + uint8_t restart_hcd_on_session_req;
  78613. +
  78614. + /** HCD callbacks */
  78615. + /** A-Device is a_host */
  78616. +#define A_HOST (1)
  78617. + /** A-Device is a_suspend */
  78618. +#define A_SUSPEND (2)
  78619. + /** A-Device is a_peripherial */
  78620. +#define A_PERIPHERAL (3)
  78621. + /** B-Device is operating as a Peripheral. */
  78622. +#define B_PERIPHERAL (4)
  78623. + /** B-Device is operating as a Host. */
  78624. +#define B_HOST (5)
  78625. +
  78626. + /** HCD callbacks */
  78627. + struct dwc_otg_cil_callbacks *hcd_cb;
  78628. + /** PCD callbacks */
  78629. + struct dwc_otg_cil_callbacks *pcd_cb;
  78630. +
  78631. + /** Device mode Periodic Tx FIFO Mask */
  78632. + uint32_t p_tx_msk;
  78633. + /** Device mode Periodic Tx FIFO Mask */
  78634. + uint32_t tx_msk;
  78635. +
  78636. + /** Workqueue object used for handling several interrupts */
  78637. + dwc_workq_t *wq_otg;
  78638. +
  78639. + /** Timer object used for handling "Wakeup Detected" Interrupt */
  78640. + dwc_timer_t *wkp_timer;
  78641. + /** This arrays used for debug purposes for DEV OUT NAK enhancement */
  78642. + uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
  78643. + ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
  78644. + dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
  78645. +#ifdef DEBUG
  78646. + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
  78647. +
  78648. + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
  78649. + dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
  78650. +
  78651. + uint32_t hfnum_7_samples;
  78652. + uint64_t hfnum_7_frrem_accum;
  78653. + uint32_t hfnum_0_samples;
  78654. + uint64_t hfnum_0_frrem_accum;
  78655. + uint32_t hfnum_other_samples;
  78656. + uint64_t hfnum_other_frrem_accum;
  78657. +#endif
  78658. +
  78659. +#ifdef DWC_UTE_CFI
  78660. + uint16_t pwron_rxfsiz;
  78661. + uint16_t pwron_gnptxfsiz;
  78662. + uint16_t pwron_txfsiz[15];
  78663. +
  78664. + uint16_t init_rxfsiz;
  78665. + uint16_t init_gnptxfsiz;
  78666. + uint16_t init_txfsiz[15];
  78667. +#endif
  78668. +
  78669. + /** Lx state of device */
  78670. + dwc_otg_lx_state_e lx_state;
  78671. +
  78672. + /** Saved Core Global registers */
  78673. + struct dwc_otg_global_regs_backup *gr_backup;
  78674. + /** Saved Host registers */
  78675. + struct dwc_otg_host_regs_backup *hr_backup;
  78676. + /** Saved Device registers */
  78677. + struct dwc_otg_dev_regs_backup *dr_backup;
  78678. +
  78679. + /** Power Down Enable */
  78680. + uint32_t power_down;
  78681. +
  78682. + /** ADP support Enable */
  78683. + uint32_t adp_enable;
  78684. +
  78685. + /** ADP structure object */
  78686. + dwc_otg_adp_t adp;
  78687. +
  78688. + /** hibernation/suspend flag */
  78689. + int hibernation_suspend;
  78690. +
  78691. + /** Device mode extended hibernation flag */
  78692. + int xhib;
  78693. +
  78694. + /** OTG revision supported */
  78695. + uint32_t otg_ver;
  78696. +
  78697. + /** OTG status flag used for HNP polling */
  78698. + uint8_t otg_sts;
  78699. +
  78700. + /** Pointer to either hcd->lock or pcd->lock */
  78701. + dwc_spinlock_t *lock;
  78702. +
  78703. + /** Start predict NextEP based on Learning Queue if equal 1,
  78704. + * also used as counter of disabled NP IN EP's */
  78705. + uint8_t start_predict;
  78706. +
  78707. + /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
  78708. + * active, 0xff otherwise */
  78709. + uint8_t nextep_seq[MAX_EPS_CHANNELS];
  78710. +
  78711. + /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
  78712. + uint8_t first_in_nextep_seq;
  78713. +
  78714. + /** Frame number while entering to ISR - needed for ISOCs **/
  78715. + uint32_t frame_num;
  78716. +
  78717. +};
  78718. +
  78719. +#ifdef DEBUG
  78720. +/*
  78721. + * This function is called when transfer is timed out.
  78722. + */
  78723. +extern void hc_xfer_timeout(void *ptr);
  78724. +#endif
  78725. +
  78726. +/*
  78727. + * This function is called when transfer is timed out on endpoint.
  78728. + */
  78729. +extern void ep_xfer_timeout(void *ptr);
  78730. +
  78731. +/*
  78732. + * The following functions are functions for works
  78733. + * using during handling some interrupts
  78734. + */
  78735. +extern void w_conn_id_status_change(void *p);
  78736. +
  78737. +extern void w_wakeup_detected(void *p);
  78738. +
  78739. +/** Saves global register values into system memory. */
  78740. +extern int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if);
  78741. +/** Saves device register values into system memory. */
  78742. +extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if);
  78743. +/** Saves host register values into system memory. */
  78744. +extern int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if);
  78745. +/** Restore global register values. */
  78746. +extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t * core_if);
  78747. +/** Restore host register values. */
  78748. +extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset);
  78749. +/** Restore device register values. */
  78750. +extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if,
  78751. + int rem_wakeup);
  78752. +extern int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if);
  78753. +extern int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode,
  78754. + int is_host);
  78755. +
  78756. +extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  78757. + int restore_mode, int reset);
  78758. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  78759. + int rem_wakeup, int reset);
  78760. +
  78761. +/*
  78762. + * The following functions support initialization of the CIL driver component
  78763. + * and the DWC_otg controller.
  78764. + */
  78765. +extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
  78766. +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
  78767. +
  78768. +/** @name Device CIL Functions
  78769. + * The following functions support managing the DWC_otg controller in device
  78770. + * mode.
  78771. + */
  78772. +/**@{*/
  78773. +extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
  78774. +extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
  78775. + uint32_t * _dest);
  78776. +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
  78777. +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  78778. +extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  78779. +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  78780. +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
  78781. + dwc_ep_t * _ep);
  78782. +extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
  78783. + dwc_ep_t * _ep);
  78784. +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
  78785. + dwc_ep_t * _ep);
  78786. +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
  78787. + dwc_ep_t * _ep);
  78788. +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
  78789. + dwc_ep_t * _ep, int _dma);
  78790. +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  78791. +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
  78792. + dwc_ep_t * _ep);
  78793. +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
  78794. +
  78795. +#ifdef DWC_EN_ISOC
  78796. +extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  78797. + dwc_ep_t * ep);
  78798. +extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  78799. + dwc_ep_t * ep);
  78800. +#endif /* DWC_EN_ISOC */
  78801. +/**@}*/
  78802. +
  78803. +/** @name Host CIL Functions
  78804. + * The following functions support managing the DWC_otg controller in host
  78805. + * mode.
  78806. + */
  78807. +/**@{*/
  78808. +extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  78809. +extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
  78810. + dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
  78811. +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  78812. +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
  78813. + dwc_hc_t * _hc);
  78814. +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
  78815. + dwc_hc_t * _hc);
  78816. +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  78817. +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
  78818. + dwc_hc_t * _hc);
  78819. +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
  78820. +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
  78821. +
  78822. +extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if,
  78823. + dwc_hc_t * hc);
  78824. +
  78825. +extern uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if);
  78826. +
  78827. +/* Macro used to clear one channel interrupt */
  78828. +#define clear_hc_int(_hc_regs_, _intr_) \
  78829. +do { \
  78830. + hcint_data_t hcint_clear = {.d32 = 0}; \
  78831. + hcint_clear.b._intr_ = 1; \
  78832. + DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
  78833. +} while (0)
  78834. +
  78835. +/*
  78836. + * Macro used to disable one channel interrupt. Channel interrupts are
  78837. + * disabled when the channel is halted or released by the interrupt handler.
  78838. + * There is no need to handle further interrupts of that type until the
  78839. + * channel is re-assigned. In fact, subsequent handling may cause crashes
  78840. + * because the channel structures are cleaned up when the channel is released.
  78841. + */
  78842. +#define disable_hc_int(_hc_regs_, _intr_) \
  78843. +do { \
  78844. + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
  78845. + hcintmsk.b._intr_ = 1; \
  78846. + DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
  78847. +} while (0)
  78848. +
  78849. +/**
  78850. + * This function Reads HPRT0 in preparation to modify. It keeps the
  78851. + * WC bits 0 so that if they are read as 1, they won't clear when you
  78852. + * write it back
  78853. + */
  78854. +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
  78855. +{
  78856. + hprt0_data_t hprt0;
  78857. + hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
  78858. + hprt0.b.prtena = 0;
  78859. + hprt0.b.prtconndet = 0;
  78860. + hprt0.b.prtenchng = 0;
  78861. + hprt0.b.prtovrcurrchng = 0;
  78862. + return hprt0.d32;
  78863. +}
  78864. +
  78865. +/**@}*/
  78866. +
  78867. +/** @name Common CIL Functions
  78868. + * The following functions support managing the DWC_otg controller in either
  78869. + * device or host mode.
  78870. + */
  78871. +/**@{*/
  78872. +
  78873. +extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  78874. + uint8_t * dest, uint16_t bytes);
  78875. +
  78876. +extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
  78877. +extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
  78878. +extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
  78879. +
  78880. +/**
  78881. + * This function returns the Core Interrupt register.
  78882. + */
  78883. +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
  78884. +{
  78885. + return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
  78886. + DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
  78887. +}
  78888. +
  78889. +/**
  78890. + * This function returns the OTG Interrupt register.
  78891. + */
  78892. +static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
  78893. +{
  78894. + return (DWC_READ_REG32(&core_if->core_global_regs->gotgint));
  78895. +}
  78896. +
  78897. +/**
  78898. + * This function reads the Device All Endpoints Interrupt register and
  78899. + * returns the IN endpoint interrupt bits.
  78900. + */
  78901. +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
  78902. + core_if)
  78903. +{
  78904. +
  78905. + uint32_t v;
  78906. +
  78907. + if (core_if->multiproc_int_enable) {
  78908. + v = DWC_READ_REG32(&core_if->dev_if->
  78909. + dev_global_regs->deachint) &
  78910. + DWC_READ_REG32(&core_if->
  78911. + dev_if->dev_global_regs->deachintmsk);
  78912. + } else {
  78913. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  78914. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  78915. + }
  78916. + return (v & 0xffff);
  78917. +}
  78918. +
  78919. +/**
  78920. + * This function reads the Device All Endpoints Interrupt register and
  78921. + * returns the OUT endpoint interrupt bits.
  78922. + */
  78923. +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
  78924. + core_if)
  78925. +{
  78926. + uint32_t v;
  78927. +
  78928. + if (core_if->multiproc_int_enable) {
  78929. + v = DWC_READ_REG32(&core_if->dev_if->
  78930. + dev_global_regs->deachint) &
  78931. + DWC_READ_REG32(&core_if->
  78932. + dev_if->dev_global_regs->deachintmsk);
  78933. + } else {
  78934. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  78935. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  78936. + }
  78937. +
  78938. + return ((v & 0xffff0000) >> 16);
  78939. +}
  78940. +
  78941. +/**
  78942. + * This function returns the Device IN EP Interrupt register
  78943. + */
  78944. +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
  78945. + dwc_ep_t * ep)
  78946. +{
  78947. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  78948. + uint32_t v, msk, emp;
  78949. +
  78950. + if (core_if->multiproc_int_enable) {
  78951. + msk =
  78952. + DWC_READ_REG32(&dev_if->
  78953. + dev_global_regs->diepeachintmsk[ep->num]);
  78954. + emp =
  78955. + DWC_READ_REG32(&dev_if->
  78956. + dev_global_regs->dtknqr4_fifoemptymsk);
  78957. + msk |= ((emp >> ep->num) & 0x1) << 7;
  78958. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  78959. + } else {
  78960. + msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
  78961. + emp =
  78962. + DWC_READ_REG32(&dev_if->
  78963. + dev_global_regs->dtknqr4_fifoemptymsk);
  78964. + msk |= ((emp >> ep->num) & 0x1) << 7;
  78965. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  78966. + }
  78967. +
  78968. + return v;
  78969. +}
  78970. +
  78971. +/**
  78972. + * This function returns the Device OUT EP Interrupt register
  78973. + */
  78974. +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
  78975. + _core_if, dwc_ep_t * _ep)
  78976. +{
  78977. + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
  78978. + uint32_t v;
  78979. + doepmsk_data_t msk = {.d32 = 0 };
  78980. +
  78981. + if (_core_if->multiproc_int_enable) {
  78982. + msk.d32 =
  78983. + DWC_READ_REG32(&dev_if->
  78984. + dev_global_regs->doepeachintmsk[_ep->num]);
  78985. + if (_core_if->pti_enh_enable) {
  78986. + msk.b.pktdrpsts = 1;
  78987. + }
  78988. + v = DWC_READ_REG32(&dev_if->
  78989. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  78990. + } else {
  78991. + msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
  78992. + if (_core_if->pti_enh_enable) {
  78993. + msk.b.pktdrpsts = 1;
  78994. + }
  78995. + v = DWC_READ_REG32(&dev_if->
  78996. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  78997. + }
  78998. + return v;
  78999. +}
  79000. +
  79001. +/**
  79002. + * This function returns the Host All Channel Interrupt register
  79003. + */
  79004. +static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
  79005. + _core_if)
  79006. +{
  79007. + return (DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint));
  79008. +}
  79009. +
  79010. +static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
  79011. + _core_if, dwc_hc_t * _hc)
  79012. +{
  79013. + return (DWC_READ_REG32
  79014. + (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
  79015. +}
  79016. +
  79017. +/**
  79018. + * This function returns the mode of the operation, host or device.
  79019. + *
  79020. + * @return 0 - Device Mode, 1 - Host Mode
  79021. + */
  79022. +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
  79023. +{
  79024. + return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
  79025. +}
  79026. +
  79027. +/**@}*/
  79028. +
  79029. +/**
  79030. + * DWC_otg CIL callback structure. This structure allows the HCD and
  79031. + * PCD to register functions used for starting and stopping the PCD
  79032. + * and HCD for role change on for a DRD.
  79033. + */
  79034. +typedef struct dwc_otg_cil_callbacks {
  79035. + /** Start function for role change */
  79036. + int (*start) (void *_p);
  79037. + /** Stop Function for role change */
  79038. + int (*stop) (void *_p);
  79039. + /** Disconnect Function for role change */
  79040. + int (*disconnect) (void *_p);
  79041. + /** Resume/Remote wakeup Function */
  79042. + int (*resume_wakeup) (void *_p);
  79043. + /** Suspend function */
  79044. + int (*suspend) (void *_p);
  79045. + /** Session Start (SRP) */
  79046. + int (*session_start) (void *_p);
  79047. +#ifdef CONFIG_USB_DWC_OTG_LPM
  79048. + /** Sleep (switch to L0 state) */
  79049. + int (*sleep) (void *_p);
  79050. +#endif
  79051. + /** Pointer passed to start() and stop() */
  79052. + void *p;
  79053. +} dwc_otg_cil_callbacks_t;
  79054. +
  79055. +extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
  79056. + dwc_otg_cil_callbacks_t * _cb,
  79057. + void *_p);
  79058. +extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
  79059. + dwc_otg_cil_callbacks_t * _cb,
  79060. + void *_p);
  79061. +
  79062. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if);
  79063. +
  79064. +//////////////////////////////////////////////////////////////////////
  79065. +/** Start the HCD. Helper function for using the HCD callbacks.
  79066. + *
  79067. + * @param core_if Programming view of DWC_otg controller.
  79068. + */
  79069. +static inline void cil_hcd_start(dwc_otg_core_if_t * core_if)
  79070. +{
  79071. + if (core_if->hcd_cb && core_if->hcd_cb->start) {
  79072. + core_if->hcd_cb->start(core_if->hcd_cb->p);
  79073. + }
  79074. +}
  79075. +
  79076. +/** Stop the HCD. Helper function for using the HCD callbacks.
  79077. + *
  79078. + * @param core_if Programming view of DWC_otg controller.
  79079. + */
  79080. +static inline void cil_hcd_stop(dwc_otg_core_if_t * core_if)
  79081. +{
  79082. + if (core_if->hcd_cb && core_if->hcd_cb->stop) {
  79083. + core_if->hcd_cb->stop(core_if->hcd_cb->p);
  79084. + }
  79085. +}
  79086. +
  79087. +/** Disconnect the HCD. Helper function for using the HCD callbacks.
  79088. + *
  79089. + * @param core_if Programming view of DWC_otg controller.
  79090. + */
  79091. +static inline void cil_hcd_disconnect(dwc_otg_core_if_t * core_if)
  79092. +{
  79093. + if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
  79094. + core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
  79095. + }
  79096. +}
  79097. +
  79098. +/** Inform the HCD the a New Session has begun. Helper function for
  79099. + * using the HCD callbacks.
  79100. + *
  79101. + * @param core_if Programming view of DWC_otg controller.
  79102. + */
  79103. +static inline void cil_hcd_session_start(dwc_otg_core_if_t * core_if)
  79104. +{
  79105. + if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
  79106. + core_if->hcd_cb->session_start(core_if->hcd_cb->p);
  79107. + }
  79108. +}
  79109. +
  79110. +#ifdef CONFIG_USB_DWC_OTG_LPM
  79111. +/**
  79112. + * Inform the HCD about LPM sleep.
  79113. + * Helper function for using the HCD callbacks.
  79114. + *
  79115. + * @param core_if Programming view of DWC_otg controller.
  79116. + */
  79117. +static inline void cil_hcd_sleep(dwc_otg_core_if_t * core_if)
  79118. +{
  79119. + if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
  79120. + core_if->hcd_cb->sleep(core_if->hcd_cb->p);
  79121. + }
  79122. +}
  79123. +#endif
  79124. +
  79125. +/** Resume the HCD. Helper function for using the HCD callbacks.
  79126. + *
  79127. + * @param core_if Programming view of DWC_otg controller.
  79128. + */
  79129. +static inline void cil_hcd_resume(dwc_otg_core_if_t * core_if)
  79130. +{
  79131. + if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
  79132. + core_if->hcd_cb->resume_wakeup(core_if->hcd_cb->p);
  79133. + }
  79134. +}
  79135. +
  79136. +/** Start the PCD. Helper function for using the PCD callbacks.
  79137. + *
  79138. + * @param core_if Programming view of DWC_otg controller.
  79139. + */
  79140. +static inline void cil_pcd_start(dwc_otg_core_if_t * core_if)
  79141. +{
  79142. + if (core_if->pcd_cb && core_if->pcd_cb->start) {
  79143. + core_if->pcd_cb->start(core_if->pcd_cb->p);
  79144. + }
  79145. +}
  79146. +
  79147. +/** Stop the PCD. Helper function for using the PCD callbacks.
  79148. + *
  79149. + * @param core_if Programming view of DWC_otg controller.
  79150. + */
  79151. +static inline void cil_pcd_stop(dwc_otg_core_if_t * core_if)
  79152. +{
  79153. + if (core_if->pcd_cb && core_if->pcd_cb->stop) {
  79154. + core_if->pcd_cb->stop(core_if->pcd_cb->p);
  79155. + }
  79156. +}
  79157. +
  79158. +/** Suspend the PCD. Helper function for using the PCD callbacks.
  79159. + *
  79160. + * @param core_if Programming view of DWC_otg controller.
  79161. + */
  79162. +static inline void cil_pcd_suspend(dwc_otg_core_if_t * core_if)
  79163. +{
  79164. + if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
  79165. + core_if->pcd_cb->suspend(core_if->pcd_cb->p);
  79166. + }
  79167. +}
  79168. +
  79169. +/** Resume the PCD. Helper function for using the PCD callbacks.
  79170. + *
  79171. + * @param core_if Programming view of DWC_otg controller.
  79172. + */
  79173. +static inline void cil_pcd_resume(dwc_otg_core_if_t * core_if)
  79174. +{
  79175. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  79176. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  79177. + }
  79178. +}
  79179. +
  79180. +//////////////////////////////////////////////////////////////////////
  79181. +
  79182. +#endif
  79183. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
  79184. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 1970-01-01 01:00:00.000000000 +0100
  79185. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 2015-02-09 04:40:29.000000000 +0100
  79186. @@ -0,0 +1,1594 @@
  79187. +/* ==========================================================================
  79188. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
  79189. + * $Revision: #32 $
  79190. + * $Date: 2012/08/10 $
  79191. + * $Change: 2047372 $
  79192. + *
  79193. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  79194. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  79195. + * otherwise expressly agreed to in writing between Synopsys and you.
  79196. + *
  79197. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  79198. + * any End User Software License Agreement or Agreement for Licensed Product
  79199. + * with Synopsys or any supplement thereto. You are permitted to use and
  79200. + * redistribute this Software in source and binary forms, with or without
  79201. + * modification, provided that redistributions of source code must retain this
  79202. + * notice. You may not view, use, disclose, copy or distribute this file or
  79203. + * any information contained herein except pursuant to this license grant from
  79204. + * Synopsys. If you do not agree with this notice, including the disclaimer
  79205. + * below, then you are not authorized to use the Software.
  79206. + *
  79207. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  79208. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  79209. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  79210. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  79211. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  79212. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  79213. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  79214. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  79215. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  79216. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  79217. + * DAMAGE.
  79218. + * ========================================================================== */
  79219. +
  79220. +/** @file
  79221. + *
  79222. + * The Core Interface Layer provides basic services for accessing and
  79223. + * managing the DWC_otg hardware. These services are used by both the
  79224. + * Host Controller Driver and the Peripheral Controller Driver.
  79225. + *
  79226. + * This file contains the Common Interrupt handlers.
  79227. + */
  79228. +#include "dwc_os.h"
  79229. +#include "dwc_otg_regs.h"
  79230. +#include "dwc_otg_cil.h"
  79231. +#include "dwc_otg_driver.h"
  79232. +#include "dwc_otg_pcd.h"
  79233. +#include "dwc_otg_hcd.h"
  79234. +
  79235. +#ifdef DEBUG
  79236. +inline const char *op_state_str(dwc_otg_core_if_t * core_if)
  79237. +{
  79238. + return (core_if->op_state == A_HOST ? "a_host" :
  79239. + (core_if->op_state == A_SUSPEND ? "a_suspend" :
  79240. + (core_if->op_state == A_PERIPHERAL ? "a_peripheral" :
  79241. + (core_if->op_state == B_PERIPHERAL ? "b_peripheral" :
  79242. + (core_if->op_state == B_HOST ? "b_host" : "unknown")))));
  79243. +}
  79244. +#endif
  79245. +
  79246. +/** This function will log a debug message
  79247. + *
  79248. + * @param core_if Programming view of DWC_otg controller.
  79249. + */
  79250. +int32_t dwc_otg_handle_mode_mismatch_intr(dwc_otg_core_if_t * core_if)
  79251. +{
  79252. + gintsts_data_t gintsts;
  79253. + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
  79254. + dwc_otg_mode(core_if) ? "Host" : "Device");
  79255. +
  79256. + /* Clear interrupt */
  79257. + gintsts.d32 = 0;
  79258. + gintsts.b.modemismatch = 1;
  79259. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  79260. + return 1;
  79261. +}
  79262. +
  79263. +/**
  79264. + * This function handles the OTG Interrupts. It reads the OTG
  79265. + * Interrupt Register (GOTGINT) to determine what interrupt has
  79266. + * occurred.
  79267. + *
  79268. + * @param core_if Programming view of DWC_otg controller.
  79269. + */
  79270. +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t * core_if)
  79271. +{
  79272. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  79273. + gotgint_data_t gotgint;
  79274. + gotgctl_data_t gotgctl;
  79275. + gintmsk_data_t gintmsk;
  79276. + gpwrdn_data_t gpwrdn;
  79277. +
  79278. + gotgint.d32 = DWC_READ_REG32(&global_regs->gotgint);
  79279. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  79280. + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
  79281. + op_state_str(core_if));
  79282. +
  79283. + if (gotgint.b.sesenddet) {
  79284. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  79285. + "Session End Detected++ (%s)\n",
  79286. + op_state_str(core_if));
  79287. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  79288. +
  79289. + if (core_if->op_state == B_HOST) {
  79290. + cil_pcd_start(core_if);
  79291. + core_if->op_state = B_PERIPHERAL;
  79292. + } else {
  79293. + /* If not B_HOST and Device HNP still set. HNP
  79294. + * Did not succeed!*/
  79295. + if (gotgctl.b.devhnpen) {
  79296. + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
  79297. + __DWC_ERROR("Device Not Connected/Responding!\n");
  79298. + }
  79299. +
  79300. + /* If Session End Detected the B-Cable has
  79301. + * been disconnected. */
  79302. + /* Reset PCD and Gadget driver to a
  79303. + * clean state. */
  79304. + core_if->lx_state = DWC_OTG_L0;
  79305. + DWC_SPINUNLOCK(core_if->lock);
  79306. + cil_pcd_stop(core_if);
  79307. + DWC_SPINLOCK(core_if->lock);
  79308. +
  79309. + if (core_if->adp_enable) {
  79310. + if (core_if->power_down == 2) {
  79311. + gpwrdn.d32 = 0;
  79312. + gpwrdn.b.pwrdnswtch = 1;
  79313. + DWC_MODIFY_REG32(&core_if->
  79314. + core_global_regs->
  79315. + gpwrdn, gpwrdn.d32, 0);
  79316. + }
  79317. +
  79318. + gpwrdn.d32 = 0;
  79319. + gpwrdn.b.pmuintsel = 1;
  79320. + gpwrdn.b.pmuactv = 1;
  79321. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  79322. + gpwrdn, 0, gpwrdn.d32);
  79323. +
  79324. + dwc_otg_adp_sense_start(core_if);
  79325. + }
  79326. + }
  79327. +
  79328. + gotgctl.d32 = 0;
  79329. + gotgctl.b.devhnpen = 1;
  79330. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  79331. + }
  79332. + if (gotgint.b.sesreqsucstschng) {
  79333. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  79334. + "Session Reqeust Success Status Change++\n");
  79335. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  79336. + if (gotgctl.b.sesreqscs) {
  79337. +
  79338. + if ((core_if->core_params->phy_type ==
  79339. + DWC_PHY_TYPE_PARAM_FS) && (core_if->core_params->i2c_enable)) {
  79340. + core_if->srp_success = 1;
  79341. + } else {
  79342. + DWC_SPINUNLOCK(core_if->lock);
  79343. + cil_pcd_resume(core_if);
  79344. + DWC_SPINLOCK(core_if->lock);
  79345. + /* Clear Session Request */
  79346. + gotgctl.d32 = 0;
  79347. + gotgctl.b.sesreq = 1;
  79348. + DWC_MODIFY_REG32(&global_regs->gotgctl,
  79349. + gotgctl.d32, 0);
  79350. + }
  79351. + }
  79352. + }
  79353. + if (gotgint.b.hstnegsucstschng) {
  79354. + /* Print statements during the HNP interrupt handling
  79355. + * can cause it to fail.*/
  79356. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  79357. + /* WA for 3.00a- HW is not setting cur_mode, even sometimes
  79358. + * this does not help*/
  79359. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  79360. + dwc_udelay(100);
  79361. + if (gotgctl.b.hstnegscs) {
  79362. + if (dwc_otg_is_host_mode(core_if)) {
  79363. + core_if->op_state = B_HOST;
  79364. + /*
  79365. + * Need to disable SOF interrupt immediately.
  79366. + * When switching from device to host, the PCD
  79367. + * interrupt handler won't handle the
  79368. + * interrupt if host mode is already set. The
  79369. + * HCD interrupt handler won't get called if
  79370. + * the HCD state is HALT. This means that the
  79371. + * interrupt does not get handled and Linux
  79372. + * complains loudly.
  79373. + */
  79374. + gintmsk.d32 = 0;
  79375. + gintmsk.b.sofintr = 1;
  79376. + DWC_MODIFY_REG32(&global_regs->gintmsk,
  79377. + gintmsk.d32, 0);
  79378. + /* Call callback function with spin lock released */
  79379. + DWC_SPINUNLOCK(core_if->lock);
  79380. + cil_pcd_stop(core_if);
  79381. + /*
  79382. + * Initialize the Core for Host mode.
  79383. + */
  79384. + cil_hcd_start(core_if);
  79385. + DWC_SPINLOCK(core_if->lock);
  79386. + core_if->op_state = B_HOST;
  79387. + }
  79388. + } else {
  79389. + gotgctl.d32 = 0;
  79390. + gotgctl.b.hnpreq = 1;
  79391. + gotgctl.b.devhnpen = 1;
  79392. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  79393. + DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
  79394. + __DWC_ERROR("Device Not Connected/Responding\n");
  79395. + }
  79396. + }
  79397. + if (gotgint.b.hstnegdet) {
  79398. + /* The disconnect interrupt is set at the same time as
  79399. + * Host Negotiation Detected. During the mode
  79400. + * switch all interrupts are cleared so the disconnect
  79401. + * interrupt handler will not get executed.
  79402. + */
  79403. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  79404. + "Host Negotiation Detected++ (%s)\n",
  79405. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  79406. + "Device"));
  79407. + if (dwc_otg_is_device_mode(core_if)) {
  79408. + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",
  79409. + core_if->op_state);
  79410. + DWC_SPINUNLOCK(core_if->lock);
  79411. + cil_hcd_disconnect(core_if);
  79412. + cil_pcd_start(core_if);
  79413. + DWC_SPINLOCK(core_if->lock);
  79414. + core_if->op_state = A_PERIPHERAL;
  79415. + } else {
  79416. + /*
  79417. + * Need to disable SOF interrupt immediately. When
  79418. + * switching from device to host, the PCD interrupt
  79419. + * handler won't handle the interrupt if host mode is
  79420. + * already set. The HCD interrupt handler won't get
  79421. + * called if the HCD state is HALT. This means that
  79422. + * the interrupt does not get handled and Linux
  79423. + * complains loudly.
  79424. + */
  79425. + gintmsk.d32 = 0;
  79426. + gintmsk.b.sofintr = 1;
  79427. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmsk.d32, 0);
  79428. + DWC_SPINUNLOCK(core_if->lock);
  79429. + cil_pcd_stop(core_if);
  79430. + cil_hcd_start(core_if);
  79431. + DWC_SPINLOCK(core_if->lock);
  79432. + core_if->op_state = A_HOST;
  79433. + }
  79434. + }
  79435. + if (gotgint.b.adevtoutchng) {
  79436. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  79437. + "A-Device Timeout Change++\n");
  79438. + }
  79439. + if (gotgint.b.debdone) {
  79440. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Debounce Done++\n");
  79441. + }
  79442. +
  79443. + /* Clear GOTGINT */
  79444. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, gotgint.d32);
  79445. +
  79446. + return 1;
  79447. +}
  79448. +
  79449. +void w_conn_id_status_change(void *p)
  79450. +{
  79451. + dwc_otg_core_if_t *core_if = p;
  79452. + uint32_t count = 0;
  79453. + gotgctl_data_t gotgctl = {.d32 = 0 };
  79454. +
  79455. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  79456. + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
  79457. + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
  79458. +
  79459. + /* B-Device connector (Device Mode) */
  79460. + if (gotgctl.b.conidsts) {
  79461. + /* Wait for switch to device mode. */
  79462. + while (!dwc_otg_is_device_mode(core_if)) {
  79463. + DWC_PRINTF("Waiting for Peripheral Mode, Mode=%s\n",
  79464. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  79465. + "Peripheral"));
  79466. + dwc_mdelay(100);
  79467. + if (++count > 10000)
  79468. + break;
  79469. + }
  79470. + DWC_ASSERT(++count < 10000,
  79471. + "Connection id status change timed out");
  79472. + core_if->op_state = B_PERIPHERAL;
  79473. + dwc_otg_core_init(core_if);
  79474. + dwc_otg_enable_global_interrupts(core_if);
  79475. + cil_pcd_start(core_if);
  79476. + } else {
  79477. + /* A-Device connector (Host Mode) */
  79478. + while (!dwc_otg_is_host_mode(core_if)) {
  79479. + DWC_PRINTF("Waiting for Host Mode, Mode=%s\n",
  79480. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  79481. + "Peripheral"));
  79482. + dwc_mdelay(100);
  79483. + if (++count > 10000)
  79484. + break;
  79485. + }
  79486. + DWC_ASSERT(++count < 10000,
  79487. + "Connection id status change timed out");
  79488. + core_if->op_state = A_HOST;
  79489. + /*
  79490. + * Initialize the Core for Host mode.
  79491. + */
  79492. + dwc_otg_core_init(core_if);
  79493. + dwc_otg_enable_global_interrupts(core_if);
  79494. + cil_hcd_start(core_if);
  79495. + }
  79496. +}
  79497. +
  79498. +/**
  79499. + * This function handles the Connector ID Status Change Interrupt. It
  79500. + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
  79501. + * is a Device to Host Mode transition or a Host Mode to Device
  79502. + * Transition.
  79503. + *
  79504. + * This only occurs when the cable is connected/removed from the PHY
  79505. + * connector.
  79506. + *
  79507. + * @param core_if Programming view of DWC_otg controller.
  79508. + */
  79509. +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t * core_if)
  79510. +{
  79511. +
  79512. + /*
  79513. + * Need to disable SOF interrupt immediately. If switching from device
  79514. + * to host, the PCD interrupt handler won't handle the interrupt if
  79515. + * host mode is already set. The HCD interrupt handler won't get
  79516. + * called if the HCD state is HALT. This means that the interrupt does
  79517. + * not get handled and Linux complains loudly.
  79518. + */
  79519. + gintmsk_data_t gintmsk = {.d32 = 0 };
  79520. + gintsts_data_t gintsts = {.d32 = 0 };
  79521. +
  79522. + gintmsk.b.sofintr = 1;
  79523. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  79524. +
  79525. + DWC_DEBUGPL(DBG_CIL,
  79526. + " ++Connector ID Status Change Interrupt++ (%s)\n",
  79527. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"));
  79528. +
  79529. + DWC_SPINUNLOCK(core_if->lock);
  79530. +
  79531. + /*
  79532. + * Need to schedule a work, as there are possible DELAY function calls
  79533. + * Release lock before scheduling workq as it holds spinlock during scheduling
  79534. + */
  79535. +
  79536. + DWC_WORKQ_SCHEDULE(core_if->wq_otg, w_conn_id_status_change,
  79537. + core_if, "connection id status change");
  79538. + DWC_SPINLOCK(core_if->lock);
  79539. +
  79540. + /* Set flag and clear interrupt */
  79541. + gintsts.b.conidstschng = 1;
  79542. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  79543. +
  79544. + return 1;
  79545. +}
  79546. +
  79547. +/**
  79548. + * This interrupt indicates that a device is initiating the Session
  79549. + * Request Protocol to request the host to turn on bus power so a new
  79550. + * session can begin. The handler responds by turning on bus power. If
  79551. + * the DWC_otg controller is in low power mode, the handler brings the
  79552. + * controller out of low power mode before turning on bus power.
  79553. + *
  79554. + * @param core_if Programming view of DWC_otg controller.
  79555. + */
  79556. +int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t * core_if)
  79557. +{
  79558. + gintsts_data_t gintsts;
  79559. +
  79560. +#ifndef DWC_HOST_ONLY
  79561. + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
  79562. +
  79563. + if (dwc_otg_is_device_mode(core_if)) {
  79564. + DWC_PRINTF("SRP: Device mode\n");
  79565. + } else {
  79566. + hprt0_data_t hprt0;
  79567. + DWC_PRINTF("SRP: Host mode\n");
  79568. +
  79569. + /* Turn on the port power bit. */
  79570. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  79571. + hprt0.b.prtpwr = 1;
  79572. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  79573. +
  79574. + /* Start the Connection timer. So a message can be displayed
  79575. + * if connect does not occur within 10 seconds. */
  79576. + cil_hcd_session_start(core_if);
  79577. + }
  79578. +#endif
  79579. +
  79580. + /* Clear interrupt */
  79581. + gintsts.d32 = 0;
  79582. + gintsts.b.sessreqintr = 1;
  79583. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  79584. +
  79585. + return 1;
  79586. +}
  79587. +
  79588. +void w_wakeup_detected(void *p)
  79589. +{
  79590. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) p;
  79591. + /*
  79592. + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
  79593. + * so that OPT tests pass with all PHYs).
  79594. + */
  79595. + hprt0_data_t hprt0 = {.d32 = 0 };
  79596. +#if 0
  79597. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  79598. + /* Restart the Phy Clock */
  79599. + pcgcctl.b.stoppclk = 1;
  79600. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  79601. + dwc_udelay(10);
  79602. +#endif //0
  79603. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  79604. + DWC_DEBUGPL(DBG_ANY, "Resume: HPRT0=%0x\n", hprt0.d32);
  79605. +// dwc_mdelay(70);
  79606. + hprt0.b.prtres = 0; /* Resume */
  79607. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  79608. + DWC_DEBUGPL(DBG_ANY, "Clear Resume: HPRT0=%0x\n",
  79609. + DWC_READ_REG32(core_if->host_if->hprt0));
  79610. +
  79611. + cil_hcd_resume(core_if);
  79612. +
  79613. + /** Change to L0 state*/
  79614. + core_if->lx_state = DWC_OTG_L0;
  79615. +}
  79616. +
  79617. +/**
  79618. + * This interrupt indicates that the DWC_otg controller has detected a
  79619. + * resume or remote wakeup sequence. If the DWC_otg controller is in
  79620. + * low power mode, the handler must brings the controller out of low
  79621. + * power mode. The controller automatically begins resume
  79622. + * signaling. The handler schedules a time to stop resume signaling.
  79623. + */
  79624. +int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  79625. +{
  79626. + gintsts_data_t gintsts;
  79627. +
  79628. + DWC_DEBUGPL(DBG_ANY,
  79629. + "++Resume and Remote Wakeup Detected Interrupt++\n");
  79630. +
  79631. + DWC_PRINTF("%s lxstate = %d\n", __func__, core_if->lx_state);
  79632. +
  79633. + if (dwc_otg_is_device_mode(core_if)) {
  79634. + dctl_data_t dctl = {.d32 = 0 };
  79635. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
  79636. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  79637. + dsts));
  79638. + if (core_if->lx_state == DWC_OTG_L2) {
  79639. +#ifdef PARTIAL_POWER_DOWN
  79640. + if (core_if->hwcfg4.b.power_optimiz) {
  79641. + pcgcctl_data_t power = {.d32 = 0 };
  79642. +
  79643. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  79644. + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n",
  79645. + power.d32);
  79646. +
  79647. + power.b.stoppclk = 0;
  79648. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  79649. +
  79650. + power.b.pwrclmp = 0;
  79651. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  79652. +
  79653. + power.b.rstpdwnmodule = 0;
  79654. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  79655. + }
  79656. +#endif
  79657. + /* Clear the Remote Wakeup Signaling */
  79658. + dctl.b.rmtwkupsig = 1;
  79659. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  79660. + dctl, dctl.d32, 0);
  79661. +
  79662. + DWC_SPINUNLOCK(core_if->lock);
  79663. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  79664. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  79665. + }
  79666. + DWC_SPINLOCK(core_if->lock);
  79667. + } else {
  79668. + glpmcfg_data_t lpmcfg;
  79669. + lpmcfg.d32 =
  79670. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  79671. + lpmcfg.b.hird_thres &= (~(1 << 4));
  79672. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  79673. + lpmcfg.d32);
  79674. + }
  79675. + /** Change to L0 state*/
  79676. + core_if->lx_state = DWC_OTG_L0;
  79677. + } else {
  79678. + if (core_if->lx_state != DWC_OTG_L1) {
  79679. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  79680. +
  79681. + /* Restart the Phy Clock */
  79682. + pcgcctl.b.stoppclk = 1;
  79683. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  79684. + DWC_TIMER_SCHEDULE(core_if->wkp_timer, 71);
  79685. + } else {
  79686. + /** Change to L0 state*/
  79687. + core_if->lx_state = DWC_OTG_L0;
  79688. + }
  79689. + }
  79690. +
  79691. + /* Clear interrupt */
  79692. + gintsts.d32 = 0;
  79693. + gintsts.b.wkupintr = 1;
  79694. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  79695. +
  79696. + return 1;
  79697. +}
  79698. +
  79699. +/**
  79700. + * This interrupt indicates that the Wakeup Logic has detected a
  79701. + * Device disconnect.
  79702. + */
  79703. +static int32_t dwc_otg_handle_pwrdn_disconnect_intr(dwc_otg_core_if_t *core_if)
  79704. +{
  79705. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  79706. + gpwrdn_data_t gpwrdn_temp = { .d32 = 0 };
  79707. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  79708. +
  79709. + DWC_PRINTF("%s called\n", __FUNCTION__);
  79710. +
  79711. + if (!core_if->hibernation_suspend) {
  79712. + DWC_PRINTF("Already exited from Hibernation\n");
  79713. + return 1;
  79714. + }
  79715. +
  79716. + /* Switch on the voltage to the core */
  79717. + gpwrdn.b.pwrdnswtch = 1;
  79718. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79719. + dwc_udelay(10);
  79720. +
  79721. + /* Reset the core */
  79722. + gpwrdn.d32 = 0;
  79723. + gpwrdn.b.pwrdnrstn = 1;
  79724. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79725. + dwc_udelay(10);
  79726. +
  79727. + /* Disable power clamps*/
  79728. + gpwrdn.d32 = 0;
  79729. + gpwrdn.b.pwrdnclmp = 1;
  79730. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79731. +
  79732. + /* Remove reset the core signal */
  79733. + gpwrdn.d32 = 0;
  79734. + gpwrdn.b.pwrdnrstn = 1;
  79735. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  79736. + dwc_udelay(10);
  79737. +
  79738. + /* Disable PMU interrupt */
  79739. + gpwrdn.d32 = 0;
  79740. + gpwrdn.b.pmuintsel = 1;
  79741. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79742. +
  79743. + core_if->hibernation_suspend = 0;
  79744. +
  79745. + /* Disable PMU */
  79746. + gpwrdn.d32 = 0;
  79747. + gpwrdn.b.pmuactv = 1;
  79748. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79749. + dwc_udelay(10);
  79750. +
  79751. + if (gpwrdn_temp.b.idsts) {
  79752. + core_if->op_state = B_PERIPHERAL;
  79753. + dwc_otg_core_init(core_if);
  79754. + dwc_otg_enable_global_interrupts(core_if);
  79755. + cil_pcd_start(core_if);
  79756. + } else {
  79757. + core_if->op_state = A_HOST;
  79758. + dwc_otg_core_init(core_if);
  79759. + dwc_otg_enable_global_interrupts(core_if);
  79760. + cil_hcd_start(core_if);
  79761. + }
  79762. +
  79763. + return 1;
  79764. +}
  79765. +
  79766. +/**
  79767. + * This interrupt indicates that the Wakeup Logic has detected a
  79768. + * remote wakeup sequence.
  79769. + */
  79770. +static int32_t dwc_otg_handle_pwrdn_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  79771. +{
  79772. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  79773. + DWC_DEBUGPL(DBG_ANY,
  79774. + "++Powerdown Remote Wakeup Detected Interrupt++\n");
  79775. +
  79776. + if (!core_if->hibernation_suspend) {
  79777. + DWC_PRINTF("Already exited from Hibernation\n");
  79778. + return 1;
  79779. + }
  79780. +
  79781. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  79782. + if (gpwrdn.b.idsts) { // Device Mode
  79783. + if ((core_if->power_down == 2)
  79784. + && (core_if->hibernation_suspend == 1)) {
  79785. + dwc_otg_device_hibernation_restore(core_if, 0, 0);
  79786. + }
  79787. + } else {
  79788. + if ((core_if->power_down == 2)
  79789. + && (core_if->hibernation_suspend == 1)) {
  79790. + dwc_otg_host_hibernation_restore(core_if, 1, 0);
  79791. + }
  79792. + }
  79793. + return 1;
  79794. +}
  79795. +
  79796. +static int32_t dwc_otg_handle_pwrdn_idsts_change(dwc_otg_device_t *otg_dev)
  79797. +{
  79798. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  79799. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  79800. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  79801. +
  79802. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  79803. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  79804. + if (core_if->power_down == 2) {
  79805. + if (!core_if->hibernation_suspend) {
  79806. + DWC_PRINTF("Already exited from Hibernation\n");
  79807. + return 1;
  79808. + }
  79809. + DWC_DEBUGPL(DBG_ANY, "Exit from hibernation on ID sts change\n");
  79810. + /* Switch on the voltage to the core */
  79811. + gpwrdn.b.pwrdnswtch = 1;
  79812. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79813. + dwc_udelay(10);
  79814. +
  79815. + /* Reset the core */
  79816. + gpwrdn.d32 = 0;
  79817. + gpwrdn.b.pwrdnrstn = 1;
  79818. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79819. + dwc_udelay(10);
  79820. +
  79821. + /* Disable power clamps */
  79822. + gpwrdn.d32 = 0;
  79823. + gpwrdn.b.pwrdnclmp = 1;
  79824. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79825. +
  79826. + /* Remove reset the core signal */
  79827. + gpwrdn.d32 = 0;
  79828. + gpwrdn.b.pwrdnrstn = 1;
  79829. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  79830. + dwc_udelay(10);
  79831. +
  79832. + /* Disable PMU interrupt */
  79833. + gpwrdn.d32 = 0;
  79834. + gpwrdn.b.pmuintsel = 1;
  79835. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79836. +
  79837. + /*Indicates that we are exiting from hibernation */
  79838. + core_if->hibernation_suspend = 0;
  79839. +
  79840. + /* Disable PMU */
  79841. + gpwrdn.d32 = 0;
  79842. + gpwrdn.b.pmuactv = 1;
  79843. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79844. + dwc_udelay(10);
  79845. +
  79846. + gpwrdn.d32 = core_if->gr_backup->gpwrdn_local;
  79847. + if (gpwrdn.b.dis_vbus == 1) {
  79848. + gpwrdn.d32 = 0;
  79849. + gpwrdn.b.dis_vbus = 1;
  79850. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79851. + }
  79852. +
  79853. + if (gpwrdn_temp.b.idsts) {
  79854. + core_if->op_state = B_PERIPHERAL;
  79855. + dwc_otg_core_init(core_if);
  79856. + dwc_otg_enable_global_interrupts(core_if);
  79857. + cil_pcd_start(core_if);
  79858. + } else {
  79859. + core_if->op_state = A_HOST;
  79860. + dwc_otg_core_init(core_if);
  79861. + dwc_otg_enable_global_interrupts(core_if);
  79862. + cil_hcd_start(core_if);
  79863. + }
  79864. + }
  79865. +
  79866. + if (core_if->adp_enable) {
  79867. + uint8_t is_host = 0;
  79868. + DWC_SPINUNLOCK(core_if->lock);
  79869. + /* Change the core_if's lock to hcd/pcd lock depend on mode? */
  79870. +#ifndef DWC_HOST_ONLY
  79871. + if (gpwrdn_temp.b.idsts)
  79872. + core_if->lock = otg_dev->pcd->lock;
  79873. +#endif
  79874. +#ifndef DWC_DEVICE_ONLY
  79875. + if (!gpwrdn_temp.b.idsts) {
  79876. + core_if->lock = otg_dev->hcd->lock;
  79877. + is_host = 1;
  79878. + }
  79879. +#endif
  79880. + DWC_PRINTF("RESTART ADP\n");
  79881. + if (core_if->adp.probe_enabled)
  79882. + dwc_otg_adp_probe_stop(core_if);
  79883. + if (core_if->adp.sense_enabled)
  79884. + dwc_otg_adp_sense_stop(core_if);
  79885. + if (core_if->adp.sense_timer_started)
  79886. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  79887. + if (core_if->adp.vbuson_timer_started)
  79888. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  79889. + core_if->adp.probe_timer_values[0] = -1;
  79890. + core_if->adp.probe_timer_values[1] = -1;
  79891. + core_if->adp.sense_timer_started = 0;
  79892. + core_if->adp.vbuson_timer_started = 0;
  79893. + core_if->adp.probe_counter = 0;
  79894. + core_if->adp.gpwrdn = 0;
  79895. +
  79896. + /* Disable PMU and restart ADP */
  79897. + gpwrdn_temp.d32 = 0;
  79898. + gpwrdn_temp.b.pmuactv = 1;
  79899. + gpwrdn_temp.b.pmuintsel = 1;
  79900. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79901. + DWC_PRINTF("Check point 1\n");
  79902. + dwc_mdelay(110);
  79903. + dwc_otg_adp_start(core_if, is_host);
  79904. + DWC_SPINLOCK(core_if->lock);
  79905. + }
  79906. +
  79907. +
  79908. + return 1;
  79909. +}
  79910. +
  79911. +static int32_t dwc_otg_handle_pwrdn_session_change(dwc_otg_core_if_t * core_if)
  79912. +{
  79913. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  79914. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  79915. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  79916. +
  79917. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  79918. + if (core_if->power_down == 2) {
  79919. + if (!core_if->hibernation_suspend) {
  79920. + DWC_PRINTF("Already exited from Hibernation\n");
  79921. + return 1;
  79922. + }
  79923. +
  79924. + if ((otg_cap_param != DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  79925. + otg_cap_param != DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) &&
  79926. + gpwrdn.b.bsessvld == 0) {
  79927. + /* Save gpwrdn register for further usage if stschng interrupt */
  79928. + core_if->gr_backup->gpwrdn_local =
  79929. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  79930. + /*Exit from ISR and wait for stschng interrupt with bsessvld = 1 */
  79931. + return 1;
  79932. + }
  79933. +
  79934. + /* Switch on the voltage to the core */
  79935. + gpwrdn.d32 = 0;
  79936. + gpwrdn.b.pwrdnswtch = 1;
  79937. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79938. + dwc_udelay(10);
  79939. +
  79940. + /* Reset the core */
  79941. + gpwrdn.d32 = 0;
  79942. + gpwrdn.b.pwrdnrstn = 1;
  79943. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79944. + dwc_udelay(10);
  79945. +
  79946. + /* Disable power clamps */
  79947. + gpwrdn.d32 = 0;
  79948. + gpwrdn.b.pwrdnclmp = 1;
  79949. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79950. +
  79951. + /* Remove reset the core signal */
  79952. + gpwrdn.d32 = 0;
  79953. + gpwrdn.b.pwrdnrstn = 1;
  79954. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  79955. + dwc_udelay(10);
  79956. +
  79957. + /* Disable PMU interrupt */
  79958. + gpwrdn.d32 = 0;
  79959. + gpwrdn.b.pmuintsel = 1;
  79960. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79961. + dwc_udelay(10);
  79962. +
  79963. + /*Indicates that we are exiting from hibernation */
  79964. + core_if->hibernation_suspend = 0;
  79965. +
  79966. + /* Disable PMU */
  79967. + gpwrdn.d32 = 0;
  79968. + gpwrdn.b.pmuactv = 1;
  79969. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  79970. + dwc_udelay(10);
  79971. +
  79972. + core_if->op_state = B_PERIPHERAL;
  79973. + dwc_otg_core_init(core_if);
  79974. + dwc_otg_enable_global_interrupts(core_if);
  79975. + cil_pcd_start(core_if);
  79976. +
  79977. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  79978. + otg_cap_param == DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) {
  79979. + /*
  79980. + * Initiate SRP after initial ADP probe.
  79981. + */
  79982. + dwc_otg_initiate_srp(core_if);
  79983. + }
  79984. + }
  79985. +
  79986. + return 1;
  79987. +}
  79988. +/**
  79989. + * This interrupt indicates that the Wakeup Logic has detected a
  79990. + * status change either on IDDIG or BSessVld.
  79991. + */
  79992. +static uint32_t dwc_otg_handle_pwrdn_stschng_intr(dwc_otg_device_t *otg_dev)
  79993. +{
  79994. + int retval;
  79995. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  79996. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  79997. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  79998. +
  79999. + DWC_PRINTF("%s called\n", __FUNCTION__);
  80000. +
  80001. + if (core_if->power_down == 2) {
  80002. + if (core_if->hibernation_suspend <= 0) {
  80003. + DWC_PRINTF("Already exited from Hibernation\n");
  80004. + return 1;
  80005. + } else
  80006. + gpwrdn_temp.d32 = core_if->gr_backup->gpwrdn_local;
  80007. +
  80008. + } else {
  80009. + gpwrdn_temp.d32 = core_if->adp.gpwrdn;
  80010. + }
  80011. +
  80012. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  80013. +
  80014. + if (gpwrdn.b.idsts ^ gpwrdn_temp.b.idsts) {
  80015. + retval = dwc_otg_handle_pwrdn_idsts_change(otg_dev);
  80016. + } else if (gpwrdn.b.bsessvld ^ gpwrdn_temp.b.bsessvld) {
  80017. + retval = dwc_otg_handle_pwrdn_session_change(core_if);
  80018. + }
  80019. +
  80020. + return retval;
  80021. +}
  80022. +
  80023. +/**
  80024. + * This interrupt indicates that the Wakeup Logic has detected a
  80025. + * SRP.
  80026. + */
  80027. +static int32_t dwc_otg_handle_pwrdn_srp_intr(dwc_otg_core_if_t * core_if)
  80028. +{
  80029. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  80030. +
  80031. + DWC_PRINTF("%s called\n", __FUNCTION__);
  80032. +
  80033. + if (!core_if->hibernation_suspend) {
  80034. + DWC_PRINTF("Already exited from Hibernation\n");
  80035. + return 1;
  80036. + }
  80037. +#ifdef DWC_DEV_SRPCAP
  80038. + if (core_if->pwron_timer_started) {
  80039. + core_if->pwron_timer_started = 0;
  80040. + DWC_TIMER_CANCEL(core_if->pwron_timer);
  80041. + }
  80042. +#endif
  80043. +
  80044. + /* Switch on the voltage to the core */
  80045. + gpwrdn.b.pwrdnswtch = 1;
  80046. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80047. + dwc_udelay(10);
  80048. +
  80049. + /* Reset the core */
  80050. + gpwrdn.d32 = 0;
  80051. + gpwrdn.b.pwrdnrstn = 1;
  80052. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80053. + dwc_udelay(10);
  80054. +
  80055. + /* Disable power clamps */
  80056. + gpwrdn.d32 = 0;
  80057. + gpwrdn.b.pwrdnclmp = 1;
  80058. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80059. +
  80060. + /* Remove reset the core signal */
  80061. + gpwrdn.d32 = 0;
  80062. + gpwrdn.b.pwrdnrstn = 1;
  80063. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  80064. + dwc_udelay(10);
  80065. +
  80066. + /* Disable PMU interrupt */
  80067. + gpwrdn.d32 = 0;
  80068. + gpwrdn.b.pmuintsel = 1;
  80069. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80070. +
  80071. + /* Indicates that we are exiting from hibernation */
  80072. + core_if->hibernation_suspend = 0;
  80073. +
  80074. + /* Disable PMU */
  80075. + gpwrdn.d32 = 0;
  80076. + gpwrdn.b.pmuactv = 1;
  80077. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80078. + dwc_udelay(10);
  80079. +
  80080. + /* Programm Disable VBUS to 0 */
  80081. + gpwrdn.d32 = 0;
  80082. + gpwrdn.b.dis_vbus = 1;
  80083. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80084. +
  80085. + /*Initialize the core as Host */
  80086. + core_if->op_state = A_HOST;
  80087. + dwc_otg_core_init(core_if);
  80088. + dwc_otg_enable_global_interrupts(core_if);
  80089. + cil_hcd_start(core_if);
  80090. +
  80091. + return 1;
  80092. +}
  80093. +
  80094. +/** This interrupt indicates that restore command after Hibernation
  80095. + * was completed by the core. */
  80096. +int32_t dwc_otg_handle_restore_done_intr(dwc_otg_core_if_t * core_if)
  80097. +{
  80098. + pcgcctl_data_t pcgcctl;
  80099. + DWC_DEBUGPL(DBG_ANY, "++Restore Done Interrupt++\n");
  80100. +
  80101. + //TODO De-assert restore signal. 8.a
  80102. + pcgcctl.d32 = DWC_READ_REG32(core_if->pcgcctl);
  80103. + if (pcgcctl.b.restoremode == 1) {
  80104. + gintmsk_data_t gintmsk = {.d32 = 0 };
  80105. + /*
  80106. + * If restore mode is Remote Wakeup,
  80107. + * unmask Remote Wakeup interrupt.
  80108. + */
  80109. + gintmsk.b.wkupintr = 1;
  80110. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  80111. + 0, gintmsk.d32);
  80112. + }
  80113. +
  80114. + return 1;
  80115. +}
  80116. +
  80117. +/**
  80118. + * This interrupt indicates that a device has been disconnected from
  80119. + * the root port.
  80120. + */
  80121. +int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t * core_if)
  80122. +{
  80123. + gintsts_data_t gintsts;
  80124. +
  80125. + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
  80126. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"),
  80127. + op_state_str(core_if));
  80128. +
  80129. +/** @todo Consolidate this if statement. */
  80130. +#ifndef DWC_HOST_ONLY
  80131. + if (core_if->op_state == B_HOST) {
  80132. + /* If in device mode Disconnect and stop the HCD, then
  80133. + * start the PCD. */
  80134. + DWC_SPINUNLOCK(core_if->lock);
  80135. + cil_hcd_disconnect(core_if);
  80136. + cil_pcd_start(core_if);
  80137. + DWC_SPINLOCK(core_if->lock);
  80138. + core_if->op_state = B_PERIPHERAL;
  80139. + } else if (dwc_otg_is_device_mode(core_if)) {
  80140. + gotgctl_data_t gotgctl = {.d32 = 0 };
  80141. + gotgctl.d32 =
  80142. + DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  80143. + if (gotgctl.b.hstsethnpen == 1) {
  80144. + /* Do nothing, if HNP in process the OTG
  80145. + * interrupt "Host Negotiation Detected"
  80146. + * interrupt will do the mode switch.
  80147. + */
  80148. + } else if (gotgctl.b.devhnpen == 0) {
  80149. + /* If in device mode Disconnect and stop the HCD, then
  80150. + * start the PCD. */
  80151. + DWC_SPINUNLOCK(core_if->lock);
  80152. + cil_hcd_disconnect(core_if);
  80153. + cil_pcd_start(core_if);
  80154. + DWC_SPINLOCK(core_if->lock);
  80155. + core_if->op_state = B_PERIPHERAL;
  80156. + } else {
  80157. + DWC_DEBUGPL(DBG_ANY, "!a_peripheral && !devhnpen\n");
  80158. + }
  80159. + } else {
  80160. + if (core_if->op_state == A_HOST) {
  80161. + /* A-Cable still connected but device disconnected. */
  80162. + cil_hcd_disconnect(core_if);
  80163. + if (core_if->adp_enable) {
  80164. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  80165. + cil_hcd_stop(core_if);
  80166. + /* Enable Power Down Logic */
  80167. + gpwrdn.b.pmuintsel = 1;
  80168. + gpwrdn.b.pmuactv = 1;
  80169. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  80170. + gpwrdn, 0, gpwrdn.d32);
  80171. + dwc_otg_adp_probe_start(core_if);
  80172. +
  80173. + /* Power off the core */
  80174. + if (core_if->power_down == 2) {
  80175. + gpwrdn.d32 = 0;
  80176. + gpwrdn.b.pwrdnswtch = 1;
  80177. + DWC_MODIFY_REG32
  80178. + (&core_if->core_global_regs->gpwrdn,
  80179. + gpwrdn.d32, 0);
  80180. + }
  80181. + }
  80182. + }
  80183. + }
  80184. +#endif
  80185. + /* Change to L3(OFF) state */
  80186. + core_if->lx_state = DWC_OTG_L3;
  80187. +
  80188. + gintsts.d32 = 0;
  80189. + gintsts.b.disconnect = 1;
  80190. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  80191. + return 1;
  80192. +}
  80193. +
  80194. +/**
  80195. + * This interrupt indicates that SUSPEND state has been detected on
  80196. + * the USB.
  80197. + *
  80198. + * For HNP the USB Suspend interrupt signals the change from
  80199. + * "a_peripheral" to "a_host".
  80200. + *
  80201. + * When power management is enabled the core will be put in low power
  80202. + * mode.
  80203. + */
  80204. +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t * core_if)
  80205. +{
  80206. + dsts_data_t dsts;
  80207. + gintsts_data_t gintsts;
  80208. + dcfg_data_t dcfg;
  80209. +
  80210. + DWC_DEBUGPL(DBG_ANY, "USB SUSPEND\n");
  80211. +
  80212. + if (dwc_otg_is_device_mode(core_if)) {
  80213. + /* Check the Device status register to determine if the Suspend
  80214. + * state is active. */
  80215. + dsts.d32 =
  80216. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  80217. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
  80218. + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
  80219. + "HWCFG4.power Optimize=%d\n",
  80220. + dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
  80221. +
  80222. +#ifdef PARTIAL_POWER_DOWN
  80223. +/** @todo Add a module parameter for power management. */
  80224. +
  80225. + if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
  80226. + pcgcctl_data_t power = {.d32 = 0 };
  80227. + DWC_DEBUGPL(DBG_CIL, "suspend\n");
  80228. +
  80229. + power.b.pwrclmp = 1;
  80230. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  80231. +
  80232. + power.b.rstpdwnmodule = 1;
  80233. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  80234. +
  80235. + power.b.stoppclk = 1;
  80236. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  80237. +
  80238. + } else {
  80239. + DWC_DEBUGPL(DBG_ANY, "disconnect?\n");
  80240. + }
  80241. +#endif
  80242. + /* PCD callback for suspend. Release the lock inside of callback function */
  80243. + cil_pcd_suspend(core_if);
  80244. + if (core_if->power_down == 2)
  80245. + {
  80246. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  80247. + DWC_DEBUGPL(DBG_ANY,"lx_state = %08x\n",core_if->lx_state);
  80248. + DWC_DEBUGPL(DBG_ANY," device address = %08d\n",dcfg.b.devaddr);
  80249. +
  80250. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  80251. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  80252. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  80253. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  80254. +
  80255. + /* Change to L2(suspend) state */
  80256. + core_if->lx_state = DWC_OTG_L2;
  80257. +
  80258. + /* Clear interrupt in gintsts */
  80259. + gintsts.d32 = 0;
  80260. + gintsts.b.usbsuspend = 1;
  80261. + DWC_WRITE_REG32(&core_if->core_global_regs->
  80262. + gintsts, gintsts.d32);
  80263. + DWC_PRINTF("Start of hibernation completed\n");
  80264. + dwc_otg_save_global_regs(core_if);
  80265. + dwc_otg_save_dev_regs(core_if);
  80266. +
  80267. + gusbcfg.d32 =
  80268. + DWC_READ_REG32(&core_if->core_global_regs->
  80269. + gusbcfg);
  80270. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  80271. + /* ULPI interface */
  80272. + /* Suspend the Phy Clock */
  80273. + pcgcctl.d32 = 0;
  80274. + pcgcctl.b.stoppclk = 1;
  80275. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  80276. + pcgcctl.d32);
  80277. + dwc_udelay(10);
  80278. + gpwrdn.b.pmuactv = 1;
  80279. + DWC_MODIFY_REG32(&core_if->
  80280. + core_global_regs->
  80281. + gpwrdn, 0, gpwrdn.d32);
  80282. + } else {
  80283. + /* UTMI+ Interface */
  80284. + gpwrdn.b.pmuactv = 1;
  80285. + DWC_MODIFY_REG32(&core_if->
  80286. + core_global_regs->
  80287. + gpwrdn, 0, gpwrdn.d32);
  80288. + dwc_udelay(10);
  80289. + pcgcctl.b.stoppclk = 1;
  80290. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  80291. + pcgcctl.d32);
  80292. + dwc_udelay(10);
  80293. + }
  80294. +
  80295. + /* Set flag to indicate that we are in hibernation */
  80296. + core_if->hibernation_suspend = 1;
  80297. + /* Enable interrupts from wake up logic */
  80298. + gpwrdn.d32 = 0;
  80299. + gpwrdn.b.pmuintsel = 1;
  80300. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  80301. + gpwrdn, 0, gpwrdn.d32);
  80302. + dwc_udelay(10);
  80303. +
  80304. + /* Unmask device mode interrupts in GPWRDN */
  80305. + gpwrdn.d32 = 0;
  80306. + gpwrdn.b.rst_det_msk = 1;
  80307. + gpwrdn.b.lnstchng_msk = 1;
  80308. + gpwrdn.b.sts_chngint_msk = 1;
  80309. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  80310. + gpwrdn, 0, gpwrdn.d32);
  80311. + dwc_udelay(10);
  80312. +
  80313. + /* Enable Power Down Clamp */
  80314. + gpwrdn.d32 = 0;
  80315. + gpwrdn.b.pwrdnclmp = 1;
  80316. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  80317. + gpwrdn, 0, gpwrdn.d32);
  80318. + dwc_udelay(10);
  80319. +
  80320. + /* Switch off VDD */
  80321. + gpwrdn.d32 = 0;
  80322. + gpwrdn.b.pwrdnswtch = 1;
  80323. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  80324. + gpwrdn, 0, gpwrdn.d32);
  80325. +
  80326. + /* Save gpwrdn register for further usage if stschng interrupt */
  80327. + core_if->gr_backup->gpwrdn_local =
  80328. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  80329. + DWC_PRINTF("Hibernation completed\n");
  80330. +
  80331. + return 1;
  80332. + }
  80333. + } else if (core_if->power_down == 3) {
  80334. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  80335. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  80336. + DWC_DEBUGPL(DBG_ANY, "lx_state = %08x\n",core_if->lx_state);
  80337. + DWC_DEBUGPL(DBG_ANY, " device address = %08d\n",dcfg.b.devaddr);
  80338. +
  80339. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  80340. + DWC_DEBUGPL(DBG_ANY, "Start entering to extended hibernation\n");
  80341. + core_if->xhib = 1;
  80342. +
  80343. + /* Clear interrupt in gintsts */
  80344. + gintsts.d32 = 0;
  80345. + gintsts.b.usbsuspend = 1;
  80346. + DWC_WRITE_REG32(&core_if->core_global_regs->
  80347. + gintsts, gintsts.d32);
  80348. +
  80349. + dwc_otg_save_global_regs(core_if);
  80350. + dwc_otg_save_dev_regs(core_if);
  80351. +
  80352. + /* Wait for 10 PHY clocks */
  80353. + dwc_udelay(10);
  80354. +
  80355. + /* Program GPIO register while entering to xHib */
  80356. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x1);
  80357. +
  80358. + pcgcctl.b.enbl_extnd_hiber = 1;
  80359. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  80360. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  80361. +
  80362. + pcgcctl.d32 = 0;
  80363. + pcgcctl.b.extnd_hiber_pwrclmp = 1;
  80364. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  80365. +
  80366. + pcgcctl.d32 = 0;
  80367. + pcgcctl.b.extnd_hiber_switch = 1;
  80368. + core_if->gr_backup->xhib_gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  80369. + core_if->gr_backup->xhib_pcgcctl = DWC_READ_REG32(core_if->pcgcctl) | pcgcctl.d32;
  80370. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  80371. +
  80372. + DWC_DEBUGPL(DBG_ANY, "Finished entering to extended hibernation\n");
  80373. +
  80374. + return 1;
  80375. + }
  80376. + }
  80377. + } else {
  80378. + if (core_if->op_state == A_PERIPHERAL) {
  80379. + DWC_DEBUGPL(DBG_ANY, "a_peripheral->a_host\n");
  80380. + /* Clear the a_peripheral flag, back to a_host. */
  80381. + DWC_SPINUNLOCK(core_if->lock);
  80382. + cil_pcd_stop(core_if);
  80383. + cil_hcd_start(core_if);
  80384. + DWC_SPINLOCK(core_if->lock);
  80385. + core_if->op_state = A_HOST;
  80386. + }
  80387. + }
  80388. +
  80389. + /* Change to L2(suspend) state */
  80390. + core_if->lx_state = DWC_OTG_L2;
  80391. +
  80392. + /* Clear interrupt */
  80393. + gintsts.d32 = 0;
  80394. + gintsts.b.usbsuspend = 1;
  80395. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  80396. +
  80397. + return 1;
  80398. +}
  80399. +
  80400. +static int32_t dwc_otg_handle_xhib_exit_intr(dwc_otg_core_if_t * core_if)
  80401. +{
  80402. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  80403. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  80404. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  80405. +
  80406. + dwc_udelay(10);
  80407. +
  80408. + /* Program GPIO register while entering to xHib */
  80409. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x0);
  80410. +
  80411. + pcgcctl.d32 = core_if->gr_backup->xhib_pcgcctl;
  80412. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  80413. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  80414. + dwc_udelay(10);
  80415. +
  80416. + gpwrdn.d32 = core_if->gr_backup->xhib_gpwrdn;
  80417. + gpwrdn.b.restore = 1;
  80418. + DWC_WRITE_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32);
  80419. + dwc_udelay(10);
  80420. +
  80421. + restore_lpm_i2c_regs(core_if);
  80422. +
  80423. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  80424. + pcgcctl.b.max_xcvrselect = 1;
  80425. + pcgcctl.b.ess_reg_restored = 0;
  80426. + pcgcctl.b.extnd_hiber_switch = 0;
  80427. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  80428. + pcgcctl.b.enbl_extnd_hiber = 1;
  80429. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  80430. +
  80431. + gahbcfg.d32 = core_if->gr_backup->gahbcfg_local;
  80432. + gahbcfg.b.glblintrmsk = 1;
  80433. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  80434. +
  80435. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  80436. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0x1 << 16);
  80437. +
  80438. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  80439. + core_if->gr_backup->gusbcfg_local);
  80440. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  80441. + core_if->dr_backup->dcfg);
  80442. +
  80443. + pcgcctl.d32 = 0;
  80444. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  80445. + pcgcctl.b.max_xcvrselect = 1;
  80446. + pcgcctl.d32 |= 0x608;
  80447. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  80448. + dwc_udelay(10);
  80449. +
  80450. + pcgcctl.d32 = 0;
  80451. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  80452. + pcgcctl.b.max_xcvrselect = 1;
  80453. + pcgcctl.b.ess_reg_restored = 1;
  80454. + pcgcctl.b.enbl_extnd_hiber = 1;
  80455. + pcgcctl.b.rstpdwnmodule = 1;
  80456. + pcgcctl.b.restoremode = 1;
  80457. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  80458. +
  80459. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  80460. +
  80461. + return 1;
  80462. +}
  80463. +
  80464. +#ifdef CONFIG_USB_DWC_OTG_LPM
  80465. +/**
  80466. + * This function hadles LPM transaction received interrupt.
  80467. + */
  80468. +static int32_t dwc_otg_handle_lpm_intr(dwc_otg_core_if_t * core_if)
  80469. +{
  80470. + glpmcfg_data_t lpmcfg;
  80471. + gintsts_data_t gintsts;
  80472. +
  80473. + if (!core_if->core_params->lpm_enable) {
  80474. + DWC_PRINTF("Unexpected LPM interrupt\n");
  80475. + }
  80476. +
  80477. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  80478. + DWC_PRINTF("LPM config register = 0x%08x\n", lpmcfg.d32);
  80479. +
  80480. + if (dwc_otg_is_host_mode(core_if)) {
  80481. + cil_hcd_sleep(core_if);
  80482. + } else {
  80483. + lpmcfg.b.hird_thres |= (1 << 4);
  80484. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  80485. + lpmcfg.d32);
  80486. + }
  80487. +
  80488. + /* Examine prt_sleep_sts after TL1TokenTetry period max (10 us) */
  80489. + dwc_udelay(10);
  80490. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  80491. + if (lpmcfg.b.prt_sleep_sts) {
  80492. + /* Save the current state */
  80493. + core_if->lx_state = DWC_OTG_L1;
  80494. + }
  80495. +
  80496. + /* Clear interrupt */
  80497. + gintsts.d32 = 0;
  80498. + gintsts.b.lpmtranrcvd = 1;
  80499. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  80500. + return 1;
  80501. +}
  80502. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  80503. +
  80504. +/**
  80505. + * This function returns the Core Interrupt register.
  80506. + */
  80507. +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if, gintmsk_data_t *reenable_gintmsk, dwc_otg_hcd_t *hcd)
  80508. +{
  80509. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  80510. + gintsts_data_t gintsts;
  80511. + gintmsk_data_t gintmsk;
  80512. + gintmsk_data_t gintmsk_common = {.d32 = 0 };
  80513. + gintmsk_common.b.wkupintr = 1;
  80514. + gintmsk_common.b.sessreqintr = 1;
  80515. + gintmsk_common.b.conidstschng = 1;
  80516. + gintmsk_common.b.otgintr = 1;
  80517. + gintmsk_common.b.modemismatch = 1;
  80518. + gintmsk_common.b.disconnect = 1;
  80519. + gintmsk_common.b.usbsuspend = 1;
  80520. +#ifdef CONFIG_USB_DWC_OTG_LPM
  80521. + gintmsk_common.b.lpmtranrcvd = 1;
  80522. +#endif
  80523. + gintmsk_common.b.restoredone = 1;
  80524. + if(dwc_otg_is_device_mode(core_if))
  80525. + {
  80526. + /** @todo: The port interrupt occurs while in device
  80527. + * mode. Added code to CIL to clear the interrupt for now!
  80528. + */
  80529. + gintmsk_common.b.portintr = 1;
  80530. + }
  80531. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  80532. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  80533. + if(fiq_enable) {
  80534. + local_fiq_disable();
  80535. + /* Pull in the interrupts that the FIQ has masked */
  80536. + gintmsk.d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
  80537. + gintmsk.d32 |= gintmsk_common.d32;
  80538. + /* for the upstairs function to reenable - have to read it here in case FIQ triggers again */
  80539. + reenable_gintmsk->d32 = gintmsk.d32;
  80540. + local_fiq_enable();
  80541. + }
  80542. +
  80543. + gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  80544. +
  80545. +#ifdef DEBUG
  80546. + /* if any common interrupts set */
  80547. + if (gintsts.d32 & gintmsk_common.d32) {
  80548. + DWC_DEBUGPL(DBG_ANY, "common_intr: gintsts=%08x gintmsk=%08x\n",
  80549. + gintsts.d32, gintmsk.d32);
  80550. + }
  80551. +#endif
  80552. + if (!fiq_enable){
  80553. + if (gahbcfg.b.glblintrmsk)
  80554. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  80555. + else
  80556. + return 0;
  80557. + } else {
  80558. + /* Our IRQ kicker is no longer the USB hardware, it's the MPHI interface.
  80559. + * Can't trust the global interrupt mask bit in this case.
  80560. + */
  80561. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  80562. + }
  80563. +
  80564. +}
  80565. +
  80566. +/* MACRO for clearing interupt bits in GPWRDN register */
  80567. +#define CLEAR_GPWRDN_INTR(__core_if,__intr) \
  80568. +do { \
  80569. + gpwrdn_data_t gpwrdn = {.d32=0}; \
  80570. + gpwrdn.b.__intr = 1; \
  80571. + DWC_MODIFY_REG32(&__core_if->core_global_regs->gpwrdn, \
  80572. + 0, gpwrdn.d32); \
  80573. +} while (0)
  80574. +
  80575. +/**
  80576. + * Common interrupt handler.
  80577. + *
  80578. + * The common interrupts are those that occur in both Host and Device mode.
  80579. + * This handler handles the following interrupts:
  80580. + * - Mode Mismatch Interrupt
  80581. + * - Disconnect Interrupt
  80582. + * - OTG Interrupt
  80583. + * - Connector ID Status Change Interrupt
  80584. + * - Session Request Interrupt.
  80585. + * - Resume / Remote Wakeup Detected Interrupt.
  80586. + * - LPM Transaction Received Interrupt
  80587. + * - ADP Transaction Received Interrupt
  80588. + *
  80589. + */
  80590. +int32_t dwc_otg_handle_common_intr(void *dev)
  80591. +{
  80592. + int retval = 0;
  80593. + gintsts_data_t gintsts;
  80594. + gintmsk_data_t gintmsk_reenable = { .d32 = 0 };
  80595. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  80596. + dwc_otg_device_t *otg_dev = dev;
  80597. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  80598. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  80599. + if (dwc_otg_is_device_mode(core_if))
  80600. + core_if->frame_num = dwc_otg_get_frame_number(core_if);
  80601. +
  80602. + if (core_if->lock)
  80603. + DWC_SPINLOCK(core_if->lock);
  80604. +
  80605. + if (core_if->power_down == 3 && core_if->xhib == 1) {
  80606. + DWC_DEBUGPL(DBG_ANY, "Exiting from xHIB state\n");
  80607. + retval |= dwc_otg_handle_xhib_exit_intr(core_if);
  80608. + core_if->xhib = 2;
  80609. + if (core_if->lock)
  80610. + DWC_SPINUNLOCK(core_if->lock);
  80611. +
  80612. + return retval;
  80613. + }
  80614. +
  80615. + if (core_if->hibernation_suspend <= 0) {
  80616. + /* read_common will have to poke the FIQ's saved mask. We must then clear this mask at the end
  80617. + * of this handler - god only knows why it's done like this
  80618. + */
  80619. + gintsts.d32 = dwc_otg_read_common_intr(core_if, &gintmsk_reenable, otg_dev->hcd);
  80620. +
  80621. + if (gintsts.b.modemismatch) {
  80622. + retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
  80623. + }
  80624. + if (gintsts.b.otgintr) {
  80625. + retval |= dwc_otg_handle_otg_intr(core_if);
  80626. + }
  80627. + if (gintsts.b.conidstschng) {
  80628. + retval |=
  80629. + dwc_otg_handle_conn_id_status_change_intr(core_if);
  80630. + }
  80631. + if (gintsts.b.disconnect) {
  80632. + retval |= dwc_otg_handle_disconnect_intr(core_if);
  80633. + }
  80634. + if (gintsts.b.sessreqintr) {
  80635. + retval |= dwc_otg_handle_session_req_intr(core_if);
  80636. + }
  80637. + if (gintsts.b.wkupintr) {
  80638. + retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
  80639. + }
  80640. + if (gintsts.b.usbsuspend) {
  80641. + retval |= dwc_otg_handle_usb_suspend_intr(core_if);
  80642. + }
  80643. +#ifdef CONFIG_USB_DWC_OTG_LPM
  80644. + if (gintsts.b.lpmtranrcvd) {
  80645. + retval |= dwc_otg_handle_lpm_intr(core_if);
  80646. + }
  80647. +#endif
  80648. + if (gintsts.b.restoredone) {
  80649. + gintsts.d32 = 0;
  80650. + if (core_if->power_down == 2)
  80651. + core_if->hibernation_suspend = -1;
  80652. + else if (core_if->power_down == 3 && core_if->xhib == 2) {
  80653. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  80654. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  80655. + dctl_data_t dctl = {.d32 = 0 };
  80656. +
  80657. + DWC_WRITE_REG32(&core_if->core_global_regs->
  80658. + gintsts, 0xFFFFFFFF);
  80659. +
  80660. + DWC_DEBUGPL(DBG_ANY,
  80661. + "RESTORE DONE generated\n");
  80662. +
  80663. + gpwrdn.b.restore = 1;
  80664. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80665. + dwc_udelay(10);
  80666. +
  80667. + pcgcctl.b.rstpdwnmodule = 1;
  80668. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  80669. +
  80670. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, core_if->gr_backup->gusbcfg_local);
  80671. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, core_if->dr_backup->dcfg);
  80672. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, core_if->dr_backup->dctl);
  80673. + dwc_udelay(50);
  80674. +
  80675. + dctl.b.pwronprgdone = 1;
  80676. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  80677. + dwc_udelay(10);
  80678. +
  80679. + dwc_otg_restore_global_regs(core_if);
  80680. + dwc_otg_restore_dev_regs(core_if, 0);
  80681. +
  80682. + dctl.d32 = 0;
  80683. + dctl.b.pwronprgdone = 1;
  80684. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  80685. + dwc_udelay(10);
  80686. +
  80687. + pcgcctl.d32 = 0;
  80688. + pcgcctl.b.enbl_extnd_hiber = 1;
  80689. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  80690. +
  80691. + /* The core will be in ON STATE */
  80692. + core_if->lx_state = DWC_OTG_L0;
  80693. + core_if->xhib = 0;
  80694. +
  80695. + DWC_SPINUNLOCK(core_if->lock);
  80696. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  80697. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  80698. + }
  80699. + DWC_SPINLOCK(core_if->lock);
  80700. +
  80701. + }
  80702. +
  80703. + gintsts.b.restoredone = 1;
  80704. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  80705. + DWC_PRINTF(" --Restore done interrupt received-- \n");
  80706. + retval |= 1;
  80707. + }
  80708. + if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
  80709. + /* The port interrupt occurs while in device mode with HPRT0
  80710. + * Port Enable/Disable.
  80711. + */
  80712. + gintsts.d32 = 0;
  80713. + gintsts.b.portintr = 1;
  80714. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  80715. + retval |= 1;
  80716. + gintmsk_reenable.b.portintr = 1;
  80717. +
  80718. + }
  80719. + /* Did we actually handle anything? if so, unmask the interrupt */
  80720. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "CILOUT %1d", retval);
  80721. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintsts.d32);
  80722. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintmsk_reenable.d32);
  80723. + if (retval && fiq_enable) {
  80724. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_reenable.d32);
  80725. + }
  80726. +
  80727. + } else {
  80728. + DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
  80729. +
  80730. + if (gpwrdn.b.disconn_det && gpwrdn.b.disconn_det_msk) {
  80731. + CLEAR_GPWRDN_INTR(core_if, disconn_det);
  80732. + if (gpwrdn.b.linestate == 0) {
  80733. + dwc_otg_handle_pwrdn_disconnect_intr(core_if);
  80734. + } else {
  80735. + DWC_PRINTF("Disconnect detected while linestate is not 0\n");
  80736. + }
  80737. +
  80738. + retval |= 1;
  80739. + }
  80740. + if (gpwrdn.b.lnstschng && gpwrdn.b.lnstchng_msk) {
  80741. + CLEAR_GPWRDN_INTR(core_if, lnstschng);
  80742. + /* remote wakeup from hibernation */
  80743. + if (gpwrdn.b.linestate == 2 || gpwrdn.b.linestate == 1) {
  80744. + dwc_otg_handle_pwrdn_wakeup_detected_intr(core_if);
  80745. + } else {
  80746. + DWC_PRINTF("gpwrdn.linestate = %d\n", gpwrdn.b.linestate);
  80747. + }
  80748. + retval |= 1;
  80749. + }
  80750. + if (gpwrdn.b.rst_det && gpwrdn.b.rst_det_msk) {
  80751. + CLEAR_GPWRDN_INTR(core_if, rst_det);
  80752. + if (gpwrdn.b.linestate == 0) {
  80753. + DWC_PRINTF("Reset detected\n");
  80754. + retval |= dwc_otg_device_hibernation_restore(core_if, 0, 1);
  80755. + }
  80756. + }
  80757. + if (gpwrdn.b.srp_det && gpwrdn.b.srp_det_msk) {
  80758. + CLEAR_GPWRDN_INTR(core_if, srp_det);
  80759. + dwc_otg_handle_pwrdn_srp_intr(core_if);
  80760. + retval |= 1;
  80761. + }
  80762. + }
  80763. + /* Handle ADP interrupt here */
  80764. + if (gpwrdn.b.adp_int) {
  80765. + DWC_PRINTF("ADP interrupt\n");
  80766. + CLEAR_GPWRDN_INTR(core_if, adp_int);
  80767. + dwc_otg_adp_handle_intr(core_if);
  80768. + retval |= 1;
  80769. + }
  80770. + if (gpwrdn.b.sts_chngint && gpwrdn.b.sts_chngint_msk) {
  80771. + DWC_PRINTF("STS CHNG interrupt asserted\n");
  80772. + CLEAR_GPWRDN_INTR(core_if, sts_chngint);
  80773. + dwc_otg_handle_pwrdn_stschng_intr(otg_dev);
  80774. +
  80775. + retval |= 1;
  80776. + }
  80777. + if (core_if->lock)
  80778. + DWC_SPINUNLOCK(core_if->lock);
  80779. + return retval;
  80780. +}
  80781. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_core_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h
  80782. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 1970-01-01 01:00:00.000000000 +0100
  80783. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 2015-02-09 04:40:29.000000000 +0100
  80784. @@ -0,0 +1,705 @@
  80785. +/* ==========================================================================
  80786. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_core_if.h $
  80787. + * $Revision: #13 $
  80788. + * $Date: 2012/08/10 $
  80789. + * $Change: 2047372 $
  80790. + *
  80791. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  80792. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  80793. + * otherwise expressly agreed to in writing between Synopsys and you.
  80794. + *
  80795. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  80796. + * any End User Software License Agreement or Agreement for Licensed Product
  80797. + * with Synopsys or any supplement thereto. You are permitted to use and
  80798. + * redistribute this Software in source and binary forms, with or without
  80799. + * modification, provided that redistributions of source code must retain this
  80800. + * notice. You may not view, use, disclose, copy or distribute this file or
  80801. + * any information contained herein except pursuant to this license grant from
  80802. + * Synopsys. If you do not agree with this notice, including the disclaimer
  80803. + * below, then you are not authorized to use the Software.
  80804. + *
  80805. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  80806. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  80807. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  80808. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  80809. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  80810. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  80811. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  80812. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  80813. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  80814. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  80815. + * DAMAGE.
  80816. + * ========================================================================== */
  80817. +#if !defined(__DWC_CORE_IF_H__)
  80818. +#define __DWC_CORE_IF_H__
  80819. +
  80820. +#include "dwc_os.h"
  80821. +
  80822. +/** @file
  80823. + * This file defines DWC_OTG Core API
  80824. + */
  80825. +
  80826. +struct dwc_otg_core_if;
  80827. +typedef struct dwc_otg_core_if dwc_otg_core_if_t;
  80828. +
  80829. +/** Maximum number of Periodic FIFOs */
  80830. +#define MAX_PERIO_FIFOS 15
  80831. +/** Maximum number of Periodic FIFOs */
  80832. +#define MAX_TX_FIFOS 15
  80833. +
  80834. +/** Maximum number of Endpoints/HostChannels */
  80835. +#define MAX_EPS_CHANNELS 16
  80836. +
  80837. +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * _reg_base_addr);
  80838. +extern void dwc_otg_core_init(dwc_otg_core_if_t * _core_if);
  80839. +extern void dwc_otg_cil_remove(dwc_otg_core_if_t * _core_if);
  80840. +
  80841. +extern void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * _core_if);
  80842. +extern void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * _core_if);
  80843. +
  80844. +extern uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if);
  80845. +extern uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if);
  80846. +
  80847. +extern uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if);
  80848. +
  80849. +/** This function should be called on every hardware interrupt. */
  80850. +extern int32_t dwc_otg_handle_common_intr(void *otg_dev);
  80851. +
  80852. +/** @name OTG Core Parameters */
  80853. +/** @{ */
  80854. +
  80855. +/**
  80856. + * Specifies the OTG capabilities. The driver will automatically
  80857. + * detect the value for this parameter if none is specified.
  80858. + * 0 - HNP and SRP capable (default)
  80859. + * 1 - SRP Only capable
  80860. + * 2 - No HNP/SRP capable
  80861. + */
  80862. +extern int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val);
  80863. +extern int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if);
  80864. +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
  80865. +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
  80866. +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  80867. +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
  80868. +
  80869. +extern int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val);
  80870. +extern int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if);
  80871. +#define dwc_param_opt_default 1
  80872. +
  80873. +/**
  80874. + * Specifies whether to use slave or DMA mode for accessing the data
  80875. + * FIFOs. The driver will automatically detect the value for this
  80876. + * parameter if none is specified.
  80877. + * 0 - Slave
  80878. + * 1 - DMA (default, if available)
  80879. + */
  80880. +extern int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if,
  80881. + int32_t val);
  80882. +extern int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if);
  80883. +#define dwc_param_dma_enable_default 1
  80884. +
  80885. +/**
  80886. + * When DMA mode is enabled specifies whether to use
  80887. + * address DMA or DMA Descritor mode for accessing the data
  80888. + * FIFOs in device mode. The driver will automatically detect
  80889. + * the value for this parameter if none is specified.
  80890. + * 0 - address DMA
  80891. + * 1 - DMA Descriptor(default, if available)
  80892. + */
  80893. +extern int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if,
  80894. + int32_t val);
  80895. +extern int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if);
  80896. +//#define dwc_param_dma_desc_enable_default 1
  80897. +#define dwc_param_dma_desc_enable_default 0 // Broadcom BCM2708
  80898. +
  80899. +/** The DMA Burst size (applicable only for External DMA
  80900. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  80901. + */
  80902. +extern int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if,
  80903. + int32_t val);
  80904. +extern int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if);
  80905. +#define dwc_param_dma_burst_size_default 32
  80906. +
  80907. +/**
  80908. + * Specifies the maximum speed of operation in host and device mode.
  80909. + * The actual speed depends on the speed of the attached device and
  80910. + * the value of phy_type. The actual speed depends on the speed of the
  80911. + * attached device.
  80912. + * 0 - High Speed (default)
  80913. + * 1 - Full Speed
  80914. + */
  80915. +extern int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val);
  80916. +extern int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if);
  80917. +#define dwc_param_speed_default 0
  80918. +#define DWC_SPEED_PARAM_HIGH 0
  80919. +#define DWC_SPEED_PARAM_FULL 1
  80920. +
  80921. +/** Specifies whether low power mode is supported when attached
  80922. + * to a Full Speed or Low Speed device in host mode.
  80923. + * 0 - Don't support low power mode (default)
  80924. + * 1 - Support low power mode
  80925. + */
  80926. +extern int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  80927. + core_if, int32_t val);
  80928. +extern int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t
  80929. + * core_if);
  80930. +#define dwc_param_host_support_fs_ls_low_power_default 0
  80931. +
  80932. +/** Specifies the PHY clock rate in low power mode when connected to a
  80933. + * Low Speed device in host mode. This parameter is applicable only if
  80934. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  80935. + * then defaults to 6 MHZ otherwise 48 MHZ.
  80936. + *
  80937. + * 0 - 48 MHz
  80938. + * 1 - 6 MHz
  80939. + */
  80940. +extern int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  80941. + core_if, int32_t val);
  80942. +extern int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  80943. + core_if);
  80944. +#define dwc_param_host_ls_low_power_phy_clk_default 0
  80945. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  80946. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  80947. +
  80948. +/**
  80949. + * 0 - Use cC FIFO size parameters
  80950. + * 1 - Allow dynamic FIFO sizing (default)
  80951. + */
  80952. +extern int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  80953. + int32_t val);
  80954. +extern int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t *
  80955. + core_if);
  80956. +#define dwc_param_enable_dynamic_fifo_default 1
  80957. +
  80958. +/** Total number of 4-byte words in the data FIFO memory. This
  80959. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  80960. + * Tx FIFOs.
  80961. + * 32 to 32768 (default 8192)
  80962. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  80963. + */
  80964. +extern int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if,
  80965. + int32_t val);
  80966. +extern int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if);
  80967. +//#define dwc_param_data_fifo_size_default 8192
  80968. +#define dwc_param_data_fifo_size_default 0xFF0 // Broadcom BCM2708
  80969. +
  80970. +/** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  80971. + * FIFO sizing is enabled.
  80972. + * 16 to 32768 (default 1064)
  80973. + */
  80974. +extern int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if,
  80975. + int32_t val);
  80976. +extern int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if);
  80977. +#define dwc_param_dev_rx_fifo_size_default 1064
  80978. +
  80979. +/** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  80980. + * when dynamic FIFO sizing is enabled.
  80981. + * 16 to 32768 (default 1024)
  80982. + */
  80983. +extern int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  80984. + core_if, int32_t val);
  80985. +extern int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  80986. + core_if);
  80987. +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
  80988. +
  80989. +/** Number of 4-byte words in each of the periodic Tx FIFOs in device
  80990. + * mode when dynamic FIFO sizing is enabled.
  80991. + * 4 to 768 (default 256)
  80992. + */
  80993. +extern int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  80994. + int32_t val, int fifo_num);
  80995. +extern int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t *
  80996. + core_if, int fifo_num);
  80997. +#define dwc_param_dev_perio_tx_fifo_size_default 256
  80998. +
  80999. +/** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  81000. + * FIFO sizing is enabled.
  81001. + * 16 to 32768 (default 1024)
  81002. + */
  81003. +extern int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  81004. + int32_t val);
  81005. +extern int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if);
  81006. +//#define dwc_param_host_rx_fifo_size_default 1024
  81007. +#define dwc_param_host_rx_fifo_size_default 774 // Broadcom BCM2708
  81008. +
  81009. +/** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  81010. + * when Dynamic FIFO sizing is enabled in the core.
  81011. + * 16 to 32768 (default 1024)
  81012. + */
  81013. +extern int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  81014. + core_if, int32_t val);
  81015. +extern int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  81016. + core_if);
  81017. +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
  81018. +#define dwc_param_host_nperio_tx_fifo_size_default 0x100 // Broadcom BCM2708
  81019. +
  81020. +/** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  81021. + * FIFO sizing is enabled.
  81022. + * 16 to 32768 (default 1024)
  81023. + */
  81024. +extern int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  81025. + core_if, int32_t val);
  81026. +extern int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  81027. + core_if);
  81028. +//#define dwc_param_host_perio_tx_fifo_size_default 1024
  81029. +#define dwc_param_host_perio_tx_fifo_size_default 0x200 // Broadcom BCM2708
  81030. +
  81031. +/** The maximum transfer size supported in bytes.
  81032. + * 2047 to 65,535 (default 65,535)
  81033. + */
  81034. +extern int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  81035. + int32_t val);
  81036. +extern int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if);
  81037. +#define dwc_param_max_transfer_size_default 65535
  81038. +
  81039. +/** The maximum number of packets in a transfer.
  81040. + * 15 to 511 (default 511)
  81041. + */
  81042. +extern int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if,
  81043. + int32_t val);
  81044. +extern int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if);
  81045. +#define dwc_param_max_packet_count_default 511
  81046. +
  81047. +/** The number of host channel registers to use.
  81048. + * 1 to 16 (default 12)
  81049. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  81050. + */
  81051. +extern int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if,
  81052. + int32_t val);
  81053. +extern int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if);
  81054. +//#define dwc_param_host_channels_default 12
  81055. +#define dwc_param_host_channels_default 8 // Broadcom BCM2708
  81056. +
  81057. +/** The number of endpoints in addition to EP0 available for device
  81058. + * mode operations.
  81059. + * 1 to 15 (default 6 IN and OUT)
  81060. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  81061. + * endpoints in addition to EP0.
  81062. + */
  81063. +extern int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if,
  81064. + int32_t val);
  81065. +extern int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if);
  81066. +#define dwc_param_dev_endpoints_default 6
  81067. +
  81068. +/**
  81069. + * Specifies the type of PHY interface to use. By default, the driver
  81070. + * will automatically detect the phy_type.
  81071. + *
  81072. + * 0 - Full Speed PHY
  81073. + * 1 - UTMI+ (default)
  81074. + * 2 - ULPI
  81075. + */
  81076. +extern int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val);
  81077. +extern int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if);
  81078. +#define DWC_PHY_TYPE_PARAM_FS 0
  81079. +#define DWC_PHY_TYPE_PARAM_UTMI 1
  81080. +#define DWC_PHY_TYPE_PARAM_ULPI 2
  81081. +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
  81082. +
  81083. +/**
  81084. + * Specifies the UTMI+ Data Width. This parameter is
  81085. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  81086. + * PHY_TYPE, this parameter indicates the data width between
  81087. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  81088. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  81089. + * to "8 and 16 bits", meaning that the core has been
  81090. + * configured to work at either data path width.
  81091. + *
  81092. + * 8 or 16 bits (default 16)
  81093. + */
  81094. +extern int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if,
  81095. + int32_t val);
  81096. +extern int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if);
  81097. +//#define dwc_param_phy_utmi_width_default 16
  81098. +#define dwc_param_phy_utmi_width_default 8 // Broadcom BCM2708
  81099. +
  81100. +/**
  81101. + * Specifies whether the ULPI operates at double or single
  81102. + * data rate. This parameter is only applicable if PHY_TYPE is
  81103. + * ULPI.
  81104. + *
  81105. + * 0 - single data rate ULPI interface with 8 bit wide data
  81106. + * bus (default)
  81107. + * 1 - double data rate ULPI interface with 4 bit wide data
  81108. + * bus
  81109. + */
  81110. +extern int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if,
  81111. + int32_t val);
  81112. +extern int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if);
  81113. +#define dwc_param_phy_ulpi_ddr_default 0
  81114. +
  81115. +/**
  81116. + * Specifies whether to use the internal or external supply to
  81117. + * drive the vbus with a ULPI phy.
  81118. + */
  81119. +extern int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  81120. + int32_t val);
  81121. +extern int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if);
  81122. +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
  81123. +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
  81124. +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
  81125. +
  81126. +/**
  81127. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  81128. + * parameter is only applicable if PHY_TYPE is FS.
  81129. + * 0 - No (default)
  81130. + * 1 - Yes
  81131. + */
  81132. +extern int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if,
  81133. + int32_t val);
  81134. +extern int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if);
  81135. +#define dwc_param_i2c_enable_default 0
  81136. +
  81137. +extern int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if,
  81138. + int32_t val);
  81139. +extern int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if);
  81140. +#define dwc_param_ulpi_fs_ls_default 0
  81141. +
  81142. +extern int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val);
  81143. +extern int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if);
  81144. +#define dwc_param_ts_dline_default 0
  81145. +
  81146. +/**
  81147. + * Specifies whether dedicated transmit FIFOs are
  81148. + * enabled for non periodic IN endpoints in device mode
  81149. + * 0 - No
  81150. + * 1 - Yes
  81151. + */
  81152. +extern int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  81153. + int32_t val);
  81154. +extern int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t *
  81155. + core_if);
  81156. +#define dwc_param_en_multiple_tx_fifo_default 1
  81157. +
  81158. +/** Number of 4-byte words in each of the Tx FIFOs in device
  81159. + * mode when dynamic FIFO sizing is enabled.
  81160. + * 4 to 768 (default 256)
  81161. + */
  81162. +extern int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  81163. + int fifo_num, int32_t val);
  81164. +extern int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  81165. + int fifo_num);
  81166. +#define dwc_param_dev_tx_fifo_size_default 768
  81167. +
  81168. +/** Thresholding enable flag-
  81169. + * bit 0 - enable non-ISO Tx thresholding
  81170. + * bit 1 - enable ISO Tx thresholding
  81171. + * bit 2 - enable Rx thresholding
  81172. + */
  81173. +extern int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val);
  81174. +extern int32_t dwc_otg_get_thr_ctl(dwc_otg_core_if_t * core_if, int fifo_num);
  81175. +#define dwc_param_thr_ctl_default 0
  81176. +
  81177. +/** Thresholding length for Tx
  81178. + * FIFOs in 32 bit DWORDs
  81179. + */
  81180. +extern int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if,
  81181. + int32_t val);
  81182. +extern int32_t dwc_otg_get_tx_thr_length(dwc_otg_core_if_t * core_if);
  81183. +#define dwc_param_tx_thr_length_default 64
  81184. +
  81185. +/** Thresholding length for Rx
  81186. + * FIFOs in 32 bit DWORDs
  81187. + */
  81188. +extern int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if,
  81189. + int32_t val);
  81190. +extern int32_t dwc_otg_get_rx_thr_length(dwc_otg_core_if_t * core_if);
  81191. +#define dwc_param_rx_thr_length_default 64
  81192. +
  81193. +/**
  81194. + * Specifies whether LPM (Link Power Management) support is enabled
  81195. + */
  81196. +extern int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if,
  81197. + int32_t val);
  81198. +extern int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if);
  81199. +#define dwc_param_lpm_enable_default 1
  81200. +
  81201. +/**
  81202. + * Specifies whether PTI enhancement is enabled
  81203. + */
  81204. +extern int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if,
  81205. + int32_t val);
  81206. +extern int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if);
  81207. +#define dwc_param_pti_enable_default 0
  81208. +
  81209. +/**
  81210. + * Specifies whether MPI enhancement is enabled
  81211. + */
  81212. +extern int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if,
  81213. + int32_t val);
  81214. +extern int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if);
  81215. +#define dwc_param_mpi_enable_default 0
  81216. +
  81217. +/**
  81218. + * Specifies whether ADP capability is enabled
  81219. + */
  81220. +extern int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if,
  81221. + int32_t val);
  81222. +extern int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if);
  81223. +#define dwc_param_adp_enable_default 0
  81224. +
  81225. +/**
  81226. + * Specifies whether IC_USB capability is enabled
  81227. + */
  81228. +
  81229. +extern int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if,
  81230. + int32_t val);
  81231. +extern int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if);
  81232. +#define dwc_param_ic_usb_cap_default 0
  81233. +
  81234. +extern int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if,
  81235. + int32_t val);
  81236. +extern int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if);
  81237. +#define dwc_param_ahb_thr_ratio_default 0
  81238. +
  81239. +extern int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if,
  81240. + int32_t val);
  81241. +extern int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if);
  81242. +#define dwc_param_power_down_default 0
  81243. +
  81244. +extern int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if,
  81245. + int32_t val);
  81246. +extern int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if);
  81247. +#define dwc_param_reload_ctl_default 0
  81248. +
  81249. +extern int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if,
  81250. + int32_t val);
  81251. +extern int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if);
  81252. +#define dwc_param_dev_out_nak_default 0
  81253. +
  81254. +extern int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if,
  81255. + int32_t val);
  81256. +extern int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if);
  81257. +#define dwc_param_cont_on_bna_default 0
  81258. +
  81259. +extern int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if,
  81260. + int32_t val);
  81261. +extern int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if);
  81262. +#define dwc_param_ahb_single_default 0
  81263. +
  81264. +extern int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val);
  81265. +extern int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if);
  81266. +#define dwc_param_otg_ver_default 0
  81267. +
  81268. +/** @} */
  81269. +
  81270. +/** @name Access to registers and bit-fields */
  81271. +
  81272. +/**
  81273. + * Dump core registers and SPRAM
  81274. + */
  81275. +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * _core_if);
  81276. +extern void dwc_otg_dump_spram(dwc_otg_core_if_t * _core_if);
  81277. +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t * _core_if);
  81278. +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t * _core_if);
  81279. +
  81280. +/**
  81281. + * Get host negotiation status.
  81282. + */
  81283. +extern uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if);
  81284. +
  81285. +/**
  81286. + * Get srp status
  81287. + */
  81288. +extern uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if);
  81289. +
  81290. +/**
  81291. + * Set hnpreq bit in the GOTGCTL register.
  81292. + */
  81293. +extern void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val);
  81294. +
  81295. +/**
  81296. + * Get Content of SNPSID register.
  81297. + */
  81298. +extern uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if);
  81299. +
  81300. +/**
  81301. + * Get current mode.
  81302. + * Returns 0 if in device mode, and 1 if in host mode.
  81303. + */
  81304. +extern uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if);
  81305. +
  81306. +/**
  81307. + * Get value of hnpcapable field in the GUSBCFG register
  81308. + */
  81309. +extern uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if);
  81310. +/**
  81311. + * Set value of hnpcapable field in the GUSBCFG register
  81312. + */
  81313. +extern void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  81314. +
  81315. +/**
  81316. + * Get value of srpcapable field in the GUSBCFG register
  81317. + */
  81318. +extern uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if);
  81319. +/**
  81320. + * Set value of srpcapable field in the GUSBCFG register
  81321. + */
  81322. +extern void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  81323. +
  81324. +/**
  81325. + * Get value of devspeed field in the DCFG register
  81326. + */
  81327. +extern uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if);
  81328. +/**
  81329. + * Set value of devspeed field in the DCFG register
  81330. + */
  81331. +extern void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val);
  81332. +
  81333. +/**
  81334. + * Get the value of busconnected field from the HPRT0 register
  81335. + */
  81336. +extern uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if);
  81337. +
  81338. +/**
  81339. + * Gets the device enumeration Speed.
  81340. + */
  81341. +extern uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if);
  81342. +
  81343. +/**
  81344. + * Get value of prtpwr field from the HPRT0 register
  81345. + */
  81346. +extern uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if);
  81347. +
  81348. +/**
  81349. + * Get value of flag indicating core state - hibernated or not
  81350. + */
  81351. +extern uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if);
  81352. +
  81353. +/**
  81354. + * Set value of prtpwr field from the HPRT0 register
  81355. + */
  81356. +extern void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val);
  81357. +
  81358. +/**
  81359. + * Get value of prtsusp field from the HPRT0 regsiter
  81360. + */
  81361. +extern uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if);
  81362. +/**
  81363. + * Set value of prtpwr field from the HPRT0 register
  81364. + */
  81365. +extern void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val);
  81366. +
  81367. +/**
  81368. + * Get value of ModeChTimEn field from the HCFG regsiter
  81369. + */
  81370. +extern uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if);
  81371. +/**
  81372. + * Set value of ModeChTimEn field from the HCFG regsiter
  81373. + */
  81374. +extern void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val);
  81375. +
  81376. +/**
  81377. + * Get value of Fram Interval field from the HFIR regsiter
  81378. + */
  81379. +extern uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if);
  81380. +/**
  81381. + * Set value of Frame Interval field from the HFIR regsiter
  81382. + */
  81383. +extern void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val);
  81384. +
  81385. +/**
  81386. + * Set value of prtres field from the HPRT0 register
  81387. + *FIXME Remove?
  81388. + */
  81389. +extern void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val);
  81390. +
  81391. +/**
  81392. + * Get value of rmtwkupsig bit in DCTL register
  81393. + */
  81394. +extern uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if);
  81395. +
  81396. +/**
  81397. + * Get value of prt_sleep_sts field from the GLPMCFG register
  81398. + */
  81399. +extern uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if);
  81400. +
  81401. +/**
  81402. + * Get value of rem_wkup_en field from the GLPMCFG register
  81403. + */
  81404. +extern uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if);
  81405. +
  81406. +/**
  81407. + * Get value of appl_resp field from the GLPMCFG register
  81408. + */
  81409. +extern uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if);
  81410. +/**
  81411. + * Set value of appl_resp field from the GLPMCFG register
  81412. + */
  81413. +extern void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val);
  81414. +
  81415. +/**
  81416. + * Get value of hsic_connect field from the GLPMCFG register
  81417. + */
  81418. +extern uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if);
  81419. +/**
  81420. + * Set value of hsic_connect field from the GLPMCFG register
  81421. + */
  81422. +extern void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val);
  81423. +
  81424. +/**
  81425. + * Get value of inv_sel_hsic field from the GLPMCFG register.
  81426. + */
  81427. +extern uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if);
  81428. +/**
  81429. + * Set value of inv_sel_hsic field from the GLPMFG register.
  81430. + */
  81431. +extern void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val);
  81432. +
  81433. +/*
  81434. + * Some functions for accessing registers
  81435. + */
  81436. +
  81437. +/**
  81438. + * GOTGCTL register
  81439. + */
  81440. +extern uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if);
  81441. +extern void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val);
  81442. +
  81443. +/**
  81444. + * GUSBCFG register
  81445. + */
  81446. +extern uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if);
  81447. +extern void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val);
  81448. +
  81449. +/**
  81450. + * GRXFSIZ register
  81451. + */
  81452. +extern uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if);
  81453. +extern void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  81454. +
  81455. +/**
  81456. + * GNPTXFSIZ register
  81457. + */
  81458. +extern uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if);
  81459. +extern void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  81460. +
  81461. +extern uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if);
  81462. +extern void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val);
  81463. +
  81464. +/**
  81465. + * GGPIO register
  81466. + */
  81467. +extern uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if);
  81468. +extern void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val);
  81469. +
  81470. +/**
  81471. + * GUID register
  81472. + */
  81473. +extern uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if);
  81474. +extern void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val);
  81475. +
  81476. +/**
  81477. + * HPRT0 register
  81478. + */
  81479. +extern uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if);
  81480. +extern void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val);
  81481. +
  81482. +/**
  81483. + * GHPTXFSIZE
  81484. + */
  81485. +extern uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if);
  81486. +
  81487. +/** @} */
  81488. +
  81489. +#endif /* __DWC_CORE_IF_H__ */
  81490. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_dbg.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h
  81491. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 1970-01-01 01:00:00.000000000 +0100
  81492. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 2015-02-09 04:40:29.000000000 +0100
  81493. @@ -0,0 +1,117 @@
  81494. +/* ==========================================================================
  81495. + *
  81496. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  81497. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  81498. + * otherwise expressly agreed to in writing between Synopsys and you.
  81499. + *
  81500. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  81501. + * any End User Software License Agreement or Agreement for Licensed Product
  81502. + * with Synopsys or any supplement thereto. You are permitted to use and
  81503. + * redistribute this Software in source and binary forms, with or without
  81504. + * modification, provided that redistributions of source code must retain this
  81505. + * notice. You may not view, use, disclose, copy or distribute this file or
  81506. + * any information contained herein except pursuant to this license grant from
  81507. + * Synopsys. If you do not agree with this notice, including the disclaimer
  81508. + * below, then you are not authorized to use the Software.
  81509. + *
  81510. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  81511. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  81512. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  81513. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  81514. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  81515. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  81516. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  81517. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  81518. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  81519. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  81520. + * DAMAGE.
  81521. + * ========================================================================== */
  81522. +
  81523. +#ifndef __DWC_OTG_DBG_H__
  81524. +#define __DWC_OTG_DBG_H__
  81525. +
  81526. +/** @file
  81527. + * This file defines debug levels.
  81528. + * Debugging support vanishes in non-debug builds.
  81529. + */
  81530. +
  81531. +/**
  81532. + * The Debug Level bit-mask variable.
  81533. + */
  81534. +extern uint32_t g_dbg_lvl;
  81535. +/**
  81536. + * Set the Debug Level variable.
  81537. + */
  81538. +static inline uint32_t SET_DEBUG_LEVEL(const uint32_t new)
  81539. +{
  81540. + uint32_t old = g_dbg_lvl;
  81541. + g_dbg_lvl = new;
  81542. + return old;
  81543. +}
  81544. +
  81545. +#define DBG_USER (0x1)
  81546. +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
  81547. +#define DBG_CIL (0x2)
  81548. +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
  81549. + * messages */
  81550. +#define DBG_CILV (0x20)
  81551. +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
  81552. + * messages */
  81553. +#define DBG_PCD (0x4)
  81554. +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
  81555. + * messages */
  81556. +#define DBG_PCDV (0x40)
  81557. +/** When debug level has the DBG_HCD bit set, display Host debug messages */
  81558. +#define DBG_HCD (0x8)
  81559. +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
  81560. + * messages */
  81561. +#define DBG_HCDV (0x80)
  81562. +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
  81563. + * mode. */
  81564. +#define DBG_HCD_URB (0x800)
  81565. +/** When debug level has the DBG_HCDI bit set, display host interrupt
  81566. + * messages. */
  81567. +#define DBG_HCDI (0x1000)
  81568. +
  81569. +/** When debug level has any bit set, display debug messages */
  81570. +#define DBG_ANY (0xFF)
  81571. +
  81572. +/** All debug messages off */
  81573. +#define DBG_OFF 0
  81574. +
  81575. +/** Prefix string for DWC_DEBUG print macros. */
  81576. +#define USB_DWC "DWC_otg: "
  81577. +
  81578. +/**
  81579. + * Print a debug message when the Global debug level variable contains
  81580. + * the bit defined in <code>lvl</code>.
  81581. + *
  81582. + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
  81583. + * @param[in] x - like printf
  81584. + *
  81585. + * Example:<p>
  81586. + * <code>
  81587. + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
  81588. + * </code>
  81589. + * <br>
  81590. + * results in:<br>
  81591. + * <code>
  81592. + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
  81593. + * </code>
  81594. + */
  81595. +#ifdef DEBUG
  81596. +
  81597. +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)__DWC_DEBUG(USB_DWC x ); }while(0)
  81598. +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
  81599. +
  81600. +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
  81601. +
  81602. +#else
  81603. +
  81604. +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
  81605. +# define DWC_DEBUGP(x...)
  81606. +
  81607. +# define CHK_DEBUG_LEVEL(level) (0)
  81608. +
  81609. +#endif /*DEBUG*/
  81610. +#endif
  81611. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_driver.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.c
  81612. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_driver.c 1970-01-01 01:00:00.000000000 +0100
  81613. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.c 2015-02-09 04:40:29.000000000 +0100
  81614. @@ -0,0 +1,1749 @@
  81615. +/* ==========================================================================
  81616. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.c $
  81617. + * $Revision: #92 $
  81618. + * $Date: 2012/08/10 $
  81619. + * $Change: 2047372 $
  81620. + *
  81621. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  81622. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  81623. + * otherwise expressly agreed to in writing between Synopsys and you.
  81624. + *
  81625. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  81626. + * any End User Software License Agreement or Agreement for Licensed Product
  81627. + * with Synopsys or any supplement thereto. You are permitted to use and
  81628. + * redistribute this Software in source and binary forms, with or without
  81629. + * modification, provided that redistributions of source code must retain this
  81630. + * notice. You may not view, use, disclose, copy or distribute this file or
  81631. + * any information contained herein except pursuant to this license grant from
  81632. + * Synopsys. If you do not agree with this notice, including the disclaimer
  81633. + * below, then you are not authorized to use the Software.
  81634. + *
  81635. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  81636. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  81637. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  81638. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  81639. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  81640. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  81641. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  81642. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  81643. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  81644. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  81645. + * DAMAGE.
  81646. + * ========================================================================== */
  81647. +
  81648. +/** @file
  81649. + * The dwc_otg_driver module provides the initialization and cleanup entry
  81650. + * points for the DWC_otg driver. This module will be dynamically installed
  81651. + * after Linux is booted using the insmod command. When the module is
  81652. + * installed, the dwc_otg_driver_init function is called. When the module is
  81653. + * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
  81654. + *
  81655. + * This module also defines a data structure for the dwc_otg_driver, which is
  81656. + * used in conjunction with the standard ARM lm_device structure. These
  81657. + * structures allow the OTG driver to comply with the standard Linux driver
  81658. + * model in which devices and drivers are registered with a bus driver. This
  81659. + * has the benefit that Linux can expose attributes of the driver and device
  81660. + * in its special sysfs file system. Users can then read or write files in
  81661. + * this file system to perform diagnostics on the driver components or the
  81662. + * device.
  81663. + */
  81664. +
  81665. +#include "dwc_otg_os_dep.h"
  81666. +#include "dwc_os.h"
  81667. +#include "dwc_otg_dbg.h"
  81668. +#include "dwc_otg_driver.h"
  81669. +#include "dwc_otg_attr.h"
  81670. +#include "dwc_otg_core_if.h"
  81671. +#include "dwc_otg_pcd_if.h"
  81672. +#include "dwc_otg_hcd_if.h"
  81673. +#include "dwc_otg_fiq_fsm.h"
  81674. +
  81675. +#define DWC_DRIVER_VERSION "3.00a 10-AUG-2012"
  81676. +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
  81677. +
  81678. +bool microframe_schedule=true;
  81679. +
  81680. +static const char dwc_driver_name[] = "dwc_otg";
  81681. +
  81682. +
  81683. +extern int pcd_init(
  81684. +#ifdef LM_INTERFACE
  81685. + struct lm_device *_dev
  81686. +#elif defined(PCI_INTERFACE)
  81687. + struct pci_dev *_dev
  81688. +#elif defined(PLATFORM_INTERFACE)
  81689. + struct platform_device *dev
  81690. +#endif
  81691. + );
  81692. +extern int hcd_init(
  81693. +#ifdef LM_INTERFACE
  81694. + struct lm_device *_dev
  81695. +#elif defined(PCI_INTERFACE)
  81696. + struct pci_dev *_dev
  81697. +#elif defined(PLATFORM_INTERFACE)
  81698. + struct platform_device *dev
  81699. +#endif
  81700. + );
  81701. +
  81702. +extern int pcd_remove(
  81703. +#ifdef LM_INTERFACE
  81704. + struct lm_device *_dev
  81705. +#elif defined(PCI_INTERFACE)
  81706. + struct pci_dev *_dev
  81707. +#elif defined(PLATFORM_INTERFACE)
  81708. + struct platform_device *_dev
  81709. +#endif
  81710. + );
  81711. +
  81712. +extern void hcd_remove(
  81713. +#ifdef LM_INTERFACE
  81714. + struct lm_device *_dev
  81715. +#elif defined(PCI_INTERFACE)
  81716. + struct pci_dev *_dev
  81717. +#elif defined(PLATFORM_INTERFACE)
  81718. + struct platform_device *_dev
  81719. +#endif
  81720. + );
  81721. +
  81722. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  81723. +
  81724. +/*-------------------------------------------------------------------------*/
  81725. +/* Encapsulate the module parameter settings */
  81726. +
  81727. +struct dwc_otg_driver_module_params {
  81728. + int32_t opt;
  81729. + int32_t otg_cap;
  81730. + int32_t dma_enable;
  81731. + int32_t dma_desc_enable;
  81732. + int32_t dma_burst_size;
  81733. + int32_t speed;
  81734. + int32_t host_support_fs_ls_low_power;
  81735. + int32_t host_ls_low_power_phy_clk;
  81736. + int32_t enable_dynamic_fifo;
  81737. + int32_t data_fifo_size;
  81738. + int32_t dev_rx_fifo_size;
  81739. + int32_t dev_nperio_tx_fifo_size;
  81740. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  81741. + int32_t host_rx_fifo_size;
  81742. + int32_t host_nperio_tx_fifo_size;
  81743. + int32_t host_perio_tx_fifo_size;
  81744. + int32_t max_transfer_size;
  81745. + int32_t max_packet_count;
  81746. + int32_t host_channels;
  81747. + int32_t dev_endpoints;
  81748. + int32_t phy_type;
  81749. + int32_t phy_utmi_width;
  81750. + int32_t phy_ulpi_ddr;
  81751. + int32_t phy_ulpi_ext_vbus;
  81752. + int32_t i2c_enable;
  81753. + int32_t ulpi_fs_ls;
  81754. + int32_t ts_dline;
  81755. + int32_t en_multiple_tx_fifo;
  81756. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  81757. + uint32_t thr_ctl;
  81758. + uint32_t tx_thr_length;
  81759. + uint32_t rx_thr_length;
  81760. + int32_t pti_enable;
  81761. + int32_t mpi_enable;
  81762. + int32_t lpm_enable;
  81763. + int32_t ic_usb_cap;
  81764. + int32_t ahb_thr_ratio;
  81765. + int32_t power_down;
  81766. + int32_t reload_ctl;
  81767. + int32_t dev_out_nak;
  81768. + int32_t cont_on_bna;
  81769. + int32_t ahb_single;
  81770. + int32_t otg_ver;
  81771. + int32_t adp_enable;
  81772. +};
  81773. +
  81774. +static struct dwc_otg_driver_module_params dwc_otg_module_params = {
  81775. + .opt = -1,
  81776. + .otg_cap = -1,
  81777. + .dma_enable = -1,
  81778. + .dma_desc_enable = -1,
  81779. + .dma_burst_size = -1,
  81780. + .speed = -1,
  81781. + .host_support_fs_ls_low_power = -1,
  81782. + .host_ls_low_power_phy_clk = -1,
  81783. + .enable_dynamic_fifo = -1,
  81784. + .data_fifo_size = -1,
  81785. + .dev_rx_fifo_size = -1,
  81786. + .dev_nperio_tx_fifo_size = -1,
  81787. + .dev_perio_tx_fifo_size = {
  81788. + /* dev_perio_tx_fifo_size_1 */
  81789. + -1,
  81790. + -1,
  81791. + -1,
  81792. + -1,
  81793. + -1,
  81794. + -1,
  81795. + -1,
  81796. + -1,
  81797. + -1,
  81798. + -1,
  81799. + -1,
  81800. + -1,
  81801. + -1,
  81802. + -1,
  81803. + -1
  81804. + /* 15 */
  81805. + },
  81806. + .host_rx_fifo_size = -1,
  81807. + .host_nperio_tx_fifo_size = -1,
  81808. + .host_perio_tx_fifo_size = -1,
  81809. + .max_transfer_size = -1,
  81810. + .max_packet_count = -1,
  81811. + .host_channels = -1,
  81812. + .dev_endpoints = -1,
  81813. + .phy_type = -1,
  81814. + .phy_utmi_width = -1,
  81815. + .phy_ulpi_ddr = -1,
  81816. + .phy_ulpi_ext_vbus = -1,
  81817. + .i2c_enable = -1,
  81818. + .ulpi_fs_ls = -1,
  81819. + .ts_dline = -1,
  81820. + .en_multiple_tx_fifo = -1,
  81821. + .dev_tx_fifo_size = {
  81822. + /* dev_tx_fifo_size */
  81823. + -1,
  81824. + -1,
  81825. + -1,
  81826. + -1,
  81827. + -1,
  81828. + -1,
  81829. + -1,
  81830. + -1,
  81831. + -1,
  81832. + -1,
  81833. + -1,
  81834. + -1,
  81835. + -1,
  81836. + -1,
  81837. + -1
  81838. + /* 15 */
  81839. + },
  81840. + .thr_ctl = -1,
  81841. + .tx_thr_length = -1,
  81842. + .rx_thr_length = -1,
  81843. + .pti_enable = -1,
  81844. + .mpi_enable = -1,
  81845. + .lpm_enable = 0,
  81846. + .ic_usb_cap = -1,
  81847. + .ahb_thr_ratio = -1,
  81848. + .power_down = -1,
  81849. + .reload_ctl = -1,
  81850. + .dev_out_nak = -1,
  81851. + .cont_on_bna = -1,
  81852. + .ahb_single = -1,
  81853. + .otg_ver = -1,
  81854. + .adp_enable = -1,
  81855. +};
  81856. +
  81857. +//Global variable to switch the fiq fix on or off
  81858. +bool fiq_enable = 1;
  81859. +// Global variable to enable the split transaction fix
  81860. +bool fiq_fsm_enable = true;
  81861. +//Bulk split-transaction NAK holdoff in microframes
  81862. +uint16_t nak_holdoff = 8;
  81863. +
  81864. +unsigned short fiq_fsm_mask = 0x07;
  81865. +
  81866. +/**
  81867. + * This function shows the Driver Version.
  81868. + */
  81869. +static ssize_t version_show(struct device_driver *dev, char *buf)
  81870. +{
  81871. + return snprintf(buf, sizeof(DWC_DRIVER_VERSION) + 2, "%s\n",
  81872. + DWC_DRIVER_VERSION);
  81873. +}
  81874. +
  81875. +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
  81876. +
  81877. +/**
  81878. + * Global Debug Level Mask.
  81879. + */
  81880. +uint32_t g_dbg_lvl = 0; /* OFF */
  81881. +
  81882. +/**
  81883. + * This function shows the driver Debug Level.
  81884. + */
  81885. +static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
  81886. +{
  81887. + return sprintf(buf, "0x%0x\n", g_dbg_lvl);
  81888. +}
  81889. +
  81890. +/**
  81891. + * This function stores the driver Debug Level.
  81892. + */
  81893. +static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
  81894. + size_t count)
  81895. +{
  81896. + g_dbg_lvl = simple_strtoul(buf, NULL, 16);
  81897. + return count;
  81898. +}
  81899. +
  81900. +static DRIVER_ATTR(debuglevel, S_IRUGO | S_IWUSR, dbg_level_show,
  81901. + dbg_level_store);
  81902. +
  81903. +/**
  81904. + * This function is called during module intialization
  81905. + * to pass module parameters to the DWC_OTG CORE.
  81906. + */
  81907. +static int set_parameters(dwc_otg_core_if_t * core_if)
  81908. +{
  81909. + int retval = 0;
  81910. + int i;
  81911. +
  81912. + if (dwc_otg_module_params.otg_cap != -1) {
  81913. + retval +=
  81914. + dwc_otg_set_param_otg_cap(core_if,
  81915. + dwc_otg_module_params.otg_cap);
  81916. + }
  81917. + if (dwc_otg_module_params.dma_enable != -1) {
  81918. + retval +=
  81919. + dwc_otg_set_param_dma_enable(core_if,
  81920. + dwc_otg_module_params.
  81921. + dma_enable);
  81922. + }
  81923. + if (dwc_otg_module_params.dma_desc_enable != -1) {
  81924. + retval +=
  81925. + dwc_otg_set_param_dma_desc_enable(core_if,
  81926. + dwc_otg_module_params.
  81927. + dma_desc_enable);
  81928. + }
  81929. + if (dwc_otg_module_params.opt != -1) {
  81930. + retval +=
  81931. + dwc_otg_set_param_opt(core_if, dwc_otg_module_params.opt);
  81932. + }
  81933. + if (dwc_otg_module_params.dma_burst_size != -1) {
  81934. + retval +=
  81935. + dwc_otg_set_param_dma_burst_size(core_if,
  81936. + dwc_otg_module_params.
  81937. + dma_burst_size);
  81938. + }
  81939. + if (dwc_otg_module_params.host_support_fs_ls_low_power != -1) {
  81940. + retval +=
  81941. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  81942. + dwc_otg_module_params.
  81943. + host_support_fs_ls_low_power);
  81944. + }
  81945. + if (dwc_otg_module_params.enable_dynamic_fifo != -1) {
  81946. + retval +=
  81947. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  81948. + dwc_otg_module_params.
  81949. + enable_dynamic_fifo);
  81950. + }
  81951. + if (dwc_otg_module_params.data_fifo_size != -1) {
  81952. + retval +=
  81953. + dwc_otg_set_param_data_fifo_size(core_if,
  81954. + dwc_otg_module_params.
  81955. + data_fifo_size);
  81956. + }
  81957. + if (dwc_otg_module_params.dev_rx_fifo_size != -1) {
  81958. + retval +=
  81959. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  81960. + dwc_otg_module_params.
  81961. + dev_rx_fifo_size);
  81962. + }
  81963. + if (dwc_otg_module_params.dev_nperio_tx_fifo_size != -1) {
  81964. + retval +=
  81965. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  81966. + dwc_otg_module_params.
  81967. + dev_nperio_tx_fifo_size);
  81968. + }
  81969. + if (dwc_otg_module_params.host_rx_fifo_size != -1) {
  81970. + retval +=
  81971. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  81972. + dwc_otg_module_params.host_rx_fifo_size);
  81973. + }
  81974. + if (dwc_otg_module_params.host_nperio_tx_fifo_size != -1) {
  81975. + retval +=
  81976. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  81977. + dwc_otg_module_params.
  81978. + host_nperio_tx_fifo_size);
  81979. + }
  81980. + if (dwc_otg_module_params.host_perio_tx_fifo_size != -1) {
  81981. + retval +=
  81982. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  81983. + dwc_otg_module_params.
  81984. + host_perio_tx_fifo_size);
  81985. + }
  81986. + if (dwc_otg_module_params.max_transfer_size != -1) {
  81987. + retval +=
  81988. + dwc_otg_set_param_max_transfer_size(core_if,
  81989. + dwc_otg_module_params.
  81990. + max_transfer_size);
  81991. + }
  81992. + if (dwc_otg_module_params.max_packet_count != -1) {
  81993. + retval +=
  81994. + dwc_otg_set_param_max_packet_count(core_if,
  81995. + dwc_otg_module_params.
  81996. + max_packet_count);
  81997. + }
  81998. + if (dwc_otg_module_params.host_channels != -1) {
  81999. + retval +=
  82000. + dwc_otg_set_param_host_channels(core_if,
  82001. + dwc_otg_module_params.
  82002. + host_channels);
  82003. + }
  82004. + if (dwc_otg_module_params.dev_endpoints != -1) {
  82005. + retval +=
  82006. + dwc_otg_set_param_dev_endpoints(core_if,
  82007. + dwc_otg_module_params.
  82008. + dev_endpoints);
  82009. + }
  82010. + if (dwc_otg_module_params.phy_type != -1) {
  82011. + retval +=
  82012. + dwc_otg_set_param_phy_type(core_if,
  82013. + dwc_otg_module_params.phy_type);
  82014. + }
  82015. + if (dwc_otg_module_params.speed != -1) {
  82016. + retval +=
  82017. + dwc_otg_set_param_speed(core_if,
  82018. + dwc_otg_module_params.speed);
  82019. + }
  82020. + if (dwc_otg_module_params.host_ls_low_power_phy_clk != -1) {
  82021. + retval +=
  82022. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  82023. + dwc_otg_module_params.
  82024. + host_ls_low_power_phy_clk);
  82025. + }
  82026. + if (dwc_otg_module_params.phy_ulpi_ddr != -1) {
  82027. + retval +=
  82028. + dwc_otg_set_param_phy_ulpi_ddr(core_if,
  82029. + dwc_otg_module_params.
  82030. + phy_ulpi_ddr);
  82031. + }
  82032. + if (dwc_otg_module_params.phy_ulpi_ext_vbus != -1) {
  82033. + retval +=
  82034. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  82035. + dwc_otg_module_params.
  82036. + phy_ulpi_ext_vbus);
  82037. + }
  82038. + if (dwc_otg_module_params.phy_utmi_width != -1) {
  82039. + retval +=
  82040. + dwc_otg_set_param_phy_utmi_width(core_if,
  82041. + dwc_otg_module_params.
  82042. + phy_utmi_width);
  82043. + }
  82044. + if (dwc_otg_module_params.ulpi_fs_ls != -1) {
  82045. + retval +=
  82046. + dwc_otg_set_param_ulpi_fs_ls(core_if,
  82047. + dwc_otg_module_params.ulpi_fs_ls);
  82048. + }
  82049. + if (dwc_otg_module_params.ts_dline != -1) {
  82050. + retval +=
  82051. + dwc_otg_set_param_ts_dline(core_if,
  82052. + dwc_otg_module_params.ts_dline);
  82053. + }
  82054. + if (dwc_otg_module_params.i2c_enable != -1) {
  82055. + retval +=
  82056. + dwc_otg_set_param_i2c_enable(core_if,
  82057. + dwc_otg_module_params.
  82058. + i2c_enable);
  82059. + }
  82060. + if (dwc_otg_module_params.en_multiple_tx_fifo != -1) {
  82061. + retval +=
  82062. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  82063. + dwc_otg_module_params.
  82064. + en_multiple_tx_fifo);
  82065. + }
  82066. + for (i = 0; i < 15; i++) {
  82067. + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
  82068. + retval +=
  82069. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  82070. + dwc_otg_module_params.
  82071. + dev_perio_tx_fifo_size
  82072. + [i], i);
  82073. + }
  82074. + }
  82075. +
  82076. + for (i = 0; i < 15; i++) {
  82077. + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
  82078. + retval += dwc_otg_set_param_dev_tx_fifo_size(core_if,
  82079. + dwc_otg_module_params.
  82080. + dev_tx_fifo_size
  82081. + [i], i);
  82082. + }
  82083. + }
  82084. + if (dwc_otg_module_params.thr_ctl != -1) {
  82085. + retval +=
  82086. + dwc_otg_set_param_thr_ctl(core_if,
  82087. + dwc_otg_module_params.thr_ctl);
  82088. + }
  82089. + if (dwc_otg_module_params.mpi_enable != -1) {
  82090. + retval +=
  82091. + dwc_otg_set_param_mpi_enable(core_if,
  82092. + dwc_otg_module_params.
  82093. + mpi_enable);
  82094. + }
  82095. + if (dwc_otg_module_params.pti_enable != -1) {
  82096. + retval +=
  82097. + dwc_otg_set_param_pti_enable(core_if,
  82098. + dwc_otg_module_params.
  82099. + pti_enable);
  82100. + }
  82101. + if (dwc_otg_module_params.lpm_enable != -1) {
  82102. + retval +=
  82103. + dwc_otg_set_param_lpm_enable(core_if,
  82104. + dwc_otg_module_params.
  82105. + lpm_enable);
  82106. + }
  82107. + if (dwc_otg_module_params.ic_usb_cap != -1) {
  82108. + retval +=
  82109. + dwc_otg_set_param_ic_usb_cap(core_if,
  82110. + dwc_otg_module_params.
  82111. + ic_usb_cap);
  82112. + }
  82113. + if (dwc_otg_module_params.tx_thr_length != -1) {
  82114. + retval +=
  82115. + dwc_otg_set_param_tx_thr_length(core_if,
  82116. + dwc_otg_module_params.tx_thr_length);
  82117. + }
  82118. + if (dwc_otg_module_params.rx_thr_length != -1) {
  82119. + retval +=
  82120. + dwc_otg_set_param_rx_thr_length(core_if,
  82121. + dwc_otg_module_params.
  82122. + rx_thr_length);
  82123. + }
  82124. + if (dwc_otg_module_params.ahb_thr_ratio != -1) {
  82125. + retval +=
  82126. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  82127. + dwc_otg_module_params.ahb_thr_ratio);
  82128. + }
  82129. + if (dwc_otg_module_params.power_down != -1) {
  82130. + retval +=
  82131. + dwc_otg_set_param_power_down(core_if,
  82132. + dwc_otg_module_params.power_down);
  82133. + }
  82134. + if (dwc_otg_module_params.reload_ctl != -1) {
  82135. + retval +=
  82136. + dwc_otg_set_param_reload_ctl(core_if,
  82137. + dwc_otg_module_params.reload_ctl);
  82138. + }
  82139. +
  82140. + if (dwc_otg_module_params.dev_out_nak != -1) {
  82141. + retval +=
  82142. + dwc_otg_set_param_dev_out_nak(core_if,
  82143. + dwc_otg_module_params.dev_out_nak);
  82144. + }
  82145. +
  82146. + if (dwc_otg_module_params.cont_on_bna != -1) {
  82147. + retval +=
  82148. + dwc_otg_set_param_cont_on_bna(core_if,
  82149. + dwc_otg_module_params.cont_on_bna);
  82150. + }
  82151. +
  82152. + if (dwc_otg_module_params.ahb_single != -1) {
  82153. + retval +=
  82154. + dwc_otg_set_param_ahb_single(core_if,
  82155. + dwc_otg_module_params.ahb_single);
  82156. + }
  82157. +
  82158. + if (dwc_otg_module_params.otg_ver != -1) {
  82159. + retval +=
  82160. + dwc_otg_set_param_otg_ver(core_if,
  82161. + dwc_otg_module_params.otg_ver);
  82162. + }
  82163. + if (dwc_otg_module_params.adp_enable != -1) {
  82164. + retval +=
  82165. + dwc_otg_set_param_adp_enable(core_if,
  82166. + dwc_otg_module_params.
  82167. + adp_enable);
  82168. + }
  82169. + return retval;
  82170. +}
  82171. +
  82172. +/**
  82173. + * This function is the top level interrupt handler for the Common
  82174. + * (Device and host modes) interrupts.
  82175. + */
  82176. +static irqreturn_t dwc_otg_common_irq(int irq, void *dev)
  82177. +{
  82178. + int32_t retval = IRQ_NONE;
  82179. +
  82180. + retval = dwc_otg_handle_common_intr(dev);
  82181. + if (retval != 0) {
  82182. + S3C2410X_CLEAR_EINTPEND();
  82183. + }
  82184. + return IRQ_RETVAL(retval);
  82185. +}
  82186. +
  82187. +/**
  82188. + * This function is called when a lm_device is unregistered with the
  82189. + * dwc_otg_driver. This happens, for example, when the rmmod command is
  82190. + * executed. The device may or may not be electrically present. If it is
  82191. + * present, the driver stops device processing. Any resources used on behalf
  82192. + * of this device are freed.
  82193. + *
  82194. + * @param _dev
  82195. + */
  82196. +#ifdef LM_INTERFACE
  82197. +#define REM_RETVAL(n)
  82198. +static void dwc_otg_driver_remove( struct lm_device *_dev )
  82199. +{ dwc_otg_device_t *otg_dev = lm_get_drvdata(_dev);
  82200. +#elif defined(PCI_INTERFACE)
  82201. +#define REM_RETVAL(n)
  82202. +static void dwc_otg_driver_remove( struct pci_dev *_dev )
  82203. +{ dwc_otg_device_t *otg_dev = pci_get_drvdata(_dev);
  82204. +#elif defined(PLATFORM_INTERFACE)
  82205. +#define REM_RETVAL(n) n
  82206. +static int dwc_otg_driver_remove( struct platform_device *_dev )
  82207. +{ dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
  82208. +#endif
  82209. +
  82210. + DWC_DEBUGPL(DBG_ANY, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  82211. +
  82212. + if (!otg_dev) {
  82213. + /* Memory allocation for the dwc_otg_device failed. */
  82214. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  82215. + return REM_RETVAL(-ENOMEM);
  82216. + }
  82217. +#ifndef DWC_DEVICE_ONLY
  82218. + if (otg_dev->hcd) {
  82219. + hcd_remove(_dev);
  82220. + } else {
  82221. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  82222. + return REM_RETVAL(-EINVAL);
  82223. + }
  82224. +#endif
  82225. +
  82226. +#ifndef DWC_HOST_ONLY
  82227. + if (otg_dev->pcd) {
  82228. + pcd_remove(_dev);
  82229. + } else {
  82230. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->pcd NULL!\n", __func__);
  82231. + return REM_RETVAL(-EINVAL);
  82232. + }
  82233. +#endif
  82234. + /*
  82235. + * Free the IRQ
  82236. + */
  82237. + if (otg_dev->common_irq_installed) {
  82238. +#ifdef PLATFORM_INTERFACE
  82239. + free_irq(platform_get_irq(_dev, 0), otg_dev);
  82240. +#else
  82241. + free_irq(_dev->irq, otg_dev);
  82242. +#endif
  82243. + } else {
  82244. + DWC_DEBUGPL(DBG_ANY, "%s: There is no installed irq!\n", __func__);
  82245. + return REM_RETVAL(-ENXIO);
  82246. + }
  82247. +
  82248. + if (otg_dev->core_if) {
  82249. + dwc_otg_cil_remove(otg_dev->core_if);
  82250. + } else {
  82251. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->core_if NULL!\n", __func__);
  82252. + return REM_RETVAL(-ENXIO);
  82253. + }
  82254. +
  82255. + /*
  82256. + * Remove the device attributes
  82257. + */
  82258. + dwc_otg_attr_remove(_dev);
  82259. +
  82260. + /*
  82261. + * Return the memory.
  82262. + */
  82263. + if (otg_dev->os_dep.base) {
  82264. + iounmap(otg_dev->os_dep.base);
  82265. + }
  82266. + DWC_FREE(otg_dev);
  82267. +
  82268. + /*
  82269. + * Clear the drvdata pointer.
  82270. + */
  82271. +#ifdef LM_INTERFACE
  82272. + lm_set_drvdata(_dev, 0);
  82273. +#elif defined(PCI_INTERFACE)
  82274. + release_mem_region(otg_dev->os_dep.rsrc_start,
  82275. + otg_dev->os_dep.rsrc_len);
  82276. + pci_set_drvdata(_dev, 0);
  82277. +#elif defined(PLATFORM_INTERFACE)
  82278. + platform_set_drvdata(_dev, 0);
  82279. +#endif
  82280. + return REM_RETVAL(0);
  82281. +}
  82282. +
  82283. +/**
  82284. + * This function is called when an lm_device is bound to a
  82285. + * dwc_otg_driver. It creates the driver components required to
  82286. + * control the device (CIL, HCD, and PCD) and it initializes the
  82287. + * device. The driver components are stored in a dwc_otg_device
  82288. + * structure. A reference to the dwc_otg_device is saved in the
  82289. + * lm_device. This allows the driver to access the dwc_otg_device
  82290. + * structure on subsequent calls to driver methods for this device.
  82291. + *
  82292. + * @param _dev Bus device
  82293. + */
  82294. +static int dwc_otg_driver_probe(
  82295. +#ifdef LM_INTERFACE
  82296. + struct lm_device *_dev
  82297. +#elif defined(PCI_INTERFACE)
  82298. + struct pci_dev *_dev,
  82299. + const struct pci_device_id *id
  82300. +#elif defined(PLATFORM_INTERFACE)
  82301. + struct platform_device *_dev
  82302. +#endif
  82303. + )
  82304. +{
  82305. + int retval = 0;
  82306. + dwc_otg_device_t *dwc_otg_device;
  82307. + int devirq;
  82308. +
  82309. + dev_dbg(&_dev->dev, "dwc_otg_driver_probe(%p)\n", _dev);
  82310. +#ifdef LM_INTERFACE
  82311. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)_dev->resource.start);
  82312. +#elif defined(PCI_INTERFACE)
  82313. + if (!id) {
  82314. + DWC_ERROR("Invalid pci_device_id %p", id);
  82315. + return -EINVAL;
  82316. + }
  82317. +
  82318. + if (!_dev || (pci_enable_device(_dev) < 0)) {
  82319. + DWC_ERROR("Invalid pci_device %p", _dev);
  82320. + return -ENODEV;
  82321. + }
  82322. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)pci_resource_start(_dev,0));
  82323. + /* other stuff needed as well? */
  82324. +
  82325. +#elif defined(PLATFORM_INTERFACE)
  82326. + dev_dbg(&_dev->dev, "start=0x%08x (len 0x%x)\n",
  82327. + (unsigned)_dev->resource->start,
  82328. + (unsigned)(_dev->resource->end - _dev->resource->start));
  82329. +#endif
  82330. +
  82331. + dwc_otg_device = DWC_ALLOC(sizeof(dwc_otg_device_t));
  82332. +
  82333. + if (!dwc_otg_device) {
  82334. + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
  82335. + return -ENOMEM;
  82336. + }
  82337. +
  82338. + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
  82339. + dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
  82340. +
  82341. + /*
  82342. + * Map the DWC_otg Core memory into virtual address space.
  82343. + */
  82344. +#ifdef LM_INTERFACE
  82345. + dwc_otg_device->os_dep.base = ioremap(_dev->resource.start, SZ_256K);
  82346. +
  82347. + if (!dwc_otg_device->os_dep.base) {
  82348. + dev_err(&_dev->dev, "ioremap() failed\n");
  82349. + DWC_FREE(dwc_otg_device);
  82350. + return -ENOMEM;
  82351. + }
  82352. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  82353. + (unsigned)dwc_otg_device->os_dep.base);
  82354. +#elif defined(PCI_INTERFACE)
  82355. + _dev->current_state = PCI_D0;
  82356. + _dev->dev.power.power_state = PMSG_ON;
  82357. +
  82358. + if (!_dev->irq) {
  82359. + DWC_ERROR("Found HC with no IRQ. Check BIOS/PCI %s setup!",
  82360. + pci_name(_dev));
  82361. + iounmap(dwc_otg_device->os_dep.base);
  82362. + DWC_FREE(dwc_otg_device);
  82363. + return -ENODEV;
  82364. + }
  82365. +
  82366. + dwc_otg_device->os_dep.rsrc_start = pci_resource_start(_dev, 0);
  82367. + dwc_otg_device->os_dep.rsrc_len = pci_resource_len(_dev, 0);
  82368. + DWC_DEBUGPL(DBG_ANY, "PCI resource: start=%08x, len=%08x\n",
  82369. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  82370. + (unsigned)dwc_otg_device->os_dep.rsrc_len);
  82371. + if (!request_mem_region
  82372. + (dwc_otg_device->os_dep.rsrc_start, dwc_otg_device->os_dep.rsrc_len,
  82373. + "dwc_otg")) {
  82374. + dev_dbg(&_dev->dev, "error requesting memory\n");
  82375. + iounmap(dwc_otg_device->os_dep.base);
  82376. + DWC_FREE(dwc_otg_device);
  82377. + return -EFAULT;
  82378. + }
  82379. +
  82380. + dwc_otg_device->os_dep.base =
  82381. + ioremap_nocache(dwc_otg_device->os_dep.rsrc_start,
  82382. + dwc_otg_device->os_dep.rsrc_len);
  82383. + if (dwc_otg_device->os_dep.base == NULL) {
  82384. + dev_dbg(&_dev->dev, "error mapping memory\n");
  82385. + release_mem_region(dwc_otg_device->os_dep.rsrc_start,
  82386. + dwc_otg_device->os_dep.rsrc_len);
  82387. + iounmap(dwc_otg_device->os_dep.base);
  82388. + DWC_FREE(dwc_otg_device);
  82389. + return -EFAULT;
  82390. + }
  82391. + dev_dbg(&_dev->dev, "base=0x%p (before adjust) \n",
  82392. + dwc_otg_device->os_dep.base);
  82393. + dwc_otg_device->os_dep.base = (char *)dwc_otg_device->os_dep.base;
  82394. + dev_dbg(&_dev->dev, "base=0x%p (after adjust) \n",
  82395. + dwc_otg_device->os_dep.base);
  82396. + dev_dbg(&_dev->dev, "%s: mapped PA 0x%x to VA 0x%p\n", __func__,
  82397. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  82398. + dwc_otg_device->os_dep.base);
  82399. +
  82400. + pci_set_master(_dev);
  82401. + pci_set_drvdata(_dev, dwc_otg_device);
  82402. +#elif defined(PLATFORM_INTERFACE)
  82403. + DWC_DEBUGPL(DBG_ANY,"Platform resource: start=%08x, len=%08x\n",
  82404. + _dev->resource->start,
  82405. + _dev->resource->end - _dev->resource->start + 1);
  82406. +#if 1
  82407. + if (!request_mem_region(_dev->resource[0].start,
  82408. + _dev->resource[0].end - _dev->resource[0].start + 1,
  82409. + "dwc_otg")) {
  82410. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  82411. + retval = -EFAULT;
  82412. + goto fail;
  82413. + }
  82414. +
  82415. + dwc_otg_device->os_dep.base = ioremap_nocache(_dev->resource[0].start,
  82416. + _dev->resource[0].end -
  82417. + _dev->resource[0].start+1);
  82418. + if (fiq_enable)
  82419. + {
  82420. + if (!request_mem_region(_dev->resource[1].start,
  82421. + _dev->resource[1].end - _dev->resource[1].start + 1,
  82422. + "dwc_otg")) {
  82423. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  82424. + retval = -EFAULT;
  82425. + goto fail;
  82426. + }
  82427. +
  82428. + dwc_otg_device->os_dep.mphi_base = ioremap_nocache(_dev->resource[1].start,
  82429. + _dev->resource[1].end -
  82430. + _dev->resource[1].start + 1);
  82431. + }
  82432. +
  82433. +#else
  82434. + {
  82435. + struct map_desc desc = {
  82436. + .virtual = IO_ADDRESS((unsigned)_dev->resource->start),
  82437. + .pfn = __phys_to_pfn((unsigned)_dev->resource->start),
  82438. + .length = SZ_128K,
  82439. + .type = MT_DEVICE
  82440. + };
  82441. + iotable_init(&desc, 1);
  82442. + dwc_otg_device->os_dep.base = (void *)desc.virtual;
  82443. + }
  82444. +#endif
  82445. + if (!dwc_otg_device->os_dep.base) {
  82446. + dev_err(&_dev->dev, "ioremap() failed\n");
  82447. + retval = -ENOMEM;
  82448. + goto fail;
  82449. + }
  82450. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  82451. + (unsigned)dwc_otg_device->os_dep.base);
  82452. +#endif
  82453. +
  82454. + /*
  82455. + * Initialize driver data to point to the global DWC_otg
  82456. + * Device structure.
  82457. + */
  82458. +#ifdef LM_INTERFACE
  82459. + lm_set_drvdata(_dev, dwc_otg_device);
  82460. +#elif defined(PLATFORM_INTERFACE)
  82461. + platform_set_drvdata(_dev, dwc_otg_device);
  82462. +#endif
  82463. + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
  82464. +
  82465. + dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->os_dep.base);
  82466. + DWC_DEBUGPL(DBG_HCDV, "probe of device %p given core_if %p\n",
  82467. + dwc_otg_device, dwc_otg_device->core_if);//GRAYG
  82468. +
  82469. + if (!dwc_otg_device->core_if) {
  82470. + dev_err(&_dev->dev, "CIL initialization failed!\n");
  82471. + retval = -ENOMEM;
  82472. + goto fail;
  82473. + }
  82474. +
  82475. + dev_dbg(&_dev->dev, "Calling get_gsnpsid\n");
  82476. + /*
  82477. + * Attempt to ensure this device is really a DWC_otg Controller.
  82478. + * Read and verify the SNPSID register contents. The value should be
  82479. + * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3",
  82480. + * as in "OTG version 2.XX" or "OTG version 3.XX".
  82481. + */
  82482. +
  82483. + if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F542000) &&
  82484. + ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) {
  82485. + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n",
  82486. + dwc_otg_get_gsnpsid(dwc_otg_device->core_if));
  82487. + retval = -EINVAL;
  82488. + goto fail;
  82489. + }
  82490. +
  82491. + /*
  82492. + * Validate parameter values.
  82493. + */
  82494. + dev_dbg(&_dev->dev, "Calling set_parameters\n");
  82495. + if (set_parameters(dwc_otg_device->core_if)) {
  82496. + retval = -EINVAL;
  82497. + goto fail;
  82498. + }
  82499. +
  82500. + /*
  82501. + * Create Device Attributes in sysfs
  82502. + */
  82503. + dev_dbg(&_dev->dev, "Calling attr_create\n");
  82504. + dwc_otg_attr_create(_dev);
  82505. +
  82506. + /*
  82507. + * Disable the global interrupt until all the interrupt
  82508. + * handlers are installed.
  82509. + */
  82510. + dev_dbg(&_dev->dev, "Calling disable_global_interrupts\n");
  82511. + dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
  82512. +
  82513. + /*
  82514. + * Install the interrupt handler for the common interrupts before
  82515. + * enabling common interrupts in core_init below.
  82516. + */
  82517. +
  82518. +#if defined(PLATFORM_INTERFACE)
  82519. + devirq = platform_get_irq(_dev, fiq_enable ? 0 : 1);
  82520. +#else
  82521. + devirq = _dev->irq;
  82522. +#endif
  82523. + DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
  82524. + devirq);
  82525. + dev_dbg(&_dev->dev, "Calling request_irq(%d)\n", devirq);
  82526. + retval = request_irq(devirq, dwc_otg_common_irq,
  82527. + IRQF_SHARED,
  82528. + "dwc_otg", dwc_otg_device);
  82529. + if (retval) {
  82530. + DWC_ERROR("request of irq%d failed\n", devirq);
  82531. + retval = -EBUSY;
  82532. + goto fail;
  82533. + } else {
  82534. + dwc_otg_device->common_irq_installed = 1;
  82535. + }
  82536. +
  82537. +#ifndef IRQF_TRIGGER_LOW
  82538. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  82539. + dev_dbg(&_dev->dev, "Calling set_irq_type\n");
  82540. + set_irq_type(devirq,
  82541. +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  82542. + IRQT_LOW
  82543. +#else
  82544. + IRQ_TYPE_LEVEL_LOW
  82545. +#endif
  82546. + );
  82547. +#endif
  82548. +#endif /*IRQF_TRIGGER_LOW*/
  82549. +
  82550. + /*
  82551. + * Initialize the DWC_otg core.
  82552. + */
  82553. + dev_dbg(&_dev->dev, "Calling dwc_otg_core_init\n");
  82554. + dwc_otg_core_init(dwc_otg_device->core_if);
  82555. +
  82556. +#ifndef DWC_HOST_ONLY
  82557. + /*
  82558. + * Initialize the PCD
  82559. + */
  82560. + dev_dbg(&_dev->dev, "Calling pcd_init\n");
  82561. + retval = pcd_init(_dev);
  82562. + if (retval != 0) {
  82563. + DWC_ERROR("pcd_init failed\n");
  82564. + dwc_otg_device->pcd = NULL;
  82565. + goto fail;
  82566. + }
  82567. +#endif
  82568. +#ifndef DWC_DEVICE_ONLY
  82569. + /*
  82570. + * Initialize the HCD
  82571. + */
  82572. + dev_dbg(&_dev->dev, "Calling hcd_init\n");
  82573. + retval = hcd_init(_dev);
  82574. + if (retval != 0) {
  82575. + DWC_ERROR("hcd_init failed\n");
  82576. + dwc_otg_device->hcd = NULL;
  82577. + goto fail;
  82578. + }
  82579. +#endif
  82580. + /* Recover from drvdata having been overwritten by hcd_init() */
  82581. +#ifdef LM_INTERFACE
  82582. + lm_set_drvdata(_dev, dwc_otg_device);
  82583. +#elif defined(PLATFORM_INTERFACE)
  82584. + platform_set_drvdata(_dev, dwc_otg_device);
  82585. +#elif defined(PCI_INTERFACE)
  82586. + pci_set_drvdata(_dev, dwc_otg_device);
  82587. + dwc_otg_device->os_dep.pcidev = _dev;
  82588. +#endif
  82589. +
  82590. + /*
  82591. + * Enable the global interrupt after all the interrupt
  82592. + * handlers are installed if there is no ADP support else
  82593. + * perform initial actions required for Internal ADP logic.
  82594. + */
  82595. + if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if)) {
  82596. + dev_dbg(&_dev->dev, "Calling enable_global_interrupts\n");
  82597. + dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
  82598. + dev_dbg(&_dev->dev, "Done\n");
  82599. + } else
  82600. + dwc_otg_adp_start(dwc_otg_device->core_if,
  82601. + dwc_otg_is_host_mode(dwc_otg_device->core_if));
  82602. +
  82603. + return 0;
  82604. +
  82605. +fail:
  82606. + dwc_otg_driver_remove(_dev);
  82607. + return retval;
  82608. +}
  82609. +
  82610. +/**
  82611. + * This structure defines the methods to be called by a bus driver
  82612. + * during the lifecycle of a device on that bus. Both drivers and
  82613. + * devices are registered with a bus driver. The bus driver matches
  82614. + * devices to drivers based on information in the device and driver
  82615. + * structures.
  82616. + *
  82617. + * The probe function is called when the bus driver matches a device
  82618. + * to this driver. The remove function is called when a device is
  82619. + * unregistered with the bus driver.
  82620. + */
  82621. +#ifdef LM_INTERFACE
  82622. +static struct lm_driver dwc_otg_driver = {
  82623. + .drv = {.name = (char *)dwc_driver_name,},
  82624. + .probe = dwc_otg_driver_probe,
  82625. + .remove = dwc_otg_driver_remove,
  82626. + // 'suspend' and 'resume' absent
  82627. +};
  82628. +#elif defined(PCI_INTERFACE)
  82629. +static const struct pci_device_id pci_ids[] = { {
  82630. + PCI_DEVICE(0x16c3, 0xabcd),
  82631. + .driver_data =
  82632. + (unsigned long)0xdeadbeef,
  82633. + }, { /* end: all zeroes */ }
  82634. +};
  82635. +
  82636. +MODULE_DEVICE_TABLE(pci, pci_ids);
  82637. +
  82638. +/* pci driver glue; this is a "new style" PCI driver module */
  82639. +static struct pci_driver dwc_otg_driver = {
  82640. + .name = "dwc_otg",
  82641. + .id_table = pci_ids,
  82642. +
  82643. + .probe = dwc_otg_driver_probe,
  82644. + .remove = dwc_otg_driver_remove,
  82645. +
  82646. + .driver = {
  82647. + .name = (char *)dwc_driver_name,
  82648. + },
  82649. +};
  82650. +#elif defined(PLATFORM_INTERFACE)
  82651. +static struct platform_device_id platform_ids[] = {
  82652. + {
  82653. + .name = "bcm2708_usb",
  82654. + .driver_data = (kernel_ulong_t) 0xdeadbeef,
  82655. + },
  82656. + { /* end: all zeroes */ }
  82657. +};
  82658. +MODULE_DEVICE_TABLE(platform, platform_ids);
  82659. +
  82660. +static struct platform_driver dwc_otg_driver = {
  82661. + .driver = {
  82662. + .name = (char *)dwc_driver_name,
  82663. + },
  82664. + .id_table = platform_ids,
  82665. +
  82666. + .probe = dwc_otg_driver_probe,
  82667. + .remove = dwc_otg_driver_remove,
  82668. + // no 'shutdown', 'suspend', 'resume', 'suspend_late' or 'resume_early'
  82669. +};
  82670. +#endif
  82671. +
  82672. +/**
  82673. + * This function is called when the dwc_otg_driver is installed with the
  82674. + * insmod command. It registers the dwc_otg_driver structure with the
  82675. + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
  82676. + * to be called. In addition, the bus driver will automatically expose
  82677. + * attributes defined for the device and driver in the special sysfs file
  82678. + * system.
  82679. + *
  82680. + * @return
  82681. + */
  82682. +static int __init dwc_otg_driver_init(void)
  82683. +{
  82684. + int retval = 0;
  82685. + int error;
  82686. + struct device_driver *drv;
  82687. +
  82688. + if(fiq_fsm_enable && !fiq_enable) {
  82689. + printk(KERN_WARNING "dwc_otg: fiq_fsm_enable was set without fiq_enable! Correcting.\n");
  82690. + fiq_enable = 1;
  82691. + }
  82692. +
  82693. + printk(KERN_INFO "%s: version %s (%s bus)\n", dwc_driver_name,
  82694. + DWC_DRIVER_VERSION,
  82695. +#ifdef LM_INTERFACE
  82696. + "logicmodule");
  82697. + retval = lm_driver_register(&dwc_otg_driver);
  82698. + drv = &dwc_otg_driver.drv;
  82699. +#elif defined(PCI_INTERFACE)
  82700. + "pci");
  82701. + retval = pci_register_driver(&dwc_otg_driver);
  82702. + drv = &dwc_otg_driver.driver;
  82703. +#elif defined(PLATFORM_INTERFACE)
  82704. + "platform");
  82705. + retval = platform_driver_register(&dwc_otg_driver);
  82706. + drv = &dwc_otg_driver.driver;
  82707. +#endif
  82708. + if (retval < 0) {
  82709. + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
  82710. + return retval;
  82711. + }
  82712. + printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_enable ? "enabled":"disabled");
  82713. + printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff ? "enabled":"disabled");
  82714. + printk(KERN_DEBUG "dwc_otg: FIQ split-transaction FSM %s\n", fiq_fsm_enable ? "enabled":"disabled");
  82715. +
  82716. + error = driver_create_file(drv, &driver_attr_version);
  82717. +#ifdef DEBUG
  82718. + error = driver_create_file(drv, &driver_attr_debuglevel);
  82719. +#endif
  82720. + return retval;
  82721. +}
  82722. +
  82723. +module_init(dwc_otg_driver_init);
  82724. +
  82725. +/**
  82726. + * This function is called when the driver is removed from the kernel
  82727. + * with the rmmod command. The driver unregisters itself with its bus
  82728. + * driver.
  82729. + *
  82730. + */
  82731. +static void __exit dwc_otg_driver_cleanup(void)
  82732. +{
  82733. + printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
  82734. +
  82735. +#ifdef LM_INTERFACE
  82736. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_debuglevel);
  82737. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_version);
  82738. + lm_driver_unregister(&dwc_otg_driver);
  82739. +#elif defined(PCI_INTERFACE)
  82740. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  82741. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  82742. + pci_unregister_driver(&dwc_otg_driver);
  82743. +#elif defined(PLATFORM_INTERFACE)
  82744. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  82745. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  82746. + platform_driver_unregister(&dwc_otg_driver);
  82747. +#endif
  82748. +
  82749. + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
  82750. +}
  82751. +
  82752. +module_exit(dwc_otg_driver_cleanup);
  82753. +
  82754. +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
  82755. +MODULE_AUTHOR("Synopsys Inc.");
  82756. +MODULE_LICENSE("GPL");
  82757. +
  82758. +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
  82759. +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
  82760. +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
  82761. +MODULE_PARM_DESC(opt, "OPT Mode");
  82762. +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
  82763. +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
  82764. +
  82765. +module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int,
  82766. + 0444);
  82767. +MODULE_PARM_DESC(dma_desc_enable,
  82768. + "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
  82769. +
  82770. +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int,
  82771. + 0444);
  82772. +MODULE_PARM_DESC(dma_burst_size,
  82773. + "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
  82774. +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
  82775. +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
  82776. +module_param_named(host_support_fs_ls_low_power,
  82777. + dwc_otg_module_params.host_support_fs_ls_low_power, int,
  82778. + 0444);
  82779. +MODULE_PARM_DESC(host_support_fs_ls_low_power,
  82780. + "Support Low Power w/FS or LS 0=Support 1=Don't Support");
  82781. +module_param_named(host_ls_low_power_phy_clk,
  82782. + dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
  82783. +MODULE_PARM_DESC(host_ls_low_power_phy_clk,
  82784. + "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
  82785. +module_param_named(enable_dynamic_fifo,
  82786. + dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
  82787. +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
  82788. +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int,
  82789. + 0444);
  82790. +MODULE_PARM_DESC(data_fifo_size,
  82791. + "Total number of words in the data FIFO memory 32-32768");
  82792. +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size,
  82793. + int, 0444);
  82794. +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  82795. +module_param_named(dev_nperio_tx_fifo_size,
  82796. + dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
  82797. +MODULE_PARM_DESC(dev_nperio_tx_fifo_size,
  82798. + "Number of words in the non-periodic Tx FIFO 16-32768");
  82799. +module_param_named(dev_perio_tx_fifo_size_1,
  82800. + dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
  82801. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1,
  82802. + "Number of words in the periodic Tx FIFO 4-768");
  82803. +module_param_named(dev_perio_tx_fifo_size_2,
  82804. + dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
  82805. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2,
  82806. + "Number of words in the periodic Tx FIFO 4-768");
  82807. +module_param_named(dev_perio_tx_fifo_size_3,
  82808. + dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
  82809. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3,
  82810. + "Number of words in the periodic Tx FIFO 4-768");
  82811. +module_param_named(dev_perio_tx_fifo_size_4,
  82812. + dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
  82813. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4,
  82814. + "Number of words in the periodic Tx FIFO 4-768");
  82815. +module_param_named(dev_perio_tx_fifo_size_5,
  82816. + dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
  82817. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5,
  82818. + "Number of words in the periodic Tx FIFO 4-768");
  82819. +module_param_named(dev_perio_tx_fifo_size_6,
  82820. + dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
  82821. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6,
  82822. + "Number of words in the periodic Tx FIFO 4-768");
  82823. +module_param_named(dev_perio_tx_fifo_size_7,
  82824. + dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
  82825. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7,
  82826. + "Number of words in the periodic Tx FIFO 4-768");
  82827. +module_param_named(dev_perio_tx_fifo_size_8,
  82828. + dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
  82829. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8,
  82830. + "Number of words in the periodic Tx FIFO 4-768");
  82831. +module_param_named(dev_perio_tx_fifo_size_9,
  82832. + dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
  82833. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9,
  82834. + "Number of words in the periodic Tx FIFO 4-768");
  82835. +module_param_named(dev_perio_tx_fifo_size_10,
  82836. + dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
  82837. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10,
  82838. + "Number of words in the periodic Tx FIFO 4-768");
  82839. +module_param_named(dev_perio_tx_fifo_size_11,
  82840. + dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
  82841. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11,
  82842. + "Number of words in the periodic Tx FIFO 4-768");
  82843. +module_param_named(dev_perio_tx_fifo_size_12,
  82844. + dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
  82845. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12,
  82846. + "Number of words in the periodic Tx FIFO 4-768");
  82847. +module_param_named(dev_perio_tx_fifo_size_13,
  82848. + dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
  82849. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13,
  82850. + "Number of words in the periodic Tx FIFO 4-768");
  82851. +module_param_named(dev_perio_tx_fifo_size_14,
  82852. + dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
  82853. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14,
  82854. + "Number of words in the periodic Tx FIFO 4-768");
  82855. +module_param_named(dev_perio_tx_fifo_size_15,
  82856. + dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
  82857. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15,
  82858. + "Number of words in the periodic Tx FIFO 4-768");
  82859. +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size,
  82860. + int, 0444);
  82861. +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  82862. +module_param_named(host_nperio_tx_fifo_size,
  82863. + dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
  82864. +MODULE_PARM_DESC(host_nperio_tx_fifo_size,
  82865. + "Number of words in the non-periodic Tx FIFO 16-32768");
  82866. +module_param_named(host_perio_tx_fifo_size,
  82867. + dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
  82868. +MODULE_PARM_DESC(host_perio_tx_fifo_size,
  82869. + "Number of words in the host periodic Tx FIFO 16-32768");
  82870. +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size,
  82871. + int, 0444);
  82872. +/** @todo Set the max to 512K, modify checks */
  82873. +MODULE_PARM_DESC(max_transfer_size,
  82874. + "The maximum transfer size supported in bytes 2047-65535");
  82875. +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count,
  82876. + int, 0444);
  82877. +MODULE_PARM_DESC(max_packet_count,
  82878. + "The maximum number of packets in a transfer 15-511");
  82879. +module_param_named(host_channels, dwc_otg_module_params.host_channels, int,
  82880. + 0444);
  82881. +MODULE_PARM_DESC(host_channels,
  82882. + "The number of host channel registers to use 1-16");
  82883. +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int,
  82884. + 0444);
  82885. +MODULE_PARM_DESC(dev_endpoints,
  82886. + "The number of endpoints in addition to EP0 available for device mode 1-15");
  82887. +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
  82888. +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
  82889. +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int,
  82890. + 0444);
  82891. +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
  82892. +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
  82893. +MODULE_PARM_DESC(phy_ulpi_ddr,
  82894. + "ULPI at double or single data rate 0=Single 1=Double");
  82895. +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus,
  82896. + int, 0444);
  82897. +MODULE_PARM_DESC(phy_ulpi_ext_vbus,
  82898. + "ULPI PHY using internal or external vbus 0=Internal");
  82899. +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
  82900. +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
  82901. +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
  82902. +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
  82903. +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
  82904. +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
  82905. +module_param_named(debug, g_dbg_lvl, int, 0444);
  82906. +MODULE_PARM_DESC(debug, "");
  82907. +
  82908. +module_param_named(en_multiple_tx_fifo,
  82909. + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
  82910. +MODULE_PARM_DESC(en_multiple_tx_fifo,
  82911. + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
  82912. +module_param_named(dev_tx_fifo_size_1,
  82913. + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
  82914. +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
  82915. +module_param_named(dev_tx_fifo_size_2,
  82916. + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
  82917. +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
  82918. +module_param_named(dev_tx_fifo_size_3,
  82919. + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
  82920. +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
  82921. +module_param_named(dev_tx_fifo_size_4,
  82922. + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
  82923. +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
  82924. +module_param_named(dev_tx_fifo_size_5,
  82925. + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
  82926. +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
  82927. +module_param_named(dev_tx_fifo_size_6,
  82928. + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
  82929. +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
  82930. +module_param_named(dev_tx_fifo_size_7,
  82931. + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
  82932. +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
  82933. +module_param_named(dev_tx_fifo_size_8,
  82934. + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
  82935. +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
  82936. +module_param_named(dev_tx_fifo_size_9,
  82937. + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
  82938. +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
  82939. +module_param_named(dev_tx_fifo_size_10,
  82940. + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
  82941. +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
  82942. +module_param_named(dev_tx_fifo_size_11,
  82943. + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
  82944. +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
  82945. +module_param_named(dev_tx_fifo_size_12,
  82946. + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
  82947. +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
  82948. +module_param_named(dev_tx_fifo_size_13,
  82949. + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
  82950. +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
  82951. +module_param_named(dev_tx_fifo_size_14,
  82952. + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
  82953. +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
  82954. +module_param_named(dev_tx_fifo_size_15,
  82955. + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
  82956. +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
  82957. +
  82958. +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
  82959. +MODULE_PARM_DESC(thr_ctl,
  82960. + "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
  82961. +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int,
  82962. + 0444);
  82963. +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
  82964. +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int,
  82965. + 0444);
  82966. +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
  82967. +
  82968. +module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
  82969. +module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
  82970. +module_param_named(lpm_enable, dwc_otg_module_params.lpm_enable, int, 0444);
  82971. +MODULE_PARM_DESC(lpm_enable, "LPM Enable 0=LPM Disabled 1=LPM Enabled");
  82972. +module_param_named(ic_usb_cap, dwc_otg_module_params.ic_usb_cap, int, 0444);
  82973. +MODULE_PARM_DESC(ic_usb_cap,
  82974. + "IC_USB Capability 0=IC_USB Disabled 1=IC_USB Enabled");
  82975. +module_param_named(ahb_thr_ratio, dwc_otg_module_params.ahb_thr_ratio, int,
  82976. + 0444);
  82977. +MODULE_PARM_DESC(ahb_thr_ratio, "AHB Threshold Ratio");
  82978. +module_param_named(power_down, dwc_otg_module_params.power_down, int, 0444);
  82979. +MODULE_PARM_DESC(power_down, "Power Down Mode");
  82980. +module_param_named(reload_ctl, dwc_otg_module_params.reload_ctl, int, 0444);
  82981. +MODULE_PARM_DESC(reload_ctl, "HFIR Reload Control");
  82982. +module_param_named(dev_out_nak, dwc_otg_module_params.dev_out_nak, int, 0444);
  82983. +MODULE_PARM_DESC(dev_out_nak, "Enable Device OUT NAK");
  82984. +module_param_named(cont_on_bna, dwc_otg_module_params.cont_on_bna, int, 0444);
  82985. +MODULE_PARM_DESC(cont_on_bna, "Enable Enable Continue on BNA");
  82986. +module_param_named(ahb_single, dwc_otg_module_params.ahb_single, int, 0444);
  82987. +MODULE_PARM_DESC(ahb_single, "Enable AHB Single Support");
  82988. +module_param_named(adp_enable, dwc_otg_module_params.adp_enable, int, 0444);
  82989. +MODULE_PARM_DESC(adp_enable, "ADP Enable 0=ADP Disabled 1=ADP Enabled");
  82990. +module_param_named(otg_ver, dwc_otg_module_params.otg_ver, int, 0444);
  82991. +MODULE_PARM_DESC(otg_ver, "OTG revision supported 0=OTG 1.3 1=OTG 2.0");
  82992. +module_param(microframe_schedule, bool, 0444);
  82993. +MODULE_PARM_DESC(microframe_schedule, "Enable the microframe scheduler");
  82994. +
  82995. +module_param(fiq_enable, bool, 0444);
  82996. +MODULE_PARM_DESC(fiq_enable, "Enable the FIQ");
  82997. +module_param(nak_holdoff, ushort, 0644);
  82998. +MODULE_PARM_DESC(nak_holdoff, "Throttle duration for bulk split-transaction endpoints on a NAK. Default 8");
  82999. +module_param(fiq_fsm_enable, bool, 0444);
  83000. +MODULE_PARM_DESC(fiq_fsm_enable, "Enable the FIQ to perform split transactions as defined by fiq_fsm_mask");
  83001. +module_param(fiq_fsm_mask, ushort, 0444);
  83002. +MODULE_PARM_DESC(fiq_fsm_mask, "Bitmask of transactions to perform in the FIQ.\n"
  83003. + "Bit 0 : Non-periodic split transactions\n"
  83004. + "Bit 1 : Periodic split transactions\n"
  83005. + "Bit 2 : High-speed multi-transfer isochronous\n"
  83006. + "All other bits should be set 0.");
  83007. +
  83008. +
  83009. +/** @page "Module Parameters"
  83010. + *
  83011. + * The following parameters may be specified when starting the module.
  83012. + * These parameters define how the DWC_otg controller should be
  83013. + * configured. Parameter values are passed to the CIL initialization
  83014. + * function dwc_otg_cil_init
  83015. + *
  83016. + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
  83017. + *
  83018. +
  83019. + <table>
  83020. + <tr><td>Parameter Name</td><td>Meaning</td></tr>
  83021. +
  83022. + <tr>
  83023. + <td>otg_cap</td>
  83024. + <td>Specifies the OTG capabilities. The driver will automatically detect the
  83025. + value for this parameter if none is specified.
  83026. + - 0: HNP and SRP capable (default, if available)
  83027. + - 1: SRP Only capable
  83028. + - 2: No HNP/SRP capable
  83029. + </td></tr>
  83030. +
  83031. + <tr>
  83032. + <td>dma_enable</td>
  83033. + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
  83034. + The driver will automatically detect the value for this parameter if none is
  83035. + specified.
  83036. + - 0: Slave
  83037. + - 1: DMA (default, if available)
  83038. + </td></tr>
  83039. +
  83040. + <tr>
  83041. + <td>dma_burst_size</td>
  83042. + <td>The DMA Burst size (applicable only for External DMA Mode).
  83043. + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  83044. + </td></tr>
  83045. +
  83046. + <tr>
  83047. + <td>speed</td>
  83048. + <td>Specifies the maximum speed of operation in host and device mode. The
  83049. + actual speed depends on the speed of the attached device and the value of
  83050. + phy_type.
  83051. + - 0: High Speed (default)
  83052. + - 1: Full Speed
  83053. + </td></tr>
  83054. +
  83055. + <tr>
  83056. + <td>host_support_fs_ls_low_power</td>
  83057. + <td>Specifies whether low power mode is supported when attached to a Full
  83058. + Speed or Low Speed device in host mode.
  83059. + - 0: Don't support low power mode (default)
  83060. + - 1: Support low power mode
  83061. + </td></tr>
  83062. +
  83063. + <tr>
  83064. + <td>host_ls_low_power_phy_clk</td>
  83065. + <td>Specifies the PHY clock rate in low power mode when connected to a Low
  83066. + Speed device in host mode. This parameter is applicable only if
  83067. + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
  83068. + - 0: 48 MHz (default)
  83069. + - 1: 6 MHz
  83070. + </td></tr>
  83071. +
  83072. + <tr>
  83073. + <td>enable_dynamic_fifo</td>
  83074. + <td> Specifies whether FIFOs may be resized by the driver software.
  83075. + - 0: Use cC FIFO size parameters
  83076. + - 1: Allow dynamic FIFO sizing (default)
  83077. + </td></tr>
  83078. +
  83079. + <tr>
  83080. + <td>data_fifo_size</td>
  83081. + <td>Total number of 4-byte words in the data FIFO memory. This memory
  83082. + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
  83083. + - Values: 32 to 32768 (default 8192)
  83084. +
  83085. + Note: The total FIFO memory depth in the FPGA configuration is 8192.
  83086. + </td></tr>
  83087. +
  83088. + <tr>
  83089. + <td>dev_rx_fifo_size</td>
  83090. + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
  83091. + FIFO sizing is enabled.
  83092. + - Values: 16 to 32768 (default 1064)
  83093. + </td></tr>
  83094. +
  83095. + <tr>
  83096. + <td>dev_nperio_tx_fifo_size</td>
  83097. + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
  83098. + dynamic FIFO sizing is enabled.
  83099. + - Values: 16 to 32768 (default 1024)
  83100. + </td></tr>
  83101. +
  83102. + <tr>
  83103. + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
  83104. + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
  83105. + when dynamic FIFO sizing is enabled.
  83106. + - Values: 4 to 768 (default 256)
  83107. + </td></tr>
  83108. +
  83109. + <tr>
  83110. + <td>host_rx_fifo_size</td>
  83111. + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
  83112. + sizing is enabled.
  83113. + - Values: 16 to 32768 (default 1024)
  83114. + </td></tr>
  83115. +
  83116. + <tr>
  83117. + <td>host_nperio_tx_fifo_size</td>
  83118. + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
  83119. + dynamic FIFO sizing is enabled in the core.
  83120. + - Values: 16 to 32768 (default 1024)
  83121. + </td></tr>
  83122. +
  83123. + <tr>
  83124. + <td>host_perio_tx_fifo_size</td>
  83125. + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
  83126. + sizing is enabled.
  83127. + - Values: 16 to 32768 (default 1024)
  83128. + </td></tr>
  83129. +
  83130. + <tr>
  83131. + <td>max_transfer_size</td>
  83132. + <td>The maximum transfer size supported in bytes.
  83133. + - Values: 2047 to 65,535 (default 65,535)
  83134. + </td></tr>
  83135. +
  83136. + <tr>
  83137. + <td>max_packet_count</td>
  83138. + <td>The maximum number of packets in a transfer.
  83139. + - Values: 15 to 511 (default 511)
  83140. + </td></tr>
  83141. +
  83142. + <tr>
  83143. + <td>host_channels</td>
  83144. + <td>The number of host channel registers to use.
  83145. + - Values: 1 to 16 (default 12)
  83146. +
  83147. + Note: The FPGA configuration supports a maximum of 12 host channels.
  83148. + </td></tr>
  83149. +
  83150. + <tr>
  83151. + <td>dev_endpoints</td>
  83152. + <td>The number of endpoints in addition to EP0 available for device mode
  83153. + operations.
  83154. + - Values: 1 to 15 (default 6 IN and OUT)
  83155. +
  83156. + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
  83157. + addition to EP0.
  83158. + </td></tr>
  83159. +
  83160. + <tr>
  83161. + <td>phy_type</td>
  83162. + <td>Specifies the type of PHY interface to use. By default, the driver will
  83163. + automatically detect the phy_type.
  83164. + - 0: Full Speed
  83165. + - 1: UTMI+ (default, if available)
  83166. + - 2: ULPI
  83167. + </td></tr>
  83168. +
  83169. + <tr>
  83170. + <td>phy_utmi_width</td>
  83171. + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
  83172. + phy_type of UTMI+. Also, this parameter is applicable only if the
  83173. + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
  83174. + core has been configured to work at either data path width.
  83175. + - Values: 8 or 16 bits (default 16)
  83176. + </td></tr>
  83177. +
  83178. + <tr>
  83179. + <td>phy_ulpi_ddr</td>
  83180. + <td>Specifies whether the ULPI operates at double or single data rate. This
  83181. + parameter is only applicable if phy_type is ULPI.
  83182. + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
  83183. + - 1: double data rate ULPI interface with 4 bit wide data bus
  83184. + </td></tr>
  83185. +
  83186. + <tr>
  83187. + <td>i2c_enable</td>
  83188. + <td>Specifies whether to use the I2C interface for full speed PHY. This
  83189. + parameter is only applicable if PHY_TYPE is FS.
  83190. + - 0: Disabled (default)
  83191. + - 1: Enabled
  83192. + </td></tr>
  83193. +
  83194. + <tr>
  83195. + <td>ulpi_fs_ls</td>
  83196. + <td>Specifies whether to use ULPI FS/LS mode only.
  83197. + - 0: Disabled (default)
  83198. + - 1: Enabled
  83199. + </td></tr>
  83200. +
  83201. + <tr>
  83202. + <td>ts_dline</td>
  83203. + <td>Specifies whether term select D-Line pulsing for all PHYs is enabled.
  83204. + - 0: Disabled (default)
  83205. + - 1: Enabled
  83206. + </td></tr>
  83207. +
  83208. + <tr>
  83209. + <td>en_multiple_tx_fifo</td>
  83210. + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
  83211. + The driver will automatically detect the value for this parameter if none is
  83212. + specified.
  83213. + - 0: Disabled
  83214. + - 1: Enabled (default, if available)
  83215. + </td></tr>
  83216. +
  83217. + <tr>
  83218. + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
  83219. + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
  83220. + when dynamic FIFO sizing is enabled.
  83221. + - Values: 4 to 768 (default 256)
  83222. + </td></tr>
  83223. +
  83224. + <tr>
  83225. + <td>tx_thr_length</td>
  83226. + <td>Transmit Threshold length in 32 bit double words
  83227. + - Values: 8 to 128 (default 64)
  83228. + </td></tr>
  83229. +
  83230. + <tr>
  83231. + <td>rx_thr_length</td>
  83232. + <td>Receive Threshold length in 32 bit double words
  83233. + - Values: 8 to 128 (default 64)
  83234. + </td></tr>
  83235. +
  83236. +<tr>
  83237. + <td>thr_ctl</td>
  83238. + <td>Specifies whether to enable Thresholding for Device mode. Bits 0, 1, 2 of
  83239. + this parmater specifies if thresholding is enabled for non-Iso Tx, Iso Tx and
  83240. + Rx transfers accordingly.
  83241. + The driver will automatically detect the value for this parameter if none is
  83242. + specified.
  83243. + - Values: 0 to 7 (default 0)
  83244. + Bit values indicate:
  83245. + - 0: Thresholding disabled
  83246. + - 1: Thresholding enabled
  83247. + </td></tr>
  83248. +
  83249. +<tr>
  83250. + <td>dma_desc_enable</td>
  83251. + <td>Specifies whether to enable Descriptor DMA mode.
  83252. + The driver will automatically detect the value for this parameter if none is
  83253. + specified.
  83254. + - 0: Descriptor DMA disabled
  83255. + - 1: Descriptor DMA (default, if available)
  83256. + </td></tr>
  83257. +
  83258. +<tr>
  83259. + <td>mpi_enable</td>
  83260. + <td>Specifies whether to enable MPI enhancement mode.
  83261. + The driver will automatically detect the value for this parameter if none is
  83262. + specified.
  83263. + - 0: MPI disabled (default)
  83264. + - 1: MPI enable
  83265. + </td></tr>
  83266. +
  83267. +<tr>
  83268. + <td>pti_enable</td>
  83269. + <td>Specifies whether to enable PTI enhancement support.
  83270. + The driver will automatically detect the value for this parameter if none is
  83271. + specified.
  83272. + - 0: PTI disabled (default)
  83273. + - 1: PTI enable
  83274. + </td></tr>
  83275. +
  83276. +<tr>
  83277. + <td>lpm_enable</td>
  83278. + <td>Specifies whether to enable LPM support.
  83279. + The driver will automatically detect the value for this parameter if none is
  83280. + specified.
  83281. + - 0: LPM disabled
  83282. + - 1: LPM enable (default, if available)
  83283. + </td></tr>
  83284. +
  83285. +<tr>
  83286. + <td>ic_usb_cap</td>
  83287. + <td>Specifies whether to enable IC_USB capability.
  83288. + The driver will automatically detect the value for this parameter if none is
  83289. + specified.
  83290. + - 0: IC_USB disabled (default, if available)
  83291. + - 1: IC_USB enable
  83292. + </td></tr>
  83293. +
  83294. +<tr>
  83295. + <td>ahb_thr_ratio</td>
  83296. + <td>Specifies AHB Threshold ratio.
  83297. + - Values: 0 to 3 (default 0)
  83298. + </td></tr>
  83299. +
  83300. +<tr>
  83301. + <td>power_down</td>
  83302. + <td>Specifies Power Down(Hibernation) Mode.
  83303. + The driver will automatically detect the value for this parameter if none is
  83304. + specified.
  83305. + - 0: Power Down disabled (default)
  83306. + - 2: Power Down enabled
  83307. + </td></tr>
  83308. +
  83309. + <tr>
  83310. + <td>reload_ctl</td>
  83311. + <td>Specifies whether dynamic reloading of the HFIR register is allowed during
  83312. + run time. The driver will automatically detect the value for this parameter if
  83313. + none is specified. In case the HFIR value is reloaded when HFIR.RldCtrl == 1'b0
  83314. + the core might misbehave.
  83315. + - 0: Reload Control disabled (default)
  83316. + - 1: Reload Control enabled
  83317. + </td></tr>
  83318. +
  83319. + <tr>
  83320. + <td>dev_out_nak</td>
  83321. + <td>Specifies whether Device OUT NAK enhancement enabled or no.
  83322. + The driver will automatically detect the value for this parameter if
  83323. + none is specified. This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  83324. + - 0: The core does not set NAK after Bulk OUT transfer complete (default)
  83325. + - 1: The core sets NAK after Bulk OUT transfer complete
  83326. + </td></tr>
  83327. +
  83328. + <tr>
  83329. + <td>cont_on_bna</td>
  83330. + <td>Specifies whether Enable Continue on BNA enabled or no.
  83331. + After receiving BNA interrupt the core disables the endpoint,when the
  83332. + endpoint is re-enabled by the application the
  83333. + - 0: Core starts processing from the DOEPDMA descriptor (default)
  83334. + - 1: Core starts processing from the descriptor which received the BNA.
  83335. + This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  83336. + </td></tr>
  83337. +
  83338. + <tr>
  83339. + <td>ahb_single</td>
  83340. + <td>This bit when programmed supports SINGLE transfers for remainder data
  83341. + in a transfer for DMA mode of operation.
  83342. + - 0: The remainder data will be sent using INCR burst size (default)
  83343. + - 1: The remainder data will be sent using SINGLE burst size.
  83344. + </td></tr>
  83345. +
  83346. +<tr>
  83347. + <td>adp_enable</td>
  83348. + <td>Specifies whether ADP feature is enabled.
  83349. + The driver will automatically detect the value for this parameter if none is
  83350. + specified.
  83351. + - 0: ADP feature disabled (default)
  83352. + - 1: ADP feature enabled
  83353. + </td></tr>
  83354. +
  83355. + <tr>
  83356. + <td>otg_ver</td>
  83357. + <td>Specifies whether OTG is performing as USB OTG Revision 2.0 or Revision 1.3
  83358. + USB OTG device.
  83359. + - 0: OTG 2.0 support disabled (default)
  83360. + - 1: OTG 2.0 support enabled
  83361. + </td></tr>
  83362. +
  83363. +*/
  83364. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_driver.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.h
  83365. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_driver.h 1970-01-01 01:00:00.000000000 +0100
  83366. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.h 2015-02-09 04:40:29.000000000 +0100
  83367. @@ -0,0 +1,86 @@
  83368. +/* ==========================================================================
  83369. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.h $
  83370. + * $Revision: #19 $
  83371. + * $Date: 2010/11/15 $
  83372. + * $Change: 1627671 $
  83373. + *
  83374. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  83375. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  83376. + * otherwise expressly agreed to in writing between Synopsys and you.
  83377. + *
  83378. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  83379. + * any End User Software License Agreement or Agreement for Licensed Product
  83380. + * with Synopsys or any supplement thereto. You are permitted to use and
  83381. + * redistribute this Software in source and binary forms, with or without
  83382. + * modification, provided that redistributions of source code must retain this
  83383. + * notice. You may not view, use, disclose, copy or distribute this file or
  83384. + * any information contained herein except pursuant to this license grant from
  83385. + * Synopsys. If you do not agree with this notice, including the disclaimer
  83386. + * below, then you are not authorized to use the Software.
  83387. + *
  83388. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  83389. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  83390. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  83391. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  83392. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  83393. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  83394. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  83395. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  83396. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  83397. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  83398. + * DAMAGE.
  83399. + * ========================================================================== */
  83400. +
  83401. +#ifndef __DWC_OTG_DRIVER_H__
  83402. +#define __DWC_OTG_DRIVER_H__
  83403. +
  83404. +/** @file
  83405. + * This file contains the interface to the Linux driver.
  83406. + */
  83407. +#include "dwc_otg_os_dep.h"
  83408. +#include "dwc_otg_core_if.h"
  83409. +
  83410. +/* Type declarations */
  83411. +struct dwc_otg_pcd;
  83412. +struct dwc_otg_hcd;
  83413. +
  83414. +/**
  83415. + * This structure is a wrapper that encapsulates the driver components used to
  83416. + * manage a single DWC_otg controller.
  83417. + */
  83418. +typedef struct dwc_otg_device {
  83419. + /** Structure containing OS-dependent stuff. KEEP THIS STRUCT AT THE
  83420. + * VERY BEGINNING OF THE DEVICE STRUCT. OSes such as FreeBSD and NetBSD
  83421. + * require this. */
  83422. + struct os_dependent os_dep;
  83423. +
  83424. + /** Pointer to the core interface structure. */
  83425. + dwc_otg_core_if_t *core_if;
  83426. +
  83427. + /** Pointer to the PCD structure. */
  83428. + struct dwc_otg_pcd *pcd;
  83429. +
  83430. + /** Pointer to the HCD structure. */
  83431. + struct dwc_otg_hcd *hcd;
  83432. +
  83433. + /** Flag to indicate whether the common IRQ handler is installed. */
  83434. + uint8_t common_irq_installed;
  83435. +
  83436. +} dwc_otg_device_t;
  83437. +
  83438. +/*We must clear S3C24XX_EINTPEND external interrupt register
  83439. + * because after clearing in this register trigerred IRQ from
  83440. + * H/W core in kernel interrupt can be occured again before OTG
  83441. + * handlers clear all IRQ sources of Core registers because of
  83442. + * timing latencies and Low Level IRQ Type.
  83443. + */
  83444. +#ifdef CONFIG_MACH_IPMATE
  83445. +#define S3C2410X_CLEAR_EINTPEND() \
  83446. +do { \
  83447. + __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
  83448. +} while (0)
  83449. +#else
  83450. +#define S3C2410X_CLEAR_EINTPEND() do { } while (0)
  83451. +#endif
  83452. +
  83453. +#endif
  83454. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
  83455. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 1970-01-01 01:00:00.000000000 +0100
  83456. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 2015-02-09 04:40:29.000000000 +0100
  83457. @@ -0,0 +1,1346 @@
  83458. +/*
  83459. + * dwc_otg_fiq_fsm.c - The finite state machine FIQ
  83460. + *
  83461. + * Copyright (c) 2013 Raspberry Pi Foundation
  83462. + *
  83463. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  83464. + * All rights reserved.
  83465. + *
  83466. + * Redistribution and use in source and binary forms, with or without
  83467. + * modification, are permitted provided that the following conditions are met:
  83468. + * * Redistributions of source code must retain the above copyright
  83469. + * notice, this list of conditions and the following disclaimer.
  83470. + * * Redistributions in binary form must reproduce the above copyright
  83471. + * notice, this list of conditions and the following disclaimer in the
  83472. + * documentation and/or other materials provided with the distribution.
  83473. + * * Neither the name of Raspberry Pi nor the
  83474. + * names of its contributors may be used to endorse or promote products
  83475. + * derived from this software without specific prior written permission.
  83476. + *
  83477. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  83478. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  83479. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  83480. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  83481. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  83482. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  83483. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  83484. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  83485. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  83486. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  83487. + *
  83488. + * This FIQ implements functionality that performs split transactions on
  83489. + * the dwc_otg hardware without any outside intervention. A split transaction
  83490. + * is "queued" by nominating a specific host channel to perform the entirety
  83491. + * of a split transaction. This FIQ will then perform the microframe-precise
  83492. + * scheduling required in each phase of the transaction until completion.
  83493. + *
  83494. + * The FIQ functionality is glued into the Synopsys driver via the entry point
  83495. + * in the FSM enqueue function, and at the exit point in handling a HC interrupt
  83496. + * for a FSM-enabled channel.
  83497. + *
  83498. + * NB: Large parts of this implementation have architecture-specific code.
  83499. + * For porting this functionality to other ARM machines, the minimum is required:
  83500. + * - An interrupt controller allowing the top-level dwc USB interrupt to be routed
  83501. + * to the FIQ
  83502. + * - A method of forcing a software generated interrupt from FIQ mode that then
  83503. + * triggers an IRQ entry (with the dwc USB handler called by this IRQ number)
  83504. + * - Guaranteed interrupt routing such that both the FIQ and SGI occur on the same
  83505. + * processor core - there is no locking between the FIQ and IRQ (aside from
  83506. + * local_fiq_disable)
  83507. + *
  83508. + */
  83509. +
  83510. +#include "dwc_otg_fiq_fsm.h"
  83511. +
  83512. +
  83513. +char buffer[1000*16];
  83514. +int wptr;
  83515. +void notrace _fiq_print(enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...)
  83516. +{
  83517. + enum fiq_debug_level dbg_lvl_req = FIQDBG_ERR;
  83518. + va_list args;
  83519. + char text[17];
  83520. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + 0x408) };
  83521. +
  83522. + if((dbg_lvl & dbg_lvl_req) || dbg_lvl == FIQDBG_ERR)
  83523. + {
  83524. + snprintf(text, 9, " %4d:%1u ", hfnum.b.frnum/8, hfnum.b.frnum & 7);
  83525. + va_start(args, fmt);
  83526. + vsnprintf(text+8, 9, fmt, args);
  83527. + va_end(args);
  83528. +
  83529. + memcpy(buffer + wptr, text, 16);
  83530. + wptr = (wptr + 16) % sizeof(buffer);
  83531. + }
  83532. +}
  83533. +
  83534. +/**
  83535. + * fiq_fsm_spin_lock() - ARMv6+ bare bones spinlock
  83536. + * Must be called with local interrupts and FIQ disabled.
  83537. + */
  83538. +#ifdef CONFIG_ARCH_BCM2709
  83539. +inline void fiq_fsm_spin_lock(fiq_lock_t *lock)
  83540. +{
  83541. + unsigned long tmp;
  83542. + uint32_t newval;
  83543. + fiq_lock_t lockval;
  83544. + smp_mb__before_spinlock();
  83545. + /* Nested locking, yay. If we are on the same CPU as the fiq, then the disable
  83546. + * will be sufficient. If we are on a different CPU, then the lock protects us. */
  83547. + prefetchw(&lock->slock);
  83548. + asm volatile (
  83549. + "1: ldrex %0, [%3]\n"
  83550. + " add %1, %0, %4\n"
  83551. + " strex %2, %1, [%3]\n"
  83552. + " teq %2, #0\n"
  83553. + " bne 1b"
  83554. + : "=&r" (lockval), "=&r" (newval), "=&r" (tmp)
  83555. + : "r" (&lock->slock), "I" (1 << 16)
  83556. + : "cc");
  83557. +
  83558. + while (lockval.tickets.next != lockval.tickets.owner) {
  83559. + wfe();
  83560. + lockval.tickets.owner = ACCESS_ONCE(lock->tickets.owner);
  83561. + }
  83562. + smp_mb();
  83563. +}
  83564. +#else
  83565. +inline void fiq_fsm_spin_lock(fiq_lock_t *lock) { }
  83566. +#endif
  83567. +
  83568. +/**
  83569. + * fiq_fsm_spin_unlock() - ARMv6+ bare bones spinunlock
  83570. + */
  83571. +#ifdef CONFIG_ARCH_BCM2709
  83572. +inline void fiq_fsm_spin_unlock(fiq_lock_t *lock)
  83573. +{
  83574. + smp_mb();
  83575. + lock->tickets.owner++;
  83576. + dsb_sev();
  83577. +}
  83578. +#else
  83579. +inline void fiq_fsm_spin_unlock(fiq_lock_t *lock) { }
  83580. +#endif
  83581. +
  83582. +/**
  83583. + * fiq_fsm_restart_channel() - Poke channel enable bit for a split transaction
  83584. + * @channel: channel to re-enable
  83585. + */
  83586. +static void fiq_fsm_restart_channel(struct fiq_state *st, int n, int force)
  83587. +{
  83588. + hcchar_data_t hcchar = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR) };
  83589. +
  83590. + hcchar.b.chen = 0;
  83591. + if (st->channel[n].hcchar_copy.b.eptype & 0x1) {
  83592. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  83593. + /* Hardware bug workaround: update the ssplit index */
  83594. + if (st->channel[n].hcsplt_copy.b.spltena)
  83595. + st->channel[n].expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  83596. +
  83597. + hcchar.b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  83598. + }
  83599. +
  83600. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  83601. + hcchar.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  83602. + hcchar.b.chen = 1;
  83603. +
  83604. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  83605. + fiq_print(FIQDBG_INT, st, "HCGO %01d %01d", n, force);
  83606. +}
  83607. +
  83608. +/**
  83609. + * fiq_fsm_setup_csplit() - Prepare a host channel for a CSplit transaction stage
  83610. + * @st: Pointer to the channel's state
  83611. + * @n : channel number
  83612. + *
  83613. + * Change host channel registers to perform a complete-split transaction. Being mindful of the
  83614. + * endpoint direction, set control regs up correctly.
  83615. + */
  83616. +static void notrace fiq_fsm_setup_csplit(struct fiq_state *st, int n)
  83617. +{
  83618. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT) };
  83619. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  83620. +
  83621. + hcsplt.b.compsplt = 1;
  83622. + if (st->channel[n].hcchar_copy.b.epdir == 1) {
  83623. + // If IN, the CSPLIT result contains the data or a hub handshake. hctsiz = maxpacket.
  83624. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  83625. + } else {
  83626. + // If OUT, the CSPLIT result contains handshake only.
  83627. + hctsiz.b.xfersize = 0;
  83628. + }
  83629. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  83630. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  83631. + mb();
  83632. +}
  83633. +
  83634. +static inline int notrace fiq_get_xfer_len(struct fiq_state *st, int n)
  83635. +{
  83636. + /* The xfersize register is a bit wonky. For IN transfers, it decrements by the packet size. */
  83637. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  83638. +
  83639. + if (st->channel[n].hcchar_copy.b.epdir == 0) {
  83640. + return st->channel[n].hctsiz_copy.b.xfersize;
  83641. + } else {
  83642. + return st->channel[n].hctsiz_copy.b.xfersize - hctsiz.b.xfersize;
  83643. + }
  83644. +
  83645. +}
  83646. +
  83647. +
  83648. +/**
  83649. + * fiq_increment_dma_buf() - update DMA address for bounce buffers after a CSPLIT
  83650. + *
  83651. + * Of use only for IN periodic transfers.
  83652. + */
  83653. +static int notrace fiq_increment_dma_buf(struct fiq_state *st, int num_channels, int n)
  83654. +{
  83655. + hcdma_data_t hcdma;
  83656. + int i = st->channel[n].dma_info.index;
  83657. + int len;
  83658. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  83659. +
  83660. + len = fiq_get_xfer_len(st, n);
  83661. + fiq_print(FIQDBG_INT, st, "LEN: %03d", len);
  83662. + st->channel[n].dma_info.slot_len[i] = len;
  83663. + i++;
  83664. + if (i > 6)
  83665. + BUG();
  83666. +
  83667. + hcdma.d32 = (dma_addr_t) &blob->channel[n].index[i].buf[0];
  83668. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  83669. + st->channel[n].dma_info.index = i;
  83670. + return 0;
  83671. +}
  83672. +
  83673. +/**
  83674. + * fiq_reload_hctsiz() - for IN transactions, reset HCTSIZ
  83675. + */
  83676. +static void notrace fiq_fsm_reload_hctsiz(struct fiq_state *st, int n)
  83677. +{
  83678. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  83679. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  83680. + hctsiz.b.pktcnt = 1;
  83681. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  83682. +}
  83683. +
  83684. +/**
  83685. + * fiq_iso_out_advance() - update DMA address and split position bits
  83686. + * for isochronous OUT transactions.
  83687. + *
  83688. + * Returns 1 if this is the last packet queued, 0 otherwise. Split-ALL and
  83689. + * Split-BEGIN states are not handled - this is done when the transaction was queued.
  83690. + *
  83691. + * This function must only be called from the FIQ_ISO_OUT_ACTIVE state.
  83692. + */
  83693. +static int notrace fiq_iso_out_advance(struct fiq_state *st, int num_channels, int n)
  83694. +{
  83695. + hcsplt_data_t hcsplt;
  83696. + hctsiz_data_t hctsiz;
  83697. + hcdma_data_t hcdma;
  83698. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  83699. + int last = 0;
  83700. + int i = st->channel[n].dma_info.index;
  83701. +
  83702. + fiq_print(FIQDBG_INT, st, "ADV %01d %01d ", n, i);
  83703. + i++;
  83704. + if (i == 4)
  83705. + last = 1;
  83706. + if (st->channel[n].dma_info.slot_len[i+1] == 255)
  83707. + last = 1;
  83708. +
  83709. + /* New DMA address - address of bounce buffer referred to in index */
  83710. + hcdma.d32 = (uint32_t) &blob->channel[n].index[i].buf[0];
  83711. + //hcdma.d32 = FIQ_READ(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n));
  83712. + //hcdma.d32 += st->channel[n].dma_info.slot_len[i];
  83713. + fiq_print(FIQDBG_INT, st, "LAST: %01d ", last);
  83714. + fiq_print(FIQDBG_INT, st, "LEN: %03d", st->channel[n].dma_info.slot_len[i]);
  83715. + hcsplt.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT);
  83716. + hctsiz.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ);
  83717. + hcsplt.b.xactpos = (last) ? ISOC_XACTPOS_END : ISOC_XACTPOS_MID;
  83718. + /* Set up new packet length */
  83719. + hctsiz.b.pktcnt = 1;
  83720. + hctsiz.b.xfersize = st->channel[n].dma_info.slot_len[i];
  83721. + fiq_print(FIQDBG_INT, st, "%08x", hctsiz.d32);
  83722. +
  83723. + st->channel[n].dma_info.index++;
  83724. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  83725. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  83726. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  83727. + return last;
  83728. +}
  83729. +
  83730. +/**
  83731. + * fiq_fsm_tt_next_isoc() - queue next pending isochronous out start-split on a TT
  83732. + *
  83733. + * Despite the limitations of the DWC core, we can force a microframe pipeline of
  83734. + * isochronous OUT start-split transactions while waiting for a corresponding other-type
  83735. + * of endpoint to finish its CSPLITs. TTs have big periodic buffers therefore it
  83736. + * is very unlikely that filling the start-split FIFO will cause data loss.
  83737. + * This allows much better interleaving of transactions in an order-independent way-
  83738. + * there is no requirement to prioritise isochronous, just a state-space search has
  83739. + * to be performed on each periodic start-split complete interrupt.
  83740. + */
  83741. +static int notrace fiq_fsm_tt_next_isoc(struct fiq_state *st, int num_channels, int n)
  83742. +{
  83743. + int hub_addr = st->channel[n].hub_addr;
  83744. + int port_addr = st->channel[n].port_addr;
  83745. + int i, poked = 0;
  83746. + for (i = 0; i < num_channels; i++) {
  83747. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  83748. + continue;
  83749. + if (st->channel[i].hub_addr == hub_addr &&
  83750. + st->channel[i].port_addr == port_addr) {
  83751. + switch (st->channel[i].fsm) {
  83752. + case FIQ_PER_ISO_OUT_PENDING:
  83753. + if (st->channel[i].nrpackets == 1) {
  83754. + st->channel[i].fsm = FIQ_PER_ISO_OUT_LAST;
  83755. + } else {
  83756. + st->channel[i].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  83757. + }
  83758. + fiq_fsm_restart_channel(st, i, 0);
  83759. + poked = 1;
  83760. + break;
  83761. +
  83762. + default:
  83763. + break;
  83764. + }
  83765. + }
  83766. + if (poked)
  83767. + break;
  83768. + }
  83769. + return poked;
  83770. +}
  83771. +
  83772. +/**
  83773. + * fiq_fsm_tt_in_use() - search for host channels using this TT
  83774. + * @n: Channel to use as reference
  83775. + *
  83776. + */
  83777. +int notrace noinline fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n)
  83778. +{
  83779. + int hub_addr = st->channel[n].hub_addr;
  83780. + int port_addr = st->channel[n].port_addr;
  83781. + int i, in_use = 0;
  83782. + for (i = 0; i < num_channels; i++) {
  83783. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  83784. + continue;
  83785. + switch (st->channel[i].fsm) {
  83786. + /* TT is reserved for channels that are in the middle of a periodic
  83787. + * split transaction.
  83788. + */
  83789. + case FIQ_PER_SSPLIT_STARTED:
  83790. + case FIQ_PER_CSPLIT_WAIT:
  83791. + case FIQ_PER_CSPLIT_NYET1:
  83792. + //case FIQ_PER_CSPLIT_POLL:
  83793. + case FIQ_PER_ISO_OUT_ACTIVE:
  83794. + case FIQ_PER_ISO_OUT_LAST:
  83795. + if (st->channel[i].hub_addr == hub_addr &&
  83796. + st->channel[i].port_addr == port_addr) {
  83797. + in_use = 1;
  83798. + }
  83799. + break;
  83800. + default:
  83801. + break;
  83802. + }
  83803. + if (in_use)
  83804. + break;
  83805. + }
  83806. + return in_use;
  83807. +}
  83808. +
  83809. +/**
  83810. + * fiq_fsm_more_csplits() - determine whether additional CSPLITs need
  83811. + * to be issued for this IN transaction.
  83812. + *
  83813. + * We cannot tell the inbound PID of a data packet due to hardware limitations.
  83814. + * we need to make an educated guess as to whether we need to queue another CSPLIT
  83815. + * or not. A no-brainer is when we have received enough data to fill the endpoint
  83816. + * size, but for endpoints that give variable-length data then we have to resort
  83817. + * to heuristics.
  83818. + *
  83819. + * We also return whether this is the last CSPLIT to be queued, again based on
  83820. + * heuristics. This is to allow a 1-uframe overlap of periodic split transactions.
  83821. + * Note: requires at least 1 CSPLIT to have been performed prior to being called.
  83822. + */
  83823. +
  83824. +/*
  83825. + * We need some way of guaranteeing if a returned periodic packet of size X
  83826. + * has a DATA0 PID.
  83827. + * The heuristic value of 144 bytes assumes that the received data has maximal
  83828. + * bit-stuffing and the clock frequency of the transmitting device is at the lowest
  83829. + * permissible limit. If the transfer length results in a final packet size
  83830. + * 144 < p <= 188, then an erroneous CSPLIT will be issued.
  83831. + * Also used to ensure that an endpoint will nominally only return a single
  83832. + * complete-split worth of data.
  83833. + */
  83834. +#define DATA0_PID_HEURISTIC 144
  83835. +
  83836. +static int notrace noinline fiq_fsm_more_csplits(struct fiq_state *state, int n, int *probably_last)
  83837. +{
  83838. +
  83839. + int i;
  83840. + int total_len = 0;
  83841. + int more_needed = 1;
  83842. + struct fiq_channel_state *st = &state->channel[n];
  83843. +
  83844. + for (i = 0; i < st->dma_info.index; i++) {
  83845. + total_len += st->dma_info.slot_len[i];
  83846. + }
  83847. +
  83848. + *probably_last = 0;
  83849. +
  83850. + if (st->hcchar_copy.b.eptype == 0x3) {
  83851. + /*
  83852. + * An interrupt endpoint will take max 2 CSPLITs. if we are receiving data
  83853. + * then this is definitely the last CSPLIT.
  83854. + */
  83855. + *probably_last = 1;
  83856. + } else {
  83857. + /* Isoc IN. This is a bit risky if we are the first transaction:
  83858. + * we may have been held off slightly. */
  83859. + if (i > 1 && st->dma_info.slot_len[st->dma_info.index-1] <= DATA0_PID_HEURISTIC) {
  83860. + more_needed = 0;
  83861. + }
  83862. + /* If in the next uframe we will receive enough data to fill the endpoint,
  83863. + * then only issue 1 more csplit.
  83864. + */
  83865. + if (st->hctsiz_copy.b.xfersize - total_len <= DATA0_PID_HEURISTIC)
  83866. + *probably_last = 1;
  83867. + }
  83868. +
  83869. + if (total_len >= st->hctsiz_copy.b.xfersize ||
  83870. + i == 6 || total_len == 0)
  83871. + /* Note: due to bit stuffing it is possible to have > 6 CSPLITs for
  83872. + * a single endpoint. Accepting more would completely break our scheduling mechanism though
  83873. + * - in these extreme cases we will pass through a truncated packet.
  83874. + */
  83875. + more_needed = 0;
  83876. +
  83877. + return more_needed;
  83878. +}
  83879. +
  83880. +/**
  83881. + * fiq_fsm_too_late() - Test transaction for lateness
  83882. + *
  83883. + * If a SSPLIT for a large IN transaction is issued too late in a frame,
  83884. + * the hub will disable the port to the device and respond with ERR handshakes.
  83885. + * The hub status endpoint will not reflect this change.
  83886. + * Returns 1 if we will issue a SSPLIT that will result in a device babble.
  83887. + */
  83888. +int notrace fiq_fsm_too_late(struct fiq_state *st, int n)
  83889. +{
  83890. + int uframe;
  83891. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  83892. + uframe = hfnum.b.frnum & 0x7;
  83893. + if ((uframe < 6) && (st->channel[n].nrpackets + 1 + uframe > 7)) {
  83894. + return 1;
  83895. + } else {
  83896. + return 0;
  83897. + }
  83898. +}
  83899. +
  83900. +
  83901. +/**
  83902. + * fiq_fsm_start_next_periodic() - A half-arsed attempt at a microframe pipeline
  83903. + *
  83904. + * Search pending transactions in the start-split pending state and queue them.
  83905. + * Don't queue packets in uframe .5 (comes out in .6) (USB2.0 11.18.4).
  83906. + * Note: we specifically don't do isochronous OUT transactions first because better
  83907. + * use of the TT's start-split fifo can be achieved by pipelining an IN before an OUT.
  83908. + */
  83909. +static void notrace noinline fiq_fsm_start_next_periodic(struct fiq_state *st, int num_channels)
  83910. +{
  83911. + int n;
  83912. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  83913. + if ((hfnum.b.frnum & 0x7) == 5)
  83914. + return;
  83915. + for (n = 0; n < num_channels; n++) {
  83916. + if (st->channel[n].fsm == FIQ_PER_SSPLIT_QUEUED) {
  83917. + /* Check to see if any other transactions are using this TT */
  83918. + if(!fiq_fsm_tt_in_use(st, num_channels, n)) {
  83919. + if (!fiq_fsm_too_late(st, n)) {
  83920. + st->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  83921. + fiq_print(FIQDBG_INT, st, "NEXTPER ");
  83922. + fiq_fsm_restart_channel(st, n, 0);
  83923. + } else {
  83924. + st->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  83925. + }
  83926. + break;
  83927. + }
  83928. + }
  83929. + }
  83930. + for (n = 0; n < num_channels; n++) {
  83931. + if (st->channel[n].fsm == FIQ_PER_ISO_OUT_PENDING) {
  83932. + if (!fiq_fsm_tt_in_use(st, num_channels, n)) {
  83933. + fiq_print(FIQDBG_INT, st, "NEXTISO ");
  83934. + st->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  83935. + fiq_fsm_restart_channel(st, n, 0);
  83936. + break;
  83937. + }
  83938. + }
  83939. + }
  83940. +}
  83941. +
  83942. +/**
  83943. + * fiq_fsm_update_hs_isoc() - update isochronous frame and transfer data
  83944. + * @state: Pointer to fiq_state
  83945. + * @n: Channel transaction is active on
  83946. + * @hcint: Copy of host channel interrupt register
  83947. + *
  83948. + * Returns 0 if there are no more transactions for this HC to do, 1
  83949. + * otherwise.
  83950. + */
  83951. +static int notrace noinline fiq_fsm_update_hs_isoc(struct fiq_state *state, int n, hcint_data_t hcint)
  83952. +{
  83953. + struct fiq_channel_state *st = &state->channel[n];
  83954. + int xfer_len = 0, nrpackets = 0;
  83955. + hcdma_data_t hcdma;
  83956. + fiq_print(FIQDBG_INT, state, "HSISO %02d", n);
  83957. +
  83958. + xfer_len = fiq_get_xfer_len(state, n);
  83959. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].actual_length = xfer_len;
  83960. +
  83961. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].status = hcint.d32;
  83962. +
  83963. + st->hs_isoc_info.index++;
  83964. + if (st->hs_isoc_info.index == st->hs_isoc_info.nrframes) {
  83965. + return 0;
  83966. + }
  83967. +
  83968. + /* grab the next DMA address offset from the array */
  83969. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].offset;
  83970. + FIQ_WRITE(state->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  83971. +
  83972. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  83973. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  83974. + * this is always set to the maximum size of the endpoint. */
  83975. + xfer_len = st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].length;
  83976. + /* Integer divide in a FIQ: fun. FIXME: make this not suck */
  83977. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  83978. + if (nrpackets == 0)
  83979. + nrpackets = 1;
  83980. + st->hcchar_copy.b.multicnt = nrpackets;
  83981. + st->hctsiz_copy.b.pktcnt = nrpackets;
  83982. +
  83983. + /* Initial PID also needs to be set */
  83984. + if (st->hcchar_copy.b.epdir == 0) {
  83985. + st->hctsiz_copy.b.xfersize = xfer_len;
  83986. + switch (st->hcchar_copy.b.multicnt) {
  83987. + case 1:
  83988. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  83989. + break;
  83990. + case 2:
  83991. + case 3:
  83992. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  83993. + break;
  83994. + }
  83995. +
  83996. + } else {
  83997. + switch (st->hcchar_copy.b.multicnt) {
  83998. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  83999. + case 1:
  84000. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  84001. + break;
  84002. + case 2:
  84003. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  84004. + break;
  84005. + case 3:
  84006. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  84007. + break;
  84008. + }
  84009. + }
  84010. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, st->hctsiz_copy.d32);
  84011. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, st->hcchar_copy.d32);
  84012. + /* Channel is enabled on hcint handler exit */
  84013. + fiq_print(FIQDBG_INT, state, "HSISOOUT");
  84014. + return 1;
  84015. +}
  84016. +
  84017. +
  84018. +/**
  84019. + * fiq_fsm_do_sof() - FSM start-of-frame interrupt handler
  84020. + * @state: Pointer to the state struct passed from banked FIQ mode registers.
  84021. + * @num_channels: set according to the DWC hardware configuration
  84022. + *
  84023. + * The SOF handler in FSM mode has two functions
  84024. + * 1. Hold off SOF from causing schedule advancement in IRQ context if there's
  84025. + * nothing to do
  84026. + * 2. Advance certain FSM states that require either a microframe delay, or a microframe
  84027. + * of holdoff.
  84028. + *
  84029. + * The second part is architecture-specific to mach-bcm2835 -
  84030. + * a sane interrupt controller would have a mask register for ARM interrupt sources
  84031. + * to be promoted to the nFIQ line, but it doesn't. Instead a single interrupt
  84032. + * number (USB) can be enabled. This means that certain parts of the USB specification
  84033. + * that require "wait a little while, then issue another packet" cannot be fulfilled with
  84034. + * the timing granularity required to achieve optimal throughout. The workaround is to use
  84035. + * the SOF "timer" (125uS) to perform this task.
  84036. + */
  84037. +static int notrace noinline fiq_fsm_do_sof(struct fiq_state *state, int num_channels)
  84038. +{
  84039. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + HFNUM) };
  84040. + int n;
  84041. + int kick_irq = 0;
  84042. +
  84043. + if ((hfnum.b.frnum & 0x7) == 1) {
  84044. + /* We cannot issue csplits for transactions in the last frame past (n+1).1
  84045. + * Check to see if there are any transactions that are stale.
  84046. + * Boot them out.
  84047. + */
  84048. + for (n = 0; n < num_channels; n++) {
  84049. + switch (state->channel[n].fsm) {
  84050. + case FIQ_PER_CSPLIT_WAIT:
  84051. + case FIQ_PER_CSPLIT_NYET1:
  84052. + case FIQ_PER_CSPLIT_POLL:
  84053. + case FIQ_PER_CSPLIT_LAST:
  84054. + /* Check if we are no longer in the same full-speed frame. */
  84055. + if (((state->channel[n].expected_uframe & 0x3FFF) & ~0x7) <
  84056. + (hfnum.b.frnum & ~0x7))
  84057. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  84058. + break;
  84059. + default:
  84060. + break;
  84061. + }
  84062. + }
  84063. + }
  84064. +
  84065. + for (n = 0; n < num_channels; n++) {
  84066. + switch (state->channel[n].fsm) {
  84067. +
  84068. + case FIQ_NP_SSPLIT_RETRY:
  84069. + case FIQ_NP_IN_CSPLIT_RETRY:
  84070. + case FIQ_NP_OUT_CSPLIT_RETRY:
  84071. + fiq_fsm_restart_channel(state, n, 0);
  84072. + break;
  84073. +
  84074. + case FIQ_HS_ISOC_SLEEPING:
  84075. + state->channel[n].fsm = FIQ_HS_ISOC_TURBO;
  84076. + fiq_fsm_restart_channel(state, n, 0);
  84077. + break;
  84078. +
  84079. + case FIQ_PER_SSPLIT_QUEUED:
  84080. + if ((hfnum.b.frnum & 0x7) == 5)
  84081. + break;
  84082. + if(!fiq_fsm_tt_in_use(state, num_channels, n)) {
  84083. + if (!fiq_fsm_too_late(state, n)) {
  84084. + fiq_print(FIQDBG_INT, st, "SOF GO %01d", n);
  84085. + fiq_fsm_restart_channel(state, n, 0);
  84086. + state->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  84087. + } else {
  84088. + /* Transaction cannot be started without risking a device babble error */
  84089. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  84090. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  84091. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, 0);
  84092. + kick_irq |= 1;
  84093. + }
  84094. + }
  84095. + break;
  84096. +
  84097. + case FIQ_PER_ISO_OUT_PENDING:
  84098. + /* Ordinarily, this should be poked after the SSPLIT
  84099. + * complete interrupt for a competing transfer on the same
  84100. + * TT. Doesn't happen for aborted transactions though.
  84101. + */
  84102. + if ((hfnum.b.frnum & 0x7) >= 5)
  84103. + break;
  84104. + if (!fiq_fsm_tt_in_use(state, num_channels, n)) {
  84105. + /* Hardware bug. SOF can sometimes occur after the channel halt interrupt
  84106. + * that caused this.
  84107. + */
  84108. + fiq_fsm_restart_channel(state, n, 0);
  84109. + fiq_print(FIQDBG_INT, state, "SOF ISOC");
  84110. + if (state->channel[n].nrpackets == 1) {
  84111. + state->channel[n].fsm = FIQ_PER_ISO_OUT_LAST;
  84112. + } else {
  84113. + state->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  84114. + }
  84115. + }
  84116. + break;
  84117. +
  84118. + case FIQ_PER_CSPLIT_WAIT:
  84119. + /* we are guaranteed to be in this state if and only if the SSPLIT interrupt
  84120. + * occurred when the bus transaction occurred. The SOF interrupt reversal bug
  84121. + * will utterly bugger this up though.
  84122. + */
  84123. + if (hfnum.b.frnum != state->channel[n].expected_uframe) {
  84124. + fiq_print(FIQDBG_INT, state, "SOFCS %d ", n);
  84125. + state->channel[n].fsm = FIQ_PER_CSPLIT_POLL;
  84126. + fiq_fsm_restart_channel(state, n, 0);
  84127. + fiq_fsm_start_next_periodic(state, num_channels);
  84128. +
  84129. + }
  84130. + break;
  84131. +
  84132. + case FIQ_PER_SPLIT_TIMEOUT:
  84133. + case FIQ_DEQUEUE_ISSUED:
  84134. + /* Ugly: we have to force a HCD interrupt.
  84135. + * Poke the mask for the channel in question.
  84136. + * We will take a fake SOF because of this, but
  84137. + * that's OK.
  84138. + */
  84139. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  84140. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, 0);
  84141. + kick_irq |= 1;
  84142. + break;
  84143. +
  84144. + default:
  84145. + break;
  84146. + }
  84147. + }
  84148. +
  84149. + if (state->kick_np_queues ||
  84150. + dwc_frame_num_le(state->next_sched_frame, hfnum.b.frnum))
  84151. + kick_irq |= 1;
  84152. +
  84153. + return !kick_irq;
  84154. +}
  84155. +
  84156. +
  84157. +/**
  84158. + * fiq_fsm_do_hcintr() - FSM host channel interrupt handler
  84159. + * @state: Pointer to the FIQ state struct
  84160. + * @num_channels: Number of channels as per hardware config
  84161. + * @n: channel for which HAINT(i) was raised
  84162. + *
  84163. + * An important property is that only the CHHLT interrupt is unmasked. Unfortunately, AHBerr is as well.
  84164. + */
  84165. +static int notrace noinline fiq_fsm_do_hcintr(struct fiq_state *state, int num_channels, int n)
  84166. +{
  84167. + hcint_data_t hcint;
  84168. + hcintmsk_data_t hcintmsk;
  84169. + hcint_data_t hcint_probe;
  84170. + hcchar_data_t hcchar;
  84171. + int handled = 0;
  84172. + int restart = 0;
  84173. + int last_csplit = 0;
  84174. + int start_next_periodic = 0;
  84175. + struct fiq_channel_state *st = &state->channel[n];
  84176. + hfnum_data_t hfnum;
  84177. +
  84178. + hcint.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT);
  84179. + hcintmsk.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK);
  84180. + hcint_probe.d32 = hcint.d32 & hcintmsk.d32;
  84181. +
  84182. + if (st->fsm != FIQ_PASSTHROUGH) {
  84183. + fiq_print(FIQDBG_INT, state, "HC%01d ST%02d", n, st->fsm);
  84184. + fiq_print(FIQDBG_INT, state, "%08x", hcint.d32);
  84185. + }
  84186. +
  84187. + switch (st->fsm) {
  84188. +
  84189. + case FIQ_PASSTHROUGH:
  84190. + case FIQ_DEQUEUE_ISSUED:
  84191. + /* doesn't belong to us, kick it upstairs */
  84192. + break;
  84193. +
  84194. + case FIQ_PASSTHROUGH_ERRORSTATE:
  84195. + /* We are here to emulate the error recovery mechanism of the dwc HCD.
  84196. + * Several interrupts are unmasked if a previous transaction failed - it's
  84197. + * death for the FIQ to attempt to handle them as the channel isn't halted.
  84198. + * Emulate what the HCD does in this situation: mask and continue.
  84199. + * The FSM has no other state setup so this has to be handled out-of-band.
  84200. + */
  84201. + fiq_print(FIQDBG_ERR, state, "ERRST %02d", n);
  84202. + if (hcint_probe.b.nak || hcint_probe.b.ack || hcint_probe.b.datatglerr) {
  84203. + fiq_print(FIQDBG_ERR, state, "RESET %02d", n);
  84204. + /* In some random cases we can get a NAK interrupt coincident with a Xacterr
  84205. + * interrupt, after the device has disappeared.
  84206. + */
  84207. + if (!hcint.b.xacterr)
  84208. + st->nr_errors = 0;
  84209. + hcintmsk.b.nak = 0;
  84210. + hcintmsk.b.ack = 0;
  84211. + hcintmsk.b.datatglerr = 0;
  84212. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, hcintmsk.d32);
  84213. + return 1;
  84214. + }
  84215. + if (hcint_probe.b.chhltd) {
  84216. + fiq_print(FIQDBG_ERR, state, "CHHLT %02d", n);
  84217. + fiq_print(FIQDBG_ERR, state, "%08x", hcint.d32);
  84218. + return 0;
  84219. + }
  84220. + break;
  84221. +
  84222. + /* Non-periodic state groups */
  84223. + case FIQ_NP_SSPLIT_STARTED:
  84224. + case FIQ_NP_SSPLIT_RETRY:
  84225. + /* Got a HCINT for a NP SSPLIT. Expected ACK / NAK / fail */
  84226. + if (hcint.b.ack) {
  84227. + /* SSPLIT complete. For OUT, the data has been sent. For IN, the LS transaction
  84228. + * will start shortly. SOF needs to kick the transaction to prevent a NYET flood.
  84229. + */
  84230. + if(st->hcchar_copy.b.epdir == 1)
  84231. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  84232. + else
  84233. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  84234. + st->nr_errors = 0;
  84235. + handled = 1;
  84236. + fiq_fsm_setup_csplit(state, n);
  84237. + } else if (hcint.b.nak) {
  84238. + // No buffer space in TT. Retry on a uframe boundary.
  84239. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  84240. + handled = 1;
  84241. + } else if (hcint.b.xacterr) {
  84242. + // The only other one we care about is xacterr. This implies HS bus error - retry.
  84243. + st->nr_errors++;
  84244. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  84245. + if (st->nr_errors >= 3) {
  84246. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  84247. + } else {
  84248. + handled = 1;
  84249. + restart = 1;
  84250. + }
  84251. + } else {
  84252. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  84253. + handled = 0;
  84254. + restart = 0;
  84255. + }
  84256. + break;
  84257. +
  84258. + case FIQ_NP_IN_CSPLIT_RETRY:
  84259. + /* Received a CSPLIT done interrupt.
  84260. + * Expected Data/NAK/STALL/NYET for IN.
  84261. + */
  84262. + if (hcint.b.xfercomp) {
  84263. + /* For IN, data is present. */
  84264. + st->fsm = FIQ_NP_SPLIT_DONE;
  84265. + } else if (hcint.b.nak) {
  84266. + /* no endpoint data. Punt it upstairs */
  84267. + st->fsm = FIQ_NP_SPLIT_DONE;
  84268. + } else if (hcint.b.nyet) {
  84269. + /* CSPLIT NYET - retry on a uframe boundary. */
  84270. + handled = 1;
  84271. + st->nr_errors = 0;
  84272. + } else if (hcint.b.datatglerr) {
  84273. + /* data toggle errors do not set the xfercomp bit. */
  84274. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  84275. + } else if (hcint.b.xacterr) {
  84276. + /* HS error. Retry immediate */
  84277. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  84278. + st->nr_errors++;
  84279. + if (st->nr_errors >= 3) {
  84280. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  84281. + } else {
  84282. + handled = 1;
  84283. + restart = 1;
  84284. + }
  84285. + } else if (hcint.b.stall || hcint.b.bblerr) {
  84286. + /* A STALL implies either a LS bus error or a genuine STALL. */
  84287. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  84288. + } else {
  84289. + /* Hardware bug. It's possible in some cases to
  84290. + * get a channel halt with nothing else set when
  84291. + * the response was a NYET. Treat as local 3-strikes retry.
  84292. + */
  84293. + hcint_data_t hcint_test = hcint;
  84294. + hcint_test.b.chhltd = 0;
  84295. + if (!hcint_test.d32) {
  84296. + st->nr_errors++;
  84297. + if (st->nr_errors >= 3) {
  84298. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  84299. + } else {
  84300. + handled = 1;
  84301. + }
  84302. + } else {
  84303. + /* Bail out if something unexpected happened */
  84304. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  84305. + }
  84306. + }
  84307. + break;
  84308. +
  84309. + case FIQ_NP_OUT_CSPLIT_RETRY:
  84310. + /* Received a CSPLIT done interrupt.
  84311. + * Expected ACK/NAK/STALL/NYET/XFERCOMP for OUT.*/
  84312. + if (hcint.b.xfercomp) {
  84313. + st->fsm = FIQ_NP_SPLIT_DONE;
  84314. + } else if (hcint.b.nak) {
  84315. + // The HCD will implement the holdoff on frame boundaries.
  84316. + st->fsm = FIQ_NP_SPLIT_DONE;
  84317. + } else if (hcint.b.nyet) {
  84318. + // Hub still processing.
  84319. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  84320. + handled = 1;
  84321. + st->nr_errors = 0;
  84322. + //restart = 1;
  84323. + } else if (hcint.b.xacterr) {
  84324. + /* HS error. retry immediate */
  84325. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  84326. + st->nr_errors++;
  84327. + if (st->nr_errors >= 3) {
  84328. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  84329. + } else {
  84330. + handled = 1;
  84331. + restart = 1;
  84332. + }
  84333. + } else if (hcint.b.stall) {
  84334. + /* LS bus error or genuine stall */
  84335. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  84336. + } else {
  84337. + /*
  84338. + * Hardware bug. It's possible in some cases to get a
  84339. + * channel halt with nothing else set when the response was a NYET.
  84340. + * Treat as local 3-strikes retry.
  84341. + */
  84342. + hcint_data_t hcint_test = hcint;
  84343. + hcint_test.b.chhltd = 0;
  84344. + if (!hcint_test.d32) {
  84345. + st->nr_errors++;
  84346. + if (st->nr_errors >= 3) {
  84347. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  84348. + } else {
  84349. + handled = 1;
  84350. + }
  84351. + } else {
  84352. + // Something unexpected happened. AHBerror or babble perhaps. Let the IRQ deal with it.
  84353. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  84354. + }
  84355. + }
  84356. + break;
  84357. +
  84358. + /* Periodic split states (except isoc out) */
  84359. + case FIQ_PER_SSPLIT_STARTED:
  84360. + /* Expect an ACK or failure for SSPLIT */
  84361. + if (hcint.b.ack) {
  84362. + /*
  84363. + * SSPLIT transfer complete interrupt - the generation of this interrupt is fraught with bugs.
  84364. + * For a packet queued in microframe n-3 to appear in n-2, if the channel is enabled near the EOF1
  84365. + * point for microframe n-3, the packet will not appear on the bus until microframe n.
  84366. + * Additionally, the generation of the actual interrupt is dodgy. For a packet appearing on the bus
  84367. + * in microframe n, sometimes the interrupt is generated immediately. Sometimes, it appears in n+1
  84368. + * coincident with SOF for n+1.
  84369. + * SOF is also buggy. It can sometimes be raised AFTER the first bus transaction has taken place.
  84370. + * These appear to be caused by timing/clock crossing bugs within the core itself.
  84371. + * State machine workaround.
  84372. + */
  84373. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  84374. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  84375. + fiq_fsm_setup_csplit(state, n);
  84376. + /* Poke the oddfrm bit. If we are equivalent, we received the interrupt at the correct
  84377. + * time. If not, then we're in the next SOF.
  84378. + */
  84379. + if ((hfnum.b.frnum & 0x1) == hcchar.b.oddfrm) {
  84380. + fiq_print(FIQDBG_INT, state, "CSWAIT %01d", n);
  84381. + st->expected_uframe = hfnum.b.frnum;
  84382. + st->fsm = FIQ_PER_CSPLIT_WAIT;
  84383. + } else {
  84384. + fiq_print(FIQDBG_INT, state, "CSPOL %01d", n);
  84385. + /* For isochronous IN endpoints,
  84386. + * we need to hold off if we are expecting a lot of data */
  84387. + if (st->hcchar_copy.b.mps < DATA0_PID_HEURISTIC) {
  84388. + start_next_periodic = 1;
  84389. + }
  84390. + /* Danger will robinson: we are in a broken state. If our first interrupt after
  84391. + * this is a NYET, it will be delayed by 1 uframe and result in an unrecoverable
  84392. + * lag. Unmask the NYET interrupt.
  84393. + */
  84394. + st->expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  84395. + st->fsm = FIQ_PER_CSPLIT_BROKEN_NYET1;
  84396. + restart = 1;
  84397. + }
  84398. + handled = 1;
  84399. + } else if (hcint.b.xacterr) {
  84400. + /* 3-strikes retry is enabled, we have hit our max nr_errors */
  84401. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  84402. + start_next_periodic = 1;
  84403. + } else {
  84404. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  84405. + start_next_periodic = 1;
  84406. + }
  84407. + /* We can now queue the next isochronous OUT transaction, if one is pending. */
  84408. + if(fiq_fsm_tt_next_isoc(state, num_channels, n)) {
  84409. + fiq_print(FIQDBG_INT, state, "NEXTISO ");
  84410. + }
  84411. + break;
  84412. +
  84413. + case FIQ_PER_CSPLIT_NYET1:
  84414. + /* First CSPLIT attempt was a NYET. If we get a subsequent NYET,
  84415. + * we are too late and the TT has dropped its CSPLIT fifo.
  84416. + */
  84417. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  84418. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  84419. + start_next_periodic = 1;
  84420. + if (hcint.b.nak) {
  84421. + st->fsm = FIQ_PER_SPLIT_DONE;
  84422. + } else if (hcint.b.xfercomp) {
  84423. + fiq_increment_dma_buf(state, num_channels, n);
  84424. + st->fsm = FIQ_PER_CSPLIT_POLL;
  84425. + st->nr_errors = 0;
  84426. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  84427. + handled = 1;
  84428. + restart = 1;
  84429. + if (!last_csplit)
  84430. + start_next_periodic = 0;
  84431. + } else {
  84432. + st->fsm = FIQ_PER_SPLIT_DONE;
  84433. + }
  84434. + } else if (hcint.b.nyet) {
  84435. + /* Doh. Data lost. */
  84436. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  84437. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  84438. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  84439. + } else {
  84440. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  84441. + }
  84442. + break;
  84443. +
  84444. + case FIQ_PER_CSPLIT_BROKEN_NYET1:
  84445. + /*
  84446. + * we got here because our host channel is in the delayed-interrupt
  84447. + * state and we cannot take a NYET interrupt any later than when it
  84448. + * occurred. Disable then re-enable the channel if this happens to force
  84449. + * CSPLITs to occur at the right time.
  84450. + */
  84451. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  84452. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  84453. + fiq_print(FIQDBG_INT, state, "BROK: %01d ", n);
  84454. + if (hcint.b.nak) {
  84455. + st->fsm = FIQ_PER_SPLIT_DONE;
  84456. + start_next_periodic = 1;
  84457. + } else if (hcint.b.xfercomp) {
  84458. + fiq_increment_dma_buf(state, num_channels, n);
  84459. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  84460. + st->fsm = FIQ_PER_CSPLIT_POLL;
  84461. + handled = 1;
  84462. + restart = 1;
  84463. + start_next_periodic = 1;
  84464. + /* Reload HCTSIZ for the next transfer */
  84465. + fiq_fsm_reload_hctsiz(state, n);
  84466. + if (!last_csplit)
  84467. + start_next_periodic = 0;
  84468. + } else {
  84469. + st->fsm = FIQ_PER_SPLIT_DONE;
  84470. + }
  84471. + } else if (hcint.b.nyet) {
  84472. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  84473. + start_next_periodic = 1;
  84474. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  84475. + /* Local 3-strikes retry is handled by the core. This is a ERR response.*/
  84476. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  84477. + } else {
  84478. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  84479. + }
  84480. + break;
  84481. +
  84482. + case FIQ_PER_CSPLIT_POLL:
  84483. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  84484. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  84485. + start_next_periodic = 1;
  84486. + if (hcint.b.nak) {
  84487. + st->fsm = FIQ_PER_SPLIT_DONE;
  84488. + } else if (hcint.b.xfercomp) {
  84489. + fiq_increment_dma_buf(state, num_channels, n);
  84490. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  84491. + handled = 1;
  84492. + restart = 1;
  84493. + /* Reload HCTSIZ for the next transfer */
  84494. + fiq_fsm_reload_hctsiz(state, n);
  84495. + if (!last_csplit)
  84496. + start_next_periodic = 0;
  84497. + } else {
  84498. + st->fsm = FIQ_PER_SPLIT_DONE;
  84499. + }
  84500. + } else if (hcint.b.nyet) {
  84501. + /* Are we a NYET after the first data packet? */
  84502. + if (st->nrpackets == 0) {
  84503. + st->fsm = FIQ_PER_CSPLIT_NYET1;
  84504. + handled = 1;
  84505. + restart = 1;
  84506. + } else {
  84507. + /* We got a NYET when polling CSPLITs. Can happen
  84508. + * if our heuristic fails, or if someone disables us
  84509. + * for any significant length of time.
  84510. + */
  84511. + if (st->nr_errors >= 3) {
  84512. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  84513. + } else {
  84514. + st->fsm = FIQ_PER_SPLIT_DONE;
  84515. + }
  84516. + }
  84517. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  84518. + /* For xacterr, Local 3-strikes retry is handled by the core. This is a ERR response.*/
  84519. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  84520. + } else {
  84521. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  84522. + }
  84523. + break;
  84524. +
  84525. + case FIQ_HS_ISOC_TURBO:
  84526. + if (fiq_fsm_update_hs_isoc(state, n, hcint)) {
  84527. + /* more transactions to come */
  84528. + handled = 1;
  84529. + restart = 1;
  84530. + fiq_print(FIQDBG_INT, state, "HSISO M ");
  84531. + } else {
  84532. + st->fsm = FIQ_HS_ISOC_DONE;
  84533. + fiq_print(FIQDBG_INT, state, "HSISO F ");
  84534. + }
  84535. + break;
  84536. +
  84537. + case FIQ_HS_ISOC_ABORTED:
  84538. + /* This abort is called by the driver rewriting the state mid-transaction
  84539. + * which allows the dequeue mechanism to work more effectively.
  84540. + */
  84541. + break;
  84542. +
  84543. + case FIQ_PER_ISO_OUT_ACTIVE:
  84544. + if (hcint.b.ack) {
  84545. + if(fiq_iso_out_advance(state, num_channels, n)) {
  84546. + /* last OUT transfer */
  84547. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  84548. + /*
  84549. + * Assuming the periodic FIFO in the dwc core
  84550. + * actually does its job properly, we can queue
  84551. + * the next ssplit now and in theory, the wire
  84552. + * transactions will be in-order.
  84553. + */
  84554. + // No it doesn't. It appears to process requests in host channel order.
  84555. + //start_next_periodic = 1;
  84556. + }
  84557. + handled = 1;
  84558. + restart = 1;
  84559. + } else {
  84560. + /*
  84561. + * Isochronous transactions carry on regardless. Log the error
  84562. + * and continue.
  84563. + */
  84564. + //explode += 1;
  84565. + st->nr_errors++;
  84566. + if(fiq_iso_out_advance(state, num_channels, n)) {
  84567. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  84568. + //start_next_periodic = 1;
  84569. + }
  84570. + handled = 1;
  84571. + restart = 1;
  84572. + }
  84573. + break;
  84574. +
  84575. + case FIQ_PER_ISO_OUT_LAST:
  84576. + if (hcint.b.ack) {
  84577. + /* All done here */
  84578. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  84579. + } else {
  84580. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  84581. + st->nr_errors++;
  84582. + }
  84583. + start_next_periodic = 1;
  84584. + break;
  84585. +
  84586. + case FIQ_PER_SPLIT_TIMEOUT:
  84587. + /* SOF kicked us because we overran. */
  84588. + start_next_periodic = 1;
  84589. + break;
  84590. +
  84591. + default:
  84592. + break;
  84593. + }
  84594. +
  84595. + if (handled) {
  84596. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT, hcint.d32);
  84597. + } else {
  84598. + /* Copy the regs into the state so the IRQ knows what to do */
  84599. + st->hcint_copy.d32 = hcint.d32;
  84600. + }
  84601. +
  84602. + if (restart) {
  84603. + /* Restart always implies handled. */
  84604. + if (restart == 2) {
  84605. + /* For complete-split INs, the show must go on.
  84606. + * Force a channel restart */
  84607. + fiq_fsm_restart_channel(state, n, 1);
  84608. + } else {
  84609. + fiq_fsm_restart_channel(state, n, 0);
  84610. + }
  84611. + }
  84612. + if (start_next_periodic) {
  84613. + fiq_fsm_start_next_periodic(state, num_channels);
  84614. + }
  84615. + if (st->fsm != FIQ_PASSTHROUGH)
  84616. + fiq_print(FIQDBG_INT, state, "FSMOUT%02d", st->fsm);
  84617. +
  84618. + return handled;
  84619. +}
  84620. +
  84621. +
  84622. +/**
  84623. + * dwc_otg_fiq_fsm() - Flying State Machine (monster) FIQ
  84624. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  84625. + * @num_channels: set according to the DWC hardware configuration
  84626. + * @dma: pointer to DMA bounce buffers for split transaction slots
  84627. + *
  84628. + * The FSM FIQ performs the low-level tasks that normally would be performed by the microcode
  84629. + * inside an EHCI or similar host controller regarding split transactions. The DWC core
  84630. + * interrupts each and every time a split transaction packet is received or sent successfully.
  84631. + * This results in either an interrupt storm when everything is working "properly", or
  84632. + * the interrupt latency of the system in general breaks time-sensitive periodic split
  84633. + * transactions. Pushing the low-level, but relatively easy state machine work into the FIQ
  84634. + * solves these problems.
  84635. + *
  84636. + * Return: void
  84637. + */
  84638. +void notrace dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels)
  84639. +{
  84640. + gintsts_data_t gintsts, gintsts_handled;
  84641. + gintmsk_data_t gintmsk;
  84642. + //hfnum_data_t hfnum;
  84643. + haint_data_t haint, haint_handled;
  84644. + haintmsk_data_t haintmsk;
  84645. + int kick_irq = 0;
  84646. +
  84647. + gintsts_handled.d32 = 0;
  84648. + haint_handled.d32 = 0;
  84649. +
  84650. + fiq_fsm_spin_lock(&state->lock);
  84651. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  84652. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  84653. + gintsts.d32 &= gintmsk.d32;
  84654. +
  84655. + if (gintsts.b.sofintr) {
  84656. + /* For FSM mode, SOF is required to keep the state machine advance for
  84657. + * certain stages of the periodic pipeline. It's death to mask this
  84658. + * interrupt in that case.
  84659. + */
  84660. +
  84661. + if (!fiq_fsm_do_sof(state, num_channels)) {
  84662. + /* Kick IRQ once. Queue advancement means that all pending transactions
  84663. + * will get serviced when the IRQ finally executes.
  84664. + */
  84665. + if (state->gintmsk_saved.b.sofintr == 1)
  84666. + kick_irq |= 1;
  84667. + state->gintmsk_saved.b.sofintr = 0;
  84668. + }
  84669. + gintsts_handled.b.sofintr = 1;
  84670. + }
  84671. +
  84672. + if (gintsts.b.hcintr) {
  84673. + int i;
  84674. + haint.d32 = FIQ_READ(state->dwc_regs_base + HAINT);
  84675. + haintmsk.d32 = FIQ_READ(state->dwc_regs_base + HAINTMSK);
  84676. + haint.d32 &= haintmsk.d32;
  84677. + haint_handled.d32 = 0;
  84678. + for (i=0; i<num_channels; i++) {
  84679. + if (haint.b2.chint & (1 << i)) {
  84680. + if(!fiq_fsm_do_hcintr(state, num_channels, i)) {
  84681. + /* HCINT was not handled in FIQ
  84682. + * HAINT is level-sensitive, leading to level-sensitive ginststs.b.hcint bit.
  84683. + * Mask HAINT(i) but keep top-level hcint unmasked.
  84684. + */
  84685. + state->haintmsk_saved.b2.chint &= ~(1 << i);
  84686. + } else {
  84687. + /* do_hcintr cleaned up after itself, but clear haint */
  84688. + haint_handled.b2.chint |= (1 << i);
  84689. + }
  84690. + }
  84691. + }
  84692. +
  84693. + if (haint_handled.b2.chint) {
  84694. + FIQ_WRITE(state->dwc_regs_base + HAINT, haint_handled.d32);
  84695. + }
  84696. +
  84697. + if (haintmsk.d32 != (haintmsk.d32 & state->haintmsk_saved.d32)) {
  84698. + /*
  84699. + * This is necessary to avoid multiple retriggers of the MPHI in the case
  84700. + * where interrupts are held off and HCINTs start to pile up.
  84701. + * Only wake up the IRQ if a new interrupt came in, was not handled and was
  84702. + * masked.
  84703. + */
  84704. + haintmsk.d32 &= state->haintmsk_saved.d32;
  84705. + FIQ_WRITE(state->dwc_regs_base + HAINTMSK, haintmsk.d32);
  84706. + kick_irq |= 1;
  84707. + }
  84708. + /* Top-Level interrupt - always handled because it's level-sensitive */
  84709. + gintsts_handled.b.hcintr = 1;
  84710. + }
  84711. +
  84712. +
  84713. + /* Clear the bits in the saved register that were not handled but were triggered. */
  84714. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  84715. +
  84716. + /* FIQ didn't handle something - mask has changed - write new mask */
  84717. + if (gintmsk.d32 != (gintmsk.d32 & state->gintmsk_saved.d32)) {
  84718. + gintmsk.d32 &= state->gintmsk_saved.d32;
  84719. + gintmsk.b.sofintr = 1;
  84720. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  84721. +// fiq_print(FIQDBG_INT, state, "KICKGINT");
  84722. +// fiq_print(FIQDBG_INT, state, "%08x", gintmsk.d32);
  84723. +// fiq_print(FIQDBG_INT, state, "%08x", state->gintmsk_saved.d32);
  84724. + kick_irq |= 1;
  84725. + }
  84726. +
  84727. + if (gintsts_handled.d32) {
  84728. + /* Only applies to edge-sensitive bits in GINTSTS */
  84729. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  84730. + }
  84731. +
  84732. + /* We got an interrupt, didn't handle it. */
  84733. + if (kick_irq) {
  84734. + state->mphi_int_count++;
  84735. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  84736. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  84737. +
  84738. + }
  84739. + state->fiq_done++;
  84740. + mb();
  84741. + fiq_fsm_spin_unlock(&state->lock);
  84742. +}
  84743. +
  84744. +
  84745. +/**
  84746. + * dwc_otg_fiq_nop() - FIQ "lite"
  84747. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  84748. + *
  84749. + * The "nop" handler does not intervene on any interrupts other than SOF.
  84750. + * It is limited in scope to deciding at each SOF if the IRQ SOF handler (which deals
  84751. + * with non-periodic/periodic queues) needs to be kicked.
  84752. + *
  84753. + * This is done to hold off the SOF interrupt, which occurs at a rate of 8000 per second.
  84754. + *
  84755. + * Return: void
  84756. + */
  84757. +void notrace dwc_otg_fiq_nop(struct fiq_state *state)
  84758. +{
  84759. + gintsts_data_t gintsts, gintsts_handled;
  84760. + gintmsk_data_t gintmsk;
  84761. + hfnum_data_t hfnum;
  84762. +
  84763. + fiq_fsm_spin_lock(&state->lock);
  84764. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  84765. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  84766. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  84767. + gintsts.d32 &= gintmsk.d32;
  84768. + gintsts_handled.d32 = 0;
  84769. +
  84770. + if (gintsts.b.sofintr) {
  84771. + if (!state->kick_np_queues &&
  84772. + dwc_frame_num_gt(state->next_sched_frame, hfnum.b.frnum)) {
  84773. + /* SOF handled, no work to do, just ACK interrupt */
  84774. + gintsts_handled.b.sofintr = 1;
  84775. + } else {
  84776. + /* Kick IRQ */
  84777. + state->gintmsk_saved.b.sofintr = 0;
  84778. + }
  84779. + }
  84780. +
  84781. + /* Reset handled interrupts */
  84782. + if(gintsts_handled.d32) {
  84783. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  84784. + }
  84785. +
  84786. + /* Clear the bits in the saved register that were not handled but were triggered. */
  84787. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  84788. +
  84789. + /* We got an interrupt, didn't handle it and want to mask it */
  84790. + if (~(state->gintmsk_saved.d32)) {
  84791. + state->mphi_int_count++;
  84792. + gintmsk.d32 &= state->gintmsk_saved.d32;
  84793. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  84794. + /* Force a clear before another dummy send */
  84795. + FIQ_WRITE(state->mphi_regs.intstat, (1<<29));
  84796. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  84797. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  84798. +
  84799. + }
  84800. + state->fiq_done++;
  84801. + mb();
  84802. + fiq_fsm_spin_unlock(&state->lock);
  84803. +}
  84804. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
  84805. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 1970-01-01 01:00:00.000000000 +0100
  84806. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 2015-02-09 04:40:29.000000000 +0100
  84807. @@ -0,0 +1,367 @@
  84808. +/*
  84809. + * dwc_otg_fiq_fsm.h - Finite state machine FIQ header definitions
  84810. + *
  84811. + * Copyright (c) 2013 Raspberry Pi Foundation
  84812. + *
  84813. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  84814. + * All rights reserved.
  84815. + *
  84816. + * Redistribution and use in source and binary forms, with or without
  84817. + * modification, are permitted provided that the following conditions are met:
  84818. + * * Redistributions of source code must retain the above copyright
  84819. + * notice, this list of conditions and the following disclaimer.
  84820. + * * Redistributions in binary form must reproduce the above copyright
  84821. + * notice, this list of conditions and the following disclaimer in the
  84822. + * documentation and/or other materials provided with the distribution.
  84823. + * * Neither the name of Raspberry Pi nor the
  84824. + * names of its contributors may be used to endorse or promote products
  84825. + * derived from this software without specific prior written permission.
  84826. + *
  84827. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  84828. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  84829. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  84830. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  84831. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  84832. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  84833. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  84834. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  84835. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  84836. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  84837. + *
  84838. + * This FIQ implements functionality that performs split transactions on
  84839. + * the dwc_otg hardware without any outside intervention. A split transaction
  84840. + * is "queued" by nominating a specific host channel to perform the entirety
  84841. + * of a split transaction. This FIQ will then perform the microframe-precise
  84842. + * scheduling required in each phase of the transaction until completion.
  84843. + *
  84844. + * The FIQ functionality has been surgically implanted into the Synopsys
  84845. + * vendor-provided driver.
  84846. + *
  84847. + */
  84848. +
  84849. +#ifndef DWC_OTG_FIQ_FSM_H_
  84850. +#define DWC_OTG_FIQ_FSM_H_
  84851. +
  84852. +#include "dwc_otg_regs.h"
  84853. +#include "dwc_otg_cil.h"
  84854. +#include "dwc_otg_hcd.h"
  84855. +#include <linux/kernel.h>
  84856. +#include <linux/irqflags.h>
  84857. +#include <linux/string.h>
  84858. +#include <asm/barrier.h>
  84859. +
  84860. +#if 0
  84861. +#define FLAME_ON(x) \
  84862. +do { \
  84863. + int gpioreg; \
  84864. + \
  84865. + gpioreg = readl(__io_address(0x20200000+0x8)); \
  84866. + gpioreg &= ~(7 << (x-20)*3); \
  84867. + gpioreg |= 0x1 << (x-20)*3; \
  84868. + writel(gpioreg, __io_address(0x20200000+0x8)); \
  84869. + \
  84870. + writel(1<<x, __io_address(0x20200000+(0x1C))); \
  84871. +} while (0)
  84872. +
  84873. +#define FLAME_OFF(x) \
  84874. +do { \
  84875. + writel(1<<x, __io_address(0x20200000+(0x28))); \
  84876. +} while (0)
  84877. +#else
  84878. +#define FLAME_ON(x) do { } while (0)
  84879. +#define FLAME_OFF(X) do { } while (0)
  84880. +#endif
  84881. +
  84882. +/* This is a quick-and-dirty arch-specific register read/write. We know that
  84883. + * writes to a peripheral on BCM2835 will always arrive in-order, also that
  84884. + * reads and writes are executed in-order therefore the need for memory barriers
  84885. + * is obviated if we're only talking to USB.
  84886. + */
  84887. +#define FIQ_WRITE(_addr_,_data_) (*(volatile unsigned int *) (_addr_) = (_data_))
  84888. +#define FIQ_READ(_addr_) (*(volatile unsigned int *) (_addr_))
  84889. +
  84890. +/* FIQ-ified register definitions. Offsets are from dwc_regs_base. */
  84891. +#define GINTSTS 0x014
  84892. +#define GINTMSK 0x018
  84893. +/* Debug register. Poll the top of the received packets FIFO. */
  84894. +#define GRXSTSR 0x01C
  84895. +#define HFNUM 0x408
  84896. +#define HAINT 0x414
  84897. +#define HAINTMSK 0x418
  84898. +#define HPRT0 0x440
  84899. +
  84900. +/* HC_regs start from an offset of 0x500 */
  84901. +#define HC_START 0x500
  84902. +#define HC_OFFSET 0x020
  84903. +
  84904. +#define HC_DMA 0x514
  84905. +
  84906. +#define HCCHAR 0x00
  84907. +#define HCSPLT 0x04
  84908. +#define HCINT 0x08
  84909. +#define HCINTMSK 0x0C
  84910. +#define HCTSIZ 0x10
  84911. +
  84912. +#define ISOC_XACTPOS_ALL 0b11
  84913. +#define ISOC_XACTPOS_BEGIN 0b10
  84914. +#define ISOC_XACTPOS_MID 0b00
  84915. +#define ISOC_XACTPOS_END 0b01
  84916. +
  84917. +#define DWC_PID_DATA2 0b01
  84918. +#define DWC_PID_MDATA 0b11
  84919. +#define DWC_PID_DATA1 0b10
  84920. +#define DWC_PID_DATA0 0b00
  84921. +
  84922. +typedef struct {
  84923. + volatile void* base;
  84924. + volatile void* ctrl;
  84925. + volatile void* outdda;
  84926. + volatile void* outddb;
  84927. + volatile void* intstat;
  84928. +} mphi_regs_t;
  84929. +
  84930. +enum fiq_debug_level {
  84931. + FIQDBG_SCHED = (1 << 0),
  84932. + FIQDBG_INT = (1 << 1),
  84933. + FIQDBG_ERR = (1 << 2),
  84934. + FIQDBG_PORTHUB = (1 << 3),
  84935. +};
  84936. +
  84937. +typedef struct {
  84938. + union {
  84939. + uint32_t slock;
  84940. + struct _tickets {
  84941. + uint16_t owner;
  84942. + uint16_t next;
  84943. + } tickets;
  84944. + };
  84945. +} fiq_lock_t;
  84946. +
  84947. +struct fiq_state;
  84948. +
  84949. +extern void _fiq_print (enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...);
  84950. +#if 0
  84951. +#define fiq_print _fiq_print
  84952. +#else
  84953. +#define fiq_print(x, y, ...)
  84954. +#endif
  84955. +
  84956. +extern bool fiq_enable, fiq_fsm_enable;
  84957. +extern ushort nak_holdoff;
  84958. +
  84959. +/**
  84960. + * enum fiq_fsm_state - The FIQ FSM states.
  84961. + *
  84962. + * This is the "core" of the FIQ FSM. Broadly, the FSM states follow the
  84963. + * USB2.0 specification for host responses to various transaction states.
  84964. + * There are modifications to this host state machine because of a variety of
  84965. + * quirks and limitations in the dwc_otg hardware.
  84966. + *
  84967. + * The fsm state is also used to communicate back to the driver on completion of
  84968. + * a split transaction. The end states are used in conjunction with the interrupts
  84969. + * raised by the final transaction.
  84970. + */
  84971. +enum fiq_fsm_state {
  84972. + /* FIQ isn't enabled for this host channel */
  84973. + FIQ_PASSTHROUGH = 0,
  84974. + /* For the first interrupt received for this channel,
  84975. + * the FIQ has to ack any interrupts indicating success. */
  84976. + FIQ_PASSTHROUGH_ERRORSTATE = 31,
  84977. + /* Nonperiodic state groups */
  84978. + FIQ_NP_SSPLIT_STARTED = 1,
  84979. + FIQ_NP_SSPLIT_RETRY = 2,
  84980. + FIQ_NP_OUT_CSPLIT_RETRY = 3,
  84981. + FIQ_NP_IN_CSPLIT_RETRY = 4,
  84982. + FIQ_NP_SPLIT_DONE = 5,
  84983. + FIQ_NP_SPLIT_LS_ABORTED = 6,
  84984. + /* This differentiates a HS transaction error from a LS one
  84985. + * (handling the hub state is different) */
  84986. + FIQ_NP_SPLIT_HS_ABORTED = 7,
  84987. +
  84988. + /* Periodic state groups */
  84989. + /* Periodic transactions are either started directly by the IRQ handler
  84990. + * or deferred if the TT is already in use.
  84991. + */
  84992. + FIQ_PER_SSPLIT_QUEUED = 8,
  84993. + FIQ_PER_SSPLIT_STARTED = 9,
  84994. + FIQ_PER_SSPLIT_LAST = 10,
  84995. +
  84996. +
  84997. + FIQ_PER_ISO_OUT_PENDING = 11,
  84998. + FIQ_PER_ISO_OUT_ACTIVE = 12,
  84999. + FIQ_PER_ISO_OUT_LAST = 13,
  85000. + FIQ_PER_ISO_OUT_DONE = 27,
  85001. +
  85002. + FIQ_PER_CSPLIT_WAIT = 14,
  85003. + FIQ_PER_CSPLIT_NYET1 = 15,
  85004. + FIQ_PER_CSPLIT_BROKEN_NYET1 = 28,
  85005. + FIQ_PER_CSPLIT_NYET_FAFF = 29,
  85006. + /* For multiple CSPLITs (large isoc IN, or delayed interrupt) */
  85007. + FIQ_PER_CSPLIT_POLL = 16,
  85008. + /* The last CSPLIT for a transaction has been issued, differentiates
  85009. + * for the state machine to queue the next packet.
  85010. + */
  85011. + FIQ_PER_CSPLIT_LAST = 17,
  85012. +
  85013. + FIQ_PER_SPLIT_DONE = 18,
  85014. + FIQ_PER_SPLIT_LS_ABORTED = 19,
  85015. + FIQ_PER_SPLIT_HS_ABORTED = 20,
  85016. + FIQ_PER_SPLIT_NYET_ABORTED = 21,
  85017. + /* Frame rollover has occurred without the transaction finishing. */
  85018. + FIQ_PER_SPLIT_TIMEOUT = 22,
  85019. +
  85020. + /* FIQ-accelerated HS Isochronous state groups */
  85021. + FIQ_HS_ISOC_TURBO = 23,
  85022. + /* For interval > 1, SOF wakes up the isochronous FSM */
  85023. + FIQ_HS_ISOC_SLEEPING = 24,
  85024. + FIQ_HS_ISOC_DONE = 25,
  85025. + FIQ_HS_ISOC_ABORTED = 26,
  85026. + FIQ_DEQUEUE_ISSUED = 30,
  85027. + FIQ_TEST = 32,
  85028. +};
  85029. +
  85030. +struct fiq_stack {
  85031. + int magic1;
  85032. + uint8_t stack[2048];
  85033. + int magic2;
  85034. +};
  85035. +
  85036. +
  85037. +/**
  85038. + * struct fiq_dma_info - DMA bounce buffer utilisation information (per-channel)
  85039. + * @index: Number of slots reported used for IN transactions / number of slots
  85040. + * transmitted for an OUT transaction
  85041. + * @slot_len[6]: Number of actual transfer bytes in each slot (255 if unused)
  85042. + *
  85043. + * Split transaction transfers can have variable length depending on other bus
  85044. + * traffic. The OTG core DMA engine requires 4-byte aligned addresses therefore
  85045. + * each transaction needs a guaranteed aligned address. A maximum of 6 split transfers
  85046. + * can happen per-frame.
  85047. + */
  85048. +struct fiq_dma_info {
  85049. + u8 index;
  85050. + u8 slot_len[6];
  85051. +};
  85052. +
  85053. +struct __attribute__((packed)) fiq_split_dma_slot {
  85054. + u8 buf[188];
  85055. +};
  85056. +
  85057. +struct fiq_dma_channel {
  85058. + struct __attribute__((packed)) fiq_split_dma_slot index[6];
  85059. +};
  85060. +
  85061. +struct fiq_dma_blob {
  85062. + struct __attribute__((packed)) fiq_dma_channel channel[0];
  85063. +};
  85064. +
  85065. +/**
  85066. + * struct fiq_hs_isoc_info - USB2.0 isochronous data
  85067. + * @iso_frame: Pointer to the array of OTG URB iso_frame_descs.
  85068. + * @nrframes: Total length of iso_frame_desc array
  85069. + * @index: Current index (FIQ-maintained)
  85070. + *
  85071. + */
  85072. +struct fiq_hs_isoc_info {
  85073. + struct dwc_otg_hcd_iso_packet_desc *iso_desc;
  85074. + unsigned int nrframes;
  85075. + unsigned int index;
  85076. +};
  85077. +
  85078. +/**
  85079. + * struct fiq_channel_state - FIQ state machine storage
  85080. + * @fsm: Current state of the channel as understood by the FIQ
  85081. + * @nr_errors: Number of transaction errors on this split-transaction
  85082. + * @hub_addr: SSPLIT/CSPLIT destination hub
  85083. + * @port_addr: SSPLIT/CSPLIT destination port - always 1 if single TT hub
  85084. + * @nrpackets: For isoc OUT, the number of split-OUT packets to transmit. For
  85085. + * split-IN, number of CSPLIT data packets that were received.
  85086. + * @hcchar_copy:
  85087. + * @hcsplt_copy:
  85088. + * @hcintmsk_copy:
  85089. + * @hctsiz_copy: Copies of the host channel registers.
  85090. + * For use as scratch, or for returning state.
  85091. + *
  85092. + * The fiq_channel_state is state storage between interrupts for a host channel. The
  85093. + * FSM state is stored here. Members of this structure must only be set up by the
  85094. + * driver prior to enabling the FIQ for this host channel, and not touched until the FIQ
  85095. + * has updated the state to either a COMPLETE state group or ABORT state group.
  85096. + */
  85097. +
  85098. +struct fiq_channel_state {
  85099. + enum fiq_fsm_state fsm;
  85100. + unsigned int nr_errors;
  85101. + unsigned int hub_addr;
  85102. + unsigned int port_addr;
  85103. + /* Hardware bug workaround: sometimes channel halt interrupts are
  85104. + * delayed until the next SOF. Keep track of when we expected to get interrupted. */
  85105. + unsigned int expected_uframe;
  85106. + /* in/out for communicating number of dma buffers used, or number of ISOC to do */
  85107. + unsigned int nrpackets;
  85108. + struct fiq_dma_info dma_info;
  85109. + struct fiq_hs_isoc_info hs_isoc_info;
  85110. + /* Copies of HC registers - in/out communication from/to IRQ handler
  85111. + * and for ease of channel setup. A bit of mungeing is performed - for
  85112. + * example the hctsiz.b.maxp is _always_ the max packet size of the endpoint.
  85113. + */
  85114. + hcchar_data_t hcchar_copy;
  85115. + hcsplt_data_t hcsplt_copy;
  85116. + hcint_data_t hcint_copy;
  85117. + hcintmsk_data_t hcintmsk_copy;
  85118. + hctsiz_data_t hctsiz_copy;
  85119. + hcdma_data_t hcdma_copy;
  85120. +};
  85121. +
  85122. +/**
  85123. + * struct fiq_state - top-level FIQ state machine storage
  85124. + * @mphi_regs: virtual address of the MPHI peripheral register file
  85125. + * @dwc_regs_base: virtual address of the base of the DWC core register file
  85126. + * @dma_base: physical address for the base of the DMA bounce buffers
  85127. + * @dummy_send: Scratch area for sending a fake message to the MPHI peripheral
  85128. + * @gintmsk_saved: Top-level mask of interrupts that the FIQ has not handled.
  85129. + * Used for determining which interrupts fired to set off the IRQ handler.
  85130. + * @haintmsk_saved: Mask of interrupts from host channels that the FIQ did not handle internally.
  85131. + * @np_count: Non-periodic transactions in the active queue
  85132. + * @np_sent: Count of non-periodic transactions that have completed
  85133. + * @next_sched_frame: For periodic transactions handled by the driver's SOF-driven queuing mechanism,
  85134. + * this is the next frame on which a SOF interrupt is required. Used to hold off
  85135. + * passing SOF through to the driver until necessary.
  85136. + * @channel[n]: Per-channel FIQ state. Allocated during init depending on the number of host
  85137. + * channels configured into the core logic.
  85138. + *
  85139. + * This is passed as the first argument to the dwc_otg_fiq_fsm top-level FIQ handler from the asm stub.
  85140. + * It contains top-level state information.
  85141. + */
  85142. +struct fiq_state {
  85143. + fiq_lock_t lock;
  85144. + mphi_regs_t mphi_regs;
  85145. + void *dwc_regs_base;
  85146. + dma_addr_t dma_base;
  85147. + struct fiq_dma_blob *fiq_dmab;
  85148. + void *dummy_send;
  85149. + gintmsk_data_t gintmsk_saved;
  85150. + haintmsk_data_t haintmsk_saved;
  85151. + int mphi_int_count;
  85152. + unsigned int fiq_done;
  85153. + unsigned int kick_np_queues;
  85154. + unsigned int next_sched_frame;
  85155. +#ifdef FIQ_DEBUG
  85156. + char * buffer;
  85157. + unsigned int bufsiz;
  85158. +#endif
  85159. + struct fiq_channel_state channel[0];
  85160. +};
  85161. +
  85162. +extern void fiq_fsm_spin_lock(fiq_lock_t *lock);
  85163. +
  85164. +extern void fiq_fsm_spin_unlock(fiq_lock_t *lock);
  85165. +
  85166. +extern int fiq_fsm_too_late(struct fiq_state *st, int n);
  85167. +
  85168. +extern int fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n);
  85169. +
  85170. +extern void dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels);
  85171. +
  85172. +extern void dwc_otg_fiq_nop(struct fiq_state *state);
  85173. +
  85174. +#endif /* DWC_OTG_FIQ_FSM_H_ */
  85175. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S
  85176. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 1970-01-01 01:00:00.000000000 +0100
  85177. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 2015-02-09 04:40:29.000000000 +0100
  85178. @@ -0,0 +1,81 @@
  85179. +/*
  85180. + * dwc_otg_fiq_fsm.S - assembly stub for the FSM FIQ
  85181. + *
  85182. + * Copyright (c) 2013 Raspberry Pi Foundation
  85183. + *
  85184. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  85185. + * All rights reserved.
  85186. + *
  85187. + * Redistribution and use in source and binary forms, with or without
  85188. + * modification, are permitted provided that the following conditions are met:
  85189. + * * Redistributions of source code must retain the above copyright
  85190. + * notice, this list of conditions and the following disclaimer.
  85191. + * * Redistributions in binary form must reproduce the above copyright
  85192. + * notice, this list of conditions and the following disclaimer in the
  85193. + * documentation and/or other materials provided with the distribution.
  85194. + * * Neither the name of Raspberry Pi nor the
  85195. + * names of its contributors may be used to endorse or promote products
  85196. + * derived from this software without specific prior written permission.
  85197. + *
  85198. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  85199. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  85200. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  85201. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  85202. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  85203. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  85204. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  85205. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  85206. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  85207. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  85208. + */
  85209. +
  85210. +
  85211. +#include <asm/assembler.h>
  85212. +#include <linux/linkage.h>
  85213. +
  85214. +
  85215. +.text
  85216. +
  85217. +.global _dwc_otg_fiq_stub_end;
  85218. +
  85219. +/**
  85220. + * _dwc_otg_fiq_stub() - entry copied to the FIQ vector page to allow
  85221. + * a C-style function call with arguments from the FIQ banked registers.
  85222. + * r0 = &hcd->fiq_state
  85223. + * r1 = &hcd->num_channels
  85224. + * r2 = &hcd->dma_buffers
  85225. + * Tramples: r0, r1, r2, r4, fp, ip
  85226. + */
  85227. +
  85228. +ENTRY(_dwc_otg_fiq_stub)
  85229. + /* Stash unbanked regs - SP will have been set up for us */
  85230. + mov ip, sp;
  85231. + stmdb sp!, {r0-r12, lr};
  85232. +#ifdef FIQ_DEBUG
  85233. + // Cycle profiling - read cycle counter at start
  85234. + mrc p15, 0, r5, c15, c12, 1;
  85235. +#endif
  85236. + /* r11 = fp, don't trample it */
  85237. + mov r4, fp;
  85238. + /* set EABI frame size */
  85239. + sub fp, ip, #512;
  85240. +
  85241. + /* for fiq NOP mode - just need state */
  85242. + mov r0, r8;
  85243. + /* r9 = num_channels */
  85244. + mov r1, r9;
  85245. + /* r10 = struct *dma_bufs */
  85246. +// mov r2, r10;
  85247. +
  85248. + /* r4 = &fiq_c_function */
  85249. + blx r4;
  85250. +#ifdef FIQ_DEBUG
  85251. + mrc p15, 0, r4, c15, c12, 1;
  85252. + subs r5, r5, r4;
  85253. + // r5 is now the cycle count time for executing the FIQ. Store it somewhere?
  85254. +#endif
  85255. + ldmia sp!, {r0-r12, lr};
  85256. + subs pc, lr, #4;
  85257. +_dwc_otg_fiq_stub_end:
  85258. +END(_dwc_otg_fiq_stub)
  85259. +
  85260. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_hcd.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
  85261. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 1970-01-01 01:00:00.000000000 +0100
  85262. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 2015-02-09 04:40:29.000000000 +0100
  85263. @@ -0,0 +1,4244 @@
  85264. +
  85265. +/* ==========================================================================
  85266. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.c $
  85267. + * $Revision: #104 $
  85268. + * $Date: 2011/10/24 $
  85269. + * $Change: 1871159 $
  85270. + *
  85271. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  85272. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  85273. + * otherwise expressly agreed to in writing between Synopsys and you.
  85274. + *
  85275. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  85276. + * any End User Software License Agreement or Agreement for Licensed Product
  85277. + * with Synopsys or any supplement thereto. You are permitted to use and
  85278. + * redistribute this Software in source and binary forms, with or without
  85279. + * modification, provided that redistributions of source code must retain this
  85280. + * notice. You may not view, use, disclose, copy or distribute this file or
  85281. + * any information contained herein except pursuant to this license grant from
  85282. + * Synopsys. If you do not agree with this notice, including the disclaimer
  85283. + * below, then you are not authorized to use the Software.
  85284. + *
  85285. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  85286. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  85287. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  85288. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  85289. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  85290. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  85291. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  85292. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  85293. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  85294. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  85295. + * DAMAGE.
  85296. + * ========================================================================== */
  85297. +#ifndef DWC_DEVICE_ONLY
  85298. +
  85299. +/** @file
  85300. + * This file implements HCD Core. All code in this file is portable and doesn't
  85301. + * use any OS specific functions.
  85302. + * Interface provided by HCD Core is defined in <code><hcd_if.h></code>
  85303. + * header file.
  85304. + */
  85305. +
  85306. +#include <linux/usb.h>
  85307. +#include <linux/usb/hcd.h>
  85308. +
  85309. +#include "dwc_otg_hcd.h"
  85310. +#include "dwc_otg_regs.h"
  85311. +#include "dwc_otg_fiq_fsm.h"
  85312. +
  85313. +extern bool microframe_schedule;
  85314. +extern uint16_t fiq_fsm_mask, nak_holdoff;
  85315. +
  85316. +//#define DEBUG_HOST_CHANNELS
  85317. +#ifdef DEBUG_HOST_CHANNELS
  85318. +static int last_sel_trans_num_per_scheduled = 0;
  85319. +static int last_sel_trans_num_nonper_scheduled = 0;
  85320. +static int last_sel_trans_num_avail_hc_at_start = 0;
  85321. +static int last_sel_trans_num_avail_hc_at_end = 0;
  85322. +#endif /* DEBUG_HOST_CHANNELS */
  85323. +
  85324. +
  85325. +dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
  85326. +{
  85327. + return DWC_ALLOC(sizeof(dwc_otg_hcd_t));
  85328. +}
  85329. +
  85330. +/**
  85331. + * Connection timeout function. An OTG host is required to display a
  85332. + * message if the device does not connect within 10 seconds.
  85333. + */
  85334. +void dwc_otg_hcd_connect_timeout(void *ptr)
  85335. +{
  85336. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, ptr);
  85337. + DWC_PRINTF("Connect Timeout\n");
  85338. + __DWC_ERROR("Device Not Connected/Responding\n");
  85339. +}
  85340. +
  85341. +#if defined(DEBUG)
  85342. +static void dump_channel_info(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  85343. +{
  85344. + if (qh->channel != NULL) {
  85345. + dwc_hc_t *hc = qh->channel;
  85346. + dwc_list_link_t *item;
  85347. + dwc_otg_qh_t *qh_item;
  85348. + int num_channels = hcd->core_if->core_params->host_channels;
  85349. + int i;
  85350. +
  85351. + dwc_otg_hc_regs_t *hc_regs;
  85352. + hcchar_data_t hcchar;
  85353. + hcsplt_data_t hcsplt;
  85354. + hctsiz_data_t hctsiz;
  85355. + uint32_t hcdma;
  85356. +
  85357. + hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  85358. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  85359. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  85360. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  85361. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  85362. +
  85363. + DWC_PRINTF(" Assigned to channel %p:\n", hc);
  85364. + DWC_PRINTF(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32,
  85365. + hcsplt.d32);
  85366. + DWC_PRINTF(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32,
  85367. + hcdma);
  85368. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  85369. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  85370. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  85371. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  85372. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  85373. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  85374. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  85375. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  85376. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  85377. + DWC_PRINTF(" qh: %p\n", hc->qh);
  85378. + DWC_PRINTF(" NP inactive sched:\n");
  85379. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_inactive) {
  85380. + qh_item =
  85381. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  85382. + DWC_PRINTF(" %p\n", qh_item);
  85383. + }
  85384. + DWC_PRINTF(" NP active sched:\n");
  85385. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_active) {
  85386. + qh_item =
  85387. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  85388. + DWC_PRINTF(" %p\n", qh_item);
  85389. + }
  85390. + DWC_PRINTF(" Channels: \n");
  85391. + for (i = 0; i < num_channels; i++) {
  85392. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  85393. + DWC_PRINTF(" %2d: %p\n", i, hc);
  85394. + }
  85395. + }
  85396. +}
  85397. +#else
  85398. +#define dump_channel_info(hcd, qh)
  85399. +#endif /* DEBUG */
  85400. +
  85401. +/**
  85402. + * Work queue function for starting the HCD when A-Cable is connected.
  85403. + * The hcd_start() must be called in a process context.
  85404. + */
  85405. +static void hcd_start_func(void *_vp)
  85406. +{
  85407. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) _vp;
  85408. +
  85409. + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, hcd);
  85410. + if (hcd) {
  85411. + hcd->fops->start(hcd);
  85412. + }
  85413. +}
  85414. +
  85415. +static void del_xfer_timers(dwc_otg_hcd_t * hcd)
  85416. +{
  85417. +#ifdef DEBUG
  85418. + int i;
  85419. + int num_channels = hcd->core_if->core_params->host_channels;
  85420. + for (i = 0; i < num_channels; i++) {
  85421. + DWC_TIMER_CANCEL(hcd->core_if->hc_xfer_timer[i]);
  85422. + }
  85423. +#endif
  85424. +}
  85425. +
  85426. +static void del_timers(dwc_otg_hcd_t * hcd)
  85427. +{
  85428. + del_xfer_timers(hcd);
  85429. + DWC_TIMER_CANCEL(hcd->conn_timer);
  85430. +}
  85431. +
  85432. +/**
  85433. + * Processes all the URBs in a single list of QHs. Completes them with
  85434. + * -ESHUTDOWN and frees the QTD.
  85435. + */
  85436. +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  85437. +{
  85438. + dwc_list_link_t *qh_item, *qh_tmp;
  85439. + dwc_otg_qh_t *qh;
  85440. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  85441. +
  85442. + DWC_LIST_FOREACH_SAFE(qh_item, qh_tmp, qh_list) {
  85443. + qh = DWC_LIST_ENTRY(qh_item, dwc_otg_qh_t, qh_list_entry);
  85444. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp,
  85445. + &qh->qtd_list, qtd_list_entry) {
  85446. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  85447. + if (qtd->urb != NULL) {
  85448. + hcd->fops->complete(hcd, qtd->urb->priv,
  85449. + qtd->urb, -DWC_E_SHUTDOWN);
  85450. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  85451. + }
  85452. +
  85453. + }
  85454. + if(qh->channel) {
  85455. + /* Using hcchar.chen == 1 is not a reliable test.
  85456. + * It is possible that the channel has already halted
  85457. + * but not yet been through the IRQ handler.
  85458. + */
  85459. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  85460. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  85461. + if(microframe_schedule)
  85462. + hcd->available_host_channels++;
  85463. + qh->channel = NULL;
  85464. + }
  85465. + dwc_otg_hcd_qh_remove(hcd, qh);
  85466. + }
  85467. +}
  85468. +
  85469. +/**
  85470. + * Responds with an error status of ESHUTDOWN to all URBs in the non-periodic
  85471. + * and periodic schedules. The QTD associated with each URB is removed from
  85472. + * the schedule and freed. This function may be called when a disconnect is
  85473. + * detected or when the HCD is being stopped.
  85474. + */
  85475. +static void kill_all_urbs(dwc_otg_hcd_t * hcd)
  85476. +{
  85477. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_inactive);
  85478. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_active);
  85479. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_inactive);
  85480. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_ready);
  85481. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_assigned);
  85482. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_queued);
  85483. +}
  85484. +
  85485. +/**
  85486. + * Start the connection timer. An OTG host is required to display a
  85487. + * message if the device does not connect within 10 seconds. The
  85488. + * timer is deleted if a port connect interrupt occurs before the
  85489. + * timer expires.
  85490. + */
  85491. +static void dwc_otg_hcd_start_connect_timer(dwc_otg_hcd_t * hcd)
  85492. +{
  85493. + DWC_TIMER_SCHEDULE(hcd->conn_timer, 10000 /* 10 secs */ );
  85494. +}
  85495. +
  85496. +/**
  85497. + * HCD Callback function for disconnect of the HCD.
  85498. + *
  85499. + * @param p void pointer to the <code>struct usb_hcd</code>
  85500. + */
  85501. +static int32_t dwc_otg_hcd_session_start_cb(void *p)
  85502. +{
  85503. + dwc_otg_hcd_t *dwc_otg_hcd;
  85504. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  85505. + dwc_otg_hcd = p;
  85506. + dwc_otg_hcd_start_connect_timer(dwc_otg_hcd);
  85507. + return 1;
  85508. +}
  85509. +
  85510. +/**
  85511. + * HCD Callback function for starting the HCD when A-Cable is
  85512. + * connected.
  85513. + *
  85514. + * @param p void pointer to the <code>struct usb_hcd</code>
  85515. + */
  85516. +static int32_t dwc_otg_hcd_start_cb(void *p)
  85517. +{
  85518. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  85519. + dwc_otg_core_if_t *core_if;
  85520. + hprt0_data_t hprt0;
  85521. +
  85522. + core_if = dwc_otg_hcd->core_if;
  85523. +
  85524. + if (core_if->op_state == B_HOST) {
  85525. + /*
  85526. + * Reset the port. During a HNP mode switch the reset
  85527. + * needs to occur within 1ms and have a duration of at
  85528. + * least 50ms.
  85529. + */
  85530. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  85531. + hprt0.b.prtrst = 1;
  85532. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  85533. + }
  85534. + DWC_WORKQ_SCHEDULE_DELAYED(core_if->wq_otg,
  85535. + hcd_start_func, dwc_otg_hcd, 50,
  85536. + "start hcd");
  85537. +
  85538. + return 1;
  85539. +}
  85540. +
  85541. +/**
  85542. + * HCD Callback function for disconnect of the HCD.
  85543. + *
  85544. + * @param p void pointer to the <code>struct usb_hcd</code>
  85545. + */
  85546. +static int32_t dwc_otg_hcd_disconnect_cb(void *p)
  85547. +{
  85548. + gintsts_data_t intr;
  85549. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  85550. +
  85551. + /*
  85552. + * Set status flags for the hub driver.
  85553. + */
  85554. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  85555. + dwc_otg_hcd->flags.b.port_connect_status = 0;
  85556. + if(fiq_enable)
  85557. + local_fiq_disable();
  85558. + /*
  85559. + * Shutdown any transfers in process by clearing the Tx FIFO Empty
  85560. + * interrupt mask and status bits and disabling subsequent host
  85561. + * channel interrupts.
  85562. + */
  85563. + intr.d32 = 0;
  85564. + intr.b.nptxfempty = 1;
  85565. + intr.b.ptxfempty = 1;
  85566. + intr.b.hcintr = 1;
  85567. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk,
  85568. + intr.d32, 0);
  85569. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintsts,
  85570. + intr.d32, 0);
  85571. +
  85572. + del_timers(dwc_otg_hcd);
  85573. +
  85574. + /*
  85575. + * Turn off the vbus power only if the core has transitioned to device
  85576. + * mode. If still in host mode, need to keep power on to detect a
  85577. + * reconnection.
  85578. + */
  85579. + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
  85580. + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
  85581. + hprt0_data_t hprt0 = {.d32 = 0 };
  85582. + DWC_PRINTF("Disconnect: PortPower off\n");
  85583. + hprt0.b.prtpwr = 0;
  85584. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0,
  85585. + hprt0.d32);
  85586. + }
  85587. +
  85588. + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
  85589. + }
  85590. +
  85591. + /* Respond with an error status to all URBs in the schedule. */
  85592. + kill_all_urbs(dwc_otg_hcd);
  85593. +
  85594. + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
  85595. + /* Clean up any host channels that were in use. */
  85596. + int num_channels;
  85597. + int i;
  85598. + dwc_hc_t *channel;
  85599. + dwc_otg_hc_regs_t *hc_regs;
  85600. + hcchar_data_t hcchar;
  85601. +
  85602. + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
  85603. +
  85604. + if (!dwc_otg_hcd->core_if->dma_enable) {
  85605. + /* Flush out any channel requests in slave mode. */
  85606. + for (i = 0; i < num_channels; i++) {
  85607. + channel = dwc_otg_hcd->hc_ptr_array[i];
  85608. + if (DWC_CIRCLEQ_EMPTY_ENTRY
  85609. + (channel, hc_list_entry)) {
  85610. + hc_regs =
  85611. + dwc_otg_hcd->core_if->
  85612. + host_if->hc_regs[i];
  85613. + hcchar.d32 =
  85614. + DWC_READ_REG32(&hc_regs->hcchar);
  85615. + if (hcchar.b.chen) {
  85616. + hcchar.b.chen = 0;
  85617. + hcchar.b.chdis = 1;
  85618. + hcchar.b.epdir = 0;
  85619. + DWC_WRITE_REG32
  85620. + (&hc_regs->hcchar,
  85621. + hcchar.d32);
  85622. + }
  85623. + }
  85624. + }
  85625. + }
  85626. +
  85627. + for (i = 0; i < num_channels; i++) {
  85628. + channel = dwc_otg_hcd->hc_ptr_array[i];
  85629. + if (DWC_CIRCLEQ_EMPTY_ENTRY(channel, hc_list_entry)) {
  85630. + hc_regs =
  85631. + dwc_otg_hcd->core_if->host_if->hc_regs[i];
  85632. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  85633. + if (hcchar.b.chen) {
  85634. + /* Halt the channel. */
  85635. + hcchar.b.chdis = 1;
  85636. + DWC_WRITE_REG32(&hc_regs->hcchar,
  85637. + hcchar.d32);
  85638. + }
  85639. +
  85640. + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if,
  85641. + channel);
  85642. + DWC_CIRCLEQ_INSERT_TAIL
  85643. + (&dwc_otg_hcd->free_hc_list, channel,
  85644. + hc_list_entry);
  85645. + /*
  85646. + * Added for Descriptor DMA to prevent channel double cleanup
  85647. + * in release_channel_ddma(). Which called from ep_disable
  85648. + * when device disconnect.
  85649. + */
  85650. + channel->qh = NULL;
  85651. + }
  85652. + }
  85653. + if(fiq_fsm_enable) {
  85654. + for(i=0; i < 128; i++) {
  85655. + dwc_otg_hcd->hub_port[i] = 0;
  85656. + }
  85657. + }
  85658. +
  85659. + }
  85660. +
  85661. + if(fiq_enable)
  85662. + local_fiq_enable();
  85663. +
  85664. + if (dwc_otg_hcd->fops->disconnect) {
  85665. + dwc_otg_hcd->fops->disconnect(dwc_otg_hcd);
  85666. + }
  85667. +
  85668. + return 1;
  85669. +}
  85670. +
  85671. +/**
  85672. + * HCD Callback function for stopping the HCD.
  85673. + *
  85674. + * @param p void pointer to the <code>struct usb_hcd</code>
  85675. + */
  85676. +static int32_t dwc_otg_hcd_stop_cb(void *p)
  85677. +{
  85678. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  85679. +
  85680. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  85681. + dwc_otg_hcd_stop(dwc_otg_hcd);
  85682. + return 1;
  85683. +}
  85684. +
  85685. +#ifdef CONFIG_USB_DWC_OTG_LPM
  85686. +/**
  85687. + * HCD Callback function for sleep of HCD.
  85688. + *
  85689. + * @param p void pointer to the <code>struct usb_hcd</code>
  85690. + */
  85691. +static int dwc_otg_hcd_sleep_cb(void *p)
  85692. +{
  85693. + dwc_otg_hcd_t *hcd = p;
  85694. +
  85695. + dwc_otg_hcd_free_hc_from_lpm(hcd);
  85696. +
  85697. + return 0;
  85698. +}
  85699. +#endif
  85700. +
  85701. +
  85702. +/**
  85703. + * HCD Callback function for Remote Wakeup.
  85704. + *
  85705. + * @param p void pointer to the <code>struct usb_hcd</code>
  85706. + */
  85707. +static int dwc_otg_hcd_rem_wakeup_cb(void *p)
  85708. +{
  85709. + dwc_otg_hcd_t *hcd = p;
  85710. +
  85711. + if (hcd->core_if->lx_state == DWC_OTG_L2) {
  85712. + hcd->flags.b.port_suspend_change = 1;
  85713. + }
  85714. +#ifdef CONFIG_USB_DWC_OTG_LPM
  85715. + else {
  85716. + hcd->flags.b.port_l1_change = 1;
  85717. + }
  85718. +#endif
  85719. + return 0;
  85720. +}
  85721. +
  85722. +/**
  85723. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  85724. + * stopped.
  85725. + */
  85726. +void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd)
  85727. +{
  85728. + hprt0_data_t hprt0 = {.d32 = 0 };
  85729. +
  85730. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
  85731. +
  85732. + /*
  85733. + * The root hub should be disconnected before this function is called.
  85734. + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
  85735. + * and the QH lists (via ..._hcd_endpoint_disable).
  85736. + */
  85737. +
  85738. + /* Turn off all host-specific interrupts. */
  85739. + dwc_otg_disable_host_interrupts(hcd->core_if);
  85740. +
  85741. + /* Turn off the vbus power */
  85742. + DWC_PRINTF("PortPower off\n");
  85743. + hprt0.b.prtpwr = 0;
  85744. + DWC_WRITE_REG32(hcd->core_if->host_if->hprt0, hprt0.d32);
  85745. + dwc_mdelay(1);
  85746. +}
  85747. +
  85748. +int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * hcd,
  85749. + dwc_otg_hcd_urb_t * dwc_otg_urb, void **ep_handle,
  85750. + int atomic_alloc)
  85751. +{
  85752. + int retval = 0;
  85753. + uint8_t needs_scheduling = 0;
  85754. + dwc_otg_transaction_type_e tr_type;
  85755. + dwc_otg_qtd_t *qtd;
  85756. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85757. + hprt0_data_t hprt0 = { .d32 = 0 };
  85758. +
  85759. +#ifdef DEBUG /* integrity checks (Broadcom) */
  85760. + if (NULL == hcd->core_if) {
  85761. + DWC_ERROR("**** DWC OTG HCD URB Enqueue - HCD has NULL core_if\n");
  85762. + /* No longer connected. */
  85763. + return -DWC_E_INVALID;
  85764. + }
  85765. +#endif
  85766. + if (!hcd->flags.b.port_connect_status) {
  85767. + /* No longer connected. */
  85768. + DWC_ERROR("Not connected\n");
  85769. + return -DWC_E_NO_DEVICE;
  85770. + }
  85771. +
  85772. + /* Some core configurations cannot support LS traffic on a FS root port */
  85773. + if ((hcd->fops->speed(hcd, dwc_otg_urb->priv) == USB_SPEED_LOW) &&
  85774. + (hcd->core_if->hwcfg2.b.fs_phy_type == 1) &&
  85775. + (hcd->core_if->hwcfg2.b.hs_phy_type == 1)) {
  85776. + hprt0.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  85777. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED) {
  85778. + return -DWC_E_NO_DEVICE;
  85779. + }
  85780. + }
  85781. +
  85782. + qtd = dwc_otg_hcd_qtd_create(dwc_otg_urb, atomic_alloc);
  85783. + if (qtd == NULL) {
  85784. + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
  85785. + return -DWC_E_NO_MEMORY;
  85786. + }
  85787. +#ifdef DEBUG /* integrity checks (Broadcom) */
  85788. + if (qtd->urb == NULL) {
  85789. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD with no URBs\n");
  85790. + return -DWC_E_NO_MEMORY;
  85791. + }
  85792. + if (qtd->urb->priv == NULL) {
  85793. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD URB with no URB handle\n");
  85794. + return -DWC_E_NO_MEMORY;
  85795. + }
  85796. +#endif
  85797. + intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
  85798. + if(!intr_mask.b.sofintr || fiq_enable) needs_scheduling = 1;
  85799. + if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
  85800. + /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
  85801. + needs_scheduling = 0;
  85802. +
  85803. + retval = dwc_otg_hcd_qtd_add(qtd, hcd, (dwc_otg_qh_t **) ep_handle, atomic_alloc);
  85804. + // creates a new queue in ep_handle if it doesn't exist already
  85805. + if (retval < 0) {
  85806. + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
  85807. + "Error status %d\n", retval);
  85808. + dwc_otg_hcd_qtd_free(qtd);
  85809. + return retval;
  85810. + }
  85811. +
  85812. + if(needs_scheduling) {
  85813. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  85814. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  85815. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  85816. + }
  85817. + }
  85818. + return retval;
  85819. +}
  85820. +
  85821. +int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * hcd,
  85822. + dwc_otg_hcd_urb_t * dwc_otg_urb)
  85823. +{
  85824. + dwc_otg_qh_t *qh;
  85825. + dwc_otg_qtd_t *urb_qtd;
  85826. + BUG_ON(!hcd);
  85827. + BUG_ON(!dwc_otg_urb);
  85828. +
  85829. +#ifdef DEBUG /* integrity checks (Broadcom) */
  85830. +
  85831. + if (hcd == NULL) {
  85832. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL HCD\n");
  85833. + return -DWC_E_INVALID;
  85834. + }
  85835. + if (dwc_otg_urb == NULL) {
  85836. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL URB\n");
  85837. + return -DWC_E_INVALID;
  85838. + }
  85839. + if (dwc_otg_urb->qtd == NULL) {
  85840. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with NULL QTD\n");
  85841. + return -DWC_E_INVALID;
  85842. + }
  85843. + urb_qtd = dwc_otg_urb->qtd;
  85844. + BUG_ON(!urb_qtd);
  85845. + if (urb_qtd->qh == NULL) {
  85846. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with QTD with NULL Q handler\n");
  85847. + return -DWC_E_INVALID;
  85848. + }
  85849. +#else
  85850. + urb_qtd = dwc_otg_urb->qtd;
  85851. + BUG_ON(!urb_qtd);
  85852. +#endif
  85853. + qh = urb_qtd->qh;
  85854. + BUG_ON(!qh);
  85855. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  85856. + if (urb_qtd->in_process) {
  85857. + dump_channel_info(hcd, qh);
  85858. + }
  85859. + }
  85860. +#ifdef DEBUG /* integrity checks (Broadcom) */
  85861. + if (hcd->core_if == NULL) {
  85862. + DWC_ERROR("**** DWC OTG HCD URB Dequeue HCD has NULL core_if\n");
  85863. + return -DWC_E_INVALID;
  85864. + }
  85865. +#endif
  85866. + if (urb_qtd->in_process && qh->channel) {
  85867. + /* The QTD is in process (it has been assigned to a channel). */
  85868. + if (hcd->flags.b.port_connect_status) {
  85869. + int n = qh->channel->hc_num;
  85870. + /*
  85871. + * If still connected (i.e. in host mode), halt the
  85872. + * channel so it can be used for other transfers. If
  85873. + * no longer connected, the host registers can't be
  85874. + * written to halt the channel since the core is in
  85875. + * device mode.
  85876. + */
  85877. + /* In FIQ FSM mode, we need to shut down carefully.
  85878. + * The FIQ may attempt to restart a disabled channel */
  85879. + if (fiq_fsm_enable && (hcd->fiq_state->channel[n].fsm != FIQ_PASSTHROUGH)) {
  85880. + qh->channel->halt_status = DWC_OTG_HC_XFER_URB_DEQUEUE;
  85881. + qh->channel->halt_pending = 1;
  85882. + hcd->fiq_state->channel[n].fsm = FIQ_DEQUEUE_ISSUED;
  85883. + } else {
  85884. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  85885. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  85886. + }
  85887. + }
  85888. + }
  85889. +
  85890. + /*
  85891. + * Free the QTD and clean up the associated QH. Leave the QH in the
  85892. + * schedule if it has any remaining QTDs.
  85893. + */
  85894. +
  85895. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue - "
  85896. + "delete %sQueue handler\n",
  85897. + hcd->core_if->dma_desc_enable?"DMA ":"");
  85898. + if (!hcd->core_if->dma_desc_enable) {
  85899. + uint8_t b = urb_qtd->in_process;
  85900. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  85901. + if (b) {
  85902. + dwc_otg_hcd_qh_deactivate(hcd, qh, 0);
  85903. + qh->channel = NULL;
  85904. + } else if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  85905. + dwc_otg_hcd_qh_remove(hcd, qh);
  85906. + }
  85907. + } else {
  85908. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  85909. + }
  85910. + return 0;
  85911. +}
  85912. +
  85913. +int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  85914. + int retry)
  85915. +{
  85916. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  85917. + int retval = 0;
  85918. + dwc_irqflags_t flags;
  85919. +
  85920. + if (retry < 0) {
  85921. + retval = -DWC_E_INVALID;
  85922. + goto done;
  85923. + }
  85924. +
  85925. + if (!qh) {
  85926. + retval = -DWC_E_INVALID;
  85927. + goto done;
  85928. + }
  85929. +
  85930. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  85931. +
  85932. + while (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list) && retry) {
  85933. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  85934. + retry--;
  85935. + dwc_msleep(5);
  85936. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  85937. + }
  85938. +
  85939. + dwc_otg_hcd_qh_remove(hcd, qh);
  85940. +
  85941. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  85942. + /*
  85943. + * Split dwc_otg_hcd_qh_remove_and_free() into qh_remove
  85944. + * and qh_free to prevent stack dump on DWC_DMA_FREE() with
  85945. + * irq_disabled (spinlock_irqsave) in dwc_otg_hcd_desc_list_free()
  85946. + * and dwc_otg_hcd_frame_list_alloc().
  85947. + */
  85948. + dwc_otg_hcd_qh_free(hcd, qh);
  85949. +
  85950. +done:
  85951. + return retval;
  85952. +}
  85953. +
  85954. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  85955. +int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle)
  85956. +{
  85957. + int retval = 0;
  85958. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  85959. + if (!qh)
  85960. + return -DWC_E_INVALID;
  85961. +
  85962. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  85963. + return retval;
  85964. +}
  85965. +#endif
  85966. +
  85967. +/**
  85968. + * HCD Callback structure for handling mode switching.
  85969. + */
  85970. +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
  85971. + .start = dwc_otg_hcd_start_cb,
  85972. + .stop = dwc_otg_hcd_stop_cb,
  85973. + .disconnect = dwc_otg_hcd_disconnect_cb,
  85974. + .session_start = dwc_otg_hcd_session_start_cb,
  85975. + .resume_wakeup = dwc_otg_hcd_rem_wakeup_cb,
  85976. +#ifdef CONFIG_USB_DWC_OTG_LPM
  85977. + .sleep = dwc_otg_hcd_sleep_cb,
  85978. +#endif
  85979. + .p = 0,
  85980. +};
  85981. +
  85982. +/**
  85983. + * Reset tasklet function
  85984. + */
  85985. +static void reset_tasklet_func(void *data)
  85986. +{
  85987. + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *) data;
  85988. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  85989. + hprt0_data_t hprt0;
  85990. +
  85991. + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
  85992. +
  85993. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  85994. + hprt0.b.prtrst = 1;
  85995. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  85996. + dwc_mdelay(60);
  85997. +
  85998. + hprt0.b.prtrst = 0;
  85999. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  86000. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  86001. +}
  86002. +
  86003. +static void completion_tasklet_func(void *ptr)
  86004. +{
  86005. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) ptr;
  86006. + struct urb *urb;
  86007. + urb_tq_entry_t *item;
  86008. + dwc_irqflags_t flags;
  86009. +
  86010. + /* This could just be spin_lock_irq */
  86011. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  86012. + while (!DWC_TAILQ_EMPTY(&hcd->completed_urb_list)) {
  86013. + item = DWC_TAILQ_FIRST(&hcd->completed_urb_list);
  86014. + urb = item->urb;
  86015. + DWC_TAILQ_REMOVE(&hcd->completed_urb_list, item,
  86016. + urb_tq_entries);
  86017. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  86018. + DWC_FREE(item);
  86019. +
  86020. + usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
  86021. +
  86022. +
  86023. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  86024. + }
  86025. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  86026. + return;
  86027. +}
  86028. +
  86029. +static void qh_list_free(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  86030. +{
  86031. + dwc_list_link_t *item;
  86032. + dwc_otg_qh_t *qh;
  86033. + dwc_irqflags_t flags;
  86034. +
  86035. + if (!qh_list->next) {
  86036. + /* The list hasn't been initialized yet. */
  86037. + return;
  86038. + }
  86039. + /*
  86040. + * Hold spinlock here. Not needed in that case if bellow
  86041. + * function is being called from ISR
  86042. + */
  86043. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  86044. + /* Ensure there are no QTDs or URBs left. */
  86045. + kill_urbs_in_qh_list(hcd, qh_list);
  86046. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  86047. +
  86048. + DWC_LIST_FOREACH(item, qh_list) {
  86049. + qh = DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  86050. + dwc_otg_hcd_qh_remove_and_free(hcd, qh);
  86051. + }
  86052. +}
  86053. +
  86054. +/**
  86055. + * Exit from Hibernation if Host did not detect SRP from connected SRP capable
  86056. + * Device during SRP time by host power up.
  86057. + */
  86058. +void dwc_otg_hcd_power_up(void *ptr)
  86059. +{
  86060. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  86061. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  86062. +
  86063. + DWC_PRINTF("%s called\n", __FUNCTION__);
  86064. +
  86065. + if (!core_if->hibernation_suspend) {
  86066. + DWC_PRINTF("Already exited from Hibernation\n");
  86067. + return;
  86068. + }
  86069. +
  86070. + /* Switch on the voltage to the core */
  86071. + gpwrdn.b.pwrdnswtch = 1;
  86072. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  86073. + dwc_udelay(10);
  86074. +
  86075. + /* Reset the core */
  86076. + gpwrdn.d32 = 0;
  86077. + gpwrdn.b.pwrdnrstn = 1;
  86078. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  86079. + dwc_udelay(10);
  86080. +
  86081. + /* Disable power clamps */
  86082. + gpwrdn.d32 = 0;
  86083. + gpwrdn.b.pwrdnclmp = 1;
  86084. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  86085. +
  86086. + /* Remove reset the core signal */
  86087. + gpwrdn.d32 = 0;
  86088. + gpwrdn.b.pwrdnrstn = 1;
  86089. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  86090. + dwc_udelay(10);
  86091. +
  86092. + /* Disable PMU interrupt */
  86093. + gpwrdn.d32 = 0;
  86094. + gpwrdn.b.pmuintsel = 1;
  86095. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  86096. +
  86097. + core_if->hibernation_suspend = 0;
  86098. +
  86099. + /* Disable PMU */
  86100. + gpwrdn.d32 = 0;
  86101. + gpwrdn.b.pmuactv = 1;
  86102. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  86103. + dwc_udelay(10);
  86104. +
  86105. + /* Enable VBUS */
  86106. + gpwrdn.d32 = 0;
  86107. + gpwrdn.b.dis_vbus = 1;
  86108. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  86109. +
  86110. + core_if->op_state = A_HOST;
  86111. + dwc_otg_core_init(core_if);
  86112. + dwc_otg_enable_global_interrupts(core_if);
  86113. + cil_hcd_start(core_if);
  86114. +}
  86115. +
  86116. +void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num)
  86117. +{
  86118. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  86119. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  86120. + int i;
  86121. +
  86122. + st->fsm = FIQ_PASSTHROUGH;
  86123. + st->hcchar_copy.d32 = 0;
  86124. + st->hcsplt_copy.d32 = 0;
  86125. + st->hcint_copy.d32 = 0;
  86126. + st->hcintmsk_copy.d32 = 0;
  86127. + st->hctsiz_copy.d32 = 0;
  86128. + st->hcdma_copy.d32 = 0;
  86129. + st->nr_errors = 0;
  86130. + st->hub_addr = 0;
  86131. + st->port_addr = 0;
  86132. + st->expected_uframe = 0;
  86133. + st->nrpackets = 0;
  86134. + st->dma_info.index = 0;
  86135. + for (i = 0; i < 6; i++)
  86136. + st->dma_info.slot_len[i] = 255;
  86137. + st->hs_isoc_info.index = 0;
  86138. + st->hs_isoc_info.iso_desc = NULL;
  86139. + st->hs_isoc_info.nrframes = 0;
  86140. +
  86141. + DWC_MEMSET(&blob->channel[num].index[0], 0x6b, 1128);
  86142. +}
  86143. +
  86144. +/**
  86145. + * Frees secondary storage associated with the dwc_otg_hcd structure contained
  86146. + * in the struct usb_hcd field.
  86147. + */
  86148. +static void dwc_otg_hcd_free(dwc_otg_hcd_t * dwc_otg_hcd)
  86149. +{
  86150. + int i;
  86151. +
  86152. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
  86153. +
  86154. + del_timers(dwc_otg_hcd);
  86155. +
  86156. + /* Free memory for QH/QTD lists */
  86157. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
  86158. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
  86159. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
  86160. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
  86161. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
  86162. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
  86163. +
  86164. + /* Free memory for the host channels. */
  86165. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  86166. + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
  86167. +
  86168. +#ifdef DEBUG
  86169. + if (dwc_otg_hcd->core_if->hc_xfer_timer[i]) {
  86170. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->hc_xfer_timer[i]);
  86171. + }
  86172. +#endif
  86173. + if (hc != NULL) {
  86174. + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n",
  86175. + i, hc);
  86176. + DWC_FREE(hc);
  86177. + }
  86178. + }
  86179. +
  86180. + if (dwc_otg_hcd->core_if->dma_enable) {
  86181. + if (dwc_otg_hcd->status_buf_dma) {
  86182. + DWC_DMA_FREE(DWC_OTG_HCD_STATUS_BUF_SIZE,
  86183. + dwc_otg_hcd->status_buf,
  86184. + dwc_otg_hcd->status_buf_dma);
  86185. + }
  86186. + } else if (dwc_otg_hcd->status_buf != NULL) {
  86187. + DWC_FREE(dwc_otg_hcd->status_buf);
  86188. + }
  86189. + DWC_SPINLOCK_FREE(dwc_otg_hcd->channel_lock);
  86190. + DWC_SPINLOCK_FREE(dwc_otg_hcd->lock);
  86191. + /* Set core_if's lock pointer to NULL */
  86192. + dwc_otg_hcd->core_if->lock = NULL;
  86193. +
  86194. + DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
  86195. + DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
  86196. + DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
  86197. + DWC_FREE(dwc_otg_hcd->fiq_state);
  86198. +
  86199. +#ifdef DWC_DEV_SRPCAP
  86200. + if (dwc_otg_hcd->core_if->power_down == 2 &&
  86201. + dwc_otg_hcd->core_if->pwron_timer) {
  86202. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->pwron_timer);
  86203. + }
  86204. +#endif
  86205. + DWC_FREE(dwc_otg_hcd);
  86206. +}
  86207. +
  86208. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
  86209. +
  86210. +int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
  86211. +{
  86212. + int retval = 0;
  86213. + int num_channels;
  86214. + int i;
  86215. + dwc_hc_t *channel;
  86216. +
  86217. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK))
  86218. + DWC_SPINLOCK_ALLOC_LINUX_DEBUG(hcd->lock);
  86219. + DWC_SPINLOCK_ALLOC_LINUX_DEBUG(hcd->channel_lock);
  86220. +#else
  86221. + hcd->lock = DWC_SPINLOCK_ALLOC();
  86222. + hcd->channel_lock = DWC_SPINLOCK_ALLOC();
  86223. +#endif
  86224. + DWC_DEBUGPL(DBG_HCDV, "init of HCD %p given core_if %p\n",
  86225. + hcd, core_if);
  86226. + if (!hcd->lock) {
  86227. + DWC_ERROR("Could not allocate lock for pcd");
  86228. + DWC_FREE(hcd);
  86229. + retval = -DWC_E_NO_MEMORY;
  86230. + goto out;
  86231. + }
  86232. + hcd->core_if = core_if;
  86233. +
  86234. + /* Register the HCD CIL Callbacks */
  86235. + dwc_otg_cil_register_hcd_callbacks(hcd->core_if,
  86236. + &hcd_cil_callbacks, hcd);
  86237. +
  86238. + /* Initialize the non-periodic schedule. */
  86239. + DWC_LIST_INIT(&hcd->non_periodic_sched_inactive);
  86240. + DWC_LIST_INIT(&hcd->non_periodic_sched_active);
  86241. +
  86242. + /* Initialize the periodic schedule. */
  86243. + DWC_LIST_INIT(&hcd->periodic_sched_inactive);
  86244. + DWC_LIST_INIT(&hcd->periodic_sched_ready);
  86245. + DWC_LIST_INIT(&hcd->periodic_sched_assigned);
  86246. + DWC_LIST_INIT(&hcd->periodic_sched_queued);
  86247. + DWC_TAILQ_INIT(&hcd->completed_urb_list);
  86248. + /*
  86249. + * Create a host channel descriptor for each host channel implemented
  86250. + * in the controller. Initialize the channel descriptor array.
  86251. + */
  86252. + DWC_CIRCLEQ_INIT(&hcd->free_hc_list);
  86253. + num_channels = hcd->core_if->core_params->host_channels;
  86254. + DWC_MEMSET(hcd->hc_ptr_array, 0, sizeof(hcd->hc_ptr_array));
  86255. + for (i = 0; i < num_channels; i++) {
  86256. + channel = DWC_ALLOC(sizeof(dwc_hc_t));
  86257. + if (channel == NULL) {
  86258. + retval = -DWC_E_NO_MEMORY;
  86259. + DWC_ERROR("%s: host channel allocation failed\n",
  86260. + __func__);
  86261. + dwc_otg_hcd_free(hcd);
  86262. + goto out;
  86263. + }
  86264. + channel->hc_num = i;
  86265. + hcd->hc_ptr_array[i] = channel;
  86266. +#ifdef DEBUG
  86267. + hcd->core_if->hc_xfer_timer[i] =
  86268. + DWC_TIMER_ALLOC("hc timer", hc_xfer_timeout,
  86269. + &hcd->core_if->hc_xfer_info[i]);
  86270. +#endif
  86271. + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i,
  86272. + channel);
  86273. + }
  86274. +
  86275. + if (fiq_enable) {
  86276. + hcd->fiq_state = DWC_ALLOC(sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels));
  86277. + if (!hcd->fiq_state) {
  86278. + retval = -DWC_E_NO_MEMORY;
  86279. + DWC_ERROR("%s: cannot allocate fiq_state structure\n", __func__);
  86280. + dwc_otg_hcd_free(hcd);
  86281. + goto out;
  86282. + }
  86283. + DWC_MEMSET(hcd->fiq_state, 0, (sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels)));
  86284. +
  86285. + for (i = 0; i < num_channels; i++) {
  86286. + hcd->fiq_state->channel[i].fsm = FIQ_PASSTHROUGH;
  86287. + }
  86288. + hcd->fiq_state->dummy_send = DWC_ALLOC_ATOMIC(16);
  86289. +
  86290. + hcd->fiq_stack = DWC_ALLOC(sizeof(struct fiq_stack));
  86291. + if (!hcd->fiq_stack) {
  86292. + retval = -DWC_E_NO_MEMORY;
  86293. + DWC_ERROR("%s: cannot allocate fiq_stack structure\n", __func__);
  86294. + dwc_otg_hcd_free(hcd);
  86295. + goto out;
  86296. + }
  86297. + hcd->fiq_stack->magic1 = 0xDEADBEEF;
  86298. + hcd->fiq_stack->magic2 = 0xD00DFEED;
  86299. + hcd->fiq_state->gintmsk_saved.d32 = ~0;
  86300. + hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  86301. +
  86302. + /* This bit is terrible and uses no API, but necessary. The FIQ has no concept of DMA pools
  86303. + * (and if it did, would be a lot slower). This allocates a chunk of memory (~9kiB for 8 host channels)
  86304. + * for use as transaction bounce buffers in a 2-D array. Our access into this chunk is done by some
  86305. + * moderately readable array casts.
  86306. + */
  86307. + hcd->fiq_dmab = DWC_DMA_ALLOC((sizeof(struct fiq_dma_channel) * num_channels), &hcd->fiq_state->dma_base);
  86308. + DWC_WARN("FIQ DMA bounce buffers: virt = 0x%08x dma = 0x%08x len=%d",
  86309. + (unsigned int)hcd->fiq_dmab, (unsigned int)hcd->fiq_state->dma_base,
  86310. + sizeof(struct fiq_dma_channel) * num_channels);
  86311. +
  86312. + DWC_MEMSET(hcd->fiq_dmab, 0x6b, 9024);
  86313. +
  86314. + /* pointer for debug in fiq_print */
  86315. + hcd->fiq_state->fiq_dmab = hcd->fiq_dmab;
  86316. + if (fiq_fsm_enable) {
  86317. + int i;
  86318. + for (i=0; i < hcd->core_if->core_params->host_channels; i++) {
  86319. + dwc_otg_cleanup_fiq_channel(hcd, i);
  86320. + }
  86321. + DWC_PRINTF("FIQ FSM acceleration enabled for :\n%s%s%s%s",
  86322. + (fiq_fsm_mask & 0x1) ? "Non-periodic Split Transactions\n" : "",
  86323. + (fiq_fsm_mask & 0x2) ? "Periodic Split Transactions\n" : "",
  86324. + (fiq_fsm_mask & 0x4) ? "High-Speed Isochronous Endpoints\n" : "",
  86325. + (fiq_fsm_mask & 0x8) ? "Interrupt/Control Split Transaction hack enabled\n" : "");
  86326. + }
  86327. + }
  86328. +
  86329. + /* Initialize the Connection timeout timer. */
  86330. + hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
  86331. + dwc_otg_hcd_connect_timeout, 0);
  86332. +
  86333. + printk(KERN_DEBUG "dwc_otg: Microframe scheduler %s\n", microframe_schedule ? "enabled":"disabled");
  86334. + if (microframe_schedule)
  86335. + init_hcd_usecs(hcd);
  86336. +
  86337. + /* Initialize reset tasklet. */
  86338. + hcd->reset_tasklet = DWC_TASK_ALLOC("reset_tasklet", reset_tasklet_func, hcd);
  86339. +
  86340. + hcd->completion_tasklet = DWC_TASK_ALLOC("completion_tasklet",
  86341. + completion_tasklet_func, hcd);
  86342. +#ifdef DWC_DEV_SRPCAP
  86343. + if (hcd->core_if->power_down == 2) {
  86344. + /* Initialize Power on timer for Host power up in case hibernation */
  86345. + hcd->core_if->pwron_timer = DWC_TIMER_ALLOC("PWRON TIMER",
  86346. + dwc_otg_hcd_power_up, core_if);
  86347. + }
  86348. +#endif
  86349. +
  86350. + /*
  86351. + * Allocate space for storing data on status transactions. Normally no
  86352. + * data is sent, but this space acts as a bit bucket. This must be
  86353. + * done after usb_add_hcd since that function allocates the DMA buffer
  86354. + * pool.
  86355. + */
  86356. + if (hcd->core_if->dma_enable) {
  86357. + hcd->status_buf =
  86358. + DWC_DMA_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE,
  86359. + &hcd->status_buf_dma);
  86360. + } else {
  86361. + hcd->status_buf = DWC_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE);
  86362. + }
  86363. + if (!hcd->status_buf) {
  86364. + retval = -DWC_E_NO_MEMORY;
  86365. + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
  86366. + dwc_otg_hcd_free(hcd);
  86367. + goto out;
  86368. + }
  86369. +
  86370. + hcd->otg_port = 1;
  86371. + hcd->frame_list = NULL;
  86372. + hcd->frame_list_dma = 0;
  86373. + hcd->periodic_qh_count = 0;
  86374. +
  86375. + DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
  86376. +#ifdef FIQ_DEBUG
  86377. + DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
  86378. +#endif
  86379. +
  86380. +out:
  86381. + return retval;
  86382. +}
  86383. +
  86384. +void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd)
  86385. +{
  86386. + /* Turn off all host-specific interrupts. */
  86387. + dwc_otg_disable_host_interrupts(hcd->core_if);
  86388. +
  86389. + dwc_otg_hcd_free(hcd);
  86390. +}
  86391. +
  86392. +/**
  86393. + * Initializes dynamic portions of the DWC_otg HCD state.
  86394. + */
  86395. +static void dwc_otg_hcd_reinit(dwc_otg_hcd_t * hcd)
  86396. +{
  86397. + int num_channels;
  86398. + int i;
  86399. + dwc_hc_t *channel;
  86400. + dwc_hc_t *channel_tmp;
  86401. +
  86402. + hcd->flags.d32 = 0;
  86403. +
  86404. + hcd->non_periodic_qh_ptr = &hcd->non_periodic_sched_active;
  86405. + if (!microframe_schedule) {
  86406. + hcd->non_periodic_channels = 0;
  86407. + hcd->periodic_channels = 0;
  86408. + } else {
  86409. + hcd->available_host_channels = hcd->core_if->core_params->host_channels;
  86410. + }
  86411. + /*
  86412. + * Put all channels in the free channel list and clean up channel
  86413. + * states.
  86414. + */
  86415. + DWC_CIRCLEQ_FOREACH_SAFE(channel, channel_tmp,
  86416. + &hcd->free_hc_list, hc_list_entry) {
  86417. + DWC_CIRCLEQ_REMOVE(&hcd->free_hc_list, channel, hc_list_entry);
  86418. + }
  86419. +
  86420. + num_channels = hcd->core_if->core_params->host_channels;
  86421. + for (i = 0; i < num_channels; i++) {
  86422. + channel = hcd->hc_ptr_array[i];
  86423. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, channel,
  86424. + hc_list_entry);
  86425. + dwc_otg_hc_cleanup(hcd->core_if, channel);
  86426. + }
  86427. +
  86428. + /* Initialize the DWC core for host mode operation. */
  86429. + dwc_otg_core_host_init(hcd->core_if);
  86430. +
  86431. + /* Set core_if's lock pointer to the hcd->lock */
  86432. + hcd->core_if->lock = hcd->lock;
  86433. +}
  86434. +
  86435. +/**
  86436. + * Assigns transactions from a QTD to a free host channel and initializes the
  86437. + * host channel to perform the transactions. The host channel is removed from
  86438. + * the free list.
  86439. + *
  86440. + * @param hcd The HCD state structure.
  86441. + * @param qh Transactions from the first QTD for this QH are selected and
  86442. + * assigned to a free host channel.
  86443. + */
  86444. +static void assign_and_init_hc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  86445. +{
  86446. + dwc_hc_t *hc;
  86447. + dwc_otg_qtd_t *qtd;
  86448. + dwc_otg_hcd_urb_t *urb;
  86449. + void* ptr = NULL;
  86450. + uint32_t intr_enable;
  86451. + unsigned long flags;
  86452. + gintmsk_data_t gintmsk = { .d32 = 0, };
  86453. +
  86454. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  86455. +
  86456. + urb = qtd->urb;
  86457. +
  86458. + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p) - urb %x, actual_length %d\n", __func__, hcd, qh, (unsigned int)urb, urb->actual_length);
  86459. +
  86460. + if (((urb->actual_length < 0) || (urb->actual_length > urb->length)) && !dwc_otg_hcd_is_pipe_in(&urb->pipe_info))
  86461. + urb->actual_length = urb->length;
  86462. +
  86463. +
  86464. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  86465. +
  86466. + /* Remove the host channel from the free list. */
  86467. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  86468. +
  86469. + qh->channel = hc;
  86470. +
  86471. + qtd->in_process = 1;
  86472. +
  86473. + /*
  86474. + * Use usb_pipedevice to determine device address. This address is
  86475. + * 0 before the SET_ADDRESS command and the correct address afterward.
  86476. + */
  86477. + hc->dev_addr = dwc_otg_hcd_get_dev_addr(&urb->pipe_info);
  86478. + hc->ep_num = dwc_otg_hcd_get_ep_num(&urb->pipe_info);
  86479. + hc->speed = qh->dev_speed;
  86480. + hc->max_packet = dwc_max_packet(qh->maxp);
  86481. +
  86482. + hc->xfer_started = 0;
  86483. + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
  86484. + hc->error_state = (qtd->error_count > 0);
  86485. + hc->halt_on_queue = 0;
  86486. + hc->halt_pending = 0;
  86487. + hc->requests = 0;
  86488. +
  86489. + /*
  86490. + * The following values may be modified in the transfer type section
  86491. + * below. The xfer_len value may be reduced when the transfer is
  86492. + * started to accommodate the max widths of the XferSize and PktCnt
  86493. + * fields in the HCTSIZn register.
  86494. + */
  86495. +
  86496. + hc->ep_is_in = (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) != 0);
  86497. + if (hc->ep_is_in) {
  86498. + hc->do_ping = 0;
  86499. + } else {
  86500. + hc->do_ping = qh->ping_state;
  86501. + }
  86502. +
  86503. + hc->data_pid_start = qh->data_toggle;
  86504. + hc->multi_count = 1;
  86505. +
  86506. + if (hcd->core_if->dma_enable) {
  86507. + hc->xfer_buff = (uint8_t *) urb->dma + urb->actual_length;
  86508. +
  86509. + /* For non-dword aligned case */
  86510. + if (((unsigned long)hc->xfer_buff & 0x3)
  86511. + && !hcd->core_if->dma_desc_enable) {
  86512. + ptr = (uint8_t *) urb->buf + urb->actual_length;
  86513. + }
  86514. + } else {
  86515. + hc->xfer_buff = (uint8_t *) urb->buf + urb->actual_length;
  86516. + }
  86517. + hc->xfer_len = urb->length - urb->actual_length;
  86518. + hc->xfer_count = 0;
  86519. +
  86520. + /*
  86521. + * Set the split attributes
  86522. + */
  86523. + hc->do_split = 0;
  86524. + if (qh->do_split) {
  86525. + uint32_t hub_addr, port_addr;
  86526. + hc->do_split = 1;
  86527. + hc->xact_pos = qtd->isoc_split_pos;
  86528. + /* We don't need to do complete splits anymore */
  86529. +// if(fiq_fsm_enable)
  86530. + if (0)
  86531. + hc->complete_split = qtd->complete_split = 0;
  86532. + else
  86533. + hc->complete_split = qtd->complete_split;
  86534. +
  86535. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &port_addr);
  86536. + hc->hub_addr = (uint8_t) hub_addr;
  86537. + hc->port_addr = (uint8_t) port_addr;
  86538. + }
  86539. +
  86540. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  86541. + case UE_CONTROL:
  86542. + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
  86543. + switch (qtd->control_phase) {
  86544. + case DWC_OTG_CONTROL_SETUP:
  86545. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
  86546. + hc->do_ping = 0;
  86547. + hc->ep_is_in = 0;
  86548. + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
  86549. + if (hcd->core_if->dma_enable) {
  86550. + hc->xfer_buff = (uint8_t *) urb->setup_dma;
  86551. + } else {
  86552. + hc->xfer_buff = (uint8_t *) urb->setup_packet;
  86553. + }
  86554. + hc->xfer_len = 8;
  86555. + ptr = NULL;
  86556. + break;
  86557. + case DWC_OTG_CONTROL_DATA:
  86558. + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
  86559. + hc->data_pid_start = qtd->data_toggle;
  86560. + break;
  86561. + case DWC_OTG_CONTROL_STATUS:
  86562. + /*
  86563. + * Direction is opposite of data direction or IN if no
  86564. + * data.
  86565. + */
  86566. + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
  86567. + if (urb->length == 0) {
  86568. + hc->ep_is_in = 1;
  86569. + } else {
  86570. + hc->ep_is_in =
  86571. + dwc_otg_hcd_is_pipe_out(&urb->pipe_info);
  86572. + }
  86573. + if (hc->ep_is_in) {
  86574. + hc->do_ping = 0;
  86575. + }
  86576. +
  86577. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  86578. +
  86579. + hc->xfer_len = 0;
  86580. + if (hcd->core_if->dma_enable) {
  86581. + hc->xfer_buff = (uint8_t *) hcd->status_buf_dma;
  86582. + } else {
  86583. + hc->xfer_buff = (uint8_t *) hcd->status_buf;
  86584. + }
  86585. + ptr = NULL;
  86586. + break;
  86587. + }
  86588. + break;
  86589. + case UE_BULK:
  86590. + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
  86591. + break;
  86592. + case UE_INTERRUPT:
  86593. + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
  86594. + break;
  86595. + case UE_ISOCHRONOUS:
  86596. + {
  86597. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  86598. +
  86599. + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
  86600. +
  86601. + if (hcd->core_if->dma_desc_enable)
  86602. + break;
  86603. +
  86604. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  86605. +
  86606. + frame_desc->status = 0;
  86607. +
  86608. + if (hcd->core_if->dma_enable) {
  86609. + hc->xfer_buff = (uint8_t *) urb->dma;
  86610. + } else {
  86611. + hc->xfer_buff = (uint8_t *) urb->buf;
  86612. + }
  86613. + hc->xfer_buff +=
  86614. + frame_desc->offset + qtd->isoc_split_offset;
  86615. + hc->xfer_len =
  86616. + frame_desc->length - qtd->isoc_split_offset;
  86617. +
  86618. + /* For non-dword aligned buffers */
  86619. + if (((unsigned long)hc->xfer_buff & 0x3)
  86620. + && hcd->core_if->dma_enable) {
  86621. + ptr =
  86622. + (uint8_t *) urb->buf + frame_desc->offset +
  86623. + qtd->isoc_split_offset;
  86624. + } else
  86625. + ptr = NULL;
  86626. +
  86627. + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  86628. + if (hc->xfer_len <= 188) {
  86629. + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
  86630. + } else {
  86631. + hc->xact_pos =
  86632. + DWC_HCSPLIT_XACTPOS_BEGIN;
  86633. + }
  86634. + }
  86635. + }
  86636. + break;
  86637. + }
  86638. + /* non DWORD-aligned buffer case */
  86639. + if (ptr) {
  86640. + uint32_t buf_size;
  86641. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  86642. + buf_size = hcd->core_if->core_params->max_transfer_size;
  86643. + } else {
  86644. + buf_size = 4096;
  86645. + }
  86646. + if (!qh->dw_align_buf) {
  86647. + qh->dw_align_buf = DWC_DMA_ALLOC_ATOMIC(buf_size,
  86648. + &qh->dw_align_buf_dma);
  86649. + if (!qh->dw_align_buf) {
  86650. + DWC_ERROR
  86651. + ("%s: Failed to allocate memory to handle "
  86652. + "non-dword aligned buffer case\n",
  86653. + __func__);
  86654. + return;
  86655. + }
  86656. + }
  86657. + if (!hc->ep_is_in) {
  86658. + dwc_memcpy(qh->dw_align_buf, ptr, hc->xfer_len);
  86659. + }
  86660. + hc->align_buff = qh->dw_align_buf_dma;
  86661. + } else {
  86662. + hc->align_buff = 0;
  86663. + }
  86664. +
  86665. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  86666. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  86667. + /*
  86668. + * This value may be modified when the transfer is started to
  86669. + * reflect the actual transfer length.
  86670. + */
  86671. + hc->multi_count = dwc_hb_mult(qh->maxp);
  86672. + }
  86673. +
  86674. + if (hcd->core_if->dma_desc_enable)
  86675. + hc->desc_list_addr = qh->desc_list_dma;
  86676. +
  86677. + dwc_otg_hc_init(hcd->core_if, hc);
  86678. +
  86679. + local_irq_save(flags);
  86680. + local_fiq_disable();
  86681. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  86682. + /* Enable the top level host channel interrupt. */
  86683. + intr_enable = (1 << hc->hc_num);
  86684. + DWC_MODIFY_REG32(&hcd->core_if->host_if->host_global_regs->haintmsk, 0, intr_enable);
  86685. +
  86686. + /* Make sure host channel interrupts are enabled. */
  86687. + gintmsk.b.hcintr = 1;
  86688. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  86689. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  86690. + local_fiq_enable();
  86691. + local_irq_restore(flags);
  86692. + hc->qh = qh;
  86693. +}
  86694. +
  86695. +
  86696. +/**
  86697. + * fiq_fsm_transaction_suitable() - Test a QH for compatibility with the FIQ
  86698. + * @qh: pointer to the endpoint's queue head
  86699. + *
  86700. + * Transaction start/end control flow is grafted onto the existing dwc_otg
  86701. + * mechanisms, to avoid spaghettifying the functions more than they already are.
  86702. + * This function's eligibility check is altered by debug parameter.
  86703. + *
  86704. + * Returns: 0 for unsuitable, 1 implies the FIQ can be enabled for this transaction.
  86705. + */
  86706. +
  86707. +int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh)
  86708. +{
  86709. + if (qh->do_split) {
  86710. + switch (qh->ep_type) {
  86711. + case UE_CONTROL:
  86712. + case UE_BULK:
  86713. + if (fiq_fsm_mask & (1 << 0))
  86714. + return 1;
  86715. + break;
  86716. + case UE_INTERRUPT:
  86717. + case UE_ISOCHRONOUS:
  86718. + if (fiq_fsm_mask & (1 << 1))
  86719. + return 1;
  86720. + break;
  86721. + default:
  86722. + break;
  86723. + }
  86724. + } else if (qh->ep_type == UE_ISOCHRONOUS) {
  86725. + if (fiq_fsm_mask & (1 << 2)) {
  86726. + /* HS ISOCH support. We test for compatibility:
  86727. + * - DWORD aligned buffers
  86728. + * - Must be at least 2 transfers (otherwise pointless to use the FIQ)
  86729. + * If yes, then the fsm enqueue function will handle the state machine setup.
  86730. + */
  86731. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  86732. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  86733. + struct dwc_otg_hcd_iso_packet_desc (*iso_descs)[0] = &urb->iso_descs;
  86734. + int nr_iso_frames = urb->packet_count;
  86735. + int i;
  86736. + uint32_t ptr;
  86737. +
  86738. + if (nr_iso_frames < 2)
  86739. + return 0;
  86740. + for (i = 0; i < nr_iso_frames; i++) {
  86741. + ptr = urb->dma + iso_descs[i]->offset;
  86742. + if (ptr & 0x3) {
  86743. + printk_ratelimited("%s: Non-Dword aligned isochronous frame offset."
  86744. + " Cannot queue FIQ-accelerated transfer to device %d endpoint %d\n",
  86745. + __FUNCTION__, qh->channel->dev_addr, qh->channel->ep_num);
  86746. + return 0;
  86747. + }
  86748. + }
  86749. + return 1;
  86750. + }
  86751. + }
  86752. + return 0;
  86753. +}
  86754. +
  86755. +/**
  86756. + * fiq_fsm_setup_periodic_dma() - Set up DMA bounce buffers
  86757. + * @hcd: Pointer to the dwc_otg_hcd struct
  86758. + * @qh: Pointer to the endpoint's queue head
  86759. + *
  86760. + * Periodic split transactions are transmitted modulo 188 bytes.
  86761. + * This necessitates slicing data up into buckets for isochronous out
  86762. + * and fixing up the DMA address for all IN transfers.
  86763. + *
  86764. + * Returns 1 if the DMA bounce buffers have been used, 0 if the default
  86765. + * HC buffer has been used.
  86766. + */
  86767. +int fiq_fsm_setup_periodic_dma(dwc_otg_hcd_t *hcd, struct fiq_channel_state *st, dwc_otg_qh_t *qh)
  86768. + {
  86769. + int frame_length, i = 0;
  86770. + uint8_t *ptr = NULL;
  86771. + dwc_hc_t *hc = qh->channel;
  86772. + struct fiq_dma_blob *blob;
  86773. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  86774. +
  86775. + for (i = 0; i < 6; i++) {
  86776. + st->dma_info.slot_len[i] = 255;
  86777. + }
  86778. + st->dma_info.index = 0;
  86779. + i = 0;
  86780. + if (hc->ep_is_in) {
  86781. + /*
  86782. + * Set dma_regs to bounce buffer. FIQ will update the
  86783. + * state depending on transaction progress.
  86784. + */
  86785. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  86786. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  86787. + /* Calculate the max number of CSPLITS such that the FIQ can time out
  86788. + * a transaction if it fails.
  86789. + */
  86790. + frame_length = st->hcchar_copy.b.mps;
  86791. + do {
  86792. + i++;
  86793. + frame_length -= 188;
  86794. + } while (frame_length >= 0);
  86795. + st->nrpackets = i;
  86796. + return 1;
  86797. + } else {
  86798. + if (qh->ep_type == UE_ISOCHRONOUS) {
  86799. +
  86800. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  86801. +
  86802. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  86803. + frame_length = frame_desc->length;
  86804. +
  86805. + /* Virtual address for bounce buffers */
  86806. + blob = hcd->fiq_dmab;
  86807. +
  86808. + ptr = qtd->urb->buf + frame_desc->offset;
  86809. + if (frame_length == 0) {
  86810. + /*
  86811. + * for isochronous transactions, we must still transmit a packet
  86812. + * even if the length is zero.
  86813. + */
  86814. + st->dma_info.slot_len[0] = 0;
  86815. + st->nrpackets = 1;
  86816. + } else {
  86817. + do {
  86818. + if (frame_length <= 188) {
  86819. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, frame_length);
  86820. + st->dma_info.slot_len[i] = frame_length;
  86821. + ptr += frame_length;
  86822. + } else {
  86823. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, 188);
  86824. + st->dma_info.slot_len[i] = 188;
  86825. + ptr += 188;
  86826. + }
  86827. + i++;
  86828. + frame_length -= 188;
  86829. + } while (frame_length > 0);
  86830. + st->nrpackets = i;
  86831. + }
  86832. + ptr = qtd->urb->buf + frame_desc->offset;
  86833. + /* Point the HC at the DMA address of the bounce buffers */
  86834. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  86835. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  86836. +
  86837. + /* fixup xfersize to the actual packet size */
  86838. + st->hctsiz_copy.b.pid = 0;
  86839. + st->hctsiz_copy.b.xfersize = st->dma_info.slot_len[0];
  86840. + return 1;
  86841. + } else {
  86842. + /* For interrupt, single OUT packet required, goes in the SSPLIT from hc_buff. */
  86843. + return 0;
  86844. + }
  86845. + }
  86846. +}
  86847. +
  86848. +/*
  86849. + * Pushing a periodic request into the queue near the EOF1 point
  86850. + * in a microframe causes erroneous behaviour (frmovrun) interrupt.
  86851. + * Usually, the request goes out on the bus causing a transfer but
  86852. + * the core does not transfer the data to memory.
  86853. + * This guard interval (in number of 60MHz clocks) is required which
  86854. + * must cater for CPU latency between reading the value and enabling
  86855. + * the channel.
  86856. + */
  86857. +#define PERIODIC_FRREM_BACKOFF 1000
  86858. +
  86859. +int fiq_fsm_queue_isoc_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  86860. +{
  86861. + dwc_hc_t *hc = qh->channel;
  86862. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  86863. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  86864. + int frame;
  86865. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  86866. + int xfer_len, nrpackets;
  86867. + hcdma_data_t hcdma;
  86868. + hfnum_data_t hfnum;
  86869. +
  86870. + if (st->fsm != FIQ_PASSTHROUGH)
  86871. + return 0;
  86872. +
  86873. + st->nr_errors = 0;
  86874. +
  86875. + st->hcchar_copy.d32 = 0;
  86876. + st->hcchar_copy.b.mps = hc->max_packet;
  86877. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  86878. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  86879. + st->hcchar_copy.b.epnum = hc->ep_num;
  86880. + st->hcchar_copy.b.eptype = hc->ep_type;
  86881. +
  86882. + st->hcintmsk_copy.b.chhltd = 1;
  86883. +
  86884. + frame = dwc_otg_hcd_get_frame_number(hcd);
  86885. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  86886. +
  86887. + st->hcchar_copy.b.lspddev = 0;
  86888. + /* Enable the channel later as a final register write. */
  86889. +
  86890. + st->hcsplt_copy.d32 = 0;
  86891. +
  86892. + st->hs_isoc_info.iso_desc = (struct dwc_otg_hcd_iso_packet_desc *) &qtd->urb->iso_descs;
  86893. + st->hs_isoc_info.nrframes = qtd->urb->packet_count;
  86894. + /* grab the next DMA address offset from the array */
  86895. + st->hcdma_copy.d32 = qtd->urb->dma;
  86896. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[0].offset;
  86897. +
  86898. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  86899. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  86900. + * this is always set to the maximum size of the endpoint. */
  86901. + xfer_len = st->hs_isoc_info.iso_desc[0].length;
  86902. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  86903. + if (nrpackets == 0)
  86904. + nrpackets = 1;
  86905. + st->hcchar_copy.b.multicnt = nrpackets;
  86906. + st->hctsiz_copy.b.pktcnt = nrpackets;
  86907. +
  86908. + /* Initial PID also needs to be set */
  86909. + if (st->hcchar_copy.b.epdir == 0) {
  86910. + st->hctsiz_copy.b.xfersize = xfer_len;
  86911. + switch (st->hcchar_copy.b.multicnt) {
  86912. + case 1:
  86913. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  86914. + break;
  86915. + case 2:
  86916. + case 3:
  86917. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  86918. + break;
  86919. + }
  86920. +
  86921. + } else {
  86922. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  86923. + switch (st->hcchar_copy.b.multicnt) {
  86924. + case 1:
  86925. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  86926. + break;
  86927. + case 2:
  86928. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  86929. + break;
  86930. + case 3:
  86931. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  86932. + break;
  86933. + }
  86934. + }
  86935. +
  86936. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d ", hc->hc_num);
  86937. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcchar_copy.d32);
  86938. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  86939. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  86940. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  86941. + local_fiq_disable();
  86942. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  86943. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  86944. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  86945. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  86946. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  86947. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  86948. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  86949. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  86950. + * split transaction is queued very close to EOF.
  86951. + */
  86952. + st->fsm = FIQ_HS_ISOC_SLEEPING;
  86953. + } else {
  86954. + st->fsm = FIQ_HS_ISOC_TURBO;
  86955. + st->hcchar_copy.b.chen = 1;
  86956. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  86957. + }
  86958. + mb();
  86959. + st->hcchar_copy.b.chen = 0;
  86960. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  86961. + local_fiq_enable();
  86962. + return 0;
  86963. +}
  86964. +
  86965. +
  86966. +/**
  86967. + * fiq_fsm_queue_split_transaction() - Set up a host channel and FIQ state
  86968. + * @hcd: Pointer to the dwc_otg_hcd struct
  86969. + * @qh: Pointer to the endpoint's queue head
  86970. + *
  86971. + * This overrides the dwc_otg driver's normal method of queueing a transaction.
  86972. + * Called from dwc_otg_hcd_queue_transactions(), this performs specific setup
  86973. + * for the nominated host channel.
  86974. + *
  86975. + * For periodic transfers, it also peeks at the FIQ state to see if an immediate
  86976. + * start is possible. If not, then the FIQ is left to start the transfer.
  86977. + */
  86978. +int fiq_fsm_queue_split_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  86979. +{
  86980. + int start_immediate = 1, i;
  86981. + hfnum_data_t hfnum;
  86982. + dwc_hc_t *hc = qh->channel;
  86983. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  86984. + /* Program HC registers, setup FIQ_state, examine FIQ if periodic, start transfer (not if uframe 5) */
  86985. + int hub_addr, port_addr, frame, uframe;
  86986. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  86987. +
  86988. + if (st->fsm != FIQ_PASSTHROUGH)
  86989. + return 0;
  86990. + st->nr_errors = 0;
  86991. +
  86992. + st->hcchar_copy.d32 = 0;
  86993. + st->hcchar_copy.b.mps = hc->max_packet;
  86994. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  86995. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  86996. + st->hcchar_copy.b.epnum = hc->ep_num;
  86997. + st->hcchar_copy.b.eptype = hc->ep_type;
  86998. + if (hc->ep_type & 0x1) {
  86999. + if (hc->ep_is_in)
  87000. + st->hcchar_copy.b.multicnt = 3;
  87001. + else
  87002. + /* Docs say set this to 1, but driver sets to 0! */
  87003. + st->hcchar_copy.b.multicnt = 0;
  87004. + } else {
  87005. + st->hcchar_copy.b.multicnt = 1;
  87006. + st->hcchar_copy.b.oddfrm = 0;
  87007. + }
  87008. + st->hcchar_copy.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW) ? 1 : 0;
  87009. + /* Enable the channel later as a final register write. */
  87010. +
  87011. + st->hcsplt_copy.d32 = 0;
  87012. + if(qh->do_split) {
  87013. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  87014. + st->hcsplt_copy.b.compsplt = 0;
  87015. + st->hcsplt_copy.b.spltena = 1;
  87016. + // XACTPOS is for isoc-out only but needs initialising anyway.
  87017. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_ALL;
  87018. + if((qh->ep_type == DWC_OTG_EP_TYPE_ISOC) && (!qh->ep_is_in)) {
  87019. + /* For packetsize 0 < L < 188, ISOC_XACTPOS_ALL.
  87020. + * for longer than this, ISOC_XACTPOS_BEGIN and the FIQ
  87021. + * will update as necessary.
  87022. + */
  87023. + if (hc->xfer_len > 188) {
  87024. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_BEGIN;
  87025. + }
  87026. + }
  87027. + st->hcsplt_copy.b.hubaddr = (uint8_t) hub_addr;
  87028. + st->hcsplt_copy.b.prtaddr = (uint8_t) port_addr;
  87029. + st->hub_addr = hub_addr;
  87030. + st->port_addr = port_addr;
  87031. + }
  87032. +
  87033. + st->hctsiz_copy.d32 = 0;
  87034. + st->hctsiz_copy.b.dopng = 0;
  87035. + st->hctsiz_copy.b.pid = hc->data_pid_start;
  87036. +
  87037. + if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  87038. + hc->xfer_len = hc->max_packet;
  87039. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  87040. + hc->xfer_len = 188;
  87041. + }
  87042. + st->hctsiz_copy.b.xfersize = hc->xfer_len;
  87043. +
  87044. + st->hctsiz_copy.b.pktcnt = 1;
  87045. +
  87046. + if (hc->ep_type & 0x1) {
  87047. + /*
  87048. + * For potentially multi-packet transfers, must use the DMA bounce buffers. For IN transfers,
  87049. + * the DMA address is the address of the first 188byte slot buffer in the bounce buffer array.
  87050. + * For multi-packet OUT transfers, we need to copy the data into the bounce buffer array so the FIQ can punt
  87051. + * the right address out as necessary. hc->xfer_buff and hc->xfer_len have already been set
  87052. + * in assign_and_init_hc(), but this is for the eventual transaction completion only. The FIQ
  87053. + * must not touch internal driver state.
  87054. + */
  87055. + if(!fiq_fsm_setup_periodic_dma(hcd, st, qh)) {
  87056. + if (hc->align_buff) {
  87057. + st->hcdma_copy.d32 = hc->align_buff;
  87058. + } else {
  87059. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  87060. + }
  87061. + }
  87062. + } else {
  87063. + if (hc->align_buff) {
  87064. + st->hcdma_copy.d32 = hc->align_buff;
  87065. + } else {
  87066. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  87067. + }
  87068. + }
  87069. + /* The FIQ depends upon no other interrupts being enabled except channel halt.
  87070. + * Fixup channel interrupt mask. */
  87071. + st->hcintmsk_copy.d32 = 0;
  87072. + st->hcintmsk_copy.b.chhltd = 1;
  87073. + st->hcintmsk_copy.b.ahberr = 1;
  87074. +
  87075. + /* Hack courtesy of FreeBSD: apparently forcing Interrupt Split transactions
  87076. + * as Control puts the transfer into the non-periodic request queue and the
  87077. + * non-periodic handler in the hub. Makes things lots easier.
  87078. + */
  87079. + if ((fiq_fsm_mask & 0x8) && hc->ep_type == UE_INTERRUPT) {
  87080. + st->hcchar_copy.b.multicnt = 0;
  87081. + st->hcchar_copy.b.oddfrm = 0;
  87082. + st->hcchar_copy.b.eptype = UE_CONTROL;
  87083. + if (hc->align_buff) {
  87084. + st->hcdma_copy.d32 = hc->align_buff;
  87085. + } else {
  87086. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  87087. + }
  87088. + }
  87089. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  87090. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  87091. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  87092. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  87093. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  87094. +
  87095. + local_fiq_disable();
  87096. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  87097. +
  87098. + if (hc->ep_type & 0x1) {
  87099. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  87100. + frame = (hfnum.b.frnum & ~0x7) >> 3;
  87101. + uframe = hfnum.b.frnum & 0x7;
  87102. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  87103. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  87104. + * split transaction is queued very close to EOF.
  87105. + */
  87106. + start_immediate = 0;
  87107. + } else if (uframe == 5) {
  87108. + start_immediate = 0;
  87109. + } else if (hc->ep_type == UE_ISOCHRONOUS && !hc->ep_is_in) {
  87110. + start_immediate = 0;
  87111. + } else if (hc->ep_is_in && fiq_fsm_too_late(hcd->fiq_state, hc->hc_num)) {
  87112. + start_immediate = 0;
  87113. + } else {
  87114. + /* Search through all host channels to determine if a transaction
  87115. + * is currently in progress */
  87116. + for (i = 0; i < hcd->core_if->core_params->host_channels; i++) {
  87117. + if (i == hc->hc_num || hcd->fiq_state->channel[i].fsm == FIQ_PASSTHROUGH)
  87118. + continue;
  87119. + switch (hcd->fiq_state->channel[i].fsm) {
  87120. + /* TT is reserved for channels that are in the middle of a periodic
  87121. + * split transaction.
  87122. + */
  87123. + case FIQ_PER_SSPLIT_STARTED:
  87124. + case FIQ_PER_CSPLIT_WAIT:
  87125. + case FIQ_PER_CSPLIT_NYET1:
  87126. + case FIQ_PER_CSPLIT_POLL:
  87127. + case FIQ_PER_ISO_OUT_ACTIVE:
  87128. + case FIQ_PER_ISO_OUT_LAST:
  87129. + if (hcd->fiq_state->channel[i].hub_addr == hub_addr &&
  87130. + hcd->fiq_state->channel[i].port_addr == port_addr) {
  87131. + start_immediate = 0;
  87132. + }
  87133. + break;
  87134. + default:
  87135. + break;
  87136. + }
  87137. + if (!start_immediate)
  87138. + break;
  87139. + }
  87140. + }
  87141. + }
  87142. + if ((fiq_fsm_mask & 0x8) && hc->ep_type == UE_INTERRUPT)
  87143. + start_immediate = 1;
  87144. +
  87145. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d %01d", hc->hc_num, start_immediate);
  87146. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08d", hfnum.b.frrem);
  87147. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "H:%02dP:%02d", hub_addr, port_addr);
  87148. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  87149. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  87150. + switch (hc->ep_type) {
  87151. + case UE_CONTROL:
  87152. + case UE_BULK:
  87153. + st->fsm = FIQ_NP_SSPLIT_STARTED;
  87154. + break;
  87155. + case UE_ISOCHRONOUS:
  87156. + if (hc->ep_is_in) {
  87157. + if (start_immediate) {
  87158. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  87159. + } else {
  87160. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  87161. + }
  87162. + } else {
  87163. + if (start_immediate) {
  87164. + /* Single-isoc OUT packets don't require FIQ involvement */
  87165. + if (st->nrpackets == 1) {
  87166. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  87167. + } else {
  87168. + st->fsm = FIQ_PER_ISO_OUT_ACTIVE;
  87169. + }
  87170. + } else {
  87171. + st->fsm = FIQ_PER_ISO_OUT_PENDING;
  87172. + }
  87173. + }
  87174. + break;
  87175. + case UE_INTERRUPT:
  87176. + if (fiq_fsm_mask & 0x8) {
  87177. + st->fsm = FIQ_NP_SSPLIT_STARTED;
  87178. + } else if (start_immediate) {
  87179. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  87180. + } else {
  87181. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  87182. + }
  87183. + default:
  87184. + break;
  87185. + }
  87186. + if (start_immediate) {
  87187. + /* Set the oddfrm bit as close as possible to actual queueing */
  87188. + frame = dwc_otg_hcd_get_frame_number(hcd);
  87189. + st->expected_uframe = (frame + 1) & 0x3FFF;
  87190. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  87191. + st->hcchar_copy.b.chen = 1;
  87192. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  87193. + }
  87194. + mb();
  87195. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  87196. + local_fiq_enable();
  87197. + return 0;
  87198. +}
  87199. +
  87200. +
  87201. +/**
  87202. + * This function selects transactions from the HCD transfer schedule and
  87203. + * assigns them to available host channels. It is called from HCD interrupt
  87204. + * handler functions.
  87205. + *
  87206. + * @param hcd The HCD state structure.
  87207. + *
  87208. + * @return The types of new transactions that were assigned to host channels.
  87209. + */
  87210. +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
  87211. +{
  87212. + dwc_list_link_t *qh_ptr;
  87213. + dwc_otg_qh_t *qh;
  87214. + int num_channels;
  87215. + dwc_irqflags_t flags;
  87216. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  87217. + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
  87218. +
  87219. +#ifdef DEBUG_HOST_CHANNELS
  87220. + last_sel_trans_num_per_scheduled = 0;
  87221. + last_sel_trans_num_nonper_scheduled = 0;
  87222. + last_sel_trans_num_avail_hc_at_start = hcd->available_host_channels;
  87223. +#endif /* DEBUG_HOST_CHANNELS */
  87224. +
  87225. + /* Process entries in the periodic ready list. */
  87226. + qh_ptr = DWC_LIST_FIRST(&hcd->periodic_sched_ready);
  87227. +
  87228. + while (qh_ptr != &hcd->periodic_sched_ready &&
  87229. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  87230. +
  87231. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  87232. +
  87233. + if (microframe_schedule) {
  87234. + // Make sure we leave one channel for non periodic transactions.
  87235. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  87236. + if (hcd->available_host_channels <= 1) {
  87237. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  87238. + break;
  87239. + }
  87240. + hcd->available_host_channels--;
  87241. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  87242. +#ifdef DEBUG_HOST_CHANNELS
  87243. + last_sel_trans_num_per_scheduled++;
  87244. +#endif /* DEBUG_HOST_CHANNELS */
  87245. + }
  87246. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  87247. + assign_and_init_hc(hcd, qh);
  87248. +
  87249. + /*
  87250. + * Move the QH from the periodic ready schedule to the
  87251. + * periodic assigned schedule.
  87252. + */
  87253. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  87254. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  87255. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  87256. + &qh->qh_list_entry);
  87257. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  87258. + }
  87259. +
  87260. + /*
  87261. + * Process entries in the inactive portion of the non-periodic
  87262. + * schedule. Some free host channels may not be used if they are
  87263. + * reserved for periodic transfers.
  87264. + */
  87265. + qh_ptr = hcd->non_periodic_sched_inactive.next;
  87266. + num_channels = hcd->core_if->core_params->host_channels;
  87267. + while (qh_ptr != &hcd->non_periodic_sched_inactive &&
  87268. + (microframe_schedule || hcd->non_periodic_channels <
  87269. + num_channels - hcd->periodic_channels) &&
  87270. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  87271. +
  87272. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  87273. + /*
  87274. + * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
  87275. + * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
  87276. + * cheeky devices that just hold off using NAKs
  87277. + */
  87278. + if (nak_holdoff && qh->do_split) {
  87279. + if (qh->nak_frame != 0xffff) {
  87280. + uint16_t next_frame = dwc_frame_num_inc(qh->nak_frame, (qh->ep_type == UE_BULK) ? nak_holdoff : 8);
  87281. + uint16_t frame = dwc_otg_hcd_get_frame_number(hcd);
  87282. + if (dwc_frame_num_le(frame, next_frame)) {
  87283. + if(dwc_frame_num_le(next_frame, hcd->fiq_state->next_sched_frame)) {
  87284. + hcd->fiq_state->next_sched_frame = next_frame;
  87285. + }
  87286. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  87287. + continue;
  87288. + } else {
  87289. + qh->nak_frame = 0xFFFF;
  87290. + }
  87291. + }
  87292. + }
  87293. +
  87294. + if (microframe_schedule) {
  87295. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  87296. + if (hcd->available_host_channels < 1) {
  87297. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  87298. + break;
  87299. + }
  87300. + hcd->available_host_channels--;
  87301. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  87302. +#ifdef DEBUG_HOST_CHANNELS
  87303. + last_sel_trans_num_nonper_scheduled++;
  87304. +#endif /* DEBUG_HOST_CHANNELS */
  87305. + }
  87306. +
  87307. + assign_and_init_hc(hcd, qh);
  87308. +
  87309. + /*
  87310. + * Move the QH from the non-periodic inactive schedule to the
  87311. + * non-periodic active schedule.
  87312. + */
  87313. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  87314. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  87315. + DWC_LIST_MOVE_HEAD(&hcd->non_periodic_sched_active,
  87316. + &qh->qh_list_entry);
  87317. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  87318. +
  87319. +
  87320. + if (!microframe_schedule)
  87321. + hcd->non_periodic_channels++;
  87322. + }
  87323. + /* we moved a non-periodic QH to the active schedule. If the inactive queue is empty,
  87324. + * stop the FIQ from kicking us. We could potentially still have elements here if we
  87325. + * ran out of host channels.
  87326. + */
  87327. + if (fiq_enable) {
  87328. + if (DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive)) {
  87329. + hcd->fiq_state->kick_np_queues = 0;
  87330. + } else {
  87331. + /* For each entry remaining in the NP inactive queue,
  87332. + * if this a NAK'd retransmit then don't set the kick flag.
  87333. + */
  87334. + if(nak_holdoff) {
  87335. + DWC_LIST_FOREACH(qh_ptr, &hcd->non_periodic_sched_inactive) {
  87336. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  87337. + if (qh->nak_frame == 0xFFFF) {
  87338. + hcd->fiq_state->kick_np_queues = 1;
  87339. + }
  87340. + }
  87341. + }
  87342. + }
  87343. + }
  87344. + if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
  87345. + ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
  87346. +
  87347. + if(!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active))
  87348. + ret_val |= DWC_OTG_TRANSACTION_NON_PERIODIC;
  87349. +
  87350. +
  87351. +#ifdef DEBUG_HOST_CHANNELS
  87352. + last_sel_trans_num_avail_hc_at_end = hcd->available_host_channels;
  87353. +#endif /* DEBUG_HOST_CHANNELS */
  87354. + return ret_val;
  87355. +}
  87356. +
  87357. +/**
  87358. + * Attempts to queue a single transaction request for a host channel
  87359. + * associated with either a periodic or non-periodic transfer. This function
  87360. + * assumes that there is space available in the appropriate request queue. For
  87361. + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
  87362. + * is available in the appropriate Tx FIFO.
  87363. + *
  87364. + * @param hcd The HCD state structure.
  87365. + * @param hc Host channel descriptor associated with either a periodic or
  87366. + * non-periodic transfer.
  87367. + * @param fifo_dwords_avail Number of DWORDs available in the periodic Tx
  87368. + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
  87369. + * transfers.
  87370. + *
  87371. + * @return 1 if a request is queued and more requests may be needed to
  87372. + * complete the transfer, 0 if no more requests are required for this
  87373. + * transfer, -1 if there is insufficient space in the Tx FIFO.
  87374. + */
  87375. +static int queue_transaction(dwc_otg_hcd_t * hcd,
  87376. + dwc_hc_t * hc, uint16_t fifo_dwords_avail)
  87377. +{
  87378. + int retval;
  87379. +
  87380. + if (hcd->core_if->dma_enable) {
  87381. + if (hcd->core_if->dma_desc_enable) {
  87382. + if (!hc->xfer_started
  87383. + || (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
  87384. + dwc_otg_hcd_start_xfer_ddma(hcd, hc->qh);
  87385. + hc->qh->ping_state = 0;
  87386. + }
  87387. + } else if (!hc->xfer_started) {
  87388. + if (fiq_fsm_enable && hc->error_state) {
  87389. + hcd->fiq_state->channel[hc->hc_num].nr_errors =
  87390. + DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list)->error_count;
  87391. + hcd->fiq_state->channel[hc->hc_num].fsm =
  87392. + FIQ_PASSTHROUGH_ERRORSTATE;
  87393. + }
  87394. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  87395. + hc->qh->ping_state = 0;
  87396. + }
  87397. + retval = 0;
  87398. + } else if (hc->halt_pending) {
  87399. + /* Don't queue a request if the channel has been halted. */
  87400. + retval = 0;
  87401. + } else if (hc->halt_on_queue) {
  87402. + dwc_otg_hc_halt(hcd->core_if, hc, hc->halt_status);
  87403. + retval = 0;
  87404. + } else if (hc->do_ping) {
  87405. + if (!hc->xfer_started) {
  87406. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  87407. + }
  87408. + retval = 0;
  87409. + } else if (!hc->ep_is_in || hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  87410. + if ((fifo_dwords_avail * 4) >= hc->max_packet) {
  87411. + if (!hc->xfer_started) {
  87412. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  87413. + retval = 1;
  87414. + } else {
  87415. + retval =
  87416. + dwc_otg_hc_continue_transfer(hcd->core_if,
  87417. + hc);
  87418. + }
  87419. + } else {
  87420. + retval = -1;
  87421. + }
  87422. + } else {
  87423. + if (!hc->xfer_started) {
  87424. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  87425. + retval = 1;
  87426. + } else {
  87427. + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
  87428. + }
  87429. + }
  87430. +
  87431. + return retval;
  87432. +}
  87433. +
  87434. +/**
  87435. + * Processes periodic channels for the next frame and queues transactions for
  87436. + * these channels to the DWC_otg controller. After queueing transactions, the
  87437. + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
  87438. + * to queue as Periodic Tx FIFO or request queue space becomes available.
  87439. + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
  87440. + */
  87441. +static void process_periodic_channels(dwc_otg_hcd_t * hcd)
  87442. +{
  87443. + hptxsts_data_t tx_status;
  87444. + dwc_list_link_t *qh_ptr;
  87445. + dwc_otg_qh_t *qh;
  87446. + int status = 0;
  87447. + int no_queue_space = 0;
  87448. + int no_fifo_space = 0;
  87449. +
  87450. + dwc_otg_host_global_regs_t *host_regs;
  87451. + host_regs = hcd->core_if->host_if->host_global_regs;
  87452. +
  87453. + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
  87454. +#ifdef DEBUG
  87455. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  87456. + DWC_DEBUGPL(DBG_HCDV,
  87457. + " P Tx Req Queue Space Avail (before queue): %d\n",
  87458. + tx_status.b.ptxqspcavail);
  87459. + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
  87460. + tx_status.b.ptxfspcavail);
  87461. +#endif
  87462. +
  87463. + qh_ptr = hcd->periodic_sched_assigned.next;
  87464. + while (qh_ptr != &hcd->periodic_sched_assigned) {
  87465. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  87466. + if (tx_status.b.ptxqspcavail == 0) {
  87467. + no_queue_space = 1;
  87468. + break;
  87469. + }
  87470. +
  87471. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  87472. +
  87473. + // Do not send a split start transaction any later than frame .6
  87474. + // Note, we have to schedule a periodic in .5 to make it go in .6
  87475. + if(fiq_fsm_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  87476. + {
  87477. + qh_ptr = qh_ptr->next;
  87478. + hcd->fiq_state->next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  87479. + continue;
  87480. + }
  87481. +
  87482. + if (fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  87483. + if (qh->do_split)
  87484. + fiq_fsm_queue_split_transaction(hcd, qh);
  87485. + else
  87486. + fiq_fsm_queue_isoc_transaction(hcd, qh);
  87487. + } else {
  87488. +
  87489. + /*
  87490. + * Set a flag if we're queueing high-bandwidth in slave mode.
  87491. + * The flag prevents any halts to get into the request queue in
  87492. + * the middle of multiple high-bandwidth packets getting queued.
  87493. + */
  87494. + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
  87495. + hcd->core_if->queuing_high_bandwidth = 1;
  87496. + }
  87497. + status = queue_transaction(hcd, qh->channel,
  87498. + tx_status.b.ptxfspcavail);
  87499. + if (status < 0) {
  87500. + no_fifo_space = 1;
  87501. + break;
  87502. + }
  87503. + }
  87504. +
  87505. + /*
  87506. + * In Slave mode, stay on the current transfer until there is
  87507. + * nothing more to do or the high-bandwidth request count is
  87508. + * reached. In DMA mode, only need to queue one request. The
  87509. + * controller automatically handles multiple packets for
  87510. + * high-bandwidth transfers.
  87511. + */
  87512. + if (hcd->core_if->dma_enable || status == 0 ||
  87513. + qh->channel->requests == qh->channel->multi_count) {
  87514. + qh_ptr = qh_ptr->next;
  87515. + /*
  87516. + * Move the QH from the periodic assigned schedule to
  87517. + * the periodic queued schedule.
  87518. + */
  87519. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_queued,
  87520. + &qh->qh_list_entry);
  87521. +
  87522. + /* done queuing high bandwidth */
  87523. + hcd->core_if->queuing_high_bandwidth = 0;
  87524. + }
  87525. + }
  87526. +
  87527. + if (!hcd->core_if->dma_enable) {
  87528. + dwc_otg_core_global_regs_t *global_regs;
  87529. + gintmsk_data_t intr_mask = {.d32 = 0 };
  87530. +
  87531. + global_regs = hcd->core_if->core_global_regs;
  87532. + intr_mask.b.ptxfempty = 1;
  87533. +#ifdef DEBUG
  87534. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  87535. + DWC_DEBUGPL(DBG_HCDV,
  87536. + " P Tx Req Queue Space Avail (after queue): %d\n",
  87537. + tx_status.b.ptxqspcavail);
  87538. + DWC_DEBUGPL(DBG_HCDV,
  87539. + " P Tx FIFO Space Avail (after queue): %d\n",
  87540. + tx_status.b.ptxfspcavail);
  87541. +#endif
  87542. + if (!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned) ||
  87543. + no_queue_space || no_fifo_space) {
  87544. + /*
  87545. + * May need to queue more transactions as the request
  87546. + * queue or Tx FIFO empties. Enable the periodic Tx
  87547. + * FIFO empty interrupt. (Always use the half-empty
  87548. + * level to ensure that new requests are loaded as
  87549. + * soon as possible.)
  87550. + */
  87551. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  87552. + intr_mask.d32);
  87553. + } else {
  87554. + /*
  87555. + * Disable the Tx FIFO empty interrupt since there are
  87556. + * no more transactions that need to be queued right
  87557. + * now. This function is called from interrupt
  87558. + * handlers to queue more transactions as transfer
  87559. + * states change.
  87560. + */
  87561. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  87562. + 0);
  87563. + }
  87564. + }
  87565. +}
  87566. +
  87567. +/**
  87568. + * Processes active non-periodic channels and queues transactions for these
  87569. + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
  87570. + * FIFO Empty interrupt is enabled if there are more transactions to queue as
  87571. + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
  87572. + * FIFO Empty interrupt is disabled.
  87573. + */
  87574. +static void process_non_periodic_channels(dwc_otg_hcd_t * hcd)
  87575. +{
  87576. + gnptxsts_data_t tx_status;
  87577. + dwc_list_link_t *orig_qh_ptr;
  87578. + dwc_otg_qh_t *qh;
  87579. + int status;
  87580. + int no_queue_space = 0;
  87581. + int no_fifo_space = 0;
  87582. + int more_to_do = 0;
  87583. +
  87584. + dwc_otg_core_global_regs_t *global_regs =
  87585. + hcd->core_if->core_global_regs;
  87586. +
  87587. + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
  87588. +#ifdef DEBUG
  87589. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  87590. + DWC_DEBUGPL(DBG_HCDV,
  87591. + " NP Tx Req Queue Space Avail (before queue): %d\n",
  87592. + tx_status.b.nptxqspcavail);
  87593. + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
  87594. + tx_status.b.nptxfspcavail);
  87595. +#endif
  87596. + /*
  87597. + * Keep track of the starting point. Skip over the start-of-list
  87598. + * entry.
  87599. + */
  87600. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  87601. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  87602. + }
  87603. + orig_qh_ptr = hcd->non_periodic_qh_ptr;
  87604. +
  87605. + /*
  87606. + * Process once through the active list or until no more space is
  87607. + * available in the request queue or the Tx FIFO.
  87608. + */
  87609. + do {
  87610. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  87611. + if (!hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
  87612. + no_queue_space = 1;
  87613. + break;
  87614. + }
  87615. +
  87616. + qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
  87617. + qh_list_entry);
  87618. +
  87619. + if(fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  87620. + fiq_fsm_queue_split_transaction(hcd, qh);
  87621. + } else {
  87622. + status = queue_transaction(hcd, qh->channel,
  87623. + tx_status.b.nptxfspcavail);
  87624. +
  87625. + if (status > 0) {
  87626. + more_to_do = 1;
  87627. + } else if (status < 0) {
  87628. + no_fifo_space = 1;
  87629. + break;
  87630. + }
  87631. + }
  87632. + /* Advance to next QH, skipping start-of-list entry. */
  87633. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  87634. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  87635. + hcd->non_periodic_qh_ptr =
  87636. + hcd->non_periodic_qh_ptr->next;
  87637. + }
  87638. +
  87639. + } while (hcd->non_periodic_qh_ptr != orig_qh_ptr);
  87640. +
  87641. + if (!hcd->core_if->dma_enable) {
  87642. + gintmsk_data_t intr_mask = {.d32 = 0 };
  87643. + intr_mask.b.nptxfempty = 1;
  87644. +
  87645. +#ifdef DEBUG
  87646. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  87647. + DWC_DEBUGPL(DBG_HCDV,
  87648. + " NP Tx Req Queue Space Avail (after queue): %d\n",
  87649. + tx_status.b.nptxqspcavail);
  87650. + DWC_DEBUGPL(DBG_HCDV,
  87651. + " NP Tx FIFO Space Avail (after queue): %d\n",
  87652. + tx_status.b.nptxfspcavail);
  87653. +#endif
  87654. + if (more_to_do || no_queue_space || no_fifo_space) {
  87655. + /*
  87656. + * May need to queue more transactions as the request
  87657. + * queue or Tx FIFO empties. Enable the non-periodic
  87658. + * Tx FIFO empty interrupt. (Always use the half-empty
  87659. + * level to ensure that new requests are loaded as
  87660. + * soon as possible.)
  87661. + */
  87662. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  87663. + intr_mask.d32);
  87664. + } else {
  87665. + /*
  87666. + * Disable the Tx FIFO empty interrupt since there are
  87667. + * no more transactions that need to be queued right
  87668. + * now. This function is called from interrupt
  87669. + * handlers to queue more transactions as transfer
  87670. + * states change.
  87671. + */
  87672. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  87673. + 0);
  87674. + }
  87675. + }
  87676. +}
  87677. +
  87678. +/**
  87679. + * This function processes the currently active host channels and queues
  87680. + * transactions for these channels to the DWC_otg controller. It is called
  87681. + * from HCD interrupt handler functions.
  87682. + *
  87683. + * @param hcd The HCD state structure.
  87684. + * @param tr_type The type(s) of transactions to queue (non-periodic,
  87685. + * periodic, or both).
  87686. + */
  87687. +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  87688. + dwc_otg_transaction_type_e tr_type)
  87689. +{
  87690. +#ifdef DEBUG_SOF
  87691. + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
  87692. +#endif
  87693. + /* Process host channels associated with periodic transfers. */
  87694. + if ((tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
  87695. + tr_type == DWC_OTG_TRANSACTION_ALL) &&
  87696. + !DWC_LIST_EMPTY(&hcd->periodic_sched_assigned)) {
  87697. +
  87698. + process_periodic_channels(hcd);
  87699. + }
  87700. +
  87701. + /* Process host channels associated with non-periodic transfers. */
  87702. + if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
  87703. + tr_type == DWC_OTG_TRANSACTION_ALL) {
  87704. + if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active)) {
  87705. + process_non_periodic_channels(hcd);
  87706. + } else {
  87707. + /*
  87708. + * Ensure NP Tx FIFO empty interrupt is disabled when
  87709. + * there are no non-periodic transfers to process.
  87710. + */
  87711. + gintmsk_data_t gintmsk = {.d32 = 0 };
  87712. + gintmsk.b.nptxfempty = 1;
  87713. +
  87714. + if (fiq_enable) {
  87715. + local_fiq_disable();
  87716. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  87717. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  87718. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  87719. + local_fiq_enable();
  87720. + } else {
  87721. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  87722. + }
  87723. + }
  87724. + }
  87725. +}
  87726. +
  87727. +#ifdef DWC_HS_ELECT_TST
  87728. +/*
  87729. + * Quick and dirty hack to implement the HS Electrical Test
  87730. + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
  87731. + *
  87732. + * This code was copied from our userspace app "hset". It sends a
  87733. + * Get Device Descriptor control sequence in two parts, first the
  87734. + * Setup packet by itself, followed some time later by the In and
  87735. + * Ack packets. Rather than trying to figure out how to add this
  87736. + * functionality to the normal driver code, we just hijack the
  87737. + * hardware, using these two function to drive the hardware
  87738. + * directly.
  87739. + */
  87740. +
  87741. +static dwc_otg_core_global_regs_t *global_regs;
  87742. +static dwc_otg_host_global_regs_t *hc_global_regs;
  87743. +static dwc_otg_hc_regs_t *hc_regs;
  87744. +static uint32_t *data_fifo;
  87745. +
  87746. +static void do_setup(void)
  87747. +{
  87748. + gintsts_data_t gintsts;
  87749. + hctsiz_data_t hctsiz;
  87750. + hcchar_data_t hcchar;
  87751. + haint_data_t haint;
  87752. + hcint_data_t hcint;
  87753. +
  87754. + /* Enable HAINTs */
  87755. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  87756. +
  87757. + /* Enable HCINTs */
  87758. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  87759. +
  87760. + /* Read GINTSTS */
  87761. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  87762. +
  87763. + /* Read HAINT */
  87764. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  87765. +
  87766. + /* Read HCINT */
  87767. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  87768. +
  87769. + /* Read HCCHAR */
  87770. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  87771. +
  87772. + /* Clear HCINT */
  87773. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  87774. +
  87775. + /* Clear HAINT */
  87776. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  87777. +
  87778. + /* Clear GINTSTS */
  87779. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  87780. +
  87781. + /* Read GINTSTS */
  87782. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  87783. +
  87784. + /*
  87785. + * Send Setup packet (Get Device Descriptor)
  87786. + */
  87787. +
  87788. + /* Make sure channel is disabled */
  87789. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  87790. + if (hcchar.b.chen) {
  87791. + hcchar.b.chdis = 1;
  87792. +// hcchar.b.chen = 1;
  87793. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  87794. + //sleep(1);
  87795. + dwc_mdelay(1000);
  87796. +
  87797. + /* Read GINTSTS */
  87798. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  87799. +
  87800. + /* Read HAINT */
  87801. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  87802. +
  87803. + /* Read HCINT */
  87804. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  87805. +
  87806. + /* Read HCCHAR */
  87807. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  87808. +
  87809. + /* Clear HCINT */
  87810. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  87811. +
  87812. + /* Clear HAINT */
  87813. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  87814. +
  87815. + /* Clear GINTSTS */
  87816. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  87817. +
  87818. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  87819. + }
  87820. +
  87821. + /* Set HCTSIZ */
  87822. + hctsiz.d32 = 0;
  87823. + hctsiz.b.xfersize = 8;
  87824. + hctsiz.b.pktcnt = 1;
  87825. + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
  87826. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  87827. +
  87828. + /* Set HCCHAR */
  87829. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  87830. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  87831. + hcchar.b.epdir = 0;
  87832. + hcchar.b.epnum = 0;
  87833. + hcchar.b.mps = 8;
  87834. + hcchar.b.chen = 1;
  87835. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  87836. +
  87837. + /* Fill FIFO with Setup data for Get Device Descriptor */
  87838. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  87839. + DWC_WRITE_REG32(data_fifo++, 0x01000680);
  87840. + DWC_WRITE_REG32(data_fifo++, 0x00080000);
  87841. +
  87842. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  87843. +
  87844. + /* Wait for host channel interrupt */
  87845. + do {
  87846. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  87847. + } while (gintsts.b.hcintr == 0);
  87848. +
  87849. + /* Disable HCINTs */
  87850. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  87851. +
  87852. + /* Disable HAINTs */
  87853. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  87854. +
  87855. + /* Read HAINT */
  87856. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  87857. +
  87858. + /* Read HCINT */
  87859. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  87860. +
  87861. + /* Read HCCHAR */
  87862. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  87863. +
  87864. + /* Clear HCINT */
  87865. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  87866. +
  87867. + /* Clear HAINT */
  87868. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  87869. +
  87870. + /* Clear GINTSTS */
  87871. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  87872. +
  87873. + /* Read GINTSTS */
  87874. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  87875. +}
  87876. +
  87877. +static void do_in_ack(void)
  87878. +{
  87879. + gintsts_data_t gintsts;
  87880. + hctsiz_data_t hctsiz;
  87881. + hcchar_data_t hcchar;
  87882. + haint_data_t haint;
  87883. + hcint_data_t hcint;
  87884. + host_grxsts_data_t grxsts;
  87885. +
  87886. + /* Enable HAINTs */
  87887. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  87888. +
  87889. + /* Enable HCINTs */
  87890. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  87891. +
  87892. + /* Read GINTSTS */
  87893. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  87894. +
  87895. + /* Read HAINT */
  87896. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  87897. +
  87898. + /* Read HCINT */
  87899. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  87900. +
  87901. + /* Read HCCHAR */
  87902. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  87903. +
  87904. + /* Clear HCINT */
  87905. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  87906. +
  87907. + /* Clear HAINT */
  87908. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  87909. +
  87910. + /* Clear GINTSTS */
  87911. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  87912. +
  87913. + /* Read GINTSTS */
  87914. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  87915. +
  87916. + /*
  87917. + * Receive Control In packet
  87918. + */
  87919. +
  87920. + /* Make sure channel is disabled */
  87921. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  87922. + if (hcchar.b.chen) {
  87923. + hcchar.b.chdis = 1;
  87924. + hcchar.b.chen = 1;
  87925. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  87926. + //sleep(1);
  87927. + dwc_mdelay(1000);
  87928. +
  87929. + /* Read GINTSTS */
  87930. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  87931. +
  87932. + /* Read HAINT */
  87933. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  87934. +
  87935. + /* Read HCINT */
  87936. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  87937. +
  87938. + /* Read HCCHAR */
  87939. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  87940. +
  87941. + /* Clear HCINT */
  87942. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  87943. +
  87944. + /* Clear HAINT */
  87945. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  87946. +
  87947. + /* Clear GINTSTS */
  87948. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  87949. +
  87950. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  87951. + }
  87952. +
  87953. + /* Set HCTSIZ */
  87954. + hctsiz.d32 = 0;
  87955. + hctsiz.b.xfersize = 8;
  87956. + hctsiz.b.pktcnt = 1;
  87957. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  87958. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  87959. +
  87960. + /* Set HCCHAR */
  87961. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  87962. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  87963. + hcchar.b.epdir = 1;
  87964. + hcchar.b.epnum = 0;
  87965. + hcchar.b.mps = 8;
  87966. + hcchar.b.chen = 1;
  87967. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  87968. +
  87969. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  87970. +
  87971. + /* Wait for receive status queue interrupt */
  87972. + do {
  87973. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  87974. + } while (gintsts.b.rxstsqlvl == 0);
  87975. +
  87976. + /* Read RXSTS */
  87977. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  87978. +
  87979. + /* Clear RXSTSQLVL in GINTSTS */
  87980. + gintsts.d32 = 0;
  87981. + gintsts.b.rxstsqlvl = 1;
  87982. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  87983. +
  87984. + switch (grxsts.b.pktsts) {
  87985. + case DWC_GRXSTS_PKTSTS_IN:
  87986. + /* Read the data into the host buffer */
  87987. + if (grxsts.b.bcnt > 0) {
  87988. + int i;
  87989. + int word_count = (grxsts.b.bcnt + 3) / 4;
  87990. +
  87991. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  87992. +
  87993. + for (i = 0; i < word_count; i++) {
  87994. + (void)DWC_READ_REG32(data_fifo++);
  87995. + }
  87996. + }
  87997. + break;
  87998. +
  87999. + default:
  88000. + break;
  88001. + }
  88002. +
  88003. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88004. +
  88005. + /* Wait for receive status queue interrupt */
  88006. + do {
  88007. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88008. + } while (gintsts.b.rxstsqlvl == 0);
  88009. +
  88010. + /* Read RXSTS */
  88011. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  88012. +
  88013. + /* Clear RXSTSQLVL in GINTSTS */
  88014. + gintsts.d32 = 0;
  88015. + gintsts.b.rxstsqlvl = 1;
  88016. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88017. +
  88018. + switch (grxsts.b.pktsts) {
  88019. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  88020. + break;
  88021. +
  88022. + default:
  88023. + break;
  88024. + }
  88025. +
  88026. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88027. +
  88028. + /* Wait for host channel interrupt */
  88029. + do {
  88030. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88031. + } while (gintsts.b.hcintr == 0);
  88032. +
  88033. + /* Read HAINT */
  88034. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  88035. +
  88036. + /* Read HCINT */
  88037. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  88038. +
  88039. + /* Read HCCHAR */
  88040. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88041. +
  88042. + /* Clear HCINT */
  88043. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  88044. +
  88045. + /* Clear HAINT */
  88046. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  88047. +
  88048. + /* Clear GINTSTS */
  88049. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88050. +
  88051. + /* Read GINTSTS */
  88052. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88053. +
  88054. +// usleep(100000);
  88055. +// mdelay(100);
  88056. + dwc_mdelay(1);
  88057. +
  88058. + /*
  88059. + * Send handshake packet
  88060. + */
  88061. +
  88062. + /* Read HAINT */
  88063. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  88064. +
  88065. + /* Read HCINT */
  88066. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  88067. +
  88068. + /* Read HCCHAR */
  88069. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88070. +
  88071. + /* Clear HCINT */
  88072. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  88073. +
  88074. + /* Clear HAINT */
  88075. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  88076. +
  88077. + /* Clear GINTSTS */
  88078. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88079. +
  88080. + /* Read GINTSTS */
  88081. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88082. +
  88083. + /* Make sure channel is disabled */
  88084. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88085. + if (hcchar.b.chen) {
  88086. + hcchar.b.chdis = 1;
  88087. + hcchar.b.chen = 1;
  88088. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  88089. + //sleep(1);
  88090. + dwc_mdelay(1000);
  88091. +
  88092. + /* Read GINTSTS */
  88093. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88094. +
  88095. + /* Read HAINT */
  88096. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  88097. +
  88098. + /* Read HCINT */
  88099. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  88100. +
  88101. + /* Read HCCHAR */
  88102. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88103. +
  88104. + /* Clear HCINT */
  88105. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  88106. +
  88107. + /* Clear HAINT */
  88108. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  88109. +
  88110. + /* Clear GINTSTS */
  88111. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88112. +
  88113. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88114. + }
  88115. +
  88116. + /* Set HCTSIZ */
  88117. + hctsiz.d32 = 0;
  88118. + hctsiz.b.xfersize = 0;
  88119. + hctsiz.b.pktcnt = 1;
  88120. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  88121. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  88122. +
  88123. + /* Set HCCHAR */
  88124. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88125. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  88126. + hcchar.b.epdir = 0;
  88127. + hcchar.b.epnum = 0;
  88128. + hcchar.b.mps = 8;
  88129. + hcchar.b.chen = 1;
  88130. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  88131. +
  88132. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88133. +
  88134. + /* Wait for host channel interrupt */
  88135. + do {
  88136. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88137. + } while (gintsts.b.hcintr == 0);
  88138. +
  88139. + /* Disable HCINTs */
  88140. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  88141. +
  88142. + /* Disable HAINTs */
  88143. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  88144. +
  88145. + /* Read HAINT */
  88146. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  88147. +
  88148. + /* Read HCINT */
  88149. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  88150. +
  88151. + /* Read HCCHAR */
  88152. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88153. +
  88154. + /* Clear HCINT */
  88155. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  88156. +
  88157. + /* Clear HAINT */
  88158. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  88159. +
  88160. + /* Clear GINTSTS */
  88161. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88162. +
  88163. + /* Read GINTSTS */
  88164. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88165. +}
  88166. +#endif
  88167. +
  88168. +/** Handles hub class-specific requests. */
  88169. +int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  88170. + uint16_t typeReq,
  88171. + uint16_t wValue,
  88172. + uint16_t wIndex, uint8_t * buf, uint16_t wLength)
  88173. +{
  88174. + int retval = 0;
  88175. +
  88176. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  88177. + usb_hub_descriptor_t *hub_desc;
  88178. + hprt0_data_t hprt0 = {.d32 = 0 };
  88179. +
  88180. + uint32_t port_status;
  88181. +
  88182. + switch (typeReq) {
  88183. + case UCR_CLEAR_HUB_FEATURE:
  88184. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88185. + "ClearHubFeature 0x%x\n", wValue);
  88186. + switch (wValue) {
  88187. + case UHF_C_HUB_LOCAL_POWER:
  88188. + case UHF_C_HUB_OVER_CURRENT:
  88189. + /* Nothing required here */
  88190. + break;
  88191. + default:
  88192. + retval = -DWC_E_INVALID;
  88193. + DWC_ERROR("DWC OTG HCD - "
  88194. + "ClearHubFeature request %xh unknown\n",
  88195. + wValue);
  88196. + }
  88197. + break;
  88198. + case UCR_CLEAR_PORT_FEATURE:
  88199. +#ifdef CONFIG_USB_DWC_OTG_LPM
  88200. + if (wValue != UHF_PORT_L1)
  88201. +#endif
  88202. + if (!wIndex || wIndex > 1)
  88203. + goto error;
  88204. +
  88205. + switch (wValue) {
  88206. + case UHF_PORT_ENABLE:
  88207. + DWC_DEBUGPL(DBG_ANY, "DWC OTG HCD HUB CONTROL - "
  88208. + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
  88209. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88210. + hprt0.b.prtena = 1;
  88211. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88212. + break;
  88213. + case UHF_PORT_SUSPEND:
  88214. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88215. + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
  88216. +
  88217. + if (core_if->power_down == 2) {
  88218. + dwc_otg_host_hibernation_restore(core_if, 0, 0);
  88219. + } else {
  88220. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  88221. + dwc_mdelay(5);
  88222. +
  88223. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88224. + hprt0.b.prtres = 1;
  88225. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88226. + hprt0.b.prtsusp = 0;
  88227. + /* Clear Resume bit */
  88228. + dwc_mdelay(100);
  88229. + hprt0.b.prtres = 0;
  88230. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88231. + }
  88232. + break;
  88233. +#ifdef CONFIG_USB_DWC_OTG_LPM
  88234. + case UHF_PORT_L1:
  88235. + {
  88236. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  88237. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  88238. +
  88239. + lpmcfg.d32 =
  88240. + DWC_READ_REG32(&core_if->
  88241. + core_global_regs->glpmcfg);
  88242. + lpmcfg.b.en_utmi_sleep = 0;
  88243. + lpmcfg.b.hird_thres &= (~(1 << 4));
  88244. + lpmcfg.b.prt_sleep_sts = 1;
  88245. + DWC_WRITE_REG32(&core_if->
  88246. + core_global_regs->glpmcfg,
  88247. + lpmcfg.d32);
  88248. +
  88249. + /* Clear Enbl_L1Gating bit. */
  88250. + pcgcctl.b.enbl_sleep_gating = 1;
  88251. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32,
  88252. + 0);
  88253. +
  88254. + dwc_mdelay(5);
  88255. +
  88256. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88257. + hprt0.b.prtres = 1;
  88258. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  88259. + hprt0.d32);
  88260. + /* This bit will be cleared in wakeup interrupt handle */
  88261. + break;
  88262. + }
  88263. +#endif
  88264. + case UHF_PORT_POWER:
  88265. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88266. + "ClearPortFeature USB_PORT_FEAT_POWER\n");
  88267. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88268. + hprt0.b.prtpwr = 0;
  88269. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88270. + break;
  88271. + case UHF_PORT_INDICATOR:
  88272. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88273. + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
  88274. + /* Port inidicator not supported */
  88275. + break;
  88276. + case UHF_C_PORT_CONNECTION:
  88277. + /* Clears drivers internal connect status change
  88278. + * flag */
  88279. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88280. + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
  88281. + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
  88282. + break;
  88283. + case UHF_C_PORT_RESET:
  88284. + /* Clears the driver's internal Port Reset Change
  88285. + * flag */
  88286. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88287. + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
  88288. + dwc_otg_hcd->flags.b.port_reset_change = 0;
  88289. + break;
  88290. + case UHF_C_PORT_ENABLE:
  88291. + /* Clears the driver's internal Port
  88292. + * Enable/Disable Change flag */
  88293. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88294. + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
  88295. + dwc_otg_hcd->flags.b.port_enable_change = 0;
  88296. + break;
  88297. + case UHF_C_PORT_SUSPEND:
  88298. + /* Clears the driver's internal Port Suspend
  88299. + * Change flag, which is set when resume signaling on
  88300. + * the host port is complete */
  88301. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88302. + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
  88303. + dwc_otg_hcd->flags.b.port_suspend_change = 0;
  88304. + break;
  88305. +#ifdef CONFIG_USB_DWC_OTG_LPM
  88306. + case UHF_C_PORT_L1:
  88307. + dwc_otg_hcd->flags.b.port_l1_change = 0;
  88308. + break;
  88309. +#endif
  88310. + case UHF_C_PORT_OVER_CURRENT:
  88311. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88312. + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
  88313. + dwc_otg_hcd->flags.b.port_over_current_change = 0;
  88314. + break;
  88315. + default:
  88316. + retval = -DWC_E_INVALID;
  88317. + DWC_ERROR("DWC OTG HCD - "
  88318. + "ClearPortFeature request %xh "
  88319. + "unknown or unsupported\n", wValue);
  88320. + }
  88321. + break;
  88322. + case UCR_GET_HUB_DESCRIPTOR:
  88323. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88324. + "GetHubDescriptor\n");
  88325. + hub_desc = (usb_hub_descriptor_t *) buf;
  88326. + hub_desc->bDescLength = 9;
  88327. + hub_desc->bDescriptorType = 0x29;
  88328. + hub_desc->bNbrPorts = 1;
  88329. + USETW(hub_desc->wHubCharacteristics, 0x08);
  88330. + hub_desc->bPwrOn2PwrGood = 1;
  88331. + hub_desc->bHubContrCurrent = 0;
  88332. + hub_desc->DeviceRemovable[0] = 0;
  88333. + hub_desc->DeviceRemovable[1] = 0xff;
  88334. + break;
  88335. + case UCR_GET_HUB_STATUS:
  88336. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88337. + "GetHubStatus\n");
  88338. + DWC_MEMSET(buf, 0, 4);
  88339. + break;
  88340. + case UCR_GET_PORT_STATUS:
  88341. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88342. + "GetPortStatus wIndex = 0x%04x FLAGS=0x%08x\n",
  88343. + wIndex, dwc_otg_hcd->flags.d32);
  88344. + if (!wIndex || wIndex > 1)
  88345. + goto error;
  88346. +
  88347. + port_status = 0;
  88348. +
  88349. + if (dwc_otg_hcd->flags.b.port_connect_status_change)
  88350. + port_status |= (1 << UHF_C_PORT_CONNECTION);
  88351. +
  88352. + if (dwc_otg_hcd->flags.b.port_enable_change)
  88353. + port_status |= (1 << UHF_C_PORT_ENABLE);
  88354. +
  88355. + if (dwc_otg_hcd->flags.b.port_suspend_change)
  88356. + port_status |= (1 << UHF_C_PORT_SUSPEND);
  88357. +
  88358. + if (dwc_otg_hcd->flags.b.port_l1_change)
  88359. + port_status |= (1 << UHF_C_PORT_L1);
  88360. +
  88361. + if (dwc_otg_hcd->flags.b.port_reset_change) {
  88362. + port_status |= (1 << UHF_C_PORT_RESET);
  88363. + }
  88364. +
  88365. + if (dwc_otg_hcd->flags.b.port_over_current_change) {
  88366. + DWC_WARN("Overcurrent change detected\n");
  88367. + port_status |= (1 << UHF_C_PORT_OVER_CURRENT);
  88368. + }
  88369. +
  88370. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  88371. + /*
  88372. + * The port is disconnected, which means the core is
  88373. + * either in device mode or it soon will be. Just
  88374. + * return 0's for the remainder of the port status
  88375. + * since the port register can't be read if the core
  88376. + * is in device mode.
  88377. + */
  88378. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  88379. + break;
  88380. + }
  88381. +
  88382. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  88383. + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
  88384. +
  88385. + if (hprt0.b.prtconnsts)
  88386. + port_status |= (1 << UHF_PORT_CONNECTION);
  88387. +
  88388. + if (hprt0.b.prtena)
  88389. + port_status |= (1 << UHF_PORT_ENABLE);
  88390. +
  88391. + if (hprt0.b.prtsusp)
  88392. + port_status |= (1 << UHF_PORT_SUSPEND);
  88393. +
  88394. + if (hprt0.b.prtovrcurract)
  88395. + port_status |= (1 << UHF_PORT_OVER_CURRENT);
  88396. +
  88397. + if (hprt0.b.prtrst)
  88398. + port_status |= (1 << UHF_PORT_RESET);
  88399. +
  88400. + if (hprt0.b.prtpwr)
  88401. + port_status |= (1 << UHF_PORT_POWER);
  88402. +
  88403. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  88404. + port_status |= (1 << UHF_PORT_HIGH_SPEED);
  88405. + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
  88406. + port_status |= (1 << UHF_PORT_LOW_SPEED);
  88407. +
  88408. + if (hprt0.b.prttstctl)
  88409. + port_status |= (1 << UHF_PORT_TEST);
  88410. + if (dwc_otg_get_lpm_portsleepstatus(dwc_otg_hcd->core_if)) {
  88411. + port_status |= (1 << UHF_PORT_L1);
  88412. + }
  88413. + /*
  88414. + For Synopsys HW emulation of Power down wkup_control asserts the
  88415. + hreset_n and prst_n on suspned. This causes the HPRT0 to be zero.
  88416. + We intentionally tell the software that port is in L2Suspend state.
  88417. + Only for STE.
  88418. + */
  88419. + if ((core_if->power_down == 2)
  88420. + && (core_if->hibernation_suspend == 1)) {
  88421. + port_status |= (1 << UHF_PORT_SUSPEND);
  88422. + }
  88423. + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
  88424. +
  88425. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  88426. +
  88427. + break;
  88428. + case UCR_SET_HUB_FEATURE:
  88429. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88430. + "SetHubFeature\n");
  88431. + /* No HUB features supported */
  88432. + break;
  88433. + case UCR_SET_PORT_FEATURE:
  88434. + if (wValue != UHF_PORT_TEST && (!wIndex || wIndex > 1))
  88435. + goto error;
  88436. +
  88437. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  88438. + /*
  88439. + * The port is disconnected, which means the core is
  88440. + * either in device mode or it soon will be. Just
  88441. + * return without doing anything since the port
  88442. + * register can't be written if the core is in device
  88443. + * mode.
  88444. + */
  88445. + break;
  88446. + }
  88447. +
  88448. + switch (wValue) {
  88449. + case UHF_PORT_SUSPEND:
  88450. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88451. + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
  88452. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) != wIndex) {
  88453. + goto error;
  88454. + }
  88455. + if (core_if->power_down == 2) {
  88456. + int timeout = 300;
  88457. + dwc_irqflags_t flags;
  88458. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  88459. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  88460. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  88461. +#ifdef DWC_DEV_SRPCAP
  88462. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  88463. +#endif
  88464. + DWC_PRINTF("Preparing for complete power-off\n");
  88465. +
  88466. + /* Save registers before hibernation */
  88467. + dwc_otg_save_global_regs(core_if);
  88468. + dwc_otg_save_host_regs(core_if);
  88469. +
  88470. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88471. + hprt0.b.prtsusp = 1;
  88472. + hprt0.b.prtena = 0;
  88473. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88474. + /* Spin hprt0.b.prtsusp to became 1 */
  88475. + do {
  88476. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88477. + if (hprt0.b.prtsusp) {
  88478. + break;
  88479. + }
  88480. + dwc_mdelay(1);
  88481. + } while (--timeout);
  88482. + if (!timeout) {
  88483. + DWC_WARN("Suspend wasn't genereted\n");
  88484. + }
  88485. + dwc_udelay(10);
  88486. +
  88487. + /*
  88488. + * We need to disable interrupts to prevent servicing of any IRQ
  88489. + * during going to hibernation
  88490. + */
  88491. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  88492. + core_if->lx_state = DWC_OTG_L2;
  88493. +#ifdef DWC_DEV_SRPCAP
  88494. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88495. + hprt0.b.prtpwr = 0;
  88496. + hprt0.b.prtena = 0;
  88497. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  88498. + hprt0.d32);
  88499. +#endif
  88500. + gusbcfg.d32 =
  88501. + DWC_READ_REG32(&core_if->core_global_regs->
  88502. + gusbcfg);
  88503. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  88504. + /* ULPI interface */
  88505. + /* Suspend the Phy Clock */
  88506. + pcgcctl.d32 = 0;
  88507. + pcgcctl.b.stoppclk = 1;
  88508. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  88509. + pcgcctl.d32);
  88510. + dwc_udelay(10);
  88511. + gpwrdn.b.pmuactv = 1;
  88512. + DWC_MODIFY_REG32(&core_if->
  88513. + core_global_regs->
  88514. + gpwrdn, 0, gpwrdn.d32);
  88515. + } else {
  88516. + /* UTMI+ Interface */
  88517. + gpwrdn.b.pmuactv = 1;
  88518. + DWC_MODIFY_REG32(&core_if->
  88519. + core_global_regs->
  88520. + gpwrdn, 0, gpwrdn.d32);
  88521. + dwc_udelay(10);
  88522. + pcgcctl.b.stoppclk = 1;
  88523. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  88524. + dwc_udelay(10);
  88525. + }
  88526. +#ifdef DWC_DEV_SRPCAP
  88527. + gpwrdn.d32 = 0;
  88528. + gpwrdn.b.dis_vbus = 1;
  88529. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  88530. + gpwrdn, 0, gpwrdn.d32);
  88531. +#endif
  88532. + gpwrdn.d32 = 0;
  88533. + gpwrdn.b.pmuintsel = 1;
  88534. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  88535. + gpwrdn, 0, gpwrdn.d32);
  88536. + dwc_udelay(10);
  88537. +
  88538. + gpwrdn.d32 = 0;
  88539. +#ifdef DWC_DEV_SRPCAP
  88540. + gpwrdn.b.srp_det_msk = 1;
  88541. +#endif
  88542. + gpwrdn.b.disconn_det_msk = 1;
  88543. + gpwrdn.b.lnstchng_msk = 1;
  88544. + gpwrdn.b.sts_chngint_msk = 1;
  88545. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  88546. + gpwrdn, 0, gpwrdn.d32);
  88547. + dwc_udelay(10);
  88548. +
  88549. + /* Enable Power Down Clamp and all interrupts in GPWRDN */
  88550. + gpwrdn.d32 = 0;
  88551. + gpwrdn.b.pwrdnclmp = 1;
  88552. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  88553. + gpwrdn, 0, gpwrdn.d32);
  88554. + dwc_udelay(10);
  88555. +
  88556. + /* Switch off VDD */
  88557. + gpwrdn.d32 = 0;
  88558. + gpwrdn.b.pwrdnswtch = 1;
  88559. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  88560. + gpwrdn, 0, gpwrdn.d32);
  88561. +
  88562. +#ifdef DWC_DEV_SRPCAP
  88563. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE)
  88564. + {
  88565. + core_if->pwron_timer_started = 1;
  88566. + DWC_TIMER_SCHEDULE(core_if->pwron_timer, 6000 /* 6 secs */ );
  88567. + }
  88568. +#endif
  88569. + /* Save gpwrdn register for further usage if stschng interrupt */
  88570. + core_if->gr_backup->gpwrdn_local =
  88571. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  88572. +
  88573. + /* Set flag to indicate that we are in hibernation */
  88574. + core_if->hibernation_suspend = 1;
  88575. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock,flags);
  88576. +
  88577. + DWC_PRINTF("Host hibernation completed\n");
  88578. + // Exit from case statement
  88579. + break;
  88580. +
  88581. + }
  88582. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) == wIndex &&
  88583. + dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  88584. + gotgctl_data_t gotgctl = {.d32 = 0 };
  88585. + gotgctl.b.hstsethnpen = 1;
  88586. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  88587. + gotgctl, 0, gotgctl.d32);
  88588. + core_if->op_state = A_SUSPEND;
  88589. + }
  88590. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88591. + hprt0.b.prtsusp = 1;
  88592. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88593. + {
  88594. + dwc_irqflags_t flags;
  88595. + /* Update lx_state */
  88596. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  88597. + core_if->lx_state = DWC_OTG_L2;
  88598. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  88599. + }
  88600. + /* Suspend the Phy Clock */
  88601. + {
  88602. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  88603. + pcgcctl.b.stoppclk = 1;
  88604. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  88605. + pcgcctl.d32);
  88606. + dwc_udelay(10);
  88607. + }
  88608. +
  88609. + /* For HNP the bus must be suspended for at least 200ms. */
  88610. + if (dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  88611. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  88612. + pcgcctl.b.stoppclk = 1;
  88613. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  88614. + dwc_mdelay(200);
  88615. + }
  88616. +
  88617. + /** @todo - check how sw can wait for 1 sec to check asesvld??? */
  88618. +#if 0 //vahrama !!!!!!!!!!!!!!!!!!
  88619. + if (core_if->adp_enable) {
  88620. + gotgctl_data_t gotgctl = {.d32 = 0 };
  88621. + gpwrdn_data_t gpwrdn;
  88622. +
  88623. + while (gotgctl.b.asesvld == 1) {
  88624. + gotgctl.d32 =
  88625. + DWC_READ_REG32(&core_if->
  88626. + core_global_regs->
  88627. + gotgctl);
  88628. + dwc_mdelay(100);
  88629. + }
  88630. +
  88631. + /* Enable Power Down Logic */
  88632. + gpwrdn.d32 = 0;
  88633. + gpwrdn.b.pmuactv = 1;
  88634. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  88635. + gpwrdn, 0, gpwrdn.d32);
  88636. +
  88637. + /* Unmask SRP detected interrupt from Power Down Logic */
  88638. + gpwrdn.d32 = 0;
  88639. + gpwrdn.b.srp_det_msk = 1;
  88640. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  88641. + gpwrdn, 0, gpwrdn.d32);
  88642. +
  88643. + dwc_otg_adp_probe_start(core_if);
  88644. + }
  88645. +#endif
  88646. + break;
  88647. + case UHF_PORT_POWER:
  88648. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88649. + "SetPortFeature - USB_PORT_FEAT_POWER\n");
  88650. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88651. + hprt0.b.prtpwr = 1;
  88652. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88653. + break;
  88654. + case UHF_PORT_RESET:
  88655. + if ((core_if->power_down == 2)
  88656. + && (core_if->hibernation_suspend == 1)) {
  88657. + /* If we are going to exit from Hibernated
  88658. + * state via USB RESET.
  88659. + */
  88660. + dwc_otg_host_hibernation_restore(core_if, 0, 1);
  88661. + } else {
  88662. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88663. +
  88664. + DWC_DEBUGPL(DBG_HCD,
  88665. + "DWC OTG HCD HUB CONTROL - "
  88666. + "SetPortFeature - USB_PORT_FEAT_RESET\n");
  88667. + {
  88668. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  88669. + pcgcctl.b.enbl_sleep_gating = 1;
  88670. + pcgcctl.b.stoppclk = 1;
  88671. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  88672. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  88673. + }
  88674. +#ifdef CONFIG_USB_DWC_OTG_LPM
  88675. + {
  88676. + glpmcfg_data_t lpmcfg;
  88677. + lpmcfg.d32 =
  88678. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  88679. + if (lpmcfg.b.prt_sleep_sts) {
  88680. + lpmcfg.b.en_utmi_sleep = 0;
  88681. + lpmcfg.b.hird_thres &= (~(1 << 4));
  88682. + DWC_WRITE_REG32
  88683. + (&core_if->core_global_regs->glpmcfg,
  88684. + lpmcfg.d32);
  88685. + dwc_mdelay(1);
  88686. + }
  88687. + }
  88688. +#endif
  88689. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88690. + /* Clear suspend bit if resetting from suspended state. */
  88691. + hprt0.b.prtsusp = 0;
  88692. + /* When B-Host the Port reset bit is set in
  88693. + * the Start HCD Callback function, so that
  88694. + * the reset is started within 1ms of the HNP
  88695. + * success interrupt. */
  88696. + if (!dwc_otg_hcd_is_b_host(dwc_otg_hcd)) {
  88697. + hprt0.b.prtpwr = 1;
  88698. + hprt0.b.prtrst = 1;
  88699. + DWC_PRINTF("Indeed it is in host mode hprt0 = %08x\n",hprt0.d32);
  88700. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  88701. + hprt0.d32);
  88702. + }
  88703. + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
  88704. + dwc_mdelay(60);
  88705. + hprt0.b.prtrst = 0;
  88706. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88707. + core_if->lx_state = DWC_OTG_L0; /* Now back to the on state */
  88708. + }
  88709. + break;
  88710. +#ifdef DWC_HS_ELECT_TST
  88711. + case UHF_PORT_TEST:
  88712. + {
  88713. + uint32_t t;
  88714. + gintmsk_data_t gintmsk;
  88715. +
  88716. + t = (wIndex >> 8); /* MSB wIndex USB */
  88717. + DWC_DEBUGPL(DBG_HCD,
  88718. + "DWC OTG HCD HUB CONTROL - "
  88719. + "SetPortFeature - USB_PORT_FEAT_TEST %d\n",
  88720. + t);
  88721. + DWC_WARN("USB_PORT_FEAT_TEST %d\n", t);
  88722. + if (t < 6) {
  88723. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88724. + hprt0.b.prttstctl = t;
  88725. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  88726. + hprt0.d32);
  88727. + } else {
  88728. + /* Setup global vars with reg addresses (quick and
  88729. + * dirty hack, should be cleaned up)
  88730. + */
  88731. + global_regs = core_if->core_global_regs;
  88732. + hc_global_regs =
  88733. + core_if->host_if->host_global_regs;
  88734. + hc_regs =
  88735. + (dwc_otg_hc_regs_t *) ((char *)
  88736. + global_regs +
  88737. + 0x500);
  88738. + data_fifo =
  88739. + (uint32_t *) ((char *)global_regs +
  88740. + 0x1000);
  88741. +
  88742. + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
  88743. + /* Save current interrupt mask */
  88744. + gintmsk.d32 =
  88745. + DWC_READ_REG32
  88746. + (&global_regs->gintmsk);
  88747. +
  88748. + /* Disable all interrupts while we muck with
  88749. + * the hardware directly
  88750. + */
  88751. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  88752. +
  88753. + /* 15 second delay per the test spec */
  88754. + dwc_mdelay(15000);
  88755. +
  88756. + /* Drive suspend on the root port */
  88757. + hprt0.d32 =
  88758. + dwc_otg_read_hprt0(core_if);
  88759. + hprt0.b.prtsusp = 1;
  88760. + hprt0.b.prtres = 0;
  88761. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88762. +
  88763. + /* 15 second delay per the test spec */
  88764. + dwc_mdelay(15000);
  88765. +
  88766. + /* Drive resume on the root port */
  88767. + hprt0.d32 =
  88768. + dwc_otg_read_hprt0(core_if);
  88769. + hprt0.b.prtsusp = 0;
  88770. + hprt0.b.prtres = 1;
  88771. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88772. + dwc_mdelay(100);
  88773. +
  88774. + /* Clear the resume bit */
  88775. + hprt0.b.prtres = 0;
  88776. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88777. +
  88778. + /* Restore interrupts */
  88779. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  88780. + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  88781. + /* Save current interrupt mask */
  88782. + gintmsk.d32 =
  88783. + DWC_READ_REG32
  88784. + (&global_regs->gintmsk);
  88785. +
  88786. + /* Disable all interrupts while we muck with
  88787. + * the hardware directly
  88788. + */
  88789. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  88790. +
  88791. + /* 15 second delay per the test spec */
  88792. + dwc_mdelay(15000);
  88793. +
  88794. + /* Send the Setup packet */
  88795. + do_setup();
  88796. +
  88797. + /* 15 second delay so nothing else happens for awhile */
  88798. + dwc_mdelay(15000);
  88799. +
  88800. + /* Restore interrupts */
  88801. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  88802. + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  88803. + /* Save current interrupt mask */
  88804. + gintmsk.d32 =
  88805. + DWC_READ_REG32
  88806. + (&global_regs->gintmsk);
  88807. +
  88808. + /* Disable all interrupts while we muck with
  88809. + * the hardware directly
  88810. + */
  88811. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  88812. +
  88813. + /* Send the Setup packet */
  88814. + do_setup();
  88815. +
  88816. + /* 15 second delay so nothing else happens for awhile */
  88817. + dwc_mdelay(15000);
  88818. +
  88819. + /* Send the In and Ack packets */
  88820. + do_in_ack();
  88821. +
  88822. + /* 15 second delay so nothing else happens for awhile */
  88823. + dwc_mdelay(15000);
  88824. +
  88825. + /* Restore interrupts */
  88826. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  88827. + }
  88828. + }
  88829. + break;
  88830. + }
  88831. +#endif /* DWC_HS_ELECT_TST */
  88832. +
  88833. + case UHF_PORT_INDICATOR:
  88834. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88835. + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
  88836. + /* Not supported */
  88837. + break;
  88838. + default:
  88839. + retval = -DWC_E_INVALID;
  88840. + DWC_ERROR("DWC OTG HCD - "
  88841. + "SetPortFeature request %xh "
  88842. + "unknown or unsupported\n", wValue);
  88843. + break;
  88844. + }
  88845. + break;
  88846. +#ifdef CONFIG_USB_DWC_OTG_LPM
  88847. + case UCR_SET_AND_TEST_PORT_FEATURE:
  88848. + if (wValue != UHF_PORT_L1) {
  88849. + goto error;
  88850. + }
  88851. + {
  88852. + int portnum, hird, devaddr, remwake;
  88853. + glpmcfg_data_t lpmcfg;
  88854. + uint32_t time_usecs;
  88855. + gintsts_data_t gintsts;
  88856. + gintmsk_data_t gintmsk;
  88857. +
  88858. + if (!dwc_otg_get_param_lpm_enable(core_if)) {
  88859. + goto error;
  88860. + }
  88861. + if (wValue != UHF_PORT_L1 || wLength != 1) {
  88862. + goto error;
  88863. + }
  88864. + /* Check if the port currently is in SLEEP state */
  88865. + lpmcfg.d32 =
  88866. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  88867. + if (lpmcfg.b.prt_sleep_sts) {
  88868. + DWC_INFO("Port is already in sleep mode\n");
  88869. + buf[0] = 0; /* Return success */
  88870. + break;
  88871. + }
  88872. +
  88873. + portnum = wIndex & 0xf;
  88874. + hird = (wIndex >> 4) & 0xf;
  88875. + devaddr = (wIndex >> 8) & 0x7f;
  88876. + remwake = (wIndex >> 15);
  88877. +
  88878. + if (portnum != 1) {
  88879. + retval = -DWC_E_INVALID;
  88880. + DWC_WARN
  88881. + ("Wrong port number(%d) in SetandTestPortFeature request\n",
  88882. + portnum);
  88883. + break;
  88884. + }
  88885. +
  88886. + DWC_PRINTF
  88887. + ("SetandTestPortFeature request: portnum = %d, hird = %d, devaddr = %d, rewake = %d\n",
  88888. + portnum, hird, devaddr, remwake);
  88889. + /* Disable LPM interrupt */
  88890. + gintmsk.d32 = 0;
  88891. + gintmsk.b.lpmtranrcvd = 1;
  88892. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  88893. + gintmsk.d32, 0);
  88894. +
  88895. + if (dwc_otg_hcd_send_lpm
  88896. + (dwc_otg_hcd, devaddr, hird, remwake)) {
  88897. + retval = -DWC_E_INVALID;
  88898. + break;
  88899. + }
  88900. +
  88901. + time_usecs = 10 * (lpmcfg.b.retry_count + 1);
  88902. + /* We will consider timeout if time_usecs microseconds pass,
  88903. + * and we don't receive LPM transaction status.
  88904. + * After receiving non-error responce(ACK/NYET/STALL) from device,
  88905. + * core will set lpmtranrcvd bit.
  88906. + */
  88907. + do {
  88908. + gintsts.d32 =
  88909. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  88910. + if (gintsts.b.lpmtranrcvd) {
  88911. + break;
  88912. + }
  88913. + dwc_udelay(1);
  88914. + } while (--time_usecs);
  88915. + /* lpm_int bit will be cleared in LPM interrupt handler */
  88916. +
  88917. + /* Now fill status
  88918. + * 0x00 - Success
  88919. + * 0x10 - NYET
  88920. + * 0x11 - Timeout
  88921. + */
  88922. + if (!gintsts.b.lpmtranrcvd) {
  88923. + buf[0] = 0x3; /* Completion code is Timeout */
  88924. + dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd);
  88925. + } else {
  88926. + lpmcfg.d32 =
  88927. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  88928. + if (lpmcfg.b.lpm_resp == 0x3) {
  88929. + /* ACK responce from the device */
  88930. + buf[0] = 0x00; /* Success */
  88931. + } else if (lpmcfg.b.lpm_resp == 0x2) {
  88932. + /* NYET responce from the device */
  88933. + buf[0] = 0x2;
  88934. + } else {
  88935. + /* Otherwise responce with Timeout */
  88936. + buf[0] = 0x3;
  88937. + }
  88938. + }
  88939. + DWC_PRINTF("Device responce to LPM trans is %x\n",
  88940. + lpmcfg.b.lpm_resp);
  88941. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0,
  88942. + gintmsk.d32);
  88943. +
  88944. + break;
  88945. + }
  88946. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  88947. + default:
  88948. +error:
  88949. + retval = -DWC_E_INVALID;
  88950. + DWC_WARN("DWC OTG HCD - "
  88951. + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
  88952. + typeReq, wIndex, wValue);
  88953. + break;
  88954. + }
  88955. +
  88956. + return retval;
  88957. +}
  88958. +
  88959. +#ifdef CONFIG_USB_DWC_OTG_LPM
  88960. +/** Returns index of host channel to perform LPM transaction. */
  88961. +int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd, uint8_t devaddr)
  88962. +{
  88963. + dwc_otg_core_if_t *core_if = hcd->core_if;
  88964. + dwc_hc_t *hc;
  88965. + hcchar_data_t hcchar;
  88966. + gintmsk_data_t gintmsk = {.d32 = 0 };
  88967. +
  88968. + if (DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  88969. + DWC_PRINTF("No free channel to select for LPM transaction\n");
  88970. + return -1;
  88971. + }
  88972. +
  88973. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  88974. +
  88975. + /* Mask host channel interrupts. */
  88976. + gintmsk.b.hcintr = 1;
  88977. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  88978. +
  88979. + /* Fill fields that core needs for LPM transaction */
  88980. + hcchar.b.devaddr = devaddr;
  88981. + hcchar.b.epnum = 0;
  88982. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  88983. + hcchar.b.mps = 64;
  88984. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  88985. + hcchar.b.epdir = 0; /* OUT */
  88986. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[hc->hc_num]->hcchar,
  88987. + hcchar.d32);
  88988. +
  88989. + /* Remove the host channel from the free list. */
  88990. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  88991. +
  88992. + DWC_PRINTF("hcnum = %d devaddr = %d\n", hc->hc_num, devaddr);
  88993. +
  88994. + return hc->hc_num;
  88995. +}
  88996. +
  88997. +/** Release hc after performing LPM transaction */
  88998. +void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd)
  88999. +{
  89000. + dwc_hc_t *hc;
  89001. + glpmcfg_data_t lpmcfg;
  89002. + uint8_t hc_num;
  89003. +
  89004. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  89005. + hc_num = lpmcfg.b.lpm_chan_index;
  89006. +
  89007. + hc = hcd->hc_ptr_array[hc_num];
  89008. +
  89009. + DWC_PRINTF("Freeing channel %d after LPM\n", hc_num);
  89010. + /* Return host channel to free list */
  89011. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  89012. +}
  89013. +
  89014. +int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr, uint8_t hird,
  89015. + uint8_t bRemoteWake)
  89016. +{
  89017. + glpmcfg_data_t lpmcfg;
  89018. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  89019. + int channel;
  89020. +
  89021. + channel = dwc_otg_hcd_get_hc_for_lpm_tran(hcd, devaddr);
  89022. + if (channel < 0) {
  89023. + return channel;
  89024. + }
  89025. +
  89026. + pcgcctl.b.enbl_sleep_gating = 1;
  89027. + DWC_MODIFY_REG32(hcd->core_if->pcgcctl, 0, pcgcctl.d32);
  89028. +
  89029. + /* Read LPM config register */
  89030. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  89031. +
  89032. + /* Program LPM transaction fields */
  89033. + lpmcfg.b.rem_wkup_en = bRemoteWake;
  89034. + lpmcfg.b.hird = hird;
  89035. + lpmcfg.b.hird_thres = 0x1c;
  89036. + lpmcfg.b.lpm_chan_index = channel;
  89037. + lpmcfg.b.en_utmi_sleep = 1;
  89038. + /* Program LPM config register */
  89039. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  89040. +
  89041. + /* Send LPM transaction */
  89042. + lpmcfg.b.send_lpm = 1;
  89043. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  89044. +
  89045. + return 0;
  89046. +}
  89047. +
  89048. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  89049. +
  89050. +int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port)
  89051. +{
  89052. + int retval;
  89053. +
  89054. + if (port != 1) {
  89055. + return -DWC_E_INVALID;
  89056. + }
  89057. +
  89058. + retval = (hcd->flags.b.port_connect_status_change ||
  89059. + hcd->flags.b.port_reset_change ||
  89060. + hcd->flags.b.port_enable_change ||
  89061. + hcd->flags.b.port_suspend_change ||
  89062. + hcd->flags.b.port_over_current_change);
  89063. +#ifdef DEBUG
  89064. + if (retval) {
  89065. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
  89066. + " Root port status changed\n");
  89067. + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
  89068. + hcd->flags.b.port_connect_status_change);
  89069. + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
  89070. + hcd->flags.b.port_reset_change);
  89071. + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
  89072. + hcd->flags.b.port_enable_change);
  89073. + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
  89074. + hcd->flags.b.port_suspend_change);
  89075. + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
  89076. + hcd->flags.b.port_over_current_change);
  89077. + }
  89078. +#endif
  89079. + return retval;
  89080. +}
  89081. +
  89082. +int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * dwc_otg_hcd)
  89083. +{
  89084. + hfnum_data_t hfnum;
  89085. + hfnum.d32 =
  89086. + DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->
  89087. + hfnum);
  89088. +
  89089. +#ifdef DEBUG_SOF
  89090. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n",
  89091. + hfnum.b.frnum);
  89092. +#endif
  89093. + return hfnum.b.frnum;
  89094. +}
  89095. +
  89096. +int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  89097. + struct dwc_otg_hcd_function_ops *fops)
  89098. +{
  89099. + int retval = 0;
  89100. +
  89101. + hcd->fops = fops;
  89102. + if (!dwc_otg_is_device_mode(hcd->core_if) &&
  89103. + (!hcd->core_if->adp_enable || hcd->core_if->adp.adp_started)) {
  89104. + dwc_otg_hcd_reinit(hcd);
  89105. + } else {
  89106. + retval = -DWC_E_NO_DEVICE;
  89107. + }
  89108. +
  89109. + return retval;
  89110. +}
  89111. +
  89112. +void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd)
  89113. +{
  89114. + return hcd->priv;
  89115. +}
  89116. +
  89117. +void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data)
  89118. +{
  89119. + hcd->priv = priv_data;
  89120. +}
  89121. +
  89122. +uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd)
  89123. +{
  89124. + return hcd->otg_port;
  89125. +}
  89126. +
  89127. +uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd)
  89128. +{
  89129. + uint32_t is_b_host;
  89130. + if (hcd->core_if->op_state == B_HOST) {
  89131. + is_b_host = 1;
  89132. + } else {
  89133. + is_b_host = 0;
  89134. + }
  89135. +
  89136. + return is_b_host;
  89137. +}
  89138. +
  89139. +dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  89140. + int iso_desc_count, int atomic_alloc)
  89141. +{
  89142. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  89143. + uint32_t size;
  89144. +
  89145. + size =
  89146. + sizeof(*dwc_otg_urb) +
  89147. + iso_desc_count * sizeof(struct dwc_otg_hcd_iso_packet_desc);
  89148. + if (atomic_alloc)
  89149. + dwc_otg_urb = DWC_ALLOC_ATOMIC(size);
  89150. + else
  89151. + dwc_otg_urb = DWC_ALLOC(size);
  89152. +
  89153. + if (dwc_otg_urb)
  89154. + dwc_otg_urb->packet_count = iso_desc_count;
  89155. + else {
  89156. + DWC_ERROR("**** DWC OTG HCD URB alloc - "
  89157. + "%salloc of %db failed\n",
  89158. + atomic_alloc?"atomic ":"", size);
  89159. + }
  89160. + return dwc_otg_urb;
  89161. +}
  89162. +
  89163. +void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * dwc_otg_urb,
  89164. + uint8_t dev_addr, uint8_t ep_num,
  89165. + uint8_t ep_type, uint8_t ep_dir, uint16_t mps)
  89166. +{
  89167. + dwc_otg_hcd_fill_pipe(&dwc_otg_urb->pipe_info, dev_addr, ep_num,
  89168. + ep_type, ep_dir, mps);
  89169. +#if 0
  89170. + DWC_PRINTF
  89171. + ("addr = %d, ep_num = %d, ep_dir = 0x%x, ep_type = 0x%x, mps = %d\n",
  89172. + dev_addr, ep_num, ep_dir, ep_type, mps);
  89173. +#endif
  89174. +}
  89175. +
  89176. +void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  89177. + void *urb_handle, void *buf, dwc_dma_t dma,
  89178. + uint32_t buflen, void *setup_packet,
  89179. + dwc_dma_t setup_dma, uint32_t flags,
  89180. + uint16_t interval)
  89181. +{
  89182. + dwc_otg_urb->priv = urb_handle;
  89183. + dwc_otg_urb->buf = buf;
  89184. + dwc_otg_urb->dma = dma;
  89185. + dwc_otg_urb->length = buflen;
  89186. + dwc_otg_urb->setup_packet = setup_packet;
  89187. + dwc_otg_urb->setup_dma = setup_dma;
  89188. + dwc_otg_urb->flags = flags;
  89189. + dwc_otg_urb->interval = interval;
  89190. + dwc_otg_urb->status = -DWC_E_IN_PROGRESS;
  89191. +}
  89192. +
  89193. +uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb)
  89194. +{
  89195. + return dwc_otg_urb->status;
  89196. +}
  89197. +
  89198. +uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t * dwc_otg_urb)
  89199. +{
  89200. + return dwc_otg_urb->actual_length;
  89201. +}
  89202. +
  89203. +uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t * dwc_otg_urb)
  89204. +{
  89205. + return dwc_otg_urb->error_count;
  89206. +}
  89207. +
  89208. +void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  89209. + int desc_num, uint32_t offset,
  89210. + uint32_t length)
  89211. +{
  89212. + dwc_otg_urb->iso_descs[desc_num].offset = offset;
  89213. + dwc_otg_urb->iso_descs[desc_num].length = length;
  89214. +}
  89215. +
  89216. +uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t * dwc_otg_urb,
  89217. + int desc_num)
  89218. +{
  89219. + return dwc_otg_urb->iso_descs[desc_num].status;
  89220. +}
  89221. +
  89222. +uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  89223. + dwc_otg_urb, int desc_num)
  89224. +{
  89225. + return dwc_otg_urb->iso_descs[desc_num].actual_length;
  89226. +}
  89227. +
  89228. +int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd, void *ep_handle)
  89229. +{
  89230. + int allocated = 0;
  89231. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  89232. +
  89233. + if (qh) {
  89234. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  89235. + allocated = 1;
  89236. + }
  89237. + }
  89238. + return allocated;
  89239. +}
  89240. +
  89241. +int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle)
  89242. +{
  89243. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  89244. + int freed = 0;
  89245. + DWC_ASSERT(qh, "qh is not allocated\n");
  89246. +
  89247. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  89248. + freed = 1;
  89249. + }
  89250. +
  89251. + return freed;
  89252. +}
  89253. +
  89254. +uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd, void *ep_handle)
  89255. +{
  89256. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  89257. + DWC_ASSERT(qh, "qh is not allocated\n");
  89258. + return qh->usecs;
  89259. +}
  89260. +
  89261. +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd)
  89262. +{
  89263. +#ifdef DEBUG
  89264. + int num_channels;
  89265. + int i;
  89266. + gnptxsts_data_t np_tx_status;
  89267. + hptxsts_data_t p_tx_status;
  89268. +
  89269. + num_channels = hcd->core_if->core_params->host_channels;
  89270. + DWC_PRINTF("\n");
  89271. + DWC_PRINTF
  89272. + ("************************************************************\n");
  89273. + DWC_PRINTF("HCD State:\n");
  89274. + DWC_PRINTF(" Num channels: %d\n", num_channels);
  89275. + for (i = 0; i < num_channels; i++) {
  89276. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  89277. + DWC_PRINTF(" Channel %d:\n", i);
  89278. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  89279. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  89280. + DWC_PRINTF(" speed: %d\n", hc->speed);
  89281. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  89282. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  89283. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  89284. + DWC_PRINTF(" multi_count: %d\n", hc->multi_count);
  89285. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  89286. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  89287. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  89288. + DWC_PRINTF(" xfer_count: %d\n", hc->xfer_count);
  89289. + DWC_PRINTF(" halt_on_queue: %d\n", hc->halt_on_queue);
  89290. + DWC_PRINTF(" halt_pending: %d\n", hc->halt_pending);
  89291. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  89292. + DWC_PRINTF(" do_split: %d\n", hc->do_split);
  89293. + DWC_PRINTF(" complete_split: %d\n", hc->complete_split);
  89294. + DWC_PRINTF(" hub_addr: %d\n", hc->hub_addr);
  89295. + DWC_PRINTF(" port_addr: %d\n", hc->port_addr);
  89296. + DWC_PRINTF(" xact_pos: %d\n", hc->xact_pos);
  89297. + DWC_PRINTF(" requests: %d\n", hc->requests);
  89298. + DWC_PRINTF(" qh: %p\n", hc->qh);
  89299. + if (hc->xfer_started) {
  89300. + hfnum_data_t hfnum;
  89301. + hcchar_data_t hcchar;
  89302. + hctsiz_data_t hctsiz;
  89303. + hcint_data_t hcint;
  89304. + hcintmsk_data_t hcintmsk;
  89305. + hfnum.d32 =
  89306. + DWC_READ_REG32(&hcd->core_if->
  89307. + host_if->host_global_regs->hfnum);
  89308. + hcchar.d32 =
  89309. + DWC_READ_REG32(&hcd->core_if->host_if->
  89310. + hc_regs[i]->hcchar);
  89311. + hctsiz.d32 =
  89312. + DWC_READ_REG32(&hcd->core_if->host_if->
  89313. + hc_regs[i]->hctsiz);
  89314. + hcint.d32 =
  89315. + DWC_READ_REG32(&hcd->core_if->host_if->
  89316. + hc_regs[i]->hcint);
  89317. + hcintmsk.d32 =
  89318. + DWC_READ_REG32(&hcd->core_if->host_if->
  89319. + hc_regs[i]->hcintmsk);
  89320. + DWC_PRINTF(" hfnum: 0x%08x\n", hfnum.d32);
  89321. + DWC_PRINTF(" hcchar: 0x%08x\n", hcchar.d32);
  89322. + DWC_PRINTF(" hctsiz: 0x%08x\n", hctsiz.d32);
  89323. + DWC_PRINTF(" hcint: 0x%08x\n", hcint.d32);
  89324. + DWC_PRINTF(" hcintmsk: 0x%08x\n", hcintmsk.d32);
  89325. + }
  89326. + if (hc->xfer_started && hc->qh) {
  89327. + dwc_otg_qtd_t *qtd;
  89328. + dwc_otg_hcd_urb_t *urb;
  89329. +
  89330. + DWC_CIRCLEQ_FOREACH(qtd, &hc->qh->qtd_list, qtd_list_entry) {
  89331. + if (!qtd->in_process)
  89332. + break;
  89333. +
  89334. + urb = qtd->urb;
  89335. + DWC_PRINTF(" URB Info:\n");
  89336. + DWC_PRINTF(" qtd: %p, urb: %p\n", qtd, urb);
  89337. + if (urb) {
  89338. + DWC_PRINTF(" Dev: %d, EP: %d %s\n",
  89339. + dwc_otg_hcd_get_dev_addr(&urb->
  89340. + pipe_info),
  89341. + dwc_otg_hcd_get_ep_num(&urb->
  89342. + pipe_info),
  89343. + dwc_otg_hcd_is_pipe_in(&urb->
  89344. + pipe_info) ?
  89345. + "IN" : "OUT");
  89346. + DWC_PRINTF(" Max packet size: %d\n",
  89347. + dwc_otg_hcd_get_mps(&urb->
  89348. + pipe_info));
  89349. + DWC_PRINTF(" transfer_buffer: %p\n",
  89350. + urb->buf);
  89351. + DWC_PRINTF(" transfer_dma: %p\n",
  89352. + (void *)urb->dma);
  89353. + DWC_PRINTF(" transfer_buffer_length: %d\n",
  89354. + urb->length);
  89355. + DWC_PRINTF(" actual_length: %d\n",
  89356. + urb->actual_length);
  89357. + }
  89358. + }
  89359. + }
  89360. + }
  89361. + DWC_PRINTF(" non_periodic_channels: %d\n", hcd->non_periodic_channels);
  89362. + DWC_PRINTF(" periodic_channels: %d\n", hcd->periodic_channels);
  89363. + DWC_PRINTF(" periodic_usecs: %d\n", hcd->periodic_usecs);
  89364. + np_tx_status.d32 =
  89365. + DWC_READ_REG32(&hcd->core_if->core_global_regs->gnptxsts);
  89366. + DWC_PRINTF(" NP Tx Req Queue Space Avail: %d\n",
  89367. + np_tx_status.b.nptxqspcavail);
  89368. + DWC_PRINTF(" NP Tx FIFO Space Avail: %d\n",
  89369. + np_tx_status.b.nptxfspcavail);
  89370. + p_tx_status.d32 =
  89371. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hptxsts);
  89372. + DWC_PRINTF(" P Tx Req Queue Space Avail: %d\n",
  89373. + p_tx_status.b.ptxqspcavail);
  89374. + DWC_PRINTF(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
  89375. + dwc_otg_hcd_dump_frrem(hcd);
  89376. + dwc_otg_dump_global_registers(hcd->core_if);
  89377. + dwc_otg_dump_host_registers(hcd->core_if);
  89378. + DWC_PRINTF
  89379. + ("************************************************************\n");
  89380. + DWC_PRINTF("\n");
  89381. +#endif
  89382. +}
  89383. +
  89384. +#ifdef DEBUG
  89385. +void dwc_print_setup_data(uint8_t * setup)
  89386. +{
  89387. + int i;
  89388. + if (CHK_DEBUG_LEVEL(DBG_HCD)) {
  89389. + DWC_PRINTF("Setup Data = MSB ");
  89390. + for (i = 7; i >= 0; i--)
  89391. + DWC_PRINTF("%02x ", setup[i]);
  89392. + DWC_PRINTF("\n");
  89393. + DWC_PRINTF(" bmRequestType Tranfer = %s\n",
  89394. + (setup[0] & 0x80) ? "Device-to-Host" :
  89395. + "Host-to-Device");
  89396. + DWC_PRINTF(" bmRequestType Type = ");
  89397. + switch ((setup[0] & 0x60) >> 5) {
  89398. + case 0:
  89399. + DWC_PRINTF("Standard\n");
  89400. + break;
  89401. + case 1:
  89402. + DWC_PRINTF("Class\n");
  89403. + break;
  89404. + case 2:
  89405. + DWC_PRINTF("Vendor\n");
  89406. + break;
  89407. + case 3:
  89408. + DWC_PRINTF("Reserved\n");
  89409. + break;
  89410. + }
  89411. + DWC_PRINTF(" bmRequestType Recipient = ");
  89412. + switch (setup[0] & 0x1f) {
  89413. + case 0:
  89414. + DWC_PRINTF("Device\n");
  89415. + break;
  89416. + case 1:
  89417. + DWC_PRINTF("Interface\n");
  89418. + break;
  89419. + case 2:
  89420. + DWC_PRINTF("Endpoint\n");
  89421. + break;
  89422. + case 3:
  89423. + DWC_PRINTF("Other\n");
  89424. + break;
  89425. + default:
  89426. + DWC_PRINTF("Reserved\n");
  89427. + break;
  89428. + }
  89429. + DWC_PRINTF(" bRequest = 0x%0x\n", setup[1]);
  89430. + DWC_PRINTF(" wValue = 0x%0x\n", *((uint16_t *) & setup[2]));
  89431. + DWC_PRINTF(" wIndex = 0x%0x\n", *((uint16_t *) & setup[4]));
  89432. + DWC_PRINTF(" wLength = 0x%0x\n\n", *((uint16_t *) & setup[6]));
  89433. + }
  89434. +}
  89435. +#endif
  89436. +
  89437. +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd)
  89438. +{
  89439. +#if 0
  89440. + DWC_PRINTF("Frame remaining at SOF:\n");
  89441. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89442. + hcd->frrem_samples, hcd->frrem_accum,
  89443. + (hcd->frrem_samples > 0) ?
  89444. + hcd->frrem_accum / hcd->frrem_samples : 0);
  89445. +
  89446. + DWC_PRINTF("\n");
  89447. + DWC_PRINTF("Frame remaining at start_transfer (uframe 7):\n");
  89448. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89449. + hcd->core_if->hfnum_7_samples,
  89450. + hcd->core_if->hfnum_7_frrem_accum,
  89451. + (hcd->core_if->hfnum_7_samples >
  89452. + 0) ? hcd->core_if->hfnum_7_frrem_accum /
  89453. + hcd->core_if->hfnum_7_samples : 0);
  89454. + DWC_PRINTF("Frame remaining at start_transfer (uframe 0):\n");
  89455. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89456. + hcd->core_if->hfnum_0_samples,
  89457. + hcd->core_if->hfnum_0_frrem_accum,
  89458. + (hcd->core_if->hfnum_0_samples >
  89459. + 0) ? hcd->core_if->hfnum_0_frrem_accum /
  89460. + hcd->core_if->hfnum_0_samples : 0);
  89461. + DWC_PRINTF("Frame remaining at start_transfer (uframe 1-6):\n");
  89462. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89463. + hcd->core_if->hfnum_other_samples,
  89464. + hcd->core_if->hfnum_other_frrem_accum,
  89465. + (hcd->core_if->hfnum_other_samples >
  89466. + 0) ? hcd->core_if->hfnum_other_frrem_accum /
  89467. + hcd->core_if->hfnum_other_samples : 0);
  89468. +
  89469. + DWC_PRINTF("\n");
  89470. + DWC_PRINTF("Frame remaining at sample point A (uframe 7):\n");
  89471. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89472. + hcd->hfnum_7_samples_a, hcd->hfnum_7_frrem_accum_a,
  89473. + (hcd->hfnum_7_samples_a > 0) ?
  89474. + hcd->hfnum_7_frrem_accum_a / hcd->hfnum_7_samples_a : 0);
  89475. + DWC_PRINTF("Frame remaining at sample point A (uframe 0):\n");
  89476. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89477. + hcd->hfnum_0_samples_a, hcd->hfnum_0_frrem_accum_a,
  89478. + (hcd->hfnum_0_samples_a > 0) ?
  89479. + hcd->hfnum_0_frrem_accum_a / hcd->hfnum_0_samples_a : 0);
  89480. + DWC_PRINTF("Frame remaining at sample point A (uframe 1-6):\n");
  89481. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89482. + hcd->hfnum_other_samples_a, hcd->hfnum_other_frrem_accum_a,
  89483. + (hcd->hfnum_other_samples_a > 0) ?
  89484. + hcd->hfnum_other_frrem_accum_a /
  89485. + hcd->hfnum_other_samples_a : 0);
  89486. +
  89487. + DWC_PRINTF("\n");
  89488. + DWC_PRINTF("Frame remaining at sample point B (uframe 7):\n");
  89489. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89490. + hcd->hfnum_7_samples_b, hcd->hfnum_7_frrem_accum_b,
  89491. + (hcd->hfnum_7_samples_b > 0) ?
  89492. + hcd->hfnum_7_frrem_accum_b / hcd->hfnum_7_samples_b : 0);
  89493. + DWC_PRINTF("Frame remaining at sample point B (uframe 0):\n");
  89494. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89495. + hcd->hfnum_0_samples_b, hcd->hfnum_0_frrem_accum_b,
  89496. + (hcd->hfnum_0_samples_b > 0) ?
  89497. + hcd->hfnum_0_frrem_accum_b / hcd->hfnum_0_samples_b : 0);
  89498. + DWC_PRINTF("Frame remaining at sample point B (uframe 1-6):\n");
  89499. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89500. + hcd->hfnum_other_samples_b, hcd->hfnum_other_frrem_accum_b,
  89501. + (hcd->hfnum_other_samples_b > 0) ?
  89502. + hcd->hfnum_other_frrem_accum_b /
  89503. + hcd->hfnum_other_samples_b : 0);
  89504. +#endif
  89505. +}
  89506. +
  89507. +#endif /* DWC_DEVICE_ONLY */
  89508. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c
  89509. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 1970-01-01 01:00:00.000000000 +0100
  89510. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 2015-02-09 04:40:29.000000000 +0100
  89511. @@ -0,0 +1,1132 @@
  89512. +/*==========================================================================
  89513. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_ddma.c $
  89514. + * $Revision: #10 $
  89515. + * $Date: 2011/10/20 $
  89516. + * $Change: 1869464 $
  89517. + *
  89518. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  89519. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  89520. + * otherwise expressly agreed to in writing between Synopsys and you.
  89521. + *
  89522. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  89523. + * any End User Software License Agreement or Agreement for Licensed Product
  89524. + * with Synopsys or any supplement thereto. You are permitted to use and
  89525. + * redistribute this Software in source and binary forms, with or without
  89526. + * modification, provided that redistributions of source code must retain this
  89527. + * notice. You may not view, use, disclose, copy or distribute this file or
  89528. + * any information contained herein except pursuant to this license grant from
  89529. + * Synopsys. If you do not agree with this notice, including the disclaimer
  89530. + * below, then you are not authorized to use the Software.
  89531. + *
  89532. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  89533. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  89534. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  89535. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  89536. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  89537. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  89538. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  89539. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  89540. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  89541. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  89542. + * DAMAGE.
  89543. + * ========================================================================== */
  89544. +#ifndef DWC_DEVICE_ONLY
  89545. +
  89546. +/** @file
  89547. + * This file contains Descriptor DMA support implementation for host mode.
  89548. + */
  89549. +
  89550. +#include "dwc_otg_hcd.h"
  89551. +#include "dwc_otg_regs.h"
  89552. +
  89553. +extern bool microframe_schedule;
  89554. +
  89555. +static inline uint8_t frame_list_idx(uint16_t frame)
  89556. +{
  89557. + return (frame & (MAX_FRLIST_EN_NUM - 1));
  89558. +}
  89559. +
  89560. +static inline uint16_t desclist_idx_inc(uint16_t idx, uint16_t inc, uint8_t speed)
  89561. +{
  89562. + return (idx + inc) &
  89563. + (((speed ==
  89564. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  89565. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  89566. +}
  89567. +
  89568. +static inline uint16_t desclist_idx_dec(uint16_t idx, uint16_t inc, uint8_t speed)
  89569. +{
  89570. + return (idx - inc) &
  89571. + (((speed ==
  89572. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  89573. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  89574. +}
  89575. +
  89576. +static inline uint16_t max_desc_num(dwc_otg_qh_t * qh)
  89577. +{
  89578. + return (((qh->ep_type == UE_ISOCHRONOUS)
  89579. + && (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH))
  89580. + ? MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC);
  89581. +}
  89582. +static inline uint16_t frame_incr_val(dwc_otg_qh_t * qh)
  89583. +{
  89584. + return ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH)
  89585. + ? ((qh->interval + 8 - 1) / 8)
  89586. + : qh->interval);
  89587. +}
  89588. +
  89589. +static int desc_list_alloc(dwc_otg_qh_t * qh)
  89590. +{
  89591. + int retval = 0;
  89592. +
  89593. + qh->desc_list = (dwc_otg_host_dma_desc_t *)
  89594. + DWC_DMA_ALLOC(sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh),
  89595. + &qh->desc_list_dma);
  89596. +
  89597. + if (!qh->desc_list) {
  89598. + retval = -DWC_E_NO_MEMORY;
  89599. + DWC_ERROR("%s: DMA descriptor list allocation failed\n", __func__);
  89600. +
  89601. + }
  89602. +
  89603. + dwc_memset(qh->desc_list, 0x00,
  89604. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  89605. +
  89606. + qh->n_bytes =
  89607. + (uint32_t *) DWC_ALLOC(sizeof(uint32_t) * max_desc_num(qh));
  89608. +
  89609. + if (!qh->n_bytes) {
  89610. + retval = -DWC_E_NO_MEMORY;
  89611. + DWC_ERROR
  89612. + ("%s: Failed to allocate array for descriptors' size actual values\n",
  89613. + __func__);
  89614. +
  89615. + }
  89616. + return retval;
  89617. +
  89618. +}
  89619. +
  89620. +static void desc_list_free(dwc_otg_qh_t * qh)
  89621. +{
  89622. + if (qh->desc_list) {
  89623. + DWC_DMA_FREE(max_desc_num(qh), qh->desc_list,
  89624. + qh->desc_list_dma);
  89625. + qh->desc_list = NULL;
  89626. + }
  89627. +
  89628. + if (qh->n_bytes) {
  89629. + DWC_FREE(qh->n_bytes);
  89630. + qh->n_bytes = NULL;
  89631. + }
  89632. +}
  89633. +
  89634. +static int frame_list_alloc(dwc_otg_hcd_t * hcd)
  89635. +{
  89636. + int retval = 0;
  89637. + if (hcd->frame_list)
  89638. + return 0;
  89639. +
  89640. + hcd->frame_list = DWC_DMA_ALLOC(4 * MAX_FRLIST_EN_NUM,
  89641. + &hcd->frame_list_dma);
  89642. + if (!hcd->frame_list) {
  89643. + retval = -DWC_E_NO_MEMORY;
  89644. + DWC_ERROR("%s: Frame List allocation failed\n", __func__);
  89645. + }
  89646. +
  89647. + dwc_memset(hcd->frame_list, 0x00, 4 * MAX_FRLIST_EN_NUM);
  89648. +
  89649. + return retval;
  89650. +}
  89651. +
  89652. +static void frame_list_free(dwc_otg_hcd_t * hcd)
  89653. +{
  89654. + if (!hcd->frame_list)
  89655. + return;
  89656. +
  89657. + DWC_DMA_FREE(4 * MAX_FRLIST_EN_NUM, hcd->frame_list, hcd->frame_list_dma);
  89658. + hcd->frame_list = NULL;
  89659. +}
  89660. +
  89661. +static void per_sched_enable(dwc_otg_hcd_t * hcd, uint16_t fr_list_en)
  89662. +{
  89663. +
  89664. + hcfg_data_t hcfg;
  89665. +
  89666. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  89667. +
  89668. + if (hcfg.b.perschedena) {
  89669. + /* already enabled */
  89670. + return;
  89671. + }
  89672. +
  89673. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hflbaddr,
  89674. + hcd->frame_list_dma);
  89675. +
  89676. + switch (fr_list_en) {
  89677. + case 64:
  89678. + hcfg.b.frlisten = 3;
  89679. + break;
  89680. + case 32:
  89681. + hcfg.b.frlisten = 2;
  89682. + break;
  89683. + case 16:
  89684. + hcfg.b.frlisten = 1;
  89685. + break;
  89686. + case 8:
  89687. + hcfg.b.frlisten = 0;
  89688. + break;
  89689. + default:
  89690. + break;
  89691. + }
  89692. +
  89693. + hcfg.b.perschedena = 1;
  89694. +
  89695. + DWC_DEBUGPL(DBG_HCD, "Enabling Periodic schedule\n");
  89696. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  89697. +
  89698. +}
  89699. +
  89700. +static void per_sched_disable(dwc_otg_hcd_t * hcd)
  89701. +{
  89702. + hcfg_data_t hcfg;
  89703. +
  89704. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  89705. +
  89706. + if (!hcfg.b.perschedena) {
  89707. + /* already disabled */
  89708. + return;
  89709. + }
  89710. + hcfg.b.perschedena = 0;
  89711. +
  89712. + DWC_DEBUGPL(DBG_HCD, "Disabling Periodic schedule\n");
  89713. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  89714. +}
  89715. +
  89716. +/*
  89717. + * Activates/Deactivates FrameList entries for the channel
  89718. + * based on endpoint servicing period.
  89719. + */
  89720. +void update_frame_list(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, uint8_t enable)
  89721. +{
  89722. + uint16_t i, j, inc;
  89723. + dwc_hc_t *hc = NULL;
  89724. +
  89725. + if (!qh->channel) {
  89726. + DWC_ERROR("qh->channel = %p", qh->channel);
  89727. + return;
  89728. + }
  89729. +
  89730. + if (!hcd) {
  89731. + DWC_ERROR("------hcd = %p", hcd);
  89732. + return;
  89733. + }
  89734. +
  89735. + if (!hcd->frame_list) {
  89736. + DWC_ERROR("-------hcd->frame_list = %p", hcd->frame_list);
  89737. + return;
  89738. + }
  89739. +
  89740. + hc = qh->channel;
  89741. + inc = frame_incr_val(qh);
  89742. + if (qh->ep_type == UE_ISOCHRONOUS)
  89743. + i = frame_list_idx(qh->sched_frame);
  89744. + else
  89745. + i = 0;
  89746. +
  89747. + j = i;
  89748. + do {
  89749. + if (enable)
  89750. + hcd->frame_list[j] |= (1 << hc->hc_num);
  89751. + else
  89752. + hcd->frame_list[j] &= ~(1 << hc->hc_num);
  89753. + j = (j + inc) & (MAX_FRLIST_EN_NUM - 1);
  89754. + }
  89755. + while (j != i);
  89756. + if (!enable)
  89757. + return;
  89758. + hc->schinfo = 0;
  89759. + if (qh->channel->speed == DWC_OTG_EP_SPEED_HIGH) {
  89760. + j = 1;
  89761. + /* TODO - check this */
  89762. + inc = (8 + qh->interval - 1) / qh->interval;
  89763. + for (i = 0; i < inc; i++) {
  89764. + hc->schinfo |= j;
  89765. + j = j << qh->interval;
  89766. + }
  89767. + } else {
  89768. + hc->schinfo = 0xff;
  89769. + }
  89770. +}
  89771. +
  89772. +#if 1
  89773. +void dump_frame_list(dwc_otg_hcd_t * hcd)
  89774. +{
  89775. + int i = 0;
  89776. + DWC_PRINTF("--FRAME LIST (hex) --\n");
  89777. + for (i = 0; i < MAX_FRLIST_EN_NUM; i++) {
  89778. + DWC_PRINTF("%x\t", hcd->frame_list[i]);
  89779. + if (!(i % 8) && i)
  89780. + DWC_PRINTF("\n");
  89781. + }
  89782. + DWC_PRINTF("\n----\n");
  89783. +
  89784. +}
  89785. +#endif
  89786. +
  89787. +static void release_channel_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  89788. +{
  89789. + dwc_irqflags_t flags;
  89790. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  89791. +
  89792. + dwc_hc_t *hc = qh->channel;
  89793. + if (dwc_qh_is_non_per(qh)) {
  89794. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  89795. + if (!microframe_schedule)
  89796. + hcd->non_periodic_channels--;
  89797. + else
  89798. + hcd->available_host_channels++;
  89799. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  89800. + } else
  89801. + update_frame_list(hcd, qh, 0);
  89802. +
  89803. + /*
  89804. + * The condition is added to prevent double cleanup try in case of device
  89805. + * disconnect. See channel cleanup in dwc_otg_hcd_disconnect_cb().
  89806. + */
  89807. + if (hc->qh) {
  89808. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  89809. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  89810. + hc->qh = NULL;
  89811. + }
  89812. +
  89813. + qh->channel = NULL;
  89814. + qh->ntd = 0;
  89815. +
  89816. + if (qh->desc_list) {
  89817. + dwc_memset(qh->desc_list, 0x00,
  89818. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  89819. + }
  89820. +}
  89821. +
  89822. +/**
  89823. + * Initializes a QH structure's Descriptor DMA related members.
  89824. + * Allocates memory for descriptor list.
  89825. + * On first periodic QH, allocates memory for FrameList
  89826. + * and enables periodic scheduling.
  89827. + *
  89828. + * @param hcd The HCD state structure for the DWC OTG controller.
  89829. + * @param qh The QH to init.
  89830. + *
  89831. + * @return 0 if successful, negative error code otherwise.
  89832. + */
  89833. +int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  89834. +{
  89835. + int retval = 0;
  89836. +
  89837. + if (qh->do_split) {
  89838. + DWC_ERROR("SPLIT Transfers are not supported in Descriptor DMA.\n");
  89839. + return -1;
  89840. + }
  89841. +
  89842. + retval = desc_list_alloc(qh);
  89843. +
  89844. + if ((retval == 0)
  89845. + && (qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)) {
  89846. + if (!hcd->frame_list) {
  89847. + retval = frame_list_alloc(hcd);
  89848. + /* Enable periodic schedule on first periodic QH */
  89849. + if (retval == 0)
  89850. + per_sched_enable(hcd, MAX_FRLIST_EN_NUM);
  89851. + }
  89852. + }
  89853. +
  89854. + qh->ntd = 0;
  89855. +
  89856. + return retval;
  89857. +}
  89858. +
  89859. +/**
  89860. + * Frees descriptor list memory associated with the QH.
  89861. + * If QH is periodic and the last, frees FrameList memory
  89862. + * and disables periodic scheduling.
  89863. + *
  89864. + * @param hcd The HCD state structure for the DWC OTG controller.
  89865. + * @param qh The QH to init.
  89866. + */
  89867. +void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  89868. +{
  89869. + desc_list_free(qh);
  89870. +
  89871. + /*
  89872. + * Channel still assigned due to some reasons.
  89873. + * Seen on Isoc URB dequeue. Channel halted but no subsequent
  89874. + * ChHalted interrupt to release the channel. Afterwards
  89875. + * when it comes here from endpoint disable routine
  89876. + * channel remains assigned.
  89877. + */
  89878. + if (qh->channel)
  89879. + release_channel_ddma(hcd, qh);
  89880. +
  89881. + if ((qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)
  89882. + && (microframe_schedule || !hcd->periodic_channels) && hcd->frame_list) {
  89883. +
  89884. + per_sched_disable(hcd);
  89885. + frame_list_free(hcd);
  89886. + }
  89887. +}
  89888. +
  89889. +static uint8_t frame_to_desc_idx(dwc_otg_qh_t * qh, uint16_t frame_idx)
  89890. +{
  89891. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  89892. + /*
  89893. + * Descriptor set(8 descriptors) index
  89894. + * which is 8-aligned.
  89895. + */
  89896. + return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
  89897. + } else {
  89898. + return (frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1));
  89899. + }
  89900. +}
  89901. +
  89902. +/*
  89903. + * Determine starting frame for Isochronous transfer.
  89904. + * Few frames skipped to prevent race condition with HC.
  89905. + */
  89906. +static uint8_t calc_starting_frame(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  89907. + uint8_t * skip_frames)
  89908. +{
  89909. + uint16_t frame = 0;
  89910. + hcd->frame_number = dwc_otg_hcd_get_frame_number(hcd);
  89911. +
  89912. + /* sched_frame is always frame number(not uFrame) both in FS and HS !! */
  89913. +
  89914. + /*
  89915. + * skip_frames is used to limit activated descriptors number
  89916. + * to avoid the situation when HC services the last activated
  89917. + * descriptor firstly.
  89918. + * Example for FS:
  89919. + * Current frame is 1, scheduled frame is 3. Since HC always fetches the descriptor
  89920. + * corresponding to curr_frame+1, the descriptor corresponding to frame 2
  89921. + * will be fetched. If the number of descriptors is max=64 (or greather) the
  89922. + * list will be fully programmed with Active descriptors and it is possible
  89923. + * case(rare) that the latest descriptor(considering rollback) corresponding
  89924. + * to frame 2 will be serviced first. HS case is more probable because, in fact,
  89925. + * up to 11 uframes(16 in the code) may be skipped.
  89926. + */
  89927. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  89928. + /*
  89929. + * Consider uframe counter also, to start xfer asap.
  89930. + * If half of the frame elapsed skip 2 frames otherwise
  89931. + * just 1 frame.
  89932. + * Starting descriptor index must be 8-aligned, so
  89933. + * if the current frame is near to complete the next one
  89934. + * is skipped as well.
  89935. + */
  89936. +
  89937. + if (dwc_micro_frame_num(hcd->frame_number) >= 5) {
  89938. + *skip_frames = 2 * 8;
  89939. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  89940. + } else {
  89941. + *skip_frames = 1 * 8;
  89942. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  89943. + }
  89944. +
  89945. + frame = dwc_full_frame_num(frame);
  89946. + } else {
  89947. + /*
  89948. + * Two frames are skipped for FS - the current and the next.
  89949. + * But for descriptor programming, 1 frame(descriptor) is enough,
  89950. + * see example above.
  89951. + */
  89952. + *skip_frames = 1;
  89953. + frame = dwc_frame_num_inc(hcd->frame_number, 2);
  89954. + }
  89955. +
  89956. + return frame;
  89957. +}
  89958. +
  89959. +/*
  89960. + * Calculate initial descriptor index for isochronous transfer
  89961. + * based on scheduled frame.
  89962. + */
  89963. +static uint8_t recalc_initial_desc_idx(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  89964. +{
  89965. + uint16_t frame = 0, fr_idx, fr_idx_tmp;
  89966. + uint8_t skip_frames = 0;
  89967. + /*
  89968. + * With current ISOC processing algorithm the channel is being
  89969. + * released when no more QTDs in the list(qh->ntd == 0).
  89970. + * Thus this function is called only when qh->ntd == 0 and qh->channel == 0.
  89971. + *
  89972. + * So qh->channel != NULL branch is not used and just not removed from the
  89973. + * source file. It is required for another possible approach which is,
  89974. + * do not disable and release the channel when ISOC session completed,
  89975. + * just move QH to inactive schedule until new QTD arrives.
  89976. + * On new QTD, the QH moved back to 'ready' schedule,
  89977. + * starting frame and therefore starting desc_index are recalculated.
  89978. + * In this case channel is released only on ep_disable.
  89979. + */
  89980. +
  89981. + /* Calculate starting descriptor index. For INTERRUPT endpoint it is always 0. */
  89982. + if (qh->channel) {
  89983. + frame = calc_starting_frame(hcd, qh, &skip_frames);
  89984. + /*
  89985. + * Calculate initial descriptor index based on FrameList current bitmap
  89986. + * and servicing period.
  89987. + */
  89988. + fr_idx_tmp = frame_list_idx(frame);
  89989. + fr_idx =
  89990. + (MAX_FRLIST_EN_NUM + frame_list_idx(qh->sched_frame) -
  89991. + fr_idx_tmp)
  89992. + % frame_incr_val(qh);
  89993. + fr_idx = (fr_idx + fr_idx_tmp) % MAX_FRLIST_EN_NUM;
  89994. + } else {
  89995. + qh->sched_frame = calc_starting_frame(hcd, qh, &skip_frames);
  89996. + fr_idx = frame_list_idx(qh->sched_frame);
  89997. + }
  89998. +
  89999. + qh->td_first = qh->td_last = frame_to_desc_idx(qh, fr_idx);
  90000. +
  90001. + return skip_frames;
  90002. +}
  90003. +
  90004. +#define ISOC_URB_GIVEBACK_ASAP
  90005. +
  90006. +#define MAX_ISOC_XFER_SIZE_FS 1023
  90007. +#define MAX_ISOC_XFER_SIZE_HS 3072
  90008. +#define DESCNUM_THRESHOLD 4
  90009. +
  90010. +static void init_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  90011. + uint8_t skip_frames)
  90012. +{
  90013. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  90014. + dwc_otg_qtd_t *qtd;
  90015. + dwc_otg_host_dma_desc_t *dma_desc;
  90016. + uint16_t idx, inc, n_desc, ntd_max, max_xfer_size;
  90017. +
  90018. + idx = qh->td_last;
  90019. + inc = qh->interval;
  90020. + n_desc = 0;
  90021. +
  90022. + ntd_max = (max_desc_num(qh) + qh->interval - 1) / qh->interval;
  90023. + if (skip_frames && !qh->channel)
  90024. + ntd_max = ntd_max - skip_frames / qh->interval;
  90025. +
  90026. + max_xfer_size =
  90027. + (qh->dev_speed ==
  90028. + DWC_OTG_EP_SPEED_HIGH) ? MAX_ISOC_XFER_SIZE_HS :
  90029. + MAX_ISOC_XFER_SIZE_FS;
  90030. +
  90031. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  90032. + while ((qh->ntd < ntd_max)
  90033. + && (qtd->isoc_frame_index_last <
  90034. + qtd->urb->packet_count)) {
  90035. +
  90036. + dma_desc = &qh->desc_list[idx];
  90037. + dwc_memset(dma_desc, 0x00, sizeof(dwc_otg_host_dma_desc_t));
  90038. +
  90039. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
  90040. +
  90041. + if (frame_desc->length > max_xfer_size)
  90042. + qh->n_bytes[idx] = max_xfer_size;
  90043. + else
  90044. + qh->n_bytes[idx] = frame_desc->length;
  90045. + dma_desc->status.b_isoc.n_bytes = qh->n_bytes[idx];
  90046. + dma_desc->status.b_isoc.a = 1;
  90047. + dma_desc->status.b_isoc.sts = 0;
  90048. +
  90049. + dma_desc->buf = qtd->urb->dma + frame_desc->offset;
  90050. +
  90051. + qh->ntd++;
  90052. +
  90053. + qtd->isoc_frame_index_last++;
  90054. +
  90055. +#ifdef ISOC_URB_GIVEBACK_ASAP
  90056. + /*
  90057. + * Set IOC for each descriptor corresponding to the
  90058. + * last frame of the URB.
  90059. + */
  90060. + if (qtd->isoc_frame_index_last ==
  90061. + qtd->urb->packet_count)
  90062. + dma_desc->status.b_isoc.ioc = 1;
  90063. +
  90064. +#endif
  90065. + idx = desclist_idx_inc(idx, inc, qh->dev_speed);
  90066. + n_desc++;
  90067. +
  90068. + }
  90069. + qtd->in_process = 1;
  90070. + }
  90071. +
  90072. + qh->td_last = idx;
  90073. +
  90074. +#ifdef ISOC_URB_GIVEBACK_ASAP
  90075. + /* Set IOC for the last descriptor if descriptor list is full */
  90076. + if (qh->ntd == ntd_max) {
  90077. + idx = desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  90078. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  90079. + }
  90080. +#else
  90081. + /*
  90082. + * Set IOC bit only for one descriptor.
  90083. + * Always try to be ahead of HW processing,
  90084. + * i.e. on IOC generation driver activates next descriptors but
  90085. + * core continues to process descriptors followed the one with IOC set.
  90086. + */
  90087. +
  90088. + if (n_desc > DESCNUM_THRESHOLD) {
  90089. + /*
  90090. + * Move IOC "up". Required even if there is only one QTD
  90091. + * in the list, cause QTDs migth continue to be queued,
  90092. + * but during the activation it was only one queued.
  90093. + * Actually more than one QTD might be in the list if this function called
  90094. + * from XferCompletion - QTDs was queued during HW processing of the previous
  90095. + * descriptor chunk.
  90096. + */
  90097. + idx = dwc_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2), qh->dev_speed);
  90098. + } else {
  90099. + /*
  90100. + * Set the IOC for the latest descriptor
  90101. + * if either number of descriptor is not greather than threshold
  90102. + * or no more new descriptors activated.
  90103. + */
  90104. + idx = dwc_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  90105. + }
  90106. +
  90107. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  90108. +#endif
  90109. +}
  90110. +
  90111. +static void init_non_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  90112. +{
  90113. +
  90114. + dwc_hc_t *hc;
  90115. + dwc_otg_host_dma_desc_t *dma_desc;
  90116. + dwc_otg_qtd_t *qtd;
  90117. + int num_packets, len, n_desc = 0;
  90118. +
  90119. + hc = qh->channel;
  90120. +
  90121. + /*
  90122. + * Start with hc->xfer_buff initialized in
  90123. + * assign_and_init_hc(), then if SG transfer consists of multiple URBs,
  90124. + * this pointer re-assigned to the buffer of the currently processed QTD.
  90125. + * For non-SG request there is always one QTD active.
  90126. + */
  90127. +
  90128. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  90129. +
  90130. + if (n_desc) {
  90131. + /* SG request - more than 1 QTDs */
  90132. + hc->xfer_buff = (uint8_t *)qtd->urb->dma + qtd->urb->actual_length;
  90133. + hc->xfer_len = qtd->urb->length - qtd->urb->actual_length;
  90134. + }
  90135. +
  90136. + qtd->n_desc = 0;
  90137. +
  90138. + do {
  90139. + dma_desc = &qh->desc_list[n_desc];
  90140. + len = hc->xfer_len;
  90141. +
  90142. + if (len > MAX_DMA_DESC_SIZE)
  90143. + len = MAX_DMA_DESC_SIZE - hc->max_packet + 1;
  90144. +
  90145. + if (hc->ep_is_in) {
  90146. + if (len > 0) {
  90147. + num_packets = (len + hc->max_packet - 1) / hc->max_packet;
  90148. + } else {
  90149. + /* Need 1 packet for transfer length of 0. */
  90150. + num_packets = 1;
  90151. + }
  90152. + /* Always program an integral # of max packets for IN transfers. */
  90153. + len = num_packets * hc->max_packet;
  90154. + }
  90155. +
  90156. + dma_desc->status.b.n_bytes = len;
  90157. +
  90158. + qh->n_bytes[n_desc] = len;
  90159. +
  90160. + if ((qh->ep_type == UE_CONTROL)
  90161. + && (qtd->control_phase == DWC_OTG_CONTROL_SETUP))
  90162. + dma_desc->status.b.sup = 1; /* Setup Packet */
  90163. +
  90164. + dma_desc->status.b.a = 1; /* Active descriptor */
  90165. + dma_desc->status.b.sts = 0;
  90166. +
  90167. + dma_desc->buf =
  90168. + ((unsigned long)hc->xfer_buff & 0xffffffff);
  90169. +
  90170. + /*
  90171. + * Last descriptor(or single) of IN transfer
  90172. + * with actual size less than MaxPacket.
  90173. + */
  90174. + if (len > hc->xfer_len) {
  90175. + hc->xfer_len = 0;
  90176. + } else {
  90177. + hc->xfer_buff += len;
  90178. + hc->xfer_len -= len;
  90179. + }
  90180. +
  90181. + qtd->n_desc++;
  90182. + n_desc++;
  90183. + }
  90184. + while ((hc->xfer_len > 0) && (n_desc != MAX_DMA_DESC_NUM_GENERIC));
  90185. +
  90186. +
  90187. + qtd->in_process = 1;
  90188. +
  90189. + if (qh->ep_type == UE_CONTROL)
  90190. + break;
  90191. +
  90192. + if (n_desc == MAX_DMA_DESC_NUM_GENERIC)
  90193. + break;
  90194. + }
  90195. +
  90196. + if (n_desc) {
  90197. + /* Request Transfer Complete interrupt for the last descriptor */
  90198. + qh->desc_list[n_desc - 1].status.b.ioc = 1;
  90199. + /* End of List indicator */
  90200. + qh->desc_list[n_desc - 1].status.b.eol = 1;
  90201. +
  90202. + hc->ntd = n_desc;
  90203. + }
  90204. +}
  90205. +
  90206. +/**
  90207. + * For Control and Bulk endpoints initializes descriptor list
  90208. + * and starts the transfer.
  90209. + *
  90210. + * For Interrupt and Isochronous endpoints initializes descriptor list
  90211. + * then updates FrameList, marking appropriate entries as active.
  90212. + * In case of Isochronous, the starting descriptor index is calculated based
  90213. + * on the scheduled frame, but only on the first transfer descriptor within a session.
  90214. + * Then starts the transfer via enabling the channel.
  90215. + * For Isochronous endpoint the channel is not halted on XferComplete
  90216. + * interrupt so remains assigned to the endpoint(QH) until session is done.
  90217. + *
  90218. + * @param hcd The HCD state structure for the DWC OTG controller.
  90219. + * @param qh The QH to init.
  90220. + *
  90221. + * @return 0 if successful, negative error code otherwise.
  90222. + */
  90223. +void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  90224. +{
  90225. + /* Channel is already assigned */
  90226. + dwc_hc_t *hc = qh->channel;
  90227. + uint8_t skip_frames = 0;
  90228. +
  90229. + switch (hc->ep_type) {
  90230. + case DWC_OTG_EP_TYPE_CONTROL:
  90231. + case DWC_OTG_EP_TYPE_BULK:
  90232. + init_non_isoc_dma_desc(hcd, qh);
  90233. +
  90234. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  90235. + break;
  90236. + case DWC_OTG_EP_TYPE_INTR:
  90237. + init_non_isoc_dma_desc(hcd, qh);
  90238. +
  90239. + update_frame_list(hcd, qh, 1);
  90240. +
  90241. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  90242. + break;
  90243. + case DWC_OTG_EP_TYPE_ISOC:
  90244. +
  90245. + if (!qh->ntd)
  90246. + skip_frames = recalc_initial_desc_idx(hcd, qh);
  90247. +
  90248. + init_isoc_dma_desc(hcd, qh, skip_frames);
  90249. +
  90250. + if (!hc->xfer_started) {
  90251. +
  90252. + update_frame_list(hcd, qh, 1);
  90253. +
  90254. + /*
  90255. + * Always set to max, instead of actual size.
  90256. + * Otherwise ntd will be changed with
  90257. + * channel being enabled. Not recommended.
  90258. + *
  90259. + */
  90260. + hc->ntd = max_desc_num(qh);
  90261. + /* Enable channel only once for ISOC */
  90262. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  90263. + }
  90264. +
  90265. + break;
  90266. + default:
  90267. +
  90268. + break;
  90269. + }
  90270. +}
  90271. +
  90272. +static void complete_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  90273. + dwc_hc_t * hc,
  90274. + dwc_otg_hc_regs_t * hc_regs,
  90275. + dwc_otg_halt_status_e halt_status)
  90276. +{
  90277. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  90278. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  90279. + dwc_otg_qh_t *qh;
  90280. + dwc_otg_host_dma_desc_t *dma_desc;
  90281. + uint16_t idx, remain;
  90282. + uint8_t urb_compl;
  90283. +
  90284. + qh = hc->qh;
  90285. + idx = qh->td_first;
  90286. +
  90287. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  90288. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry)
  90289. + qtd->in_process = 0;
  90290. + return;
  90291. + } else if ((halt_status == DWC_OTG_HC_XFER_AHB_ERR) ||
  90292. + (halt_status == DWC_OTG_HC_XFER_BABBLE_ERR)) {
  90293. + /*
  90294. + * Channel is halted in these error cases.
  90295. + * Considered as serious issues.
  90296. + * Complete all URBs marking all frames as failed,
  90297. + * irrespective whether some of the descriptors(frames) succeeded or no.
  90298. + * Pass error code to completion routine as well, to
  90299. + * update urb->status, some of class drivers might use it to stop
  90300. + * queing transfer requests.
  90301. + */
  90302. + int err = (halt_status == DWC_OTG_HC_XFER_AHB_ERR)
  90303. + ? (-DWC_E_IO)
  90304. + : (-DWC_E_OVERFLOW);
  90305. +
  90306. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  90307. + for (idx = 0; idx < qtd->urb->packet_count; idx++) {
  90308. + frame_desc = &qtd->urb->iso_descs[idx];
  90309. + frame_desc->status = err;
  90310. + }
  90311. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, err);
  90312. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  90313. + }
  90314. + return;
  90315. + }
  90316. +
  90317. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  90318. +
  90319. + if (!qtd->in_process)
  90320. + break;
  90321. +
  90322. + urb_compl = 0;
  90323. +
  90324. + do {
  90325. +
  90326. + dma_desc = &qh->desc_list[idx];
  90327. +
  90328. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  90329. + remain = hc->ep_is_in ? dma_desc->status.b_isoc.n_bytes : 0;
  90330. +
  90331. + if (dma_desc->status.b_isoc.sts == DMA_DESC_STS_PKTERR) {
  90332. + /*
  90333. + * XactError or, unable to complete all the transactions
  90334. + * in the scheduled micro-frame/frame,
  90335. + * both indicated by DMA_DESC_STS_PKTERR.
  90336. + */
  90337. + qtd->urb->error_count++;
  90338. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  90339. + frame_desc->status = -DWC_E_PROTOCOL;
  90340. + } else {
  90341. + /* Success */
  90342. +
  90343. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  90344. + frame_desc->status = 0;
  90345. + }
  90346. +
  90347. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  90348. + /*
  90349. + * urb->status is not used for isoc transfers here.
  90350. + * The individual frame_desc status are used instead.
  90351. + */
  90352. +
  90353. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  90354. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  90355. +
  90356. + /*
  90357. + * This check is necessary because urb_dequeue can be called
  90358. + * from urb complete callback(sound driver example).
  90359. + * All pending URBs are dequeued there, so no need for
  90360. + * further processing.
  90361. + */
  90362. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  90363. + return;
  90364. + }
  90365. +
  90366. + urb_compl = 1;
  90367. +
  90368. + }
  90369. +
  90370. + qh->ntd--;
  90371. +
  90372. + /* Stop if IOC requested descriptor reached */
  90373. + if (dma_desc->status.b_isoc.ioc) {
  90374. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  90375. + goto stop_scan;
  90376. + }
  90377. +
  90378. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  90379. +
  90380. + if (urb_compl)
  90381. + break;
  90382. + }
  90383. + while (idx != qh->td_first);
  90384. + }
  90385. +stop_scan:
  90386. + qh->td_first = idx;
  90387. +}
  90388. +
  90389. +uint8_t update_non_isoc_urb_state_ddma(dwc_otg_hcd_t * hcd,
  90390. + dwc_hc_t * hc,
  90391. + dwc_otg_qtd_t * qtd,
  90392. + dwc_otg_host_dma_desc_t * dma_desc,
  90393. + dwc_otg_halt_status_e halt_status,
  90394. + uint32_t n_bytes, uint8_t * xfer_done)
  90395. +{
  90396. +
  90397. + uint16_t remain = hc->ep_is_in ? dma_desc->status.b.n_bytes : 0;
  90398. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  90399. +
  90400. + if (halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  90401. + urb->status = -DWC_E_IO;
  90402. + return 1;
  90403. + }
  90404. + if (dma_desc->status.b.sts == DMA_DESC_STS_PKTERR) {
  90405. + switch (halt_status) {
  90406. + case DWC_OTG_HC_XFER_STALL:
  90407. + urb->status = -DWC_E_PIPE;
  90408. + break;
  90409. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  90410. + urb->status = -DWC_E_OVERFLOW;
  90411. + break;
  90412. + case DWC_OTG_HC_XFER_XACT_ERR:
  90413. + urb->status = -DWC_E_PROTOCOL;
  90414. + break;
  90415. + default:
  90416. + DWC_ERROR("%s: Unhandled descriptor error status (%d)\n", __func__,
  90417. + halt_status);
  90418. + break;
  90419. + }
  90420. + return 1;
  90421. + }
  90422. +
  90423. + if (dma_desc->status.b.a == 1) {
  90424. + DWC_DEBUGPL(DBG_HCDV,
  90425. + "Active descriptor encountered on channel %d\n",
  90426. + hc->hc_num);
  90427. + return 0;
  90428. + }
  90429. +
  90430. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL) {
  90431. + if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  90432. + urb->actual_length += n_bytes - remain;
  90433. + if (remain || urb->actual_length == urb->length) {
  90434. + /*
  90435. + * For Control Data stage do not set urb->status=0 to prevent
  90436. + * URB callback. Set it when Status phase done. See below.
  90437. + */
  90438. + *xfer_done = 1;
  90439. + }
  90440. +
  90441. + } else if (qtd->control_phase == DWC_OTG_CONTROL_STATUS) {
  90442. + urb->status = 0;
  90443. + *xfer_done = 1;
  90444. + }
  90445. + /* No handling for SETUP stage */
  90446. + } else {
  90447. + /* BULK and INTR */
  90448. + urb->actual_length += n_bytes - remain;
  90449. + if (remain || urb->actual_length == urb->length) {
  90450. + urb->status = 0;
  90451. + *xfer_done = 1;
  90452. + }
  90453. + }
  90454. +
  90455. + return 0;
  90456. +}
  90457. +
  90458. +static void complete_non_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  90459. + dwc_hc_t * hc,
  90460. + dwc_otg_hc_regs_t * hc_regs,
  90461. + dwc_otg_halt_status_e halt_status)
  90462. +{
  90463. + dwc_otg_hcd_urb_t *urb = NULL;
  90464. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  90465. + dwc_otg_qh_t *qh;
  90466. + dwc_otg_host_dma_desc_t *dma_desc;
  90467. + uint32_t n_bytes, n_desc, i;
  90468. + uint8_t failed = 0, xfer_done;
  90469. +
  90470. + n_desc = 0;
  90471. +
  90472. + qh = hc->qh;
  90473. +
  90474. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  90475. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  90476. + qtd->in_process = 0;
  90477. + }
  90478. + return;
  90479. + }
  90480. +
  90481. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  90482. +
  90483. + urb = qtd->urb;
  90484. +
  90485. + n_bytes = 0;
  90486. + xfer_done = 0;
  90487. +
  90488. + for (i = 0; i < qtd->n_desc; i++) {
  90489. + dma_desc = &qh->desc_list[n_desc];
  90490. +
  90491. + n_bytes = qh->n_bytes[n_desc];
  90492. +
  90493. + failed =
  90494. + update_non_isoc_urb_state_ddma(hcd, hc, qtd,
  90495. + dma_desc,
  90496. + halt_status, n_bytes,
  90497. + &xfer_done);
  90498. +
  90499. + if (failed
  90500. + || (xfer_done
  90501. + && (urb->status != -DWC_E_IN_PROGRESS))) {
  90502. +
  90503. + hcd->fops->complete(hcd, urb->priv, urb,
  90504. + urb->status);
  90505. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  90506. +
  90507. + if (failed)
  90508. + goto stop_scan;
  90509. + } else if (qh->ep_type == UE_CONTROL) {
  90510. + if (qtd->control_phase == DWC_OTG_CONTROL_SETUP) {
  90511. + if (urb->length > 0) {
  90512. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  90513. + } else {
  90514. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  90515. + }
  90516. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
  90517. + } else if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  90518. + if (xfer_done) {
  90519. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  90520. + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
  90521. + } else if (i + 1 == qtd->n_desc) {
  90522. + /*
  90523. + * Last descriptor for Control data stage which is
  90524. + * not completed yet.
  90525. + */
  90526. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  90527. + }
  90528. + }
  90529. + }
  90530. +
  90531. + n_desc++;
  90532. + }
  90533. +
  90534. + }
  90535. +
  90536. +stop_scan:
  90537. +
  90538. + if (qh->ep_type != UE_CONTROL) {
  90539. + /*
  90540. + * Resetting the data toggle for bulk
  90541. + * and interrupt endpoints in case of stall. See handle_hc_stall_intr()
  90542. + */
  90543. + if (halt_status == DWC_OTG_HC_XFER_STALL)
  90544. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  90545. + else
  90546. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  90547. + }
  90548. +
  90549. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  90550. + hcint_data_t hcint;
  90551. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  90552. + if (hcint.b.nyet) {
  90553. + /*
  90554. + * Got a NYET on the last transaction of the transfer. It
  90555. + * means that the endpoint should be in the PING state at the
  90556. + * beginning of the next transfer.
  90557. + */
  90558. + qh->ping_state = 1;
  90559. + clear_hc_int(hc_regs, nyet);
  90560. + }
  90561. +
  90562. + }
  90563. +
  90564. +}
  90565. +
  90566. +/**
  90567. + * This function is called from interrupt handlers.
  90568. + * Scans the descriptor list, updates URB's status and
  90569. + * calls completion routine for the URB if it's done.
  90570. + * Releases the channel to be used by other transfers.
  90571. + * In case of Isochronous endpoint the channel is not halted until
  90572. + * the end of the session, i.e. QTD list is empty.
  90573. + * If periodic channel released the FrameList is updated accordingly.
  90574. + *
  90575. + * Calls transaction selection routines to activate pending transfers.
  90576. + *
  90577. + * @param hcd The HCD state structure for the DWC OTG controller.
  90578. + * @param hc Host channel, the transfer is completed on.
  90579. + * @param hc_regs Host channel registers.
  90580. + * @param halt_status Reason the channel is being halted,
  90581. + * or just XferComplete for isochronous transfer
  90582. + */
  90583. +void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  90584. + dwc_hc_t * hc,
  90585. + dwc_otg_hc_regs_t * hc_regs,
  90586. + dwc_otg_halt_status_e halt_status)
  90587. +{
  90588. + uint8_t continue_isoc_xfer = 0;
  90589. + dwc_otg_transaction_type_e tr_type;
  90590. + dwc_otg_qh_t *qh = hc->qh;
  90591. +
  90592. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  90593. +
  90594. + complete_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  90595. +
  90596. + /* Release the channel if halted or session completed */
  90597. + if (halt_status != DWC_OTG_HC_XFER_COMPLETE ||
  90598. + DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  90599. +
  90600. + /* Halt the channel if session completed */
  90601. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  90602. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  90603. + }
  90604. +
  90605. + release_channel_ddma(hcd, qh);
  90606. + dwc_otg_hcd_qh_remove(hcd, qh);
  90607. + } else {
  90608. + /* Keep in assigned schedule to continue transfer */
  90609. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  90610. + &qh->qh_list_entry);
  90611. + continue_isoc_xfer = 1;
  90612. +
  90613. + }
  90614. + /** @todo Consider the case when period exceeds FrameList size.
  90615. + * Frame Rollover interrupt should be used.
  90616. + */
  90617. + } else {
  90618. + /* Scan descriptor list to complete the URB(s), then release the channel */
  90619. + complete_non_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  90620. +
  90621. + release_channel_ddma(hcd, qh);
  90622. + dwc_otg_hcd_qh_remove(hcd, qh);
  90623. +
  90624. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  90625. + /* Add back to inactive non-periodic schedule on normal completion */
  90626. + dwc_otg_hcd_qh_add(hcd, qh);
  90627. + }
  90628. +
  90629. + }
  90630. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  90631. + if (tr_type != DWC_OTG_TRANSACTION_NONE || continue_isoc_xfer) {
  90632. + if (continue_isoc_xfer) {
  90633. + if (tr_type == DWC_OTG_TRANSACTION_NONE) {
  90634. + tr_type = DWC_OTG_TRANSACTION_PERIODIC;
  90635. + } else if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC) {
  90636. + tr_type = DWC_OTG_TRANSACTION_ALL;
  90637. + }
  90638. + }
  90639. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  90640. + }
  90641. +}
  90642. +
  90643. +#endif /* DWC_DEVICE_ONLY */
  90644. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_hcd.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
  90645. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 1970-01-01 01:00:00.000000000 +0100
  90646. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 2015-02-09 04:40:29.000000000 +0100
  90647. @@ -0,0 +1,862 @@
  90648. +/* ==========================================================================
  90649. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
  90650. + * $Revision: #58 $
  90651. + * $Date: 2011/09/15 $
  90652. + * $Change: 1846647 $
  90653. + *
  90654. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  90655. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  90656. + * otherwise expressly agreed to in writing between Synopsys and you.
  90657. + *
  90658. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  90659. + * any End User Software License Agreement or Agreement for Licensed Product
  90660. + * with Synopsys or any supplement thereto. You are permitted to use and
  90661. + * redistribute this Software in source and binary forms, with or without
  90662. + * modification, provided that redistributions of source code must retain this
  90663. + * notice. You may not view, use, disclose, copy or distribute this file or
  90664. + * any information contained herein except pursuant to this license grant from
  90665. + * Synopsys. If you do not agree with this notice, including the disclaimer
  90666. + * below, then you are not authorized to use the Software.
  90667. + *
  90668. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  90669. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  90670. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  90671. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  90672. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  90673. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  90674. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  90675. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  90676. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  90677. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  90678. + * DAMAGE.
  90679. + * ========================================================================== */
  90680. +#ifndef DWC_DEVICE_ONLY
  90681. +#ifndef __DWC_HCD_H__
  90682. +#define __DWC_HCD_H__
  90683. +
  90684. +#include "dwc_otg_os_dep.h"
  90685. +#include "usb.h"
  90686. +#include "dwc_otg_hcd_if.h"
  90687. +#include "dwc_otg_core_if.h"
  90688. +#include "dwc_list.h"
  90689. +#include "dwc_otg_cil.h"
  90690. +#include "dwc_otg_fiq_fsm.h"
  90691. +
  90692. +
  90693. +/**
  90694. + * @file
  90695. + *
  90696. + * This file contains the structures, constants, and interfaces for
  90697. + * the Host Contoller Driver (HCD).
  90698. + *
  90699. + * The Host Controller Driver (HCD) is responsible for translating requests
  90700. + * from the USB Driver into the appropriate actions on the DWC_otg controller.
  90701. + * It isolates the USBD from the specifics of the controller by providing an
  90702. + * API to the USBD.
  90703. + */
  90704. +
  90705. +struct dwc_otg_hcd_pipe_info {
  90706. + uint8_t dev_addr;
  90707. + uint8_t ep_num;
  90708. + uint8_t pipe_type;
  90709. + uint8_t pipe_dir;
  90710. + uint16_t mps;
  90711. +};
  90712. +
  90713. +struct dwc_otg_hcd_iso_packet_desc {
  90714. + uint32_t offset;
  90715. + uint32_t length;
  90716. + uint32_t actual_length;
  90717. + uint32_t status;
  90718. +};
  90719. +
  90720. +struct dwc_otg_qtd;
  90721. +
  90722. +struct dwc_otg_hcd_urb {
  90723. + void *priv;
  90724. + struct dwc_otg_qtd *qtd;
  90725. + void *buf;
  90726. + dwc_dma_t dma;
  90727. + void *setup_packet;
  90728. + dwc_dma_t setup_dma;
  90729. + uint32_t length;
  90730. + uint32_t actual_length;
  90731. + uint32_t status;
  90732. + uint32_t error_count;
  90733. + uint32_t packet_count;
  90734. + uint32_t flags;
  90735. + uint16_t interval;
  90736. + struct dwc_otg_hcd_pipe_info pipe_info;
  90737. + struct dwc_otg_hcd_iso_packet_desc iso_descs[0];
  90738. +};
  90739. +
  90740. +static inline uint8_t dwc_otg_hcd_get_ep_num(struct dwc_otg_hcd_pipe_info *pipe)
  90741. +{
  90742. + return pipe->ep_num;
  90743. +}
  90744. +
  90745. +static inline uint8_t dwc_otg_hcd_get_pipe_type(struct dwc_otg_hcd_pipe_info
  90746. + *pipe)
  90747. +{
  90748. + return pipe->pipe_type;
  90749. +}
  90750. +
  90751. +static inline uint16_t dwc_otg_hcd_get_mps(struct dwc_otg_hcd_pipe_info *pipe)
  90752. +{
  90753. + return pipe->mps;
  90754. +}
  90755. +
  90756. +static inline uint8_t dwc_otg_hcd_get_dev_addr(struct dwc_otg_hcd_pipe_info
  90757. + *pipe)
  90758. +{
  90759. + return pipe->dev_addr;
  90760. +}
  90761. +
  90762. +static inline uint8_t dwc_otg_hcd_is_pipe_isoc(struct dwc_otg_hcd_pipe_info
  90763. + *pipe)
  90764. +{
  90765. + return (pipe->pipe_type == UE_ISOCHRONOUS);
  90766. +}
  90767. +
  90768. +static inline uint8_t dwc_otg_hcd_is_pipe_int(struct dwc_otg_hcd_pipe_info
  90769. + *pipe)
  90770. +{
  90771. + return (pipe->pipe_type == UE_INTERRUPT);
  90772. +}
  90773. +
  90774. +static inline uint8_t dwc_otg_hcd_is_pipe_bulk(struct dwc_otg_hcd_pipe_info
  90775. + *pipe)
  90776. +{
  90777. + return (pipe->pipe_type == UE_BULK);
  90778. +}
  90779. +
  90780. +static inline uint8_t dwc_otg_hcd_is_pipe_control(struct dwc_otg_hcd_pipe_info
  90781. + *pipe)
  90782. +{
  90783. + return (pipe->pipe_type == UE_CONTROL);
  90784. +}
  90785. +
  90786. +static inline uint8_t dwc_otg_hcd_is_pipe_in(struct dwc_otg_hcd_pipe_info *pipe)
  90787. +{
  90788. + return (pipe->pipe_dir == UE_DIR_IN);
  90789. +}
  90790. +
  90791. +static inline uint8_t dwc_otg_hcd_is_pipe_out(struct dwc_otg_hcd_pipe_info
  90792. + *pipe)
  90793. +{
  90794. + return (!dwc_otg_hcd_is_pipe_in(pipe));
  90795. +}
  90796. +
  90797. +static inline void dwc_otg_hcd_fill_pipe(struct dwc_otg_hcd_pipe_info *pipe,
  90798. + uint8_t devaddr, uint8_t ep_num,
  90799. + uint8_t pipe_type, uint8_t pipe_dir,
  90800. + uint16_t mps)
  90801. +{
  90802. + pipe->dev_addr = devaddr;
  90803. + pipe->ep_num = ep_num;
  90804. + pipe->pipe_type = pipe_type;
  90805. + pipe->pipe_dir = pipe_dir;
  90806. + pipe->mps = mps;
  90807. +}
  90808. +
  90809. +/**
  90810. + * Phases for control transfers.
  90811. + */
  90812. +typedef enum dwc_otg_control_phase {
  90813. + DWC_OTG_CONTROL_SETUP,
  90814. + DWC_OTG_CONTROL_DATA,
  90815. + DWC_OTG_CONTROL_STATUS
  90816. +} dwc_otg_control_phase_e;
  90817. +
  90818. +/** Transaction types. */
  90819. +typedef enum dwc_otg_transaction_type {
  90820. + DWC_OTG_TRANSACTION_NONE = 0,
  90821. + DWC_OTG_TRANSACTION_PERIODIC = 1,
  90822. + DWC_OTG_TRANSACTION_NON_PERIODIC = 2,
  90823. + DWC_OTG_TRANSACTION_ALL = DWC_OTG_TRANSACTION_PERIODIC + DWC_OTG_TRANSACTION_NON_PERIODIC
  90824. +} dwc_otg_transaction_type_e;
  90825. +
  90826. +struct dwc_otg_qh;
  90827. +
  90828. +/**
  90829. + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
  90830. + * interrupt, or isochronous transfer. A single QTD is created for each URB
  90831. + * (of one of these types) submitted to the HCD. The transfer associated with
  90832. + * a QTD may require one or multiple transactions.
  90833. + *
  90834. + * A QTD is linked to a Queue Head, which is entered in either the
  90835. + * non-periodic or periodic schedule for execution. When a QTD is chosen for
  90836. + * execution, some or all of its transactions may be executed. After
  90837. + * execution, the state of the QTD is updated. The QTD may be retired if all
  90838. + * its transactions are complete or if an error occurred. Otherwise, it
  90839. + * remains in the schedule so more transactions can be executed later.
  90840. + */
  90841. +typedef struct dwc_otg_qtd {
  90842. + /**
  90843. + * Determines the PID of the next data packet for the data phase of
  90844. + * control transfers. Ignored for other transfer types.<br>
  90845. + * One of the following values:
  90846. + * - DWC_OTG_HC_PID_DATA0
  90847. + * - DWC_OTG_HC_PID_DATA1
  90848. + */
  90849. + uint8_t data_toggle;
  90850. +
  90851. + /** Current phase for control transfers (Setup, Data, or Status). */
  90852. + dwc_otg_control_phase_e control_phase;
  90853. +
  90854. + /** Keep track of the current split type
  90855. + * for FS/LS endpoints on a HS Hub */
  90856. + uint8_t complete_split;
  90857. +
  90858. + /** How many bytes transferred during SSPLIT OUT */
  90859. + uint32_t ssplit_out_xfer_count;
  90860. +
  90861. + /**
  90862. + * Holds the number of bus errors that have occurred for a transaction
  90863. + * within this transfer.
  90864. + */
  90865. + uint8_t error_count;
  90866. +
  90867. + /**
  90868. + * Index of the next frame descriptor for an isochronous transfer. A
  90869. + * frame descriptor describes the buffer position and length of the
  90870. + * data to be transferred in the next scheduled (micro)frame of an
  90871. + * isochronous transfer. It also holds status for that transaction.
  90872. + * The frame index starts at 0.
  90873. + */
  90874. + uint16_t isoc_frame_index;
  90875. +
  90876. + /** Position of the ISOC split on full/low speed */
  90877. + uint8_t isoc_split_pos;
  90878. +
  90879. + /** Position of the ISOC split in the buffer for the current frame */
  90880. + uint16_t isoc_split_offset;
  90881. +
  90882. + /** URB for this transfer */
  90883. + struct dwc_otg_hcd_urb *urb;
  90884. +
  90885. + struct dwc_otg_qh *qh;
  90886. +
  90887. + /** This list of QTDs */
  90888. + DWC_CIRCLEQ_ENTRY(dwc_otg_qtd) qtd_list_entry;
  90889. +
  90890. + /** Indicates if this QTD is currently processed by HW. */
  90891. + uint8_t in_process;
  90892. +
  90893. + /** Number of DMA descriptors for this QTD */
  90894. + uint8_t n_desc;
  90895. +
  90896. + /**
  90897. + * Last activated frame(packet) index.
  90898. + * Used in Descriptor DMA mode only.
  90899. + */
  90900. + uint16_t isoc_frame_index_last;
  90901. +
  90902. +} dwc_otg_qtd_t;
  90903. +
  90904. +DWC_CIRCLEQ_HEAD(dwc_otg_qtd_list, dwc_otg_qtd);
  90905. +
  90906. +/**
  90907. + * A Queue Head (QH) holds the static characteristics of an endpoint and
  90908. + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
  90909. + * be entered in either the non-periodic or periodic schedule.
  90910. + */
  90911. +typedef struct dwc_otg_qh {
  90912. + /**
  90913. + * Endpoint type.
  90914. + * One of the following values:
  90915. + * - UE_CONTROL
  90916. + * - UE_BULK
  90917. + * - UE_INTERRUPT
  90918. + * - UE_ISOCHRONOUS
  90919. + */
  90920. + uint8_t ep_type;
  90921. + uint8_t ep_is_in;
  90922. +
  90923. + /** wMaxPacketSize Field of Endpoint Descriptor. */
  90924. + uint16_t maxp;
  90925. +
  90926. + /**
  90927. + * Device speed.
  90928. + * One of the following values:
  90929. + * - DWC_OTG_EP_SPEED_LOW
  90930. + * - DWC_OTG_EP_SPEED_FULL
  90931. + * - DWC_OTG_EP_SPEED_HIGH
  90932. + */
  90933. + uint8_t dev_speed;
  90934. +
  90935. + /**
  90936. + * Determines the PID of the next data packet for non-control
  90937. + * transfers. Ignored for control transfers.<br>
  90938. + * One of the following values:
  90939. + * - DWC_OTG_HC_PID_DATA0
  90940. + * - DWC_OTG_HC_PID_DATA1
  90941. + */
  90942. + uint8_t data_toggle;
  90943. +
  90944. + /** Ping state if 1. */
  90945. + uint8_t ping_state;
  90946. +
  90947. + /**
  90948. + * List of QTDs for this QH.
  90949. + */
  90950. + struct dwc_otg_qtd_list qtd_list;
  90951. +
  90952. + /** Host channel currently processing transfers for this QH. */
  90953. + struct dwc_hc *channel;
  90954. +
  90955. + /** Full/low speed endpoint on high-speed hub requires split. */
  90956. + uint8_t do_split;
  90957. +
  90958. + /** @name Periodic schedule information */
  90959. + /** @{ */
  90960. +
  90961. + /** Bandwidth in microseconds per (micro)frame. */
  90962. + uint16_t usecs;
  90963. +
  90964. + /** Interval between transfers in (micro)frames. */
  90965. + uint16_t interval;
  90966. +
  90967. + /**
  90968. + * (micro)frame to initialize a periodic transfer. The transfer
  90969. + * executes in the following (micro)frame.
  90970. + */
  90971. + uint16_t sched_frame;
  90972. +
  90973. + /*
  90974. + ** Frame a NAK was received on this queue head, used to minimise NAK retransmission
  90975. + */
  90976. + uint16_t nak_frame;
  90977. +
  90978. + /** (micro)frame at which last start split was initialized. */
  90979. + uint16_t start_split_frame;
  90980. +
  90981. + /** @} */
  90982. +
  90983. + /**
  90984. + * Used instead of original buffer if
  90985. + * it(physical address) is not dword-aligned.
  90986. + */
  90987. + uint8_t *dw_align_buf;
  90988. + dwc_dma_t dw_align_buf_dma;
  90989. +
  90990. + /** Entry for QH in either the periodic or non-periodic schedule. */
  90991. + dwc_list_link_t qh_list_entry;
  90992. +
  90993. + /** @name Descriptor DMA support */
  90994. + /** @{ */
  90995. +
  90996. + /** Descriptor List. */
  90997. + dwc_otg_host_dma_desc_t *desc_list;
  90998. +
  90999. + /** Descriptor List physical address. */
  91000. + dwc_dma_t desc_list_dma;
  91001. +
  91002. + /**
  91003. + * Xfer Bytes array.
  91004. + * Each element corresponds to a descriptor and indicates
  91005. + * original XferSize size value for the descriptor.
  91006. + */
  91007. + uint32_t *n_bytes;
  91008. +
  91009. + /** Actual number of transfer descriptors in a list. */
  91010. + uint16_t ntd;
  91011. +
  91012. + /** First activated isochronous transfer descriptor index. */
  91013. + uint8_t td_first;
  91014. + /** Last activated isochronous transfer descriptor index. */
  91015. + uint8_t td_last;
  91016. +
  91017. + /** @} */
  91018. +
  91019. +
  91020. + uint16_t speed;
  91021. + uint16_t frame_usecs[8];
  91022. +
  91023. + uint32_t skip_count;
  91024. +} dwc_otg_qh_t;
  91025. +
  91026. +DWC_CIRCLEQ_HEAD(hc_list, dwc_hc);
  91027. +
  91028. +typedef struct urb_tq_entry {
  91029. + struct urb *urb;
  91030. + DWC_TAILQ_ENTRY(urb_tq_entry) urb_tq_entries;
  91031. +} urb_tq_entry_t;
  91032. +
  91033. +DWC_TAILQ_HEAD(urb_list, urb_tq_entry);
  91034. +
  91035. +/**
  91036. + * This structure holds the state of the HCD, including the non-periodic and
  91037. + * periodic schedules.
  91038. + */
  91039. +struct dwc_otg_hcd {
  91040. + /** The DWC otg device pointer */
  91041. + struct dwc_otg_device *otg_dev;
  91042. + /** DWC OTG Core Interface Layer */
  91043. + dwc_otg_core_if_t *core_if;
  91044. +
  91045. + /** Function HCD driver callbacks */
  91046. + struct dwc_otg_hcd_function_ops *fops;
  91047. +
  91048. + /** Internal DWC HCD Flags */
  91049. + volatile union dwc_otg_hcd_internal_flags {
  91050. + uint32_t d32;
  91051. + struct {
  91052. + unsigned port_connect_status_change:1;
  91053. + unsigned port_connect_status:1;
  91054. + unsigned port_reset_change:1;
  91055. + unsigned port_enable_change:1;
  91056. + unsigned port_suspend_change:1;
  91057. + unsigned port_over_current_change:1;
  91058. + unsigned port_l1_change:1;
  91059. + unsigned reserved:26;
  91060. + } b;
  91061. + } flags;
  91062. +
  91063. + /**
  91064. + * Inactive items in the non-periodic schedule. This is a list of
  91065. + * Queue Heads. Transfers associated with these Queue Heads are not
  91066. + * currently assigned to a host channel.
  91067. + */
  91068. + dwc_list_link_t non_periodic_sched_inactive;
  91069. +
  91070. + /**
  91071. + * Active items in the non-periodic schedule. This is a list of
  91072. + * Queue Heads. Transfers associated with these Queue Heads are
  91073. + * currently assigned to a host channel.
  91074. + */
  91075. + dwc_list_link_t non_periodic_sched_active;
  91076. +
  91077. + /**
  91078. + * Pointer to the next Queue Head to process in the active
  91079. + * non-periodic schedule.
  91080. + */
  91081. + dwc_list_link_t *non_periodic_qh_ptr;
  91082. +
  91083. + /**
  91084. + * Inactive items in the periodic schedule. This is a list of QHs for
  91085. + * periodic transfers that are _not_ scheduled for the next frame.
  91086. + * Each QH in the list has an interval counter that determines when it
  91087. + * needs to be scheduled for execution. This scheduling mechanism
  91088. + * allows only a simple calculation for periodic bandwidth used (i.e.
  91089. + * must assume that all periodic transfers may need to execute in the
  91090. + * same frame). However, it greatly simplifies scheduling and should
  91091. + * be sufficient for the vast majority of OTG hosts, which need to
  91092. + * connect to a small number of peripherals at one time.
  91093. + *
  91094. + * Items move from this list to periodic_sched_ready when the QH
  91095. + * interval counter is 0 at SOF.
  91096. + */
  91097. + dwc_list_link_t periodic_sched_inactive;
  91098. +
  91099. + /**
  91100. + * List of periodic QHs that are ready for execution in the next
  91101. + * frame, but have not yet been assigned to host channels.
  91102. + *
  91103. + * Items move from this list to periodic_sched_assigned as host
  91104. + * channels become available during the current frame.
  91105. + */
  91106. + dwc_list_link_t periodic_sched_ready;
  91107. +
  91108. + /**
  91109. + * List of periodic QHs to be executed in the next frame that are
  91110. + * assigned to host channels.
  91111. + *
  91112. + * Items move from this list to periodic_sched_queued as the
  91113. + * transactions for the QH are queued to the DWC_otg controller.
  91114. + */
  91115. + dwc_list_link_t periodic_sched_assigned;
  91116. +
  91117. + /**
  91118. + * List of periodic QHs that have been queued for execution.
  91119. + *
  91120. + * Items move from this list to either periodic_sched_inactive or
  91121. + * periodic_sched_ready when the channel associated with the transfer
  91122. + * is released. If the interval for the QH is 1, the item moves to
  91123. + * periodic_sched_ready because it must be rescheduled for the next
  91124. + * frame. Otherwise, the item moves to periodic_sched_inactive.
  91125. + */
  91126. + dwc_list_link_t periodic_sched_queued;
  91127. +
  91128. + /**
  91129. + * Total bandwidth claimed so far for periodic transfers. This value
  91130. + * is in microseconds per (micro)frame. The assumption is that all
  91131. + * periodic transfers may occur in the same (micro)frame.
  91132. + */
  91133. + uint16_t periodic_usecs;
  91134. +
  91135. + /**
  91136. + * Total bandwidth claimed so far for all periodic transfers
  91137. + * in a frame.
  91138. + * This will include a mixture of HS and FS transfers.
  91139. + * Units are microseconds per (micro)frame.
  91140. + * We have a budget per frame and have to schedule
  91141. + * transactions accordingly.
  91142. + * Watch out for the fact that things are actually scheduled for the
  91143. + * "next frame".
  91144. + */
  91145. + uint16_t frame_usecs[8];
  91146. +
  91147. +
  91148. + /**
  91149. + * Frame number read from the core at SOF. The value ranges from 0 to
  91150. + * DWC_HFNUM_MAX_FRNUM.
  91151. + */
  91152. + uint16_t frame_number;
  91153. +
  91154. + /**
  91155. + * Count of periodic QHs, if using several eps. For SOF enable/disable.
  91156. + */
  91157. + uint16_t periodic_qh_count;
  91158. +
  91159. + /**
  91160. + * Free host channels in the controller. This is a list of
  91161. + * dwc_hc_t items.
  91162. + */
  91163. + struct hc_list free_hc_list;
  91164. + /**
  91165. + * Number of host channels assigned to periodic transfers. Currently
  91166. + * assuming that there is a dedicated host channel for each periodic
  91167. + * transaction and at least one host channel available for
  91168. + * non-periodic transactions.
  91169. + */
  91170. + int periodic_channels; /* microframe_schedule==0 */
  91171. +
  91172. + /**
  91173. + * Number of host channels assigned to non-periodic transfers.
  91174. + */
  91175. + int non_periodic_channels; /* microframe_schedule==0 */
  91176. +
  91177. + /**
  91178. + * Number of host channels assigned to non-periodic transfers.
  91179. + */
  91180. + int available_host_channels;
  91181. +
  91182. + /**
  91183. + * Array of pointers to the host channel descriptors. Allows accessing
  91184. + * a host channel descriptor given the host channel number. This is
  91185. + * useful in interrupt handlers.
  91186. + */
  91187. + struct dwc_hc *hc_ptr_array[MAX_EPS_CHANNELS];
  91188. +
  91189. + /**
  91190. + * Buffer to use for any data received during the status phase of a
  91191. + * control transfer. Normally no data is transferred during the status
  91192. + * phase. This buffer is used as a bit bucket.
  91193. + */
  91194. + uint8_t *status_buf;
  91195. +
  91196. + /**
  91197. + * DMA address for status_buf.
  91198. + */
  91199. + dma_addr_t status_buf_dma;
  91200. +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
  91201. +
  91202. + /**
  91203. + * Connection timer. An OTG host must display a message if the device
  91204. + * does not connect. Started when the VBus power is turned on via
  91205. + * sysfs attribute "buspower".
  91206. + */
  91207. + dwc_timer_t *conn_timer;
  91208. +
  91209. + /* Tasket to do a reset */
  91210. + dwc_tasklet_t *reset_tasklet;
  91211. +
  91212. + dwc_tasklet_t *completion_tasklet;
  91213. + struct urb_list completed_urb_list;
  91214. +
  91215. + /* */
  91216. + dwc_spinlock_t *lock;
  91217. + dwc_spinlock_t *channel_lock;
  91218. + /**
  91219. + * Private data that could be used by OS wrapper.
  91220. + */
  91221. + void *priv;
  91222. +
  91223. + uint8_t otg_port;
  91224. +
  91225. + /** Frame List */
  91226. + uint32_t *frame_list;
  91227. +
  91228. + /** Hub - Port assignment */
  91229. + int hub_port[128];
  91230. +#ifdef FIQ_DEBUG
  91231. + int hub_port_alloc[2048];
  91232. +#endif
  91233. +
  91234. + /** Frame List DMA address */
  91235. + dma_addr_t frame_list_dma;
  91236. +
  91237. + struct fiq_stack *fiq_stack;
  91238. + struct fiq_state *fiq_state;
  91239. +
  91240. + /** Virtual address for split transaction DMA bounce buffers */
  91241. + struct fiq_dma_blob *fiq_dmab;
  91242. +
  91243. +#ifdef DEBUG
  91244. + uint32_t frrem_samples;
  91245. + uint64_t frrem_accum;
  91246. +
  91247. + uint32_t hfnum_7_samples_a;
  91248. + uint64_t hfnum_7_frrem_accum_a;
  91249. + uint32_t hfnum_0_samples_a;
  91250. + uint64_t hfnum_0_frrem_accum_a;
  91251. + uint32_t hfnum_other_samples_a;
  91252. + uint64_t hfnum_other_frrem_accum_a;
  91253. +
  91254. + uint32_t hfnum_7_samples_b;
  91255. + uint64_t hfnum_7_frrem_accum_b;
  91256. + uint32_t hfnum_0_samples_b;
  91257. + uint64_t hfnum_0_frrem_accum_b;
  91258. + uint32_t hfnum_other_samples_b;
  91259. + uint64_t hfnum_other_frrem_accum_b;
  91260. +#endif
  91261. +};
  91262. +
  91263. +/** @name Transaction Execution Functions */
  91264. +/** @{ */
  91265. +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t
  91266. + * hcd);
  91267. +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  91268. + dwc_otg_transaction_type_e tr_type);
  91269. +
  91270. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
  91271. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
  91272. +
  91273. +extern int fiq_fsm_queue_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
  91274. +extern int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh);
  91275. +extern void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num);
  91276. +
  91277. +/** @} */
  91278. +
  91279. +/** @name Interrupt Handler Functions */
  91280. +/** @{ */
  91281. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  91282. +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  91283. +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *
  91284. + dwc_otg_hcd);
  91285. +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *
  91286. + dwc_otg_hcd);
  91287. +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *
  91288. + dwc_otg_hcd);
  91289. +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *
  91290. + dwc_otg_hcd);
  91291. +extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  91292. +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *
  91293. + dwc_otg_hcd);
  91294. +extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  91295. +extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  91296. +extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd,
  91297. + uint32_t num);
  91298. +extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  91299. +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *
  91300. + dwc_otg_hcd);
  91301. +/** @} */
  91302. +
  91303. +/** @name Schedule Queue Functions */
  91304. +/** @{ */
  91305. +
  91306. +/* Implemented in dwc_otg_hcd_queue.c */
  91307. +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  91308. + dwc_otg_hcd_urb_t * urb, int atomic_alloc);
  91309. +extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  91310. +extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  91311. +extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  91312. +extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  91313. + int sched_csplit);
  91314. +
  91315. +/** Remove and free a QH */
  91316. +static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t * hcd,
  91317. + dwc_otg_qh_t * qh)
  91318. +{
  91319. + dwc_irqflags_t flags;
  91320. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  91321. + dwc_otg_hcd_qh_remove(hcd, qh);
  91322. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  91323. + dwc_otg_hcd_qh_free(hcd, qh);
  91324. +}
  91325. +
  91326. +/** Allocates memory for a QH structure.
  91327. + * @return Returns the memory allocate or NULL on error. */
  91328. +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(int atomic_alloc)
  91329. +{
  91330. + if (atomic_alloc)
  91331. + return (dwc_otg_qh_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qh_t));
  91332. + else
  91333. + return (dwc_otg_qh_t *) DWC_ALLOC(sizeof(dwc_otg_qh_t));
  91334. +}
  91335. +
  91336. +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb,
  91337. + int atomic_alloc);
  91338. +extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb);
  91339. +extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd, dwc_otg_hcd_t * dwc_otg_hcd,
  91340. + dwc_otg_qh_t ** qh, int atomic_alloc);
  91341. +
  91342. +/** Allocates memory for a QTD structure.
  91343. + * @return Returns the memory allocate or NULL on error. */
  91344. +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(int atomic_alloc)
  91345. +{
  91346. + if (atomic_alloc)
  91347. + return (dwc_otg_qtd_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qtd_t));
  91348. + else
  91349. + return (dwc_otg_qtd_t *) DWC_ALLOC(sizeof(dwc_otg_qtd_t));
  91350. +}
  91351. +
  91352. +/** Frees the memory for a QTD structure. QTD should already be removed from
  91353. + * list.
  91354. + * @param qtd QTD to free.*/
  91355. +static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t * qtd)
  91356. +{
  91357. + DWC_FREE(qtd);
  91358. +}
  91359. +
  91360. +/** Removes a QTD from list.
  91361. + * @param hcd HCD instance.
  91362. + * @param qtd QTD to remove from list.
  91363. + * @param qh QTD belongs to.
  91364. + */
  91365. +static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t * hcd,
  91366. + dwc_otg_qtd_t * qtd,
  91367. + dwc_otg_qh_t * qh)
  91368. +{
  91369. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  91370. +}
  91371. +
  91372. +/** Remove and free a QTD
  91373. + * Need to disable IRQ and hold hcd lock while calling this function out of
  91374. + * interrupt servicing chain */
  91375. +static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t * hcd,
  91376. + dwc_otg_qtd_t * qtd,
  91377. + dwc_otg_qh_t * qh)
  91378. +{
  91379. + dwc_otg_hcd_qtd_remove(hcd, qtd, qh);
  91380. + dwc_otg_hcd_qtd_free(qtd);
  91381. +}
  91382. +
  91383. +/** @} */
  91384. +
  91385. +/** @name Descriptor DMA Supporting Functions */
  91386. +/** @{ */
  91387. +
  91388. +extern void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  91389. +extern void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  91390. + dwc_hc_t * hc,
  91391. + dwc_otg_hc_regs_t * hc_regs,
  91392. + dwc_otg_halt_status_e halt_status);
  91393. +
  91394. +extern int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  91395. +extern void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  91396. +
  91397. +/** @} */
  91398. +
  91399. +/** @name Internal Functions */
  91400. +/** @{ */
  91401. +dwc_otg_qh_t *dwc_urb_to_qh(dwc_otg_hcd_urb_t * urb);
  91402. +/** @} */
  91403. +
  91404. +#ifdef CONFIG_USB_DWC_OTG_LPM
  91405. +extern int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd,
  91406. + uint8_t devaddr);
  91407. +extern void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd);
  91408. +#endif
  91409. +
  91410. +/** Gets the QH that contains the list_head */
  91411. +#define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
  91412. +
  91413. +/** Gets the QTD that contains the list_head */
  91414. +#define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
  91415. +
  91416. +/** Check if QH is non-periodic */
  91417. +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == UE_BULK) || \
  91418. + (_qh_ptr_->ep_type == UE_CONTROL))
  91419. +
  91420. +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
  91421. +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
  91422. +
  91423. +/** Packet size for any kind of endpoint descriptor */
  91424. +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
  91425. +
  91426. +/**
  91427. + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
  91428. + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
  91429. + * frame number when the max frame number is reached.
  91430. + */
  91431. +static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
  91432. +{
  91433. + return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
  91434. + (DWC_HFNUM_MAX_FRNUM >> 1);
  91435. +}
  91436. +
  91437. +/**
  91438. + * Returns true if _frame1 is greater than _frame2. The comparison is done
  91439. + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
  91440. + * number when the max frame number is reached.
  91441. + */
  91442. +static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
  91443. +{
  91444. + return (frame1 != frame2) &&
  91445. + (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
  91446. + (DWC_HFNUM_MAX_FRNUM >> 1));
  91447. +}
  91448. +
  91449. +/**
  91450. + * Increments _frame by the amount specified by _inc. The addition is done
  91451. + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
  91452. + */
  91453. +static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
  91454. +{
  91455. + return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
  91456. +}
  91457. +
  91458. +static inline uint16_t dwc_full_frame_num(uint16_t frame)
  91459. +{
  91460. + return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
  91461. +}
  91462. +
  91463. +static inline uint16_t dwc_micro_frame_num(uint16_t frame)
  91464. +{
  91465. + return frame & 0x7;
  91466. +}
  91467. +
  91468. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  91469. + dwc_otg_hc_regs_t * hc_regs,
  91470. + dwc_otg_qtd_t * qtd);
  91471. +
  91472. +#ifdef DEBUG
  91473. +/**
  91474. + * Macro to sample the remaining PHY clocks left in the current frame. This
  91475. + * may be used during debugging to determine the average time it takes to
  91476. + * execute sections of code. There are two possible sample points, "a" and
  91477. + * "b", so the _letter argument must be one of these values.
  91478. + *
  91479. + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
  91480. + * example, "cat /sys/devices/lm0/hcd_frrem".
  91481. + */
  91482. +#define dwc_sample_frrem(_hcd, _qh, _letter) \
  91483. +{ \
  91484. + hfnum_data_t hfnum; \
  91485. + dwc_otg_qtd_t *qtd; \
  91486. + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
  91487. + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
  91488. + hfnum.d32 = DWC_READ_REG32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
  91489. + switch (hfnum.b.frnum & 0x7) { \
  91490. + case 7: \
  91491. + _hcd->hfnum_7_samples_##_letter++; \
  91492. + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
  91493. + break; \
  91494. + case 0: \
  91495. + _hcd->hfnum_0_samples_##_letter++; \
  91496. + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
  91497. + break; \
  91498. + default: \
  91499. + _hcd->hfnum_other_samples_##_letter++; \
  91500. + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
  91501. + break; \
  91502. + } \
  91503. + } \
  91504. +}
  91505. +#else
  91506. +#define dwc_sample_frrem(_hcd, _qh, _letter)
  91507. +#endif
  91508. +#endif
  91509. +#endif /* DWC_DEVICE_ONLY */
  91510. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h
  91511. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 1970-01-01 01:00:00.000000000 +0100
  91512. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 2015-02-09 04:40:29.000000000 +0100
  91513. @@ -0,0 +1,417 @@
  91514. +/* ==========================================================================
  91515. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_if.h $
  91516. + * $Revision: #12 $
  91517. + * $Date: 2011/10/26 $
  91518. + * $Change: 1873028 $
  91519. + *
  91520. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  91521. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  91522. + * otherwise expressly agreed to in writing between Synopsys and you.
  91523. + *
  91524. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  91525. + * any End User Software License Agreement or Agreement for Licensed Product
  91526. + * with Synopsys or any supplement thereto. You are permitted to use and
  91527. + * redistribute this Software in source and binary forms, with or without
  91528. + * modification, provided that redistributions of source code must retain this
  91529. + * notice. You may not view, use, disclose, copy or distribute this file or
  91530. + * any information contained herein except pursuant to this license grant from
  91531. + * Synopsys. If you do not agree with this notice, including the disclaimer
  91532. + * below, then you are not authorized to use the Software.
  91533. + *
  91534. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  91535. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  91536. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  91537. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  91538. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  91539. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  91540. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  91541. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  91542. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  91543. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  91544. + * DAMAGE.
  91545. + * ========================================================================== */
  91546. +#ifndef DWC_DEVICE_ONLY
  91547. +#ifndef __DWC_HCD_IF_H__
  91548. +#define __DWC_HCD_IF_H__
  91549. +
  91550. +#include "dwc_otg_core_if.h"
  91551. +
  91552. +/** @file
  91553. + * This file defines DWC_OTG HCD Core API.
  91554. + */
  91555. +
  91556. +struct dwc_otg_hcd;
  91557. +typedef struct dwc_otg_hcd dwc_otg_hcd_t;
  91558. +
  91559. +struct dwc_otg_hcd_urb;
  91560. +typedef struct dwc_otg_hcd_urb dwc_otg_hcd_urb_t;
  91561. +
  91562. +/** @name HCD Function Driver Callbacks */
  91563. +/** @{ */
  91564. +
  91565. +/** This function is called whenever core switches to host mode. */
  91566. +typedef int (*dwc_otg_hcd_start_cb_t) (dwc_otg_hcd_t * hcd);
  91567. +
  91568. +/** This function is called when device has been disconnected */
  91569. +typedef int (*dwc_otg_hcd_disconnect_cb_t) (dwc_otg_hcd_t * hcd);
  91570. +
  91571. +/** Wrapper provides this function to HCD to core, so it can get hub information to which device is connected */
  91572. +typedef int (*dwc_otg_hcd_hub_info_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  91573. + void *urb_handle,
  91574. + uint32_t * hub_addr,
  91575. + uint32_t * port_addr);
  91576. +/** Via this function HCD core gets device speed */
  91577. +typedef int (*dwc_otg_hcd_speed_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  91578. + void *urb_handle);
  91579. +
  91580. +/** This function is called when urb is completed */
  91581. +typedef int (*dwc_otg_hcd_complete_urb_cb_t) (dwc_otg_hcd_t * hcd,
  91582. + void *urb_handle,
  91583. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  91584. + int32_t status);
  91585. +
  91586. +/** Via this function HCD core gets b_hnp_enable parameter */
  91587. +typedef int (*dwc_otg_hcd_get_b_hnp_enable) (dwc_otg_hcd_t * hcd);
  91588. +
  91589. +struct dwc_otg_hcd_function_ops {
  91590. + dwc_otg_hcd_start_cb_t start;
  91591. + dwc_otg_hcd_disconnect_cb_t disconnect;
  91592. + dwc_otg_hcd_hub_info_from_urb_cb_t hub_info;
  91593. + dwc_otg_hcd_speed_from_urb_cb_t speed;
  91594. + dwc_otg_hcd_complete_urb_cb_t complete;
  91595. + dwc_otg_hcd_get_b_hnp_enable get_b_hnp_enable;
  91596. +};
  91597. +/** @} */
  91598. +
  91599. +/** @name HCD Core API */
  91600. +/** @{ */
  91601. +/** This function allocates dwc_otg_hcd structure and returns pointer on it. */
  91602. +extern dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void);
  91603. +
  91604. +/** This function should be called to initiate HCD Core.
  91605. + *
  91606. + * @param hcd The HCD
  91607. + * @param core_if The DWC_OTG Core
  91608. + *
  91609. + * Returns -DWC_E_NO_MEMORY if no enough memory.
  91610. + * Returns 0 on success
  91611. + */
  91612. +extern int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if);
  91613. +
  91614. +/** Frees HCD
  91615. + *
  91616. + * @param hcd The HCD
  91617. + */
  91618. +extern void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd);
  91619. +
  91620. +/** This function should be called on every hardware interrupt.
  91621. + *
  91622. + * @param dwc_otg_hcd The HCD
  91623. + *
  91624. + * Returns non zero if interrupt is handled
  91625. + * Return 0 if interrupt is not handled
  91626. + */
  91627. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  91628. +
  91629. +/** This function is used to handle the fast interrupt
  91630. + *
  91631. + */
  91632. +extern void __attribute__ ((naked)) dwc_otg_hcd_handle_fiq(void);
  91633. +
  91634. +/**
  91635. + * Returns private data set by
  91636. + * dwc_otg_hcd_set_priv_data function.
  91637. + *
  91638. + * @param hcd The HCD
  91639. + */
  91640. +extern void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd);
  91641. +
  91642. +/**
  91643. + * Set private data.
  91644. + *
  91645. + * @param hcd The HCD
  91646. + * @param priv_data pointer to be stored in private data
  91647. + */
  91648. +extern void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data);
  91649. +
  91650. +/**
  91651. + * This function initializes the HCD Core.
  91652. + *
  91653. + * @param hcd The HCD
  91654. + * @param fops The Function Driver Operations data structure containing pointers to all callbacks.
  91655. + *
  91656. + * Returns -DWC_E_NO_DEVICE if Core is currently is in device mode.
  91657. + * Returns 0 on success
  91658. + */
  91659. +extern int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  91660. + struct dwc_otg_hcd_function_ops *fops);
  91661. +
  91662. +/**
  91663. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  91664. + * stopped.
  91665. + *
  91666. + * @param hcd The HCD
  91667. + */
  91668. +extern void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd);
  91669. +
  91670. +/**
  91671. + * Handles hub class-specific requests.
  91672. + *
  91673. + * @param dwc_otg_hcd The HCD
  91674. + * @param typeReq Request Type
  91675. + * @param wValue wValue from control request
  91676. + * @param wIndex wIndex from control request
  91677. + * @param buf data buffer
  91678. + * @param wLength data buffer length
  91679. + *
  91680. + * Returns -DWC_E_INVALID if invalid argument is passed
  91681. + * Returns 0 on success
  91682. + */
  91683. +extern int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  91684. + uint16_t typeReq, uint16_t wValue,
  91685. + uint16_t wIndex, uint8_t * buf,
  91686. + uint16_t wLength);
  91687. +
  91688. +/**
  91689. + * Returns otg port number.
  91690. + *
  91691. + * @param hcd The HCD
  91692. + */
  91693. +extern uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd);
  91694. +
  91695. +/**
  91696. + * Returns OTG version - either 1.3 or 2.0.
  91697. + *
  91698. + * @param core_if The core_if structure pointer
  91699. + */
  91700. +extern uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if);
  91701. +
  91702. +/**
  91703. + * Returns 1 if currently core is acting as B host, and 0 otherwise.
  91704. + *
  91705. + * @param hcd The HCD
  91706. + */
  91707. +extern uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd);
  91708. +
  91709. +/**
  91710. + * Returns current frame number.
  91711. + *
  91712. + * @param hcd The HCD
  91713. + */
  91714. +extern int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * hcd);
  91715. +
  91716. +/**
  91717. + * Dumps hcd state.
  91718. + *
  91719. + * @param hcd The HCD
  91720. + */
  91721. +extern void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd);
  91722. +
  91723. +/**
  91724. + * Dump the average frame remaining at SOF. This can be used to
  91725. + * determine average interrupt latency. Frame remaining is also shown for
  91726. + * start transfer and two additional sample points.
  91727. + * Currently this function is not implemented.
  91728. + *
  91729. + * @param hcd The HCD
  91730. + */
  91731. +extern void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd);
  91732. +
  91733. +/**
  91734. + * Sends LPM transaction to the local device.
  91735. + *
  91736. + * @param hcd The HCD
  91737. + * @param devaddr Device Address
  91738. + * @param hird Host initiated resume duration
  91739. + * @param bRemoteWake Value of bRemoteWake field in LPM transaction
  91740. + *
  91741. + * Returns negative value if sending LPM transaction was not succeeded.
  91742. + * Returns 0 on success.
  91743. + */
  91744. +extern int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr,
  91745. + uint8_t hird, uint8_t bRemoteWake);
  91746. +
  91747. +/* URB interface */
  91748. +
  91749. +/**
  91750. + * Allocates memory for dwc_otg_hcd_urb structure.
  91751. + * Allocated memory should be freed by call of DWC_FREE.
  91752. + *
  91753. + * @param hcd The HCD
  91754. + * @param iso_desc_count Count of ISOC descriptors
  91755. + * @param atomic_alloc Specefies whether to perform atomic allocation.
  91756. + */
  91757. +extern dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  91758. + int iso_desc_count,
  91759. + int atomic_alloc);
  91760. +
  91761. +/**
  91762. + * Set pipe information in URB.
  91763. + *
  91764. + * @param hcd_urb DWC_OTG URB
  91765. + * @param devaddr Device Address
  91766. + * @param ep_num Endpoint Number
  91767. + * @param ep_type Endpoint Type
  91768. + * @param ep_dir Endpoint Direction
  91769. + * @param mps Max Packet Size
  91770. + */
  91771. +extern void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * hcd_urb,
  91772. + uint8_t devaddr, uint8_t ep_num,
  91773. + uint8_t ep_type, uint8_t ep_dir,
  91774. + uint16_t mps);
  91775. +
  91776. +/* Transfer flags */
  91777. +#define URB_GIVEBACK_ASAP 0x1
  91778. +#define URB_SEND_ZERO_PACKET 0x2
  91779. +
  91780. +/**
  91781. + * Sets dwc_otg_hcd_urb parameters.
  91782. + *
  91783. + * @param urb DWC_OTG URB allocated by dwc_otg_hcd_urb_alloc function.
  91784. + * @param urb_handle Unique handle for request, this will be passed back
  91785. + * to function driver in completion callback.
  91786. + * @param buf The buffer for the data
  91787. + * @param dma The DMA buffer for the data
  91788. + * @param buflen Transfer length
  91789. + * @param sp Buffer for setup data
  91790. + * @param sp_dma DMA address of setup data buffer
  91791. + * @param flags Transfer flags
  91792. + * @param interval Polling interval for interrupt or isochronous transfers.
  91793. + */
  91794. +extern void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * urb,
  91795. + void *urb_handle, void *buf,
  91796. + dwc_dma_t dma, uint32_t buflen, void *sp,
  91797. + dwc_dma_t sp_dma, uint32_t flags,
  91798. + uint16_t interval);
  91799. +
  91800. +/** Gets status from dwc_otg_hcd_urb
  91801. + *
  91802. + * @param dwc_otg_urb DWC_OTG URB
  91803. + */
  91804. +extern uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb);
  91805. +
  91806. +/** Gets actual length from dwc_otg_hcd_urb
  91807. + *
  91808. + * @param dwc_otg_urb DWC_OTG URB
  91809. + */
  91810. +extern uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t *
  91811. + dwc_otg_urb);
  91812. +
  91813. +/** Gets error count from dwc_otg_hcd_urb. Only for ISOC URBs
  91814. + *
  91815. + * @param dwc_otg_urb DWC_OTG URB
  91816. + */
  91817. +extern uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t *
  91818. + dwc_otg_urb);
  91819. +
  91820. +/** Set ISOC descriptor offset and length
  91821. + *
  91822. + * @param dwc_otg_urb DWC_OTG URB
  91823. + * @param desc_num ISOC descriptor number
  91824. + * @param offset Offset from beginig of buffer.
  91825. + * @param length Transaction length
  91826. + */
  91827. +extern void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  91828. + int desc_num, uint32_t offset,
  91829. + uint32_t length);
  91830. +
  91831. +/** Get status of ISOC descriptor, specified by desc_num
  91832. + *
  91833. + * @param dwc_otg_urb DWC_OTG URB
  91834. + * @param desc_num ISOC descriptor number
  91835. + */
  91836. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t *
  91837. + dwc_otg_urb, int desc_num);
  91838. +
  91839. +/** Get actual length of ISOC descriptor, specified by desc_num
  91840. + *
  91841. + * @param dwc_otg_urb DWC_OTG URB
  91842. + * @param desc_num ISOC descriptor number
  91843. + */
  91844. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  91845. + dwc_otg_urb,
  91846. + int desc_num);
  91847. +
  91848. +/** Queue URB. After transfer is completes, the complete callback will be called with the URB status
  91849. + *
  91850. + * @param dwc_otg_hcd The HCD
  91851. + * @param dwc_otg_urb DWC_OTG URB
  91852. + * @param ep_handle Out parameter for returning endpoint handle
  91853. + * @param atomic_alloc Flag to do atomic allocation if needed
  91854. + *
  91855. + * Returns -DWC_E_NO_DEVICE if no device is connected.
  91856. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  91857. + * Returns 0 on success.
  91858. + */
  91859. +extern int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * dwc_otg_hcd,
  91860. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  91861. + void **ep_handle, int atomic_alloc);
  91862. +
  91863. +/** De-queue the specified URB
  91864. + *
  91865. + * @param dwc_otg_hcd The HCD
  91866. + * @param dwc_otg_urb DWC_OTG URB
  91867. + */
  91868. +extern int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * dwc_otg_hcd,
  91869. + dwc_otg_hcd_urb_t * dwc_otg_urb);
  91870. +
  91871. +/** Frees resources in the DWC_otg controller related to a given endpoint.
  91872. + * Any URBs for the endpoint must already be dequeued.
  91873. + *
  91874. + * @param hcd The HCD
  91875. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  91876. + * @param retry Number of retries if there are queued transfers.
  91877. + *
  91878. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  91879. + * Returns 0 on success
  91880. + */
  91881. +extern int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  91882. + int retry);
  91883. +
  91884. +/* Resets the data toggle in qh structure. This function can be called from
  91885. + * usb_clear_halt routine.
  91886. + *
  91887. + * @param hcd The HCD
  91888. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  91889. + *
  91890. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  91891. + * Returns 0 on success
  91892. + */
  91893. +extern int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle);
  91894. +
  91895. +/** Returns 1 if status of specified port is changed and 0 otherwise.
  91896. + *
  91897. + * @param hcd The HCD
  91898. + * @param port Port number
  91899. + */
  91900. +extern int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port);
  91901. +
  91902. +/** Call this function to check if bandwidth was allocated for specified endpoint.
  91903. + * Only for ISOC and INTERRUPT endpoints.
  91904. + *
  91905. + * @param hcd The HCD
  91906. + * @param ep_handle Endpoint handle
  91907. + */
  91908. +extern int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd,
  91909. + void *ep_handle);
  91910. +
  91911. +/** Call this function to check if bandwidth was freed for specified endpoint.
  91912. + *
  91913. + * @param hcd The HCD
  91914. + * @param ep_handle Endpoint handle
  91915. + */
  91916. +extern int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle);
  91917. +
  91918. +/** Returns bandwidth allocated for specified endpoint in microseconds.
  91919. + * Only for ISOC and INTERRUPT endpoints.
  91920. + *
  91921. + * @param hcd The HCD
  91922. + * @param ep_handle Endpoint handle
  91923. + */
  91924. +extern uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd,
  91925. + void *ep_handle);
  91926. +
  91927. +/** @} */
  91928. +
  91929. +#endif /* __DWC_HCD_IF_H__ */
  91930. +#endif /* DWC_DEVICE_ONLY */
  91931. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
  91932. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  91933. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 2015-02-09 04:40:29.000000000 +0100
  91934. @@ -0,0 +1,2719 @@
  91935. +/* ==========================================================================
  91936. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
  91937. + * $Revision: #89 $
  91938. + * $Date: 2011/10/20 $
  91939. + * $Change: 1869487 $
  91940. + *
  91941. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  91942. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  91943. + * otherwise expressly agreed to in writing between Synopsys and you.
  91944. + *
  91945. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  91946. + * any End User Software License Agreement or Agreement for Licensed Product
  91947. + * with Synopsys or any supplement thereto. You are permitted to use and
  91948. + * redistribute this Software in source and binary forms, with or without
  91949. + * modification, provided that redistributions of source code must retain this
  91950. + * notice. You may not view, use, disclose, copy or distribute this file or
  91951. + * any information contained herein except pursuant to this license grant from
  91952. + * Synopsys. If you do not agree with this notice, including the disclaimer
  91953. + * below, then you are not authorized to use the Software.
  91954. + *
  91955. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  91956. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  91957. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  91958. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  91959. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  91960. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  91961. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  91962. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  91963. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  91964. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  91965. + * DAMAGE.
  91966. + * ========================================================================== */
  91967. +#ifndef DWC_DEVICE_ONLY
  91968. +
  91969. +#include "dwc_otg_hcd.h"
  91970. +#include "dwc_otg_regs.h"
  91971. +
  91972. +#include <linux/jiffies.h>
  91973. +#include <mach/hardware.h>
  91974. +#include <asm/fiq.h>
  91975. +
  91976. +
  91977. +extern bool microframe_schedule;
  91978. +
  91979. +/** @file
  91980. + * This file contains the implementation of the HCD Interrupt handlers.
  91981. + */
  91982. +
  91983. +int fiq_done, int_done;
  91984. +
  91985. +#ifdef FIQ_DEBUG
  91986. +char buffer[1000*16];
  91987. +int wptr;
  91988. +void notrace _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...)
  91989. +{
  91990. + FIQDBG_T dbg_lvl_req = FIQDBG_PORTHUB;
  91991. + va_list args;
  91992. + char text[17];
  91993. + hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
  91994. +
  91995. + if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
  91996. + {
  91997. + local_fiq_disable();
  91998. + snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
  91999. + va_start(args, fmt);
  92000. + vsnprintf(text+8, 9, fmt, args);
  92001. + va_end(args);
  92002. +
  92003. + memcpy(buffer + wptr, text, 16);
  92004. + wptr = (wptr + 16) % sizeof(buffer);
  92005. + local_fiq_enable();
  92006. + }
  92007. +}
  92008. +#endif
  92009. +
  92010. +/** This function handles interrupts for the HCD. */
  92011. +int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  92012. +{
  92013. + int retval = 0;
  92014. + static int last_time;
  92015. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  92016. + gintsts_data_t gintsts;
  92017. + gintmsk_data_t gintmsk;
  92018. + hfnum_data_t hfnum;
  92019. + haintmsk_data_t haintmsk;
  92020. +
  92021. +#ifdef DEBUG
  92022. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  92023. +
  92024. +#endif
  92025. +
  92026. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  92027. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  92028. +
  92029. + /* Exit from ISR if core is hibernated */
  92030. + if (core_if->hibernation_suspend == 1) {
  92031. + goto exit_handler_routine;
  92032. + }
  92033. + DWC_SPINLOCK(dwc_otg_hcd->lock);
  92034. + /* Check if HOST Mode */
  92035. + if (dwc_otg_is_host_mode(core_if)) {
  92036. + if (fiq_enable) {
  92037. + local_fiq_disable();
  92038. + fiq_fsm_spin_lock(&dwc_otg_hcd->fiq_state->lock);
  92039. + /* Pull in from the FIQ's disabled mask */
  92040. + gintmsk.d32 = gintmsk.d32 | ~(dwc_otg_hcd->fiq_state->gintmsk_saved.d32);
  92041. + dwc_otg_hcd->fiq_state->gintmsk_saved.d32 = ~0;
  92042. + }
  92043. +
  92044. + if (fiq_fsm_enable && ( 0x0000FFFF & ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint))) {
  92045. + gintsts.b.hcintr = 1;
  92046. + }
  92047. +
  92048. + /* Danger will robinson: fake a SOF if necessary */
  92049. + if (fiq_fsm_enable && (dwc_otg_hcd->fiq_state->gintmsk_saved.b.sofintr == 1)) {
  92050. + gintsts.b.sofintr = 1;
  92051. + }
  92052. + gintsts.d32 &= gintmsk.d32;
  92053. +
  92054. + if (fiq_enable) {
  92055. + fiq_fsm_spin_unlock(&dwc_otg_hcd->fiq_state->lock);
  92056. + local_fiq_enable();
  92057. + }
  92058. +
  92059. + if (!gintsts.d32) {
  92060. + goto exit_handler_routine;
  92061. + }
  92062. +
  92063. +#ifdef DEBUG
  92064. + // We should be OK doing this because the common interrupts should already have been serviced
  92065. + /* Don't print debug message in the interrupt handler on SOF */
  92066. +#ifndef DEBUG_SOF
  92067. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  92068. +#endif
  92069. + DWC_DEBUGPL(DBG_HCDI, "\n");
  92070. +#endif
  92071. +
  92072. +#ifdef DEBUG
  92073. +#ifndef DEBUG_SOF
  92074. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  92075. +#endif
  92076. + DWC_DEBUGPL(DBG_HCDI,
  92077. + "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x core_if=%p\n",
  92078. + gintsts.d32, core_if);
  92079. +#endif
  92080. + hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
  92081. + if (gintsts.b.sofintr) {
  92082. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  92083. + }
  92084. +
  92085. + if (gintsts.b.rxstsqlvl) {
  92086. + retval |=
  92087. + dwc_otg_hcd_handle_rx_status_q_level_intr
  92088. + (dwc_otg_hcd);
  92089. + }
  92090. + if (gintsts.b.nptxfempty) {
  92091. + retval |=
  92092. + dwc_otg_hcd_handle_np_tx_fifo_empty_intr
  92093. + (dwc_otg_hcd);
  92094. + }
  92095. + if (gintsts.b.i2cintr) {
  92096. + /** @todo Implement i2cintr handler. */
  92097. + }
  92098. + if (gintsts.b.portintr) {
  92099. +
  92100. + gintmsk_data_t gintmsk = { .b.portintr = 1};
  92101. + retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
  92102. + if (fiq_enable) {
  92103. + local_fiq_disable();
  92104. + fiq_fsm_spin_lock(&dwc_otg_hcd->fiq_state->lock);
  92105. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  92106. + fiq_fsm_spin_unlock(&dwc_otg_hcd->fiq_state->lock);
  92107. + local_fiq_enable();
  92108. + } else {
  92109. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  92110. + }
  92111. + }
  92112. + if (gintsts.b.hcintr) {
  92113. + retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
  92114. + }
  92115. + if (gintsts.b.ptxfempty) {
  92116. + retval |=
  92117. + dwc_otg_hcd_handle_perio_tx_fifo_empty_intr
  92118. + (dwc_otg_hcd);
  92119. + }
  92120. +#ifdef DEBUG
  92121. +#ifndef DEBUG_SOF
  92122. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  92123. +#endif
  92124. + {
  92125. + DWC_DEBUGPL(DBG_HCDI,
  92126. + "DWC OTG HCD Finished Servicing Interrupts\n");
  92127. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
  92128. + DWC_READ_REG32(&global_regs->gintsts));
  92129. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
  92130. + DWC_READ_REG32(&global_regs->gintmsk));
  92131. + }
  92132. +#endif
  92133. +
  92134. +#ifdef DEBUG
  92135. +#ifndef DEBUG_SOF
  92136. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  92137. +#endif
  92138. + DWC_DEBUGPL(DBG_HCDI, "\n");
  92139. +#endif
  92140. +
  92141. + }
  92142. +
  92143. +exit_handler_routine:
  92144. + if (fiq_enable) {
  92145. + gintmsk_data_t gintmsk_new;
  92146. + haintmsk_data_t haintmsk_new;
  92147. + local_fiq_disable();
  92148. + fiq_fsm_spin_lock(&dwc_otg_hcd->fiq_state->lock);
  92149. + gintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->gintmsk_saved.d32;
  92150. + if(fiq_fsm_enable)
  92151. + haintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->haintmsk_saved.d32;
  92152. + else
  92153. + haintmsk_new.d32 = 0x0000FFFF;
  92154. +
  92155. + /* The FIQ could have sneaked another interrupt in. If so, don't clear MPHI */
  92156. + if ((gintmsk_new.d32 == ~0) && (haintmsk_new.d32 == 0x0000FFFF)) {
  92157. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.intstat, (1<<16));
  92158. + if (dwc_otg_hcd->fiq_state->mphi_int_count >= 50) {
  92159. + fiq_print(FIQDBG_INT, dwc_otg_hcd->fiq_state, "MPHI CLR");
  92160. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, ((1<<31) + (1<<16)));
  92161. + while (!(DWC_READ_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & (1 << 17)))
  92162. + ;
  92163. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, (1<<31));
  92164. + dwc_otg_hcd->fiq_state->mphi_int_count = 0;
  92165. + }
  92166. + int_done++;
  92167. + }
  92168. + haintmsk.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  92169. + /* Re-enable interrupts that the FIQ masked (first time round) */
  92170. + FIQ_WRITE(dwc_otg_hcd->fiq_state->dwc_regs_base + GINTMSK, gintmsk.d32);
  92171. + fiq_fsm_spin_unlock(&dwc_otg_hcd->fiq_state->lock);
  92172. + local_fiq_enable();
  92173. +
  92174. + if ((jiffies / HZ) > last_time) {
  92175. + //dwc_otg_qh_t *qh;
  92176. + //dwc_list_link_t *cur;
  92177. + /* Once a second output the fiq and irq numbers, useful for debug */
  92178. + last_time = jiffies / HZ;
  92179. + // DWC_WARN("np_kick=%d AHC=%d sched_frame=%d cur_frame=%d int_done=%d fiq_done=%d",
  92180. + // dwc_otg_hcd->fiq_state->kick_np_queues, dwc_otg_hcd->available_host_channels,
  92181. + // dwc_otg_hcd->fiq_state->next_sched_frame, hfnum.b.frnum, int_done, dwc_otg_hcd->fiq_state->fiq_done);
  92182. + //printk(KERN_WARNING "Periodic queues:\n");
  92183. + }
  92184. + }
  92185. +
  92186. + DWC_SPINUNLOCK(dwc_otg_hcd->lock);
  92187. + return retval;
  92188. +}
  92189. +
  92190. +#ifdef DWC_TRACK_MISSED_SOFS
  92191. +
  92192. +#warning Compiling code to track missed SOFs
  92193. +#define FRAME_NUM_ARRAY_SIZE 1000
  92194. +/**
  92195. + * This function is for debug only.
  92196. + */
  92197. +static inline void track_missed_sofs(uint16_t curr_frame_number)
  92198. +{
  92199. + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
  92200. + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
  92201. + static int frame_num_idx = 0;
  92202. + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
  92203. + static int dumped_frame_num_array = 0;
  92204. +
  92205. + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
  92206. + if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) !=
  92207. + curr_frame_number) {
  92208. + frame_num_array[frame_num_idx] = curr_frame_number;
  92209. + last_frame_num_array[frame_num_idx++] = last_frame_num;
  92210. + }
  92211. + } else if (!dumped_frame_num_array) {
  92212. + int i;
  92213. + DWC_PRINTF("Frame Last Frame\n");
  92214. + DWC_PRINTF("----- ----------\n");
  92215. + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
  92216. + DWC_PRINTF("0x%04x 0x%04x\n",
  92217. + frame_num_array[i], last_frame_num_array[i]);
  92218. + }
  92219. + dumped_frame_num_array = 1;
  92220. + }
  92221. + last_frame_num = curr_frame_number;
  92222. +}
  92223. +#endif
  92224. +
  92225. +/**
  92226. + * Handles the start-of-frame interrupt in host mode. Non-periodic
  92227. + * transactions may be queued to the DWC_otg controller for the current
  92228. + * (micro)frame. Periodic transactions may be queued to the controller for the
  92229. + * next (micro)frame.
  92230. + */
  92231. +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
  92232. +{
  92233. + hfnum_data_t hfnum;
  92234. + gintsts_data_t gintsts = { .d32 = 0 };
  92235. + dwc_list_link_t *qh_entry;
  92236. + dwc_otg_qh_t *qh;
  92237. + dwc_otg_transaction_type_e tr_type;
  92238. + int did_something = 0;
  92239. + int32_t next_sched_frame = -1;
  92240. +
  92241. + hfnum.d32 =
  92242. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  92243. +
  92244. +#ifdef DEBUG_SOF
  92245. + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
  92246. +#endif
  92247. + hcd->frame_number = hfnum.b.frnum;
  92248. +
  92249. +#ifdef DEBUG
  92250. + hcd->frrem_accum += hfnum.b.frrem;
  92251. + hcd->frrem_samples++;
  92252. +#endif
  92253. +
  92254. +#ifdef DWC_TRACK_MISSED_SOFS
  92255. + track_missed_sofs(hcd->frame_number);
  92256. +#endif
  92257. + /* Determine whether any periodic QHs should be executed. */
  92258. + qh_entry = DWC_LIST_FIRST(&hcd->periodic_sched_inactive);
  92259. + while (qh_entry != &hcd->periodic_sched_inactive) {
  92260. + qh = DWC_LIST_ENTRY(qh_entry, dwc_otg_qh_t, qh_list_entry);
  92261. + qh_entry = qh_entry->next;
  92262. + if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
  92263. +
  92264. + /*
  92265. + * Move QH to the ready list to be executed next
  92266. + * (micro)frame.
  92267. + */
  92268. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  92269. + &qh->qh_list_entry);
  92270. +
  92271. + did_something = 1;
  92272. + }
  92273. + else
  92274. + {
  92275. + if(next_sched_frame < 0 || dwc_frame_num_le(qh->sched_frame, next_sched_frame))
  92276. + {
  92277. + next_sched_frame = qh->sched_frame;
  92278. + }
  92279. + }
  92280. + }
  92281. + if (fiq_enable)
  92282. + hcd->fiq_state->next_sched_frame = next_sched_frame;
  92283. +
  92284. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  92285. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  92286. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  92287. + did_something = 1;
  92288. + }
  92289. +
  92290. + /* Clear interrupt - but do not trample on the FIQ sof */
  92291. + if (!fiq_fsm_enable) {
  92292. + gintsts.b.sofintr = 1;
  92293. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
  92294. + }
  92295. + return 1;
  92296. +}
  92297. +
  92298. +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
  92299. + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
  92300. + * memory if the DWC_otg controller is operating in Slave mode. */
  92301. +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  92302. +{
  92303. + host_grxsts_data_t grxsts;
  92304. + dwc_hc_t *hc = NULL;
  92305. +
  92306. + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
  92307. +
  92308. + grxsts.d32 =
  92309. + DWC_READ_REG32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
  92310. +
  92311. + hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
  92312. + if (!hc) {
  92313. + DWC_ERROR("Unable to get corresponding channel\n");
  92314. + return 0;
  92315. + }
  92316. +
  92317. + /* Packet Status */
  92318. + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
  92319. + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
  92320. + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid,
  92321. + hc->data_pid_start);
  92322. + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
  92323. +
  92324. + switch (grxsts.b.pktsts) {
  92325. + case DWC_GRXSTS_PKTSTS_IN:
  92326. + /* Read the data into the host buffer. */
  92327. + if (grxsts.b.bcnt > 0) {
  92328. + dwc_otg_read_packet(dwc_otg_hcd->core_if,
  92329. + hc->xfer_buff, grxsts.b.bcnt);
  92330. +
  92331. + /* Update the HC fields for the next packet received. */
  92332. + hc->xfer_count += grxsts.b.bcnt;
  92333. + hc->xfer_buff += grxsts.b.bcnt;
  92334. + }
  92335. +
  92336. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  92337. + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
  92338. + case DWC_GRXSTS_PKTSTS_CH_HALTED:
  92339. + /* Handled in interrupt, just ignore data */
  92340. + break;
  92341. + default:
  92342. + DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n",
  92343. + grxsts.b.pktsts);
  92344. + break;
  92345. + }
  92346. +
  92347. + return 1;
  92348. +}
  92349. +
  92350. +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
  92351. + * data packets may be written to the FIFO for OUT transfers. More requests
  92352. + * may be written to the non-periodic request queue for IN transfers. This
  92353. + * interrupt is enabled only in Slave mode. */
  92354. +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  92355. +{
  92356. + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
  92357. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  92358. + DWC_OTG_TRANSACTION_NON_PERIODIC);
  92359. + return 1;
  92360. +}
  92361. +
  92362. +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
  92363. + * packets may be written to the FIFO for OUT transfers. More requests may be
  92364. + * written to the periodic request queue for IN transfers. This interrupt is
  92365. + * enabled only in Slave mode. */
  92366. +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  92367. +{
  92368. + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
  92369. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  92370. + DWC_OTG_TRANSACTION_PERIODIC);
  92371. + return 1;
  92372. +}
  92373. +
  92374. +/** There are multiple conditions that can cause a port interrupt. This function
  92375. + * determines which interrupt conditions have occurred and handles them
  92376. + * appropriately. */
  92377. +int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  92378. +{
  92379. + int retval = 0;
  92380. + hprt0_data_t hprt0;
  92381. + hprt0_data_t hprt0_modify;
  92382. +
  92383. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  92384. + hprt0_modify.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  92385. +
  92386. + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
  92387. + * GINTSTS */
  92388. +
  92389. + hprt0_modify.b.prtena = 0;
  92390. + hprt0_modify.b.prtconndet = 0;
  92391. + hprt0_modify.b.prtenchng = 0;
  92392. + hprt0_modify.b.prtovrcurrchng = 0;
  92393. +
  92394. + /* Port Connect Detected
  92395. + * Set flag and clear if detected */
  92396. + if (dwc_otg_hcd->core_if->hibernation_suspend == 1) {
  92397. + // Dont modify port status if we are in hibernation state
  92398. + hprt0_modify.b.prtconndet = 1;
  92399. + hprt0_modify.b.prtenchng = 1;
  92400. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  92401. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  92402. + return retval;
  92403. + }
  92404. +
  92405. + if (hprt0.b.prtconndet) {
  92406. + /** @todo - check if steps performed in 'else' block should be perfromed regardles adp */
  92407. + if (dwc_otg_hcd->core_if->adp_enable &&
  92408. + dwc_otg_hcd->core_if->adp.vbuson_timer_started == 1) {
  92409. + DWC_PRINTF("PORT CONNECT DETECTED ----------------\n");
  92410. + DWC_TIMER_CANCEL(dwc_otg_hcd->core_if->adp.vbuson_timer);
  92411. + dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  92412. + /* TODO - check if this is required, as
  92413. + * host initialization was already performed
  92414. + * after initial ADP probing
  92415. + */
  92416. + /*dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  92417. + dwc_otg_core_init(dwc_otg_hcd->core_if);
  92418. + dwc_otg_enable_global_interrupts(dwc_otg_hcd->core_if);
  92419. + cil_hcd_start(dwc_otg_hcd->core_if);*/
  92420. + } else {
  92421. +
  92422. + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
  92423. + "Port Connect Detected--\n", hprt0.d32);
  92424. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  92425. + dwc_otg_hcd->flags.b.port_connect_status = 1;
  92426. + hprt0_modify.b.prtconndet = 1;
  92427. +
  92428. + /* B-Device has connected, Delete the connection timer. */
  92429. + DWC_TIMER_CANCEL(dwc_otg_hcd->conn_timer);
  92430. + }
  92431. + /* The Hub driver asserts a reset when it sees port connect
  92432. + * status change flag */
  92433. + retval |= 1;
  92434. + }
  92435. +
  92436. + /* Port Enable Changed
  92437. + * Clear if detected - Set internal flag if disabled */
  92438. + if (hprt0.b.prtenchng) {
  92439. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  92440. + "Port Enable Changed--\n", hprt0.d32);
  92441. + hprt0_modify.b.prtenchng = 1;
  92442. + if (hprt0.b.prtena == 1) {
  92443. + hfir_data_t hfir;
  92444. + int do_reset = 0;
  92445. + dwc_otg_core_params_t *params =
  92446. + dwc_otg_hcd->core_if->core_params;
  92447. + dwc_otg_core_global_regs_t *global_regs =
  92448. + dwc_otg_hcd->core_if->core_global_regs;
  92449. + dwc_otg_host_if_t *host_if =
  92450. + dwc_otg_hcd->core_if->host_if;
  92451. +
  92452. + /* Every time when port enables calculate
  92453. + * HFIR.FrInterval
  92454. + */
  92455. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  92456. + hfir.b.frint = calc_frame_interval(dwc_otg_hcd->core_if);
  92457. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  92458. +
  92459. + /* Check if we need to adjust the PHY clock speed for
  92460. + * low power and adjust it */
  92461. + if (params->host_support_fs_ls_low_power) {
  92462. + gusbcfg_data_t usbcfg;
  92463. +
  92464. + usbcfg.d32 =
  92465. + DWC_READ_REG32(&global_regs->gusbcfg);
  92466. +
  92467. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED
  92468. + || hprt0.b.prtspd ==
  92469. + DWC_HPRT0_PRTSPD_FULL_SPEED) {
  92470. + /*
  92471. + * Low power
  92472. + */
  92473. + hcfg_data_t hcfg;
  92474. + if (usbcfg.b.phylpwrclksel == 0) {
  92475. + /* Set PHY low power clock select for FS/LS devices */
  92476. + usbcfg.b.phylpwrclksel = 1;
  92477. + DWC_WRITE_REG32
  92478. + (&global_regs->gusbcfg,
  92479. + usbcfg.d32);
  92480. + do_reset = 1;
  92481. + }
  92482. +
  92483. + hcfg.d32 =
  92484. + DWC_READ_REG32
  92485. + (&host_if->host_global_regs->hcfg);
  92486. +
  92487. + if (hprt0.b.prtspd ==
  92488. + DWC_HPRT0_PRTSPD_LOW_SPEED
  92489. + && params->host_ls_low_power_phy_clk
  92490. + ==
  92491. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)
  92492. + {
  92493. + /* 6 MHZ */
  92494. + DWC_DEBUGPL(DBG_CIL,
  92495. + "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
  92496. + if (hcfg.b.fslspclksel !=
  92497. + DWC_HCFG_6_MHZ) {
  92498. + hcfg.b.fslspclksel =
  92499. + DWC_HCFG_6_MHZ;
  92500. + DWC_WRITE_REG32
  92501. + (&host_if->host_global_regs->hcfg,
  92502. + hcfg.d32);
  92503. + do_reset = 1;
  92504. + }
  92505. + } else {
  92506. + /* 48 MHZ */
  92507. + DWC_DEBUGPL(DBG_CIL,
  92508. + "FS_PHY programming HCFG to 48 MHz ()\n");
  92509. + if (hcfg.b.fslspclksel !=
  92510. + DWC_HCFG_48_MHZ) {
  92511. + hcfg.b.fslspclksel =
  92512. + DWC_HCFG_48_MHZ;
  92513. + DWC_WRITE_REG32
  92514. + (&host_if->host_global_regs->hcfg,
  92515. + hcfg.d32);
  92516. + do_reset = 1;
  92517. + }
  92518. + }
  92519. + } else {
  92520. + /*
  92521. + * Not low power
  92522. + */
  92523. + if (usbcfg.b.phylpwrclksel == 1) {
  92524. + usbcfg.b.phylpwrclksel = 0;
  92525. + DWC_WRITE_REG32
  92526. + (&global_regs->gusbcfg,
  92527. + usbcfg.d32);
  92528. + do_reset = 1;
  92529. + }
  92530. + }
  92531. +
  92532. + if (do_reset) {
  92533. + DWC_TASK_SCHEDULE(dwc_otg_hcd->reset_tasklet);
  92534. + }
  92535. + }
  92536. +
  92537. + if (!do_reset) {
  92538. + /* Port has been enabled set the reset change flag */
  92539. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  92540. + }
  92541. + } else {
  92542. + dwc_otg_hcd->flags.b.port_enable_change = 1;
  92543. + }
  92544. + retval |= 1;
  92545. + }
  92546. +
  92547. + /** Overcurrent Change Interrupt */
  92548. + if (hprt0.b.prtovrcurrchng) {
  92549. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  92550. + "Port Overcurrent Changed--\n", hprt0.d32);
  92551. + dwc_otg_hcd->flags.b.port_over_current_change = 1;
  92552. + hprt0_modify.b.prtovrcurrchng = 1;
  92553. + retval |= 1;
  92554. + }
  92555. +
  92556. + /* Clear Port Interrupts */
  92557. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  92558. +
  92559. + return retval;
  92560. +}
  92561. +
  92562. +/** This interrupt indicates that one or more host channels has a pending
  92563. + * interrupt. There are multiple conditions that can cause each host channel
  92564. + * interrupt. This function determines which conditions have occurred for each
  92565. + * host channel interrupt and handles them appropriately. */
  92566. +int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  92567. +{
  92568. + int i;
  92569. + int retval = 0;
  92570. + haint_data_t haint = { .d32 = 0 } ;
  92571. +
  92572. + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
  92573. + * GINTSTS */
  92574. +
  92575. + if (!fiq_fsm_enable)
  92576. + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
  92577. +
  92578. + // Overwrite with saved interrupts from fiq handler
  92579. + if(fiq_fsm_enable)
  92580. + {
  92581. + /* check the mask? */
  92582. + local_fiq_disable();
  92583. + fiq_fsm_spin_lock(&dwc_otg_hcd->fiq_state->lock);
  92584. + haint.b2.chint |= ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint);
  92585. + dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  92586. + fiq_fsm_spin_unlock(&dwc_otg_hcd->fiq_state->lock);
  92587. + local_fiq_enable();
  92588. + }
  92589. +
  92590. + for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
  92591. + if (haint.b2.chint & (1 << i)) {
  92592. + retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
  92593. + }
  92594. + }
  92595. +
  92596. + return retval;
  92597. +}
  92598. +
  92599. +/**
  92600. + * Gets the actual length of a transfer after the transfer halts. _halt_status
  92601. + * holds the reason for the halt.
  92602. + *
  92603. + * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
  92604. + * *short_read is set to 1 upon return if less than the requested
  92605. + * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
  92606. + * return. short_read may also be NULL on entry, in which case it remains
  92607. + * unchanged.
  92608. + */
  92609. +static uint32_t get_actual_xfer_length(dwc_hc_t * hc,
  92610. + dwc_otg_hc_regs_t * hc_regs,
  92611. + dwc_otg_qtd_t * qtd,
  92612. + dwc_otg_halt_status_e halt_status,
  92613. + int *short_read)
  92614. +{
  92615. + hctsiz_data_t hctsiz;
  92616. + uint32_t length;
  92617. +
  92618. + if (short_read != NULL) {
  92619. + *short_read = 0;
  92620. + }
  92621. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  92622. +
  92623. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  92624. + if (hc->ep_is_in) {
  92625. + length = hc->xfer_len - hctsiz.b.xfersize;
  92626. + if (short_read != NULL) {
  92627. + *short_read = (hctsiz.b.xfersize != 0);
  92628. + }
  92629. + } else if (hc->qh->do_split) {
  92630. + //length = split_out_xfersize[hc->hc_num];
  92631. + length = qtd->ssplit_out_xfer_count;
  92632. + } else {
  92633. + length = hc->xfer_len;
  92634. + }
  92635. + } else {
  92636. + /*
  92637. + * Must use the hctsiz.pktcnt field to determine how much data
  92638. + * has been transferred. This field reflects the number of
  92639. + * packets that have been transferred via the USB. This is
  92640. + * always an integral number of packets if the transfer was
  92641. + * halted before its normal completion. (Can't use the
  92642. + * hctsiz.xfersize field because that reflects the number of
  92643. + * bytes transferred via the AHB, not the USB).
  92644. + */
  92645. + length =
  92646. + (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
  92647. + }
  92648. +
  92649. + return length;
  92650. +}
  92651. +
  92652. +/**
  92653. + * Updates the state of the URB after a Transfer Complete interrupt on the
  92654. + * host channel. Updates the actual_length field of the URB based on the
  92655. + * number of bytes transferred via the host channel. Sets the URB status
  92656. + * if the data transfer is finished.
  92657. + *
  92658. + * @return 1 if the data transfer specified by the URB is completely finished,
  92659. + * 0 otherwise.
  92660. + */
  92661. +static int update_urb_state_xfer_comp(dwc_hc_t * hc,
  92662. + dwc_otg_hc_regs_t * hc_regs,
  92663. + dwc_otg_hcd_urb_t * urb,
  92664. + dwc_otg_qtd_t * qtd)
  92665. +{
  92666. + int xfer_done = 0;
  92667. + int short_read = 0;
  92668. +
  92669. + int xfer_length;
  92670. +
  92671. + xfer_length = get_actual_xfer_length(hc, hc_regs, qtd,
  92672. + DWC_OTG_HC_XFER_COMPLETE,
  92673. + &short_read);
  92674. +
  92675. + /* non DWORD-aligned buffer case handling. */
  92676. + if (hc->align_buff && xfer_length && hc->ep_is_in) {
  92677. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  92678. + xfer_length);
  92679. + }
  92680. +
  92681. + urb->actual_length += xfer_length;
  92682. +
  92683. + if (xfer_length && (hc->ep_type == DWC_OTG_EP_TYPE_BULK) &&
  92684. + (urb->flags & URB_SEND_ZERO_PACKET)
  92685. + && (urb->actual_length == urb->length)
  92686. + && !(urb->length % hc->max_packet)) {
  92687. + xfer_done = 0;
  92688. + } else if (short_read || urb->actual_length >= urb->length) {
  92689. + xfer_done = 1;
  92690. + urb->status = 0;
  92691. + }
  92692. +
  92693. +#ifdef DEBUG
  92694. + {
  92695. + hctsiz_data_t hctsiz;
  92696. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  92697. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  92698. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  92699. + hc->hc_num);
  92700. + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
  92701. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n",
  92702. + hctsiz.b.xfersize);
  92703. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  92704. + urb->length);
  92705. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  92706. + urb->actual_length);
  92707. + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
  92708. + short_read, xfer_done);
  92709. + }
  92710. +#endif
  92711. +
  92712. + return xfer_done;
  92713. +}
  92714. +
  92715. +/*
  92716. + * Save the starting data toggle for the next transfer. The data toggle is
  92717. + * saved in the QH for non-control transfers and it's saved in the QTD for
  92718. + * control transfers.
  92719. + */
  92720. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  92721. + dwc_otg_hc_regs_t * hc_regs, dwc_otg_qtd_t * qtd)
  92722. +{
  92723. + hctsiz_data_t hctsiz;
  92724. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  92725. +
  92726. + if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
  92727. + dwc_otg_qh_t *qh = hc->qh;
  92728. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  92729. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  92730. + } else {
  92731. + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
  92732. + }
  92733. + } else {
  92734. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  92735. + qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
  92736. + } else {
  92737. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  92738. + }
  92739. + }
  92740. +}
  92741. +
  92742. +/**
  92743. + * Updates the state of an Isochronous URB when the transfer is stopped for
  92744. + * any reason. The fields of the current entry in the frame descriptor array
  92745. + * are set based on the transfer state and the input _halt_status. Completes
  92746. + * the Isochronous URB if all the URB frames have been completed.
  92747. + *
  92748. + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
  92749. + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
  92750. + */
  92751. +static dwc_otg_halt_status_e
  92752. +update_isoc_urb_state(dwc_otg_hcd_t * hcd,
  92753. + dwc_hc_t * hc,
  92754. + dwc_otg_hc_regs_t * hc_regs,
  92755. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  92756. +{
  92757. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  92758. + dwc_otg_halt_status_e ret_val = halt_status;
  92759. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  92760. +
  92761. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  92762. + switch (halt_status) {
  92763. + case DWC_OTG_HC_XFER_COMPLETE:
  92764. + frame_desc->status = 0;
  92765. + frame_desc->actual_length =
  92766. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  92767. +
  92768. + /* non DWORD-aligned buffer case handling. */
  92769. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  92770. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  92771. + hc->qh->dw_align_buf, frame_desc->actual_length);
  92772. + }
  92773. +
  92774. + break;
  92775. + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
  92776. + urb->error_count++;
  92777. + if (hc->ep_is_in) {
  92778. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  92779. + } else {
  92780. + frame_desc->status = -DWC_E_COMMUNICATION;
  92781. + }
  92782. + frame_desc->actual_length = 0;
  92783. + break;
  92784. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  92785. + urb->error_count++;
  92786. + frame_desc->status = -DWC_E_OVERFLOW;
  92787. + /* Don't need to update actual_length in this case. */
  92788. + break;
  92789. + case DWC_OTG_HC_XFER_XACT_ERR:
  92790. + urb->error_count++;
  92791. + frame_desc->status = -DWC_E_PROTOCOL;
  92792. + frame_desc->actual_length =
  92793. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  92794. +
  92795. + /* non DWORD-aligned buffer case handling. */
  92796. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  92797. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  92798. + hc->qh->dw_align_buf, frame_desc->actual_length);
  92799. + }
  92800. + /* Skip whole frame */
  92801. + if (hc->qh->do_split && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) &&
  92802. + hc->ep_is_in && hcd->core_if->dma_enable) {
  92803. + qtd->complete_split = 0;
  92804. + qtd->isoc_split_offset = 0;
  92805. + }
  92806. +
  92807. + break;
  92808. + default:
  92809. + DWC_ASSERT(1, "Unhandled _halt_status (%d)\n", halt_status);
  92810. + break;
  92811. + }
  92812. + if (++qtd->isoc_frame_index == urb->packet_count) {
  92813. + /*
  92814. + * urb->status is not used for isoc transfers.
  92815. + * The individual frame_desc statuses are used instead.
  92816. + */
  92817. + hcd->fops->complete(hcd, urb->priv, urb, 0);
  92818. + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
  92819. + } else {
  92820. + ret_val = DWC_OTG_HC_XFER_COMPLETE;
  92821. + }
  92822. + return ret_val;
  92823. +}
  92824. +
  92825. +/**
  92826. + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  92827. + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  92828. + * still linked to the QH, the QH is added to the end of the inactive
  92829. + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  92830. + * schedule if no more QTDs are linked to the QH.
  92831. + */
  92832. +static void deactivate_qh(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, int free_qtd)
  92833. +{
  92834. + int continue_split = 0;
  92835. + dwc_otg_qtd_t *qtd;
  92836. +
  92837. + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
  92838. +
  92839. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  92840. +
  92841. + if (qtd->complete_split) {
  92842. + continue_split = 1;
  92843. + } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  92844. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
  92845. + continue_split = 1;
  92846. + }
  92847. +
  92848. + if (free_qtd) {
  92849. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  92850. + continue_split = 0;
  92851. + }
  92852. +
  92853. + qh->channel = NULL;
  92854. + dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
  92855. +}
  92856. +
  92857. +/**
  92858. + * Releases a host channel for use by other transfers. Attempts to select and
  92859. + * queue more transactions since at least one host channel is available.
  92860. + *
  92861. + * @param hcd The HCD state structure.
  92862. + * @param hc The host channel to release.
  92863. + * @param qtd The QTD associated with the host channel. This QTD may be freed
  92864. + * if the transfer is complete or an error has occurred.
  92865. + * @param halt_status Reason the channel is being released. This status
  92866. + * determines the actions taken by this function.
  92867. + */
  92868. +static void release_channel(dwc_otg_hcd_t * hcd,
  92869. + dwc_hc_t * hc,
  92870. + dwc_otg_qtd_t * qtd,
  92871. + dwc_otg_halt_status_e halt_status)
  92872. +{
  92873. + dwc_otg_transaction_type_e tr_type;
  92874. + int free_qtd;
  92875. + dwc_irqflags_t flags;
  92876. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  92877. +
  92878. + int hog_port = 0;
  92879. +
  92880. + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
  92881. + __func__, hc->hc_num, halt_status, hc->xfer_len);
  92882. +
  92883. + if(fiq_fsm_enable && hc->do_split) {
  92884. + if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
  92885. + if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
  92886. + hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
  92887. + hog_port = 0;
  92888. + }
  92889. + }
  92890. + }
  92891. +
  92892. + switch (halt_status) {
  92893. + case DWC_OTG_HC_XFER_URB_COMPLETE:
  92894. + free_qtd = 1;
  92895. + break;
  92896. + case DWC_OTG_HC_XFER_AHB_ERR:
  92897. + case DWC_OTG_HC_XFER_STALL:
  92898. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  92899. + free_qtd = 1;
  92900. + break;
  92901. + case DWC_OTG_HC_XFER_XACT_ERR:
  92902. + if (qtd->error_count >= 3) {
  92903. + DWC_DEBUGPL(DBG_HCDV,
  92904. + " Complete URB with transaction error\n");
  92905. + free_qtd = 1;
  92906. + qtd->urb->status = -DWC_E_PROTOCOL;
  92907. + hcd->fops->complete(hcd, qtd->urb->priv,
  92908. + qtd->urb, -DWC_E_PROTOCOL);
  92909. + } else {
  92910. + free_qtd = 0;
  92911. + }
  92912. + break;
  92913. + case DWC_OTG_HC_XFER_URB_DEQUEUE:
  92914. + /*
  92915. + * The QTD has already been removed and the QH has been
  92916. + * deactivated. Don't want to do anything except release the
  92917. + * host channel and try to queue more transfers.
  92918. + */
  92919. + goto cleanup;
  92920. + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
  92921. + free_qtd = 0;
  92922. + break;
  92923. + case DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE:
  92924. + DWC_DEBUGPL(DBG_HCDV,
  92925. + " Complete URB with I/O error\n");
  92926. + free_qtd = 1;
  92927. + qtd->urb->status = -DWC_E_IO;
  92928. + hcd->fops->complete(hcd, qtd->urb->priv,
  92929. + qtd->urb, -DWC_E_IO);
  92930. + break;
  92931. + default:
  92932. + free_qtd = 0;
  92933. + break;
  92934. + }
  92935. +
  92936. + deactivate_qh(hcd, hc->qh, free_qtd);
  92937. +
  92938. +cleanup:
  92939. + /*
  92940. + * Release the host channel for use by other transfers. The cleanup
  92941. + * function clears the channel interrupt enables and conditions, so
  92942. + * there's no need to clear the Channel Halted interrupt separately.
  92943. + */
  92944. + if (fiq_fsm_enable && hcd->fiq_state->channel[hc->hc_num].fsm != FIQ_PASSTHROUGH)
  92945. + dwc_otg_cleanup_fiq_channel(hcd, hc->hc_num);
  92946. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  92947. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  92948. +
  92949. + if (!microframe_schedule) {
  92950. + switch (hc->ep_type) {
  92951. + case DWC_OTG_EP_TYPE_CONTROL:
  92952. + case DWC_OTG_EP_TYPE_BULK:
  92953. + hcd->non_periodic_channels--;
  92954. + break;
  92955. +
  92956. + default:
  92957. + /*
  92958. + * Don't release reservations for periodic channels here.
  92959. + * That's done when a periodic transfer is descheduled (i.e.
  92960. + * when the QH is removed from the periodic schedule).
  92961. + */
  92962. + break;
  92963. + }
  92964. + } else {
  92965. +
  92966. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  92967. + hcd->available_host_channels++;
  92968. + fiq_print(FIQDBG_INT, hcd->fiq_state, "AHC = %d ", hcd->available_host_channels);
  92969. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  92970. + }
  92971. +
  92972. + /* Try to queue more transfers now that there's a free channel. */
  92973. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  92974. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  92975. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  92976. + }
  92977. +}
  92978. +
  92979. +/**
  92980. + * Halts a host channel. If the channel cannot be halted immediately because
  92981. + * the request queue is full, this function ensures that the FIFO empty
  92982. + * interrupt for the appropriate queue is enabled so that the halt request can
  92983. + * be queued when there is space in the request queue.
  92984. + *
  92985. + * This function may also be called in DMA mode. In that case, the channel is
  92986. + * simply released since the core always halts the channel automatically in
  92987. + * DMA mode.
  92988. + */
  92989. +static void halt_channel(dwc_otg_hcd_t * hcd,
  92990. + dwc_hc_t * hc,
  92991. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  92992. +{
  92993. + if (hcd->core_if->dma_enable) {
  92994. + release_channel(hcd, hc, qtd, halt_status);
  92995. + return;
  92996. + }
  92997. +
  92998. + /* Slave mode processing... */
  92999. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  93000. +
  93001. + if (hc->halt_on_queue) {
  93002. + gintmsk_data_t gintmsk = {.d32 = 0 };
  93003. + dwc_otg_core_global_regs_t *global_regs;
  93004. + global_regs = hcd->core_if->core_global_regs;
  93005. +
  93006. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  93007. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  93008. + /*
  93009. + * Make sure the Non-periodic Tx FIFO empty interrupt
  93010. + * is enabled so that the non-periodic schedule will
  93011. + * be processed.
  93012. + */
  93013. + gintmsk.b.nptxfempty = 1;
  93014. + if (fiq_enable) {
  93015. + local_fiq_disable();
  93016. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  93017. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  93018. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  93019. + local_fiq_enable();
  93020. + } else {
  93021. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  93022. + }
  93023. + } else {
  93024. + /*
  93025. + * Move the QH from the periodic queued schedule to
  93026. + * the periodic assigned schedule. This allows the
  93027. + * halt to be queued when the periodic schedule is
  93028. + * processed.
  93029. + */
  93030. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  93031. + &hc->qh->qh_list_entry);
  93032. +
  93033. + /*
  93034. + * Make sure the Periodic Tx FIFO Empty interrupt is
  93035. + * enabled so that the periodic schedule will be
  93036. + * processed.
  93037. + */
  93038. + gintmsk.b.ptxfempty = 1;
  93039. + if (fiq_enable) {
  93040. + local_fiq_disable();
  93041. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  93042. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  93043. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  93044. + local_fiq_enable();
  93045. + } else {
  93046. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  93047. + }
  93048. + }
  93049. + }
  93050. +}
  93051. +
  93052. +/**
  93053. + * Performs common cleanup for non-periodic transfers after a Transfer
  93054. + * Complete interrupt. This function should be called after any endpoint type
  93055. + * specific handling is finished to release the host channel.
  93056. + */
  93057. +static void complete_non_periodic_xfer(dwc_otg_hcd_t * hcd,
  93058. + dwc_hc_t * hc,
  93059. + dwc_otg_hc_regs_t * hc_regs,
  93060. + dwc_otg_qtd_t * qtd,
  93061. + dwc_otg_halt_status_e halt_status)
  93062. +{
  93063. + hcint_data_t hcint;
  93064. +
  93065. + qtd->error_count = 0;
  93066. +
  93067. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  93068. + if (hcint.b.nyet) {
  93069. + /*
  93070. + * Got a NYET on the last transaction of the transfer. This
  93071. + * means that the endpoint should be in the PING state at the
  93072. + * beginning of the next transfer.
  93073. + */
  93074. + hc->qh->ping_state = 1;
  93075. + clear_hc_int(hc_regs, nyet);
  93076. + }
  93077. +
  93078. + /*
  93079. + * Always halt and release the host channel to make it available for
  93080. + * more transfers. There may still be more phases for a control
  93081. + * transfer or more data packets for a bulk transfer at this point,
  93082. + * but the host channel is still halted. A channel will be reassigned
  93083. + * to the transfer when the non-periodic schedule is processed after
  93084. + * the channel is released. This allows transactions to be queued
  93085. + * properly via dwc_otg_hcd_queue_transactions, which also enables the
  93086. + * Tx FIFO Empty interrupt if necessary.
  93087. + */
  93088. + if (hc->ep_is_in) {
  93089. + /*
  93090. + * IN transfers in Slave mode require an explicit disable to
  93091. + * halt the channel. (In DMA mode, this call simply releases
  93092. + * the channel.)
  93093. + */
  93094. + halt_channel(hcd, hc, qtd, halt_status);
  93095. + } else {
  93096. + /*
  93097. + * The channel is automatically disabled by the core for OUT
  93098. + * transfers in Slave mode.
  93099. + */
  93100. + release_channel(hcd, hc, qtd, halt_status);
  93101. + }
  93102. +}
  93103. +
  93104. +/**
  93105. + * Performs common cleanup for periodic transfers after a Transfer Complete
  93106. + * interrupt. This function should be called after any endpoint type specific
  93107. + * handling is finished to release the host channel.
  93108. + */
  93109. +static void complete_periodic_xfer(dwc_otg_hcd_t * hcd,
  93110. + dwc_hc_t * hc,
  93111. + dwc_otg_hc_regs_t * hc_regs,
  93112. + dwc_otg_qtd_t * qtd,
  93113. + dwc_otg_halt_status_e halt_status)
  93114. +{
  93115. + hctsiz_data_t hctsiz;
  93116. + qtd->error_count = 0;
  93117. +
  93118. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  93119. + if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
  93120. + /* Core halts channel in these cases. */
  93121. + release_channel(hcd, hc, qtd, halt_status);
  93122. + } else {
  93123. + /* Flush any outstanding requests from the Tx queue. */
  93124. + halt_channel(hcd, hc, qtd, halt_status);
  93125. + }
  93126. +}
  93127. +
  93128. +static int32_t handle_xfercomp_isoc_split_in(dwc_otg_hcd_t * hcd,
  93129. + dwc_hc_t * hc,
  93130. + dwc_otg_hc_regs_t * hc_regs,
  93131. + dwc_otg_qtd_t * qtd)
  93132. +{
  93133. + uint32_t len;
  93134. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  93135. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  93136. +
  93137. + len = get_actual_xfer_length(hc, hc_regs, qtd,
  93138. + DWC_OTG_HC_XFER_COMPLETE, NULL);
  93139. +
  93140. + if (!len) {
  93141. + qtd->complete_split = 0;
  93142. + qtd->isoc_split_offset = 0;
  93143. + return 0;
  93144. + }
  93145. + frame_desc->actual_length += len;
  93146. +
  93147. + if (hc->align_buff && len)
  93148. + dwc_memcpy(qtd->urb->buf + frame_desc->offset +
  93149. + qtd->isoc_split_offset, hc->qh->dw_align_buf, len);
  93150. + qtd->isoc_split_offset += len;
  93151. +
  93152. + if (frame_desc->length == frame_desc->actual_length) {
  93153. + frame_desc->status = 0;
  93154. + qtd->isoc_frame_index++;
  93155. + qtd->complete_split = 0;
  93156. + qtd->isoc_split_offset = 0;
  93157. + }
  93158. +
  93159. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  93160. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  93161. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  93162. + } else {
  93163. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  93164. + }
  93165. +
  93166. + return 1; /* Indicates that channel released */
  93167. +}
  93168. +
  93169. +/**
  93170. + * Handles a host channel Transfer Complete interrupt. This handler may be
  93171. + * called in either DMA mode or Slave mode.
  93172. + */
  93173. +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t * hcd,
  93174. + dwc_hc_t * hc,
  93175. + dwc_otg_hc_regs_t * hc_regs,
  93176. + dwc_otg_qtd_t * qtd)
  93177. +{
  93178. + int urb_xfer_done;
  93179. + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
  93180. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  93181. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  93182. +
  93183. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  93184. + "Transfer Complete--\n", hc->hc_num);
  93185. +
  93186. + if (hcd->core_if->dma_desc_enable) {
  93187. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, halt_status);
  93188. + if (pipe_type == UE_ISOCHRONOUS) {
  93189. + /* Do not disable the interrupt, just clear it */
  93190. + clear_hc_int(hc_regs, xfercomp);
  93191. + return 1;
  93192. + }
  93193. + goto handle_xfercomp_done;
  93194. + }
  93195. +
  93196. + /*
  93197. + * Handle xfer complete on CSPLIT.
  93198. + */
  93199. +
  93200. + if (hc->qh->do_split) {
  93201. + if ((hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && hc->ep_is_in
  93202. + && hcd->core_if->dma_enable) {
  93203. + if (qtd->complete_split
  93204. + && handle_xfercomp_isoc_split_in(hcd, hc, hc_regs,
  93205. + qtd))
  93206. + goto handle_xfercomp_done;
  93207. + } else {
  93208. + qtd->complete_split = 0;
  93209. + }
  93210. + }
  93211. +
  93212. + /* Update the QTD and URB states. */
  93213. + switch (pipe_type) {
  93214. + case UE_CONTROL:
  93215. + switch (qtd->control_phase) {
  93216. + case DWC_OTG_CONTROL_SETUP:
  93217. + if (urb->length > 0) {
  93218. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  93219. + } else {
  93220. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  93221. + }
  93222. + DWC_DEBUGPL(DBG_HCDV,
  93223. + " Control setup transaction done\n");
  93224. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  93225. + break;
  93226. + case DWC_OTG_CONTROL_DATA:{
  93227. + urb_xfer_done =
  93228. + update_urb_state_xfer_comp(hc, hc_regs, urb,
  93229. + qtd);
  93230. + if (urb_xfer_done) {
  93231. + qtd->control_phase =
  93232. + DWC_OTG_CONTROL_STATUS;
  93233. + DWC_DEBUGPL(DBG_HCDV,
  93234. + " Control data transfer done\n");
  93235. + } else {
  93236. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  93237. + }
  93238. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  93239. + break;
  93240. + }
  93241. + case DWC_OTG_CONTROL_STATUS:
  93242. + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
  93243. + if (urb->status == -DWC_E_IN_PROGRESS) {
  93244. + urb->status = 0;
  93245. + }
  93246. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  93247. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  93248. + break;
  93249. + }
  93250. +
  93251. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  93252. + break;
  93253. + case UE_BULK:
  93254. + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
  93255. + urb_xfer_done =
  93256. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  93257. + if (urb_xfer_done) {
  93258. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  93259. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  93260. + } else {
  93261. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  93262. + }
  93263. +
  93264. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  93265. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  93266. + break;
  93267. + case UE_INTERRUPT:
  93268. + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
  93269. + urb_xfer_done =
  93270. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  93271. +
  93272. + /*
  93273. + * Interrupt URB is done on the first transfer complete
  93274. + * interrupt.
  93275. + */
  93276. + if (urb_xfer_done) {
  93277. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  93278. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  93279. + } else {
  93280. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  93281. + }
  93282. +
  93283. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  93284. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  93285. + break;
  93286. + case UE_ISOCHRONOUS:
  93287. + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
  93288. + if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  93289. + halt_status =
  93290. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  93291. + DWC_OTG_HC_XFER_COMPLETE);
  93292. + }
  93293. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  93294. + break;
  93295. + }
  93296. +
  93297. +handle_xfercomp_done:
  93298. + disable_hc_int(hc_regs, xfercompl);
  93299. +
  93300. + return 1;
  93301. +}
  93302. +
  93303. +/**
  93304. + * Handles a host channel STALL interrupt. This handler may be called in
  93305. + * either DMA mode or Slave mode.
  93306. + */
  93307. +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t * hcd,
  93308. + dwc_hc_t * hc,
  93309. + dwc_otg_hc_regs_t * hc_regs,
  93310. + dwc_otg_qtd_t * qtd)
  93311. +{
  93312. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  93313. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  93314. +
  93315. + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
  93316. + "STALL Received--\n", hc->hc_num);
  93317. +
  93318. + if (hcd->core_if->dma_desc_enable) {
  93319. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, DWC_OTG_HC_XFER_STALL);
  93320. + goto handle_stall_done;
  93321. + }
  93322. +
  93323. + if (pipe_type == UE_CONTROL) {
  93324. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  93325. + }
  93326. +
  93327. + if (pipe_type == UE_BULK || pipe_type == UE_INTERRUPT) {
  93328. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  93329. + /*
  93330. + * USB protocol requires resetting the data toggle for bulk
  93331. + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
  93332. + * setup command is issued to the endpoint. Anticipate the
  93333. + * CLEAR_FEATURE command since a STALL has occurred and reset
  93334. + * the data toggle now.
  93335. + */
  93336. + hc->qh->data_toggle = 0;
  93337. + }
  93338. +
  93339. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
  93340. +
  93341. +handle_stall_done:
  93342. + disable_hc_int(hc_regs, stall);
  93343. +
  93344. + return 1;
  93345. +}
  93346. +
  93347. +/*
  93348. + * Updates the state of the URB when a transfer has been stopped due to an
  93349. + * abnormal condition before the transfer completes. Modifies the
  93350. + * actual_length field of the URB to reflect the number of bytes that have
  93351. + * actually been transferred via the host channel.
  93352. + */
  93353. +static void update_urb_state_xfer_intr(dwc_hc_t * hc,
  93354. + dwc_otg_hc_regs_t * hc_regs,
  93355. + dwc_otg_hcd_urb_t * urb,
  93356. + dwc_otg_qtd_t * qtd,
  93357. + dwc_otg_halt_status_e halt_status)
  93358. +{
  93359. + uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
  93360. + halt_status, NULL);
  93361. + /* non DWORD-aligned buffer case handling. */
  93362. + if (hc->align_buff && bytes_transferred && hc->ep_is_in) {
  93363. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  93364. + bytes_transferred);
  93365. + }
  93366. +
  93367. + urb->actual_length += bytes_transferred;
  93368. +
  93369. +#ifdef DEBUG
  93370. + {
  93371. + hctsiz_data_t hctsiz;
  93372. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  93373. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  93374. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  93375. + hc->hc_num);
  93376. + DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n",
  93377. + hc->start_pkt_count);
  93378. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
  93379. + DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
  93380. + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n",
  93381. + bytes_transferred);
  93382. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  93383. + urb->actual_length);
  93384. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  93385. + urb->length);
  93386. + }
  93387. +#endif
  93388. +}
  93389. +
  93390. +/**
  93391. + * Handles a host channel NAK interrupt. This handler may be called in either
  93392. + * DMA mode or Slave mode.
  93393. + */
  93394. +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t * hcd,
  93395. + dwc_hc_t * hc,
  93396. + dwc_otg_hc_regs_t * hc_regs,
  93397. + dwc_otg_qtd_t * qtd)
  93398. +{
  93399. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  93400. + "NAK Received--\n", hc->hc_num);
  93401. +
  93402. + /*
  93403. + * When we get bulk NAKs then remember this so we holdoff on this qh until
  93404. + * the beginning of the next frame
  93405. + */
  93406. + switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  93407. + case UE_BULK:
  93408. + case UE_CONTROL:
  93409. + if (nak_holdoff && qtd->qh->do_split)
  93410. + hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
  93411. + }
  93412. +
  93413. + /*
  93414. + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  93415. + * interrupt. Re-start the SSPLIT transfer.
  93416. + */
  93417. + if (hc->do_split) {
  93418. + if (hc->complete_split) {
  93419. + qtd->error_count = 0;
  93420. + }
  93421. + qtd->complete_split = 0;
  93422. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  93423. + goto handle_nak_done;
  93424. + }
  93425. +
  93426. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  93427. + case UE_CONTROL:
  93428. + case UE_BULK:
  93429. + if (hcd->core_if->dma_enable && hc->ep_is_in) {
  93430. + /*
  93431. + * NAK interrupts are enabled on bulk/control IN
  93432. + * transfers in DMA mode for the sole purpose of
  93433. + * resetting the error count after a transaction error
  93434. + * occurs. The core will continue transferring data.
  93435. + * Disable other interrupts unmasked for the same
  93436. + * reason.
  93437. + */
  93438. + disable_hc_int(hc_regs, datatglerr);
  93439. + disable_hc_int(hc_regs, ack);
  93440. + qtd->error_count = 0;
  93441. + goto handle_nak_done;
  93442. + }
  93443. +
  93444. + /*
  93445. + * NAK interrupts normally occur during OUT transfers in DMA
  93446. + * or Slave mode. For IN transfers, more requests will be
  93447. + * queued as request queue space is available.
  93448. + */
  93449. + qtd->error_count = 0;
  93450. +
  93451. + if (!hc->qh->ping_state) {
  93452. + update_urb_state_xfer_intr(hc, hc_regs,
  93453. + qtd->urb, qtd,
  93454. + DWC_OTG_HC_XFER_NAK);
  93455. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  93456. +
  93457. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH)
  93458. + hc->qh->ping_state = 1;
  93459. + }
  93460. +
  93461. + /*
  93462. + * Halt the channel so the transfer can be re-started from
  93463. + * the appropriate point or the PING protocol will
  93464. + * start/continue.
  93465. + */
  93466. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  93467. + break;
  93468. + case UE_INTERRUPT:
  93469. + qtd->error_count = 0;
  93470. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  93471. + break;
  93472. + case UE_ISOCHRONOUS:
  93473. + /* Should never get called for isochronous transfers. */
  93474. + DWC_ASSERT(1, "NACK interrupt for ISOC transfer\n");
  93475. + break;
  93476. + }
  93477. +
  93478. +handle_nak_done:
  93479. + disable_hc_int(hc_regs, nak);
  93480. +
  93481. + return 1;
  93482. +}
  93483. +
  93484. +/**
  93485. + * Handles a host channel ACK interrupt. This interrupt is enabled when
  93486. + * performing the PING protocol in Slave mode, when errors occur during
  93487. + * either Slave mode or DMA mode, and during Start Split transactions.
  93488. + */
  93489. +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t * hcd,
  93490. + dwc_hc_t * hc,
  93491. + dwc_otg_hc_regs_t * hc_regs,
  93492. + dwc_otg_qtd_t * qtd)
  93493. +{
  93494. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  93495. + "ACK Received--\n", hc->hc_num);
  93496. +
  93497. + if (hc->do_split) {
  93498. + /*
  93499. + * Handle ACK on SSPLIT.
  93500. + * ACK should not occur in CSPLIT.
  93501. + */
  93502. + if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
  93503. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  93504. + }
  93505. + if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
  93506. + /* Don't need complete for isochronous out transfers. */
  93507. + qtd->complete_split = 1;
  93508. + }
  93509. +
  93510. + /* ISOC OUT */
  93511. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  93512. + switch (hc->xact_pos) {
  93513. + case DWC_HCSPLIT_XACTPOS_ALL:
  93514. + break;
  93515. + case DWC_HCSPLIT_XACTPOS_END:
  93516. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  93517. + qtd->isoc_split_offset = 0;
  93518. + break;
  93519. + case DWC_HCSPLIT_XACTPOS_BEGIN:
  93520. + case DWC_HCSPLIT_XACTPOS_MID:
  93521. + /*
  93522. + * For BEGIN or MID, calculate the length for
  93523. + * the next microframe to determine the correct
  93524. + * SSPLIT token, either MID or END.
  93525. + */
  93526. + {
  93527. + struct dwc_otg_hcd_iso_packet_desc
  93528. + *frame_desc;
  93529. +
  93530. + frame_desc =
  93531. + &qtd->urb->
  93532. + iso_descs[qtd->isoc_frame_index];
  93533. + qtd->isoc_split_offset += 188;
  93534. +
  93535. + if ((frame_desc->length -
  93536. + qtd->isoc_split_offset) <= 188) {
  93537. + qtd->isoc_split_pos =
  93538. + DWC_HCSPLIT_XACTPOS_END;
  93539. + } else {
  93540. + qtd->isoc_split_pos =
  93541. + DWC_HCSPLIT_XACTPOS_MID;
  93542. + }
  93543. +
  93544. + }
  93545. + break;
  93546. + }
  93547. + } else {
  93548. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  93549. + }
  93550. + } else {
  93551. + /*
  93552. + * An unmasked ACK on a non-split DMA transaction is
  93553. + * for the sole purpose of resetting error counts. Disable other
  93554. + * interrupts unmasked for the same reason.
  93555. + */
  93556. + if(hcd->core_if->dma_enable) {
  93557. + disable_hc_int(hc_regs, datatglerr);
  93558. + disable_hc_int(hc_regs, nak);
  93559. + }
  93560. + qtd->error_count = 0;
  93561. +
  93562. + if (hc->qh->ping_state) {
  93563. + hc->qh->ping_state = 0;
  93564. + /*
  93565. + * Halt the channel so the transfer can be re-started
  93566. + * from the appropriate point. This only happens in
  93567. + * Slave mode. In DMA mode, the ping_state is cleared
  93568. + * when the transfer is started because the core
  93569. + * automatically executes the PING, then the transfer.
  93570. + */
  93571. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  93572. + }
  93573. + }
  93574. +
  93575. + /*
  93576. + * If the ACK occurred when _not_ in the PING state, let the channel
  93577. + * continue transferring data after clearing the error count.
  93578. + */
  93579. +
  93580. + disable_hc_int(hc_regs, ack);
  93581. +
  93582. + return 1;
  93583. +}
  93584. +
  93585. +/**
  93586. + * Handles a host channel NYET interrupt. This interrupt should only occur on
  93587. + * Bulk and Control OUT endpoints and for complete split transactions. If a
  93588. + * NYET occurs at the same time as a Transfer Complete interrupt, it is
  93589. + * handled in the xfercomp interrupt handler, not here. This handler may be
  93590. + * called in either DMA mode or Slave mode.
  93591. + */
  93592. +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t * hcd,
  93593. + dwc_hc_t * hc,
  93594. + dwc_otg_hc_regs_t * hc_regs,
  93595. + dwc_otg_qtd_t * qtd)
  93596. +{
  93597. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  93598. + "NYET Received--\n", hc->hc_num);
  93599. +
  93600. + /*
  93601. + * NYET on CSPLIT
  93602. + * re-do the CSPLIT immediately on non-periodic
  93603. + */
  93604. + if (hc->do_split && hc->complete_split) {
  93605. + if (hc->ep_is_in && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  93606. + && hcd->core_if->dma_enable) {
  93607. + qtd->complete_split = 0;
  93608. + qtd->isoc_split_offset = 0;
  93609. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  93610. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  93611. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  93612. + }
  93613. + else
  93614. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  93615. + goto handle_nyet_done;
  93616. + }
  93617. +
  93618. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  93619. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  93620. + int frnum = dwc_otg_hcd_get_frame_number(hcd);
  93621. +
  93622. + // With the FIQ running we only ever see the failed NYET
  93623. + if (dwc_full_frame_num(frnum) !=
  93624. + dwc_full_frame_num(hc->qh->sched_frame) ||
  93625. + fiq_fsm_enable) {
  93626. + /*
  93627. + * No longer in the same full speed frame.
  93628. + * Treat this as a transaction error.
  93629. + */
  93630. +#if 0
  93631. + /** @todo Fix system performance so this can
  93632. + * be treated as an error. Right now complete
  93633. + * splits cannot be scheduled precisely enough
  93634. + * due to other system activity, so this error
  93635. + * occurs regularly in Slave mode.
  93636. + */
  93637. + qtd->error_count++;
  93638. +#endif
  93639. + qtd->complete_split = 0;
  93640. + halt_channel(hcd, hc, qtd,
  93641. + DWC_OTG_HC_XFER_XACT_ERR);
  93642. + /** @todo add support for isoc release */
  93643. + goto handle_nyet_done;
  93644. + }
  93645. + }
  93646. +
  93647. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  93648. + goto handle_nyet_done;
  93649. + }
  93650. +
  93651. + hc->qh->ping_state = 1;
  93652. + qtd->error_count = 0;
  93653. +
  93654. + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
  93655. + DWC_OTG_HC_XFER_NYET);
  93656. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  93657. +
  93658. + /*
  93659. + * Halt the channel and re-start the transfer so the PING
  93660. + * protocol will start.
  93661. + */
  93662. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  93663. +
  93664. +handle_nyet_done:
  93665. + disable_hc_int(hc_regs, nyet);
  93666. + return 1;
  93667. +}
  93668. +
  93669. +/**
  93670. + * Handles a host channel babble interrupt. This handler may be called in
  93671. + * either DMA mode or Slave mode.
  93672. + */
  93673. +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t * hcd,
  93674. + dwc_hc_t * hc,
  93675. + dwc_otg_hc_regs_t * hc_regs,
  93676. + dwc_otg_qtd_t * qtd)
  93677. +{
  93678. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  93679. + "Babble Error--\n", hc->hc_num);
  93680. +
  93681. + if (hcd->core_if->dma_desc_enable) {
  93682. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  93683. + DWC_OTG_HC_XFER_BABBLE_ERR);
  93684. + goto handle_babble_done;
  93685. + }
  93686. +
  93687. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  93688. + hcd->fops->complete(hcd, qtd->urb->priv,
  93689. + qtd->urb, -DWC_E_OVERFLOW);
  93690. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
  93691. + } else {
  93692. + dwc_otg_halt_status_e halt_status;
  93693. + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  93694. + DWC_OTG_HC_XFER_BABBLE_ERR);
  93695. + halt_channel(hcd, hc, qtd, halt_status);
  93696. + }
  93697. +
  93698. +handle_babble_done:
  93699. + disable_hc_int(hc_regs, bblerr);
  93700. + return 1;
  93701. +}
  93702. +
  93703. +/**
  93704. + * Handles a host channel AHB error interrupt. This handler is only called in
  93705. + * DMA mode.
  93706. + */
  93707. +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t * hcd,
  93708. + dwc_hc_t * hc,
  93709. + dwc_otg_hc_regs_t * hc_regs,
  93710. + dwc_otg_qtd_t * qtd)
  93711. +{
  93712. + hcchar_data_t hcchar;
  93713. + hcsplt_data_t hcsplt;
  93714. + hctsiz_data_t hctsiz;
  93715. + uint32_t hcdma;
  93716. + char *pipetype, *speed;
  93717. +
  93718. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  93719. +
  93720. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  93721. + "AHB Error--\n", hc->hc_num);
  93722. +
  93723. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  93724. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  93725. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  93726. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  93727. +
  93728. + DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
  93729. + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
  93730. + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
  93731. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
  93732. + DWC_ERROR(" Device address: %d\n",
  93733. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  93734. + DWC_ERROR(" Endpoint: %d, %s\n",
  93735. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  93736. + (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"));
  93737. +
  93738. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  93739. + case UE_CONTROL:
  93740. + pipetype = "CONTROL";
  93741. + break;
  93742. + case UE_BULK:
  93743. + pipetype = "BULK";
  93744. + break;
  93745. + case UE_INTERRUPT:
  93746. + pipetype = "INTERRUPT";
  93747. + break;
  93748. + case UE_ISOCHRONOUS:
  93749. + pipetype = "ISOCHRONOUS";
  93750. + break;
  93751. + default:
  93752. + pipetype = "UNKNOWN";
  93753. + break;
  93754. + }
  93755. +
  93756. + DWC_ERROR(" Endpoint type: %s\n", pipetype);
  93757. +
  93758. + switch (hc->speed) {
  93759. + case DWC_OTG_EP_SPEED_HIGH:
  93760. + speed = "HIGH";
  93761. + break;
  93762. + case DWC_OTG_EP_SPEED_FULL:
  93763. + speed = "FULL";
  93764. + break;
  93765. + case DWC_OTG_EP_SPEED_LOW:
  93766. + speed = "LOW";
  93767. + break;
  93768. + default:
  93769. + speed = "UNKNOWN";
  93770. + break;
  93771. + };
  93772. +
  93773. + DWC_ERROR(" Speed: %s\n", speed);
  93774. +
  93775. + DWC_ERROR(" Max packet size: %d\n",
  93776. + dwc_otg_hcd_get_mps(&urb->pipe_info));
  93777. + DWC_ERROR(" Data buffer length: %d\n", urb->length);
  93778. + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
  93779. + urb->buf, (void *)urb->dma);
  93780. + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
  93781. + urb->setup_packet, (void *)urb->setup_dma);
  93782. + DWC_ERROR(" Interval: %d\n", urb->interval);
  93783. +
  93784. + /* Core haltes the channel for Descriptor DMA mode */
  93785. + if (hcd->core_if->dma_desc_enable) {
  93786. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  93787. + DWC_OTG_HC_XFER_AHB_ERR);
  93788. + goto handle_ahberr_done;
  93789. + }
  93790. +
  93791. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_IO);
  93792. +
  93793. + /*
  93794. + * Force a channel halt. Don't call halt_channel because that won't
  93795. + * write to the HCCHARn register in DMA mode to force the halt.
  93796. + */
  93797. + dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
  93798. +handle_ahberr_done:
  93799. + disable_hc_int(hc_regs, ahberr);
  93800. + return 1;
  93801. +}
  93802. +
  93803. +/**
  93804. + * Handles a host channel transaction error interrupt. This handler may be
  93805. + * called in either DMA mode or Slave mode.
  93806. + */
  93807. +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t * hcd,
  93808. + dwc_hc_t * hc,
  93809. + dwc_otg_hc_regs_t * hc_regs,
  93810. + dwc_otg_qtd_t * qtd)
  93811. +{
  93812. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  93813. + "Transaction Error--\n", hc->hc_num);
  93814. +
  93815. + if (hcd->core_if->dma_desc_enable) {
  93816. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  93817. + DWC_OTG_HC_XFER_XACT_ERR);
  93818. + goto handle_xacterr_done;
  93819. + }
  93820. +
  93821. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  93822. + case UE_CONTROL:
  93823. + case UE_BULK:
  93824. + qtd->error_count++;
  93825. + if (!hc->qh->ping_state) {
  93826. +
  93827. + update_urb_state_xfer_intr(hc, hc_regs,
  93828. + qtd->urb, qtd,
  93829. + DWC_OTG_HC_XFER_XACT_ERR);
  93830. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  93831. + if (!hc->ep_is_in && hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  93832. + hc->qh->ping_state = 1;
  93833. + }
  93834. + }
  93835. +
  93836. + /*
  93837. + * Halt the channel so the transfer can be re-started from
  93838. + * the appropriate point or the PING protocol will start.
  93839. + */
  93840. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  93841. + break;
  93842. + case UE_INTERRUPT:
  93843. + qtd->error_count++;
  93844. + if (hc->do_split && hc->complete_split) {
  93845. + qtd->complete_split = 0;
  93846. + }
  93847. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  93848. + break;
  93849. + case UE_ISOCHRONOUS:
  93850. + {
  93851. + dwc_otg_halt_status_e halt_status;
  93852. + halt_status =
  93853. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  93854. + DWC_OTG_HC_XFER_XACT_ERR);
  93855. +
  93856. + halt_channel(hcd, hc, qtd, halt_status);
  93857. + }
  93858. + break;
  93859. + }
  93860. +handle_xacterr_done:
  93861. + disable_hc_int(hc_regs, xacterr);
  93862. +
  93863. + return 1;
  93864. +}
  93865. +
  93866. +/**
  93867. + * Handles a host channel frame overrun interrupt. This handler may be called
  93868. + * in either DMA mode or Slave mode.
  93869. + */
  93870. +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t * hcd,
  93871. + dwc_hc_t * hc,
  93872. + dwc_otg_hc_regs_t * hc_regs,
  93873. + dwc_otg_qtd_t * qtd)
  93874. +{
  93875. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  93876. + "Frame Overrun--\n", hc->hc_num);
  93877. +
  93878. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  93879. + case UE_CONTROL:
  93880. + case UE_BULK:
  93881. + break;
  93882. + case UE_INTERRUPT:
  93883. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
  93884. + break;
  93885. + case UE_ISOCHRONOUS:
  93886. + {
  93887. + dwc_otg_halt_status_e halt_status;
  93888. + halt_status =
  93889. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  93890. + DWC_OTG_HC_XFER_FRAME_OVERRUN);
  93891. +
  93892. + halt_channel(hcd, hc, qtd, halt_status);
  93893. + }
  93894. + break;
  93895. + }
  93896. +
  93897. + disable_hc_int(hc_regs, frmovrun);
  93898. +
  93899. + return 1;
  93900. +}
  93901. +
  93902. +/**
  93903. + * Handles a host channel data toggle error interrupt. This handler may be
  93904. + * called in either DMA mode or Slave mode.
  93905. + */
  93906. +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t * hcd,
  93907. + dwc_hc_t * hc,
  93908. + dwc_otg_hc_regs_t * hc_regs,
  93909. + dwc_otg_qtd_t * qtd)
  93910. +{
  93911. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  93912. + "Data Toggle Error on %s transfer--\n",
  93913. + hc->hc_num, (hc->ep_is_in ? "IN" : "OUT"));
  93914. +
  93915. + /* Data toggles on split transactions cause the hc to halt.
  93916. + * restart transfer */
  93917. + if(hc->qh->do_split)
  93918. + {
  93919. + qtd->error_count++;
  93920. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  93921. + update_urb_state_xfer_intr(hc, hc_regs,
  93922. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  93923. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  93924. + } else if (hc->ep_is_in) {
  93925. + /* An unmasked data toggle error on a non-split DMA transaction is
  93926. + * for the sole purpose of resetting error counts. Disable other
  93927. + * interrupts unmasked for the same reason.
  93928. + */
  93929. + if(hcd->core_if->dma_enable) {
  93930. + disable_hc_int(hc_regs, ack);
  93931. + disable_hc_int(hc_regs, nak);
  93932. + }
  93933. + qtd->error_count = 0;
  93934. + }
  93935. +
  93936. + disable_hc_int(hc_regs, datatglerr);
  93937. +
  93938. + return 1;
  93939. +}
  93940. +
  93941. +#ifdef DEBUG
  93942. +/**
  93943. + * This function is for debug only. It checks that a valid halt status is set
  93944. + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
  93945. + * taken and a warning is issued.
  93946. + * @return 1 if halt status is ok, 0 otherwise.
  93947. + */
  93948. +static inline int halt_status_ok(dwc_otg_hcd_t * hcd,
  93949. + dwc_hc_t * hc,
  93950. + dwc_otg_hc_regs_t * hc_regs,
  93951. + dwc_otg_qtd_t * qtd)
  93952. +{
  93953. + hcchar_data_t hcchar;
  93954. + hctsiz_data_t hctsiz;
  93955. + hcint_data_t hcint;
  93956. + hcintmsk_data_t hcintmsk;
  93957. + hcsplt_data_t hcsplt;
  93958. +
  93959. + if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
  93960. + /*
  93961. + * This code is here only as a check. This condition should
  93962. + * never happen. Ignore the halt if it does occur.
  93963. + */
  93964. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  93965. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  93966. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  93967. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  93968. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  93969. + DWC_WARN
  93970. + ("%s: hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
  93971. + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
  93972. + "hcint 0x%08x, hcintmsk 0x%08x, "
  93973. + "hcsplt 0x%08x, qtd->complete_split %d\n", __func__,
  93974. + hc->hc_num, hcchar.d32, hctsiz.d32, hcint.d32,
  93975. + hcintmsk.d32, hcsplt.d32, qtd->complete_split);
  93976. +
  93977. + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
  93978. + __func__, hc->hc_num);
  93979. + DWC_WARN("\n");
  93980. + clear_hc_int(hc_regs, chhltd);
  93981. + return 0;
  93982. + }
  93983. +
  93984. + /*
  93985. + * This code is here only as a check. hcchar.chdis should
  93986. + * never be set when the halt interrupt occurs. Halt the
  93987. + * channel again if it does occur.
  93988. + */
  93989. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  93990. + if (hcchar.b.chdis) {
  93991. + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
  93992. + "hcchar 0x%08x, trying to halt again\n",
  93993. + __func__, hcchar.d32);
  93994. + clear_hc_int(hc_regs, chhltd);
  93995. + hc->halt_pending = 0;
  93996. + halt_channel(hcd, hc, qtd, hc->halt_status);
  93997. + return 0;
  93998. + }
  93999. +
  94000. + return 1;
  94001. +}
  94002. +#endif
  94003. +
  94004. +/**
  94005. + * Handles a host Channel Halted interrupt in DMA mode. This handler
  94006. + * determines the reason the channel halted and proceeds accordingly.
  94007. + */
  94008. +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
  94009. + dwc_hc_t * hc,
  94010. + dwc_otg_hc_regs_t * hc_regs,
  94011. + dwc_otg_qtd_t * qtd)
  94012. +{
  94013. + int out_nak_enh = 0;
  94014. + hcint_data_t hcint;
  94015. + hcintmsk_data_t hcintmsk;
  94016. + /* For core with OUT NAK enhancement, the flow for high-
  94017. + * speed CONTROL/BULK OUT is handled a little differently.
  94018. + */
  94019. + if (hcd->core_if->snpsid >= OTG_CORE_REV_2_71a) {
  94020. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
  94021. + (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  94022. + hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
  94023. + out_nak_enh = 1;
  94024. + }
  94025. + }
  94026. +
  94027. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  94028. + (hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR
  94029. + && !hcd->core_if->dma_desc_enable)) {
  94030. + /*
  94031. + * Just release the channel. A dequeue can happen on a
  94032. + * transfer timeout. In the case of an AHB Error, the channel
  94033. + * was forced to halt because there's no way to gracefully
  94034. + * recover.
  94035. + */
  94036. + if (hcd->core_if->dma_desc_enable)
  94037. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  94038. + hc->halt_status);
  94039. + else
  94040. + release_channel(hcd, hc, qtd, hc->halt_status);
  94041. + return;
  94042. + }
  94043. +
  94044. + /* Read the HCINTn register to determine the cause for the halt. */
  94045. +
  94046. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  94047. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  94048. +
  94049. + if (hcint.b.xfercomp) {
  94050. + /** @todo This is here because of a possible hardware bug. Spec
  94051. + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  94052. + * interrupt w/ACK bit set should occur, but I only see the
  94053. + * XFERCOMP bit, even with it masked out. This is a workaround
  94054. + * for that behavior. Should fix this when hardware is fixed.
  94055. + */
  94056. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  94057. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  94058. + }
  94059. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  94060. + } else if (hcint.b.stall) {
  94061. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  94062. + } else if (hcint.b.xacterr && !hcd->core_if->dma_desc_enable) {
  94063. + if (out_nak_enh) {
  94064. + if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
  94065. + DWC_DEBUGPL(DBG_HCD, "XactErr with NYET/NAK/ACK\n");
  94066. + qtd->error_count = 0;
  94067. + } else {
  94068. + DWC_DEBUGPL(DBG_HCD, "XactErr without NYET/NAK/ACK\n");
  94069. + }
  94070. + }
  94071. +
  94072. + /*
  94073. + * Must handle xacterr before nak or ack. Could get a xacterr
  94074. + * at the same time as either of these on a BULK/CONTROL OUT
  94075. + * that started with a PING. The xacterr takes precedence.
  94076. + */
  94077. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  94078. + } else if (hcint.b.xcs_xact && hcd->core_if->dma_desc_enable) {
  94079. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  94080. + } else if (hcint.b.ahberr && hcd->core_if->dma_desc_enable) {
  94081. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  94082. + } else if (hcint.b.bblerr) {
  94083. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  94084. + } else if (hcint.b.frmovrun) {
  94085. + handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
  94086. + } else if (hcint.b.datatglerr) {
  94087. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  94088. + } else if (!out_nak_enh) {
  94089. + if (hcint.b.nyet) {
  94090. + /*
  94091. + * Must handle nyet before nak or ack. Could get a nyet at the
  94092. + * same time as either of those on a BULK/CONTROL OUT that
  94093. + * started with a PING. The nyet takes precedence.
  94094. + */
  94095. + handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
  94096. + } else if (hcint.b.nak && !hcintmsk.b.nak) {
  94097. + /*
  94098. + * If nak is not masked, it's because a non-split IN transfer
  94099. + * is in an error state. In that case, the nak is handled by
  94100. + * the nak interrupt handler, not here. Handle nak here for
  94101. + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
  94102. + * rewinding the buffer pointer.
  94103. + */
  94104. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  94105. + } else if (hcint.b.ack && !hcintmsk.b.ack) {
  94106. + /*
  94107. + * If ack is not masked, it's because a non-split IN transfer
  94108. + * is in an error state. In that case, the ack is handled by
  94109. + * the ack interrupt handler, not here. Handle ack here for
  94110. + * split transfers. Start splits halt on ACK.
  94111. + */
  94112. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  94113. + } else {
  94114. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  94115. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  94116. + /*
  94117. + * A periodic transfer halted with no other channel
  94118. + * interrupts set. Assume it was halted by the core
  94119. + * because it could not be completed in its scheduled
  94120. + * (micro)frame.
  94121. + */
  94122. +#ifdef DEBUG
  94123. + DWC_PRINTF
  94124. + ("%s: Halt channel %d (assume incomplete periodic transfer)\n",
  94125. + __func__, hc->hc_num);
  94126. +#endif
  94127. + halt_channel(hcd, hc, qtd,
  94128. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
  94129. + } else {
  94130. + DWC_ERROR
  94131. + ("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
  94132. + "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
  94133. + __func__, hc->hc_num, hcint.d32,
  94134. + DWC_READ_REG32(&hcd->
  94135. + core_if->core_global_regs->
  94136. + gintsts));
  94137. + /* Failthrough: use 3-strikes rule */
  94138. + qtd->error_count++;
  94139. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  94140. + update_urb_state_xfer_intr(hc, hc_regs,
  94141. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  94142. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  94143. + }
  94144. +
  94145. + }
  94146. + } else {
  94147. + DWC_PRINTF("NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  94148. + hcint.d32);
  94149. + /* Failthrough: use 3-strikes rule */
  94150. + qtd->error_count++;
  94151. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  94152. + update_urb_state_xfer_intr(hc, hc_regs,
  94153. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  94154. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  94155. + }
  94156. +}
  94157. +
  94158. +/**
  94159. + * Handles a host channel Channel Halted interrupt.
  94160. + *
  94161. + * In slave mode, this handler is called only when the driver specifically
  94162. + * requests a halt. This occurs during handling other host channel interrupts
  94163. + * (e.g. nak, xacterr, stall, nyet, etc.).
  94164. + *
  94165. + * In DMA mode, this is the interrupt that occurs when the core has finished
  94166. + * processing a transfer on a channel. Other host channel interrupts (except
  94167. + * ahberr) are disabled in DMA mode.
  94168. + */
  94169. +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
  94170. + dwc_hc_t * hc,
  94171. + dwc_otg_hc_regs_t * hc_regs,
  94172. + dwc_otg_qtd_t * qtd)
  94173. +{
  94174. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  94175. + "Channel Halted--\n", hc->hc_num);
  94176. +
  94177. + if (hcd->core_if->dma_enable) {
  94178. + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
  94179. + } else {
  94180. +#ifdef DEBUG
  94181. + if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
  94182. + return 1;
  94183. + }
  94184. +#endif
  94185. + release_channel(hcd, hc, qtd, hc->halt_status);
  94186. + }
  94187. +
  94188. + return 1;
  94189. +}
  94190. +
  94191. +
  94192. +/**
  94193. + * dwc_otg_fiq_unmangle_isoc() - Update the iso_frame_desc structure on
  94194. + * FIQ transfer completion
  94195. + * @hcd: Pointer to dwc_otg_hcd struct
  94196. + * @num: Host channel number
  94197. + *
  94198. + * 1. Un-mangle the status as recorded in each iso_frame_desc status
  94199. + * 2. Copy it from the dwc_otg_urb into the real URB
  94200. + */
  94201. +void dwc_otg_fiq_unmangle_isoc(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
  94202. +{
  94203. + struct dwc_otg_hcd_urb *dwc_urb = qtd->urb;
  94204. + int nr_frames = dwc_urb->packet_count;
  94205. + int i;
  94206. + hcint_data_t frame_hcint;
  94207. +
  94208. + for (i = 0; i < nr_frames; i++) {
  94209. + frame_hcint.d32 = dwc_urb->iso_descs[i].status;
  94210. + if (frame_hcint.b.xfercomp) {
  94211. + dwc_urb->iso_descs[i].status = 0;
  94212. + dwc_urb->actual_length += dwc_urb->iso_descs[i].actual_length;
  94213. + } else if (frame_hcint.b.frmovrun) {
  94214. + if (qh->ep_is_in)
  94215. + dwc_urb->iso_descs[i].status = -DWC_E_NO_STREAM_RES;
  94216. + else
  94217. + dwc_urb->iso_descs[i].status = -DWC_E_COMMUNICATION;
  94218. + dwc_urb->error_count++;
  94219. + dwc_urb->iso_descs[i].actual_length = 0;
  94220. + } else if (frame_hcint.b.xacterr) {
  94221. + dwc_urb->iso_descs[i].status = -DWC_E_PROTOCOL;
  94222. + dwc_urb->error_count++;
  94223. + dwc_urb->iso_descs[i].actual_length = 0;
  94224. + } else if (frame_hcint.b.bblerr) {
  94225. + dwc_urb->iso_descs[i].status = -DWC_E_OVERFLOW;
  94226. + dwc_urb->error_count++;
  94227. + dwc_urb->iso_descs[i].actual_length = 0;
  94228. + } else {
  94229. + /* Something went wrong */
  94230. + dwc_urb->iso_descs[i].status = -1;
  94231. + dwc_urb->iso_descs[i].actual_length = 0;
  94232. + dwc_urb->error_count++;
  94233. + }
  94234. + }
  94235. + //printk_ratelimited(KERN_INFO "%s: HS isochronous of %d/%d frames with %d errors complete\n",
  94236. + // __FUNCTION__, i, dwc_urb->packet_count, dwc_urb->error_count);
  94237. + hcd->fops->complete(hcd, dwc_urb->priv, dwc_urb, 0);
  94238. + release_channel(hcd, qh->channel, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94239. +}
  94240. +
  94241. +/**
  94242. + * dwc_otg_fiq_unsetup_per_dma() - Remove data from bounce buffers for split transactions
  94243. + * @hcd: Pointer to dwc_otg_hcd struct
  94244. + * @num: Host channel number
  94245. + *
  94246. + * Copies data from the FIQ bounce buffers into the URB's transfer buffer. Does not modify URB state.
  94247. + * Returns total length of data or -1 if the buffers were not used.
  94248. + *
  94249. + */
  94250. +int dwc_otg_fiq_unsetup_per_dma(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
  94251. +{
  94252. + dwc_hc_t *hc = qh->channel;
  94253. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  94254. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  94255. + uint8_t *ptr = NULL;
  94256. + int index = 0, len = 0;
  94257. + int i = 0;
  94258. + if (hc->ep_is_in) {
  94259. + /* Copy data out of the DMA bounce buffers to the URB's buffer.
  94260. + * The align_buf is ignored as this is ignored on FSM enqueue. */
  94261. + ptr = qtd->urb->buf;
  94262. + if (qh->ep_type == UE_ISOCHRONOUS) {
  94263. + /* Isoc IN transactions - grab the offset of the iso_frame_desc into the URB transfer buffer */
  94264. + index = qtd->isoc_frame_index;
  94265. + ptr += qtd->urb->iso_descs[index].offset;
  94266. + } else {
  94267. + /* Need to increment by actual_length for interrupt IN */
  94268. + ptr += qtd->urb->actual_length;
  94269. + }
  94270. +
  94271. + for (i = 0; i < st->dma_info.index; i++) {
  94272. + len += st->dma_info.slot_len[i];
  94273. + dwc_memcpy(ptr, &blob->channel[num].index[i].buf[0], st->dma_info.slot_len[i]);
  94274. + ptr += st->dma_info.slot_len[i];
  94275. + }
  94276. + return len;
  94277. + } else {
  94278. + /* OUT endpoints - nothing to do. */
  94279. + return -1;
  94280. + }
  94281. +
  94282. +}
  94283. +/**
  94284. + * dwc_otg_hcd_handle_hc_fsm() - handle an unmasked channel interrupt
  94285. + * from a channel handled in the FIQ
  94286. + * @hcd: Pointer to dwc_otg_hcd struct
  94287. + * @num: Host channel number
  94288. + *
  94289. + * If a host channel interrupt was received by the IRQ and this was a channel
  94290. + * used by the FIQ, the execution flow for transfer completion is substantially
  94291. + * different from the normal (messy) path. This function and its friends handles
  94292. + * channel cleanup and transaction completion from a FIQ transaction.
  94293. + */
  94294. +int32_t dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd_t *hcd, uint32_t num)
  94295. +{
  94296. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  94297. + dwc_hc_t *hc = hcd->hc_ptr_array[num];
  94298. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  94299. + dwc_otg_qh_t *qh = hc->qh;
  94300. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[num];
  94301. + hcint_data_t hcint = hcd->fiq_state->channel[num].hcint_copy;
  94302. + int hostchannels = 0;
  94303. + int ret = 0;
  94304. + fiq_print(FIQDBG_INT, hcd->fiq_state, "OUT %01d %01d ", num , st->fsm);
  94305. +
  94306. + hostchannels = hcd->available_host_channels;
  94307. + switch (st->fsm) {
  94308. + case FIQ_TEST:
  94309. + break;
  94310. +
  94311. + case FIQ_DEQUEUE_ISSUED:
  94312. + /* hc_halt was called. QTD no longer exists. */
  94313. + /* TODO: for a nonperiodic split transaction, need to issue a
  94314. + * CLEAR_TT_BUFFER hub command if we were in the start-split phase.
  94315. + */
  94316. + release_channel(hcd, hc, NULL, hc->halt_status);
  94317. + ret = 1;
  94318. + break;
  94319. +
  94320. + case FIQ_NP_SPLIT_DONE:
  94321. + /* Nonperiodic transaction complete. */
  94322. + if (!hc->ep_is_in) {
  94323. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  94324. + }
  94325. + if (hcint.b.xfercomp) {
  94326. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  94327. + } else if (hcint.b.nak) {
  94328. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  94329. + }
  94330. + ret = 1;
  94331. + break;
  94332. +
  94333. + case FIQ_NP_SPLIT_HS_ABORTED:
  94334. + /* A HS abort is a 3-strikes on the HS bus at any point in the transaction.
  94335. + * Normally a CLEAR_TT_BUFFER hub command would be required: we can't do that
  94336. + * because there's no guarantee which order a non-periodic split happened in.
  94337. + * We could end up clearing a perfectly good transaction out of the buffer.
  94338. + */
  94339. + if (hcint.b.xacterr) {
  94340. + qtd->error_count += st->nr_errors;
  94341. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  94342. + } else if (hcint.b.ahberr) {
  94343. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  94344. + } else {
  94345. + local_fiq_disable();
  94346. + BUG();
  94347. + }
  94348. + break;
  94349. +
  94350. + case FIQ_NP_SPLIT_LS_ABORTED:
  94351. + /* A few cases can cause this - either an unknown state on a SSPLIT or
  94352. + * STALL/data toggle error response on a CSPLIT */
  94353. + if (hcint.b.stall) {
  94354. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  94355. + } else if (hcint.b.datatglerr) {
  94356. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  94357. + } else if (hcint.b.bblerr) {
  94358. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  94359. + } else if (hcint.b.ahberr) {
  94360. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  94361. + } else {
  94362. + local_fiq_disable();
  94363. + BUG();
  94364. + }
  94365. + break;
  94366. +
  94367. + case FIQ_PER_SPLIT_DONE:
  94368. + /* Isoc IN or Interrupt IN/OUT */
  94369. +
  94370. + /* Flow control here is different from the normal execution by the driver.
  94371. + * We need to completely ignore most of the driver's method of handling
  94372. + * split transactions and do it ourselves.
  94373. + */
  94374. + if (hc->ep_type == UE_INTERRUPT) {
  94375. + if (hcint.b.nak) {
  94376. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  94377. + } else if (hc->ep_is_in) {
  94378. + int len;
  94379. + len = dwc_otg_fiq_unsetup_per_dma(hcd, hc->qh, qtd, num);
  94380. + //printk(KERN_NOTICE "FIQ Transaction: hc=%d len=%d urb_len = %d\n", num, len, qtd->urb->length);
  94381. + qtd->urb->actual_length += len;
  94382. + if (qtd->urb->actual_length >= qtd->urb->length) {
  94383. + qtd->urb->status = 0;
  94384. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  94385. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94386. + } else {
  94387. + /* Interrupt transfer not complete yet - is it a short read? */
  94388. + if (len < hc->max_packet) {
  94389. + /* Interrupt transaction complete */
  94390. + qtd->urb->status = 0;
  94391. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  94392. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94393. + } else {
  94394. + /* Further transactions required */
  94395. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  94396. + }
  94397. + }
  94398. + } else {
  94399. + /* Interrupt OUT complete. */
  94400. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  94401. + qtd->urb->actual_length += hc->xfer_len;
  94402. + if (qtd->urb->actual_length >= qtd->urb->length) {
  94403. + qtd->urb->status = 0;
  94404. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  94405. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94406. + } else {
  94407. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  94408. + }
  94409. + }
  94410. + } else {
  94411. + /* ISOC IN complete. */
  94412. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  94413. + int len = 0;
  94414. + /* Record errors, update qtd. */
  94415. + if (st->nr_errors) {
  94416. + frame_desc->actual_length = 0;
  94417. + frame_desc->status = -DWC_E_PROTOCOL;
  94418. + } else {
  94419. + frame_desc->status = 0;
  94420. + /* Unswizzle dma */
  94421. + len = dwc_otg_fiq_unsetup_per_dma(hcd, qh, qtd, num);
  94422. + frame_desc->actual_length = len;
  94423. + }
  94424. + qtd->isoc_frame_index++;
  94425. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  94426. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  94427. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94428. + } else {
  94429. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  94430. + }
  94431. + }
  94432. + break;
  94433. +
  94434. + case FIQ_PER_ISO_OUT_DONE: {
  94435. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  94436. + /* Record errors, update qtd. */
  94437. + if (st->nr_errors) {
  94438. + frame_desc->actual_length = 0;
  94439. + frame_desc->status = -DWC_E_PROTOCOL;
  94440. + } else {
  94441. + frame_desc->status = 0;
  94442. + frame_desc->actual_length = frame_desc->length;
  94443. + }
  94444. + qtd->isoc_frame_index++;
  94445. + qtd->isoc_split_offset = 0;
  94446. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  94447. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  94448. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94449. + } else {
  94450. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  94451. + }
  94452. + }
  94453. + break;
  94454. +
  94455. + case FIQ_PER_SPLIT_NYET_ABORTED:
  94456. + /* Doh. lost the data. */
  94457. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  94458. + "- FIQ reported NYET. Data may have been lost.\n",
  94459. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  94460. + if (hc->ep_type == UE_ISOCHRONOUS) {
  94461. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  94462. + /* Record errors, update qtd. */
  94463. + frame_desc->actual_length = 0;
  94464. + frame_desc->status = -DWC_E_PROTOCOL;
  94465. + qtd->isoc_frame_index++;
  94466. + qtd->isoc_split_offset = 0;
  94467. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  94468. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  94469. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94470. + } else {
  94471. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  94472. + }
  94473. + } else {
  94474. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  94475. + }
  94476. + break;
  94477. +
  94478. + case FIQ_HS_ISOC_DONE:
  94479. + /* The FIQ has performed a whole pile of isochronous transactions.
  94480. + * The status is recorded as the interrupt state should the transaction
  94481. + * fail.
  94482. + */
  94483. + dwc_otg_fiq_unmangle_isoc(hcd, qh, qtd, num);
  94484. + break;
  94485. +
  94486. + case FIQ_PER_SPLIT_LS_ABORTED:
  94487. + if (hcint.b.xacterr) {
  94488. + /* Hub has responded with an ERR packet. Device
  94489. + * has been unplugged or the port has been disabled.
  94490. + * TODO: need to issue a reset to the hub port. */
  94491. + qtd->error_count += 3;
  94492. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  94493. + } else if (hcint.b.stall) {
  94494. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  94495. + } else if (hcint.b.bblerr) {
  94496. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  94497. + } else {
  94498. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x failed "
  94499. + "- FIQ reported FSM=%d. Data may have been lost.\n",
  94500. + st->fsm, hc->dev_addr, hc->ep_num);
  94501. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  94502. + }
  94503. + break;
  94504. +
  94505. + case FIQ_PER_SPLIT_HS_ABORTED:
  94506. + /* Either the SSPLIT phase suffered transaction errors or something
  94507. + * unexpected happened.
  94508. + */
  94509. + qtd->error_count += 3;
  94510. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  94511. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  94512. + break;
  94513. +
  94514. + case FIQ_PER_SPLIT_TIMEOUT:
  94515. + /* Couldn't complete in the nominated frame */
  94516. + printk(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  94517. + "- FIQ timed out. Data may have been lost.\n",
  94518. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  94519. + if (hc->ep_type == UE_ISOCHRONOUS) {
  94520. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  94521. + /* Record errors, update qtd. */
  94522. + frame_desc->actual_length = 0;
  94523. + if (hc->ep_is_in) {
  94524. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  94525. + } else {
  94526. + frame_desc->status = -DWC_E_COMMUNICATION;
  94527. + }
  94528. + qtd->isoc_frame_index++;
  94529. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  94530. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  94531. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94532. + } else {
  94533. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  94534. + }
  94535. + } else {
  94536. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  94537. + }
  94538. + break;
  94539. +
  94540. + default:
  94541. + local_fiq_disable();
  94542. + DWC_WARN("unexpected state received on hc=%d fsm=%d", hc->hc_num, st->fsm);
  94543. + BUG();
  94544. + }
  94545. + //if (hostchannels != hcd->available_host_channels) {
  94546. + /* should have incremented by now! */
  94547. + // BUG();
  94548. +// }
  94549. + return ret;
  94550. +}
  94551. +
  94552. +/** Handles interrupt for a specific Host Channel */
  94553. +int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
  94554. +{
  94555. + int retval = 0;
  94556. + hcint_data_t hcint;
  94557. + hcintmsk_data_t hcintmsk;
  94558. + dwc_hc_t *hc;
  94559. + dwc_otg_hc_regs_t *hc_regs;
  94560. + dwc_otg_qtd_t *qtd;
  94561. +
  94562. + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
  94563. +
  94564. + hc = dwc_otg_hcd->hc_ptr_array[num];
  94565. + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
  94566. + if(hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  94567. + /* We are responding to a channel disable. Driver
  94568. + * state is cleared - our qtd has gone away.
  94569. + */
  94570. + release_channel(dwc_otg_hcd, hc, NULL, hc->halt_status);
  94571. + return 1;
  94572. + }
  94573. + qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  94574. +
  94575. + /*
  94576. + * FSM mode: Check to see if this is a HC interrupt from a channel handled by the FIQ.
  94577. + * Execution path is fundamentally different for the channels after a FIQ has completed
  94578. + * a split transaction.
  94579. + */
  94580. + if (fiq_fsm_enable) {
  94581. + switch (dwc_otg_hcd->fiq_state->channel[num].fsm) {
  94582. + case FIQ_PASSTHROUGH:
  94583. + break;
  94584. + case FIQ_PASSTHROUGH_ERRORSTATE:
  94585. + /* Hook into the error count */
  94586. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "HCDERR%02d", num);
  94587. + if (!dwc_otg_hcd->fiq_state->channel[num].nr_errors) {
  94588. + qtd->error_count = 0;
  94589. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "RESET ");
  94590. + }
  94591. + break;
  94592. + default:
  94593. + dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd, num);
  94594. + return 1;
  94595. + }
  94596. + }
  94597. +
  94598. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  94599. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  94600. + hcint.d32 = hcint.d32 & hcintmsk.d32;
  94601. + if (!dwc_otg_hcd->core_if->dma_enable) {
  94602. + if (hcint.b.chhltd && hcint.d32 != 0x2) {
  94603. + hcint.b.chhltd = 0;
  94604. + }
  94605. + }
  94606. +
  94607. + if (hcint.b.xfercomp) {
  94608. + retval |=
  94609. + handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  94610. + /*
  94611. + * If NYET occurred at same time as Xfer Complete, the NYET is
  94612. + * handled by the Xfer Complete interrupt handler. Don't want
  94613. + * to call the NYET interrupt handler in this case.
  94614. + */
  94615. + hcint.b.nyet = 0;
  94616. + }
  94617. + if (hcint.b.chhltd) {
  94618. + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  94619. + }
  94620. + if (hcint.b.ahberr) {
  94621. + retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  94622. + }
  94623. + if (hcint.b.stall) {
  94624. + retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  94625. + }
  94626. + if (hcint.b.nak) {
  94627. + retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  94628. + }
  94629. + if (hcint.b.ack) {
  94630. + if(!hcint.b.chhltd)
  94631. + retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  94632. + }
  94633. + if (hcint.b.nyet) {
  94634. + retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  94635. + }
  94636. + if (hcint.b.xacterr) {
  94637. + retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  94638. + }
  94639. + if (hcint.b.bblerr) {
  94640. + retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  94641. + }
  94642. + if (hcint.b.frmovrun) {
  94643. + retval |=
  94644. + handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  94645. + }
  94646. + if (hcint.b.datatglerr) {
  94647. + retval |=
  94648. + handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  94649. + }
  94650. +
  94651. + return retval;
  94652. +}
  94653. +#endif /* DWC_DEVICE_ONLY */
  94654. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
  94655. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  94656. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 2015-02-09 04:40:29.000000000 +0100
  94657. @@ -0,0 +1,994 @@
  94658. +
  94659. +/* ==========================================================================
  94660. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_linux.c $
  94661. + * $Revision: #20 $
  94662. + * $Date: 2011/10/26 $
  94663. + * $Change: 1872981 $
  94664. + *
  94665. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  94666. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  94667. + * otherwise expressly agreed to in writing between Synopsys and you.
  94668. + *
  94669. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  94670. + * any End User Software License Agreement or Agreement for Licensed Product
  94671. + * with Synopsys or any supplement thereto. You are permitted to use and
  94672. + * redistribute this Software in source and binary forms, with or without
  94673. + * modification, provided that redistributions of source code must retain this
  94674. + * notice. You may not view, use, disclose, copy or distribute this file or
  94675. + * any information contained herein except pursuant to this license grant from
  94676. + * Synopsys. If you do not agree with this notice, including the disclaimer
  94677. + * below, then you are not authorized to use the Software.
  94678. + *
  94679. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  94680. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  94681. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  94682. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  94683. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  94684. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  94685. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  94686. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  94687. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  94688. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  94689. + * DAMAGE.
  94690. + * ========================================================================== */
  94691. +#ifndef DWC_DEVICE_ONLY
  94692. +
  94693. +/**
  94694. + * @file
  94695. + *
  94696. + * This file contains the implementation of the HCD. In Linux, the HCD
  94697. + * implements the hc_driver API.
  94698. + */
  94699. +#include <linux/kernel.h>
  94700. +#include <linux/module.h>
  94701. +#include <linux/moduleparam.h>
  94702. +#include <linux/init.h>
  94703. +#include <linux/device.h>
  94704. +#include <linux/errno.h>
  94705. +#include <linux/list.h>
  94706. +#include <linux/interrupt.h>
  94707. +#include <linux/string.h>
  94708. +#include <linux/dma-mapping.h>
  94709. +#include <linux/version.h>
  94710. +#include <asm/io.h>
  94711. +#include <asm/fiq.h>
  94712. +#include <linux/usb.h>
  94713. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
  94714. +#include <../drivers/usb/core/hcd.h>
  94715. +#else
  94716. +#include <linux/usb/hcd.h>
  94717. +#endif
  94718. +#include <asm/bug.h>
  94719. +
  94720. +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  94721. +#define USB_URB_EP_LINKING 1
  94722. +#else
  94723. +#define USB_URB_EP_LINKING 0
  94724. +#endif
  94725. +
  94726. +#include "dwc_otg_hcd_if.h"
  94727. +#include "dwc_otg_dbg.h"
  94728. +#include "dwc_otg_driver.h"
  94729. +#include "dwc_otg_hcd.h"
  94730. +
  94731. +extern unsigned char _dwc_otg_fiq_stub, _dwc_otg_fiq_stub_end;
  94732. +
  94733. +/**
  94734. + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
  94735. + * qualified with its direction (possible 32 endpoints per device).
  94736. + */
  94737. +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
  94738. + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
  94739. +
  94740. +static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
  94741. +
  94742. +extern bool fiq_enable;
  94743. +
  94744. +/** @name Linux HC Driver API Functions */
  94745. +/** @{ */
  94746. +/* manage i/o requests, device state */
  94747. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  94748. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  94749. + struct usb_host_endpoint *ep,
  94750. +#endif
  94751. + struct urb *urb, gfp_t mem_flags);
  94752. +
  94753. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  94754. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  94755. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb);
  94756. +#endif
  94757. +#else /* kernels at or post 2.6.30 */
  94758. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd,
  94759. + struct urb *urb, int status);
  94760. +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */
  94761. +
  94762. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  94763. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  94764. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  94765. +#endif
  94766. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
  94767. +extern int hcd_start(struct usb_hcd *hcd);
  94768. +extern void hcd_stop(struct usb_hcd *hcd);
  94769. +static int get_frame_number(struct usb_hcd *hcd);
  94770. +extern int hub_status_data(struct usb_hcd *hcd, char *buf);
  94771. +extern int hub_control(struct usb_hcd *hcd,
  94772. + u16 typeReq,
  94773. + u16 wValue, u16 wIndex, char *buf, u16 wLength);
  94774. +
  94775. +struct wrapper_priv_data {
  94776. + dwc_otg_hcd_t *dwc_otg_hcd;
  94777. +};
  94778. +
  94779. +/** @} */
  94780. +
  94781. +static struct hc_driver dwc_otg_hc_driver = {
  94782. +
  94783. + .description = dwc_otg_hcd_name,
  94784. + .product_desc = "DWC OTG Controller",
  94785. + .hcd_priv_size = sizeof(struct wrapper_priv_data),
  94786. +
  94787. + .irq = dwc_otg_hcd_irq,
  94788. +
  94789. + .flags = HCD_MEMORY | HCD_USB2,
  94790. +
  94791. + //.reset =
  94792. + .start = hcd_start,
  94793. + //.suspend =
  94794. + //.resume =
  94795. + .stop = hcd_stop,
  94796. +
  94797. + .urb_enqueue = dwc_otg_urb_enqueue,
  94798. + .urb_dequeue = dwc_otg_urb_dequeue,
  94799. + .endpoint_disable = endpoint_disable,
  94800. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  94801. + .endpoint_reset = endpoint_reset,
  94802. +#endif
  94803. + .get_frame_number = get_frame_number,
  94804. +
  94805. + .hub_status_data = hub_status_data,
  94806. + .hub_control = hub_control,
  94807. + //.bus_suspend =
  94808. + //.bus_resume =
  94809. +};
  94810. +
  94811. +/** Gets the dwc_otg_hcd from a struct usb_hcd */
  94812. +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
  94813. +{
  94814. + struct wrapper_priv_data *p;
  94815. + p = (struct wrapper_priv_data *)(hcd->hcd_priv);
  94816. + return p->dwc_otg_hcd;
  94817. +}
  94818. +
  94819. +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
  94820. +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t * dwc_otg_hcd)
  94821. +{
  94822. + return dwc_otg_hcd_get_priv_data(dwc_otg_hcd);
  94823. +}
  94824. +
  94825. +/** Gets the usb_host_endpoint associated with an URB. */
  94826. +inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
  94827. +{
  94828. + struct usb_device *dev = urb->dev;
  94829. + int ep_num = usb_pipeendpoint(urb->pipe);
  94830. +
  94831. + if (usb_pipein(urb->pipe))
  94832. + return dev->ep_in[ep_num];
  94833. + else
  94834. + return dev->ep_out[ep_num];
  94835. +}
  94836. +
  94837. +static int _disconnect(dwc_otg_hcd_t * hcd)
  94838. +{
  94839. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  94840. +
  94841. + usb_hcd->self.is_b_host = 0;
  94842. + return 0;
  94843. +}
  94844. +
  94845. +static int _start(dwc_otg_hcd_t * hcd)
  94846. +{
  94847. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  94848. +
  94849. + usb_hcd->self.is_b_host = dwc_otg_hcd_is_b_host(hcd);
  94850. + hcd_start(usb_hcd);
  94851. +
  94852. + return 0;
  94853. +}
  94854. +
  94855. +static int _hub_info(dwc_otg_hcd_t * hcd, void *urb_handle, uint32_t * hub_addr,
  94856. + uint32_t * port_addr)
  94857. +{
  94858. + struct urb *urb = (struct urb *)urb_handle;
  94859. + struct usb_bus *bus;
  94860. +#if 1 //GRAYG - temporary
  94861. + if (NULL == urb_handle)
  94862. + DWC_ERROR("**** %s - NULL URB handle\n", __func__);//GRAYG
  94863. + if (NULL == urb->dev)
  94864. + DWC_ERROR("**** %s - URB has no device\n", __func__);//GRAYG
  94865. + if (NULL == port_addr)
  94866. + DWC_ERROR("**** %s - NULL port_address\n", __func__);//GRAYG
  94867. +#endif
  94868. + if (urb->dev->tt) {
  94869. + if (NULL == urb->dev->tt->hub) {
  94870. + DWC_ERROR("**** %s - (URB's transactor has no TT - giving no hub)\n",
  94871. + __func__); //GRAYG
  94872. + //*hub_addr = (u8)usb_pipedevice(urb->pipe); //GRAYG
  94873. + *hub_addr = 0; //GRAYG
  94874. + // we probably shouldn't have a transaction translator if
  94875. + // there's no associated hub?
  94876. + } else {
  94877. + bus = hcd_to_bus(dwc_otg_hcd_to_hcd(hcd));
  94878. + if (urb->dev->tt->hub == bus->root_hub)
  94879. + *hub_addr = 0;
  94880. + else
  94881. + *hub_addr = urb->dev->tt->hub->devnum;
  94882. + }
  94883. + *port_addr = urb->dev->tt->multi ? urb->dev->ttport : 1;
  94884. + } else {
  94885. + *hub_addr = 0;
  94886. + *port_addr = urb->dev->ttport;
  94887. + }
  94888. + return 0;
  94889. +}
  94890. +
  94891. +static int _speed(dwc_otg_hcd_t * hcd, void *urb_handle)
  94892. +{
  94893. + struct urb *urb = (struct urb *)urb_handle;
  94894. + return urb->dev->speed;
  94895. +}
  94896. +
  94897. +static int _get_b_hnp_enable(dwc_otg_hcd_t * hcd)
  94898. +{
  94899. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  94900. + return usb_hcd->self.b_hnp_enable;
  94901. +}
  94902. +
  94903. +static void allocate_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  94904. + struct urb *urb)
  94905. +{
  94906. + hcd_to_bus(hcd)->bandwidth_allocated += bw / urb->interval;
  94907. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  94908. + hcd_to_bus(hcd)->bandwidth_isoc_reqs++;
  94909. + } else {
  94910. + hcd_to_bus(hcd)->bandwidth_int_reqs++;
  94911. + }
  94912. +}
  94913. +
  94914. +static void free_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  94915. + struct urb *urb)
  94916. +{
  94917. + hcd_to_bus(hcd)->bandwidth_allocated -= bw / urb->interval;
  94918. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  94919. + hcd_to_bus(hcd)->bandwidth_isoc_reqs--;
  94920. + } else {
  94921. + hcd_to_bus(hcd)->bandwidth_int_reqs--;
  94922. + }
  94923. +}
  94924. +
  94925. +/**
  94926. + * Sets the final status of an URB and returns it to the device driver. Any
  94927. + * required cleanup of the URB is performed. The HCD lock should be held on
  94928. + * entry.
  94929. + */
  94930. +static int _complete(dwc_otg_hcd_t * hcd, void *urb_handle,
  94931. + dwc_otg_hcd_urb_t * dwc_otg_urb, int32_t status)
  94932. +{
  94933. + struct urb *urb = (struct urb *)urb_handle;
  94934. + urb_tq_entry_t *new_entry;
  94935. + int rc = 0;
  94936. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  94937. + DWC_PRINTF("%s: urb %p, device %d, ep %d %s, status=%d\n",
  94938. + __func__, urb, usb_pipedevice(urb->pipe),
  94939. + usb_pipeendpoint(urb->pipe),
  94940. + usb_pipein(urb->pipe) ? "IN" : "OUT", status);
  94941. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  94942. + int i;
  94943. + for (i = 0; i < urb->number_of_packets; i++) {
  94944. + DWC_PRINTF(" ISO Desc %d status: %d\n",
  94945. + i, urb->iso_frame_desc[i].status);
  94946. + }
  94947. + }
  94948. + }
  94949. + new_entry = DWC_ALLOC_ATOMIC(sizeof(urb_tq_entry_t));
  94950. + urb->actual_length = dwc_otg_hcd_urb_get_actual_length(dwc_otg_urb);
  94951. + /* Convert status value. */
  94952. + switch (status) {
  94953. + case -DWC_E_PROTOCOL:
  94954. + status = -EPROTO;
  94955. + break;
  94956. + case -DWC_E_IN_PROGRESS:
  94957. + status = -EINPROGRESS;
  94958. + break;
  94959. + case -DWC_E_PIPE:
  94960. + status = -EPIPE;
  94961. + break;
  94962. + case -DWC_E_IO:
  94963. + status = -EIO;
  94964. + break;
  94965. + case -DWC_E_TIMEOUT:
  94966. + status = -ETIMEDOUT;
  94967. + break;
  94968. + case -DWC_E_OVERFLOW:
  94969. + status = -EOVERFLOW;
  94970. + break;
  94971. + case -DWC_E_SHUTDOWN:
  94972. + status = -ESHUTDOWN;
  94973. + break;
  94974. + default:
  94975. + if (status) {
  94976. + DWC_PRINTF("Uknown urb status %d\n", status);
  94977. +
  94978. + }
  94979. + }
  94980. +
  94981. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  94982. + int i;
  94983. +
  94984. + urb->error_count = dwc_otg_hcd_urb_get_error_count(dwc_otg_urb);
  94985. + for (i = 0; i < urb->number_of_packets; ++i) {
  94986. + urb->iso_frame_desc[i].actual_length =
  94987. + dwc_otg_hcd_urb_get_iso_desc_actual_length
  94988. + (dwc_otg_urb, i);
  94989. + urb->iso_frame_desc[i].status =
  94990. + dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_urb, i);
  94991. + }
  94992. + }
  94993. +
  94994. + urb->status = status;
  94995. + urb->hcpriv = NULL;
  94996. + if (!status) {
  94997. + if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
  94998. + (urb->actual_length < urb->transfer_buffer_length)) {
  94999. + urb->status = -EREMOTEIO;
  95000. + }
  95001. + }
  95002. +
  95003. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) ||
  95004. + (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  95005. + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
  95006. + if (ep) {
  95007. + free_bus_bandwidth(dwc_otg_hcd_to_hcd(hcd),
  95008. + dwc_otg_hcd_get_ep_bandwidth(hcd,
  95009. + ep->hcpriv),
  95010. + urb);
  95011. + }
  95012. + }
  95013. + DWC_FREE(dwc_otg_urb);
  95014. + if (!new_entry) {
  95015. + DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
  95016. + urb->status = -EPROTO;
  95017. + /* don't schedule the tasklet -
  95018. + * directly return the packet here with error. */
  95019. +#if USB_URB_EP_LINKING
  95020. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  95021. +#endif
  95022. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  95023. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb);
  95024. +#else
  95025. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  95026. +#endif
  95027. + } else {
  95028. + new_entry->urb = urb;
  95029. +#if USB_URB_EP_LINKING
  95030. + rc = usb_hcd_check_unlink_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  95031. + if(0 == rc) {
  95032. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  95033. + }
  95034. +#endif
  95035. + if(0 == rc) {
  95036. + DWC_TAILQ_INSERT_TAIL(&hcd->completed_urb_list, new_entry,
  95037. + urb_tq_entries);
  95038. + DWC_TASK_HI_SCHEDULE(hcd->completion_tasklet);
  95039. + }
  95040. + }
  95041. + return 0;
  95042. +}
  95043. +
  95044. +static struct dwc_otg_hcd_function_ops hcd_fops = {
  95045. + .start = _start,
  95046. + .disconnect = _disconnect,
  95047. + .hub_info = _hub_info,
  95048. + .speed = _speed,
  95049. + .complete = _complete,
  95050. + .get_b_hnp_enable = _get_b_hnp_enable,
  95051. +};
  95052. +
  95053. +static struct fiq_handler fh = {
  95054. + .name = "usb_fiq",
  95055. +};
  95056. +
  95057. +static void hcd_init_fiq(void *cookie)
  95058. +{
  95059. + dwc_otg_device_t *otg_dev = cookie;
  95060. + dwc_otg_hcd_t *dwc_otg_hcd = otg_dev->hcd;
  95061. + struct pt_regs regs;
  95062. +
  95063. + if (claim_fiq(&fh)) {
  95064. + DWC_ERROR("Can't claim FIQ");
  95065. + BUG();
  95066. + }
  95067. + DWC_WARN("FIQ on core %d at 0x%08x",
  95068. + smp_processor_id(),
  95069. + (fiq_fsm_enable ? (int)&dwc_otg_fiq_fsm : (int)&dwc_otg_fiq_nop));
  95070. + DWC_WARN("FIQ ASM at 0x%08x length %d", (int)&_dwc_otg_fiq_stub, (int)(&_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub));
  95071. + set_fiq_handler((void *) &_dwc_otg_fiq_stub, &_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub);
  95072. + memset(&regs,0,sizeof(regs));
  95073. +
  95074. + regs.ARM_r8 = (long) dwc_otg_hcd->fiq_state;
  95075. + if (fiq_fsm_enable) {
  95076. + regs.ARM_r9 = dwc_otg_hcd->core_if->core_params->host_channels;
  95077. + //regs.ARM_r10 = dwc_otg_hcd->dma;
  95078. + regs.ARM_fp = (long) dwc_otg_fiq_fsm;
  95079. + } else {
  95080. + regs.ARM_fp = (long) dwc_otg_fiq_nop;
  95081. + }
  95082. +
  95083. + regs.ARM_sp = (long) dwc_otg_hcd->fiq_stack + (sizeof(struct fiq_stack) - 4);
  95084. +
  95085. +// __show_regs(&regs);
  95086. + set_fiq_regs(&regs);
  95087. +
  95088. + //Set the mphi periph to the required registers
  95089. + dwc_otg_hcd->fiq_state->mphi_regs.base = otg_dev->os_dep.mphi_base;
  95090. + dwc_otg_hcd->fiq_state->mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
  95091. + dwc_otg_hcd->fiq_state->mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
  95092. + dwc_otg_hcd->fiq_state->mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
  95093. + dwc_otg_hcd->fiq_state->mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
  95094. + dwc_otg_hcd->fiq_state->dwc_regs_base = otg_dev->os_dep.base;
  95095. + DWC_WARN("MPHI regs_base at 0x%08x", (int)dwc_otg_hcd->fiq_state->mphi_regs.base);
  95096. + //Enable mphi peripheral
  95097. + writel((1<<31),dwc_otg_hcd->fiq_state->mphi_regs.ctrl);
  95098. +#ifdef DEBUG
  95099. + if (readl(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & 0x80000000)
  95100. + DWC_WARN("MPHI periph has been enabled");
  95101. + else
  95102. + DWC_WARN("MPHI periph has NOT been enabled");
  95103. +#endif
  95104. + // Enable FIQ interrupt from USB peripheral
  95105. + enable_fiq(INTERRUPT_VC_USB);
  95106. + local_fiq_enable();
  95107. +}
  95108. +
  95109. +/**
  95110. + * Initializes the HCD. This function allocates memory for and initializes the
  95111. + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
  95112. + * USB bus with the core and calls the hc_driver->start() function. It returns
  95113. + * a negative error on failure.
  95114. + */
  95115. +int hcd_init(dwc_bus_dev_t *_dev)
  95116. +{
  95117. + struct usb_hcd *hcd = NULL;
  95118. + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
  95119. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  95120. + int retval = 0;
  95121. + u64 dmamask;
  95122. +
  95123. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT otg_dev=%p\n", otg_dev);
  95124. +
  95125. + /* Set device flags indicating whether the HCD supports DMA. */
  95126. + if (dwc_otg_is_dma_enable(otg_dev->core_if))
  95127. + dmamask = DMA_BIT_MASK(32);
  95128. + else
  95129. + dmamask = 0;
  95130. +
  95131. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  95132. + dma_set_mask(&_dev->dev, dmamask);
  95133. + dma_set_coherent_mask(&_dev->dev, dmamask);
  95134. +#elif defined(PCI_INTERFACE)
  95135. + pci_set_dma_mask(_dev, dmamask);
  95136. + pci_set_consistent_dma_mask(_dev, dmamask);
  95137. +#endif
  95138. +
  95139. + /*
  95140. + * Allocate memory for the base HCD plus the DWC OTG HCD.
  95141. + * Initialize the base HCD.
  95142. + */
  95143. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  95144. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, _dev->dev.bus_id);
  95145. +#else
  95146. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, dev_name(&_dev->dev));
  95147. + hcd->has_tt = 1;
  95148. +// hcd->uses_new_polling = 1;
  95149. +// hcd->poll_rh = 0;
  95150. +#endif
  95151. + if (!hcd) {
  95152. + retval = -ENOMEM;
  95153. + goto error1;
  95154. + }
  95155. +
  95156. + hcd->regs = otg_dev->os_dep.base;
  95157. +
  95158. +
  95159. + /* Initialize the DWC OTG HCD. */
  95160. + dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
  95161. + if (!dwc_otg_hcd) {
  95162. + goto error2;
  95163. + }
  95164. + ((struct wrapper_priv_data *)(hcd->hcd_priv))->dwc_otg_hcd =
  95165. + dwc_otg_hcd;
  95166. + otg_dev->hcd = dwc_otg_hcd;
  95167. +
  95168. + if (dwc_otg_hcd_init(dwc_otg_hcd, otg_dev->core_if)) {
  95169. + goto error2;
  95170. + }
  95171. +
  95172. + if (fiq_enable) {
  95173. + if (num_online_cpus() > 1) {
  95174. + /* bcm2709: can run the FIQ on a separate core to IRQs */
  95175. + smp_call_function_single(1, hcd_init_fiq, otg_dev, 1);
  95176. + } else {
  95177. + smp_call_function_single(0, hcd_init_fiq, otg_dev, 1);
  95178. + }
  95179. + }
  95180. +
  95181. + otg_dev->hcd->otg_dev = otg_dev;
  95182. + hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
  95183. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
  95184. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) //version field absent later
  95185. + hcd->self.otg_version = dwc_otg_get_otg_version(otg_dev->core_if);
  95186. +#endif
  95187. + /* Don't support SG list at this point */
  95188. + hcd->self.sg_tablesize = 0;
  95189. +#endif
  95190. + /*
  95191. + * Finish generic HCD initialization and start the HCD. This function
  95192. + * allocates the DMA buffer pool, registers the USB bus, requests the
  95193. + * IRQ line, and calls hcd_start method.
  95194. + */
  95195. +#ifdef PLATFORM_INTERFACE
  95196. + retval = usb_add_hcd(hcd, platform_get_irq(_dev, fiq_enable ? 0 : 1), IRQF_SHARED | IRQF_DISABLED);
  95197. +#else
  95198. + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
  95199. +#endif
  95200. + if (retval < 0) {
  95201. + goto error2;
  95202. + }
  95203. +
  95204. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, hcd);
  95205. + return 0;
  95206. +
  95207. +error2:
  95208. + usb_put_hcd(hcd);
  95209. +error1:
  95210. + return retval;
  95211. +}
  95212. +
  95213. +/**
  95214. + * Removes the HCD.
  95215. + * Frees memory and resources associated with the HCD and deregisters the bus.
  95216. + */
  95217. +void hcd_remove(dwc_bus_dev_t *_dev)
  95218. +{
  95219. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  95220. + dwc_otg_hcd_t *dwc_otg_hcd;
  95221. + struct usb_hcd *hcd;
  95222. +
  95223. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE otg_dev=%p\n", otg_dev);
  95224. +
  95225. + if (!otg_dev) {
  95226. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  95227. + return;
  95228. + }
  95229. +
  95230. + dwc_otg_hcd = otg_dev->hcd;
  95231. +
  95232. + if (!dwc_otg_hcd) {
  95233. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  95234. + return;
  95235. + }
  95236. +
  95237. + hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
  95238. +
  95239. + if (!hcd) {
  95240. + DWC_DEBUGPL(DBG_ANY,
  95241. + "%s: dwc_otg_hcd_to_hcd(dwc_otg_hcd) NULL!\n",
  95242. + __func__);
  95243. + return;
  95244. + }
  95245. + usb_remove_hcd(hcd);
  95246. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, NULL);
  95247. + dwc_otg_hcd_remove(dwc_otg_hcd);
  95248. + usb_put_hcd(hcd);
  95249. +}
  95250. +
  95251. +/* =========================================================================
  95252. + * Linux HC Driver Functions
  95253. + * ========================================================================= */
  95254. +
  95255. +/** Initializes the DWC_otg controller and its root hub and prepares it for host
  95256. + * mode operation. Activates the root port. Returns 0 on success and a negative
  95257. + * error code on failure. */
  95258. +int hcd_start(struct usb_hcd *hcd)
  95259. +{
  95260. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  95261. + struct usb_bus *bus;
  95262. +
  95263. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
  95264. + bus = hcd_to_bus(hcd);
  95265. +
  95266. + hcd->state = HC_STATE_RUNNING;
  95267. + if (dwc_otg_hcd_start(dwc_otg_hcd, &hcd_fops)) {
  95268. + return 0;
  95269. + }
  95270. +
  95271. + /* Initialize and connect root hub if one is not already attached */
  95272. + if (bus->root_hub) {
  95273. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
  95274. + /* Inform the HUB driver to resume. */
  95275. + usb_hcd_resume_root_hub(hcd);
  95276. + }
  95277. +
  95278. + return 0;
  95279. +}
  95280. +
  95281. +/**
  95282. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  95283. + * stopped.
  95284. + */
  95285. +void hcd_stop(struct usb_hcd *hcd)
  95286. +{
  95287. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  95288. +
  95289. + dwc_otg_hcd_stop(dwc_otg_hcd);
  95290. +}
  95291. +
  95292. +/** Returns the current frame number. */
  95293. +static int get_frame_number(struct usb_hcd *hcd)
  95294. +{
  95295. + hprt0_data_t hprt0;
  95296. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  95297. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  95298. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  95299. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd) >> 3;
  95300. + else
  95301. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
  95302. +}
  95303. +
  95304. +#ifdef DEBUG
  95305. +static void dump_urb_info(struct urb *urb, char *fn_name)
  95306. +{
  95307. + DWC_PRINTF("%s, urb %p\n", fn_name, urb);
  95308. + DWC_PRINTF(" Device address: %d\n", usb_pipedevice(urb->pipe));
  95309. + DWC_PRINTF(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
  95310. + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
  95311. + DWC_PRINTF(" Endpoint type: %s\n", ( {
  95312. + char *pipetype;
  95313. + switch (usb_pipetype(urb->pipe)) {
  95314. +case PIPE_CONTROL:
  95315. +pipetype = "CONTROL"; break; case PIPE_BULK:
  95316. +pipetype = "BULK"; break; case PIPE_INTERRUPT:
  95317. +pipetype = "INTERRUPT"; break; case PIPE_ISOCHRONOUS:
  95318. +pipetype = "ISOCHRONOUS"; break; default:
  95319. + pipetype = "UNKNOWN"; break;};
  95320. + pipetype;}
  95321. + )) ;
  95322. + DWC_PRINTF(" Speed: %s\n", ( {
  95323. + char *speed; switch (urb->dev->speed) {
  95324. +case USB_SPEED_HIGH:
  95325. +speed = "HIGH"; break; case USB_SPEED_FULL:
  95326. +speed = "FULL"; break; case USB_SPEED_LOW:
  95327. +speed = "LOW"; break; default:
  95328. + speed = "UNKNOWN"; break;};
  95329. + speed;}
  95330. + )) ;
  95331. + DWC_PRINTF(" Max packet size: %d\n",
  95332. + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
  95333. + DWC_PRINTF(" Data buffer length: %d\n", urb->transfer_buffer_length);
  95334. + DWC_PRINTF(" Transfer buffer: %p, Transfer DMA: %p\n",
  95335. + urb->transfer_buffer, (void *)urb->transfer_dma);
  95336. + DWC_PRINTF(" Setup buffer: %p, Setup DMA: %p\n",
  95337. + urb->setup_packet, (void *)urb->setup_dma);
  95338. + DWC_PRINTF(" Interval: %d\n", urb->interval);
  95339. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  95340. + int i;
  95341. + for (i = 0; i < urb->number_of_packets; i++) {
  95342. + DWC_PRINTF(" ISO Desc %d:\n", i);
  95343. + DWC_PRINTF(" offset: %d, length %d\n",
  95344. + urb->iso_frame_desc[i].offset,
  95345. + urb->iso_frame_desc[i].length);
  95346. + }
  95347. + }
  95348. +}
  95349. +#endif
  95350. +
  95351. +/** Starts processing a USB transfer request specified by a USB Request Block
  95352. + * (URB). mem_flags indicates the type of memory allocation to use while
  95353. + * processing this URB. */
  95354. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  95355. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  95356. + struct usb_host_endpoint *ep,
  95357. +#endif
  95358. + struct urb *urb, gfp_t mem_flags)
  95359. +{
  95360. + int retval = 0;
  95361. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
  95362. + struct usb_host_endpoint *ep = urb->ep;
  95363. +#endif
  95364. + dwc_irqflags_t irqflags;
  95365. + void **ref_ep_hcpriv = &ep->hcpriv;
  95366. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  95367. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  95368. + int i;
  95369. + int alloc_bandwidth = 0;
  95370. + uint8_t ep_type = 0;
  95371. + uint32_t flags = 0;
  95372. + void *buf;
  95373. +
  95374. +#ifdef DEBUG
  95375. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  95376. + dump_urb_info(urb, "dwc_otg_urb_enqueue");
  95377. + }
  95378. +#endif
  95379. +
  95380. + if (!urb->transfer_buffer && urb->transfer_buffer_length)
  95381. + return -EINVAL;
  95382. +
  95383. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
  95384. + || (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  95385. + if (!dwc_otg_hcd_is_bandwidth_allocated
  95386. + (dwc_otg_hcd, ref_ep_hcpriv)) {
  95387. + alloc_bandwidth = 1;
  95388. + }
  95389. + }
  95390. +
  95391. + switch (usb_pipetype(urb->pipe)) {
  95392. + case PIPE_CONTROL:
  95393. + ep_type = USB_ENDPOINT_XFER_CONTROL;
  95394. + break;
  95395. + case PIPE_ISOCHRONOUS:
  95396. + ep_type = USB_ENDPOINT_XFER_ISOC;
  95397. + break;
  95398. + case PIPE_BULK:
  95399. + ep_type = USB_ENDPOINT_XFER_BULK;
  95400. + break;
  95401. + case PIPE_INTERRUPT:
  95402. + ep_type = USB_ENDPOINT_XFER_INT;
  95403. + break;
  95404. + default:
  95405. + DWC_WARN("Wrong EP type - %d\n", usb_pipetype(urb->pipe));
  95406. + }
  95407. +
  95408. + /* # of packets is often 0 - do we really need to call this then? */
  95409. + dwc_otg_urb = dwc_otg_hcd_urb_alloc(dwc_otg_hcd,
  95410. + urb->number_of_packets,
  95411. + mem_flags == GFP_ATOMIC ? 1 : 0);
  95412. +
  95413. + if(dwc_otg_urb == NULL)
  95414. + return -ENOMEM;
  95415. +
  95416. + if (!dwc_otg_urb && urb->number_of_packets)
  95417. + return -ENOMEM;
  95418. +
  95419. + dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_urb, usb_pipedevice(urb->pipe),
  95420. + usb_pipeendpoint(urb->pipe), ep_type,
  95421. + usb_pipein(urb->pipe),
  95422. + usb_maxpacket(urb->dev, urb->pipe,
  95423. + !(usb_pipein(urb->pipe))));
  95424. +
  95425. + buf = urb->transfer_buffer;
  95426. + if (hcd->self.uses_dma) {
  95427. + /*
  95428. + * Calculate virtual address from physical address,
  95429. + * because some class driver may not fill transfer_buffer.
  95430. + * In Buffer DMA mode virual address is used,
  95431. + * when handling non DWORD aligned buffers.
  95432. + */
  95433. + //buf = phys_to_virt(urb->transfer_dma);
  95434. + // DMA addresses are bus addresses not physical addresses!
  95435. + buf = dma_to_virt(&urb->dev->dev, urb->transfer_dma);
  95436. + }
  95437. +
  95438. + if (!(urb->transfer_flags & URB_NO_INTERRUPT))
  95439. + flags |= URB_GIVEBACK_ASAP;
  95440. + if (urb->transfer_flags & URB_ZERO_PACKET)
  95441. + flags |= URB_SEND_ZERO_PACKET;
  95442. +
  95443. + dwc_otg_hcd_urb_set_params(dwc_otg_urb, urb, buf,
  95444. + urb->transfer_dma,
  95445. + urb->transfer_buffer_length,
  95446. + urb->setup_packet,
  95447. + urb->setup_dma, flags, urb->interval);
  95448. +
  95449. + for (i = 0; i < urb->number_of_packets; ++i) {
  95450. + dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_urb, i,
  95451. + urb->
  95452. + iso_frame_desc[i].offset,
  95453. + urb->
  95454. + iso_frame_desc[i].length);
  95455. + }
  95456. +
  95457. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &irqflags);
  95458. + urb->hcpriv = dwc_otg_urb;
  95459. +#if USB_URB_EP_LINKING
  95460. + retval = usb_hcd_link_urb_to_ep(hcd, urb);
  95461. + if (0 == retval)
  95462. +#endif
  95463. + {
  95464. + retval = dwc_otg_hcd_urb_enqueue(dwc_otg_hcd, dwc_otg_urb,
  95465. + /*(dwc_otg_qh_t **)*/
  95466. + ref_ep_hcpriv, 1);
  95467. + if (0 == retval) {
  95468. + if (alloc_bandwidth) {
  95469. + allocate_bus_bandwidth(hcd,
  95470. + dwc_otg_hcd_get_ep_bandwidth(
  95471. + dwc_otg_hcd, *ref_ep_hcpriv),
  95472. + urb);
  95473. + }
  95474. + } else {
  95475. + DWC_DEBUGPL(DBG_HCD, "DWC OTG dwc_otg_hcd_urb_enqueue failed rc %d\n", retval);
  95476. +#if USB_URB_EP_LINKING
  95477. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  95478. +#endif
  95479. + DWC_FREE(dwc_otg_urb);
  95480. + urb->hcpriv = NULL;
  95481. + if (retval == -DWC_E_NO_DEVICE)
  95482. + retval = -ENODEV;
  95483. + }
  95484. + }
  95485. +#if USB_URB_EP_LINKING
  95486. + else
  95487. + {
  95488. + DWC_FREE(dwc_otg_urb);
  95489. + urb->hcpriv = NULL;
  95490. + }
  95491. +#endif
  95492. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, irqflags);
  95493. + return retval;
  95494. +}
  95495. +
  95496. +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
  95497. + * success. */
  95498. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  95499. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
  95500. +#else
  95501. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  95502. +#endif
  95503. +{
  95504. + dwc_irqflags_t flags;
  95505. + dwc_otg_hcd_t *dwc_otg_hcd;
  95506. + int rc;
  95507. +
  95508. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
  95509. +
  95510. + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  95511. +
  95512. +#ifdef DEBUG
  95513. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  95514. + dump_urb_info(urb, "dwc_otg_urb_dequeue");
  95515. + }
  95516. +#endif
  95517. +
  95518. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  95519. + rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  95520. + if (0 == rc) {
  95521. + if(urb->hcpriv != NULL) {
  95522. + dwc_otg_hcd_urb_dequeue(dwc_otg_hcd,
  95523. + (dwc_otg_hcd_urb_t *)urb->hcpriv);
  95524. +
  95525. + DWC_FREE(urb->hcpriv);
  95526. + urb->hcpriv = NULL;
  95527. + }
  95528. + }
  95529. +
  95530. + if (0 == rc) {
  95531. + /* Higher layer software sets URB status. */
  95532. +#if USB_URB_EP_LINKING
  95533. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  95534. +#endif
  95535. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  95536. +
  95537. +
  95538. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  95539. + usb_hcd_giveback_urb(hcd, urb);
  95540. +#else
  95541. + usb_hcd_giveback_urb(hcd, urb, status);
  95542. +#endif
  95543. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  95544. + DWC_PRINTF("Called usb_hcd_giveback_urb() \n");
  95545. + DWC_PRINTF(" 1urb->status = %d\n", urb->status);
  95546. + }
  95547. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue OK\n");
  95548. + } else {
  95549. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  95550. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue failed - rc %d\n",
  95551. + rc);
  95552. + }
  95553. +
  95554. + return rc;
  95555. +}
  95556. +
  95557. +/* Frees resources in the DWC_otg controller related to a given endpoint. Also
  95558. + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
  95559. + * must already be dequeued. */
  95560. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  95561. +{
  95562. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  95563. +
  95564. + DWC_DEBUGPL(DBG_HCD,
  95565. + "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
  95566. + "endpoint=%d\n", ep->desc.bEndpointAddress,
  95567. + dwc_ep_addr_to_endpoint(ep->desc.bEndpointAddress));
  95568. + dwc_otg_hcd_endpoint_disable(dwc_otg_hcd, ep->hcpriv, 250);
  95569. + ep->hcpriv = NULL;
  95570. +}
  95571. +
  95572. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  95573. +/* Resets endpoint specific parameter values, in current version used to reset
  95574. + * the data toggle(as a WA). This function can be called from usb_clear_halt routine */
  95575. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  95576. +{
  95577. + dwc_irqflags_t flags;
  95578. + struct usb_device *udev = NULL;
  95579. + int epnum = usb_endpoint_num(&ep->desc);
  95580. + int is_out = usb_endpoint_dir_out(&ep->desc);
  95581. + int is_control = usb_endpoint_xfer_control(&ep->desc);
  95582. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  95583. + struct device *dev = DWC_OTG_OS_GETDEV(dwc_otg_hcd->otg_dev->os_dep);
  95584. +
  95585. + if (dev)
  95586. + udev = to_usb_device(dev);
  95587. + else
  95588. + return;
  95589. +
  95590. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP RESET: Endpoint Num=0x%02d\n", epnum);
  95591. +
  95592. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  95593. + usb_settoggle(udev, epnum, is_out, 0);
  95594. + if (is_control)
  95595. + usb_settoggle(udev, epnum, !is_out, 0);
  95596. +
  95597. + if (ep->hcpriv) {
  95598. + dwc_otg_hcd_endpoint_reset(dwc_otg_hcd, ep->hcpriv);
  95599. + }
  95600. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  95601. +}
  95602. +#endif
  95603. +
  95604. +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
  95605. + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
  95606. + * interrupt.
  95607. + *
  95608. + * This function is called by the USB core when an interrupt occurs */
  95609. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd)
  95610. +{
  95611. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  95612. + int32_t retval = dwc_otg_hcd_handle_intr(dwc_otg_hcd);
  95613. + if (retval != 0) {
  95614. + S3C2410X_CLEAR_EINTPEND();
  95615. + }
  95616. + return IRQ_RETVAL(retval);
  95617. +}
  95618. +
  95619. +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
  95620. + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
  95621. + * is the status change indicator for the single root port. Returns 1 if either
  95622. + * change indicator is 1, otherwise returns 0. */
  95623. +int hub_status_data(struct usb_hcd *hcd, char *buf)
  95624. +{
  95625. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  95626. +
  95627. + buf[0] = 0;
  95628. + buf[0] |= (dwc_otg_hcd_is_status_changed(dwc_otg_hcd, 1)) << 1;
  95629. +
  95630. + return (buf[0] != 0);
  95631. +}
  95632. +
  95633. +/** Handles hub class-specific requests. */
  95634. +int hub_control(struct usb_hcd *hcd,
  95635. + u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength)
  95636. +{
  95637. + int retval;
  95638. +
  95639. + retval = dwc_otg_hcd_hub_control(hcd_to_dwc_otg_hcd(hcd),
  95640. + typeReq, wValue, wIndex, buf, wLength);
  95641. +
  95642. + switch (retval) {
  95643. + case -DWC_E_INVALID:
  95644. + retval = -EINVAL;
  95645. + break;
  95646. + }
  95647. +
  95648. + return retval;
  95649. +}
  95650. +
  95651. +#endif /* DWC_DEVICE_ONLY */
  95652. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
  95653. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 1970-01-01 01:00:00.000000000 +0100
  95654. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 2015-02-09 04:40:29.000000000 +0100
  95655. @@ -0,0 +1,957 @@
  95656. +/* ==========================================================================
  95657. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_queue.c $
  95658. + * $Revision: #44 $
  95659. + * $Date: 2011/10/26 $
  95660. + * $Change: 1873028 $
  95661. + *
  95662. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  95663. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  95664. + * otherwise expressly agreed to in writing between Synopsys and you.
  95665. + *
  95666. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  95667. + * any End User Software License Agreement or Agreement for Licensed Product
  95668. + * with Synopsys or any supplement thereto. You are permitted to use and
  95669. + * redistribute this Software in source and binary forms, with or without
  95670. + * modification, provided that redistributions of source code must retain this
  95671. + * notice. You may not view, use, disclose, copy or distribute this file or
  95672. + * any information contained herein except pursuant to this license grant from
  95673. + * Synopsys. If you do not agree with this notice, including the disclaimer
  95674. + * below, then you are not authorized to use the Software.
  95675. + *
  95676. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  95677. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  95678. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  95679. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  95680. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  95681. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  95682. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  95683. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  95684. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  95685. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  95686. + * DAMAGE.
  95687. + * ========================================================================== */
  95688. +#ifndef DWC_DEVICE_ONLY
  95689. +
  95690. +/**
  95691. + * @file
  95692. + *
  95693. + * This file contains the functions to manage Queue Heads and Queue
  95694. + * Transfer Descriptors.
  95695. + */
  95696. +
  95697. +#include "dwc_otg_hcd.h"
  95698. +#include "dwc_otg_regs.h"
  95699. +
  95700. +extern bool microframe_schedule;
  95701. +
  95702. +/**
  95703. + * Free each QTD in the QH's QTD-list then free the QH. QH should already be
  95704. + * removed from a list. QTD list should already be empty if called from URB
  95705. + * Dequeue.
  95706. + *
  95707. + * @param hcd HCD instance.
  95708. + * @param qh The QH to free.
  95709. + */
  95710. +void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  95711. +{
  95712. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  95713. + dwc_irqflags_t flags;
  95714. +
  95715. + /* Free each QTD in the QTD list */
  95716. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  95717. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  95718. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  95719. + dwc_otg_hcd_qtd_free(qtd);
  95720. + }
  95721. +
  95722. + if (hcd->core_if->dma_desc_enable) {
  95723. + dwc_otg_hcd_qh_free_ddma(hcd, qh);
  95724. + } else if (qh->dw_align_buf) {
  95725. + uint32_t buf_size;
  95726. + if (qh->ep_type == UE_ISOCHRONOUS) {
  95727. + buf_size = 4096;
  95728. + } else {
  95729. + buf_size = hcd->core_if->core_params->max_transfer_size;
  95730. + }
  95731. + DWC_DMA_FREE(buf_size, qh->dw_align_buf, qh->dw_align_buf_dma);
  95732. + }
  95733. +
  95734. + DWC_FREE(qh);
  95735. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  95736. + return;
  95737. +}
  95738. +
  95739. +#define BitStuffTime(bytecount) ((8 * 7* bytecount) / 6)
  95740. +#define HS_HOST_DELAY 5 /* nanoseconds */
  95741. +#define FS_LS_HOST_DELAY 1000 /* nanoseconds */
  95742. +#define HUB_LS_SETUP 333 /* nanoseconds */
  95743. +#define NS_TO_US(ns) ((ns + 500) / 1000)
  95744. + /* convert & round nanoseconds to microseconds */
  95745. +
  95746. +static uint32_t calc_bus_time(int speed, int is_in, int is_isoc, int bytecount)
  95747. +{
  95748. + unsigned long retval;
  95749. +
  95750. + switch (speed) {
  95751. + case USB_SPEED_HIGH:
  95752. + if (is_isoc) {
  95753. + retval =
  95754. + ((38 * 8 * 2083) +
  95755. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  95756. + HS_HOST_DELAY;
  95757. + } else {
  95758. + retval =
  95759. + ((55 * 8 * 2083) +
  95760. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  95761. + HS_HOST_DELAY;
  95762. + }
  95763. + break;
  95764. + case USB_SPEED_FULL:
  95765. + if (is_isoc) {
  95766. + retval =
  95767. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  95768. + if (is_in) {
  95769. + retval = 7268 + FS_LS_HOST_DELAY + retval;
  95770. + } else {
  95771. + retval = 6265 + FS_LS_HOST_DELAY + retval;
  95772. + }
  95773. + } else {
  95774. + retval =
  95775. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  95776. + retval = 9107 + FS_LS_HOST_DELAY + retval;
  95777. + }
  95778. + break;
  95779. + case USB_SPEED_LOW:
  95780. + if (is_in) {
  95781. + retval =
  95782. + (67667 * (31 + 10 * BitStuffTime(bytecount))) /
  95783. + 1000;
  95784. + retval =
  95785. + 64060 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  95786. + retval;
  95787. + } else {
  95788. + retval =
  95789. + (66700 * (31 + 10 * BitStuffTime(bytecount))) /
  95790. + 1000;
  95791. + retval =
  95792. + 64107 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  95793. + retval;
  95794. + }
  95795. + break;
  95796. + default:
  95797. + DWC_WARN("Unknown device speed\n");
  95798. + retval = -1;
  95799. + }
  95800. +
  95801. + return NS_TO_US(retval);
  95802. +}
  95803. +
  95804. +/**
  95805. + * Initializes a QH structure.
  95806. + *
  95807. + * @param hcd The HCD state structure for the DWC OTG controller.
  95808. + * @param qh The QH to init.
  95809. + * @param urb Holds the information about the device/endpoint that we need
  95810. + * to initialize the QH.
  95811. + */
  95812. +#define SCHEDULE_SLOP 10
  95813. +void qh_init(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, dwc_otg_hcd_urb_t * urb)
  95814. +{
  95815. + char *speed, *type;
  95816. + int dev_speed;
  95817. + uint32_t hub_addr, hub_port;
  95818. +
  95819. + dwc_memset(qh, 0, sizeof(dwc_otg_qh_t));
  95820. +
  95821. + /* Initialize QH */
  95822. + qh->ep_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  95823. + qh->ep_is_in = dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
  95824. +
  95825. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  95826. + qh->maxp = dwc_otg_hcd_get_mps(&urb->pipe_info);
  95827. + DWC_CIRCLEQ_INIT(&qh->qtd_list);
  95828. + DWC_LIST_INIT(&qh->qh_list_entry);
  95829. + qh->channel = NULL;
  95830. +
  95831. + /* FS/LS Enpoint on HS Hub
  95832. + * NOT virtual root hub */
  95833. + dev_speed = hcd->fops->speed(hcd, urb->priv);
  95834. +
  95835. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &hub_port);
  95836. + qh->do_split = 0;
  95837. + if (microframe_schedule)
  95838. + qh->speed = dev_speed;
  95839. +
  95840. + qh->nak_frame = 0xffff;
  95841. +
  95842. + if (((dev_speed == USB_SPEED_LOW) ||
  95843. + (dev_speed == USB_SPEED_FULL)) &&
  95844. + (hub_addr != 0 && hub_addr != 1)) {
  95845. + DWC_DEBUGPL(DBG_HCD,
  95846. + "QH init: EP %d: TT found at hub addr %d, for port %d\n",
  95847. + dwc_otg_hcd_get_ep_num(&urb->pipe_info), hub_addr,
  95848. + hub_port);
  95849. + qh->do_split = 1;
  95850. + qh->skip_count = 0;
  95851. + }
  95852. +
  95853. + if (qh->ep_type == UE_INTERRUPT || qh->ep_type == UE_ISOCHRONOUS) {
  95854. + /* Compute scheduling parameters once and save them. */
  95855. + hprt0_data_t hprt;
  95856. +
  95857. + /** @todo Account for split transfers in the bus time. */
  95858. + int bytecount =
  95859. + dwc_hb_mult(qh->maxp) * dwc_max_packet(qh->maxp);
  95860. +
  95861. + qh->usecs =
  95862. + calc_bus_time((qh->do_split ? USB_SPEED_HIGH : dev_speed),
  95863. + qh->ep_is_in, (qh->ep_type == UE_ISOCHRONOUS),
  95864. + bytecount);
  95865. + /* Start in a slightly future (micro)frame. */
  95866. + qh->sched_frame = dwc_frame_num_inc(hcd->frame_number,
  95867. + SCHEDULE_SLOP);
  95868. + qh->interval = urb->interval;
  95869. +
  95870. +#if 0
  95871. + /* Increase interrupt polling rate for debugging. */
  95872. + if (qh->ep_type == UE_INTERRUPT) {
  95873. + qh->interval = 8;
  95874. + }
  95875. +#endif
  95876. + hprt.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  95877. + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
  95878. + ((dev_speed == USB_SPEED_LOW) ||
  95879. + (dev_speed == USB_SPEED_FULL))) {
  95880. + qh->interval *= 8;
  95881. + qh->sched_frame |= 0x7;
  95882. + qh->start_split_frame = qh->sched_frame;
  95883. + }
  95884. +
  95885. + }
  95886. +
  95887. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
  95888. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", qh);
  95889. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
  95890. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  95891. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
  95892. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  95893. + dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  95894. + switch (dev_speed) {
  95895. + case USB_SPEED_LOW:
  95896. + qh->dev_speed = DWC_OTG_EP_SPEED_LOW;
  95897. + speed = "low";
  95898. + break;
  95899. + case USB_SPEED_FULL:
  95900. + qh->dev_speed = DWC_OTG_EP_SPEED_FULL;
  95901. + speed = "full";
  95902. + break;
  95903. + case USB_SPEED_HIGH:
  95904. + qh->dev_speed = DWC_OTG_EP_SPEED_HIGH;
  95905. + speed = "high";
  95906. + break;
  95907. + default:
  95908. + speed = "?";
  95909. + break;
  95910. + }
  95911. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n", speed);
  95912. +
  95913. + switch (qh->ep_type) {
  95914. + case UE_ISOCHRONOUS:
  95915. + type = "isochronous";
  95916. + break;
  95917. + case UE_INTERRUPT:
  95918. + type = "interrupt";
  95919. + break;
  95920. + case UE_CONTROL:
  95921. + type = "control";
  95922. + break;
  95923. + case UE_BULK:
  95924. + type = "bulk";
  95925. + break;
  95926. + default:
  95927. + type = "?";
  95928. + break;
  95929. + }
  95930. +
  95931. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n", type);
  95932. +
  95933. +#ifdef DEBUG
  95934. + if (qh->ep_type == UE_INTERRUPT) {
  95935. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
  95936. + qh->usecs);
  95937. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
  95938. + qh->interval);
  95939. + }
  95940. +#endif
  95941. +
  95942. +}
  95943. +
  95944. +/**
  95945. + * This function allocates and initializes a QH.
  95946. + *
  95947. + * @param hcd The HCD state structure for the DWC OTG controller.
  95948. + * @param urb Holds the information about the device/endpoint that we need
  95949. + * to initialize the QH.
  95950. + * @param atomic_alloc Flag to do atomic allocation if needed
  95951. + *
  95952. + * @return Returns pointer to the newly allocated QH, or NULL on error. */
  95953. +dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  95954. + dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  95955. +{
  95956. + dwc_otg_qh_t *qh;
  95957. +
  95958. + /* Allocate memory */
  95959. + /** @todo add memflags argument */
  95960. + qh = dwc_otg_hcd_qh_alloc(atomic_alloc);
  95961. + if (qh == NULL) {
  95962. + DWC_ERROR("qh allocation failed");
  95963. + return NULL;
  95964. + }
  95965. +
  95966. + qh_init(hcd, qh, urb);
  95967. +
  95968. + if (hcd->core_if->dma_desc_enable
  95969. + && (dwc_otg_hcd_qh_init_ddma(hcd, qh) < 0)) {
  95970. + dwc_otg_hcd_qh_free(hcd, qh);
  95971. + return NULL;
  95972. + }
  95973. +
  95974. + return qh;
  95975. +}
  95976. +
  95977. +/* microframe_schedule=0 start */
  95978. +
  95979. +/**
  95980. + * Checks that a channel is available for a periodic transfer.
  95981. + *
  95982. + * @return 0 if successful, negative error code otherise.
  95983. + */
  95984. +static int periodic_channel_available(dwc_otg_hcd_t * hcd)
  95985. +{
  95986. + /*
  95987. + * Currently assuming that there is a dedicated host channnel for each
  95988. + * periodic transaction plus at least one host channel for
  95989. + * non-periodic transactions.
  95990. + */
  95991. + int status;
  95992. + int num_channels;
  95993. +
  95994. + num_channels = hcd->core_if->core_params->host_channels;
  95995. + if ((hcd->periodic_channels + hcd->non_periodic_channels < num_channels)
  95996. + && (hcd->periodic_channels < num_channels - 1)) {
  95997. + status = 0;
  95998. + } else {
  95999. + DWC_INFO("%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n",
  96000. + __func__, num_channels, hcd->periodic_channels, hcd->non_periodic_channels); //NOTICE
  96001. + status = -DWC_E_NO_SPACE;
  96002. + }
  96003. +
  96004. + return status;
  96005. +}
  96006. +
  96007. +/**
  96008. + * Checks that there is sufficient bandwidth for the specified QH in the
  96009. + * periodic schedule. For simplicity, this calculation assumes that all the
  96010. + * transfers in the periodic schedule may occur in the same (micro)frame.
  96011. + *
  96012. + * @param hcd The HCD state structure for the DWC OTG controller.
  96013. + * @param qh QH containing periodic bandwidth required.
  96014. + *
  96015. + * @return 0 if successful, negative error code otherwise.
  96016. + */
  96017. +static int check_periodic_bandwidth(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  96018. +{
  96019. + int status;
  96020. + int16_t max_claimed_usecs;
  96021. +
  96022. + status = 0;
  96023. +
  96024. + if ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) || qh->do_split) {
  96025. + /*
  96026. + * High speed mode.
  96027. + * Max periodic usecs is 80% x 125 usec = 100 usec.
  96028. + */
  96029. +
  96030. + max_claimed_usecs = 100 - qh->usecs;
  96031. + } else {
  96032. + /*
  96033. + * Full speed mode.
  96034. + * Max periodic usecs is 90% x 1000 usec = 900 usec.
  96035. + */
  96036. + max_claimed_usecs = 900 - qh->usecs;
  96037. + }
  96038. +
  96039. + if (hcd->periodic_usecs > max_claimed_usecs) {
  96040. + DWC_INFO("%s: already claimed usecs %d, required usecs %d\n", __func__, hcd->periodic_usecs, qh->usecs); //NOTICE
  96041. + status = -DWC_E_NO_SPACE;
  96042. + }
  96043. +
  96044. + return status;
  96045. +}
  96046. +
  96047. +/* microframe_schedule=0 end */
  96048. +
  96049. +/**
  96050. + * Microframe scheduler
  96051. + * track the total use in hcd->frame_usecs
  96052. + * keep each qh use in qh->frame_usecs
  96053. + * when surrendering the qh then donate the time back
  96054. + */
  96055. +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
  96056. +
  96057. +/*
  96058. + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
  96059. + */
  96060. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
  96061. +{
  96062. + int i;
  96063. + for (i=0; i<8; i++) {
  96064. + _hcd->frame_usecs[i] = max_uframe_usecs[i];
  96065. + }
  96066. + return 0;
  96067. +}
  96068. +
  96069. +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  96070. +{
  96071. + int i;
  96072. + unsigned short utime;
  96073. + int t_left;
  96074. + int ret;
  96075. + int done;
  96076. +
  96077. + ret = -1;
  96078. + utime = _qh->usecs;
  96079. + t_left = utime;
  96080. + i = 0;
  96081. + done = 0;
  96082. + while (done == 0) {
  96083. + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
  96084. + if (utime <= _hcd->frame_usecs[i]) {
  96085. + _hcd->frame_usecs[i] -= utime;
  96086. + _qh->frame_usecs[i] += utime;
  96087. + t_left -= utime;
  96088. + ret = i;
  96089. + done = 1;
  96090. + return ret;
  96091. + } else {
  96092. + i++;
  96093. + if (i == 8) {
  96094. + done = 1;
  96095. + ret = -1;
  96096. + }
  96097. + }
  96098. + }
  96099. + return ret;
  96100. + }
  96101. +
  96102. +/*
  96103. + * use this for FS apps that can span multiple uframes
  96104. + */
  96105. +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  96106. +{
  96107. + int i;
  96108. + int j;
  96109. + unsigned short utime;
  96110. + int t_left;
  96111. + int ret;
  96112. + int done;
  96113. + unsigned short xtime;
  96114. +
  96115. + ret = -1;
  96116. + utime = _qh->usecs;
  96117. + t_left = utime;
  96118. + i = 0;
  96119. + done = 0;
  96120. +loop:
  96121. + while (done == 0) {
  96122. + if(_hcd->frame_usecs[i] <= 0) {
  96123. + i++;
  96124. + if (i == 8) {
  96125. + done = 1;
  96126. + ret = -1;
  96127. + }
  96128. + goto loop;
  96129. + }
  96130. +
  96131. + /*
  96132. + * we need n consecutive slots
  96133. + * so use j as a start slot j plus j+1 must be enough time (for now)
  96134. + */
  96135. + xtime= _hcd->frame_usecs[i];
  96136. + for (j = i+1 ; j < 8 ; j++ ) {
  96137. + /*
  96138. + * if we add this frame remaining time to xtime we may
  96139. + * be OK, if not we need to test j for a complete frame
  96140. + */
  96141. + if ((xtime+_hcd->frame_usecs[j]) < utime) {
  96142. + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
  96143. + j = 8;
  96144. + ret = -1;
  96145. + continue;
  96146. + }
  96147. + }
  96148. + if (xtime >= utime) {
  96149. + ret = i;
  96150. + j = 8; /* stop loop with a good value ret */
  96151. + continue;
  96152. + }
  96153. + /* add the frame time to x time */
  96154. + xtime += _hcd->frame_usecs[j];
  96155. + /* we must have a fully available next frame or break */
  96156. + if ((xtime < utime)
  96157. + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
  96158. + ret = -1;
  96159. + j = 8; /* stop loop with a bad value ret */
  96160. + continue;
  96161. + }
  96162. + }
  96163. + if (ret >= 0) {
  96164. + t_left = utime;
  96165. + for (j = i; (t_left>0) && (j < 8); j++ ) {
  96166. + t_left -= _hcd->frame_usecs[j];
  96167. + if ( t_left <= 0 ) {
  96168. + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
  96169. + _hcd->frame_usecs[j]= -t_left;
  96170. + ret = i;
  96171. + done = 1;
  96172. + } else {
  96173. + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
  96174. + _hcd->frame_usecs[j] = 0;
  96175. + }
  96176. + }
  96177. + } else {
  96178. + i++;
  96179. + if (i == 8) {
  96180. + done = 1;
  96181. + ret = -1;
  96182. + }
  96183. + }
  96184. + }
  96185. + return ret;
  96186. +}
  96187. +
  96188. +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  96189. +{
  96190. + int ret;
  96191. + ret = -1;
  96192. +
  96193. + if (_qh->speed == USB_SPEED_HIGH) {
  96194. + /* if this is a hs transaction we need a full frame */
  96195. + ret = find_single_uframe(_hcd, _qh);
  96196. + } else {
  96197. + /* if this is a fs transaction we may need a sequence of frames */
  96198. + ret = find_multi_uframe(_hcd, _qh);
  96199. + }
  96200. + return ret;
  96201. +}
  96202. +
  96203. +/**
  96204. + * Checks that the max transfer size allowed in a host channel is large enough
  96205. + * to handle the maximum data transfer in a single (micro)frame for a periodic
  96206. + * transfer.
  96207. + *
  96208. + * @param hcd The HCD state structure for the DWC OTG controller.
  96209. + * @param qh QH for a periodic endpoint.
  96210. + *
  96211. + * @return 0 if successful, negative error code otherwise.
  96212. + */
  96213. +static int check_max_xfer_size(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  96214. +{
  96215. + int status;
  96216. + uint32_t max_xfer_size;
  96217. + uint32_t max_channel_xfer_size;
  96218. +
  96219. + status = 0;
  96220. +
  96221. + max_xfer_size = dwc_max_packet(qh->maxp) * dwc_hb_mult(qh->maxp);
  96222. + max_channel_xfer_size = hcd->core_if->core_params->max_transfer_size;
  96223. +
  96224. + if (max_xfer_size > max_channel_xfer_size) {
  96225. + DWC_INFO("%s: Periodic xfer length %d > " "max xfer length for channel %d\n",
  96226. + __func__, max_xfer_size, max_channel_xfer_size); //NOTICE
  96227. + status = -DWC_E_NO_SPACE;
  96228. + }
  96229. +
  96230. + return status;
  96231. +}
  96232. +
  96233. +
  96234. +
  96235. +/**
  96236. + * Schedules an interrupt or isochronous transfer in the periodic schedule.
  96237. + *
  96238. + * @param hcd The HCD state structure for the DWC OTG controller.
  96239. + * @param qh QH for the periodic transfer. The QH should already contain the
  96240. + * scheduling information.
  96241. + *
  96242. + * @return 0 if successful, negative error code otherwise.
  96243. + */
  96244. +static int schedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  96245. +{
  96246. + int status = 0;
  96247. +
  96248. + if (microframe_schedule) {
  96249. + int frame;
  96250. + status = find_uframe(hcd, qh);
  96251. + frame = -1;
  96252. + if (status == 0) {
  96253. + frame = 7;
  96254. + } else {
  96255. + if (status > 0 )
  96256. + frame = status-1;
  96257. + }
  96258. +
  96259. + /* Set the new frame up */
  96260. + if (frame > -1) {
  96261. + qh->sched_frame &= ~0x7;
  96262. + qh->sched_frame |= (frame & 7);
  96263. + }
  96264. +
  96265. + if (status != -1)
  96266. + status = 0;
  96267. + } else {
  96268. + status = periodic_channel_available(hcd);
  96269. + if (status) {
  96270. + DWC_INFO("%s: No host channel available for periodic " "transfer.\n", __func__); //NOTICE
  96271. + return status;
  96272. + }
  96273. +
  96274. + status = check_periodic_bandwidth(hcd, qh);
  96275. + }
  96276. + if (status) {
  96277. + DWC_INFO("%s: Insufficient periodic bandwidth for "
  96278. + "periodic transfer.\n", __func__);
  96279. + return status;
  96280. + }
  96281. + status = check_max_xfer_size(hcd, qh);
  96282. + if (status) {
  96283. + DWC_INFO("%s: Channel max transfer size too small "
  96284. + "for periodic transfer.\n", __func__);
  96285. + return status;
  96286. + }
  96287. +
  96288. + if (hcd->core_if->dma_desc_enable) {
  96289. + /* Don't rely on SOF and start in ready schedule */
  96290. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
  96291. + }
  96292. + else {
  96293. + if(fiq_enable && (DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, hcd->fiq_state->next_sched_frame)))
  96294. + {
  96295. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  96296. +
  96297. + }
  96298. + /* Always start in the inactive schedule. */
  96299. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_inactive, &qh->qh_list_entry);
  96300. + }
  96301. +
  96302. + if (!microframe_schedule) {
  96303. + /* Reserve the periodic channel. */
  96304. + hcd->periodic_channels++;
  96305. + }
  96306. +
  96307. + /* Update claimed usecs per (micro)frame. */
  96308. + hcd->periodic_usecs += qh->usecs;
  96309. +
  96310. + return status;
  96311. +}
  96312. +
  96313. +
  96314. +/**
  96315. + * This function adds a QH to either the non periodic or periodic schedule if
  96316. + * it is not already in the schedule. If the QH is already in the schedule, no
  96317. + * action is taken.
  96318. + *
  96319. + * @return 0 if successful, negative error code otherwise.
  96320. + */
  96321. +int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  96322. +{
  96323. + int status = 0;
  96324. + gintmsk_data_t intr_mask = {.d32 = 0 };
  96325. +
  96326. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  96327. + /* QH already in a schedule. */
  96328. + return status;
  96329. + }
  96330. +
  96331. + /* Add the new QH to the appropriate schedule */
  96332. + if (dwc_qh_is_non_per(qh)) {
  96333. + /* Always start in the inactive schedule. */
  96334. + DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
  96335. + &qh->qh_list_entry);
  96336. + //hcd->fiq_state->kick_np_queues = 1;
  96337. + } else {
  96338. + status = schedule_periodic(hcd, qh);
  96339. + if ( !hcd->periodic_qh_count ) {
  96340. + intr_mask.b.sofintr = 1;
  96341. + if (fiq_enable) {
  96342. + local_fiq_disable();
  96343. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  96344. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  96345. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  96346. + local_fiq_enable();
  96347. + } else {
  96348. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  96349. + }
  96350. + }
  96351. + hcd->periodic_qh_count++;
  96352. + }
  96353. +
  96354. + return status;
  96355. +}
  96356. +
  96357. +/**
  96358. + * Removes an interrupt or isochronous transfer from the periodic schedule.
  96359. + *
  96360. + * @param hcd The HCD state structure for the DWC OTG controller.
  96361. + * @param qh QH for the periodic transfer.
  96362. + */
  96363. +static void deschedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  96364. +{
  96365. + int i;
  96366. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  96367. +
  96368. + /* Update claimed usecs per (micro)frame. */
  96369. + hcd->periodic_usecs -= qh->usecs;
  96370. +
  96371. + if (!microframe_schedule) {
  96372. + /* Release the periodic channel reservation. */
  96373. + hcd->periodic_channels--;
  96374. + } else {
  96375. + for (i = 0; i < 8; i++) {
  96376. + hcd->frame_usecs[i] += qh->frame_usecs[i];
  96377. + qh->frame_usecs[i] = 0;
  96378. + }
  96379. + }
  96380. +}
  96381. +
  96382. +/**
  96383. + * Removes a QH from either the non-periodic or periodic schedule. Memory is
  96384. + * not freed.
  96385. + *
  96386. + * @param hcd The HCD state structure.
  96387. + * @param qh QH to remove from schedule. */
  96388. +void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  96389. +{
  96390. + gintmsk_data_t intr_mask = {.d32 = 0 };
  96391. +
  96392. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  96393. + /* QH is not in a schedule. */
  96394. + return;
  96395. + }
  96396. +
  96397. + if (dwc_qh_is_non_per(qh)) {
  96398. + if (hcd->non_periodic_qh_ptr == &qh->qh_list_entry) {
  96399. + hcd->non_periodic_qh_ptr =
  96400. + hcd->non_periodic_qh_ptr->next;
  96401. + }
  96402. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  96403. + //if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive))
  96404. + // hcd->fiq_state->kick_np_queues = 1;
  96405. + } else {
  96406. + deschedule_periodic(hcd, qh);
  96407. + hcd->periodic_qh_count--;
  96408. + if( !hcd->periodic_qh_count && !fiq_fsm_enable ) {
  96409. + intr_mask.b.sofintr = 1;
  96410. + if (fiq_enable) {
  96411. + local_fiq_disable();
  96412. + fiq_fsm_spin_lock(&hcd->fiq_state->lock);
  96413. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  96414. + fiq_fsm_spin_unlock(&hcd->fiq_state->lock);
  96415. + local_fiq_enable();
  96416. + } else {
  96417. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  96418. + }
  96419. + }
  96420. + }
  96421. +}
  96422. +
  96423. +/**
  96424. + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
  96425. + * non-periodic schedule. The QH is added to the inactive non-periodic
  96426. + * schedule if any QTDs are still attached to the QH.
  96427. + *
  96428. + * For periodic QHs, the QH is removed from the periodic queued schedule. If
  96429. + * there are any QTDs still attached to the QH, the QH is added to either the
  96430. + * periodic inactive schedule or the periodic ready schedule and its next
  96431. + * scheduled frame is calculated. The QH is placed in the ready schedule if
  96432. + * the scheduled frame has been reached already. Otherwise it's placed in the
  96433. + * inactive schedule. If there are no QTDs attached to the QH, the QH is
  96434. + * completely removed from the periodic schedule.
  96435. + */
  96436. +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  96437. + int sched_next_periodic_split)
  96438. +{
  96439. + if (dwc_qh_is_non_per(qh)) {
  96440. + dwc_otg_hcd_qh_remove(hcd, qh);
  96441. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  96442. + /* Add back to inactive non-periodic schedule. */
  96443. + dwc_otg_hcd_qh_add(hcd, qh);
  96444. + //hcd->fiq_state->kick_np_queues = 1;
  96445. + }
  96446. + } else {
  96447. + uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
  96448. +
  96449. + if (qh->do_split) {
  96450. + /* Schedule the next continuing periodic split transfer */
  96451. + if (sched_next_periodic_split) {
  96452. +
  96453. + qh->sched_frame = frame_number;
  96454. +
  96455. + if (dwc_frame_num_le(frame_number,
  96456. + dwc_frame_num_inc
  96457. + (qh->start_split_frame,
  96458. + 1))) {
  96459. + /*
  96460. + * Allow one frame to elapse after start
  96461. + * split microframe before scheduling
  96462. + * complete split, but DONT if we are
  96463. + * doing the next start split in the
  96464. + * same frame for an ISOC out.
  96465. + */
  96466. + if ((qh->ep_type != UE_ISOCHRONOUS) ||
  96467. + (qh->ep_is_in != 0)) {
  96468. + qh->sched_frame =
  96469. + dwc_frame_num_inc(qh->sched_frame, 1);
  96470. + }
  96471. + }
  96472. + } else {
  96473. + qh->sched_frame =
  96474. + dwc_frame_num_inc(qh->start_split_frame,
  96475. + qh->interval);
  96476. + if (dwc_frame_num_le
  96477. + (qh->sched_frame, frame_number)) {
  96478. + qh->sched_frame = frame_number;
  96479. + }
  96480. + qh->sched_frame |= 0x7;
  96481. + qh->start_split_frame = qh->sched_frame;
  96482. + }
  96483. + } else {
  96484. + qh->sched_frame =
  96485. + dwc_frame_num_inc(qh->sched_frame, qh->interval);
  96486. + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
  96487. + qh->sched_frame = frame_number;
  96488. + }
  96489. + }
  96490. +
  96491. + if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  96492. + dwc_otg_hcd_qh_remove(hcd, qh);
  96493. + } else {
  96494. + /*
  96495. + * Remove from periodic_sched_queued and move to
  96496. + * appropriate queue.
  96497. + */
  96498. + if ((microframe_schedule && dwc_frame_num_le(qh->sched_frame, frame_number)) ||
  96499. + (!microframe_schedule && qh->sched_frame == frame_number)) {
  96500. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  96501. + &qh->qh_list_entry);
  96502. + } else {
  96503. + if(fiq_enable && !dwc_frame_num_le(hcd->fiq_state->next_sched_frame, qh->sched_frame))
  96504. + {
  96505. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  96506. + }
  96507. +
  96508. + DWC_LIST_MOVE_HEAD
  96509. + (&hcd->periodic_sched_inactive,
  96510. + &qh->qh_list_entry);
  96511. + }
  96512. + }
  96513. + }
  96514. +}
  96515. +
  96516. +/**
  96517. + * This function allocates and initializes a QTD.
  96518. + *
  96519. + * @param urb The URB to create a QTD from. Each URB-QTD pair will end up
  96520. + * pointing to each other so each pair should have a unique correlation.
  96521. + * @param atomic_alloc Flag to do atomic alloc if needed
  96522. + *
  96523. + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
  96524. +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  96525. +{
  96526. + dwc_otg_qtd_t *qtd;
  96527. +
  96528. + qtd = dwc_otg_hcd_qtd_alloc(atomic_alloc);
  96529. + if (qtd == NULL) {
  96530. + return NULL;
  96531. + }
  96532. +
  96533. + dwc_otg_hcd_qtd_init(qtd, urb);
  96534. + return qtd;
  96535. +}
  96536. +
  96537. +/**
  96538. + * Initializes a QTD structure.
  96539. + *
  96540. + * @param qtd The QTD to initialize.
  96541. + * @param urb The URB to use for initialization. */
  96542. +void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb)
  96543. +{
  96544. + dwc_memset(qtd, 0, sizeof(dwc_otg_qtd_t));
  96545. + qtd->urb = urb;
  96546. + if (dwc_otg_hcd_get_pipe_type(&urb->pipe_info) == UE_CONTROL) {
  96547. + /*
  96548. + * The only time the QTD data toggle is used is on the data
  96549. + * phase of control transfers. This phase always starts with
  96550. + * DATA1.
  96551. + */
  96552. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  96553. + qtd->control_phase = DWC_OTG_CONTROL_SETUP;
  96554. + }
  96555. +
  96556. + /* start split */
  96557. + qtd->complete_split = 0;
  96558. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  96559. + qtd->isoc_split_offset = 0;
  96560. + qtd->in_process = 0;
  96561. +
  96562. + /* Store the qtd ptr in the urb to reference what QTD. */
  96563. + urb->qtd = qtd;
  96564. + return;
  96565. +}
  96566. +
  96567. +/**
  96568. + * This function adds a QTD to the QTD-list of a QH. It will find the correct
  96569. + * QH to place the QTD into. If it does not find a QH, then it will create a
  96570. + * new QH. If the QH to which the QTD is added is not currently scheduled, it
  96571. + * is placed into the proper schedule based on its EP type.
  96572. + * HCD lock must be held and interrupts must be disabled on entry
  96573. + *
  96574. + * @param[in] qtd The QTD to add
  96575. + * @param[in] hcd The DWC HCD structure
  96576. + * @param[out] qh out parameter to return queue head
  96577. + * @param atomic_alloc Flag to do atomic alloc if needed
  96578. + *
  96579. + * @return 0 if successful, negative error code otherwise.
  96580. + */
  96581. +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd,
  96582. + dwc_otg_hcd_t * hcd, dwc_otg_qh_t ** qh, int atomic_alloc)
  96583. +{
  96584. + int retval = 0;
  96585. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  96586. +
  96587. + /*
  96588. + * Get the QH which holds the QTD-list to insert to. Create QH if it
  96589. + * doesn't exist.
  96590. + */
  96591. + if (*qh == NULL) {
  96592. + *qh = dwc_otg_hcd_qh_create(hcd, urb, atomic_alloc);
  96593. + if (*qh == NULL) {
  96594. + retval = -DWC_E_NO_MEMORY;
  96595. + goto done;
  96596. + } else {
  96597. + if (fiq_enable)
  96598. + hcd->fiq_state->kick_np_queues = 1;
  96599. + }
  96600. + }
  96601. + retval = dwc_otg_hcd_qh_add(hcd, *qh);
  96602. + if (retval == 0) {
  96603. + DWC_CIRCLEQ_INSERT_TAIL(&((*qh)->qtd_list), qtd,
  96604. + qtd_list_entry);
  96605. + qtd->qh = *qh;
  96606. + }
  96607. +done:
  96608. +
  96609. + return retval;
  96610. +}
  96611. +
  96612. +#endif /* DWC_DEVICE_ONLY */
  96613. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h
  96614. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 1970-01-01 01:00:00.000000000 +0100
  96615. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 2015-02-09 04:40:29.000000000 +0100
  96616. @@ -0,0 +1,188 @@
  96617. +#ifndef _DWC_OS_DEP_H_
  96618. +#define _DWC_OS_DEP_H_
  96619. +
  96620. +/**
  96621. + * @file
  96622. + *
  96623. + * This file contains OS dependent structures.
  96624. + *
  96625. + */
  96626. +
  96627. +#include <linux/kernel.h>
  96628. +#include <linux/module.h>
  96629. +#include <linux/moduleparam.h>
  96630. +#include <linux/init.h>
  96631. +#include <linux/device.h>
  96632. +#include <linux/errno.h>
  96633. +#include <linux/types.h>
  96634. +#include <linux/slab.h>
  96635. +#include <linux/list.h>
  96636. +#include <linux/interrupt.h>
  96637. +#include <linux/ctype.h>
  96638. +#include <linux/string.h>
  96639. +#include <linux/dma-mapping.h>
  96640. +#include <linux/jiffies.h>
  96641. +#include <linux/delay.h>
  96642. +#include <linux/timer.h>
  96643. +#include <linux/workqueue.h>
  96644. +#include <linux/stat.h>
  96645. +#include <linux/pci.h>
  96646. +
  96647. +#include <linux/version.h>
  96648. +
  96649. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
  96650. +# include <linux/irq.h>
  96651. +#endif
  96652. +
  96653. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  96654. +# include <linux/usb/ch9.h>
  96655. +#else
  96656. +# include <linux/usb_ch9.h>
  96657. +#endif
  96658. +
  96659. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  96660. +# include <linux/usb/gadget.h>
  96661. +#else
  96662. +# include <linux/usb_gadget.h>
  96663. +#endif
  96664. +
  96665. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
  96666. +# include <asm/irq.h>
  96667. +#endif
  96668. +
  96669. +#ifdef PCI_INTERFACE
  96670. +# include <asm/io.h>
  96671. +#endif
  96672. +
  96673. +#ifdef LM_INTERFACE
  96674. +# include <asm/unaligned.h>
  96675. +# include <asm/sizes.h>
  96676. +# include <asm/param.h>
  96677. +# include <asm/io.h>
  96678. +# if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  96679. +# include <asm/arch/hardware.h>
  96680. +# include <asm/arch/lm.h>
  96681. +# include <asm/arch/irqs.h>
  96682. +# include <asm/arch/regs-irq.h>
  96683. +# else
  96684. +/* in 2.6.31, at least, we seem to have lost the generic LM infrastructure -
  96685. + here we assume that the machine architecture provides definitions
  96686. + in its own header
  96687. +*/
  96688. +# include <mach/lm.h>
  96689. +# include <mach/hardware.h>
  96690. +# endif
  96691. +#endif
  96692. +
  96693. +#ifdef PLATFORM_INTERFACE
  96694. +#include <linux/platform_device.h>
  96695. +#include <asm/mach/map.h>
  96696. +#endif
  96697. +
  96698. +/** The OS page size */
  96699. +#define DWC_OS_PAGE_SIZE PAGE_SIZE
  96700. +
  96701. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
  96702. +typedef int gfp_t;
  96703. +#endif
  96704. +
  96705. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  96706. +# define IRQF_SHARED SA_SHIRQ
  96707. +#endif
  96708. +
  96709. +typedef struct os_dependent {
  96710. + /** Base address returned from ioremap() */
  96711. + void *base;
  96712. +
  96713. + /** Register offset for Diagnostic API */
  96714. + uint32_t reg_offset;
  96715. +
  96716. + /** Base address for MPHI peripheral */
  96717. + void *mphi_base;
  96718. +
  96719. +#ifdef LM_INTERFACE
  96720. + struct lm_device *lmdev;
  96721. +#elif defined(PCI_INTERFACE)
  96722. + struct pci_dev *pcidev;
  96723. +
  96724. + /** Start address of a PCI region */
  96725. + resource_size_t rsrc_start;
  96726. +
  96727. + /** Length address of a PCI region */
  96728. + resource_size_t rsrc_len;
  96729. +#elif defined(PLATFORM_INTERFACE)
  96730. + struct platform_device *platformdev;
  96731. +#endif
  96732. +
  96733. +} os_dependent_t;
  96734. +
  96735. +#ifdef __cplusplus
  96736. +}
  96737. +#endif
  96738. +
  96739. +
  96740. +
  96741. +/* Type for the our device on the chosen bus */
  96742. +#if defined(LM_INTERFACE)
  96743. +typedef struct lm_device dwc_bus_dev_t;
  96744. +#elif defined(PCI_INTERFACE)
  96745. +typedef struct pci_dev dwc_bus_dev_t;
  96746. +#elif defined(PLATFORM_INTERFACE)
  96747. +typedef struct platform_device dwc_bus_dev_t;
  96748. +#endif
  96749. +
  96750. +/* Helper macro to retrieve drvdata from the device on the chosen bus */
  96751. +#if defined(LM_INTERFACE)
  96752. +#define DWC_OTG_BUSDRVDATA(_dev) lm_get_drvdata(_dev)
  96753. +#elif defined(PCI_INTERFACE)
  96754. +#define DWC_OTG_BUSDRVDATA(_dev) pci_get_drvdata(_dev)
  96755. +#elif defined(PLATFORM_INTERFACE)
  96756. +#define DWC_OTG_BUSDRVDATA(_dev) platform_get_drvdata(_dev)
  96757. +#endif
  96758. +
  96759. +/**
  96760. + * Helper macro returning the otg_device structure of a given struct device
  96761. + *
  96762. + * c.f. static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  96763. + */
  96764. +#ifdef LM_INTERFACE
  96765. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  96766. + struct lm_device *lm_dev = \
  96767. + container_of(_dev, struct lm_device, dev); \
  96768. + _var = lm_get_drvdata(lm_dev); \
  96769. + } while (0)
  96770. +
  96771. +#elif defined(PCI_INTERFACE)
  96772. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  96773. + _var = dev_get_drvdata(_dev); \
  96774. + } while (0)
  96775. +
  96776. +#elif defined(PLATFORM_INTERFACE)
  96777. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  96778. + struct platform_device *platform_dev = \
  96779. + container_of(_dev, struct platform_device, dev); \
  96780. + _var = platform_get_drvdata(platform_dev); \
  96781. + } while (0)
  96782. +#endif
  96783. +
  96784. +
  96785. +/**
  96786. + * Helper macro returning the struct dev of the given struct os_dependent
  96787. + *
  96788. + * c.f. static struct device *dwc_otg_getdev(struct os_dependent *osdep)
  96789. + */
  96790. +#ifdef LM_INTERFACE
  96791. +#define DWC_OTG_OS_GETDEV(_osdep) \
  96792. + ((_osdep).lmdev == NULL? NULL: &(_osdep).lmdev->dev)
  96793. +#elif defined(PCI_INTERFACE)
  96794. +#define DWC_OTG_OS_GETDEV(_osdep) \
  96795. + ((_osdep).pci_dev == NULL? NULL: &(_osdep).pci_dev->dev)
  96796. +#elif defined(PLATFORM_INTERFACE)
  96797. +#define DWC_OTG_OS_GETDEV(_osdep) \
  96798. + ((_osdep).platformdev == NULL? NULL: &(_osdep).platformdev->dev)
  96799. +#endif
  96800. +
  96801. +
  96802. +
  96803. +
  96804. +#endif /* _DWC_OS_DEP_H_ */
  96805. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_pcd.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c
  96806. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 1970-01-01 01:00:00.000000000 +0100
  96807. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 2015-02-09 04:40:29.000000000 +0100
  96808. @@ -0,0 +1,2712 @@
  96809. +/* ==========================================================================
  96810. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.c $
  96811. + * $Revision: #101 $
  96812. + * $Date: 2012/08/10 $
  96813. + * $Change: 2047372 $
  96814. + *
  96815. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  96816. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  96817. + * otherwise expressly agreed to in writing between Synopsys and you.
  96818. + *
  96819. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  96820. + * any End User Software License Agreement or Agreement for Licensed Product
  96821. + * with Synopsys or any supplement thereto. You are permitted to use and
  96822. + * redistribute this Software in source and binary forms, with or without
  96823. + * modification, provided that redistributions of source code must retain this
  96824. + * notice. You may not view, use, disclose, copy or distribute this file or
  96825. + * any information contained herein except pursuant to this license grant from
  96826. + * Synopsys. If you do not agree with this notice, including the disclaimer
  96827. + * below, then you are not authorized to use the Software.
  96828. + *
  96829. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  96830. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  96831. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  96832. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  96833. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  96834. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  96835. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  96836. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  96837. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  96838. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  96839. + * DAMAGE.
  96840. + * ========================================================================== */
  96841. +#ifndef DWC_HOST_ONLY
  96842. +
  96843. +/** @file
  96844. + * This file implements PCD Core. All code in this file is portable and doesn't
  96845. + * use any OS specific functions.
  96846. + * PCD Core provides Interface, defined in <code><dwc_otg_pcd_if.h></code>
  96847. + * header file, which can be used to implement OS specific PCD interface.
  96848. + *
  96849. + * An important function of the PCD is managing interrupts generated
  96850. + * by the DWC_otg controller. The implementation of the DWC_otg device
  96851. + * mode interrupt service routines is in dwc_otg_pcd_intr.c.
  96852. + *
  96853. + * @todo Add Device Mode test modes (Test J mode, Test K mode, etc).
  96854. + * @todo Does it work when the request size is greater than DEPTSIZ
  96855. + * transfer size
  96856. + *
  96857. + */
  96858. +
  96859. +#include "dwc_otg_pcd.h"
  96860. +
  96861. +#ifdef DWC_UTE_CFI
  96862. +#include "dwc_otg_cfi.h"
  96863. +
  96864. +extern int init_cfi(cfiobject_t * cfiobj);
  96865. +#endif
  96866. +
  96867. +/**
  96868. + * Choose endpoint from ep arrays using usb_ep structure.
  96869. + */
  96870. +static dwc_otg_pcd_ep_t *get_ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  96871. +{
  96872. + int i;
  96873. + if (pcd->ep0.priv == handle) {
  96874. + return &pcd->ep0;
  96875. + }
  96876. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  96877. + if (pcd->in_ep[i].priv == handle)
  96878. + return &pcd->in_ep[i];
  96879. + if (pcd->out_ep[i].priv == handle)
  96880. + return &pcd->out_ep[i];
  96881. + }
  96882. +
  96883. + return NULL;
  96884. +}
  96885. +
  96886. +/**
  96887. + * This function completes a request. It call's the request call back.
  96888. + */
  96889. +void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req,
  96890. + int32_t status)
  96891. +{
  96892. + unsigned stopped = ep->stopped;
  96893. +
  96894. + DWC_DEBUGPL(DBG_PCDV, "%s(ep %p req %p)\n", __func__, ep, req);
  96895. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  96896. +
  96897. + /* don't modify queue heads during completion callback */
  96898. + ep->stopped = 1;
  96899. + /* spin_unlock/spin_lock now done in fops->complete() */
  96900. + ep->pcd->fops->complete(ep->pcd, ep->priv, req->priv, status,
  96901. + req->actual);
  96902. +
  96903. + if (ep->pcd->request_pending > 0) {
  96904. + --ep->pcd->request_pending;
  96905. + }
  96906. +
  96907. + ep->stopped = stopped;
  96908. + DWC_FREE(req);
  96909. +}
  96910. +
  96911. +/**
  96912. + * This function terminates all the requsts in the EP request queue.
  96913. + */
  96914. +void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep)
  96915. +{
  96916. + dwc_otg_pcd_request_t *req;
  96917. +
  96918. + ep->stopped = 1;
  96919. +
  96920. + /* called with irqs blocked?? */
  96921. + while (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  96922. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  96923. + dwc_otg_request_done(ep, req, -DWC_E_SHUTDOWN);
  96924. + }
  96925. +}
  96926. +
  96927. +void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  96928. + const struct dwc_otg_pcd_function_ops *fops)
  96929. +{
  96930. + pcd->fops = fops;
  96931. +}
  96932. +
  96933. +/**
  96934. + * PCD Callback function for initializing the PCD when switching to
  96935. + * device mode.
  96936. + *
  96937. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  96938. + */
  96939. +static int32_t dwc_otg_pcd_start_cb(void *p)
  96940. +{
  96941. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  96942. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  96943. +
  96944. + /*
  96945. + * Initialized the Core for Device mode.
  96946. + */
  96947. + if (dwc_otg_is_device_mode(core_if)) {
  96948. + dwc_otg_core_dev_init(core_if);
  96949. + /* Set core_if's lock pointer to the pcd->lock */
  96950. + core_if->lock = pcd->lock;
  96951. + }
  96952. + return 1;
  96953. +}
  96954. +
  96955. +/** CFI-specific buffer allocation function for EP */
  96956. +#ifdef DWC_UTE_CFI
  96957. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  96958. + size_t buflen, int flags)
  96959. +{
  96960. + dwc_otg_pcd_ep_t *ep;
  96961. + ep = get_ep_from_handle(pcd, pep);
  96962. + if (!ep) {
  96963. + DWC_WARN("bad ep\n");
  96964. + return -DWC_E_INVALID;
  96965. + }
  96966. +
  96967. + return pcd->cfi->ops.ep_alloc_buf(pcd->cfi, pcd, ep, addr, buflen,
  96968. + flags);
  96969. +}
  96970. +#else
  96971. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  96972. + size_t buflen, int flags);
  96973. +#endif
  96974. +
  96975. +/**
  96976. + * PCD Callback function for notifying the PCD when resuming from
  96977. + * suspend.
  96978. + *
  96979. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  96980. + */
  96981. +static int32_t dwc_otg_pcd_resume_cb(void *p)
  96982. +{
  96983. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  96984. +
  96985. + if (pcd->fops->resume) {
  96986. + pcd->fops->resume(pcd);
  96987. + }
  96988. +
  96989. + /* Stop the SRP timeout timer. */
  96990. + if ((GET_CORE_IF(pcd)->core_params->phy_type != DWC_PHY_TYPE_PARAM_FS)
  96991. + || (!GET_CORE_IF(pcd)->core_params->i2c_enable)) {
  96992. + if (GET_CORE_IF(pcd)->srp_timer_started) {
  96993. + GET_CORE_IF(pcd)->srp_timer_started = 0;
  96994. + DWC_TIMER_CANCEL(GET_CORE_IF(pcd)->srp_timer);
  96995. + }
  96996. + }
  96997. + return 1;
  96998. +}
  96999. +
  97000. +/**
  97001. + * PCD Callback function for notifying the PCD device is suspended.
  97002. + *
  97003. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  97004. + */
  97005. +static int32_t dwc_otg_pcd_suspend_cb(void *p)
  97006. +{
  97007. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  97008. +
  97009. + if (pcd->fops->suspend) {
  97010. + DWC_SPINUNLOCK(pcd->lock);
  97011. + pcd->fops->suspend(pcd);
  97012. + DWC_SPINLOCK(pcd->lock);
  97013. + }
  97014. +
  97015. + return 1;
  97016. +}
  97017. +
  97018. +/**
  97019. + * PCD Callback function for stopping the PCD when switching to Host
  97020. + * mode.
  97021. + *
  97022. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  97023. + */
  97024. +static int32_t dwc_otg_pcd_stop_cb(void *p)
  97025. +{
  97026. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  97027. + extern void dwc_otg_pcd_stop(dwc_otg_pcd_t * _pcd);
  97028. +
  97029. + dwc_otg_pcd_stop(pcd);
  97030. + return 1;
  97031. +}
  97032. +
  97033. +/**
  97034. + * PCD Callback structure for handling mode switching.
  97035. + */
  97036. +static dwc_otg_cil_callbacks_t pcd_callbacks = {
  97037. + .start = dwc_otg_pcd_start_cb,
  97038. + .stop = dwc_otg_pcd_stop_cb,
  97039. + .suspend = dwc_otg_pcd_suspend_cb,
  97040. + .resume_wakeup = dwc_otg_pcd_resume_cb,
  97041. + .p = 0, /* Set at registration */
  97042. +};
  97043. +
  97044. +/**
  97045. + * This function allocates a DMA Descriptor chain for the Endpoint
  97046. + * buffer to be used for a transfer to/from the specified endpoint.
  97047. + */
  97048. +dwc_otg_dev_dma_desc_t *dwc_otg_ep_alloc_desc_chain(dwc_dma_t * dma_desc_addr,
  97049. + uint32_t count)
  97050. +{
  97051. + return DWC_DMA_ALLOC_ATOMIC(count * sizeof(dwc_otg_dev_dma_desc_t),
  97052. + dma_desc_addr);
  97053. +}
  97054. +
  97055. +/**
  97056. + * This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
  97057. + */
  97058. +void dwc_otg_ep_free_desc_chain(dwc_otg_dev_dma_desc_t * desc_addr,
  97059. + uint32_t dma_desc_addr, uint32_t count)
  97060. +{
  97061. + DWC_DMA_FREE(count * sizeof(dwc_otg_dev_dma_desc_t), desc_addr,
  97062. + dma_desc_addr);
  97063. +}
  97064. +
  97065. +#ifdef DWC_EN_ISOC
  97066. +
  97067. +/**
  97068. + * This function initializes a descriptor chain for Isochronous transfer
  97069. + *
  97070. + * @param core_if Programming view of DWC_otg controller.
  97071. + * @param dwc_ep The EP to start the transfer on.
  97072. + *
  97073. + */
  97074. +void dwc_otg_iso_ep_start_ddma_transfer(dwc_otg_core_if_t * core_if,
  97075. + dwc_ep_t * dwc_ep)
  97076. +{
  97077. +
  97078. + dsts_data_t dsts = {.d32 = 0 };
  97079. + depctl_data_t depctl = {.d32 = 0 };
  97080. + volatile uint32_t *addr;
  97081. + int i, j;
  97082. + uint32_t len;
  97083. +
  97084. + if (dwc_ep->is_in)
  97085. + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl / dwc_ep->bInterval;
  97086. + else
  97087. + dwc_ep->desc_cnt =
  97088. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  97089. + dwc_ep->bInterval;
  97090. +
  97091. + /** Allocate descriptors for double buffering */
  97092. + dwc_ep->iso_desc_addr =
  97093. + dwc_otg_ep_alloc_desc_chain(&dwc_ep->iso_dma_desc_addr,
  97094. + dwc_ep->desc_cnt * 2);
  97095. + if (dwc_ep->desc_addr) {
  97096. + DWC_WARN("%s, can't allocate DMA descriptor chain\n", __func__);
  97097. + return;
  97098. + }
  97099. +
  97100. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  97101. +
  97102. + /** ISO OUT EP */
  97103. + if (dwc_ep->is_in == 0) {
  97104. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  97105. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  97106. + dma_addr_t dma_ad;
  97107. + uint32_t data_per_desc;
  97108. + dwc_otg_dev_out_ep_regs_t *out_regs =
  97109. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  97110. + int offset;
  97111. +
  97112. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  97113. + dma_ad = (dma_addr_t) DWC_READ_REG32(&(out_regs->doepdma));
  97114. +
  97115. + /** Buffer 0 descriptors setup */
  97116. + dma_ad = dwc_ep->dma_addr0;
  97117. +
  97118. + sts.b_iso_out.bs = BS_HOST_READY;
  97119. + sts.b_iso_out.rxsts = 0;
  97120. + sts.b_iso_out.l = 0;
  97121. + sts.b_iso_out.sp = 0;
  97122. + sts.b_iso_out.ioc = 0;
  97123. + sts.b_iso_out.pid = 0;
  97124. + sts.b_iso_out.framenum = 0;
  97125. +
  97126. + offset = 0;
  97127. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  97128. + i += dwc_ep->pkt_per_frm) {
  97129. +
  97130. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  97131. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  97132. + if (len > dwc_ep->data_per_frame)
  97133. + data_per_desc =
  97134. + dwc_ep->data_per_frame -
  97135. + j * dwc_ep->maxpacket;
  97136. + else
  97137. + data_per_desc = dwc_ep->maxpacket;
  97138. + len = data_per_desc % 4;
  97139. + if (len)
  97140. + data_per_desc += 4 - len;
  97141. +
  97142. + sts.b_iso_out.rxbytes = data_per_desc;
  97143. + dma_desc->buf = dma_ad;
  97144. + dma_desc->status.d32 = sts.d32;
  97145. +
  97146. + offset += data_per_desc;
  97147. + dma_desc++;
  97148. + dma_ad += data_per_desc;
  97149. + }
  97150. + }
  97151. +
  97152. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  97153. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  97154. + if (len > dwc_ep->data_per_frame)
  97155. + data_per_desc =
  97156. + dwc_ep->data_per_frame -
  97157. + j * dwc_ep->maxpacket;
  97158. + else
  97159. + data_per_desc = dwc_ep->maxpacket;
  97160. + len = data_per_desc % 4;
  97161. + if (len)
  97162. + data_per_desc += 4 - len;
  97163. + sts.b_iso_out.rxbytes = data_per_desc;
  97164. + dma_desc->buf = dma_ad;
  97165. + dma_desc->status.d32 = sts.d32;
  97166. +
  97167. + offset += data_per_desc;
  97168. + dma_desc++;
  97169. + dma_ad += data_per_desc;
  97170. + }
  97171. +
  97172. + sts.b_iso_out.ioc = 1;
  97173. + len = (j + 1) * dwc_ep->maxpacket;
  97174. + if (len > dwc_ep->data_per_frame)
  97175. + data_per_desc =
  97176. + dwc_ep->data_per_frame - j * dwc_ep->maxpacket;
  97177. + else
  97178. + data_per_desc = dwc_ep->maxpacket;
  97179. + len = data_per_desc % 4;
  97180. + if (len)
  97181. + data_per_desc += 4 - len;
  97182. + sts.b_iso_out.rxbytes = data_per_desc;
  97183. +
  97184. + dma_desc->buf = dma_ad;
  97185. + dma_desc->status.d32 = sts.d32;
  97186. + dma_desc++;
  97187. +
  97188. + /** Buffer 1 descriptors setup */
  97189. + sts.b_iso_out.ioc = 0;
  97190. + dma_ad = dwc_ep->dma_addr1;
  97191. +
  97192. + offset = 0;
  97193. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  97194. + i += dwc_ep->pkt_per_frm) {
  97195. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  97196. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  97197. + if (len > dwc_ep->data_per_frame)
  97198. + data_per_desc =
  97199. + dwc_ep->data_per_frame -
  97200. + j * dwc_ep->maxpacket;
  97201. + else
  97202. + data_per_desc = dwc_ep->maxpacket;
  97203. + len = data_per_desc % 4;
  97204. + if (len)
  97205. + data_per_desc += 4 - len;
  97206. +
  97207. + data_per_desc =
  97208. + sts.b_iso_out.rxbytes = data_per_desc;
  97209. + dma_desc->buf = dma_ad;
  97210. + dma_desc->status.d32 = sts.d32;
  97211. +
  97212. + offset += data_per_desc;
  97213. + dma_desc++;
  97214. + dma_ad += data_per_desc;
  97215. + }
  97216. + }
  97217. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  97218. + data_per_desc =
  97219. + ((j + 1) * dwc_ep->maxpacket >
  97220. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  97221. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  97222. + data_per_desc +=
  97223. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  97224. + sts.b_iso_out.rxbytes = data_per_desc;
  97225. + dma_desc->buf = dma_ad;
  97226. + dma_desc->status.d32 = sts.d32;
  97227. +
  97228. + offset += data_per_desc;
  97229. + dma_desc++;
  97230. + dma_ad += data_per_desc;
  97231. + }
  97232. +
  97233. + sts.b_iso_out.ioc = 1;
  97234. + sts.b_iso_out.l = 1;
  97235. + data_per_desc =
  97236. + ((j + 1) * dwc_ep->maxpacket >
  97237. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  97238. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  97239. + data_per_desc +=
  97240. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  97241. + sts.b_iso_out.rxbytes = data_per_desc;
  97242. +
  97243. + dma_desc->buf = dma_ad;
  97244. + dma_desc->status.d32 = sts.d32;
  97245. +
  97246. + dwc_ep->next_frame = 0;
  97247. +
  97248. + /** Write dma_ad into DOEPDMA register */
  97249. + DWC_WRITE_REG32(&(out_regs->doepdma),
  97250. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  97251. +
  97252. + }
  97253. + /** ISO IN EP */
  97254. + else {
  97255. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  97256. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  97257. + dma_addr_t dma_ad;
  97258. + dwc_otg_dev_in_ep_regs_t *in_regs =
  97259. + core_if->dev_if->in_ep_regs[dwc_ep->num];
  97260. + unsigned int frmnumber;
  97261. + fifosize_data_t txfifosize, rxfifosize;
  97262. +
  97263. + txfifosize.d32 =
  97264. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[dwc_ep->num]->
  97265. + dtxfsts);
  97266. + rxfifosize.d32 =
  97267. + DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  97268. +
  97269. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  97270. +
  97271. + dma_ad = dwc_ep->dma_addr0;
  97272. +
  97273. + dsts.d32 =
  97274. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  97275. +
  97276. + sts.b_iso_in.bs = BS_HOST_READY;
  97277. + sts.b_iso_in.txsts = 0;
  97278. + sts.b_iso_in.sp =
  97279. + (dwc_ep->data_per_frame % dwc_ep->maxpacket) ? 1 : 0;
  97280. + sts.b_iso_in.ioc = 0;
  97281. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  97282. +
  97283. + frmnumber = dwc_ep->next_frame;
  97284. +
  97285. + sts.b_iso_in.framenum = frmnumber;
  97286. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  97287. + sts.b_iso_in.l = 0;
  97288. +
  97289. + /** Buffer 0 descriptors setup */
  97290. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  97291. + dma_desc->buf = dma_ad;
  97292. + dma_desc->status.d32 = sts.d32;
  97293. + dma_desc++;
  97294. +
  97295. + dma_ad += dwc_ep->data_per_frame;
  97296. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  97297. + }
  97298. +
  97299. + sts.b_iso_in.ioc = 1;
  97300. + dma_desc->buf = dma_ad;
  97301. + dma_desc->status.d32 = sts.d32;
  97302. + ++dma_desc;
  97303. +
  97304. + /** Buffer 1 descriptors setup */
  97305. + sts.b_iso_in.ioc = 0;
  97306. + dma_ad = dwc_ep->dma_addr1;
  97307. +
  97308. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  97309. + i += dwc_ep->pkt_per_frm) {
  97310. + dma_desc->buf = dma_ad;
  97311. + dma_desc->status.d32 = sts.d32;
  97312. + dma_desc++;
  97313. +
  97314. + dma_ad += dwc_ep->data_per_frame;
  97315. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  97316. +
  97317. + sts.b_iso_in.ioc = 0;
  97318. + }
  97319. + sts.b_iso_in.ioc = 1;
  97320. + sts.b_iso_in.l = 1;
  97321. +
  97322. + dma_desc->buf = dma_ad;
  97323. + dma_desc->status.d32 = sts.d32;
  97324. +
  97325. + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval;
  97326. +
  97327. + /** Write dma_ad into diepdma register */
  97328. + DWC_WRITE_REG32(&(in_regs->diepdma),
  97329. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  97330. + }
  97331. + /** Enable endpoint, clear nak */
  97332. + depctl.d32 = 0;
  97333. + depctl.b.epena = 1;
  97334. + depctl.b.usbactep = 1;
  97335. + depctl.b.cnak = 1;
  97336. +
  97337. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  97338. + depctl.d32 = DWC_READ_REG32(addr);
  97339. +}
  97340. +
  97341. +/**
  97342. + * This function initializes a descriptor chain for Isochronous transfer
  97343. + *
  97344. + * @param core_if Programming view of DWC_otg controller.
  97345. + * @param ep The EP to start the transfer on.
  97346. + *
  97347. + */
  97348. +void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  97349. + dwc_ep_t * ep)
  97350. +{
  97351. + depctl_data_t depctl = {.d32 = 0 };
  97352. + volatile uint32_t *addr;
  97353. +
  97354. + if (ep->is_in) {
  97355. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  97356. + } else {
  97357. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  97358. + }
  97359. +
  97360. + if (core_if->dma_enable == 0 || core_if->dma_desc_enable != 0) {
  97361. + return;
  97362. + } else {
  97363. + deptsiz_data_t deptsiz = {.d32 = 0 };
  97364. +
  97365. + ep->xfer_len =
  97366. + ep->data_per_frame * ep->buf_proc_intrvl / ep->bInterval;
  97367. + ep->pkt_cnt =
  97368. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  97369. + ep->xfer_count = 0;
  97370. + ep->xfer_buff =
  97371. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  97372. + ep->dma_addr =
  97373. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  97374. +
  97375. + if (ep->is_in) {
  97376. + /* Program the transfer size and packet count
  97377. + * as follows: xfersize = N * maxpacket +
  97378. + * short_packet pktcnt = N + (short_packet
  97379. + * exist ? 1 : 0)
  97380. + */
  97381. + deptsiz.b.mc = ep->pkt_per_frm;
  97382. + deptsiz.b.xfersize = ep->xfer_len;
  97383. + deptsiz.b.pktcnt =
  97384. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  97385. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  97386. + dieptsiz, deptsiz.d32);
  97387. +
  97388. + /* Write the DMA register */
  97389. + DWC_WRITE_REG32(&
  97390. + (core_if->dev_if->in_ep_regs[ep->num]->
  97391. + diepdma), (uint32_t) ep->dma_addr);
  97392. +
  97393. + } else {
  97394. + deptsiz.b.pktcnt =
  97395. + (ep->xfer_len + (ep->maxpacket - 1)) /
  97396. + ep->maxpacket;
  97397. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  97398. +
  97399. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  97400. + doeptsiz, deptsiz.d32);
  97401. +
  97402. + /* Write the DMA register */
  97403. + DWC_WRITE_REG32(&
  97404. + (core_if->dev_if->out_ep_regs[ep->num]->
  97405. + doepdma), (uint32_t) ep->dma_addr);
  97406. +
  97407. + }
  97408. + /** Enable endpoint, clear nak */
  97409. + depctl.d32 = 0;
  97410. + depctl.b.epena = 1;
  97411. + depctl.b.cnak = 1;
  97412. +
  97413. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  97414. + }
  97415. +}
  97416. +
  97417. +/**
  97418. + * This function does the setup for a data transfer for an EP and
  97419. + * starts the transfer. For an IN transfer, the packets will be
  97420. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  97421. + * the packets are unloaded from the Rx FIFO in the ISR.
  97422. + *
  97423. + * @param core_if Programming view of DWC_otg controller.
  97424. + * @param ep The EP to start the transfer on.
  97425. + */
  97426. +
  97427. +static void dwc_otg_iso_ep_start_transfer(dwc_otg_core_if_t * core_if,
  97428. + dwc_ep_t * ep)
  97429. +{
  97430. + if (core_if->dma_enable) {
  97431. + if (core_if->dma_desc_enable) {
  97432. + if (ep->is_in) {
  97433. + ep->desc_cnt = ep->pkt_cnt / ep->pkt_per_frm;
  97434. + } else {
  97435. + ep->desc_cnt = ep->pkt_cnt;
  97436. + }
  97437. + dwc_otg_iso_ep_start_ddma_transfer(core_if, ep);
  97438. + } else {
  97439. + if (core_if->pti_enh_enable) {
  97440. + dwc_otg_iso_ep_start_buf_transfer(core_if, ep);
  97441. + } else {
  97442. + ep->cur_pkt_addr =
  97443. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->
  97444. + xfer_buff0;
  97445. + ep->cur_pkt_dma_addr =
  97446. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->
  97447. + dma_addr0;
  97448. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  97449. + }
  97450. + }
  97451. + } else {
  97452. + ep->cur_pkt_addr =
  97453. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  97454. + ep->cur_pkt_dma_addr =
  97455. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  97456. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  97457. + }
  97458. +}
  97459. +
  97460. +/**
  97461. + * This function stops transfer for an EP and
  97462. + * resets the ep's variables.
  97463. + *
  97464. + * @param core_if Programming view of DWC_otg controller.
  97465. + * @param ep The EP to start the transfer on.
  97466. + */
  97467. +
  97468. +void dwc_otg_iso_ep_stop_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  97469. +{
  97470. + depctl_data_t depctl = {.d32 = 0 };
  97471. + volatile uint32_t *addr;
  97472. +
  97473. + if (ep->is_in == 1) {
  97474. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  97475. + } else {
  97476. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  97477. + }
  97478. +
  97479. + /* disable the ep */
  97480. + depctl.d32 = DWC_READ_REG32(addr);
  97481. +
  97482. + depctl.b.epdis = 1;
  97483. + depctl.b.snak = 1;
  97484. +
  97485. + DWC_WRITE_REG32(addr, depctl.d32);
  97486. +
  97487. + if (core_if->dma_desc_enable &&
  97488. + ep->iso_desc_addr && ep->iso_dma_desc_addr) {
  97489. + dwc_otg_ep_free_desc_chain(ep->iso_desc_addr,
  97490. + ep->iso_dma_desc_addr,
  97491. + ep->desc_cnt * 2);
  97492. + }
  97493. +
  97494. + /* reset varibales */
  97495. + ep->dma_addr0 = 0;
  97496. + ep->dma_addr1 = 0;
  97497. + ep->xfer_buff0 = 0;
  97498. + ep->xfer_buff1 = 0;
  97499. + ep->data_per_frame = 0;
  97500. + ep->data_pattern_frame = 0;
  97501. + ep->sync_frame = 0;
  97502. + ep->buf_proc_intrvl = 0;
  97503. + ep->bInterval = 0;
  97504. + ep->proc_buf_num = 0;
  97505. + ep->pkt_per_frm = 0;
  97506. + ep->pkt_per_frm = 0;
  97507. + ep->desc_cnt = 0;
  97508. + ep->iso_desc_addr = 0;
  97509. + ep->iso_dma_desc_addr = 0;
  97510. +}
  97511. +
  97512. +int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  97513. + uint8_t * buf0, uint8_t * buf1, dwc_dma_t dma0,
  97514. + dwc_dma_t dma1, int sync_frame, int dp_frame,
  97515. + int data_per_frame, int start_frame,
  97516. + int buf_proc_intrvl, void *req_handle,
  97517. + int atomic_alloc)
  97518. +{
  97519. + dwc_otg_pcd_ep_t *ep;
  97520. + dwc_irqflags_t flags = 0;
  97521. + dwc_ep_t *dwc_ep;
  97522. + int32_t frm_data;
  97523. + dsts_data_t dsts;
  97524. + dwc_otg_core_if_t *core_if;
  97525. +
  97526. + ep = get_ep_from_handle(pcd, ep_handle);
  97527. +
  97528. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  97529. + DWC_WARN("bad ep\n");
  97530. + return -DWC_E_INVALID;
  97531. + }
  97532. +
  97533. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  97534. + core_if = GET_CORE_IF(pcd);
  97535. + dwc_ep = &ep->dwc_ep;
  97536. +
  97537. + if (ep->iso_req_handle) {
  97538. + DWC_WARN("ISO request in progress\n");
  97539. + }
  97540. +
  97541. + dwc_ep->dma_addr0 = dma0;
  97542. + dwc_ep->dma_addr1 = dma1;
  97543. +
  97544. + dwc_ep->xfer_buff0 = buf0;
  97545. + dwc_ep->xfer_buff1 = buf1;
  97546. +
  97547. + dwc_ep->data_per_frame = data_per_frame;
  97548. +
  97549. + /** @todo - pattern data support is to be implemented in the future */
  97550. + dwc_ep->data_pattern_frame = dp_frame;
  97551. + dwc_ep->sync_frame = sync_frame;
  97552. +
  97553. + dwc_ep->buf_proc_intrvl = buf_proc_intrvl;
  97554. +
  97555. + dwc_ep->bInterval = 1 << (ep->desc->bInterval - 1);
  97556. +
  97557. + dwc_ep->proc_buf_num = 0;
  97558. +
  97559. + dwc_ep->pkt_per_frm = 0;
  97560. + frm_data = ep->dwc_ep.data_per_frame;
  97561. + while (frm_data > 0) {
  97562. + dwc_ep->pkt_per_frm++;
  97563. + frm_data -= ep->dwc_ep.maxpacket;
  97564. + }
  97565. +
  97566. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  97567. +
  97568. + if (start_frame == -1) {
  97569. + dwc_ep->next_frame = dsts.b.soffn + 1;
  97570. + if (dwc_ep->bInterval != 1) {
  97571. + dwc_ep->next_frame =
  97572. + dwc_ep->next_frame + (dwc_ep->bInterval - 1 -
  97573. + dwc_ep->next_frame %
  97574. + dwc_ep->bInterval);
  97575. + }
  97576. + } else {
  97577. + dwc_ep->next_frame = start_frame;
  97578. + }
  97579. +
  97580. + if (!core_if->pti_enh_enable) {
  97581. + dwc_ep->pkt_cnt =
  97582. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  97583. + dwc_ep->bInterval;
  97584. + } else {
  97585. + dwc_ep->pkt_cnt =
  97586. + (dwc_ep->data_per_frame *
  97587. + (dwc_ep->buf_proc_intrvl / dwc_ep->bInterval)
  97588. + - 1 + dwc_ep->maxpacket) / dwc_ep->maxpacket;
  97589. + }
  97590. +
  97591. + if (core_if->dma_desc_enable) {
  97592. + dwc_ep->desc_cnt =
  97593. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  97594. + dwc_ep->bInterval;
  97595. + }
  97596. +
  97597. + if (atomic_alloc) {
  97598. + dwc_ep->pkt_info =
  97599. + DWC_ALLOC_ATOMIC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  97600. + } else {
  97601. + dwc_ep->pkt_info =
  97602. + DWC_ALLOC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  97603. + }
  97604. + if (!dwc_ep->pkt_info) {
  97605. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  97606. + return -DWC_E_NO_MEMORY;
  97607. + }
  97608. + if (core_if->pti_enh_enable) {
  97609. + dwc_memset(dwc_ep->pkt_info, 0,
  97610. + sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  97611. + }
  97612. +
  97613. + dwc_ep->cur_pkt = 0;
  97614. + ep->iso_req_handle = req_handle;
  97615. +
  97616. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  97617. + dwc_otg_iso_ep_start_transfer(core_if, dwc_ep);
  97618. + return 0;
  97619. +}
  97620. +
  97621. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  97622. + void *req_handle)
  97623. +{
  97624. + dwc_irqflags_t flags = 0;
  97625. + dwc_otg_pcd_ep_t *ep;
  97626. + dwc_ep_t *dwc_ep;
  97627. +
  97628. + ep = get_ep_from_handle(pcd, ep_handle);
  97629. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  97630. + DWC_WARN("bad ep\n");
  97631. + return -DWC_E_INVALID;
  97632. + }
  97633. + dwc_ep = &ep->dwc_ep;
  97634. +
  97635. + dwc_otg_iso_ep_stop_transfer(GET_CORE_IF(pcd), dwc_ep);
  97636. +
  97637. + DWC_FREE(dwc_ep->pkt_info);
  97638. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  97639. + if (ep->iso_req_handle != req_handle) {
  97640. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  97641. + return -DWC_E_INVALID;
  97642. + }
  97643. +
  97644. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  97645. +
  97646. + ep->iso_req_handle = 0;
  97647. + return 0;
  97648. +}
  97649. +
  97650. +/**
  97651. + * This function is used for perodical data exchnage between PCD and gadget drivers.
  97652. + * for Isochronous EPs
  97653. + *
  97654. + * - Every time a sync period completes this function is called to
  97655. + * perform data exchange between PCD and gadget
  97656. + */
  97657. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  97658. + void *req_handle)
  97659. +{
  97660. + int i;
  97661. + dwc_ep_t *dwc_ep;
  97662. +
  97663. + dwc_ep = &ep->dwc_ep;
  97664. +
  97665. + DWC_SPINUNLOCK(ep->pcd->lock);
  97666. + pcd->fops->isoc_complete(pcd, ep->priv, ep->iso_req_handle,
  97667. + dwc_ep->proc_buf_num ^ 0x1);
  97668. + DWC_SPINLOCK(ep->pcd->lock);
  97669. +
  97670. + for (i = 0; i < dwc_ep->pkt_cnt; ++i) {
  97671. + dwc_ep->pkt_info[i].status = 0;
  97672. + dwc_ep->pkt_info[i].offset = 0;
  97673. + dwc_ep->pkt_info[i].length = 0;
  97674. + }
  97675. +}
  97676. +
  97677. +int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd, void *ep_handle,
  97678. + void *iso_req_handle)
  97679. +{
  97680. + dwc_otg_pcd_ep_t *ep;
  97681. + dwc_ep_t *dwc_ep;
  97682. +
  97683. + ep = get_ep_from_handle(pcd, ep_handle);
  97684. + if (!ep->desc || ep->dwc_ep.num == 0) {
  97685. + DWC_WARN("bad ep\n");
  97686. + return -DWC_E_INVALID;
  97687. + }
  97688. + dwc_ep = &ep->dwc_ep;
  97689. +
  97690. + return dwc_ep->pkt_cnt;
  97691. +}
  97692. +
  97693. +void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd, void *ep_handle,
  97694. + void *iso_req_handle, int packet,
  97695. + int *status, int *actual, int *offset)
  97696. +{
  97697. + dwc_otg_pcd_ep_t *ep;
  97698. + dwc_ep_t *dwc_ep;
  97699. +
  97700. + ep = get_ep_from_handle(pcd, ep_handle);
  97701. + if (!ep)
  97702. + DWC_WARN("bad ep\n");
  97703. +
  97704. + dwc_ep = &ep->dwc_ep;
  97705. +
  97706. + *status = dwc_ep->pkt_info[packet].status;
  97707. + *actual = dwc_ep->pkt_info[packet].length;
  97708. + *offset = dwc_ep->pkt_info[packet].offset;
  97709. +}
  97710. +
  97711. +#endif /* DWC_EN_ISOC */
  97712. +
  97713. +static void dwc_otg_pcd_init_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * pcd_ep,
  97714. + uint32_t is_in, uint32_t ep_num)
  97715. +{
  97716. + /* Init EP structure */
  97717. + pcd_ep->desc = 0;
  97718. + pcd_ep->pcd = pcd;
  97719. + pcd_ep->stopped = 1;
  97720. + pcd_ep->queue_sof = 0;
  97721. +
  97722. + /* Init DWC ep structure */
  97723. + pcd_ep->dwc_ep.is_in = is_in;
  97724. + pcd_ep->dwc_ep.num = ep_num;
  97725. + pcd_ep->dwc_ep.active = 0;
  97726. + pcd_ep->dwc_ep.tx_fifo_num = 0;
  97727. + /* Control until ep is actvated */
  97728. + pcd_ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  97729. + pcd_ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
  97730. + pcd_ep->dwc_ep.dma_addr = 0;
  97731. + pcd_ep->dwc_ep.start_xfer_buff = 0;
  97732. + pcd_ep->dwc_ep.xfer_buff = 0;
  97733. + pcd_ep->dwc_ep.xfer_len = 0;
  97734. + pcd_ep->dwc_ep.xfer_count = 0;
  97735. + pcd_ep->dwc_ep.sent_zlp = 0;
  97736. + pcd_ep->dwc_ep.total_len = 0;
  97737. + pcd_ep->dwc_ep.desc_addr = 0;
  97738. + pcd_ep->dwc_ep.dma_desc_addr = 0;
  97739. + DWC_CIRCLEQ_INIT(&pcd_ep->queue);
  97740. +}
  97741. +
  97742. +/**
  97743. + * Initialize ep's
  97744. + */
  97745. +static void dwc_otg_pcd_reinit(dwc_otg_pcd_t * pcd)
  97746. +{
  97747. + int i;
  97748. + uint32_t hwcfg1;
  97749. + dwc_otg_pcd_ep_t *ep;
  97750. + int in_ep_cntr, out_ep_cntr;
  97751. + uint32_t num_in_eps = (GET_CORE_IF(pcd))->dev_if->num_in_eps;
  97752. + uint32_t num_out_eps = (GET_CORE_IF(pcd))->dev_if->num_out_eps;
  97753. +
  97754. + /**
  97755. + * Initialize the EP0 structure.
  97756. + */
  97757. + ep = &pcd->ep0;
  97758. + dwc_otg_pcd_init_ep(pcd, ep, 0, 0);
  97759. +
  97760. + in_ep_cntr = 0;
  97761. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 3;
  97762. + for (i = 1; in_ep_cntr < num_in_eps; i++) {
  97763. + if ((hwcfg1 & 0x1) == 0) {
  97764. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[in_ep_cntr];
  97765. + in_ep_cntr++;
  97766. + /**
  97767. + * @todo NGS: Add direction to EP, based on contents
  97768. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  97769. + * sprintf(";r
  97770. + */
  97771. + dwc_otg_pcd_init_ep(pcd, ep, 1 /* IN */ , i);
  97772. +
  97773. + DWC_CIRCLEQ_INIT(&ep->queue);
  97774. + }
  97775. + hwcfg1 >>= 2;
  97776. + }
  97777. +
  97778. + out_ep_cntr = 0;
  97779. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 2;
  97780. + for (i = 1; out_ep_cntr < num_out_eps; i++) {
  97781. + if ((hwcfg1 & 0x1) == 0) {
  97782. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[out_ep_cntr];
  97783. + out_ep_cntr++;
  97784. + /**
  97785. + * @todo NGS: Add direction to EP, based on contents
  97786. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  97787. + * sprintf(";r
  97788. + */
  97789. + dwc_otg_pcd_init_ep(pcd, ep, 0 /* OUT */ , i);
  97790. + DWC_CIRCLEQ_INIT(&ep->queue);
  97791. + }
  97792. + hwcfg1 >>= 2;
  97793. + }
  97794. +
  97795. + pcd->ep0state = EP0_DISCONNECT;
  97796. + pcd->ep0.dwc_ep.maxpacket = MAX_EP0_SIZE;
  97797. + pcd->ep0.dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  97798. +}
  97799. +
  97800. +/**
  97801. + * This function is called when the SRP timer expires. The SRP should
  97802. + * complete within 6 seconds.
  97803. + */
  97804. +static void srp_timeout(void *ptr)
  97805. +{
  97806. + gotgctl_data_t gotgctl;
  97807. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  97808. + volatile uint32_t *addr = &core_if->core_global_regs->gotgctl;
  97809. +
  97810. + gotgctl.d32 = DWC_READ_REG32(addr);
  97811. +
  97812. + core_if->srp_timer_started = 0;
  97813. +
  97814. + if (core_if->adp_enable) {
  97815. + if (gotgctl.b.bsesvld == 0) {
  97816. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  97817. + DWC_PRINTF("SRP Timeout BSESSVLD = 0\n");
  97818. + /* Power off the core */
  97819. + if (core_if->power_down == 2) {
  97820. + gpwrdn.b.pwrdnswtch = 1;
  97821. + DWC_MODIFY_REG32(&core_if->
  97822. + core_global_regs->gpwrdn,
  97823. + gpwrdn.d32, 0);
  97824. + }
  97825. +
  97826. + gpwrdn.d32 = 0;
  97827. + gpwrdn.b.pmuintsel = 1;
  97828. + gpwrdn.b.pmuactv = 1;
  97829. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  97830. + gpwrdn.d32);
  97831. + dwc_otg_adp_probe_start(core_if);
  97832. + } else {
  97833. + DWC_PRINTF("SRP Timeout BSESSVLD = 1\n");
  97834. + core_if->op_state = B_PERIPHERAL;
  97835. + dwc_otg_core_init(core_if);
  97836. + dwc_otg_enable_global_interrupts(core_if);
  97837. + cil_pcd_start(core_if);
  97838. + }
  97839. + }
  97840. +
  97841. + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
  97842. + (core_if->core_params->i2c_enable)) {
  97843. + DWC_PRINTF("SRP Timeout\n");
  97844. +
  97845. + if ((core_if->srp_success) && (gotgctl.b.bsesvld)) {
  97846. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  97847. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  97848. + }
  97849. +
  97850. + /* Clear Session Request */
  97851. + gotgctl.d32 = 0;
  97852. + gotgctl.b.sesreq = 1;
  97853. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl,
  97854. + gotgctl.d32, 0);
  97855. +
  97856. + core_if->srp_success = 0;
  97857. + } else {
  97858. + __DWC_ERROR("Device not connected/responding\n");
  97859. + gotgctl.b.sesreq = 0;
  97860. + DWC_WRITE_REG32(addr, gotgctl.d32);
  97861. + }
  97862. + } else if (gotgctl.b.sesreq) {
  97863. + DWC_PRINTF("SRP Timeout\n");
  97864. +
  97865. + __DWC_ERROR("Device not connected/responding\n");
  97866. + gotgctl.b.sesreq = 0;
  97867. + DWC_WRITE_REG32(addr, gotgctl.d32);
  97868. + } else {
  97869. + DWC_PRINTF(" SRP GOTGCTL=%0x\n", gotgctl.d32);
  97870. + }
  97871. +}
  97872. +
  97873. +/**
  97874. + * Tasklet
  97875. + *
  97876. + */
  97877. +extern void start_next_request(dwc_otg_pcd_ep_t * ep);
  97878. +
  97879. +static void start_xfer_tasklet_func(void *data)
  97880. +{
  97881. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  97882. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  97883. +
  97884. + int i;
  97885. + depctl_data_t diepctl;
  97886. +
  97887. + DWC_DEBUGPL(DBG_PCDV, "Start xfer tasklet\n");
  97888. +
  97889. + diepctl.d32 = DWC_READ_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl);
  97890. +
  97891. + if (pcd->ep0.queue_sof) {
  97892. + pcd->ep0.queue_sof = 0;
  97893. + start_next_request(&pcd->ep0);
  97894. + // break;
  97895. + }
  97896. +
  97897. + for (i = 0; i < core_if->dev_if->num_in_eps; i++) {
  97898. + depctl_data_t diepctl;
  97899. + diepctl.d32 =
  97900. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  97901. +
  97902. + if (pcd->in_ep[i].queue_sof) {
  97903. + pcd->in_ep[i].queue_sof = 0;
  97904. + start_next_request(&pcd->in_ep[i]);
  97905. + // break;
  97906. + }
  97907. + }
  97908. +
  97909. + return;
  97910. +}
  97911. +
  97912. +/**
  97913. + * This function initialized the PCD portion of the driver.
  97914. + *
  97915. + */
  97916. +dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if)
  97917. +{
  97918. + dwc_otg_pcd_t *pcd = NULL;
  97919. + dwc_otg_dev_if_t *dev_if;
  97920. + int i;
  97921. +
  97922. + /*
  97923. + * Allocate PCD structure
  97924. + */
  97925. + pcd = DWC_ALLOC(sizeof(dwc_otg_pcd_t));
  97926. +
  97927. + if (pcd == NULL) {
  97928. + return NULL;
  97929. + }
  97930. +
  97931. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_SPINLOCK))
  97932. + DWC_SPINLOCK_ALLOC_LINUX_DEBUG(pcd->lock);
  97933. +#else
  97934. + pcd->lock = DWC_SPINLOCK_ALLOC();
  97935. +#endif
  97936. + DWC_DEBUGPL(DBG_HCDV, "Init of PCD %p given core_if %p\n",
  97937. + pcd, core_if);//GRAYG
  97938. + if (!pcd->lock) {
  97939. + DWC_ERROR("Could not allocate lock for pcd");
  97940. + DWC_FREE(pcd);
  97941. + return NULL;
  97942. + }
  97943. + /* Set core_if's lock pointer to hcd->lock */
  97944. + core_if->lock = pcd->lock;
  97945. + pcd->core_if = core_if;
  97946. +
  97947. + dev_if = core_if->dev_if;
  97948. + dev_if->isoc_ep = NULL;
  97949. +
  97950. + if (core_if->hwcfg4.b.ded_fifo_en) {
  97951. + DWC_PRINTF("Dedicated Tx FIFOs mode\n");
  97952. + } else {
  97953. + DWC_PRINTF("Shared Tx FIFO mode\n");
  97954. + }
  97955. +
  97956. + /*
  97957. + * Initialized the Core for Device mode here if there is nod ADP support.
  97958. + * Otherwise it will be done later in dwc_otg_adp_start routine.
  97959. + */
  97960. + if (dwc_otg_is_device_mode(core_if) /*&& !core_if->adp_enable*/) {
  97961. + dwc_otg_core_dev_init(core_if);
  97962. + }
  97963. +
  97964. + /*
  97965. + * Register the PCD Callbacks.
  97966. + */
  97967. + dwc_otg_cil_register_pcd_callbacks(core_if, &pcd_callbacks, pcd);
  97968. +
  97969. + /*
  97970. + * Initialize the DMA buffer for SETUP packets
  97971. + */
  97972. + if (GET_CORE_IF(pcd)->dma_enable) {
  97973. + pcd->setup_pkt =
  97974. + DWC_DMA_ALLOC(sizeof(*pcd->setup_pkt) * 5,
  97975. + &pcd->setup_pkt_dma_handle);
  97976. + if (pcd->setup_pkt == NULL) {
  97977. + DWC_FREE(pcd);
  97978. + return NULL;
  97979. + }
  97980. +
  97981. + pcd->status_buf =
  97982. + DWC_DMA_ALLOC(sizeof(uint16_t),
  97983. + &pcd->status_buf_dma_handle);
  97984. + if (pcd->status_buf == NULL) {
  97985. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  97986. + pcd->setup_pkt, pcd->setup_pkt_dma_handle);
  97987. + DWC_FREE(pcd);
  97988. + return NULL;
  97989. + }
  97990. +
  97991. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  97992. + dev_if->setup_desc_addr[0] =
  97993. + dwc_otg_ep_alloc_desc_chain
  97994. + (&dev_if->dma_setup_desc_addr[0], 1);
  97995. + dev_if->setup_desc_addr[1] =
  97996. + dwc_otg_ep_alloc_desc_chain
  97997. + (&dev_if->dma_setup_desc_addr[1], 1);
  97998. + dev_if->in_desc_addr =
  97999. + dwc_otg_ep_alloc_desc_chain
  98000. + (&dev_if->dma_in_desc_addr, 1);
  98001. + dev_if->out_desc_addr =
  98002. + dwc_otg_ep_alloc_desc_chain
  98003. + (&dev_if->dma_out_desc_addr, 1);
  98004. + pcd->data_terminated = 0;
  98005. +
  98006. + if (dev_if->setup_desc_addr[0] == 0
  98007. + || dev_if->setup_desc_addr[1] == 0
  98008. + || dev_if->in_desc_addr == 0
  98009. + || dev_if->out_desc_addr == 0) {
  98010. +
  98011. + if (dev_if->out_desc_addr)
  98012. + dwc_otg_ep_free_desc_chain
  98013. + (dev_if->out_desc_addr,
  98014. + dev_if->dma_out_desc_addr, 1);
  98015. + if (dev_if->in_desc_addr)
  98016. + dwc_otg_ep_free_desc_chain
  98017. + (dev_if->in_desc_addr,
  98018. + dev_if->dma_in_desc_addr, 1);
  98019. + if (dev_if->setup_desc_addr[1])
  98020. + dwc_otg_ep_free_desc_chain
  98021. + (dev_if->setup_desc_addr[1],
  98022. + dev_if->dma_setup_desc_addr[1], 1);
  98023. + if (dev_if->setup_desc_addr[0])
  98024. + dwc_otg_ep_free_desc_chain
  98025. + (dev_if->setup_desc_addr[0],
  98026. + dev_if->dma_setup_desc_addr[0], 1);
  98027. +
  98028. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  98029. + pcd->setup_pkt,
  98030. + pcd->setup_pkt_dma_handle);
  98031. + DWC_DMA_FREE(sizeof(*pcd->status_buf),
  98032. + pcd->status_buf,
  98033. + pcd->status_buf_dma_handle);
  98034. +
  98035. + DWC_FREE(pcd);
  98036. +
  98037. + return NULL;
  98038. + }
  98039. + }
  98040. + } else {
  98041. + pcd->setup_pkt = DWC_ALLOC(sizeof(*pcd->setup_pkt) * 5);
  98042. + if (pcd->setup_pkt == NULL) {
  98043. + DWC_FREE(pcd);
  98044. + return NULL;
  98045. + }
  98046. +
  98047. + pcd->status_buf = DWC_ALLOC(sizeof(uint16_t));
  98048. + if (pcd->status_buf == NULL) {
  98049. + DWC_FREE(pcd->setup_pkt);
  98050. + DWC_FREE(pcd);
  98051. + return NULL;
  98052. + }
  98053. + }
  98054. +
  98055. + dwc_otg_pcd_reinit(pcd);
  98056. +
  98057. + /* Allocate the cfi object for the PCD */
  98058. +#ifdef DWC_UTE_CFI
  98059. + pcd->cfi = DWC_ALLOC(sizeof(cfiobject_t));
  98060. + if (NULL == pcd->cfi)
  98061. + goto fail;
  98062. + if (init_cfi(pcd->cfi)) {
  98063. + CFI_INFO("%s: Failed to init the CFI object\n", __func__);
  98064. + goto fail;
  98065. + }
  98066. +#endif
  98067. +
  98068. + /* Initialize tasklets */
  98069. + pcd->start_xfer_tasklet = DWC_TASK_ALLOC("xfer_tasklet",
  98070. + start_xfer_tasklet_func, pcd);
  98071. + pcd->test_mode_tasklet = DWC_TASK_ALLOC("test_mode_tasklet",
  98072. + do_test_mode, pcd);
  98073. +
  98074. + /* Initialize SRP timer */
  98075. + core_if->srp_timer = DWC_TIMER_ALLOC("SRP TIMER", srp_timeout, core_if);
  98076. +
  98077. + if (core_if->core_params->dev_out_nak) {
  98078. + /**
  98079. + * Initialize xfer timeout timer. Implemented for
  98080. + * 2.93a feature "Device DDMA OUT NAK Enhancement"
  98081. + */
  98082. + for(i = 0; i < MAX_EPS_CHANNELS; i++) {
  98083. + pcd->core_if->ep_xfer_timer[i] =
  98084. + DWC_TIMER_ALLOC("ep timer", ep_xfer_timeout,
  98085. + &pcd->core_if->ep_xfer_info[i]);
  98086. + }
  98087. + }
  98088. +
  98089. + return pcd;
  98090. +#ifdef DWC_UTE_CFI
  98091. +fail:
  98092. +#endif
  98093. + if (pcd->setup_pkt)
  98094. + DWC_FREE(pcd->setup_pkt);
  98095. + if (pcd->status_buf)
  98096. + DWC_FREE(pcd->status_buf);
  98097. +#ifdef DWC_UTE_CFI
  98098. + if (pcd->cfi)
  98099. + DWC_FREE(pcd->cfi);
  98100. +#endif
  98101. + if (pcd)
  98102. + DWC_FREE(pcd);
  98103. + return NULL;
  98104. +
  98105. +}
  98106. +
  98107. +/**
  98108. + * Remove PCD specific data
  98109. + */
  98110. +void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd)
  98111. +{
  98112. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  98113. + int i;
  98114. + if (pcd->core_if->core_params->dev_out_nak) {
  98115. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  98116. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[i]);
  98117. + pcd->core_if->ep_xfer_info[i].state = 0;
  98118. + }
  98119. + }
  98120. +
  98121. + if (GET_CORE_IF(pcd)->dma_enable) {
  98122. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5, pcd->setup_pkt,
  98123. + pcd->setup_pkt_dma_handle);
  98124. + DWC_DMA_FREE(sizeof(uint16_t), pcd->status_buf,
  98125. + pcd->status_buf_dma_handle);
  98126. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  98127. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0],
  98128. + dev_if->dma_setup_desc_addr
  98129. + [0], 1);
  98130. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1],
  98131. + dev_if->dma_setup_desc_addr
  98132. + [1], 1);
  98133. + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr,
  98134. + dev_if->dma_in_desc_addr, 1);
  98135. + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr,
  98136. + dev_if->dma_out_desc_addr,
  98137. + 1);
  98138. + }
  98139. + } else {
  98140. + DWC_FREE(pcd->setup_pkt);
  98141. + DWC_FREE(pcd->status_buf);
  98142. + }
  98143. + DWC_SPINLOCK_FREE(pcd->lock);
  98144. + /* Set core_if's lock pointer to NULL */
  98145. + pcd->core_if->lock = NULL;
  98146. +
  98147. + DWC_TASK_FREE(pcd->start_xfer_tasklet);
  98148. + DWC_TASK_FREE(pcd->test_mode_tasklet);
  98149. + if (pcd->core_if->core_params->dev_out_nak) {
  98150. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  98151. + if (pcd->core_if->ep_xfer_timer[i]) {
  98152. + DWC_TIMER_FREE(pcd->core_if->ep_xfer_timer[i]);
  98153. + }
  98154. + }
  98155. + }
  98156. +
  98157. +/* Release the CFI object's dynamic memory */
  98158. +#ifdef DWC_UTE_CFI
  98159. + if (pcd->cfi->ops.release) {
  98160. + pcd->cfi->ops.release(pcd->cfi);
  98161. + }
  98162. +#endif
  98163. +
  98164. + DWC_FREE(pcd);
  98165. +}
  98166. +
  98167. +/**
  98168. + * Returns whether registered pcd is dual speed or not
  98169. + */
  98170. +uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd)
  98171. +{
  98172. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  98173. +
  98174. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) ||
  98175. + ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  98176. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  98177. + (core_if->core_params->ulpi_fs_ls))) {
  98178. + return 0;
  98179. + }
  98180. +
  98181. + return 1;
  98182. +}
  98183. +
  98184. +/**
  98185. + * Returns whether registered pcd is OTG capable or not
  98186. + */
  98187. +uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd)
  98188. +{
  98189. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  98190. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  98191. +
  98192. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  98193. + if (!usbcfg.b.srpcap || !usbcfg.b.hnpcap) {
  98194. + return 0;
  98195. + }
  98196. +
  98197. + return 1;
  98198. +}
  98199. +
  98200. +/**
  98201. + * This function assigns periodic Tx FIFO to an periodic EP
  98202. + * in shared Tx FIFO mode
  98203. + */
  98204. +static uint32_t assign_tx_fifo(dwc_otg_core_if_t * core_if)
  98205. +{
  98206. + uint32_t TxMsk = 1;
  98207. + int i;
  98208. +
  98209. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; ++i) {
  98210. + if ((TxMsk & core_if->tx_msk) == 0) {
  98211. + core_if->tx_msk |= TxMsk;
  98212. + return i + 1;
  98213. + }
  98214. + TxMsk <<= 1;
  98215. + }
  98216. + return 0;
  98217. +}
  98218. +
  98219. +/**
  98220. + * This function assigns periodic Tx FIFO to an periodic EP
  98221. + * in shared Tx FIFO mode
  98222. + */
  98223. +static uint32_t assign_perio_tx_fifo(dwc_otg_core_if_t * core_if)
  98224. +{
  98225. + uint32_t PerTxMsk = 1;
  98226. + int i;
  98227. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; ++i) {
  98228. + if ((PerTxMsk & core_if->p_tx_msk) == 0) {
  98229. + core_if->p_tx_msk |= PerTxMsk;
  98230. + return i + 1;
  98231. + }
  98232. + PerTxMsk <<= 1;
  98233. + }
  98234. + return 0;
  98235. +}
  98236. +
  98237. +/**
  98238. + * This function releases periodic Tx FIFO
  98239. + * in shared Tx FIFO mode
  98240. + */
  98241. +static void release_perio_tx_fifo(dwc_otg_core_if_t * core_if,
  98242. + uint32_t fifo_num)
  98243. +{
  98244. + core_if->p_tx_msk =
  98245. + (core_if->p_tx_msk & (1 << (fifo_num - 1))) ^ core_if->p_tx_msk;
  98246. +}
  98247. +
  98248. +/**
  98249. + * This function releases periodic Tx FIFO
  98250. + * in shared Tx FIFO mode
  98251. + */
  98252. +static void release_tx_fifo(dwc_otg_core_if_t * core_if, uint32_t fifo_num)
  98253. +{
  98254. + core_if->tx_msk =
  98255. + (core_if->tx_msk & (1 << (fifo_num - 1))) ^ core_if->tx_msk;
  98256. +}
  98257. +
  98258. +/**
  98259. + * This function is being called from gadget
  98260. + * to enable PCD endpoint.
  98261. + */
  98262. +int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  98263. + const uint8_t * ep_desc, void *usb_ep)
  98264. +{
  98265. + int num, dir;
  98266. + dwc_otg_pcd_ep_t *ep = NULL;
  98267. + const usb_endpoint_descriptor_t *desc;
  98268. + dwc_irqflags_t flags;
  98269. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  98270. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  98271. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  98272. + int retval = 0;
  98273. + int i, epcount;
  98274. +
  98275. + desc = (const usb_endpoint_descriptor_t *)ep_desc;
  98276. +
  98277. + if (!desc) {
  98278. + pcd->ep0.priv = usb_ep;
  98279. + ep = &pcd->ep0;
  98280. + retval = -DWC_E_INVALID;
  98281. + goto out;
  98282. + }
  98283. +
  98284. + num = UE_GET_ADDR(desc->bEndpointAddress);
  98285. + dir = UE_GET_DIR(desc->bEndpointAddress);
  98286. +
  98287. + if (!desc->wMaxPacketSize) {
  98288. + DWC_WARN("bad maxpacketsize\n");
  98289. + retval = -DWC_E_INVALID;
  98290. + goto out;
  98291. + }
  98292. +
  98293. + if (dir == UE_DIR_IN) {
  98294. + epcount = pcd->core_if->dev_if->num_in_eps;
  98295. + for (i = 0; i < epcount; i++) {
  98296. + if (num == pcd->in_ep[i].dwc_ep.num) {
  98297. + ep = &pcd->in_ep[i];
  98298. + break;
  98299. + }
  98300. + }
  98301. + } else {
  98302. + epcount = pcd->core_if->dev_if->num_out_eps;
  98303. + for (i = 0; i < epcount; i++) {
  98304. + if (num == pcd->out_ep[i].dwc_ep.num) {
  98305. + ep = &pcd->out_ep[i];
  98306. + break;
  98307. + }
  98308. + }
  98309. + }
  98310. +
  98311. + if (!ep) {
  98312. + DWC_WARN("bad address\n");
  98313. + retval = -DWC_E_INVALID;
  98314. + goto out;
  98315. + }
  98316. +
  98317. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  98318. +
  98319. + ep->desc = desc;
  98320. + ep->priv = usb_ep;
  98321. +
  98322. + /*
  98323. + * Activate the EP
  98324. + */
  98325. + ep->stopped = 0;
  98326. +
  98327. + ep->dwc_ep.is_in = (dir == UE_DIR_IN);
  98328. + ep->dwc_ep.maxpacket = UGETW(desc->wMaxPacketSize);
  98329. +
  98330. + ep->dwc_ep.type = desc->bmAttributes & UE_XFERTYPE;
  98331. +
  98332. + if (ep->dwc_ep.is_in) {
  98333. + if (!GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  98334. + ep->dwc_ep.tx_fifo_num = 0;
  98335. +
  98336. + if (ep->dwc_ep.type == UE_ISOCHRONOUS) {
  98337. + /*
  98338. + * if ISOC EP then assign a Periodic Tx FIFO.
  98339. + */
  98340. + ep->dwc_ep.tx_fifo_num =
  98341. + assign_perio_tx_fifo(GET_CORE_IF(pcd));
  98342. + }
  98343. + } else {
  98344. + /*
  98345. + * if Dedicated FIFOs mode is on then assign a Tx FIFO.
  98346. + */
  98347. + ep->dwc_ep.tx_fifo_num =
  98348. + assign_tx_fifo(GET_CORE_IF(pcd));
  98349. + }
  98350. +
  98351. + /* Calculating EP info controller base address */
  98352. + if (ep->dwc_ep.tx_fifo_num
  98353. + && GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  98354. + gdfifocfg.d32 =
  98355. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  98356. + core_global_regs->gdfifocfg);
  98357. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  98358. + dptxfsiz.d32 =
  98359. + (DWC_READ_REG32
  98360. + (&GET_CORE_IF(pcd)->core_global_regs->
  98361. + dtxfsiz[ep->dwc_ep.tx_fifo_num - 1]) >> 16);
  98362. + gdfifocfg.b.epinfobase =
  98363. + gdfifocfgbase.d32 + dptxfsiz.d32;
  98364. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  98365. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  98366. + core_global_regs->gdfifocfg,
  98367. + gdfifocfg.d32);
  98368. + }
  98369. + }
  98370. + }
  98371. + /* Set initial data PID. */
  98372. + if (ep->dwc_ep.type == UE_BULK) {
  98373. + ep->dwc_ep.data_pid_start = 0;
  98374. + }
  98375. +
  98376. + /* Alloc DMA Descriptors */
  98377. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  98378. +#ifndef DWC_UTE_PER_IO
  98379. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  98380. +#endif
  98381. + ep->dwc_ep.desc_addr =
  98382. + dwc_otg_ep_alloc_desc_chain(&ep->
  98383. + dwc_ep.dma_desc_addr,
  98384. + MAX_DMA_DESC_CNT);
  98385. + if (!ep->dwc_ep.desc_addr) {
  98386. + DWC_WARN("%s, can't allocate DMA descriptor\n",
  98387. + __func__);
  98388. + retval = -DWC_E_SHUTDOWN;
  98389. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98390. + goto out;
  98391. + }
  98392. +#ifndef DWC_UTE_PER_IO
  98393. + }
  98394. +#endif
  98395. + }
  98396. +
  98397. + DWC_DEBUGPL(DBG_PCD, "Activate %s: type=%d, mps=%d desc=%p\n",
  98398. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  98399. + ep->dwc_ep.type, ep->dwc_ep.maxpacket, ep->desc);
  98400. +#ifdef DWC_UTE_PER_IO
  98401. + ep->dwc_ep.xiso_bInterval = 1 << (ep->desc->bInterval - 1);
  98402. +#endif
  98403. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  98404. + ep->dwc_ep.bInterval = 1 << (ep->desc->bInterval - 1);
  98405. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  98406. + }
  98407. +
  98408. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  98409. +
  98410. +#ifdef DWC_UTE_CFI
  98411. + if (pcd->cfi->ops.ep_enable) {
  98412. + pcd->cfi->ops.ep_enable(pcd->cfi, pcd, ep);
  98413. + }
  98414. +#endif
  98415. +
  98416. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98417. +
  98418. +out:
  98419. + return retval;
  98420. +}
  98421. +
  98422. +/**
  98423. + * This function is being called from gadget
  98424. + * to disable PCD endpoint.
  98425. + */
  98426. +int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle)
  98427. +{
  98428. + dwc_otg_pcd_ep_t *ep;
  98429. + dwc_irqflags_t flags;
  98430. + dwc_otg_dev_dma_desc_t *desc_addr;
  98431. + dwc_dma_t dma_desc_addr;
  98432. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  98433. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  98434. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  98435. +
  98436. + ep = get_ep_from_handle(pcd, ep_handle);
  98437. +
  98438. + if (!ep || !ep->desc) {
  98439. + DWC_DEBUGPL(DBG_PCD, "bad ep address\n");
  98440. + return -DWC_E_INVALID;
  98441. + }
  98442. +
  98443. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  98444. +
  98445. + dwc_otg_request_nuke(ep);
  98446. +
  98447. + dwc_otg_ep_deactivate(GET_CORE_IF(pcd), &ep->dwc_ep);
  98448. + if (pcd->core_if->core_params->dev_out_nak) {
  98449. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[ep->dwc_ep.num]);
  98450. + pcd->core_if->ep_xfer_info[ep->dwc_ep.num].state = 0;
  98451. + }
  98452. + ep->desc = NULL;
  98453. + ep->stopped = 1;
  98454. +
  98455. + gdfifocfg.d32 =
  98456. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg);
  98457. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  98458. +
  98459. + if (ep->dwc_ep.is_in) {
  98460. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  98461. + /* Flush the Tx FIFO */
  98462. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd),
  98463. + ep->dwc_ep.tx_fifo_num);
  98464. + }
  98465. + release_perio_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  98466. + release_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  98467. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  98468. + /* Decreasing EPinfo Base Addr */
  98469. + dptxfsiz.d32 =
  98470. + (DWC_READ_REG32
  98471. + (&GET_CORE_IF(pcd)->
  98472. + core_global_regs->dtxfsiz[ep->dwc_ep.tx_fifo_num-1]) >> 16);
  98473. + gdfifocfg.b.epinfobase = gdfifocfgbase.d32 - dptxfsiz.d32;
  98474. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  98475. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg,
  98476. + gdfifocfg.d32);
  98477. + }
  98478. + }
  98479. + }
  98480. +
  98481. + /* Free DMA Descriptors */
  98482. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  98483. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  98484. + desc_addr = ep->dwc_ep.desc_addr;
  98485. + dma_desc_addr = ep->dwc_ep.dma_desc_addr;
  98486. +
  98487. + /* Cannot call dma_free_coherent() with IRQs disabled */
  98488. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98489. + dwc_otg_ep_free_desc_chain(desc_addr, dma_desc_addr,
  98490. + MAX_DMA_DESC_CNT);
  98491. +
  98492. + goto out_unlocked;
  98493. + }
  98494. + }
  98495. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98496. +
  98497. +out_unlocked:
  98498. + DWC_DEBUGPL(DBG_PCD, "%d %s disabled\n", ep->dwc_ep.num,
  98499. + ep->dwc_ep.is_in ? "IN" : "OUT");
  98500. + return 0;
  98501. +
  98502. +}
  98503. +
  98504. +/******************************************************************************/
  98505. +#ifdef DWC_UTE_PER_IO
  98506. +
  98507. +/**
  98508. + * Free the request and its extended parts
  98509. + *
  98510. + */
  98511. +void dwc_pcd_xiso_ereq_free(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req)
  98512. +{
  98513. + DWC_FREE(req->ext_req.per_io_frame_descs);
  98514. + DWC_FREE(req);
  98515. +}
  98516. +
  98517. +/**
  98518. + * Start the next request in the endpoint's queue.
  98519. + *
  98520. + */
  98521. +int dwc_otg_pcd_xiso_start_next_request(dwc_otg_pcd_t * pcd,
  98522. + dwc_otg_pcd_ep_t * ep)
  98523. +{
  98524. + int i;
  98525. + dwc_otg_pcd_request_t *req = NULL;
  98526. + dwc_ep_t *dwcep = NULL;
  98527. + struct dwc_iso_xreq_port *ereq = NULL;
  98528. + struct dwc_iso_pkt_desc_port *ddesc_iso;
  98529. + uint16_t nat;
  98530. + depctl_data_t diepctl;
  98531. +
  98532. + dwcep = &ep->dwc_ep;
  98533. +
  98534. + if (dwcep->xiso_active_xfers > 0) {
  98535. +#if 0 //Disable this to decrease s/w overhead that is crucial for Isoc transfers
  98536. + DWC_WARN("There are currently active transfers for EP%d \
  98537. + (active=%d; queued=%d)", dwcep->num, dwcep->xiso_active_xfers,
  98538. + dwcep->xiso_queued_xfers);
  98539. +#endif
  98540. + return 0;
  98541. + }
  98542. +
  98543. + nat = UGETW(ep->desc->wMaxPacketSize);
  98544. + nat = (nat >> 11) & 0x03;
  98545. +
  98546. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  98547. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  98548. + ereq = &req->ext_req;
  98549. + ep->stopped = 0;
  98550. +
  98551. + /* Get the frame number */
  98552. + dwcep->xiso_frame_num =
  98553. + dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  98554. + DWC_DEBUG("FRM_NUM=%d", dwcep->xiso_frame_num);
  98555. +
  98556. + ddesc_iso = ereq->per_io_frame_descs;
  98557. +
  98558. + if (dwcep->is_in) {
  98559. + /* Setup DMA Descriptor chain for IN Isoc request */
  98560. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  98561. + //if ((i % (nat + 1)) == 0)
  98562. + if ( i > 0 )
  98563. + dwcep->xiso_frame_num =
  98564. + (dwcep->xiso_bInterval +
  98565. + dwcep->xiso_frame_num) & 0x3FFF;
  98566. + dwcep->desc_addr[i].buf =
  98567. + req->dma + ddesc_iso[i].offset;
  98568. + dwcep->desc_addr[i].status.b_iso_in.txbytes =
  98569. + ddesc_iso[i].length;
  98570. + dwcep->desc_addr[i].status.b_iso_in.framenum =
  98571. + dwcep->xiso_frame_num;
  98572. + dwcep->desc_addr[i].status.b_iso_in.bs =
  98573. + BS_HOST_READY;
  98574. + dwcep->desc_addr[i].status.b_iso_in.txsts = 0;
  98575. + dwcep->desc_addr[i].status.b_iso_in.sp =
  98576. + (ddesc_iso[i].length %
  98577. + dwcep->maxpacket) ? 1 : 0;
  98578. + dwcep->desc_addr[i].status.b_iso_in.ioc = 0;
  98579. + dwcep->desc_addr[i].status.b_iso_in.pid = nat + 1;
  98580. + dwcep->desc_addr[i].status.b_iso_in.l = 0;
  98581. +
  98582. + /* Process the last descriptor */
  98583. + if (i == ereq->pio_pkt_count - 1) {
  98584. + dwcep->desc_addr[i].status.b_iso_in.ioc = 1;
  98585. + dwcep->desc_addr[i].status.b_iso_in.l = 1;
  98586. + }
  98587. + }
  98588. +
  98589. + /* Setup and start the transfer for this endpoint */
  98590. + dwcep->xiso_active_xfers++;
  98591. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->dev_if->
  98592. + in_ep_regs[dwcep->num]->diepdma,
  98593. + dwcep->dma_desc_addr);
  98594. + diepctl.d32 = 0;
  98595. + diepctl.b.epena = 1;
  98596. + diepctl.b.cnak = 1;
  98597. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->dev_if->
  98598. + in_ep_regs[dwcep->num]->diepctl, 0,
  98599. + diepctl.d32);
  98600. + } else {
  98601. + /* Setup DMA Descriptor chain for OUT Isoc request */
  98602. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  98603. + //if ((i % (nat + 1)) == 0)
  98604. + dwcep->xiso_frame_num = (dwcep->xiso_bInterval +
  98605. + dwcep->xiso_frame_num) & 0x3FFF;
  98606. + dwcep->desc_addr[i].buf =
  98607. + req->dma + ddesc_iso[i].offset;
  98608. + dwcep->desc_addr[i].status.b_iso_out.rxbytes =
  98609. + ddesc_iso[i].length;
  98610. + dwcep->desc_addr[i].status.b_iso_out.framenum =
  98611. + dwcep->xiso_frame_num;
  98612. + dwcep->desc_addr[i].status.b_iso_out.bs =
  98613. + BS_HOST_READY;
  98614. + dwcep->desc_addr[i].status.b_iso_out.rxsts = 0;
  98615. + dwcep->desc_addr[i].status.b_iso_out.sp =
  98616. + (ddesc_iso[i].length %
  98617. + dwcep->maxpacket) ? 1 : 0;
  98618. + dwcep->desc_addr[i].status.b_iso_out.ioc = 0;
  98619. + dwcep->desc_addr[i].status.b_iso_out.pid = nat + 1;
  98620. + dwcep->desc_addr[i].status.b_iso_out.l = 0;
  98621. +
  98622. + /* Process the last descriptor */
  98623. + if (i == ereq->pio_pkt_count - 1) {
  98624. + dwcep->desc_addr[i].status.b_iso_out.ioc = 1;
  98625. + dwcep->desc_addr[i].status.b_iso_out.l = 1;
  98626. + }
  98627. + }
  98628. +
  98629. + /* Setup and start the transfer for this endpoint */
  98630. + dwcep->xiso_active_xfers++;
  98631. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  98632. + dev_if->out_ep_regs[dwcep->num]->
  98633. + doepdma, dwcep->dma_desc_addr);
  98634. + diepctl.d32 = 0;
  98635. + diepctl.b.epena = 1;
  98636. + diepctl.b.cnak = 1;
  98637. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  98638. + dev_if->out_ep_regs[dwcep->num]->
  98639. + doepctl, 0, diepctl.d32);
  98640. + }
  98641. +
  98642. + } else {
  98643. + ep->stopped = 1;
  98644. + }
  98645. +
  98646. + return 0;
  98647. +}
  98648. +
  98649. +/**
  98650. + * - Remove the request from the queue
  98651. + */
  98652. +void complete_xiso_ep(dwc_otg_pcd_ep_t * ep)
  98653. +{
  98654. + dwc_otg_pcd_request_t *req = NULL;
  98655. + struct dwc_iso_xreq_port *ereq = NULL;
  98656. + struct dwc_iso_pkt_desc_port *ddesc_iso = NULL;
  98657. + dwc_ep_t *dwcep = NULL;
  98658. + int i;
  98659. +
  98660. + //DWC_DEBUG();
  98661. + dwcep = &ep->dwc_ep;
  98662. +
  98663. + /* Get the first pending request from the queue */
  98664. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  98665. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  98666. + if (!req) {
  98667. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  98668. + return;
  98669. + }
  98670. + dwcep->xiso_active_xfers--;
  98671. + dwcep->xiso_queued_xfers--;
  98672. + /* Remove this request from the queue */
  98673. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  98674. + } else {
  98675. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  98676. + return;
  98677. + }
  98678. +
  98679. + ep->stopped = 1;
  98680. + ereq = &req->ext_req;
  98681. + ddesc_iso = ereq->per_io_frame_descs;
  98682. +
  98683. + if (dwcep->xiso_active_xfers < 0) {
  98684. + DWC_WARN("EP#%d (xiso_active_xfers=%d)", dwcep->num,
  98685. + dwcep->xiso_active_xfers);
  98686. + }
  98687. +
  98688. + /* Fill the Isoc descs of portable extended req from dma descriptors */
  98689. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  98690. + if (dwcep->is_in) { /* IN endpoints */
  98691. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  98692. + dwcep->desc_addr[i].status.b_iso_in.txbytes;
  98693. + ddesc_iso[i].status =
  98694. + dwcep->desc_addr[i].status.b_iso_in.txsts;
  98695. + } else { /* OUT endpoints */
  98696. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  98697. + dwcep->desc_addr[i].status.b_iso_out.rxbytes;
  98698. + ddesc_iso[i].status =
  98699. + dwcep->desc_addr[i].status.b_iso_out.rxsts;
  98700. + }
  98701. + }
  98702. +
  98703. + DWC_SPINUNLOCK(ep->pcd->lock);
  98704. +
  98705. + /* Call the completion function in the non-portable logic */
  98706. + ep->pcd->fops->xisoc_complete(ep->pcd, ep->priv, req->priv, 0,
  98707. + &req->ext_req);
  98708. +
  98709. + DWC_SPINLOCK(ep->pcd->lock);
  98710. +
  98711. + /* Free the request - specific freeing needed for extended request object */
  98712. + dwc_pcd_xiso_ereq_free(ep, req);
  98713. +
  98714. + /* Start the next request */
  98715. + dwc_otg_pcd_xiso_start_next_request(ep->pcd, ep);
  98716. +
  98717. + return;
  98718. +}
  98719. +
  98720. +/**
  98721. + * Create and initialize the Isoc pkt descriptors of the extended request.
  98722. + *
  98723. + */
  98724. +static int dwc_otg_pcd_xiso_create_pkt_descs(dwc_otg_pcd_request_t * req,
  98725. + void *ereq_nonport,
  98726. + int atomic_alloc)
  98727. +{
  98728. + struct dwc_iso_xreq_port *ereq = NULL;
  98729. + struct dwc_iso_xreq_port *req_mapped = NULL;
  98730. + struct dwc_iso_pkt_desc_port *ipds = NULL; /* To be created in this function */
  98731. + uint32_t pkt_count;
  98732. + int i;
  98733. +
  98734. + ereq = &req->ext_req;
  98735. + req_mapped = (struct dwc_iso_xreq_port *)ereq_nonport;
  98736. + pkt_count = req_mapped->pio_pkt_count;
  98737. +
  98738. + /* Create the isoc descs */
  98739. + if (atomic_alloc) {
  98740. + ipds = DWC_ALLOC_ATOMIC(sizeof(*ipds) * pkt_count);
  98741. + } else {
  98742. + ipds = DWC_ALLOC(sizeof(*ipds) * pkt_count);
  98743. + }
  98744. +
  98745. + if (!ipds) {
  98746. + DWC_ERROR("Failed to allocate isoc descriptors");
  98747. + return -DWC_E_NO_MEMORY;
  98748. + }
  98749. +
  98750. + /* Initialize the extended request fields */
  98751. + ereq->per_io_frame_descs = ipds;
  98752. + ereq->error_count = 0;
  98753. + ereq->pio_alloc_pkt_count = pkt_count;
  98754. + ereq->pio_pkt_count = pkt_count;
  98755. + ereq->tr_sub_flags = req_mapped->tr_sub_flags;
  98756. +
  98757. + /* Init the Isoc descriptors */
  98758. + for (i = 0; i < pkt_count; i++) {
  98759. + ipds[i].length = req_mapped->per_io_frame_descs[i].length;
  98760. + ipds[i].offset = req_mapped->per_io_frame_descs[i].offset;
  98761. + ipds[i].status = req_mapped->per_io_frame_descs[i].status; /* 0 */
  98762. + ipds[i].actual_length =
  98763. + req_mapped->per_io_frame_descs[i].actual_length;
  98764. + }
  98765. +
  98766. + return 0;
  98767. +}
  98768. +
  98769. +static void prn_ext_request(struct dwc_iso_xreq_port *ereq)
  98770. +{
  98771. + struct dwc_iso_pkt_desc_port *xfd = NULL;
  98772. + int i;
  98773. +
  98774. + DWC_DEBUG("per_io_frame_descs=%p", ereq->per_io_frame_descs);
  98775. + DWC_DEBUG("tr_sub_flags=%d", ereq->tr_sub_flags);
  98776. + DWC_DEBUG("error_count=%d", ereq->error_count);
  98777. + DWC_DEBUG("pio_alloc_pkt_count=%d", ereq->pio_alloc_pkt_count);
  98778. + DWC_DEBUG("pio_pkt_count=%d", ereq->pio_pkt_count);
  98779. + DWC_DEBUG("res=%d", ereq->res);
  98780. +
  98781. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  98782. + xfd = &ereq->per_io_frame_descs[0];
  98783. + DWC_DEBUG("FD #%d", i);
  98784. +
  98785. + DWC_DEBUG("xfd->actual_length=%d", xfd->actual_length);
  98786. + DWC_DEBUG("xfd->length=%d", xfd->length);
  98787. + DWC_DEBUG("xfd->offset=%d", xfd->offset);
  98788. + DWC_DEBUG("xfd->status=%d", xfd->status);
  98789. + }
  98790. +}
  98791. +
  98792. +/**
  98793. + *
  98794. + */
  98795. +int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  98796. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  98797. + int zero, void *req_handle, int atomic_alloc,
  98798. + void *ereq_nonport)
  98799. +{
  98800. + dwc_otg_pcd_request_t *req = NULL;
  98801. + dwc_otg_pcd_ep_t *ep;
  98802. + dwc_irqflags_t flags;
  98803. + int res;
  98804. +
  98805. + ep = get_ep_from_handle(pcd, ep_handle);
  98806. + if (!ep) {
  98807. + DWC_WARN("bad ep\n");
  98808. + return -DWC_E_INVALID;
  98809. + }
  98810. +
  98811. + /* We support this extension only for DDMA mode */
  98812. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  98813. + if (!GET_CORE_IF(pcd)->dma_desc_enable)
  98814. + return -DWC_E_INVALID;
  98815. +
  98816. + /* Create a dwc_otg_pcd_request_t object */
  98817. + if (atomic_alloc) {
  98818. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  98819. + } else {
  98820. + req = DWC_ALLOC(sizeof(*req));
  98821. + }
  98822. +
  98823. + if (!req) {
  98824. + return -DWC_E_NO_MEMORY;
  98825. + }
  98826. +
  98827. + /* Create the Isoc descs for this request which shall be the exact match
  98828. + * of the structure sent to us from the non-portable logic */
  98829. + res =
  98830. + dwc_otg_pcd_xiso_create_pkt_descs(req, ereq_nonport, atomic_alloc);
  98831. + if (res) {
  98832. + DWC_WARN("Failed to init the Isoc descriptors");
  98833. + DWC_FREE(req);
  98834. + return res;
  98835. + }
  98836. +
  98837. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  98838. +
  98839. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  98840. + req->buf = buf;
  98841. + req->dma = dma_buf;
  98842. + req->length = buflen;
  98843. + req->sent_zlp = zero;
  98844. + req->priv = req_handle;
  98845. +
  98846. + //DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  98847. + ep->dwc_ep.dma_addr = dma_buf;
  98848. + ep->dwc_ep.start_xfer_buff = buf;
  98849. + ep->dwc_ep.xfer_buff = buf;
  98850. + ep->dwc_ep.xfer_len = 0;
  98851. + ep->dwc_ep.xfer_count = 0;
  98852. + ep->dwc_ep.sent_zlp = 0;
  98853. + ep->dwc_ep.total_len = buflen;
  98854. +
  98855. + /* Add this request to the tail */
  98856. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  98857. + ep->dwc_ep.xiso_queued_xfers++;
  98858. +
  98859. +//DWC_DEBUG("CP_0");
  98860. +//DWC_DEBUG("req->ext_req.tr_sub_flags=%d", req->ext_req.tr_sub_flags);
  98861. +//prn_ext_request((struct dwc_iso_xreq_port *) ereq_nonport);
  98862. +//prn_ext_request(&req->ext_req);
  98863. +
  98864. + //DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98865. +
  98866. + /* If the req->status == ASAP then check if there is any active transfer
  98867. + * for this endpoint. If no active transfers, then get the first entry
  98868. + * from the queue and start that transfer
  98869. + */
  98870. + if (req->ext_req.tr_sub_flags == DWC_EREQ_TF_ASAP) {
  98871. + res = dwc_otg_pcd_xiso_start_next_request(pcd, ep);
  98872. + if (res) {
  98873. + DWC_WARN("Failed to start the next Isoc transfer");
  98874. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98875. + DWC_FREE(req);
  98876. + return res;
  98877. + }
  98878. + }
  98879. +
  98880. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98881. + return 0;
  98882. +}
  98883. +
  98884. +#endif
  98885. +/* END ifdef DWC_UTE_PER_IO ***************************************************/
  98886. +int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  98887. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  98888. + int zero, void *req_handle, int atomic_alloc)
  98889. +{
  98890. + dwc_irqflags_t flags;
  98891. + dwc_otg_pcd_request_t *req;
  98892. + dwc_otg_pcd_ep_t *ep;
  98893. + uint32_t max_transfer;
  98894. +
  98895. + ep = get_ep_from_handle(pcd, ep_handle);
  98896. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  98897. + DWC_WARN("bad ep\n");
  98898. + return -DWC_E_INVALID;
  98899. + }
  98900. +
  98901. + if (atomic_alloc) {
  98902. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  98903. + } else {
  98904. + req = DWC_ALLOC(sizeof(*req));
  98905. + }
  98906. +
  98907. + if (!req) {
  98908. + return -DWC_E_NO_MEMORY;
  98909. + }
  98910. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  98911. + if (!GET_CORE_IF(pcd)->core_params->opt) {
  98912. + if (ep->dwc_ep.num != 0) {
  98913. + DWC_ERROR("queue req %p, len %d buf %p\n",
  98914. + req_handle, buflen, buf);
  98915. + }
  98916. + }
  98917. +
  98918. + req->buf = buf;
  98919. + req->dma = dma_buf;
  98920. + req->length = buflen;
  98921. + req->sent_zlp = zero;
  98922. + req->priv = req_handle;
  98923. + req->dw_align_buf = NULL;
  98924. + if ((dma_buf & 0x3) && GET_CORE_IF(pcd)->dma_enable
  98925. + && !GET_CORE_IF(pcd)->dma_desc_enable)
  98926. + req->dw_align_buf = DWC_DMA_ALLOC(buflen,
  98927. + &req->dw_align_buf_dma);
  98928. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  98929. +
  98930. + /*
  98931. + * After adding request to the queue for IN ISOC wait for In Token Received
  98932. + * when TX FIFO is empty interrupt and for OUT ISOC wait for OUT Token
  98933. + * Received when EP is disabled interrupt to obtain starting microframe
  98934. + * (odd/even) start transfer
  98935. + */
  98936. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  98937. + if (req != 0) {
  98938. + depctl_data_t depctl = {.d32 =
  98939. + DWC_READ_REG32(&pcd->core_if->dev_if->
  98940. + in_ep_regs[ep->dwc_ep.num]->
  98941. + diepctl) };
  98942. + ++pcd->request_pending;
  98943. +
  98944. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  98945. + if (ep->dwc_ep.is_in) {
  98946. + depctl.b.cnak = 1;
  98947. + DWC_WRITE_REG32(&pcd->core_if->dev_if->
  98948. + in_ep_regs[ep->dwc_ep.num]->
  98949. + diepctl, depctl.d32);
  98950. + }
  98951. +
  98952. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98953. + }
  98954. + return 0;
  98955. + }
  98956. +
  98957. + /*
  98958. + * For EP0 IN without premature status, zlp is required?
  98959. + */
  98960. + if (ep->dwc_ep.num == 0 && ep->dwc_ep.is_in) {
  98961. + DWC_DEBUGPL(DBG_PCDV, "%d-OUT ZLP\n", ep->dwc_ep.num);
  98962. + //_req->zero = 1;
  98963. + }
  98964. +
  98965. + /* Start the transfer */
  98966. + if (DWC_CIRCLEQ_EMPTY(&ep->queue) && !ep->stopped) {
  98967. + /* EP0 Transfer? */
  98968. + if (ep->dwc_ep.num == 0) {
  98969. + switch (pcd->ep0state) {
  98970. + case EP0_IN_DATA_PHASE:
  98971. + DWC_DEBUGPL(DBG_PCD,
  98972. + "%s ep0: EP0_IN_DATA_PHASE\n",
  98973. + __func__);
  98974. + break;
  98975. +
  98976. + case EP0_OUT_DATA_PHASE:
  98977. + DWC_DEBUGPL(DBG_PCD,
  98978. + "%s ep0: EP0_OUT_DATA_PHASE\n",
  98979. + __func__);
  98980. + if (pcd->request_config) {
  98981. + /* Complete STATUS PHASE */
  98982. + ep->dwc_ep.is_in = 1;
  98983. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  98984. + }
  98985. + break;
  98986. +
  98987. + case EP0_IN_STATUS_PHASE:
  98988. + DWC_DEBUGPL(DBG_PCD,
  98989. + "%s ep0: EP0_IN_STATUS_PHASE\n",
  98990. + __func__);
  98991. + break;
  98992. +
  98993. + default:
  98994. + DWC_DEBUGPL(DBG_ANY, "ep0: odd state %d\n",
  98995. + pcd->ep0state);
  98996. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98997. + return -DWC_E_SHUTDOWN;
  98998. + }
  98999. +
  99000. + ep->dwc_ep.dma_addr = dma_buf;
  99001. + ep->dwc_ep.start_xfer_buff = buf;
  99002. + ep->dwc_ep.xfer_buff = buf;
  99003. + ep->dwc_ep.xfer_len = buflen;
  99004. + ep->dwc_ep.xfer_count = 0;
  99005. + ep->dwc_ep.sent_zlp = 0;
  99006. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  99007. +
  99008. + if (zero) {
  99009. + if ((ep->dwc_ep.xfer_len %
  99010. + ep->dwc_ep.maxpacket == 0)
  99011. + && (ep->dwc_ep.xfer_len != 0)) {
  99012. + ep->dwc_ep.sent_zlp = 1;
  99013. + }
  99014. +
  99015. + }
  99016. +
  99017. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  99018. + &ep->dwc_ep);
  99019. + } // non-ep0 endpoints
  99020. + else {
  99021. +#ifdef DWC_UTE_CFI
  99022. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  99023. + /* store the request length */
  99024. + ep->dwc_ep.cfi_req_len = buflen;
  99025. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd,
  99026. + ep, req);
  99027. + } else {
  99028. +#endif
  99029. + max_transfer =
  99030. + GET_CORE_IF(ep->pcd)->core_params->
  99031. + max_transfer_size;
  99032. +
  99033. + /* Setup and start the Transfer */
  99034. + if (req->dw_align_buf){
  99035. + if (ep->dwc_ep.is_in)
  99036. + dwc_memcpy(req->dw_align_buf,
  99037. + buf, buflen);
  99038. + ep->dwc_ep.dma_addr =
  99039. + req->dw_align_buf_dma;
  99040. + ep->dwc_ep.start_xfer_buff =
  99041. + req->dw_align_buf;
  99042. + ep->dwc_ep.xfer_buff =
  99043. + req->dw_align_buf;
  99044. + } else {
  99045. + ep->dwc_ep.dma_addr = dma_buf;
  99046. + ep->dwc_ep.start_xfer_buff = buf;
  99047. + ep->dwc_ep.xfer_buff = buf;
  99048. + }
  99049. + ep->dwc_ep.xfer_len = 0;
  99050. + ep->dwc_ep.xfer_count = 0;
  99051. + ep->dwc_ep.sent_zlp = 0;
  99052. + ep->dwc_ep.total_len = buflen;
  99053. +
  99054. + ep->dwc_ep.maxxfer = max_transfer;
  99055. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  99056. + uint32_t out_max_xfer =
  99057. + DDMA_MAX_TRANSFER_SIZE -
  99058. + (DDMA_MAX_TRANSFER_SIZE % 4);
  99059. + if (ep->dwc_ep.is_in) {
  99060. + if (ep->dwc_ep.maxxfer >
  99061. + DDMA_MAX_TRANSFER_SIZE) {
  99062. + ep->dwc_ep.maxxfer =
  99063. + DDMA_MAX_TRANSFER_SIZE;
  99064. + }
  99065. + } else {
  99066. + if (ep->dwc_ep.maxxfer >
  99067. + out_max_xfer) {
  99068. + ep->dwc_ep.maxxfer =
  99069. + out_max_xfer;
  99070. + }
  99071. + }
  99072. + }
  99073. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  99074. + ep->dwc_ep.maxxfer -=
  99075. + (ep->dwc_ep.maxxfer %
  99076. + ep->dwc_ep.maxpacket);
  99077. + }
  99078. +
  99079. + if (zero) {
  99080. + if ((ep->dwc_ep.total_len %
  99081. + ep->dwc_ep.maxpacket == 0)
  99082. + && (ep->dwc_ep.total_len != 0)) {
  99083. + ep->dwc_ep.sent_zlp = 1;
  99084. + }
  99085. + }
  99086. +#ifdef DWC_UTE_CFI
  99087. + }
  99088. +#endif
  99089. + dwc_otg_ep_start_transfer(GET_CORE_IF(pcd),
  99090. + &ep->dwc_ep);
  99091. + }
  99092. + }
  99093. +
  99094. + if (req != 0) {
  99095. + ++pcd->request_pending;
  99096. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  99097. + if (ep->dwc_ep.is_in && ep->stopped
  99098. + && !(GET_CORE_IF(pcd)->dma_enable)) {
  99099. + /** @todo NGS Create a function for this. */
  99100. + diepmsk_data_t diepmsk = {.d32 = 0 };
  99101. + diepmsk.b.intktxfemp = 1;
  99102. + if (GET_CORE_IF(pcd)->multiproc_int_enable) {
  99103. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  99104. + dev_if->dev_global_regs->diepeachintmsk
  99105. + [ep->dwc_ep.num], 0,
  99106. + diepmsk.d32);
  99107. + } else {
  99108. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  99109. + dev_if->dev_global_regs->
  99110. + diepmsk, 0, diepmsk.d32);
  99111. + }
  99112. +
  99113. + }
  99114. + }
  99115. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99116. +
  99117. + return 0;
  99118. +}
  99119. +
  99120. +int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  99121. + void *req_handle)
  99122. +{
  99123. + dwc_irqflags_t flags;
  99124. + dwc_otg_pcd_request_t *req;
  99125. + dwc_otg_pcd_ep_t *ep;
  99126. +
  99127. + ep = get_ep_from_handle(pcd, ep_handle);
  99128. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  99129. + DWC_WARN("bad argument\n");
  99130. + return -DWC_E_INVALID;
  99131. + }
  99132. +
  99133. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  99134. +
  99135. + /* make sure it's actually queued on this endpoint */
  99136. + DWC_CIRCLEQ_FOREACH(req, &ep->queue, queue_entry) {
  99137. + if (req->priv == (void *)req_handle) {
  99138. + break;
  99139. + }
  99140. + }
  99141. +
  99142. + if (req->priv != (void *)req_handle) {
  99143. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99144. + return -DWC_E_INVALID;
  99145. + }
  99146. +
  99147. + if (!DWC_CIRCLEQ_EMPTY_ENTRY(req, queue_entry)) {
  99148. + dwc_otg_request_done(ep, req, -DWC_E_RESTART);
  99149. + } else {
  99150. + req = NULL;
  99151. + }
  99152. +
  99153. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99154. +
  99155. + return req ? 0 : -DWC_E_SHUTDOWN;
  99156. +
  99157. +}
  99158. +
  99159. +/**
  99160. + * dwc_otg_pcd_ep_wedge - sets the halt feature and ignores clear requests
  99161. + *
  99162. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  99163. + * requests. If the gadget driver clears the halt status, it will
  99164. + * automatically unwedge the endpoint.
  99165. + *
  99166. + * Returns zero on success, else negative DWC error code.
  99167. + */
  99168. +int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle)
  99169. +{
  99170. + dwc_otg_pcd_ep_t *ep;
  99171. + dwc_irqflags_t flags;
  99172. + int retval = 0;
  99173. +
  99174. + ep = get_ep_from_handle(pcd, ep_handle);
  99175. +
  99176. + if ((!ep->desc && ep != &pcd->ep0) ||
  99177. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  99178. + DWC_WARN("%s, bad ep\n", __func__);
  99179. + return -DWC_E_INVALID;
  99180. + }
  99181. +
  99182. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  99183. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  99184. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  99185. + ep->dwc_ep.is_in ? "IN" : "OUT");
  99186. + retval = -DWC_E_AGAIN;
  99187. + } else {
  99188. + /* This code needs to be reviewed */
  99189. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  99190. + dtxfsts_data_t txstatus;
  99191. + fifosize_data_t txfifosize;
  99192. +
  99193. + txfifosize.d32 =
  99194. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  99195. + core_global_regs->dtxfsiz[ep->dwc_ep.
  99196. + tx_fifo_num]);
  99197. + txstatus.d32 =
  99198. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  99199. + dev_if->in_ep_regs[ep->dwc_ep.num]->
  99200. + dtxfsts);
  99201. +
  99202. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  99203. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  99204. + retval = -DWC_E_AGAIN;
  99205. + } else {
  99206. + if (ep->dwc_ep.num == 0) {
  99207. + pcd->ep0state = EP0_STALL;
  99208. + }
  99209. +
  99210. + ep->stopped = 1;
  99211. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  99212. + &ep->dwc_ep);
  99213. + }
  99214. + } else {
  99215. + if (ep->dwc_ep.num == 0) {
  99216. + pcd->ep0state = EP0_STALL;
  99217. + }
  99218. +
  99219. + ep->stopped = 1;
  99220. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  99221. + }
  99222. + }
  99223. +
  99224. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99225. +
  99226. + return retval;
  99227. +}
  99228. +
  99229. +int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value)
  99230. +{
  99231. + dwc_otg_pcd_ep_t *ep;
  99232. + dwc_irqflags_t flags;
  99233. + int retval = 0;
  99234. +
  99235. + ep = get_ep_from_handle(pcd, ep_handle);
  99236. +
  99237. + if (!ep || (!ep->desc && ep != &pcd->ep0) ||
  99238. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  99239. + DWC_WARN("%s, bad ep\n", __func__);
  99240. + return -DWC_E_INVALID;
  99241. + }
  99242. +
  99243. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  99244. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  99245. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  99246. + ep->dwc_ep.is_in ? "IN" : "OUT");
  99247. + retval = -DWC_E_AGAIN;
  99248. + } else if (value == 0) {
  99249. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  99250. + } else if (value == 1) {
  99251. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  99252. + dtxfsts_data_t txstatus;
  99253. + fifosize_data_t txfifosize;
  99254. +
  99255. + txfifosize.d32 =
  99256. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->
  99257. + dtxfsiz[ep->dwc_ep.tx_fifo_num]);
  99258. + txstatus.d32 =
  99259. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  99260. + in_ep_regs[ep->dwc_ep.num]->dtxfsts);
  99261. +
  99262. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  99263. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  99264. + retval = -DWC_E_AGAIN;
  99265. + } else {
  99266. + if (ep->dwc_ep.num == 0) {
  99267. + pcd->ep0state = EP0_STALL;
  99268. + }
  99269. +
  99270. + ep->stopped = 1;
  99271. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  99272. + &ep->dwc_ep);
  99273. + }
  99274. + } else {
  99275. + if (ep->dwc_ep.num == 0) {
  99276. + pcd->ep0state = EP0_STALL;
  99277. + }
  99278. +
  99279. + ep->stopped = 1;
  99280. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  99281. + }
  99282. + } else if (value == 2) {
  99283. + ep->dwc_ep.stall_clear_flag = 0;
  99284. + } else if (value == 3) {
  99285. + ep->dwc_ep.stall_clear_flag = 1;
  99286. + }
  99287. +
  99288. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99289. +
  99290. + return retval;
  99291. +}
  99292. +
  99293. +/**
  99294. + * This function initiates remote wakeup of the host from suspend state.
  99295. + */
  99296. +void dwc_otg_pcd_rem_wkup_from_suspend(dwc_otg_pcd_t * pcd, int set)
  99297. +{
  99298. + dctl_data_t dctl = { 0 };
  99299. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  99300. + dsts_data_t dsts;
  99301. +
  99302. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  99303. + if (!dsts.b.suspsts) {
  99304. + DWC_WARN("Remote wakeup while is not in suspend state\n");
  99305. + }
  99306. + /* Check if DEVICE_REMOTE_WAKEUP feature enabled */
  99307. + if (pcd->remote_wakeup_enable) {
  99308. + if (set) {
  99309. +
  99310. + if (core_if->adp_enable) {
  99311. + gpwrdn_data_t gpwrdn;
  99312. +
  99313. + dwc_otg_adp_probe_stop(core_if);
  99314. +
  99315. + /* Mask SRP detected interrupt from Power Down Logic */
  99316. + gpwrdn.d32 = 0;
  99317. + gpwrdn.b.srp_det_msk = 1;
  99318. + DWC_MODIFY_REG32(&core_if->
  99319. + core_global_regs->gpwrdn,
  99320. + gpwrdn.d32, 0);
  99321. +
  99322. + /* Disable Power Down Logic */
  99323. + gpwrdn.d32 = 0;
  99324. + gpwrdn.b.pmuactv = 1;
  99325. + DWC_MODIFY_REG32(&core_if->
  99326. + core_global_regs->gpwrdn,
  99327. + gpwrdn.d32, 0);
  99328. +
  99329. + /*
  99330. + * Initialize the Core for Device mode.
  99331. + */
  99332. + core_if->op_state = B_PERIPHERAL;
  99333. + dwc_otg_core_init(core_if);
  99334. + dwc_otg_enable_global_interrupts(core_if);
  99335. + cil_pcd_start(core_if);
  99336. +
  99337. + dwc_otg_initiate_srp(core_if);
  99338. + }
  99339. +
  99340. + dctl.b.rmtwkupsig = 1;
  99341. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  99342. + dctl, 0, dctl.d32);
  99343. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  99344. +
  99345. + dwc_mdelay(2);
  99346. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  99347. + dctl, dctl.d32, 0);
  99348. + DWC_DEBUGPL(DBG_PCD, "Clear Remote Wakeup\n");
  99349. + }
  99350. + } else {
  99351. + DWC_DEBUGPL(DBG_PCD, "Remote Wakeup is disabled\n");
  99352. + }
  99353. +}
  99354. +
  99355. +#ifdef CONFIG_USB_DWC_OTG_LPM
  99356. +/**
  99357. + * This function initiates remote wakeup of the host from L1 sleep state.
  99358. + */
  99359. +void dwc_otg_pcd_rem_wkup_from_sleep(dwc_otg_pcd_t * pcd, int set)
  99360. +{
  99361. + glpmcfg_data_t lpmcfg;
  99362. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  99363. +
  99364. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  99365. +
  99366. + /* Check if we are in L1 state */
  99367. + if (!lpmcfg.b.prt_sleep_sts) {
  99368. + DWC_DEBUGPL(DBG_PCD, "Device is not in sleep state\n");
  99369. + return;
  99370. + }
  99371. +
  99372. + /* Check if host allows remote wakeup */
  99373. + if (!lpmcfg.b.rem_wkup_en) {
  99374. + DWC_DEBUGPL(DBG_PCD, "Host does not allow remote wakeup\n");
  99375. + return;
  99376. + }
  99377. +
  99378. + /* Check if Resume OK */
  99379. + if (!lpmcfg.b.sleep_state_resumeok) {
  99380. + DWC_DEBUGPL(DBG_PCD, "Sleep state resume is not OK\n");
  99381. + return;
  99382. + }
  99383. +
  99384. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  99385. + lpmcfg.b.en_utmi_sleep = 0;
  99386. + lpmcfg.b.hird_thres &= (~(1 << 4));
  99387. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  99388. +
  99389. + if (set) {
  99390. + dctl_data_t dctl = {.d32 = 0 };
  99391. + dctl.b.rmtwkupsig = 1;
  99392. + /* Set RmtWkUpSig bit to start remote wakup signaling.
  99393. + * Hardware will automatically clear this bit.
  99394. + */
  99395. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl,
  99396. + 0, dctl.d32);
  99397. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  99398. + }
  99399. +
  99400. +}
  99401. +#endif
  99402. +
  99403. +/**
  99404. + * Performs remote wakeup.
  99405. + */
  99406. +void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set)
  99407. +{
  99408. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  99409. + dwc_irqflags_t flags;
  99410. + if (dwc_otg_is_device_mode(core_if)) {
  99411. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  99412. +#ifdef CONFIG_USB_DWC_OTG_LPM
  99413. + if (core_if->lx_state == DWC_OTG_L1) {
  99414. + dwc_otg_pcd_rem_wkup_from_sleep(pcd, set);
  99415. + } else {
  99416. +#endif
  99417. + dwc_otg_pcd_rem_wkup_from_suspend(pcd, set);
  99418. +#ifdef CONFIG_USB_DWC_OTG_LPM
  99419. + }
  99420. +#endif
  99421. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99422. + }
  99423. + return;
  99424. +}
  99425. +
  99426. +void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs)
  99427. +{
  99428. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  99429. + dctl_data_t dctl = { 0 };
  99430. +
  99431. + if (dwc_otg_is_device_mode(core_if)) {
  99432. + dctl.b.sftdiscon = 1;
  99433. + DWC_PRINTF("Soft disconnect for %d useconds\n",no_of_usecs);
  99434. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  99435. + dwc_udelay(no_of_usecs);
  99436. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32,0);
  99437. +
  99438. + } else{
  99439. + DWC_PRINTF("NOT SUPPORTED IN HOST MODE\n");
  99440. + }
  99441. + return;
  99442. +
  99443. +}
  99444. +
  99445. +int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd)
  99446. +{
  99447. + dsts_data_t dsts;
  99448. + gotgctl_data_t gotgctl;
  99449. +
  99450. + /*
  99451. + * This function starts the Protocol if no session is in progress. If
  99452. + * a session is already in progress, but the device is suspended,
  99453. + * remote wakeup signaling is started.
  99454. + */
  99455. +
  99456. + /* Check if valid session */
  99457. + gotgctl.d32 =
  99458. + DWC_READ_REG32(&(GET_CORE_IF(pcd)->core_global_regs->gotgctl));
  99459. + if (gotgctl.b.bsesvld) {
  99460. + /* Check if suspend state */
  99461. + dsts.d32 =
  99462. + DWC_READ_REG32(&
  99463. + (GET_CORE_IF(pcd)->dev_if->
  99464. + dev_global_regs->dsts));
  99465. + if (dsts.b.suspsts) {
  99466. + dwc_otg_pcd_remote_wakeup(pcd, 1);
  99467. + }
  99468. + } else {
  99469. + dwc_otg_pcd_initiate_srp(pcd);
  99470. + }
  99471. +
  99472. + return 0;
  99473. +
  99474. +}
  99475. +
  99476. +/**
  99477. + * Start the SRP timer to detect when the SRP does not complete within
  99478. + * 6 seconds.
  99479. + *
  99480. + * @param pcd the pcd structure.
  99481. + */
  99482. +void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd)
  99483. +{
  99484. + dwc_irqflags_t flags;
  99485. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  99486. + dwc_otg_initiate_srp(GET_CORE_IF(pcd));
  99487. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99488. +}
  99489. +
  99490. +int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd)
  99491. +{
  99492. + return dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  99493. +}
  99494. +
  99495. +int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd)
  99496. +{
  99497. + return GET_CORE_IF(pcd)->core_params->lpm_enable;
  99498. +}
  99499. +
  99500. +uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd)
  99501. +{
  99502. + return pcd->b_hnp_enable;
  99503. +}
  99504. +
  99505. +uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd)
  99506. +{
  99507. + return pcd->a_hnp_support;
  99508. +}
  99509. +
  99510. +uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd)
  99511. +{
  99512. + return pcd->a_alt_hnp_support;
  99513. +}
  99514. +
  99515. +int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd)
  99516. +{
  99517. + return pcd->remote_wakeup_enable;
  99518. +}
  99519. +
  99520. +#endif /* DWC_HOST_ONLY */
  99521. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_pcd.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h
  99522. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 1970-01-01 01:00:00.000000000 +0100
  99523. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 2015-02-09 04:40:29.000000000 +0100
  99524. @@ -0,0 +1,266 @@
  99525. +/* ==========================================================================
  99526. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
  99527. + * $Revision: #48 $
  99528. + * $Date: 2012/08/10 $
  99529. + * $Change: 2047372 $
  99530. + *
  99531. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  99532. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  99533. + * otherwise expressly agreed to in writing between Synopsys and you.
  99534. + *
  99535. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  99536. + * any End User Software License Agreement or Agreement for Licensed Product
  99537. + * with Synopsys or any supplement thereto. You are permitted to use and
  99538. + * redistribute this Software in source and binary forms, with or without
  99539. + * modification, provided that redistributions of source code must retain this
  99540. + * notice. You may not view, use, disclose, copy or distribute this file or
  99541. + * any information contained herein except pursuant to this license grant from
  99542. + * Synopsys. If you do not agree with this notice, including the disclaimer
  99543. + * below, then you are not authorized to use the Software.
  99544. + *
  99545. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  99546. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  99547. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  99548. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  99549. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  99550. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  99551. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  99552. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  99553. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  99554. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  99555. + * DAMAGE.
  99556. + * ========================================================================== */
  99557. +#ifndef DWC_HOST_ONLY
  99558. +#if !defined(__DWC_PCD_H__)
  99559. +#define __DWC_PCD_H__
  99560. +
  99561. +#include "dwc_otg_os_dep.h"
  99562. +#include "usb.h"
  99563. +#include "dwc_otg_cil.h"
  99564. +#include "dwc_otg_pcd_if.h"
  99565. +struct cfiobject;
  99566. +
  99567. +/**
  99568. + * @file
  99569. + *
  99570. + * This file contains the structures, constants, and interfaces for
  99571. + * the Perpherial Contoller Driver (PCD).
  99572. + *
  99573. + * The Peripheral Controller Driver (PCD) for Linux will implement the
  99574. + * Gadget API, so that the existing Gadget drivers can be used. For
  99575. + * the Mass Storage Function driver the File-backed USB Storage Gadget
  99576. + * (FBS) driver will be used. The FBS driver supports the
  99577. + * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
  99578. + * transports.
  99579. + *
  99580. + */
  99581. +
  99582. +/** Invalid DMA Address */
  99583. +#define DWC_DMA_ADDR_INVALID (~(dwc_dma_t)0)
  99584. +
  99585. +/** Max Transfer size for any EP */
  99586. +#define DDMA_MAX_TRANSFER_SIZE 65535
  99587. +
  99588. +/**
  99589. + * Get the pointer to the core_if from the pcd pointer.
  99590. + */
  99591. +#define GET_CORE_IF( _pcd ) (_pcd->core_if)
  99592. +
  99593. +/**
  99594. + * States of EP0.
  99595. + */
  99596. +typedef enum ep0_state {
  99597. + EP0_DISCONNECT, /* no host */
  99598. + EP0_IDLE,
  99599. + EP0_IN_DATA_PHASE,
  99600. + EP0_OUT_DATA_PHASE,
  99601. + EP0_IN_STATUS_PHASE,
  99602. + EP0_OUT_STATUS_PHASE,
  99603. + EP0_STALL,
  99604. +} ep0state_e;
  99605. +
  99606. +/** Fordward declaration.*/
  99607. +struct dwc_otg_pcd;
  99608. +
  99609. +/** DWC_otg iso request structure.
  99610. + *
  99611. + */
  99612. +typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
  99613. +
  99614. +#ifdef DWC_UTE_PER_IO
  99615. +
  99616. +/**
  99617. + * This shall be the exact analogy of the same type structure defined in the
  99618. + * usb_gadget.h. Each descriptor contains
  99619. + */
  99620. +struct dwc_iso_pkt_desc_port {
  99621. + uint32_t offset;
  99622. + uint32_t length; /* expected length */
  99623. + uint32_t actual_length;
  99624. + uint32_t status;
  99625. +};
  99626. +
  99627. +struct dwc_iso_xreq_port {
  99628. + /** transfer/submission flag */
  99629. + uint32_t tr_sub_flags;
  99630. + /** Start the request ASAP */
  99631. +#define DWC_EREQ_TF_ASAP 0x00000002
  99632. + /** Just enqueue the request w/o initiating a transfer */
  99633. +#define DWC_EREQ_TF_ENQUEUE 0x00000004
  99634. +
  99635. + /**
  99636. + * count of ISO packets attached to this request - shall
  99637. + * not exceed the pio_alloc_pkt_count
  99638. + */
  99639. + uint32_t pio_pkt_count;
  99640. + /** count of ISO packets allocated for this request */
  99641. + uint32_t pio_alloc_pkt_count;
  99642. + /** number of ISO packet errors */
  99643. + uint32_t error_count;
  99644. + /** reserved for future extension */
  99645. + uint32_t res;
  99646. + /** Will be allocated and freed in the UTE gadget and based on the CFC value */
  99647. + struct dwc_iso_pkt_desc_port *per_io_frame_descs;
  99648. +};
  99649. +#endif
  99650. +/** DWC_otg request structure.
  99651. + * This structure is a list of requests.
  99652. + */
  99653. +typedef struct dwc_otg_pcd_request {
  99654. + void *priv;
  99655. + void *buf;
  99656. + dwc_dma_t dma;
  99657. + uint32_t length;
  99658. + uint32_t actual;
  99659. + unsigned sent_zlp:1;
  99660. + /**
  99661. + * Used instead of original buffer if
  99662. + * it(physical address) is not dword-aligned.
  99663. + **/
  99664. + uint8_t *dw_align_buf;
  99665. + dwc_dma_t dw_align_buf_dma;
  99666. +
  99667. + DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
  99668. +#ifdef DWC_UTE_PER_IO
  99669. + struct dwc_iso_xreq_port ext_req;
  99670. + //void *priv_ereq_nport; /* */
  99671. +#endif
  99672. +} dwc_otg_pcd_request_t;
  99673. +
  99674. +DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
  99675. +
  99676. +/** PCD EP structure.
  99677. + * This structure describes an EP, there is an array of EPs in the PCD
  99678. + * structure.
  99679. + */
  99680. +typedef struct dwc_otg_pcd_ep {
  99681. + /** USB EP Descriptor */
  99682. + const usb_endpoint_descriptor_t *desc;
  99683. +
  99684. + /** queue of dwc_otg_pcd_requests. */
  99685. + struct req_list queue;
  99686. + unsigned stopped:1;
  99687. + unsigned disabling:1;
  99688. + unsigned dma:1;
  99689. + unsigned queue_sof:1;
  99690. +
  99691. +#ifdef DWC_EN_ISOC
  99692. + /** ISOC req handle passed */
  99693. + void *iso_req_handle;
  99694. +#endif //_EN_ISOC_
  99695. +
  99696. + /** DWC_otg ep data. */
  99697. + dwc_ep_t dwc_ep;
  99698. +
  99699. + /** Pointer to PCD */
  99700. + struct dwc_otg_pcd *pcd;
  99701. +
  99702. + void *priv;
  99703. +} dwc_otg_pcd_ep_t;
  99704. +
  99705. +/** DWC_otg PCD Structure.
  99706. + * This structure encapsulates the data for the dwc_otg PCD.
  99707. + */
  99708. +struct dwc_otg_pcd {
  99709. + const struct dwc_otg_pcd_function_ops *fops;
  99710. + /** The DWC otg device pointer */
  99711. + struct dwc_otg_device *otg_dev;
  99712. + /** Core Interface */
  99713. + dwc_otg_core_if_t *core_if;
  99714. + /** State of EP0 */
  99715. + ep0state_e ep0state;
  99716. + /** EP0 Request is pending */
  99717. + unsigned ep0_pending:1;
  99718. + /** Indicates when SET CONFIGURATION Request is in process */
  99719. + unsigned request_config:1;
  99720. + /** The state of the Remote Wakeup Enable. */
  99721. + unsigned remote_wakeup_enable:1;
  99722. + /** The state of the B-Device HNP Enable. */
  99723. + unsigned b_hnp_enable:1;
  99724. + /** The state of A-Device HNP Support. */
  99725. + unsigned a_hnp_support:1;
  99726. + /** The state of the A-Device Alt HNP support. */
  99727. + unsigned a_alt_hnp_support:1;
  99728. + /** Count of pending Requests */
  99729. + unsigned request_pending;
  99730. +
  99731. + /** SETUP packet for EP0
  99732. + * This structure is allocated as a DMA buffer on PCD initialization
  99733. + * with enough space for up to 3 setup packets.
  99734. + */
  99735. + union {
  99736. + usb_device_request_t req;
  99737. + uint32_t d32[2];
  99738. + } *setup_pkt;
  99739. +
  99740. + dwc_dma_t setup_pkt_dma_handle;
  99741. +
  99742. + /* Additional buffer and flag for CTRL_WR premature case */
  99743. + uint8_t *backup_buf;
  99744. + unsigned data_terminated;
  99745. +
  99746. + /** 2-byte dma buffer used to return status from GET_STATUS */
  99747. + uint16_t *status_buf;
  99748. + dwc_dma_t status_buf_dma_handle;
  99749. +
  99750. + /** EP0 */
  99751. + dwc_otg_pcd_ep_t ep0;
  99752. +
  99753. + /** Array of IN EPs. */
  99754. + dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
  99755. + /** Array of OUT EPs. */
  99756. + dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
  99757. + /** number of valid EPs in the above array. */
  99758. +// unsigned num_eps : 4;
  99759. + dwc_spinlock_t *lock;
  99760. +
  99761. + /** Tasklet to defer starting of TEST mode transmissions until
  99762. + * Status Phase has been completed.
  99763. + */
  99764. + dwc_tasklet_t *test_mode_tasklet;
  99765. +
  99766. + /** Tasklet to delay starting of xfer in DMA mode */
  99767. + dwc_tasklet_t *start_xfer_tasklet;
  99768. +
  99769. + /** The test mode to enter when the tasklet is executed. */
  99770. + unsigned test_mode;
  99771. + /** The cfi_api structure that implements most of the CFI API
  99772. + * and OTG specific core configuration functionality
  99773. + */
  99774. +#ifdef DWC_UTE_CFI
  99775. + struct cfiobject *cfi;
  99776. +#endif
  99777. +
  99778. +};
  99779. +
  99780. +//FIXME this functions should be static, and this prototypes should be removed
  99781. +extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep);
  99782. +extern void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep,
  99783. + dwc_otg_pcd_request_t * req, int32_t status);
  99784. +
  99785. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  99786. + void *req_handle);
  99787. +
  99788. +extern void do_test_mode(void *data);
  99789. +#endif
  99790. +#endif /* DWC_HOST_ONLY */
  99791. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h
  99792. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 1970-01-01 01:00:00.000000000 +0100
  99793. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 2015-02-09 04:40:29.000000000 +0100
  99794. @@ -0,0 +1,360 @@
  99795. +/* ==========================================================================
  99796. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_if.h $
  99797. + * $Revision: #11 $
  99798. + * $Date: 2011/10/26 $
  99799. + * $Change: 1873028 $
  99800. + *
  99801. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  99802. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  99803. + * otherwise expressly agreed to in writing between Synopsys and you.
  99804. + *
  99805. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  99806. + * any End User Software License Agreement or Agreement for Licensed Product
  99807. + * with Synopsys or any supplement thereto. You are permitted to use and
  99808. + * redistribute this Software in source and binary forms, with or without
  99809. + * modification, provided that redistributions of source code must retain this
  99810. + * notice. You may not view, use, disclose, copy or distribute this file or
  99811. + * any information contained herein except pursuant to this license grant from
  99812. + * Synopsys. If you do not agree with this notice, including the disclaimer
  99813. + * below, then you are not authorized to use the Software.
  99814. + *
  99815. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  99816. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  99817. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  99818. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  99819. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  99820. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  99821. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  99822. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  99823. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  99824. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  99825. + * DAMAGE.
  99826. + * ========================================================================== */
  99827. +#ifndef DWC_HOST_ONLY
  99828. +
  99829. +#if !defined(__DWC_PCD_IF_H__)
  99830. +#define __DWC_PCD_IF_H__
  99831. +
  99832. +//#include "dwc_os.h"
  99833. +#include "dwc_otg_core_if.h"
  99834. +
  99835. +/** @file
  99836. + * This file defines DWC_OTG PCD Core API.
  99837. + */
  99838. +
  99839. +struct dwc_otg_pcd;
  99840. +typedef struct dwc_otg_pcd dwc_otg_pcd_t;
  99841. +
  99842. +/** Maxpacket size for EP0 */
  99843. +#define MAX_EP0_SIZE 64
  99844. +/** Maxpacket size for any EP */
  99845. +#define MAX_PACKET_SIZE 1024
  99846. +
  99847. +/** @name Function Driver Callbacks */
  99848. +/** @{ */
  99849. +
  99850. +/** This function will be called whenever a previously queued request has
  99851. + * completed. The status value will be set to -DWC_E_SHUTDOWN to indicated a
  99852. + * failed or aborted transfer, or -DWC_E_RESTART to indicate the device was reset,
  99853. + * or -DWC_E_TIMEOUT to indicate it timed out, or -DWC_E_INVALID to indicate invalid
  99854. + * parameters. */
  99855. +typedef int (*dwc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  99856. + void *req_handle, int32_t status,
  99857. + uint32_t actual);
  99858. +/**
  99859. + * This function will be called whenever a previousle queued ISOC request has
  99860. + * completed. Count of ISOC packets could be read using dwc_otg_pcd_get_iso_packet_count
  99861. + * function.
  99862. + * The status of each ISOC packet could be read using dwc_otg_pcd_get_iso_packet_*
  99863. + * functions.
  99864. + */
  99865. +typedef int (*dwc_isoc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  99866. + void *req_handle, int proc_buf_num);
  99867. +/** This function should handle any SETUP request that cannot be handled by the
  99868. + * PCD Core. This includes most GET_DESCRIPTORs, SET_CONFIGS, Any
  99869. + * class-specific requests, etc. The function must non-blocking.
  99870. + *
  99871. + * Returns 0 on success.
  99872. + * Returns -DWC_E_NOT_SUPPORTED if the request is not supported.
  99873. + * Returns -DWC_E_INVALID if the setup request had invalid parameters or bytes.
  99874. + * Returns -DWC_E_SHUTDOWN on any other error. */
  99875. +typedef int (*dwc_setup_cb_t) (dwc_otg_pcd_t * pcd, uint8_t * bytes);
  99876. +/** This is called whenever the device has been disconnected. The function
  99877. + * driver should take appropriate action to clean up all pending requests in the
  99878. + * PCD Core, remove all endpoints (except ep0), and initialize back to reset
  99879. + * state. */
  99880. +typedef int (*dwc_disconnect_cb_t) (dwc_otg_pcd_t * pcd);
  99881. +/** This function is called when device has been connected. */
  99882. +typedef int (*dwc_connect_cb_t) (dwc_otg_pcd_t * pcd, int speed);
  99883. +/** This function is called when device has been suspended */
  99884. +typedef int (*dwc_suspend_cb_t) (dwc_otg_pcd_t * pcd);
  99885. +/** This function is called when device has received LPM tokens, i.e.
  99886. + * device has been sent to sleep state. */
  99887. +typedef int (*dwc_sleep_cb_t) (dwc_otg_pcd_t * pcd);
  99888. +/** This function is called when device has been resumed
  99889. + * from suspend(L2) or L1 sleep state. */
  99890. +typedef int (*dwc_resume_cb_t) (dwc_otg_pcd_t * pcd);
  99891. +/** This function is called whenever hnp params has been changed.
  99892. + * User can call get_b_hnp_enable, get_a_hnp_support, get_a_alt_hnp_support functions
  99893. + * to get hnp parameters. */
  99894. +typedef int (*dwc_hnp_params_changed_cb_t) (dwc_otg_pcd_t * pcd);
  99895. +/** This function is called whenever USB RESET is detected. */
  99896. +typedef int (*dwc_reset_cb_t) (dwc_otg_pcd_t * pcd);
  99897. +
  99898. +typedef int (*cfi_setup_cb_t) (dwc_otg_pcd_t * pcd, void *ctrl_req_bytes);
  99899. +
  99900. +/**
  99901. + *
  99902. + * @param ep_handle Void pointer to the usb_ep structure
  99903. + * @param ereq_port Pointer to the extended request structure created in the
  99904. + * portable part.
  99905. + */
  99906. +typedef int (*xiso_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  99907. + void *req_handle, int32_t status,
  99908. + void *ereq_port);
  99909. +/** Function Driver Ops Data Structure */
  99910. +struct dwc_otg_pcd_function_ops {
  99911. + dwc_connect_cb_t connect;
  99912. + dwc_disconnect_cb_t disconnect;
  99913. + dwc_setup_cb_t setup;
  99914. + dwc_completion_cb_t complete;
  99915. + dwc_isoc_completion_cb_t isoc_complete;
  99916. + dwc_suspend_cb_t suspend;
  99917. + dwc_sleep_cb_t sleep;
  99918. + dwc_resume_cb_t resume;
  99919. + dwc_reset_cb_t reset;
  99920. + dwc_hnp_params_changed_cb_t hnp_changed;
  99921. + cfi_setup_cb_t cfi_setup;
  99922. +#ifdef DWC_UTE_PER_IO
  99923. + xiso_completion_cb_t xisoc_complete;
  99924. +#endif
  99925. +};
  99926. +/** @} */
  99927. +
  99928. +/** @name Function Driver Functions */
  99929. +/** @{ */
  99930. +
  99931. +/** Call this function to get pointer on dwc_otg_pcd_t,
  99932. + * this pointer will be used for all PCD API functions.
  99933. + *
  99934. + * @param core_if The DWC_OTG Core
  99935. + */
  99936. +extern dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if);
  99937. +
  99938. +/** Frees PCD allocated by dwc_otg_pcd_init
  99939. + *
  99940. + * @param pcd The PCD
  99941. + */
  99942. +extern void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd);
  99943. +
  99944. +/** Call this to bind the function driver to the PCD Core.
  99945. + *
  99946. + * @param pcd Pointer on dwc_otg_pcd_t returned by dwc_otg_pcd_init function.
  99947. + * @param fops The Function Driver Ops data structure containing pointers to all callbacks.
  99948. + */
  99949. +extern void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  99950. + const struct dwc_otg_pcd_function_ops *fops);
  99951. +
  99952. +/** Enables an endpoint for use. This function enables an endpoint in
  99953. + * the PCD. The endpoint is described by the ep_desc which has the
  99954. + * same format as a USB ep descriptor. The ep_handle parameter is used to refer
  99955. + * to the endpoint from other API functions and in callbacks. Normally this
  99956. + * should be called after a SET_CONFIGURATION/SET_INTERFACE to configure the
  99957. + * core for that interface.
  99958. + *
  99959. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  99960. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  99961. + * Returns 0 on success.
  99962. + *
  99963. + * @param pcd The PCD
  99964. + * @param ep_desc Endpoint descriptor
  99965. + * @param usb_ep Handle on endpoint, that will be used to identify endpoint.
  99966. + */
  99967. +extern int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  99968. + const uint8_t * ep_desc, void *usb_ep);
  99969. +
  99970. +/** Disable the endpoint referenced by ep_handle.
  99971. + *
  99972. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  99973. + * Returns -DWC_E_SHUTDOWN if any other error occurred.
  99974. + * Returns 0 on success. */
  99975. +extern int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle);
  99976. +
  99977. +/** Queue a data transfer request on the endpoint referenced by ep_handle.
  99978. + * After the transfer is completes, the complete callback will be called with
  99979. + * the request status.
  99980. + *
  99981. + * @param pcd The PCD
  99982. + * @param ep_handle The handle of the endpoint
  99983. + * @param buf The buffer for the data
  99984. + * @param dma_buf The DMA buffer for the data
  99985. + * @param buflen The length of the data transfer
  99986. + * @param zero Specifies whether to send zero length last packet.
  99987. + * @param req_handle Set this handle to any value to use to reference this
  99988. + * request in the ep_dequeue function or from the complete callback
  99989. + * @param atomic_alloc If driver need to perform atomic allocations
  99990. + * for internal data structures.
  99991. + *
  99992. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  99993. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  99994. + * Returns 0 on success. */
  99995. +extern int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  99996. + uint8_t * buf, dwc_dma_t dma_buf,
  99997. + uint32_t buflen, int zero, void *req_handle,
  99998. + int atomic_alloc);
  99999. +#ifdef DWC_UTE_PER_IO
  100000. +/**
  100001. + *
  100002. + * @param ereq_nonport Pointer to the extended request part of the
  100003. + * usb_request structure defined in usb_gadget.h file.
  100004. + */
  100005. +extern int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  100006. + uint8_t * buf, dwc_dma_t dma_buf,
  100007. + uint32_t buflen, int zero,
  100008. + void *req_handle, int atomic_alloc,
  100009. + void *ereq_nonport);
  100010. +
  100011. +#endif
  100012. +
  100013. +/** De-queue the specified data transfer that has not yet completed.
  100014. + *
  100015. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  100016. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  100017. + * Returns 0 on success. */
  100018. +extern int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  100019. + void *req_handle);
  100020. +
  100021. +/** Halt (STALL) an endpoint or clear it.
  100022. + *
  100023. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  100024. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  100025. + * Returns -DWC_E_AGAIN if the STALL cannot be sent and must be tried again later
  100026. + * Returns 0 on success. */
  100027. +extern int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value);
  100028. +
  100029. +/** This function */
  100030. +extern int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle);
  100031. +
  100032. +/** This function should be called on every hardware interrupt */
  100033. +extern int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd);
  100034. +
  100035. +/** This function returns current frame number */
  100036. +extern int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd);
  100037. +
  100038. +/**
  100039. + * Start isochronous transfers on the endpoint referenced by ep_handle.
  100040. + * For isochronous transfers duble buffering is used.
  100041. + * After processing each of buffers comlete callback will be called with
  100042. + * status for each transaction.
  100043. + *
  100044. + * @param pcd The PCD
  100045. + * @param ep_handle The handle of the endpoint
  100046. + * @param buf0 The virtual address of first data buffer
  100047. + * @param buf1 The virtual address of second data buffer
  100048. + * @param dma0 The DMA address of first data buffer
  100049. + * @param dma1 The DMA address of second data buffer
  100050. + * @param sync_frame Data pattern frame number
  100051. + * @param dp_frame Data size for pattern frame
  100052. + * @param data_per_frame Data size for regular frame
  100053. + * @param start_frame Frame number to start transfers, if -1 then start transfers ASAP.
  100054. + * @param buf_proc_intrvl Interval of ISOC Buffer processing
  100055. + * @param req_handle Handle of ISOC request
  100056. + * @param atomic_alloc Specefies whether to perform atomic allocation for
  100057. + * internal data structures.
  100058. + *
  100059. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  100060. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function.
  100061. + * Returns -DW_E_SHUTDOWN for any other error.
  100062. + * Returns 0 on success
  100063. + */
  100064. +extern int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  100065. + uint8_t * buf0, uint8_t * buf1,
  100066. + dwc_dma_t dma0, dwc_dma_t dma1,
  100067. + int sync_frame, int dp_frame,
  100068. + int data_per_frame, int start_frame,
  100069. + int buf_proc_intrvl, void *req_handle,
  100070. + int atomic_alloc);
  100071. +
  100072. +/** Stop ISOC transfers on endpoint referenced by ep_handle.
  100073. + *
  100074. + * @param pcd The PCD
  100075. + * @param ep_handle The handle of the endpoint
  100076. + * @param req_handle Handle of ISOC request
  100077. + *
  100078. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function
  100079. + * Returns 0 on success
  100080. + */
  100081. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  100082. + void *req_handle);
  100083. +
  100084. +/** Get ISOC packet status.
  100085. + *
  100086. + * @param pcd The PCD
  100087. + * @param ep_handle The handle of the endpoint
  100088. + * @param iso_req_handle Isochronoush request handle
  100089. + * @param packet Number of packet
  100090. + * @param status Out parameter for returning status
  100091. + * @param actual Out parameter for returning actual length
  100092. + * @param offset Out parameter for returning offset
  100093. + *
  100094. + */
  100095. +extern void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd,
  100096. + void *ep_handle,
  100097. + void *iso_req_handle, int packet,
  100098. + int *status, int *actual,
  100099. + int *offset);
  100100. +
  100101. +/** Get ISOC packet count.
  100102. + *
  100103. + * @param pcd The PCD
  100104. + * @param ep_handle The handle of the endpoint
  100105. + * @param iso_req_handle
  100106. + */
  100107. +extern int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd,
  100108. + void *ep_handle,
  100109. + void *iso_req_handle);
  100110. +
  100111. +/** This function starts the SRP Protocol if no session is in progress. If
  100112. + * a session is already in progress, but the device is suspended,
  100113. + * remote wakeup signaling is started.
  100114. + */
  100115. +extern int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd);
  100116. +
  100117. +/** This function returns 1 if LPM support is enabled, and 0 otherwise. */
  100118. +extern int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd);
  100119. +
  100120. +/** This function returns 1 if remote wakeup is allowed and 0, otherwise. */
  100121. +extern int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd);
  100122. +
  100123. +/** Initiate SRP */
  100124. +extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd);
  100125. +
  100126. +/** Starts remote wakeup signaling. */
  100127. +extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set);
  100128. +
  100129. +/** Starts micorsecond soft disconnect. */
  100130. +extern void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs);
  100131. +/** This function returns whether device is dualspeed.*/
  100132. +extern uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd);
  100133. +
  100134. +/** This function returns whether device is otg. */
  100135. +extern uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd);
  100136. +
  100137. +/** These functions allow to get hnp parameters */
  100138. +extern uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd);
  100139. +extern uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd);
  100140. +extern uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd);
  100141. +
  100142. +/** CFI specific Interface functions */
  100143. +/** Allocate a cfi buffer */
  100144. +extern uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep,
  100145. + dwc_dma_t * addr, size_t buflen,
  100146. + int flags);
  100147. +
  100148. +/******************************************************************************/
  100149. +
  100150. +/** @} */
  100151. +
  100152. +#endif /* __DWC_PCD_IF_H__ */
  100153. +
  100154. +#endif /* DWC_HOST_ONLY */
  100155. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c
  100156. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  100157. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 2015-02-09 04:40:29.000000000 +0100
  100158. @@ -0,0 +1,5147 @@
  100159. +/* ==========================================================================
  100160. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_intr.c $
  100161. + * $Revision: #116 $
  100162. + * $Date: 2012/08/10 $
  100163. + * $Change: 2047372 $
  100164. + *
  100165. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  100166. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  100167. + * otherwise expressly agreed to in writing between Synopsys and you.
  100168. + *
  100169. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  100170. + * any End User Software License Agreement or Agreement for Licensed Product
  100171. + * with Synopsys or any supplement thereto. You are permitted to use and
  100172. + * redistribute this Software in source and binary forms, with or without
  100173. + * modification, provided that redistributions of source code must retain this
  100174. + * notice. You may not view, use, disclose, copy or distribute this file or
  100175. + * any information contained herein except pursuant to this license grant from
  100176. + * Synopsys. If you do not agree with this notice, including the disclaimer
  100177. + * below, then you are not authorized to use the Software.
  100178. + *
  100179. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  100180. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  100181. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  100182. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  100183. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  100184. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  100185. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  100186. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  100187. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  100188. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  100189. + * DAMAGE.
  100190. + * ========================================================================== */
  100191. +#ifndef DWC_HOST_ONLY
  100192. +
  100193. +#include "dwc_otg_pcd.h"
  100194. +
  100195. +#ifdef DWC_UTE_CFI
  100196. +#include "dwc_otg_cfi.h"
  100197. +#endif
  100198. +
  100199. +#ifdef DWC_UTE_PER_IO
  100200. +extern void complete_xiso_ep(dwc_otg_pcd_ep_t * ep);
  100201. +#endif
  100202. +//#define PRINT_CFI_DMA_DESCS
  100203. +
  100204. +#define DEBUG_EP0
  100205. +
  100206. +/**
  100207. + * This function updates OTG.
  100208. + */
  100209. +static void dwc_otg_pcd_update_otg(dwc_otg_pcd_t * pcd, const unsigned reset)
  100210. +{
  100211. +
  100212. + if (reset) {
  100213. + pcd->b_hnp_enable = 0;
  100214. + pcd->a_hnp_support = 0;
  100215. + pcd->a_alt_hnp_support = 0;
  100216. + }
  100217. +
  100218. + if (pcd->fops->hnp_changed) {
  100219. + pcd->fops->hnp_changed(pcd);
  100220. + }
  100221. +}
  100222. +
  100223. +/** @file
  100224. + * This file contains the implementation of the PCD Interrupt handlers.
  100225. + *
  100226. + * The PCD handles the device interrupts. Many conditions can cause a
  100227. + * device interrupt. When an interrupt occurs, the device interrupt
  100228. + * service routine determines the cause of the interrupt and
  100229. + * dispatches handling to the appropriate function. These interrupt
  100230. + * handling functions are described below.
  100231. + * All interrupt registers are processed from LSB to MSB.
  100232. + */
  100233. +
  100234. +/**
  100235. + * This function prints the ep0 state for debug purposes.
  100236. + */
  100237. +static inline void print_ep0_state(dwc_otg_pcd_t * pcd)
  100238. +{
  100239. +#ifdef DEBUG
  100240. + char str[40];
  100241. +
  100242. + switch (pcd->ep0state) {
  100243. + case EP0_DISCONNECT:
  100244. + dwc_strcpy(str, "EP0_DISCONNECT");
  100245. + break;
  100246. + case EP0_IDLE:
  100247. + dwc_strcpy(str, "EP0_IDLE");
  100248. + break;
  100249. + case EP0_IN_DATA_PHASE:
  100250. + dwc_strcpy(str, "EP0_IN_DATA_PHASE");
  100251. + break;
  100252. + case EP0_OUT_DATA_PHASE:
  100253. + dwc_strcpy(str, "EP0_OUT_DATA_PHASE");
  100254. + break;
  100255. + case EP0_IN_STATUS_PHASE:
  100256. + dwc_strcpy(str, "EP0_IN_STATUS_PHASE");
  100257. + break;
  100258. + case EP0_OUT_STATUS_PHASE:
  100259. + dwc_strcpy(str, "EP0_OUT_STATUS_PHASE");
  100260. + break;
  100261. + case EP0_STALL:
  100262. + dwc_strcpy(str, "EP0_STALL");
  100263. + break;
  100264. + default:
  100265. + dwc_strcpy(str, "EP0_INVALID");
  100266. + }
  100267. +
  100268. + DWC_DEBUGPL(DBG_ANY, "%s(%d)\n", str, pcd->ep0state);
  100269. +#endif
  100270. +}
  100271. +
  100272. +/**
  100273. + * This function calculate the size of the payload in the memory
  100274. + * for out endpoints and prints size for debug purposes(used in
  100275. + * 2.93a DevOutNak feature).
  100276. + */
  100277. +static inline void print_memory_payload(dwc_otg_pcd_t * pcd, dwc_ep_t * ep)
  100278. +{
  100279. +#ifdef DEBUG
  100280. + deptsiz_data_t deptsiz_init = {.d32 = 0 };
  100281. + deptsiz_data_t deptsiz_updt = {.d32 = 0 };
  100282. + int pack_num;
  100283. + unsigned payload;
  100284. +
  100285. + deptsiz_init.d32 = pcd->core_if->start_doeptsiz_val[ep->num];
  100286. + deptsiz_updt.d32 =
  100287. + DWC_READ_REG32(&pcd->core_if->dev_if->
  100288. + out_ep_regs[ep->num]->doeptsiz);
  100289. + /* Payload will be */
  100290. + payload = deptsiz_init.b.xfersize - deptsiz_updt.b.xfersize;
  100291. + /* Packet count is decremented every time a packet
  100292. + * is written to the RxFIFO not in to the external memory
  100293. + * So, if payload == 0, then it means no packet was sent to ext memory*/
  100294. + pack_num = (!payload) ? 0 : (deptsiz_init.b.pktcnt - deptsiz_updt.b.pktcnt);
  100295. + DWC_DEBUGPL(DBG_PCDV,
  100296. + "Payload for EP%d-%s\n",
  100297. + ep->num, (ep->is_in ? "IN" : "OUT"));
  100298. + DWC_DEBUGPL(DBG_PCDV,
  100299. + "Number of transfered bytes = 0x%08x\n", payload);
  100300. + DWC_DEBUGPL(DBG_PCDV,
  100301. + "Number of transfered packets = %d\n", pack_num);
  100302. +#endif
  100303. +}
  100304. +
  100305. +
  100306. +#ifdef DWC_UTE_CFI
  100307. +static inline void print_desc(struct dwc_otg_dma_desc *ddesc,
  100308. + const uint8_t * epname, int descnum)
  100309. +{
  100310. + CFI_INFO
  100311. + ("%s DMA_DESC(%d) buf=0x%08x bytes=0x%04x; sp=0x%x; l=0x%x; sts=0x%02x; bs=0x%02x\n",
  100312. + epname, descnum, ddesc->buf, ddesc->status.b.bytes,
  100313. + ddesc->status.b.sp, ddesc->status.b.l, ddesc->status.b.sts,
  100314. + ddesc->status.b.bs);
  100315. +}
  100316. +#endif
  100317. +
  100318. +/**
  100319. + * This function returns pointer to in ep struct with number ep_num
  100320. + */
  100321. +static inline dwc_otg_pcd_ep_t *get_in_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  100322. +{
  100323. + int i;
  100324. + int num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  100325. + if (ep_num == 0) {
  100326. + return &pcd->ep0;
  100327. + } else {
  100328. + for (i = 0; i < num_in_eps; ++i) {
  100329. + if (pcd->in_ep[i].dwc_ep.num == ep_num)
  100330. + return &pcd->in_ep[i];
  100331. + }
  100332. + return 0;
  100333. + }
  100334. +}
  100335. +
  100336. +/**
  100337. + * This function returns pointer to out ep struct with number ep_num
  100338. + */
  100339. +static inline dwc_otg_pcd_ep_t *get_out_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  100340. +{
  100341. + int i;
  100342. + int num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  100343. + if (ep_num == 0) {
  100344. + return &pcd->ep0;
  100345. + } else {
  100346. + for (i = 0; i < num_out_eps; ++i) {
  100347. + if (pcd->out_ep[i].dwc_ep.num == ep_num)
  100348. + return &pcd->out_ep[i];
  100349. + }
  100350. + return 0;
  100351. + }
  100352. +}
  100353. +
  100354. +/**
  100355. + * This functions gets a pointer to an EP from the wIndex address
  100356. + * value of the control request.
  100357. + */
  100358. +dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex)
  100359. +{
  100360. + dwc_otg_pcd_ep_t *ep;
  100361. + uint32_t ep_num = UE_GET_ADDR(wIndex);
  100362. +
  100363. + if (ep_num == 0) {
  100364. + ep = &pcd->ep0;
  100365. + } else if (UE_GET_DIR(wIndex) == UE_DIR_IN) { /* in ep */
  100366. + ep = &pcd->in_ep[ep_num - 1];
  100367. + } else {
  100368. + ep = &pcd->out_ep[ep_num - 1];
  100369. + }
  100370. +
  100371. + return ep;
  100372. +}
  100373. +
  100374. +/**
  100375. + * This function checks the EP request queue, if the queue is not
  100376. + * empty the next request is started.
  100377. + */
  100378. +void start_next_request(dwc_otg_pcd_ep_t * ep)
  100379. +{
  100380. + dwc_otg_pcd_request_t *req = 0;
  100381. + uint32_t max_transfer =
  100382. + GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
  100383. +
  100384. +#ifdef DWC_UTE_CFI
  100385. + struct dwc_otg_pcd *pcd;
  100386. + pcd = ep->pcd;
  100387. +#endif
  100388. +
  100389. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  100390. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  100391. +
  100392. +#ifdef DWC_UTE_CFI
  100393. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  100394. + ep->dwc_ep.cfi_req_len = req->length;
  100395. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd, ep, req);
  100396. + } else {
  100397. +#endif
  100398. + /* Setup and start the Transfer */
  100399. + if (req->dw_align_buf) {
  100400. + ep->dwc_ep.dma_addr = req->dw_align_buf_dma;
  100401. + ep->dwc_ep.start_xfer_buff = req->dw_align_buf;
  100402. + ep->dwc_ep.xfer_buff = req->dw_align_buf;
  100403. + } else {
  100404. + ep->dwc_ep.dma_addr = req->dma;
  100405. + ep->dwc_ep.start_xfer_buff = req->buf;
  100406. + ep->dwc_ep.xfer_buff = req->buf;
  100407. + }
  100408. + ep->dwc_ep.sent_zlp = 0;
  100409. + ep->dwc_ep.total_len = req->length;
  100410. + ep->dwc_ep.xfer_len = 0;
  100411. + ep->dwc_ep.xfer_count = 0;
  100412. +
  100413. + ep->dwc_ep.maxxfer = max_transfer;
  100414. + if (GET_CORE_IF(ep->pcd)->dma_desc_enable) {
  100415. + uint32_t out_max_xfer = DDMA_MAX_TRANSFER_SIZE
  100416. + - (DDMA_MAX_TRANSFER_SIZE % 4);
  100417. + if (ep->dwc_ep.is_in) {
  100418. + if (ep->dwc_ep.maxxfer >
  100419. + DDMA_MAX_TRANSFER_SIZE) {
  100420. + ep->dwc_ep.maxxfer =
  100421. + DDMA_MAX_TRANSFER_SIZE;
  100422. + }
  100423. + } else {
  100424. + if (ep->dwc_ep.maxxfer > out_max_xfer) {
  100425. + ep->dwc_ep.maxxfer =
  100426. + out_max_xfer;
  100427. + }
  100428. + }
  100429. + }
  100430. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  100431. + ep->dwc_ep.maxxfer -=
  100432. + (ep->dwc_ep.maxxfer % ep->dwc_ep.maxpacket);
  100433. + }
  100434. + if (req->sent_zlp) {
  100435. + if ((ep->dwc_ep.total_len %
  100436. + ep->dwc_ep.maxpacket == 0)
  100437. + && (ep->dwc_ep.total_len != 0)) {
  100438. + ep->dwc_ep.sent_zlp = 1;
  100439. + }
  100440. +
  100441. + }
  100442. +#ifdef DWC_UTE_CFI
  100443. + }
  100444. +#endif
  100445. + dwc_otg_ep_start_transfer(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
  100446. + } else if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  100447. + DWC_PRINTF("There are no more ISOC requests \n");
  100448. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  100449. + }
  100450. +}
  100451. +
  100452. +/**
  100453. + * This function handles the SOF Interrupts. At this time the SOF
  100454. + * Interrupt is disabled.
  100455. + */
  100456. +int32_t dwc_otg_pcd_handle_sof_intr(dwc_otg_pcd_t * pcd)
  100457. +{
  100458. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  100459. +
  100460. + gintsts_data_t gintsts;
  100461. +
  100462. + DWC_DEBUGPL(DBG_PCD, "SOF\n");
  100463. +
  100464. + /* Clear interrupt */
  100465. + gintsts.d32 = 0;
  100466. + gintsts.b.sofintr = 1;
  100467. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  100468. +
  100469. + return 1;
  100470. +}
  100471. +
  100472. +/**
  100473. + * This function handles the Rx Status Queue Level Interrupt, which
  100474. + * indicates that there is a least one packet in the Rx FIFO. The
  100475. + * packets are moved from the FIFO to memory, where they will be
  100476. + * processed when the Endpoint Interrupt Register indicates Transfer
  100477. + * Complete or SETUP Phase Done.
  100478. + *
  100479. + * Repeat the following until the Rx Status Queue is empty:
  100480. + * -# Read the Receive Status Pop Register (GRXSTSP) to get Packet
  100481. + * info
  100482. + * -# If Receive FIFO is empty then skip to step Clear the interrupt
  100483. + * and exit
  100484. + * -# If SETUP Packet call dwc_otg_read_setup_packet to copy the
  100485. + * SETUP data to the buffer
  100486. + * -# If OUT Data Packet call dwc_otg_read_packet to copy the data
  100487. + * to the destination buffer
  100488. + */
  100489. +int32_t dwc_otg_pcd_handle_rx_status_q_level_intr(dwc_otg_pcd_t * pcd)
  100490. +{
  100491. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  100492. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  100493. + gintmsk_data_t gintmask = {.d32 = 0 };
  100494. + device_grxsts_data_t status;
  100495. + dwc_otg_pcd_ep_t *ep;
  100496. + gintsts_data_t gintsts;
  100497. +#ifdef DEBUG
  100498. + static char *dpid_str[] = { "D0", "D2", "D1", "MDATA" };
  100499. +#endif
  100500. +
  100501. + //DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _pcd);
  100502. + /* Disable the Rx Status Queue Level interrupt */
  100503. + gintmask.b.rxstsqlvl = 1;
  100504. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmask.d32, 0);
  100505. +
  100506. + /* Get the Status from the top of the FIFO */
  100507. + status.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  100508. +
  100509. + DWC_DEBUGPL(DBG_PCD, "EP:%d BCnt:%d DPID:%s "
  100510. + "pktsts:%x Frame:%d(0x%0x)\n",
  100511. + status.b.epnum, status.b.bcnt,
  100512. + dpid_str[status.b.dpid],
  100513. + status.b.pktsts, status.b.fn, status.b.fn);
  100514. + /* Get pointer to EP structure */
  100515. + ep = get_out_ep(pcd, status.b.epnum);
  100516. +
  100517. + switch (status.b.pktsts) {
  100518. + case DWC_DSTS_GOUT_NAK:
  100519. + DWC_DEBUGPL(DBG_PCDV, "Global OUT NAK\n");
  100520. + break;
  100521. + case DWC_STS_DATA_UPDT:
  100522. + DWC_DEBUGPL(DBG_PCDV, "OUT Data Packet\n");
  100523. + if (status.b.bcnt && ep->dwc_ep.xfer_buff) {
  100524. + /** @todo NGS Check for buffer overflow? */
  100525. + dwc_otg_read_packet(core_if,
  100526. + ep->dwc_ep.xfer_buff,
  100527. + status.b.bcnt);
  100528. + ep->dwc_ep.xfer_count += status.b.bcnt;
  100529. + ep->dwc_ep.xfer_buff += status.b.bcnt;
  100530. + }
  100531. + break;
  100532. + case DWC_STS_XFER_COMP:
  100533. + DWC_DEBUGPL(DBG_PCDV, "OUT Complete\n");
  100534. + break;
  100535. + case DWC_DSTS_SETUP_COMP:
  100536. +#ifdef DEBUG_EP0
  100537. + DWC_DEBUGPL(DBG_PCDV, "Setup Complete\n");
  100538. +#endif
  100539. + break;
  100540. + case DWC_DSTS_SETUP_UPDT:
  100541. + dwc_otg_read_setup_packet(core_if, pcd->setup_pkt->d32);
  100542. +#ifdef DEBUG_EP0
  100543. + DWC_DEBUGPL(DBG_PCD,
  100544. + "SETUP PKT: %02x.%02x v%04x i%04x l%04x\n",
  100545. + pcd->setup_pkt->req.bmRequestType,
  100546. + pcd->setup_pkt->req.bRequest,
  100547. + UGETW(pcd->setup_pkt->req.wValue),
  100548. + UGETW(pcd->setup_pkt->req.wIndex),
  100549. + UGETW(pcd->setup_pkt->req.wLength));
  100550. +#endif
  100551. + ep->dwc_ep.xfer_count += status.b.bcnt;
  100552. + break;
  100553. + default:
  100554. + DWC_DEBUGPL(DBG_PCDV, "Invalid Packet Status (0x%0x)\n",
  100555. + status.b.pktsts);
  100556. + break;
  100557. + }
  100558. +
  100559. + /* Enable the Rx Status Queue Level interrupt */
  100560. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmask.d32);
  100561. + /* Clear interrupt */
  100562. + gintsts.d32 = 0;
  100563. + gintsts.b.rxstsqlvl = 1;
  100564. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  100565. +
  100566. + //DWC_DEBUGPL(DBG_PCDV, "EXIT: %s\n", __func__);
  100567. + return 1;
  100568. +}
  100569. +
  100570. +/**
  100571. + * This function examines the Device IN Token Learning Queue to
  100572. + * determine the EP number of the last IN token received. This
  100573. + * implementation is for the Mass Storage device where there are only
  100574. + * 2 IN EPs (Control-IN and BULK-IN).
  100575. + *
  100576. + * The EP numbers for the first six IN Tokens are in DTKNQR1 and there
  100577. + * are 8 EP Numbers in each of the other possible DTKNQ Registers.
  100578. + *
  100579. + * @param core_if Programming view of DWC_otg controller.
  100580. + *
  100581. + */
  100582. +static inline int get_ep_of_last_in_token(dwc_otg_core_if_t * core_if)
  100583. +{
  100584. + dwc_otg_device_global_regs_t *dev_global_regs =
  100585. + core_if->dev_if->dev_global_regs;
  100586. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  100587. + /* Number of Token Queue Registers */
  100588. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  100589. + dtknq1_data_t dtknqr1;
  100590. + uint32_t in_tkn_epnums[4];
  100591. + int ndx = 0;
  100592. + int i = 0;
  100593. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  100594. + int epnum = 0;
  100595. +
  100596. + //DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  100597. +
  100598. + /* Read the DTKNQ Registers */
  100599. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  100600. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  100601. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  100602. + in_tkn_epnums[i]);
  100603. + if (addr == &dev_global_regs->dvbusdis) {
  100604. + addr = &dev_global_regs->dtknqr3_dthrctl;
  100605. + } else {
  100606. + ++addr;
  100607. + }
  100608. +
  100609. + }
  100610. +
  100611. + /* Copy the DTKNQR1 data to the bit field. */
  100612. + dtknqr1.d32 = in_tkn_epnums[0];
  100613. + /* Get the EP numbers */
  100614. + in_tkn_epnums[0] = dtknqr1.b.epnums0_5;
  100615. + ndx = dtknqr1.b.intknwptr - 1;
  100616. +
  100617. + //DWC_DEBUGPL(DBG_PCDV,"ndx=%d\n",ndx);
  100618. + if (ndx == -1) {
  100619. + /** @todo Find a simpler way to calculate the max
  100620. + * queue position.*/
  100621. + int cnt = TOKEN_Q_DEPTH;
  100622. + if (TOKEN_Q_DEPTH <= 6) {
  100623. + cnt = TOKEN_Q_DEPTH - 1;
  100624. + } else if (TOKEN_Q_DEPTH <= 14) {
  100625. + cnt = TOKEN_Q_DEPTH - 7;
  100626. + } else if (TOKEN_Q_DEPTH <= 22) {
  100627. + cnt = TOKEN_Q_DEPTH - 15;
  100628. + } else {
  100629. + cnt = TOKEN_Q_DEPTH - 23;
  100630. + }
  100631. + epnum = (in_tkn_epnums[DTKNQ_REG_CNT - 1] >> (cnt * 4)) & 0xF;
  100632. + } else {
  100633. + if (ndx <= 5) {
  100634. + epnum = (in_tkn_epnums[0] >> (ndx * 4)) & 0xF;
  100635. + } else if (ndx <= 13) {
  100636. + ndx -= 6;
  100637. + epnum = (in_tkn_epnums[1] >> (ndx * 4)) & 0xF;
  100638. + } else if (ndx <= 21) {
  100639. + ndx -= 14;
  100640. + epnum = (in_tkn_epnums[2] >> (ndx * 4)) & 0xF;
  100641. + } else if (ndx <= 29) {
  100642. + ndx -= 22;
  100643. + epnum = (in_tkn_epnums[3] >> (ndx * 4)) & 0xF;
  100644. + }
  100645. + }
  100646. + //DWC_DEBUGPL(DBG_PCD,"epnum=%d\n",epnum);
  100647. + return epnum;
  100648. +}
  100649. +
  100650. +/**
  100651. + * This interrupt occurs when the non-periodic Tx FIFO is half-empty.
  100652. + * The active request is checked for the next packet to be loaded into
  100653. + * the non-periodic Tx FIFO.
  100654. + */
  100655. +int32_t dwc_otg_pcd_handle_np_tx_fifo_empty_intr(dwc_otg_pcd_t * pcd)
  100656. +{
  100657. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  100658. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  100659. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  100660. + gnptxsts_data_t txstatus = {.d32 = 0 };
  100661. + gintsts_data_t gintsts;
  100662. +
  100663. + int epnum = 0;
  100664. + dwc_otg_pcd_ep_t *ep = 0;
  100665. + uint32_t len = 0;
  100666. + int dwords;
  100667. +
  100668. + /* Get the epnum from the IN Token Learning Queue. */
  100669. + epnum = get_ep_of_last_in_token(core_if);
  100670. + ep = get_in_ep(pcd, epnum);
  100671. +
  100672. + DWC_DEBUGPL(DBG_PCD, "NP TxFifo Empty: %d \n", epnum);
  100673. +
  100674. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  100675. +
  100676. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  100677. + if (len > ep->dwc_ep.maxpacket) {
  100678. + len = ep->dwc_ep.maxpacket;
  100679. + }
  100680. + dwords = (len + 3) / 4;
  100681. +
  100682. + /* While there is space in the queue and space in the FIFO and
  100683. + * More data to tranfer, Write packets to the Tx FIFO */
  100684. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  100685. + DWC_DEBUGPL(DBG_PCDV, "b4 GNPTXSTS=0x%08x\n", txstatus.d32);
  100686. +
  100687. + while (txstatus.b.nptxqspcavail > 0 &&
  100688. + txstatus.b.nptxfspcavail > dwords &&
  100689. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len) {
  100690. + /* Write the FIFO */
  100691. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  100692. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  100693. +
  100694. + if (len > ep->dwc_ep.maxpacket) {
  100695. + len = ep->dwc_ep.maxpacket;
  100696. + }
  100697. +
  100698. + dwords = (len + 3) / 4;
  100699. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  100700. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n", txstatus.d32);
  100701. + }
  100702. +
  100703. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n",
  100704. + DWC_READ_REG32(&global_regs->gnptxsts));
  100705. +
  100706. + /* Clear interrupt */
  100707. + gintsts.d32 = 0;
  100708. + gintsts.b.nptxfempty = 1;
  100709. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  100710. +
  100711. + return 1;
  100712. +}
  100713. +
  100714. +/**
  100715. + * This function is called when dedicated Tx FIFO Empty interrupt occurs.
  100716. + * The active request is checked for the next packet to be loaded into
  100717. + * apropriate Tx FIFO.
  100718. + */
  100719. +static int32_t write_empty_tx_fifo(dwc_otg_pcd_t * pcd, uint32_t epnum)
  100720. +{
  100721. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  100722. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  100723. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  100724. + dtxfsts_data_t txstatus = {.d32 = 0 };
  100725. + dwc_otg_pcd_ep_t *ep = 0;
  100726. + uint32_t len = 0;
  100727. + int dwords;
  100728. +
  100729. + ep = get_in_ep(pcd, epnum);
  100730. +
  100731. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  100732. +
  100733. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  100734. +
  100735. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  100736. +
  100737. + if (len > ep->dwc_ep.maxpacket) {
  100738. + len = ep->dwc_ep.maxpacket;
  100739. + }
  100740. +
  100741. + dwords = (len + 3) / 4;
  100742. +
  100743. + /* While there is space in the queue and space in the FIFO and
  100744. + * More data to tranfer, Write packets to the Tx FIFO */
  100745. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  100746. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  100747. +
  100748. + while (txstatus.b.txfspcavail > dwords &&
  100749. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len &&
  100750. + ep->dwc_ep.xfer_len != 0) {
  100751. + /* Write the FIFO */
  100752. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  100753. +
  100754. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  100755. + if (len > ep->dwc_ep.maxpacket) {
  100756. + len = ep->dwc_ep.maxpacket;
  100757. + }
  100758. +
  100759. + dwords = (len + 3) / 4;
  100760. + txstatus.d32 =
  100761. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  100762. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  100763. + txstatus.d32);
  100764. + }
  100765. +
  100766. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  100767. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  100768. +
  100769. + return 1;
  100770. +}
  100771. +
  100772. +/**
  100773. + * This function is called when the Device is disconnected. It stops
  100774. + * any active requests and informs the Gadget driver of the
  100775. + * disconnect.
  100776. + */
  100777. +void dwc_otg_pcd_stop(dwc_otg_pcd_t * pcd)
  100778. +{
  100779. + int i, num_in_eps, num_out_eps;
  100780. + dwc_otg_pcd_ep_t *ep;
  100781. +
  100782. + gintmsk_data_t intr_mask = {.d32 = 0 };
  100783. +
  100784. + DWC_SPINLOCK(pcd->lock);
  100785. +
  100786. + num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  100787. + num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  100788. +
  100789. + DWC_DEBUGPL(DBG_PCDV, "%s() \n", __func__);
  100790. + /* don't disconnect drivers more than once */
  100791. + if (pcd->ep0state == EP0_DISCONNECT) {
  100792. + DWC_DEBUGPL(DBG_ANY, "%s() Already Disconnected\n", __func__);
  100793. + DWC_SPINUNLOCK(pcd->lock);
  100794. + return;
  100795. + }
  100796. + pcd->ep0state = EP0_DISCONNECT;
  100797. +
  100798. + /* Reset the OTG state. */
  100799. + dwc_otg_pcd_update_otg(pcd, 1);
  100800. +
  100801. + /* Disable the NP Tx Fifo Empty Interrupt. */
  100802. + intr_mask.b.nptxfempty = 1;
  100803. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  100804. + intr_mask.d32, 0);
  100805. +
  100806. + /* Flush the FIFOs */
  100807. + /**@todo NGS Flush Periodic FIFOs */
  100808. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd), 0x10);
  100809. + dwc_otg_flush_rx_fifo(GET_CORE_IF(pcd));
  100810. +
  100811. + /* prevent new request submissions, kill any outstanding requests */
  100812. + ep = &pcd->ep0;
  100813. + dwc_otg_request_nuke(ep);
  100814. + /* prevent new request submissions, kill any outstanding requests */
  100815. + for (i = 0; i < num_in_eps; i++) {
  100816. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[i];
  100817. + dwc_otg_request_nuke(ep);
  100818. + }
  100819. + /* prevent new request submissions, kill any outstanding requests */
  100820. + for (i = 0; i < num_out_eps; i++) {
  100821. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[i];
  100822. + dwc_otg_request_nuke(ep);
  100823. + }
  100824. +
  100825. + /* report disconnect; the driver is already quiesced */
  100826. + if (pcd->fops->disconnect) {
  100827. + DWC_SPINUNLOCK(pcd->lock);
  100828. + pcd->fops->disconnect(pcd);
  100829. + DWC_SPINLOCK(pcd->lock);
  100830. + }
  100831. + DWC_SPINUNLOCK(pcd->lock);
  100832. +}
  100833. +
  100834. +/**
  100835. + * This interrupt indicates that ...
  100836. + */
  100837. +int32_t dwc_otg_pcd_handle_i2c_intr(dwc_otg_pcd_t * pcd)
  100838. +{
  100839. + gintmsk_data_t intr_mask = {.d32 = 0 };
  100840. + gintsts_data_t gintsts;
  100841. +
  100842. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "i2cintr");
  100843. + intr_mask.b.i2cintr = 1;
  100844. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  100845. + intr_mask.d32, 0);
  100846. +
  100847. + /* Clear interrupt */
  100848. + gintsts.d32 = 0;
  100849. + gintsts.b.i2cintr = 1;
  100850. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  100851. + gintsts.d32);
  100852. + return 1;
  100853. +}
  100854. +
  100855. +/**
  100856. + * This interrupt indicates that ...
  100857. + */
  100858. +int32_t dwc_otg_pcd_handle_early_suspend_intr(dwc_otg_pcd_t * pcd)
  100859. +{
  100860. + gintsts_data_t gintsts;
  100861. +#if defined(VERBOSE)
  100862. + DWC_PRINTF("Early Suspend Detected\n");
  100863. +#endif
  100864. +
  100865. + /* Clear interrupt */
  100866. + gintsts.d32 = 0;
  100867. + gintsts.b.erlysuspend = 1;
  100868. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  100869. + gintsts.d32);
  100870. + return 1;
  100871. +}
  100872. +
  100873. +/**
  100874. + * This function configures EPO to receive SETUP packets.
  100875. + *
  100876. + * @todo NGS: Update the comments from the HW FS.
  100877. + *
  100878. + * -# Program the following fields in the endpoint specific registers
  100879. + * for Control OUT EP 0, in order to receive a setup packet
  100880. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  100881. + * setup packets)
  100882. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  100883. + * to back setup packets)
  100884. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  100885. + * store any setup packets received
  100886. + *
  100887. + * @param core_if Programming view of DWC_otg controller.
  100888. + * @param pcd Programming view of the PCD.
  100889. + */
  100890. +static inline void ep0_out_start(dwc_otg_core_if_t * core_if,
  100891. + dwc_otg_pcd_t * pcd)
  100892. +{
  100893. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  100894. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  100895. + dwc_otg_dev_dma_desc_t *dma_desc;
  100896. + depctl_data_t doepctl = {.d32 = 0 };
  100897. +
  100898. +#ifdef VERBOSE
  100899. + DWC_DEBUGPL(DBG_PCDV, "%s() doepctl0=%0x\n", __func__,
  100900. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  100901. +#endif
  100902. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  100903. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  100904. + if (doepctl.b.epena) {
  100905. + return;
  100906. + }
  100907. + }
  100908. +
  100909. + doeptsize0.b.supcnt = 3;
  100910. + doeptsize0.b.pktcnt = 1;
  100911. + doeptsize0.b.xfersize = 8 * 3;
  100912. +
  100913. + if (core_if->dma_enable) {
  100914. + if (!core_if->dma_desc_enable) {
  100915. + /** put here as for Hermes mode deptisz register should not be written */
  100916. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  100917. + doeptsize0.d32);
  100918. +
  100919. + /** @todo dma needs to handle multiple setup packets (up to 3) */
  100920. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  100921. + pcd->setup_pkt_dma_handle);
  100922. + } else {
  100923. + dev_if->setup_desc_index =
  100924. + (dev_if->setup_desc_index + 1) & 1;
  100925. + dma_desc =
  100926. + dev_if->setup_desc_addr[dev_if->setup_desc_index];
  100927. +
  100928. + /** DMA Descriptor Setup */
  100929. + dma_desc->status.b.bs = BS_HOST_BUSY;
  100930. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  100931. + dma_desc->status.b.sr = 0;
  100932. + dma_desc->status.b.mtrf = 0;
  100933. + }
  100934. + dma_desc->status.b.l = 1;
  100935. + dma_desc->status.b.ioc = 1;
  100936. + dma_desc->status.b.bytes = pcd->ep0.dwc_ep.maxpacket;
  100937. + dma_desc->buf = pcd->setup_pkt_dma_handle;
  100938. + dma_desc->status.b.sts = 0;
  100939. + dma_desc->status.b.bs = BS_HOST_READY;
  100940. +
  100941. + /** DOEPDMA0 Register write */
  100942. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  100943. + dev_if->dma_setup_desc_addr
  100944. + [dev_if->setup_desc_index]);
  100945. + }
  100946. +
  100947. + } else {
  100948. + /** put here as for Hermes mode deptisz register should not be written */
  100949. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  100950. + doeptsize0.d32);
  100951. + }
  100952. +
  100953. + /** DOEPCTL0 Register write cnak will be set after setup interrupt */
  100954. + doepctl.d32 = 0;
  100955. + doepctl.b.epena = 1;
  100956. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  100957. + doepctl.b.cnak = 1;
  100958. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  100959. + } else {
  100960. + DWC_MODIFY_REG32(&dev_if->out_ep_regs[0]->doepctl, 0, doepctl.d32);
  100961. + }
  100962. +
  100963. +#ifdef VERBOSE
  100964. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  100965. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  100966. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  100967. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  100968. +#endif
  100969. +}
  100970. +
  100971. +/**
  100972. + * This interrupt occurs when a USB Reset is detected. When the USB
  100973. + * Reset Interrupt occurs the device state is set to DEFAULT and the
  100974. + * EP0 state is set to IDLE.
  100975. + * -# Set the NAK bit for all OUT endpoints (DOEPCTLn.SNAK = 1)
  100976. + * -# Unmask the following interrupt bits
  100977. + * - DAINTMSK.INEP0 = 1 (Control 0 IN endpoint)
  100978. + * - DAINTMSK.OUTEP0 = 1 (Control 0 OUT endpoint)
  100979. + * - DOEPMSK.SETUP = 1
  100980. + * - DOEPMSK.XferCompl = 1
  100981. + * - DIEPMSK.XferCompl = 1
  100982. + * - DIEPMSK.TimeOut = 1
  100983. + * -# Program the following fields in the endpoint specific registers
  100984. + * for Control OUT EP 0, in order to receive a setup packet
  100985. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  100986. + * setup packets)
  100987. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  100988. + * to back setup packets)
  100989. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  100990. + * store any setup packets received
  100991. + * At this point, all the required initialization, except for enabling
  100992. + * the control 0 OUT endpoint is done, for receiving SETUP packets.
  100993. + */
  100994. +int32_t dwc_otg_pcd_handle_usb_reset_intr(dwc_otg_pcd_t * pcd)
  100995. +{
  100996. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  100997. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  100998. + depctl_data_t doepctl = {.d32 = 0 };
  100999. + depctl_data_t diepctl = {.d32 = 0 };
  101000. + daint_data_t daintmsk = {.d32 = 0 };
  101001. + doepmsk_data_t doepmsk = {.d32 = 0 };
  101002. + diepmsk_data_t diepmsk = {.d32 = 0 };
  101003. + dcfg_data_t dcfg = {.d32 = 0 };
  101004. + grstctl_t resetctl = {.d32 = 0 };
  101005. + dctl_data_t dctl = {.d32 = 0 };
  101006. + int i = 0;
  101007. + gintsts_data_t gintsts;
  101008. + pcgcctl_data_t power = {.d32 = 0 };
  101009. +
  101010. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  101011. + if (power.b.stoppclk) {
  101012. + power.d32 = 0;
  101013. + power.b.stoppclk = 1;
  101014. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  101015. +
  101016. + power.b.pwrclmp = 1;
  101017. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  101018. +
  101019. + power.b.rstpdwnmodule = 1;
  101020. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  101021. + }
  101022. +
  101023. + core_if->lx_state = DWC_OTG_L0;
  101024. +
  101025. + DWC_PRINTF("USB RESET\n");
  101026. +#ifdef DWC_EN_ISOC
  101027. + for (i = 1; i < 16; ++i) {
  101028. + dwc_otg_pcd_ep_t *ep;
  101029. + dwc_ep_t *dwc_ep;
  101030. + ep = get_in_ep(pcd, i);
  101031. + if (ep != 0) {
  101032. + dwc_ep = &ep->dwc_ep;
  101033. + dwc_ep->next_frame = 0xffffffff;
  101034. + }
  101035. + }
  101036. +#endif /* DWC_EN_ISOC */
  101037. +
  101038. + /* reset the HNP settings */
  101039. + dwc_otg_pcd_update_otg(pcd, 1);
  101040. +
  101041. + /* Clear the Remote Wakeup Signalling */
  101042. + dctl.b.rmtwkupsig = 1;
  101043. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  101044. +
  101045. + /* Set NAK for all OUT EPs */
  101046. + doepctl.b.snak = 1;
  101047. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  101048. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  101049. + }
  101050. +
  101051. + /* Flush the NP Tx FIFO */
  101052. + dwc_otg_flush_tx_fifo(core_if, 0x10);
  101053. + /* Flush the Learning Queue */
  101054. + resetctl.b.intknqflsh = 1;
  101055. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  101056. +
  101057. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  101058. + core_if->start_predict = 0;
  101059. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  101060. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  101061. + }
  101062. + core_if->nextep_seq[0] = 0;
  101063. + core_if->first_in_nextep_seq = 0;
  101064. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  101065. + diepctl.b.nextep = 0;
  101066. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  101067. +
  101068. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  101069. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  101070. + dcfg.b.epmscnt = 2;
  101071. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  101072. +
  101073. + DWC_DEBUGPL(DBG_PCDV,
  101074. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  101075. + __func__, core_if->first_in_nextep_seq);
  101076. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  101077. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  101078. + }
  101079. + }
  101080. +
  101081. + if (core_if->multiproc_int_enable) {
  101082. + daintmsk.b.inep0 = 1;
  101083. + daintmsk.b.outep0 = 1;
  101084. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk,
  101085. + daintmsk.d32);
  101086. +
  101087. + doepmsk.b.setup = 1;
  101088. + doepmsk.b.xfercompl = 1;
  101089. + doepmsk.b.ahberr = 1;
  101090. + doepmsk.b.epdisabled = 1;
  101091. +
  101092. + if ((core_if->dma_desc_enable) ||
  101093. + (core_if->dma_enable
  101094. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  101095. + doepmsk.b.stsphsercvd = 1;
  101096. + }
  101097. + if (core_if->dma_desc_enable)
  101098. + doepmsk.b.bna = 1;
  101099. +/*
  101100. + doepmsk.b.babble = 1;
  101101. + doepmsk.b.nyet = 1;
  101102. +
  101103. + if (core_if->dma_enable) {
  101104. + doepmsk.b.nak = 1;
  101105. + }
  101106. +*/
  101107. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepeachintmsk[0],
  101108. + doepmsk.d32);
  101109. +
  101110. + diepmsk.b.xfercompl = 1;
  101111. + diepmsk.b.timeout = 1;
  101112. + diepmsk.b.epdisabled = 1;
  101113. + diepmsk.b.ahberr = 1;
  101114. + diepmsk.b.intknepmis = 1;
  101115. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  101116. + diepmsk.b.intknepmis = 0;
  101117. +
  101118. +/* if (core_if->dma_desc_enable) {
  101119. + diepmsk.b.bna = 1;
  101120. + }
  101121. +*/
  101122. +/*
  101123. + if (core_if->dma_enable) {
  101124. + diepmsk.b.nak = 1;
  101125. + }
  101126. +*/
  101127. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepeachintmsk[0],
  101128. + diepmsk.d32);
  101129. + } else {
  101130. + daintmsk.b.inep0 = 1;
  101131. + daintmsk.b.outep0 = 1;
  101132. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk,
  101133. + daintmsk.d32);
  101134. +
  101135. + doepmsk.b.setup = 1;
  101136. + doepmsk.b.xfercompl = 1;
  101137. + doepmsk.b.ahberr = 1;
  101138. + doepmsk.b.epdisabled = 1;
  101139. +
  101140. + if ((core_if->dma_desc_enable) ||
  101141. + (core_if->dma_enable
  101142. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  101143. + doepmsk.b.stsphsercvd = 1;
  101144. + }
  101145. + if (core_if->dma_desc_enable)
  101146. + doepmsk.b.bna = 1;
  101147. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, doepmsk.d32);
  101148. +
  101149. + diepmsk.b.xfercompl = 1;
  101150. + diepmsk.b.timeout = 1;
  101151. + diepmsk.b.epdisabled = 1;
  101152. + diepmsk.b.ahberr = 1;
  101153. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  101154. + diepmsk.b.intknepmis = 0;
  101155. +/*
  101156. + if (core_if->dma_desc_enable) {
  101157. + diepmsk.b.bna = 1;
  101158. + }
  101159. +*/
  101160. +
  101161. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32);
  101162. + }
  101163. +
  101164. + /* Reset Device Address */
  101165. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  101166. + dcfg.b.devaddr = 0;
  101167. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  101168. +
  101169. + /* setup EP0 to receive SETUP packets */
  101170. + if (core_if->snpsid <= OTG_CORE_REV_2_94a)
  101171. + ep0_out_start(core_if, pcd);
  101172. +
  101173. + /* Clear interrupt */
  101174. + gintsts.d32 = 0;
  101175. + gintsts.b.usbreset = 1;
  101176. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  101177. +
  101178. + return 1;
  101179. +}
  101180. +
  101181. +/**
  101182. + * Get the device speed from the device status register and convert it
  101183. + * to USB speed constant.
  101184. + *
  101185. + * @param core_if Programming view of DWC_otg controller.
  101186. + */
  101187. +static int get_device_speed(dwc_otg_core_if_t * core_if)
  101188. +{
  101189. + dsts_data_t dsts;
  101190. + int speed = 0;
  101191. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  101192. +
  101193. + switch (dsts.b.enumspd) {
  101194. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  101195. + speed = USB_SPEED_HIGH;
  101196. + break;
  101197. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  101198. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  101199. + speed = USB_SPEED_FULL;
  101200. + break;
  101201. +
  101202. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  101203. + speed = USB_SPEED_LOW;
  101204. + break;
  101205. + }
  101206. +
  101207. + return speed;
  101208. +}
  101209. +
  101210. +/**
  101211. + * Read the device status register and set the device speed in the
  101212. + * data structure.
  101213. + * Set up EP0 to receive SETUP packets by calling dwc_ep0_activate.
  101214. + */
  101215. +int32_t dwc_otg_pcd_handle_enum_done_intr(dwc_otg_pcd_t * pcd)
  101216. +{
  101217. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  101218. + gintsts_data_t gintsts;
  101219. + gusbcfg_data_t gusbcfg;
  101220. + dwc_otg_core_global_regs_t *global_regs =
  101221. + GET_CORE_IF(pcd)->core_global_regs;
  101222. + uint8_t utmi16b, utmi8b;
  101223. + int speed;
  101224. + DWC_DEBUGPL(DBG_PCD, "SPEED ENUM\n");
  101225. +
  101226. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_2_60a) {
  101227. + utmi16b = 6; //vahrama old value was 6;
  101228. + utmi8b = 9;
  101229. + } else {
  101230. + utmi16b = 4;
  101231. + utmi8b = 8;
  101232. + }
  101233. + dwc_otg_ep0_activate(GET_CORE_IF(pcd), &ep0->dwc_ep);
  101234. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a) {
  101235. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  101236. + }
  101237. +
  101238. +#ifdef DEBUG_EP0
  101239. + print_ep0_state(pcd);
  101240. +#endif
  101241. +
  101242. + if (pcd->ep0state == EP0_DISCONNECT) {
  101243. + pcd->ep0state = EP0_IDLE;
  101244. + } else if (pcd->ep0state == EP0_STALL) {
  101245. + pcd->ep0state = EP0_IDLE;
  101246. + }
  101247. +
  101248. + pcd->ep0state = EP0_IDLE;
  101249. +
  101250. + ep0->stopped = 0;
  101251. +
  101252. + speed = get_device_speed(GET_CORE_IF(pcd));
  101253. + pcd->fops->connect(pcd, speed);
  101254. +
  101255. + /* Set USB turnaround time based on device speed and PHY interface. */
  101256. + gusbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  101257. + if (speed == USB_SPEED_HIGH) {
  101258. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  101259. + DWC_HWCFG2_HS_PHY_TYPE_ULPI) {
  101260. + /* ULPI interface */
  101261. + gusbcfg.b.usbtrdtim = 9;
  101262. + }
  101263. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  101264. + DWC_HWCFG2_HS_PHY_TYPE_UTMI) {
  101265. + /* UTMI+ interface */
  101266. + if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 0) {
  101267. + gusbcfg.b.usbtrdtim = utmi8b;
  101268. + } else if (GET_CORE_IF(pcd)->hwcfg4.
  101269. + b.utmi_phy_data_width == 1) {
  101270. + gusbcfg.b.usbtrdtim = utmi16b;
  101271. + } else if (GET_CORE_IF(pcd)->
  101272. + core_params->phy_utmi_width == 8) {
  101273. + gusbcfg.b.usbtrdtim = utmi8b;
  101274. + } else {
  101275. + gusbcfg.b.usbtrdtim = utmi16b;
  101276. + }
  101277. + }
  101278. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  101279. + DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI) {
  101280. + /* UTMI+ OR ULPI interface */
  101281. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  101282. + /* ULPI interface */
  101283. + gusbcfg.b.usbtrdtim = 9;
  101284. + } else {
  101285. + /* UTMI+ interface */
  101286. + if (GET_CORE_IF(pcd)->
  101287. + core_params->phy_utmi_width == 16) {
  101288. + gusbcfg.b.usbtrdtim = utmi16b;
  101289. + } else {
  101290. + gusbcfg.b.usbtrdtim = utmi8b;
  101291. + }
  101292. + }
  101293. + }
  101294. + } else {
  101295. + /* Full or low speed */
  101296. + gusbcfg.b.usbtrdtim = 9;
  101297. + }
  101298. + DWC_WRITE_REG32(&global_regs->gusbcfg, gusbcfg.d32);
  101299. +
  101300. + /* Clear interrupt */
  101301. + gintsts.d32 = 0;
  101302. + gintsts.b.enumdone = 1;
  101303. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  101304. + gintsts.d32);
  101305. + return 1;
  101306. +}
  101307. +
  101308. +/**
  101309. + * This interrupt indicates that the ISO OUT Packet was dropped due to
  101310. + * Rx FIFO full or Rx Status Queue Full. If this interrupt occurs
  101311. + * read all the data from the Rx FIFO.
  101312. + */
  101313. +int32_t dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(dwc_otg_pcd_t * pcd)
  101314. +{
  101315. + gintmsk_data_t intr_mask = {.d32 = 0 };
  101316. + gintsts_data_t gintsts;
  101317. +
  101318. + DWC_WARN("INTERRUPT Handler not implemented for %s\n",
  101319. + "ISOC Out Dropped");
  101320. +
  101321. + intr_mask.b.isooutdrop = 1;
  101322. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  101323. + intr_mask.d32, 0);
  101324. +
  101325. + /* Clear interrupt */
  101326. + gintsts.d32 = 0;
  101327. + gintsts.b.isooutdrop = 1;
  101328. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  101329. + gintsts.d32);
  101330. +
  101331. + return 1;
  101332. +}
  101333. +
  101334. +/**
  101335. + * This interrupt indicates the end of the portion of the micro-frame
  101336. + * for periodic transactions. If there is a periodic transaction for
  101337. + * the next frame, load the packets into the EP periodic Tx FIFO.
  101338. + */
  101339. +int32_t dwc_otg_pcd_handle_end_periodic_frame_intr(dwc_otg_pcd_t * pcd)
  101340. +{
  101341. + gintmsk_data_t intr_mask = {.d32 = 0 };
  101342. + gintsts_data_t gintsts;
  101343. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "EOP");
  101344. +
  101345. + intr_mask.b.eopframe = 1;
  101346. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  101347. + intr_mask.d32, 0);
  101348. +
  101349. + /* Clear interrupt */
  101350. + gintsts.d32 = 0;
  101351. + gintsts.b.eopframe = 1;
  101352. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  101353. + gintsts.d32);
  101354. +
  101355. + return 1;
  101356. +}
  101357. +
  101358. +/**
  101359. + * This interrupt indicates that EP of the packet on the top of the
  101360. + * non-periodic Tx FIFO does not match EP of the IN Token received.
  101361. + *
  101362. + * The "Device IN Token Queue" Registers are read to determine the
  101363. + * order the IN Tokens have been received. The non-periodic Tx FIFO
  101364. + * is flushed, so it can be reloaded in the order seen in the IN Token
  101365. + * Queue.
  101366. + */
  101367. +int32_t dwc_otg_pcd_handle_ep_mismatch_intr(dwc_otg_pcd_t * pcd)
  101368. +{
  101369. + gintsts_data_t gintsts;
  101370. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  101371. + dctl_data_t dctl;
  101372. + gintmsk_data_t intr_mask = {.d32 = 0 };
  101373. +
  101374. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  101375. + core_if->start_predict = 1;
  101376. +
  101377. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  101378. +
  101379. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  101380. + if (!gintsts.b.ginnakeff) {
  101381. + /* Disable EP Mismatch interrupt */
  101382. + intr_mask.d32 = 0;
  101383. + intr_mask.b.epmismatch = 1;
  101384. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  101385. + /* Enable the Global IN NAK Effective Interrupt */
  101386. + intr_mask.d32 = 0;
  101387. + intr_mask.b.ginnakeff = 1;
  101388. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  101389. + /* Set the global non-periodic IN NAK handshake */
  101390. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  101391. + dctl.b.sgnpinnak = 1;
  101392. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  101393. + } else {
  101394. + DWC_PRINTF("gintsts.b.ginnakeff = 1! dctl.b.sgnpinnak not set\n");
  101395. + }
  101396. + /* Disabling of all EP's will be done in dwc_otg_pcd_handle_in_nak_effective()
  101397. + * handler after Global IN NAK Effective interrupt will be asserted */
  101398. + }
  101399. + /* Clear interrupt */
  101400. + gintsts.d32 = 0;
  101401. + gintsts.b.epmismatch = 1;
  101402. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  101403. +
  101404. + return 1;
  101405. +}
  101406. +
  101407. +/**
  101408. + * This interrupt is valid only in DMA mode. This interrupt indicates that the
  101409. + * core has stopped fetching data for IN endpoints due to the unavailability of
  101410. + * TxFIFO space or Request Queue space. This interrupt is used by the
  101411. + * application for an endpoint mismatch algorithm.
  101412. + *
  101413. + * @param pcd The PCD
  101414. + */
  101415. +int32_t dwc_otg_pcd_handle_ep_fetsusp_intr(dwc_otg_pcd_t * pcd)
  101416. +{
  101417. + gintsts_data_t gintsts;
  101418. + gintmsk_data_t gintmsk_data;
  101419. + dctl_data_t dctl;
  101420. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  101421. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  101422. +
  101423. + /* Clear the global non-periodic IN NAK handshake */
  101424. + dctl.d32 = 0;
  101425. + dctl.b.cgnpinnak = 1;
  101426. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  101427. +
  101428. + /* Mask GINTSTS.FETSUSP interrupt */
  101429. + gintmsk_data.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  101430. + gintmsk_data.b.fetsusp = 0;
  101431. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_data.d32);
  101432. +
  101433. + /* Clear interrupt */
  101434. + gintsts.d32 = 0;
  101435. + gintsts.b.fetsusp = 1;
  101436. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  101437. +
  101438. + return 1;
  101439. +}
  101440. +/**
  101441. + * This funcion stalls EP0.
  101442. + */
  101443. +static inline void ep0_do_stall(dwc_otg_pcd_t * pcd, const int err_val)
  101444. +{
  101445. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  101446. + usb_device_request_t *ctrl = &pcd->setup_pkt->req;
  101447. + DWC_WARN("req %02x.%02x protocol STALL; err %d\n",
  101448. + ctrl->bmRequestType, ctrl->bRequest, err_val);
  101449. +
  101450. + ep0->dwc_ep.is_in = 1;
  101451. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep0->dwc_ep);
  101452. + pcd->ep0.stopped = 1;
  101453. + pcd->ep0state = EP0_IDLE;
  101454. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  101455. +}
  101456. +
  101457. +/**
  101458. + * This functions delegates the setup command to the gadget driver.
  101459. + */
  101460. +static inline void do_gadget_setup(dwc_otg_pcd_t * pcd,
  101461. + usb_device_request_t * ctrl)
  101462. +{
  101463. + int ret = 0;
  101464. + DWC_SPINUNLOCK(pcd->lock);
  101465. + ret = pcd->fops->setup(pcd, (uint8_t *) ctrl);
  101466. + DWC_SPINLOCK(pcd->lock);
  101467. + if (ret < 0) {
  101468. + ep0_do_stall(pcd, ret);
  101469. + }
  101470. +
  101471. + /** @todo This is a g_file_storage gadget driver specific
  101472. + * workaround: a DELAYED_STATUS result from the fsg_setup
  101473. + * routine will result in the gadget queueing a EP0 IN status
  101474. + * phase for a two-stage control transfer. Exactly the same as
  101475. + * a SET_CONFIGURATION/SET_INTERFACE except that this is a class
  101476. + * specific request. Need a generic way to know when the gadget
  101477. + * driver will queue the status phase. Can we assume when we
  101478. + * call the gadget driver setup() function that it will always
  101479. + * queue and require the following flag? Need to look into
  101480. + * this.
  101481. + */
  101482. +
  101483. + if (ret == 256 + 999) {
  101484. + pcd->request_config = 1;
  101485. + }
  101486. +}
  101487. +
  101488. +#ifdef DWC_UTE_CFI
  101489. +/**
  101490. + * This functions delegates the CFI setup commands to the gadget driver.
  101491. + * This function will return a negative value to indicate a failure.
  101492. + */
  101493. +static inline int cfi_gadget_setup(dwc_otg_pcd_t * pcd,
  101494. + struct cfi_usb_ctrlrequest *ctrl_req)
  101495. +{
  101496. + int ret = 0;
  101497. +
  101498. + if (pcd->fops && pcd->fops->cfi_setup) {
  101499. + DWC_SPINUNLOCK(pcd->lock);
  101500. + ret = pcd->fops->cfi_setup(pcd, ctrl_req);
  101501. + DWC_SPINLOCK(pcd->lock);
  101502. + if (ret < 0) {
  101503. + ep0_do_stall(pcd, ret);
  101504. + return ret;
  101505. + }
  101506. + }
  101507. +
  101508. + return ret;
  101509. +}
  101510. +#endif
  101511. +
  101512. +/**
  101513. + * This function starts the Zero-Length Packet for the IN status phase
  101514. + * of a 2 stage control transfer.
  101515. + */
  101516. +static inline void do_setup_in_status_phase(dwc_otg_pcd_t * pcd)
  101517. +{
  101518. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  101519. + if (pcd->ep0state == EP0_STALL) {
  101520. + return;
  101521. + }
  101522. +
  101523. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  101524. +
  101525. + /* Prepare for more SETUP Packets */
  101526. + DWC_DEBUGPL(DBG_PCD, "EP0 IN ZLP\n");
  101527. + if ((GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a)
  101528. + && (pcd->core_if->dma_desc_enable)
  101529. + && (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len)) {
  101530. + DWC_DEBUGPL(DBG_PCDV,
  101531. + "Data terminated wait next packet in out_desc_addr\n");
  101532. + pcd->backup_buf = phys_to_virt(ep0->dwc_ep.dma_addr);
  101533. + pcd->data_terminated = 1;
  101534. + }
  101535. + ep0->dwc_ep.xfer_len = 0;
  101536. + ep0->dwc_ep.xfer_count = 0;
  101537. + ep0->dwc_ep.is_in = 1;
  101538. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  101539. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  101540. +
  101541. + /* Prepare for more SETUP Packets */
  101542. + //ep0_out_start(GET_CORE_IF(pcd), pcd);
  101543. +}
  101544. +
  101545. +/**
  101546. + * This function starts the Zero-Length Packet for the OUT status phase
  101547. + * of a 2 stage control transfer.
  101548. + */
  101549. +static inline void do_setup_out_status_phase(dwc_otg_pcd_t * pcd)
  101550. +{
  101551. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  101552. + if (pcd->ep0state == EP0_STALL) {
  101553. + DWC_DEBUGPL(DBG_PCD, "EP0 STALLED\n");
  101554. + return;
  101555. + }
  101556. + pcd->ep0state = EP0_OUT_STATUS_PHASE;
  101557. +
  101558. + DWC_DEBUGPL(DBG_PCD, "EP0 OUT ZLP\n");
  101559. + ep0->dwc_ep.xfer_len = 0;
  101560. + ep0->dwc_ep.xfer_count = 0;
  101561. + ep0->dwc_ep.is_in = 0;
  101562. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  101563. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  101564. +
  101565. + /* Prepare for more SETUP Packets */
  101566. + if (GET_CORE_IF(pcd)->dma_enable == 0) {
  101567. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  101568. + }
  101569. +}
  101570. +
  101571. +/**
  101572. + * Clear the EP halt (STALL) and if pending requests start the
  101573. + * transfer.
  101574. + */
  101575. +static inline void pcd_clear_halt(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  101576. +{
  101577. + if (ep->dwc_ep.stall_clear_flag == 0)
  101578. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  101579. +
  101580. + /* Reactive the EP */
  101581. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  101582. + if (ep->stopped) {
  101583. + ep->stopped = 0;
  101584. + /* If there is a request in the EP queue start it */
  101585. +
  101586. + /** @todo FIXME: this causes an EP mismatch in DMA mode.
  101587. + * epmismatch not yet implemented. */
  101588. +
  101589. + /*
  101590. + * Above fixme is solved by implmenting a tasklet to call the
  101591. + * start_next_request(), outside of interrupt context at some
  101592. + * time after the current time, after a clear-halt setup packet.
  101593. + * Still need to implement ep mismatch in the future if a gadget
  101594. + * ever uses more than one endpoint at once
  101595. + */
  101596. + ep->queue_sof = 1;
  101597. + DWC_TASK_SCHEDULE(pcd->start_xfer_tasklet);
  101598. + }
  101599. + /* Start Control Status Phase */
  101600. + do_setup_in_status_phase(pcd);
  101601. +}
  101602. +
  101603. +/**
  101604. + * This function is called when the SET_FEATURE TEST_MODE Setup packet
  101605. + * is sent from the host. The Device Control register is written with
  101606. + * the Test Mode bits set to the specified Test Mode. This is done as
  101607. + * a tasklet so that the "Status" phase of the control transfer
  101608. + * completes before transmitting the TEST packets.
  101609. + *
  101610. + * @todo This has not been tested since the tasklet struct was put
  101611. + * into the PCD struct!
  101612. + *
  101613. + */
  101614. +void do_test_mode(void *data)
  101615. +{
  101616. + dctl_data_t dctl;
  101617. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  101618. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  101619. + int test_mode = pcd->test_mode;
  101620. +
  101621. +// DWC_WARN("%s() has not been tested since being rewritten!\n", __func__);
  101622. +
  101623. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  101624. + switch (test_mode) {
  101625. + case 1: // TEST_J
  101626. + dctl.b.tstctl = 1;
  101627. + break;
  101628. +
  101629. + case 2: // TEST_K
  101630. + dctl.b.tstctl = 2;
  101631. + break;
  101632. +
  101633. + case 3: // TEST_SE0_NAK
  101634. + dctl.b.tstctl = 3;
  101635. + break;
  101636. +
  101637. + case 4: // TEST_PACKET
  101638. + dctl.b.tstctl = 4;
  101639. + break;
  101640. +
  101641. + case 5: // TEST_FORCE_ENABLE
  101642. + dctl.b.tstctl = 5;
  101643. + break;
  101644. + }
  101645. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  101646. +}
  101647. +
  101648. +/**
  101649. + * This function process the GET_STATUS Setup Commands.
  101650. + */
  101651. +static inline void do_get_status(dwc_otg_pcd_t * pcd)
  101652. +{
  101653. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  101654. + dwc_otg_pcd_ep_t *ep;
  101655. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  101656. + uint16_t *status = pcd->status_buf;
  101657. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  101658. +
  101659. +#ifdef DEBUG_EP0
  101660. + DWC_DEBUGPL(DBG_PCD,
  101661. + "GET_STATUS %02x.%02x v%04x i%04x l%04x\n",
  101662. + ctrl.bmRequestType, ctrl.bRequest,
  101663. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  101664. + UGETW(ctrl.wLength));
  101665. +#endif
  101666. +
  101667. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  101668. + case UT_DEVICE:
  101669. + if(UGETW(ctrl.wIndex) == 0xF000) { /* OTG Status selector */
  101670. + DWC_PRINTF("wIndex - %d\n", UGETW(ctrl.wIndex));
  101671. + DWC_PRINTF("OTG VERSION - %d\n", core_if->otg_ver);
  101672. + DWC_PRINTF("OTG CAP - %d, %d\n",
  101673. + core_if->core_params->otg_cap,
  101674. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  101675. + if (core_if->otg_ver == 1
  101676. + && core_if->core_params->otg_cap ==
  101677. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  101678. + uint8_t *otgsts = (uint8_t*)pcd->status_buf;
  101679. + *otgsts = (core_if->otg_sts & 0x1);
  101680. + pcd->ep0_pending = 1;
  101681. + ep0->dwc_ep.start_xfer_buff =
  101682. + (uint8_t *) otgsts;
  101683. + ep0->dwc_ep.xfer_buff = (uint8_t *) otgsts;
  101684. + ep0->dwc_ep.dma_addr =
  101685. + pcd->status_buf_dma_handle;
  101686. + ep0->dwc_ep.xfer_len = 1;
  101687. + ep0->dwc_ep.xfer_count = 0;
  101688. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  101689. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  101690. + &ep0->dwc_ep);
  101691. + return;
  101692. + } else {
  101693. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  101694. + return;
  101695. + }
  101696. + break;
  101697. + } else {
  101698. + *status = 0x1; /* Self powered */
  101699. + *status |= pcd->remote_wakeup_enable << 1;
  101700. + break;
  101701. + }
  101702. + case UT_INTERFACE:
  101703. + *status = 0;
  101704. + break;
  101705. +
  101706. + case UT_ENDPOINT:
  101707. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  101708. + if (ep == 0 || UGETW(ctrl.wLength) > 2) {
  101709. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  101710. + return;
  101711. + }
  101712. + /** @todo check for EP stall */
  101713. + *status = ep->stopped;
  101714. + break;
  101715. + }
  101716. + pcd->ep0_pending = 1;
  101717. + ep0->dwc_ep.start_xfer_buff = (uint8_t *) status;
  101718. + ep0->dwc_ep.xfer_buff = (uint8_t *) status;
  101719. + ep0->dwc_ep.dma_addr = pcd->status_buf_dma_handle;
  101720. + ep0->dwc_ep.xfer_len = 2;
  101721. + ep0->dwc_ep.xfer_count = 0;
  101722. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  101723. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  101724. +}
  101725. +
  101726. +/**
  101727. + * This function process the SET_FEATURE Setup Commands.
  101728. + */
  101729. +static inline void do_set_feature(dwc_otg_pcd_t * pcd)
  101730. +{
  101731. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  101732. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  101733. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  101734. + dwc_otg_pcd_ep_t *ep = 0;
  101735. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  101736. + gotgctl_data_t gotgctl = {.d32 = 0 };
  101737. +
  101738. + DWC_DEBUGPL(DBG_PCD, "SET_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  101739. + ctrl.bmRequestType, ctrl.bRequest,
  101740. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  101741. + UGETW(ctrl.wLength));
  101742. + DWC_DEBUGPL(DBG_PCD, "otg_cap=%d\n", otg_cap_param);
  101743. +
  101744. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  101745. + case UT_DEVICE:
  101746. + switch (UGETW(ctrl.wValue)) {
  101747. + case UF_DEVICE_REMOTE_WAKEUP:
  101748. + pcd->remote_wakeup_enable = 1;
  101749. + break;
  101750. +
  101751. + case UF_TEST_MODE:
  101752. + /* Setup the Test Mode tasklet to do the Test
  101753. + * Packet generation after the SETUP Status
  101754. + * phase has completed. */
  101755. +
  101756. + /** @todo This has not been tested since the
  101757. + * tasklet struct was put into the PCD
  101758. + * struct! */
  101759. + pcd->test_mode = UGETW(ctrl.wIndex) >> 8;
  101760. + DWC_TASK_SCHEDULE(pcd->test_mode_tasklet);
  101761. + break;
  101762. +
  101763. + case UF_DEVICE_B_HNP_ENABLE:
  101764. + DWC_DEBUGPL(DBG_PCDV,
  101765. + "SET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
  101766. +
  101767. + /* dev may initiate HNP */
  101768. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  101769. + pcd->b_hnp_enable = 1;
  101770. + dwc_otg_pcd_update_otg(pcd, 0);
  101771. + DWC_DEBUGPL(DBG_PCD, "Request B HNP\n");
  101772. + /**@todo Is the gotgctl.devhnpen cleared
  101773. + * by a USB Reset? */
  101774. + gotgctl.b.devhnpen = 1;
  101775. + gotgctl.b.hnpreq = 1;
  101776. + DWC_WRITE_REG32(&global_regs->gotgctl,
  101777. + gotgctl.d32);
  101778. + } else {
  101779. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  101780. + return;
  101781. + }
  101782. + break;
  101783. +
  101784. + case UF_DEVICE_A_HNP_SUPPORT:
  101785. + /* RH port supports HNP */
  101786. + DWC_DEBUGPL(DBG_PCDV,
  101787. + "SET_FEATURE: USB_DEVICE_A_HNP_SUPPORT\n");
  101788. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  101789. + pcd->a_hnp_support = 1;
  101790. + dwc_otg_pcd_update_otg(pcd, 0);
  101791. + } else {
  101792. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  101793. + return;
  101794. + }
  101795. + break;
  101796. +
  101797. + case UF_DEVICE_A_ALT_HNP_SUPPORT:
  101798. + /* other RH port does */
  101799. + DWC_DEBUGPL(DBG_PCDV,
  101800. + "SET_FEATURE: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
  101801. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  101802. + pcd->a_alt_hnp_support = 1;
  101803. + dwc_otg_pcd_update_otg(pcd, 0);
  101804. + } else {
  101805. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  101806. + return;
  101807. + }
  101808. + break;
  101809. +
  101810. + default:
  101811. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  101812. + return;
  101813. +
  101814. + }
  101815. + do_setup_in_status_phase(pcd);
  101816. + break;
  101817. +
  101818. + case UT_INTERFACE:
  101819. + do_gadget_setup(pcd, &ctrl);
  101820. + break;
  101821. +
  101822. + case UT_ENDPOINT:
  101823. + if (UGETW(ctrl.wValue) == UF_ENDPOINT_HALT) {
  101824. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  101825. + if (ep == 0) {
  101826. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  101827. + return;
  101828. + }
  101829. + ep->stopped = 1;
  101830. + dwc_otg_ep_set_stall(core_if, &ep->dwc_ep);
  101831. + }
  101832. + do_setup_in_status_phase(pcd);
  101833. + break;
  101834. + }
  101835. +}
  101836. +
  101837. +/**
  101838. + * This function process the CLEAR_FEATURE Setup Commands.
  101839. + */
  101840. +static inline void do_clear_feature(dwc_otg_pcd_t * pcd)
  101841. +{
  101842. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  101843. + dwc_otg_pcd_ep_t *ep = 0;
  101844. +
  101845. + DWC_DEBUGPL(DBG_PCD,
  101846. + "CLEAR_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  101847. + ctrl.bmRequestType, ctrl.bRequest,
  101848. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  101849. + UGETW(ctrl.wLength));
  101850. +
  101851. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  101852. + case UT_DEVICE:
  101853. + switch (UGETW(ctrl.wValue)) {
  101854. + case UF_DEVICE_REMOTE_WAKEUP:
  101855. + pcd->remote_wakeup_enable = 0;
  101856. + break;
  101857. +
  101858. + case UF_TEST_MODE:
  101859. + /** @todo Add CLEAR_FEATURE for TEST modes. */
  101860. + break;
  101861. +
  101862. + default:
  101863. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  101864. + return;
  101865. + }
  101866. + do_setup_in_status_phase(pcd);
  101867. + break;
  101868. +
  101869. + case UT_ENDPOINT:
  101870. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  101871. + if (ep == 0) {
  101872. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  101873. + return;
  101874. + }
  101875. +
  101876. + pcd_clear_halt(pcd, ep);
  101877. +
  101878. + break;
  101879. + }
  101880. +}
  101881. +
  101882. +/**
  101883. + * This function process the SET_ADDRESS Setup Commands.
  101884. + */
  101885. +static inline void do_set_address(dwc_otg_pcd_t * pcd)
  101886. +{
  101887. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  101888. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  101889. +
  101890. + if (ctrl.bmRequestType == UT_DEVICE) {
  101891. + dcfg_data_t dcfg = {.d32 = 0 };
  101892. +
  101893. +#ifdef DEBUG_EP0
  101894. +// DWC_DEBUGPL(DBG_PCDV, "SET_ADDRESS:%d\n", ctrl.wValue);
  101895. +#endif
  101896. + dcfg.b.devaddr = UGETW(ctrl.wValue);
  101897. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dcfg, 0, dcfg.d32);
  101898. + do_setup_in_status_phase(pcd);
  101899. + }
  101900. +}
  101901. +
  101902. +/**
  101903. + * This function processes SETUP commands. In Linux, the USB Command
  101904. + * processing is done in two places - the first being the PCD and the
  101905. + * second in the Gadget Driver (for example, the File-Backed Storage
  101906. + * Gadget Driver).
  101907. + *
  101908. + * <table>
  101909. + * <tr><td>Command </td><td>Driver </td><td>Description</td></tr>
  101910. + *
  101911. + * <tr><td>GET_STATUS </td><td>PCD </td><td>Command is processed as
  101912. + * defined in chapter 9 of the USB 2.0 Specification chapter 9
  101913. + * </td></tr>
  101914. + *
  101915. + * <tr><td>CLEAR_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  101916. + * requests are the ENDPOINT_HALT feature is procesed, all others the
  101917. + * interface requests are ignored.</td></tr>
  101918. + *
  101919. + * <tr><td>SET_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  101920. + * requests are processed by the PCD. Interface requests are passed
  101921. + * to the Gadget Driver.</td></tr>
  101922. + *
  101923. + * <tr><td>SET_ADDRESS </td><td>PCD </td><td>Program the DCFG reg,
  101924. + * with device address received </td></tr>
  101925. + *
  101926. + * <tr><td>GET_DESCRIPTOR </td><td>Gadget Driver </td><td>Return the
  101927. + * requested descriptor</td></tr>
  101928. + *
  101929. + * <tr><td>SET_DESCRIPTOR </td><td>Gadget Driver </td><td>Optional -
  101930. + * not implemented by any of the existing Gadget Drivers.</td></tr>
  101931. + *
  101932. + * <tr><td>SET_CONFIGURATION </td><td>Gadget Driver </td><td>Disable
  101933. + * all EPs and enable EPs for new configuration.</td></tr>
  101934. + *
  101935. + * <tr><td>GET_CONFIGURATION </td><td>Gadget Driver </td><td>Return
  101936. + * the current configuration</td></tr>
  101937. + *
  101938. + * <tr><td>SET_INTERFACE </td><td>Gadget Driver </td><td>Disable all
  101939. + * EPs and enable EPs for new configuration.</td></tr>
  101940. + *
  101941. + * <tr><td>GET_INTERFACE </td><td>Gadget Driver </td><td>Return the
  101942. + * current interface.</td></tr>
  101943. + *
  101944. + * <tr><td>SYNC_FRAME </td><td>PCD </td><td>Display debug
  101945. + * message.</td></tr>
  101946. + * </table>
  101947. + *
  101948. + * When the SETUP Phase Done interrupt occurs, the PCD SETUP commands are
  101949. + * processed by pcd_setup. Calling the Function Driver's setup function from
  101950. + * pcd_setup processes the gadget SETUP commands.
  101951. + */
  101952. +static inline void pcd_setup(dwc_otg_pcd_t * pcd)
  101953. +{
  101954. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  101955. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  101956. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  101957. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  101958. +
  101959. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  101960. +
  101961. +#ifdef DWC_UTE_CFI
  101962. + int retval = 0;
  101963. + struct cfi_usb_ctrlrequest cfi_req;
  101964. +#endif
  101965. +
  101966. + doeptsize0.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doeptsiz);
  101967. +
  101968. + /** In BDMA more then 1 setup packet is not supported till 3.00a */
  101969. + if (core_if->dma_enable && core_if->dma_desc_enable == 0
  101970. + && (doeptsize0.b.supcnt < 2)
  101971. + && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  101972. + DWC_ERROR
  101973. + ("\n\n----------- CANNOT handle > 1 setup packet in DMA mode\n\n");
  101974. + }
  101975. + if ((core_if->snpsid >= OTG_CORE_REV_3_00a)
  101976. + && (core_if->dma_enable == 1) && (core_if->dma_desc_enable == 0)) {
  101977. + ctrl =
  101978. + (pcd->setup_pkt +
  101979. + (3 - doeptsize0.b.supcnt - 1 +
  101980. + ep0->dwc_ep.stp_rollover))->req;
  101981. + }
  101982. +#ifdef DEBUG_EP0
  101983. + DWC_DEBUGPL(DBG_PCD, "SETUP %02x.%02x v%04x i%04x l%04x\n",
  101984. + ctrl.bmRequestType, ctrl.bRequest,
  101985. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  101986. + UGETW(ctrl.wLength));
  101987. +#endif
  101988. +
  101989. + /* Clean up the request queue */
  101990. + dwc_otg_request_nuke(ep0);
  101991. + ep0->stopped = 0;
  101992. +
  101993. + if (ctrl.bmRequestType & UE_DIR_IN) {
  101994. + ep0->dwc_ep.is_in = 1;
  101995. + pcd->ep0state = EP0_IN_DATA_PHASE;
  101996. + } else {
  101997. + ep0->dwc_ep.is_in = 0;
  101998. + pcd->ep0state = EP0_OUT_DATA_PHASE;
  101999. + }
  102000. +
  102001. + if (UGETW(ctrl.wLength) == 0) {
  102002. + ep0->dwc_ep.is_in = 1;
  102003. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  102004. + }
  102005. +
  102006. + if (UT_GET_TYPE(ctrl.bmRequestType) != UT_STANDARD) {
  102007. +
  102008. +#ifdef DWC_UTE_CFI
  102009. + DWC_MEMCPY(&cfi_req, &ctrl, sizeof(usb_device_request_t));
  102010. +
  102011. + //printk(KERN_ALERT "CFI: req_type=0x%02x; req=0x%02x\n",
  102012. + ctrl.bRequestType, ctrl.bRequest);
  102013. + if (UT_GET_TYPE(cfi_req.bRequestType) == UT_VENDOR) {
  102014. + if (cfi_req.bRequest > 0xB0 && cfi_req.bRequest < 0xBF) {
  102015. + retval = cfi_setup(pcd, &cfi_req);
  102016. + if (retval < 0) {
  102017. + ep0_do_stall(pcd, retval);
  102018. + pcd->ep0_pending = 0;
  102019. + return;
  102020. + }
  102021. +
  102022. + /* if need gadget setup then call it and check the retval */
  102023. + if (pcd->cfi->need_gadget_att) {
  102024. + retval =
  102025. + cfi_gadget_setup(pcd,
  102026. + &pcd->
  102027. + cfi->ctrl_req);
  102028. + if (retval < 0) {
  102029. + pcd->ep0_pending = 0;
  102030. + return;
  102031. + }
  102032. + }
  102033. +
  102034. + if (pcd->cfi->need_status_in_complete) {
  102035. + do_setup_in_status_phase(pcd);
  102036. + }
  102037. + return;
  102038. + }
  102039. + }
  102040. +#endif
  102041. +
  102042. + /* handle non-standard (class/vendor) requests in the gadget driver */
  102043. + do_gadget_setup(pcd, &ctrl);
  102044. + return;
  102045. + }
  102046. +
  102047. + /** @todo NGS: Handle bad setup packet? */
  102048. +
  102049. +///////////////////////////////////////////
  102050. +//// --- Standard Request handling --- ////
  102051. +
  102052. + switch (ctrl.bRequest) {
  102053. + case UR_GET_STATUS:
  102054. + do_get_status(pcd);
  102055. + break;
  102056. +
  102057. + case UR_CLEAR_FEATURE:
  102058. + do_clear_feature(pcd);
  102059. + break;
  102060. +
  102061. + case UR_SET_FEATURE:
  102062. + do_set_feature(pcd);
  102063. + break;
  102064. +
  102065. + case UR_SET_ADDRESS:
  102066. + do_set_address(pcd);
  102067. + break;
  102068. +
  102069. + case UR_SET_INTERFACE:
  102070. + case UR_SET_CONFIG:
  102071. +// _pcd->request_config = 1; /* Configuration changed */
  102072. + do_gadget_setup(pcd, &ctrl);
  102073. + break;
  102074. +
  102075. + case UR_SYNCH_FRAME:
  102076. + do_gadget_setup(pcd, &ctrl);
  102077. + break;
  102078. +
  102079. + default:
  102080. + /* Call the Gadget Driver's setup functions */
  102081. + do_gadget_setup(pcd, &ctrl);
  102082. + break;
  102083. + }
  102084. +}
  102085. +
  102086. +/**
  102087. + * This function completes the ep0 control transfer.
  102088. + */
  102089. +static int32_t ep0_complete_request(dwc_otg_pcd_ep_t * ep)
  102090. +{
  102091. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  102092. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  102093. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  102094. + dev_if->in_ep_regs[ep->dwc_ep.num];
  102095. +#ifdef DEBUG_EP0
  102096. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  102097. + dev_if->out_ep_regs[ep->dwc_ep.num];
  102098. +#endif
  102099. + deptsiz0_data_t deptsiz;
  102100. + dev_dma_desc_sts_t desc_sts;
  102101. + dwc_otg_pcd_request_t *req;
  102102. + int is_last = 0;
  102103. + dwc_otg_pcd_t *pcd = ep->pcd;
  102104. +
  102105. +#ifdef DWC_UTE_CFI
  102106. + struct cfi_usb_ctrlrequest *ctrlreq;
  102107. + int retval = -DWC_E_NOT_SUPPORTED;
  102108. +#endif
  102109. +
  102110. + desc_sts.b.bytes = 0;
  102111. +
  102112. + if (pcd->ep0_pending && DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  102113. + if (ep->dwc_ep.is_in) {
  102114. +#ifdef DEBUG_EP0
  102115. + DWC_DEBUGPL(DBG_PCDV, "Do setup OUT status phase\n");
  102116. +#endif
  102117. + do_setup_out_status_phase(pcd);
  102118. + } else {
  102119. +#ifdef DEBUG_EP0
  102120. + DWC_DEBUGPL(DBG_PCDV, "Do setup IN status phase\n");
  102121. +#endif
  102122. +
  102123. +#ifdef DWC_UTE_CFI
  102124. + ctrlreq = &pcd->cfi->ctrl_req;
  102125. +
  102126. + if (UT_GET_TYPE(ctrlreq->bRequestType) == UT_VENDOR) {
  102127. + if (ctrlreq->bRequest > 0xB0
  102128. + && ctrlreq->bRequest < 0xBF) {
  102129. +
  102130. + /* Return if the PCD failed to handle the request */
  102131. + if ((retval =
  102132. + pcd->cfi->ops.
  102133. + ctrl_write_complete(pcd->cfi,
  102134. + pcd)) < 0) {
  102135. + CFI_INFO
  102136. + ("ERROR setting a new value in the PCD(%d)\n",
  102137. + retval);
  102138. + ep0_do_stall(pcd, retval);
  102139. + pcd->ep0_pending = 0;
  102140. + return 0;
  102141. + }
  102142. +
  102143. + /* If the gadget needs to be notified on the request */
  102144. + if (pcd->cfi->need_gadget_att == 1) {
  102145. + //retval = do_gadget_setup(pcd, &pcd->cfi->ctrl_req);
  102146. + retval =
  102147. + cfi_gadget_setup(pcd,
  102148. + &pcd->cfi->
  102149. + ctrl_req);
  102150. +
  102151. + /* Return from the function if the gadget failed to process
  102152. + * the request properly - this should never happen !!!
  102153. + */
  102154. + if (retval < 0) {
  102155. + CFI_INFO
  102156. + ("ERROR setting a new value in the gadget(%d)\n",
  102157. + retval);
  102158. + pcd->ep0_pending = 0;
  102159. + return 0;
  102160. + }
  102161. + }
  102162. +
  102163. + CFI_INFO("%s: RETVAL=%d\n", __func__,
  102164. + retval);
  102165. + /* If we hit here then the PCD and the gadget has properly
  102166. + * handled the request - so send the ZLP IN to the host.
  102167. + */
  102168. + /* @todo: MAS - decide whether we need to start the setup
  102169. + * stage based on the need_setup value of the cfi object
  102170. + */
  102171. + do_setup_in_status_phase(pcd);
  102172. + pcd->ep0_pending = 0;
  102173. + return 1;
  102174. + }
  102175. + }
  102176. +#endif
  102177. +
  102178. + do_setup_in_status_phase(pcd);
  102179. + }
  102180. + pcd->ep0_pending = 0;
  102181. + return 1;
  102182. + }
  102183. +
  102184. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  102185. + return 0;
  102186. + }
  102187. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  102188. +
  102189. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE
  102190. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  102191. + is_last = 1;
  102192. + } else if (ep->dwc_ep.is_in) {
  102193. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  102194. + if (core_if->dma_desc_enable != 0)
  102195. + desc_sts = dev_if->in_desc_addr->status;
  102196. +#ifdef DEBUG_EP0
  102197. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xfersize=%d pktcnt=%d\n",
  102198. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  102199. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  102200. +#endif
  102201. +
  102202. + if (((core_if->dma_desc_enable == 0)
  102203. + && (deptsiz.b.xfersize == 0))
  102204. + || ((core_if->dma_desc_enable != 0)
  102205. + && (desc_sts.b.bytes == 0))) {
  102206. + req->actual = ep->dwc_ep.xfer_count;
  102207. + /* Is a Zero Len Packet needed? */
  102208. + if (req->sent_zlp) {
  102209. +#ifdef DEBUG_EP0
  102210. + DWC_DEBUGPL(DBG_PCD, "Setup Rx ZLP\n");
  102211. +#endif
  102212. + req->sent_zlp = 0;
  102213. + }
  102214. + do_setup_out_status_phase(pcd);
  102215. + }
  102216. + } else {
  102217. + /* ep0-OUT */
  102218. +#ifdef DEBUG_EP0
  102219. + deptsiz.d32 = DWC_READ_REG32(&out_ep_regs->doeptsiz);
  102220. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xsize=%d pktcnt=%d\n",
  102221. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  102222. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  102223. +#endif
  102224. + req->actual = ep->dwc_ep.xfer_count;
  102225. +
  102226. + /* Is a Zero Len Packet needed? */
  102227. + if (req->sent_zlp) {
  102228. +#ifdef DEBUG_EP0
  102229. + DWC_DEBUGPL(DBG_PCDV, "Setup Tx ZLP\n");
  102230. +#endif
  102231. + req->sent_zlp = 0;
  102232. + }
  102233. + /* For older cores do setup in status phase in Slave/BDMA modes,
  102234. + * starting from 3.00 do that only in slave, and for DMA modes
  102235. + * just re-enable ep 0 OUT here*/
  102236. + if (core_if->dma_enable == 0
  102237. + || (core_if->dma_desc_enable == 0
  102238. + && core_if->snpsid <= OTG_CORE_REV_2_94a)) {
  102239. + do_setup_in_status_phase(pcd);
  102240. + } else if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  102241. + DWC_DEBUGPL(DBG_PCDV,
  102242. + "Enable out ep before in status phase\n");
  102243. + ep0_out_start(core_if, pcd);
  102244. + }
  102245. + }
  102246. +
  102247. + /* Complete the request */
  102248. + if (is_last) {
  102249. + dwc_otg_request_done(ep, req, 0);
  102250. + ep->dwc_ep.start_xfer_buff = 0;
  102251. + ep->dwc_ep.xfer_buff = 0;
  102252. + ep->dwc_ep.xfer_len = 0;
  102253. + return 1;
  102254. + }
  102255. + return 0;
  102256. +}
  102257. +
  102258. +#ifdef DWC_UTE_CFI
  102259. +/**
  102260. + * This function calculates traverses all the CFI DMA descriptors and
  102261. + * and accumulates the bytes that are left to be transfered.
  102262. + *
  102263. + * @return The total bytes left to transfered, or a negative value as failure
  102264. + */
  102265. +static inline int cfi_calc_desc_residue(dwc_otg_pcd_ep_t * ep)
  102266. +{
  102267. + int32_t ret = 0;
  102268. + int i;
  102269. + struct dwc_otg_dma_desc *ddesc = NULL;
  102270. + struct cfi_ep *cfiep;
  102271. +
  102272. + /* See if the pcd_ep has its respective cfi_ep mapped */
  102273. + cfiep = get_cfi_ep_by_pcd_ep(ep->pcd->cfi, ep);
  102274. + if (!cfiep) {
  102275. + CFI_INFO("%s: Failed to find ep\n", __func__);
  102276. + return -1;
  102277. + }
  102278. +
  102279. + ddesc = ep->dwc_ep.descs;
  102280. +
  102281. + for (i = 0; (i < cfiep->desc_count) && (i < MAX_DMA_DESCS_PER_EP); i++) {
  102282. +
  102283. +#if defined(PRINT_CFI_DMA_DESCS)
  102284. + print_desc(ddesc, ep->ep.name, i);
  102285. +#endif
  102286. + ret += ddesc->status.b.bytes;
  102287. + ddesc++;
  102288. + }
  102289. +
  102290. + if (ret)
  102291. + CFI_INFO("!!!!!!!!!! WARNING (%s) - residue=%d\n", __func__,
  102292. + ret);
  102293. +
  102294. + return ret;
  102295. +}
  102296. +#endif
  102297. +
  102298. +/**
  102299. + * This function completes the request for the EP. If there are
  102300. + * additional requests for the EP in the queue they will be started.
  102301. + */
  102302. +static void complete_ep(dwc_otg_pcd_ep_t * ep)
  102303. +{
  102304. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  102305. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  102306. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  102307. + dev_if->in_ep_regs[ep->dwc_ep.num];
  102308. + deptsiz_data_t deptsiz;
  102309. + dev_dma_desc_sts_t desc_sts;
  102310. + dwc_otg_pcd_request_t *req = 0;
  102311. + dwc_otg_dev_dma_desc_t *dma_desc;
  102312. + uint32_t byte_count = 0;
  102313. + int is_last = 0;
  102314. + int i;
  102315. +
  102316. + DWC_DEBUGPL(DBG_PCDV, "%s() %d-%s\n", __func__, ep->dwc_ep.num,
  102317. + (ep->dwc_ep.is_in ? "IN" : "OUT"));
  102318. +
  102319. + /* Get any pending requests */
  102320. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  102321. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  102322. + if (!req) {
  102323. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  102324. + return;
  102325. + }
  102326. + } else {
  102327. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  102328. + return;
  102329. + }
  102330. +
  102331. + DWC_DEBUGPL(DBG_PCD, "Requests %d\n", ep->pcd->request_pending);
  102332. +
  102333. + if (ep->dwc_ep.is_in) {
  102334. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  102335. +
  102336. + if (core_if->dma_enable) {
  102337. + if (core_if->dma_desc_enable == 0) {
  102338. + if (deptsiz.b.xfersize == 0
  102339. + && deptsiz.b.pktcnt == 0) {
  102340. + byte_count =
  102341. + ep->dwc_ep.xfer_len -
  102342. + ep->dwc_ep.xfer_count;
  102343. +
  102344. + ep->dwc_ep.xfer_buff += byte_count;
  102345. + ep->dwc_ep.dma_addr += byte_count;
  102346. + ep->dwc_ep.xfer_count += byte_count;
  102347. +
  102348. + DWC_DEBUGPL(DBG_PCDV,
  102349. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  102350. + ep->dwc_ep.num,
  102351. + (ep->dwc_ep.
  102352. + is_in ? "IN" : "OUT"),
  102353. + ep->dwc_ep.xfer_len,
  102354. + deptsiz.b.xfersize,
  102355. + deptsiz.b.pktcnt);
  102356. +
  102357. + if (ep->dwc_ep.xfer_len <
  102358. + ep->dwc_ep.total_len) {
  102359. + dwc_otg_ep_start_transfer
  102360. + (core_if, &ep->dwc_ep);
  102361. + } else if (ep->dwc_ep.sent_zlp) {
  102362. + /*
  102363. + * This fragment of code should initiate 0
  102364. + * length transfer in case if it is queued
  102365. + * a transfer with size divisible to EPs max
  102366. + * packet size and with usb_request zero field
  102367. + * is set, which means that after data is transfered,
  102368. + * it is also should be transfered
  102369. + * a 0 length packet at the end. For Slave and
  102370. + * Buffer DMA modes in this case SW has
  102371. + * to initiate 2 transfers one with transfer size,
  102372. + * and the second with 0 size. For Descriptor
  102373. + * DMA mode SW is able to initiate a transfer,
  102374. + * which will handle all the packets including
  102375. + * the last 0 length.
  102376. + */
  102377. + ep->dwc_ep.sent_zlp = 0;
  102378. + dwc_otg_ep_start_zl_transfer
  102379. + (core_if, &ep->dwc_ep);
  102380. + } else {
  102381. + is_last = 1;
  102382. + }
  102383. + } else {
  102384. + if (ep->dwc_ep.type ==
  102385. + DWC_OTG_EP_TYPE_ISOC) {
  102386. + req->actual = 0;
  102387. + dwc_otg_request_done(ep, req, 0);
  102388. +
  102389. + ep->dwc_ep.start_xfer_buff = 0;
  102390. + ep->dwc_ep.xfer_buff = 0;
  102391. + ep->dwc_ep.xfer_len = 0;
  102392. +
  102393. + /* If there is a request in the queue start it. */
  102394. + start_next_request(ep);
  102395. + } else
  102396. + DWC_WARN
  102397. + ("Incomplete transfer (%d - %s [siz=%d pkt=%d])\n",
  102398. + ep->dwc_ep.num,
  102399. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  102400. + deptsiz.b.xfersize,
  102401. + deptsiz.b.pktcnt);
  102402. + }
  102403. + } else {
  102404. + dma_desc = ep->dwc_ep.desc_addr;
  102405. + byte_count = 0;
  102406. + ep->dwc_ep.sent_zlp = 0;
  102407. +
  102408. +#ifdef DWC_UTE_CFI
  102409. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  102410. + ep->dwc_ep.buff_mode);
  102411. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  102412. + int residue;
  102413. +
  102414. + residue = cfi_calc_desc_residue(ep);
  102415. + if (residue < 0)
  102416. + return;
  102417. +
  102418. + byte_count = residue;
  102419. + } else {
  102420. +#endif
  102421. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  102422. + ++i) {
  102423. + desc_sts = dma_desc->status;
  102424. + byte_count += desc_sts.b.bytes;
  102425. + dma_desc++;
  102426. + }
  102427. +#ifdef DWC_UTE_CFI
  102428. + }
  102429. +#endif
  102430. + if (byte_count == 0) {
  102431. + ep->dwc_ep.xfer_count =
  102432. + ep->dwc_ep.total_len;
  102433. + is_last = 1;
  102434. + } else {
  102435. + DWC_WARN("Incomplete transfer\n");
  102436. + }
  102437. + }
  102438. + } else {
  102439. + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
  102440. + DWC_DEBUGPL(DBG_PCDV,
  102441. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  102442. + ep->dwc_ep.num,
  102443. + ep->dwc_ep.is_in ? "IN" : "OUT",
  102444. + ep->dwc_ep.xfer_len,
  102445. + deptsiz.b.xfersize,
  102446. + deptsiz.b.pktcnt);
  102447. +
  102448. + /* Check if the whole transfer was completed,
  102449. + * if no, setup transfer for next portion of data
  102450. + */
  102451. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  102452. + dwc_otg_ep_start_transfer(core_if,
  102453. + &ep->dwc_ep);
  102454. + } else if (ep->dwc_ep.sent_zlp) {
  102455. + /*
  102456. + * This fragment of code should initiate 0
  102457. + * length trasfer in case if it is queued
  102458. + * a trasfer with size divisible to EPs max
  102459. + * packet size and with usb_request zero field
  102460. + * is set, which means that after data is transfered,
  102461. + * it is also should be transfered
  102462. + * a 0 length packet at the end. For Slave and
  102463. + * Buffer DMA modes in this case SW has
  102464. + * to initiate 2 transfers one with transfer size,
  102465. + * and the second with 0 size. For Desriptor
  102466. + * DMA mode SW is able to initiate a transfer,
  102467. + * which will handle all the packets including
  102468. + * the last 0 legth.
  102469. + */
  102470. + ep->dwc_ep.sent_zlp = 0;
  102471. + dwc_otg_ep_start_zl_transfer(core_if,
  102472. + &ep->dwc_ep);
  102473. + } else {
  102474. + is_last = 1;
  102475. + }
  102476. + } else {
  102477. + DWC_WARN
  102478. + ("Incomplete transfer (%d-%s [siz=%d pkt=%d])\n",
  102479. + ep->dwc_ep.num,
  102480. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  102481. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  102482. + }
  102483. + }
  102484. + } else {
  102485. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  102486. + dev_if->out_ep_regs[ep->dwc_ep.num];
  102487. + desc_sts.d32 = 0;
  102488. + if (core_if->dma_enable) {
  102489. + if (core_if->dma_desc_enable) {
  102490. + dma_desc = ep->dwc_ep.desc_addr;
  102491. + byte_count = 0;
  102492. + ep->dwc_ep.sent_zlp = 0;
  102493. +
  102494. +#ifdef DWC_UTE_CFI
  102495. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  102496. + ep->dwc_ep.buff_mode);
  102497. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  102498. + int residue;
  102499. + residue = cfi_calc_desc_residue(ep);
  102500. + if (residue < 0)
  102501. + return;
  102502. + byte_count = residue;
  102503. + } else {
  102504. +#endif
  102505. +
  102506. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  102507. + ++i) {
  102508. + desc_sts = dma_desc->status;
  102509. + byte_count += desc_sts.b.bytes;
  102510. + dma_desc++;
  102511. + }
  102512. +
  102513. +#ifdef DWC_UTE_CFI
  102514. + }
  102515. +#endif
  102516. + /* Checking for interrupt Out transfers with not
  102517. + * dword aligned mps sizes
  102518. + */
  102519. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_INTR &&
  102520. + (ep->dwc_ep.maxpacket%4)) {
  102521. + ep->dwc_ep.xfer_count =
  102522. + ep->dwc_ep.total_len - byte_count;
  102523. + if ((ep->dwc_ep.xfer_len %
  102524. + ep->dwc_ep.maxpacket)
  102525. + && (ep->dwc_ep.xfer_len /
  102526. + ep->dwc_ep.maxpacket <
  102527. + MAX_DMA_DESC_CNT))
  102528. + ep->dwc_ep.xfer_len -=
  102529. + (ep->dwc_ep.desc_cnt -
  102530. + 1) * ep->dwc_ep.maxpacket +
  102531. + ep->dwc_ep.xfer_len %
  102532. + ep->dwc_ep.maxpacket;
  102533. + else
  102534. + ep->dwc_ep.xfer_len -=
  102535. + ep->dwc_ep.desc_cnt *
  102536. + ep->dwc_ep.maxpacket;
  102537. + if (ep->dwc_ep.xfer_len > 0) {
  102538. + dwc_otg_ep_start_transfer
  102539. + (core_if, &ep->dwc_ep);
  102540. + } else {
  102541. + is_last = 1;
  102542. + }
  102543. + } else {
  102544. + ep->dwc_ep.xfer_count =
  102545. + ep->dwc_ep.total_len - byte_count +
  102546. + ((4 -
  102547. + (ep->dwc_ep.
  102548. + total_len & 0x3)) & 0x3);
  102549. + is_last = 1;
  102550. + }
  102551. + } else {
  102552. + deptsiz.d32 = 0;
  102553. + deptsiz.d32 =
  102554. + DWC_READ_REG32(&out_ep_regs->doeptsiz);
  102555. +
  102556. + byte_count = (ep->dwc_ep.xfer_len -
  102557. + ep->dwc_ep.xfer_count -
  102558. + deptsiz.b.xfersize);
  102559. + ep->dwc_ep.xfer_buff += byte_count;
  102560. + ep->dwc_ep.dma_addr += byte_count;
  102561. + ep->dwc_ep.xfer_count += byte_count;
  102562. +
  102563. + /* Check if the whole transfer was completed,
  102564. + * if no, setup transfer for next portion of data
  102565. + */
  102566. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  102567. + dwc_otg_ep_start_transfer(core_if,
  102568. + &ep->dwc_ep);
  102569. + } else if (ep->dwc_ep.sent_zlp) {
  102570. + /*
  102571. + * This fragment of code should initiate 0
  102572. + * length trasfer in case if it is queued
  102573. + * a trasfer with size divisible to EPs max
  102574. + * packet size and with usb_request zero field
  102575. + * is set, which means that after data is transfered,
  102576. + * it is also should be transfered
  102577. + * a 0 length packet at the end. For Slave and
  102578. + * Buffer DMA modes in this case SW has
  102579. + * to initiate 2 transfers one with transfer size,
  102580. + * and the second with 0 size. For Desriptor
  102581. + * DMA mode SW is able to initiate a transfer,
  102582. + * which will handle all the packets including
  102583. + * the last 0 legth.
  102584. + */
  102585. + ep->dwc_ep.sent_zlp = 0;
  102586. + dwc_otg_ep_start_zl_transfer(core_if,
  102587. + &ep->dwc_ep);
  102588. + } else {
  102589. + is_last = 1;
  102590. + }
  102591. + }
  102592. + } else {
  102593. + /* Check if the whole transfer was completed,
  102594. + * if no, setup transfer for next portion of data
  102595. + */
  102596. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  102597. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  102598. + } else if (ep->dwc_ep.sent_zlp) {
  102599. + /*
  102600. + * This fragment of code should initiate 0
  102601. + * length transfer in case if it is queued
  102602. + * a transfer with size divisible to EPs max
  102603. + * packet size and with usb_request zero field
  102604. + * is set, which means that after data is transfered,
  102605. + * it is also should be transfered
  102606. + * a 0 length packet at the end. For Slave and
  102607. + * Buffer DMA modes in this case SW has
  102608. + * to initiate 2 transfers one with transfer size,
  102609. + * and the second with 0 size. For Descriptor
  102610. + * DMA mode SW is able to initiate a transfer,
  102611. + * which will handle all the packets including
  102612. + * the last 0 length.
  102613. + */
  102614. + ep->dwc_ep.sent_zlp = 0;
  102615. + dwc_otg_ep_start_zl_transfer(core_if,
  102616. + &ep->dwc_ep);
  102617. + } else {
  102618. + is_last = 1;
  102619. + }
  102620. + }
  102621. +
  102622. + DWC_DEBUGPL(DBG_PCDV,
  102623. + "addr %p, %d-%s len=%d cnt=%d xsize=%d pktcnt=%d\n",
  102624. + &out_ep_regs->doeptsiz, ep->dwc_ep.num,
  102625. + ep->dwc_ep.is_in ? "IN" : "OUT",
  102626. + ep->dwc_ep.xfer_len, ep->dwc_ep.xfer_count,
  102627. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  102628. + }
  102629. +
  102630. + /* Complete the request */
  102631. + if (is_last) {
  102632. +#ifdef DWC_UTE_CFI
  102633. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  102634. + req->actual = ep->dwc_ep.cfi_req_len - byte_count;
  102635. + } else {
  102636. +#endif
  102637. + req->actual = ep->dwc_ep.xfer_count;
  102638. +#ifdef DWC_UTE_CFI
  102639. + }
  102640. +#endif
  102641. + if (req->dw_align_buf) {
  102642. + if (!ep->dwc_ep.is_in) {
  102643. + dwc_memcpy(req->buf, req->dw_align_buf, req->length);
  102644. + }
  102645. + DWC_DMA_FREE(req->length, req->dw_align_buf,
  102646. + req->dw_align_buf_dma);
  102647. + }
  102648. +
  102649. + dwc_otg_request_done(ep, req, 0);
  102650. +
  102651. + ep->dwc_ep.start_xfer_buff = 0;
  102652. + ep->dwc_ep.xfer_buff = 0;
  102653. + ep->dwc_ep.xfer_len = 0;
  102654. +
  102655. + /* If there is a request in the queue start it. */
  102656. + start_next_request(ep);
  102657. + }
  102658. +}
  102659. +
  102660. +#ifdef DWC_EN_ISOC
  102661. +
  102662. +/**
  102663. + * This function BNA interrupt for Isochronous EPs
  102664. + *
  102665. + */
  102666. +static void dwc_otg_pcd_handle_iso_bna(dwc_otg_pcd_ep_t * ep)
  102667. +{
  102668. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  102669. + volatile uint32_t *addr;
  102670. + depctl_data_t depctl = {.d32 = 0 };
  102671. + dwc_otg_pcd_t *pcd = ep->pcd;
  102672. + dwc_otg_dev_dma_desc_t *dma_desc;
  102673. + int i;
  102674. +
  102675. + dma_desc =
  102676. + dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * (dwc_ep->proc_buf_num);
  102677. +
  102678. + if (dwc_ep->is_in) {
  102679. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  102680. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  102681. + sts.d32 = dma_desc->status.d32;
  102682. + sts.b_iso_in.bs = BS_HOST_READY;
  102683. + dma_desc->status.d32 = sts.d32;
  102684. + }
  102685. + } else {
  102686. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  102687. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  102688. + sts.d32 = dma_desc->status.d32;
  102689. + sts.b_iso_out.bs = BS_HOST_READY;
  102690. + dma_desc->status.d32 = sts.d32;
  102691. + }
  102692. + }
  102693. +
  102694. + if (dwc_ep->is_in == 0) {
  102695. + addr =
  102696. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->
  102697. + num]->doepctl;
  102698. + } else {
  102699. + addr =
  102700. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  102701. + }
  102702. + depctl.b.epena = 1;
  102703. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  102704. +}
  102705. +
  102706. +/**
  102707. + * This function sets latest iso packet information(non-PTI mode)
  102708. + *
  102709. + * @param core_if Programming view of DWC_otg controller.
  102710. + * @param ep The EP to start the transfer on.
  102711. + *
  102712. + */
  102713. +void set_current_pkt_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  102714. +{
  102715. + deptsiz_data_t deptsiz = {.d32 = 0 };
  102716. + dma_addr_t dma_addr;
  102717. + uint32_t offset;
  102718. +
  102719. + if (ep->proc_buf_num)
  102720. + dma_addr = ep->dma_addr1;
  102721. + else
  102722. + dma_addr = ep->dma_addr0;
  102723. +
  102724. + if (ep->is_in) {
  102725. + deptsiz.d32 =
  102726. + DWC_READ_REG32(&core_if->dev_if->
  102727. + in_ep_regs[ep->num]->dieptsiz);
  102728. + offset = ep->data_per_frame;
  102729. + } else {
  102730. + deptsiz.d32 =
  102731. + DWC_READ_REG32(&core_if->dev_if->
  102732. + out_ep_regs[ep->num]->doeptsiz);
  102733. + offset =
  102734. + ep->data_per_frame +
  102735. + (0x4 & (0x4 - (ep->data_per_frame & 0x3)));
  102736. + }
  102737. +
  102738. + if (!deptsiz.b.xfersize) {
  102739. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  102740. + ep->pkt_info[ep->cur_pkt].offset =
  102741. + ep->cur_pkt_dma_addr - dma_addr;
  102742. + ep->pkt_info[ep->cur_pkt].status = 0;
  102743. + } else {
  102744. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  102745. + ep->pkt_info[ep->cur_pkt].offset =
  102746. + ep->cur_pkt_dma_addr - dma_addr;
  102747. + ep->pkt_info[ep->cur_pkt].status = -DWC_E_NO_DATA;
  102748. + }
  102749. + ep->cur_pkt_addr += offset;
  102750. + ep->cur_pkt_dma_addr += offset;
  102751. + ep->cur_pkt++;
  102752. +}
  102753. +
  102754. +/**
  102755. + * This function sets latest iso packet information(DDMA mode)
  102756. + *
  102757. + * @param core_if Programming view of DWC_otg controller.
  102758. + * @param dwc_ep The EP to start the transfer on.
  102759. + *
  102760. + */
  102761. +static void set_ddma_iso_pkts_info(dwc_otg_core_if_t * core_if,
  102762. + dwc_ep_t * dwc_ep)
  102763. +{
  102764. + dwc_otg_dev_dma_desc_t *dma_desc;
  102765. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  102766. + iso_pkt_info_t *iso_packet;
  102767. + uint32_t data_per_desc;
  102768. + uint32_t offset;
  102769. + int i, j;
  102770. +
  102771. + iso_packet = dwc_ep->pkt_info;
  102772. +
  102773. + /** Reinit closed DMA Descriptors*/
  102774. + /** ISO OUT EP */
  102775. + if (dwc_ep->is_in == 0) {
  102776. + dma_desc =
  102777. + dwc_ep->iso_desc_addr +
  102778. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  102779. + offset = 0;
  102780. +
  102781. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  102782. + i += dwc_ep->pkt_per_frm) {
  102783. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  102784. + data_per_desc =
  102785. + ((j + 1) * dwc_ep->maxpacket >
  102786. + dwc_ep->
  102787. + data_per_frame) ? dwc_ep->data_per_frame -
  102788. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  102789. + data_per_desc +=
  102790. + (data_per_desc % 4) ? (4 -
  102791. + data_per_desc %
  102792. + 4) : 0;
  102793. +
  102794. + sts.d32 = dma_desc->status.d32;
  102795. +
  102796. + /* Write status in iso_packet_decsriptor */
  102797. + iso_packet->status =
  102798. + sts.b_iso_out.rxsts +
  102799. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  102800. + if (iso_packet->status) {
  102801. + iso_packet->status = -DWC_E_NO_DATA;
  102802. + }
  102803. +
  102804. + /* Received data length */
  102805. + if (!sts.b_iso_out.rxbytes) {
  102806. + iso_packet->length =
  102807. + data_per_desc -
  102808. + sts.b_iso_out.rxbytes;
  102809. + } else {
  102810. + iso_packet->length =
  102811. + data_per_desc -
  102812. + sts.b_iso_out.rxbytes + (4 -
  102813. + dwc_ep->data_per_frame
  102814. + % 4);
  102815. + }
  102816. +
  102817. + iso_packet->offset = offset;
  102818. +
  102819. + offset += data_per_desc;
  102820. + dma_desc++;
  102821. + iso_packet++;
  102822. + }
  102823. + }
  102824. +
  102825. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  102826. + data_per_desc =
  102827. + ((j + 1) * dwc_ep->maxpacket >
  102828. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  102829. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  102830. + data_per_desc +=
  102831. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  102832. +
  102833. + sts.d32 = dma_desc->status.d32;
  102834. +
  102835. + /* Write status in iso_packet_decsriptor */
  102836. + iso_packet->status =
  102837. + sts.b_iso_out.rxsts +
  102838. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  102839. + if (iso_packet->status) {
  102840. + iso_packet->status = -DWC_E_NO_DATA;
  102841. + }
  102842. +
  102843. + /* Received data length */
  102844. + iso_packet->length =
  102845. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  102846. +
  102847. + iso_packet->offset = offset;
  102848. +
  102849. + offset += data_per_desc;
  102850. + iso_packet++;
  102851. + dma_desc++;
  102852. + }
  102853. +
  102854. + sts.d32 = dma_desc->status.d32;
  102855. +
  102856. + /* Write status in iso_packet_decsriptor */
  102857. + iso_packet->status =
  102858. + sts.b_iso_out.rxsts + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  102859. + if (iso_packet->status) {
  102860. + iso_packet->status = -DWC_E_NO_DATA;
  102861. + }
  102862. + /* Received data length */
  102863. + if (!sts.b_iso_out.rxbytes) {
  102864. + iso_packet->length =
  102865. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  102866. + } else {
  102867. + iso_packet->length =
  102868. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes +
  102869. + (4 - dwc_ep->data_per_frame % 4);
  102870. + }
  102871. +
  102872. + iso_packet->offset = offset;
  102873. + } else {
  102874. +/** ISO IN EP */
  102875. +
  102876. + dma_desc =
  102877. + dwc_ep->iso_desc_addr +
  102878. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  102879. +
  102880. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  102881. + sts.d32 = dma_desc->status.d32;
  102882. +
  102883. + /* Write status in iso packet descriptor */
  102884. + iso_packet->status =
  102885. + sts.b_iso_in.txsts +
  102886. + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  102887. + if (iso_packet->status != 0) {
  102888. + iso_packet->status = -DWC_E_NO_DATA;
  102889. +
  102890. + }
  102891. + /* Bytes has been transfered */
  102892. + iso_packet->length =
  102893. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  102894. +
  102895. + dma_desc++;
  102896. + iso_packet++;
  102897. + }
  102898. +
  102899. + sts.d32 = dma_desc->status.d32;
  102900. + while (sts.b_iso_in.bs == BS_DMA_BUSY) {
  102901. + sts.d32 = dma_desc->status.d32;
  102902. + }
  102903. +
  102904. + /* Write status in iso packet descriptor ??? do be done with ERROR codes */
  102905. + iso_packet->status =
  102906. + sts.b_iso_in.txsts + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  102907. + if (iso_packet->status != 0) {
  102908. + iso_packet->status = -DWC_E_NO_DATA;
  102909. + }
  102910. +
  102911. + /* Bytes has been transfered */
  102912. + iso_packet->length =
  102913. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  102914. + }
  102915. +}
  102916. +
  102917. +/**
  102918. + * This function reinitialize DMA Descriptors for Isochronous transfer
  102919. + *
  102920. + * @param core_if Programming view of DWC_otg controller.
  102921. + * @param dwc_ep The EP to start the transfer on.
  102922. + *
  102923. + */
  102924. +static void reinit_ddma_iso_xfer(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  102925. +{
  102926. + int i, j;
  102927. + dwc_otg_dev_dma_desc_t *dma_desc;
  102928. + dma_addr_t dma_ad;
  102929. + volatile uint32_t *addr;
  102930. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  102931. + uint32_t data_per_desc;
  102932. +
  102933. + if (dwc_ep->is_in == 0) {
  102934. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  102935. + } else {
  102936. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  102937. + }
  102938. +
  102939. + if (dwc_ep->proc_buf_num == 0) {
  102940. + /** Buffer 0 descriptors setup */
  102941. + dma_ad = dwc_ep->dma_addr0;
  102942. + } else {
  102943. + /** Buffer 1 descriptors setup */
  102944. + dma_ad = dwc_ep->dma_addr1;
  102945. + }
  102946. +
  102947. + /** Reinit closed DMA Descriptors*/
  102948. + /** ISO OUT EP */
  102949. + if (dwc_ep->is_in == 0) {
  102950. + dma_desc =
  102951. + dwc_ep->iso_desc_addr +
  102952. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  102953. +
  102954. + sts.b_iso_out.bs = BS_HOST_READY;
  102955. + sts.b_iso_out.rxsts = 0;
  102956. + sts.b_iso_out.l = 0;
  102957. + sts.b_iso_out.sp = 0;
  102958. + sts.b_iso_out.ioc = 0;
  102959. + sts.b_iso_out.pid = 0;
  102960. + sts.b_iso_out.framenum = 0;
  102961. +
  102962. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  102963. + i += dwc_ep->pkt_per_frm) {
  102964. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  102965. + data_per_desc =
  102966. + ((j + 1) * dwc_ep->maxpacket >
  102967. + dwc_ep->
  102968. + data_per_frame) ? dwc_ep->data_per_frame -
  102969. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  102970. + data_per_desc +=
  102971. + (data_per_desc % 4) ? (4 -
  102972. + data_per_desc %
  102973. + 4) : 0;
  102974. + sts.b_iso_out.rxbytes = data_per_desc;
  102975. + dma_desc->buf = dma_ad;
  102976. + dma_desc->status.d32 = sts.d32;
  102977. +
  102978. + dma_ad += data_per_desc;
  102979. + dma_desc++;
  102980. + }
  102981. + }
  102982. +
  102983. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  102984. +
  102985. + data_per_desc =
  102986. + ((j + 1) * dwc_ep->maxpacket >
  102987. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  102988. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  102989. + data_per_desc +=
  102990. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  102991. + sts.b_iso_out.rxbytes = data_per_desc;
  102992. +
  102993. + dma_desc->buf = dma_ad;
  102994. + dma_desc->status.d32 = sts.d32;
  102995. +
  102996. + dma_desc++;
  102997. + dma_ad += data_per_desc;
  102998. + }
  102999. +
  103000. + sts.b_iso_out.ioc = 1;
  103001. + sts.b_iso_out.l = dwc_ep->proc_buf_num;
  103002. +
  103003. + data_per_desc =
  103004. + ((j + 1) * dwc_ep->maxpacket >
  103005. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  103006. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  103007. + data_per_desc +=
  103008. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  103009. + sts.b_iso_out.rxbytes = data_per_desc;
  103010. +
  103011. + dma_desc->buf = dma_ad;
  103012. + dma_desc->status.d32 = sts.d32;
  103013. + } else {
  103014. +/** ISO IN EP */
  103015. +
  103016. + dma_desc =
  103017. + dwc_ep->iso_desc_addr +
  103018. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  103019. +
  103020. + sts.b_iso_in.bs = BS_HOST_READY;
  103021. + sts.b_iso_in.txsts = 0;
  103022. + sts.b_iso_in.sp = 0;
  103023. + sts.b_iso_in.ioc = 0;
  103024. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  103025. + sts.b_iso_in.framenum = dwc_ep->next_frame;
  103026. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  103027. + sts.b_iso_in.l = 0;
  103028. +
  103029. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  103030. + dma_desc->buf = dma_ad;
  103031. + dma_desc->status.d32 = sts.d32;
  103032. +
  103033. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  103034. + dma_ad += dwc_ep->data_per_frame;
  103035. + dma_desc++;
  103036. + }
  103037. +
  103038. + sts.b_iso_in.ioc = 1;
  103039. + sts.b_iso_in.l = dwc_ep->proc_buf_num;
  103040. +
  103041. + dma_desc->buf = dma_ad;
  103042. + dma_desc->status.d32 = sts.d32;
  103043. +
  103044. + dwc_ep->next_frame =
  103045. + sts.b_iso_in.framenum + dwc_ep->bInterval * 1;
  103046. + }
  103047. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  103048. +}
  103049. +
  103050. +/**
  103051. + * This function is to handle Iso EP transfer complete interrupt
  103052. + * in case Iso out packet was dropped
  103053. + *
  103054. + * @param core_if Programming view of DWC_otg controller.
  103055. + * @param dwc_ep The EP for wihich transfer complete was asserted
  103056. + *
  103057. + */
  103058. +static uint32_t handle_iso_out_pkt_dropped(dwc_otg_core_if_t * core_if,
  103059. + dwc_ep_t * dwc_ep)
  103060. +{
  103061. + uint32_t dma_addr;
  103062. + uint32_t drp_pkt;
  103063. + uint32_t drp_pkt_cnt;
  103064. + deptsiz_data_t deptsiz = {.d32 = 0 };
  103065. + depctl_data_t depctl = {.d32 = 0 };
  103066. + int i;
  103067. +
  103068. + deptsiz.d32 =
  103069. + DWC_READ_REG32(&core_if->dev_if->
  103070. + out_ep_regs[dwc_ep->num]->doeptsiz);
  103071. +
  103072. + drp_pkt = dwc_ep->pkt_cnt - deptsiz.b.pktcnt;
  103073. + drp_pkt_cnt = dwc_ep->pkt_per_frm - (drp_pkt % dwc_ep->pkt_per_frm);
  103074. +
  103075. + /* Setting dropped packets status */
  103076. + for (i = 0; i < drp_pkt_cnt; ++i) {
  103077. + dwc_ep->pkt_info[drp_pkt].status = -DWC_E_NO_DATA;
  103078. + drp_pkt++;
  103079. + deptsiz.b.pktcnt--;
  103080. + }
  103081. +
  103082. + if (deptsiz.b.pktcnt > 0) {
  103083. + deptsiz.b.xfersize =
  103084. + dwc_ep->xfer_len - (dwc_ep->pkt_cnt -
  103085. + deptsiz.b.pktcnt) * dwc_ep->maxpacket;
  103086. + } else {
  103087. + deptsiz.b.xfersize = 0;
  103088. + deptsiz.b.pktcnt = 0;
  103089. + }
  103090. +
  103091. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz,
  103092. + deptsiz.d32);
  103093. +
  103094. + if (deptsiz.b.pktcnt > 0) {
  103095. + if (dwc_ep->proc_buf_num) {
  103096. + dma_addr =
  103097. + dwc_ep->dma_addr1 + dwc_ep->xfer_len -
  103098. + deptsiz.b.xfersize;
  103099. + } else {
  103100. + dma_addr =
  103101. + dwc_ep->dma_addr0 + dwc_ep->xfer_len -
  103102. + deptsiz.b.xfersize;;
  103103. + }
  103104. +
  103105. + DWC_WRITE_REG32(&core_if->dev_if->
  103106. + out_ep_regs[dwc_ep->num]->doepdma, dma_addr);
  103107. +
  103108. + /** Re-enable endpoint, clear nak */
  103109. + depctl.d32 = 0;
  103110. + depctl.b.epena = 1;
  103111. + depctl.b.cnak = 1;
  103112. +
  103113. + DWC_MODIFY_REG32(&core_if->dev_if->
  103114. + out_ep_regs[dwc_ep->num]->doepctl, depctl.d32,
  103115. + depctl.d32);
  103116. + return 0;
  103117. + } else {
  103118. + return 1;
  103119. + }
  103120. +}
  103121. +
  103122. +/**
  103123. + * This function sets iso packets information(PTI mode)
  103124. + *
  103125. + * @param core_if Programming view of DWC_otg controller.
  103126. + * @param ep The EP to start the transfer on.
  103127. + *
  103128. + */
  103129. +static uint32_t set_iso_pkts_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  103130. +{
  103131. + int i, j;
  103132. + dma_addr_t dma_ad;
  103133. + iso_pkt_info_t *packet_info = ep->pkt_info;
  103134. + uint32_t offset;
  103135. + uint32_t frame_data;
  103136. + deptsiz_data_t deptsiz;
  103137. +
  103138. + if (ep->proc_buf_num == 0) {
  103139. + /** Buffer 0 descriptors setup */
  103140. + dma_ad = ep->dma_addr0;
  103141. + } else {
  103142. + /** Buffer 1 descriptors setup */
  103143. + dma_ad = ep->dma_addr1;
  103144. + }
  103145. +
  103146. + if (ep->is_in) {
  103147. + deptsiz.d32 =
  103148. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  103149. + dieptsiz);
  103150. + } else {
  103151. + deptsiz.d32 =
  103152. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  103153. + doeptsiz);
  103154. + }
  103155. +
  103156. + if (!deptsiz.b.xfersize) {
  103157. + offset = 0;
  103158. + for (i = 0; i < ep->pkt_cnt; i += ep->pkt_per_frm) {
  103159. + frame_data = ep->data_per_frame;
  103160. + for (j = 0; j < ep->pkt_per_frm; ++j) {
  103161. +
  103162. + /* Packet status - is not set as initially
  103163. + * it is set to 0 and if packet was sent
  103164. + successfully, status field will remain 0*/
  103165. +
  103166. + /* Bytes has been transfered */
  103167. + packet_info->length =
  103168. + (ep->maxpacket <
  103169. + frame_data) ? ep->maxpacket : frame_data;
  103170. +
  103171. + /* Received packet offset */
  103172. + packet_info->offset = offset;
  103173. + offset += packet_info->length;
  103174. + frame_data -= packet_info->length;
  103175. +
  103176. + packet_info++;
  103177. + }
  103178. + }
  103179. + return 1;
  103180. + } else {
  103181. + /* This is a workaround for in case of Transfer Complete with
  103182. + * PktDrpSts interrupts merging - in this case Transfer complete
  103183. + * interrupt for Isoc Out Endpoint is asserted without PktDrpSts
  103184. + * set and with DOEPTSIZ register non zero. Investigations showed,
  103185. + * that this happens when Out packet is dropped, but because of
  103186. + * interrupts merging during first interrupt handling PktDrpSts
  103187. + * bit is cleared and for next merged interrupts it is not reset.
  103188. + * In this case SW hadles the interrupt as if PktDrpSts bit is set.
  103189. + */
  103190. + if (ep->is_in) {
  103191. + return 1;
  103192. + } else {
  103193. + return handle_iso_out_pkt_dropped(core_if, ep);
  103194. + }
  103195. + }
  103196. +}
  103197. +
  103198. +/**
  103199. + * This function is to handle Iso EP transfer complete interrupt
  103200. + *
  103201. + * @param pcd The PCD
  103202. + * @param ep The EP for which transfer complete was asserted
  103203. + *
  103204. + */
  103205. +static void complete_iso_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  103206. +{
  103207. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  103208. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  103209. + uint8_t is_last = 0;
  103210. +
  103211. + if (ep->dwc_ep.next_frame == 0xffffffff) {
  103212. + DWC_WARN("Next frame is not set!\n");
  103213. + return;
  103214. + }
  103215. +
  103216. + if (core_if->dma_enable) {
  103217. + if (core_if->dma_desc_enable) {
  103218. + set_ddma_iso_pkts_info(core_if, dwc_ep);
  103219. + reinit_ddma_iso_xfer(core_if, dwc_ep);
  103220. + is_last = 1;
  103221. + } else {
  103222. + if (core_if->pti_enh_enable) {
  103223. + if (set_iso_pkts_info(core_if, dwc_ep)) {
  103224. + dwc_ep->proc_buf_num =
  103225. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  103226. + dwc_otg_iso_ep_start_buf_transfer
  103227. + (core_if, dwc_ep);
  103228. + is_last = 1;
  103229. + }
  103230. + } else {
  103231. + set_current_pkt_info(core_if, dwc_ep);
  103232. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  103233. + is_last = 1;
  103234. + dwc_ep->cur_pkt = 0;
  103235. + dwc_ep->proc_buf_num =
  103236. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  103237. + if (dwc_ep->proc_buf_num) {
  103238. + dwc_ep->cur_pkt_addr =
  103239. + dwc_ep->xfer_buff1;
  103240. + dwc_ep->cur_pkt_dma_addr =
  103241. + dwc_ep->dma_addr1;
  103242. + } else {
  103243. + dwc_ep->cur_pkt_addr =
  103244. + dwc_ep->xfer_buff0;
  103245. + dwc_ep->cur_pkt_dma_addr =
  103246. + dwc_ep->dma_addr0;
  103247. + }
  103248. +
  103249. + }
  103250. + dwc_otg_iso_ep_start_frm_transfer(core_if,
  103251. + dwc_ep);
  103252. + }
  103253. + }
  103254. + } else {
  103255. + set_current_pkt_info(core_if, dwc_ep);
  103256. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  103257. + is_last = 1;
  103258. + dwc_ep->cur_pkt = 0;
  103259. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  103260. + if (dwc_ep->proc_buf_num) {
  103261. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
  103262. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
  103263. + } else {
  103264. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
  103265. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
  103266. + }
  103267. +
  103268. + }
  103269. + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
  103270. + }
  103271. + if (is_last)
  103272. + dwc_otg_iso_buffer_done(pcd, ep, ep->iso_req_handle);
  103273. +}
  103274. +#endif /* DWC_EN_ISOC */
  103275. +
  103276. +/**
  103277. + * This function handle BNA interrupt for Non Isochronous EPs
  103278. + *
  103279. + */
  103280. +static void dwc_otg_pcd_handle_noniso_bna(dwc_otg_pcd_ep_t * ep)
  103281. +{
  103282. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  103283. + volatile uint32_t *addr;
  103284. + depctl_data_t depctl = {.d32 = 0 };
  103285. + dwc_otg_pcd_t *pcd = ep->pcd;
  103286. + dwc_otg_dev_dma_desc_t *dma_desc;
  103287. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  103288. + dwc_otg_core_if_t *core_if = ep->pcd->core_if;
  103289. + int i, start;
  103290. +
  103291. + if (!dwc_ep->desc_cnt)
  103292. + DWC_WARN("Ep%d %s Descriptor count = %d \n", dwc_ep->num,
  103293. + (dwc_ep->is_in ? "IN" : "OUT"), dwc_ep->desc_cnt);
  103294. +
  103295. + if (core_if->core_params->cont_on_bna && !dwc_ep->is_in
  103296. + && dwc_ep->type != DWC_OTG_EP_TYPE_CONTROL) {
  103297. + uint32_t doepdma;
  103298. + dwc_otg_dev_out_ep_regs_t *out_regs =
  103299. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  103300. + doepdma = DWC_READ_REG32(&(out_regs->doepdma));
  103301. + start = (doepdma - dwc_ep->dma_desc_addr)/sizeof(dwc_otg_dev_dma_desc_t);
  103302. + dma_desc = &(dwc_ep->desc_addr[start]);
  103303. + } else {
  103304. + start = 0;
  103305. + dma_desc = dwc_ep->desc_addr;
  103306. + }
  103307. +
  103308. +
  103309. + for (i = start; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  103310. + sts.d32 = dma_desc->status.d32;
  103311. + sts.b.bs = BS_HOST_READY;
  103312. + dma_desc->status.d32 = sts.d32;
  103313. + }
  103314. +
  103315. + if (dwc_ep->is_in == 0) {
  103316. + addr =
  103317. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->num]->
  103318. + doepctl;
  103319. + } else {
  103320. + addr =
  103321. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  103322. + }
  103323. + depctl.b.epena = 1;
  103324. + depctl.b.cnak = 1;
  103325. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  103326. +}
  103327. +
  103328. +/**
  103329. + * This function handles EP0 Control transfers.
  103330. + *
  103331. + * The state of the control transfers are tracked in
  103332. + * <code>ep0state</code>.
  103333. + */
  103334. +static void handle_ep0(dwc_otg_pcd_t * pcd)
  103335. +{
  103336. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  103337. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  103338. + dev_dma_desc_sts_t desc_sts;
  103339. + deptsiz0_data_t deptsiz;
  103340. + uint32_t byte_count;
  103341. +
  103342. +#ifdef DEBUG_EP0
  103343. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  103344. + print_ep0_state(pcd);
  103345. +#endif
  103346. +
  103347. +// DWC_PRINTF("HANDLE EP0\n");
  103348. +
  103349. + switch (pcd->ep0state) {
  103350. + case EP0_DISCONNECT:
  103351. + break;
  103352. +
  103353. + case EP0_IDLE:
  103354. + pcd->request_config = 0;
  103355. +
  103356. + pcd_setup(pcd);
  103357. + break;
  103358. +
  103359. + case EP0_IN_DATA_PHASE:
  103360. +#ifdef DEBUG_EP0
  103361. + DWC_DEBUGPL(DBG_PCD, "DATA_IN EP%d-%s: type=%d, mps=%d\n",
  103362. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  103363. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  103364. +#endif
  103365. +
  103366. + if (core_if->dma_enable != 0) {
  103367. + /*
  103368. + * For EP0 we can only program 1 packet at a time so we
  103369. + * need to do the make calculations after each complete.
  103370. + * Call write_packet to make the calculations, as in
  103371. + * slave mode, and use those values to determine if we
  103372. + * can complete.
  103373. + */
  103374. + if (core_if->dma_desc_enable == 0) {
  103375. + deptsiz.d32 =
  103376. + DWC_READ_REG32(&core_if->
  103377. + dev_if->in_ep_regs[0]->
  103378. + dieptsiz);
  103379. + byte_count =
  103380. + ep0->dwc_ep.xfer_len - deptsiz.b.xfersize;
  103381. + } else {
  103382. + desc_sts =
  103383. + core_if->dev_if->in_desc_addr->status;
  103384. + byte_count =
  103385. + ep0->dwc_ep.xfer_len - desc_sts.b.bytes;
  103386. + }
  103387. + ep0->dwc_ep.xfer_count += byte_count;
  103388. + ep0->dwc_ep.xfer_buff += byte_count;
  103389. + ep0->dwc_ep.dma_addr += byte_count;
  103390. + }
  103391. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  103392. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  103393. + &ep0->dwc_ep);
  103394. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  103395. + } else if (ep0->dwc_ep.sent_zlp) {
  103396. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  103397. + &ep0->dwc_ep);
  103398. + ep0->dwc_ep.sent_zlp = 0;
  103399. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  103400. + } else {
  103401. + ep0_complete_request(ep0);
  103402. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  103403. + }
  103404. + break;
  103405. + case EP0_OUT_DATA_PHASE:
  103406. +#ifdef DEBUG_EP0
  103407. + DWC_DEBUGPL(DBG_PCD, "DATA_OUT EP%d-%s: type=%d, mps=%d\n",
  103408. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  103409. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  103410. +#endif
  103411. + if (core_if->dma_enable != 0) {
  103412. + if (core_if->dma_desc_enable == 0) {
  103413. + deptsiz.d32 =
  103414. + DWC_READ_REG32(&core_if->
  103415. + dev_if->out_ep_regs[0]->
  103416. + doeptsiz);
  103417. + byte_count =
  103418. + ep0->dwc_ep.maxpacket - deptsiz.b.xfersize;
  103419. + } else {
  103420. + desc_sts =
  103421. + core_if->dev_if->out_desc_addr->status;
  103422. + byte_count =
  103423. + ep0->dwc_ep.maxpacket - desc_sts.b.bytes;
  103424. + }
  103425. + ep0->dwc_ep.xfer_count += byte_count;
  103426. + ep0->dwc_ep.xfer_buff += byte_count;
  103427. + ep0->dwc_ep.dma_addr += byte_count;
  103428. + }
  103429. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  103430. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  103431. + &ep0->dwc_ep);
  103432. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  103433. + } else if (ep0->dwc_ep.sent_zlp) {
  103434. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  103435. + &ep0->dwc_ep);
  103436. + ep0->dwc_ep.sent_zlp = 0;
  103437. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  103438. + } else {
  103439. + ep0_complete_request(ep0);
  103440. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  103441. + }
  103442. + break;
  103443. +
  103444. + case EP0_IN_STATUS_PHASE:
  103445. + case EP0_OUT_STATUS_PHASE:
  103446. + DWC_DEBUGPL(DBG_PCD, "CASE: EP0_STATUS\n");
  103447. + ep0_complete_request(ep0);
  103448. + pcd->ep0state = EP0_IDLE;
  103449. + ep0->stopped = 1;
  103450. + ep0->dwc_ep.is_in = 0; /* OUT for next SETUP */
  103451. +
  103452. + /* Prepare for more SETUP Packets */
  103453. + if (core_if->dma_enable) {
  103454. + ep0_out_start(core_if, pcd);
  103455. + }
  103456. + break;
  103457. +
  103458. + case EP0_STALL:
  103459. + DWC_ERROR("EP0 STALLed, should not get here pcd_setup()\n");
  103460. + break;
  103461. + }
  103462. +#ifdef DEBUG_EP0
  103463. + print_ep0_state(pcd);
  103464. +#endif
  103465. +}
  103466. +
  103467. +/**
  103468. + * Restart transfer
  103469. + */
  103470. +static void restart_transfer(dwc_otg_pcd_t * pcd, const uint32_t epnum)
  103471. +{
  103472. + dwc_otg_core_if_t *core_if;
  103473. + dwc_otg_dev_if_t *dev_if;
  103474. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  103475. + dwc_otg_pcd_ep_t *ep;
  103476. +
  103477. + ep = get_in_ep(pcd, epnum);
  103478. +
  103479. +#ifdef DWC_EN_ISOC
  103480. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  103481. + return;
  103482. + }
  103483. +#endif /* DWC_EN_ISOC */
  103484. +
  103485. + core_if = GET_CORE_IF(pcd);
  103486. + dev_if = core_if->dev_if;
  103487. +
  103488. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  103489. +
  103490. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x xfer_len=%0x"
  103491. + " stopped=%d\n", ep->dwc_ep.xfer_buff,
  103492. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len, ep->stopped);
  103493. + /*
  103494. + * If xfersize is 0 and pktcnt in not 0, resend the last packet.
  103495. + */
  103496. + if (dieptsiz.b.pktcnt && dieptsiz.b.xfersize == 0 &&
  103497. + ep->dwc_ep.start_xfer_buff != 0) {
  103498. + if (ep->dwc_ep.total_len <= ep->dwc_ep.maxpacket) {
  103499. + ep->dwc_ep.xfer_count = 0;
  103500. + ep->dwc_ep.xfer_buff = ep->dwc_ep.start_xfer_buff;
  103501. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  103502. + } else {
  103503. + ep->dwc_ep.xfer_count -= ep->dwc_ep.maxpacket;
  103504. + /* convert packet size to dwords. */
  103505. + ep->dwc_ep.xfer_buff -= ep->dwc_ep.maxpacket;
  103506. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  103507. + }
  103508. + ep->stopped = 0;
  103509. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x "
  103510. + "xfer_len=%0x stopped=%d\n",
  103511. + ep->dwc_ep.xfer_buff,
  103512. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len,
  103513. + ep->stopped);
  103514. + if (epnum == 0) {
  103515. + dwc_otg_ep0_start_transfer(core_if, &ep->dwc_ep);
  103516. + } else {
  103517. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  103518. + }
  103519. + }
  103520. +}
  103521. +
  103522. +/*
  103523. + * This function create new nextep sequnce based on Learn Queue.
  103524. + *
  103525. + * @param core_if Programming view of DWC_otg controller
  103526. + */
  103527. +void predict_nextep_seq( dwc_otg_core_if_t * core_if)
  103528. +{
  103529. + dwc_otg_device_global_regs_t *dev_global_regs =
  103530. + core_if->dev_if->dev_global_regs;
  103531. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  103532. + /* Number of Token Queue Registers */
  103533. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  103534. + dtknq1_data_t dtknqr1;
  103535. + uint32_t in_tkn_epnums[4];
  103536. + uint8_t seqnum[MAX_EPS_CHANNELS];
  103537. + uint8_t intkn_seq[TOKEN_Q_DEPTH];
  103538. + grstctl_t resetctl = {.d32 = 0 };
  103539. + uint8_t temp;
  103540. + int ndx = 0;
  103541. + int start = 0;
  103542. + int end = 0;
  103543. + int sort_done = 0;
  103544. + int i = 0;
  103545. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  103546. +
  103547. +
  103548. + DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  103549. +
  103550. + /* Read the DTKNQ Registers */
  103551. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  103552. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  103553. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  103554. + in_tkn_epnums[i]);
  103555. + if (addr == &dev_global_regs->dvbusdis) {
  103556. + addr = &dev_global_regs->dtknqr3_dthrctl;
  103557. + } else {
  103558. + ++addr;
  103559. + }
  103560. +
  103561. + }
  103562. +
  103563. + /* Copy the DTKNQR1 data to the bit field. */
  103564. + dtknqr1.d32 = in_tkn_epnums[0];
  103565. + if (dtknqr1.b.wrap_bit) {
  103566. + ndx = dtknqr1.b.intknwptr;
  103567. + end = ndx -1;
  103568. + if (end < 0)
  103569. + end = TOKEN_Q_DEPTH -1;
  103570. + } else {
  103571. + ndx = 0;
  103572. + end = dtknqr1.b.intknwptr -1;
  103573. + if (end < 0)
  103574. + end = 0;
  103575. + }
  103576. + start = ndx;
  103577. +
  103578. + /* Fill seqnum[] by initial values: EP number + 31 */
  103579. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  103580. + seqnum[i] = i +31;
  103581. + }
  103582. +
  103583. + /* Fill intkn_seq[] from in_tkn_epnums[0] */
  103584. + for (i=0; i < 6; i++)
  103585. + intkn_seq[i] = (in_tkn_epnums[0] >> ((7-i) * 4)) & 0xf;
  103586. +
  103587. + if (TOKEN_Q_DEPTH > 6) {
  103588. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  103589. + for (i=6; i < 14; i++)
  103590. + intkn_seq[i] =
  103591. + (in_tkn_epnums[1] >> ((7 - (i - 6)) * 4)) & 0xf;
  103592. + }
  103593. +
  103594. + if (TOKEN_Q_DEPTH > 14) {
  103595. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  103596. + for (i=14; i < 22; i++)
  103597. + intkn_seq[i] =
  103598. + (in_tkn_epnums[2] >> ((7 - (i - 14)) * 4)) & 0xf;
  103599. + }
  103600. +
  103601. + if (TOKEN_Q_DEPTH > 22) {
  103602. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  103603. + for (i=22; i < 30; i++)
  103604. + intkn_seq[i] =
  103605. + (in_tkn_epnums[3] >> ((7 - (i - 22)) * 4)) & 0xf;
  103606. + }
  103607. +
  103608. + DWC_DEBUGPL(DBG_PCDV, "%s start=%d end=%d intkn_seq[]:\n", __func__,
  103609. + start, end);
  103610. + for (i=0; i<TOKEN_Q_DEPTH; i++)
  103611. + DWC_DEBUGPL(DBG_PCDV,"%d\n", intkn_seq[i]);
  103612. +
  103613. + /* Update seqnum based on intkn_seq[] */
  103614. + i = 0;
  103615. + do {
  103616. + seqnum[intkn_seq[ndx]] = i;
  103617. + ndx++;
  103618. + i++;
  103619. + if (ndx == TOKEN_Q_DEPTH)
  103620. + ndx = 0;
  103621. + } while ( i < TOKEN_Q_DEPTH );
  103622. +
  103623. + /* Mark non active EP's in seqnum[] by 0xff */
  103624. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  103625. + if (core_if->nextep_seq[i] == 0xff )
  103626. + seqnum[i] = 0xff;
  103627. + }
  103628. +
  103629. + /* Sort seqnum[] */
  103630. + sort_done = 0;
  103631. + while (!sort_done) {
  103632. + sort_done = 1;
  103633. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  103634. + if (seqnum[i] > seqnum[i+1]) {
  103635. + temp = seqnum[i];
  103636. + seqnum[i] = seqnum[i+1];
  103637. + seqnum[i+1] = temp;
  103638. + sort_done = 0;
  103639. + }
  103640. + }
  103641. + }
  103642. +
  103643. + ndx = start + seqnum[0];
  103644. + if (ndx >= TOKEN_Q_DEPTH)
  103645. + ndx = ndx % TOKEN_Q_DEPTH;
  103646. + core_if->first_in_nextep_seq = intkn_seq[ndx];
  103647. +
  103648. + /* Update seqnum[] by EP numbers */
  103649. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  103650. + ndx = start + i;
  103651. + if (seqnum[i] < 31) {
  103652. + ndx = start + seqnum[i];
  103653. + if (ndx >= TOKEN_Q_DEPTH)
  103654. + ndx = ndx % TOKEN_Q_DEPTH;
  103655. + seqnum[i] = intkn_seq[ndx];
  103656. + } else {
  103657. + if (seqnum[i] < 0xff) {
  103658. + seqnum[i] = seqnum[i] - 31;
  103659. + } else {
  103660. + break;
  103661. + }
  103662. + }
  103663. + }
  103664. +
  103665. + /* Update nextep_seq[] based on seqnum[] */
  103666. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  103667. + if (seqnum[i] != 0xff) {
  103668. + if (seqnum[i+1] != 0xff) {
  103669. + core_if->nextep_seq[seqnum[i]] = seqnum[i+1];
  103670. + } else {
  103671. + core_if->nextep_seq[seqnum[i]] = core_if->first_in_nextep_seq;
  103672. + break;
  103673. + }
  103674. + } else {
  103675. + break;
  103676. + }
  103677. + }
  103678. +
  103679. + DWC_DEBUGPL(DBG_PCDV, "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  103680. + __func__, core_if->first_in_nextep_seq);
  103681. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  103682. + DWC_DEBUGPL(DBG_PCDV,"%2d\n", core_if->nextep_seq[i]);
  103683. + }
  103684. +
  103685. + /* Flush the Learning Queue */
  103686. + resetctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->grstctl);
  103687. + resetctl.b.intknqflsh = 1;
  103688. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  103689. +
  103690. +
  103691. +}
  103692. +
  103693. +/**
  103694. + * handle the IN EP disable interrupt.
  103695. + */
  103696. +static inline void handle_in_ep_disable_intr(dwc_otg_pcd_t * pcd,
  103697. + const uint32_t epnum)
  103698. +{
  103699. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  103700. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  103701. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  103702. + dctl_data_t dctl = {.d32 = 0 };
  103703. + dwc_otg_pcd_ep_t *ep;
  103704. + dwc_ep_t *dwc_ep;
  103705. + gintmsk_data_t gintmsk_data;
  103706. + depctl_data_t depctl;
  103707. + uint32_t diepdma;
  103708. + uint32_t remain_to_transfer = 0;
  103709. + uint8_t i;
  103710. + uint32_t xfer_size;
  103711. +
  103712. + ep = get_in_ep(pcd, epnum);
  103713. + dwc_ep = &ep->dwc_ep;
  103714. +
  103715. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  103716. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  103717. + complete_ep(ep);
  103718. + return;
  103719. + }
  103720. +
  103721. + DWC_DEBUGPL(DBG_PCD, "diepctl%d=%0x\n", epnum,
  103722. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl));
  103723. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  103724. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  103725. +
  103726. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  103727. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  103728. +
  103729. + if ((core_if->start_predict == 0) || (depctl.b.eptype & 1)) {
  103730. + if (ep->stopped) {
  103731. + if (core_if->en_multiple_tx_fifo)
  103732. + /* Flush the Tx FIFO */
  103733. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  103734. + /* Clear the Global IN NP NAK */
  103735. + dctl.d32 = 0;
  103736. + dctl.b.cgnpinnak = 1;
  103737. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  103738. + /* Restart the transaction */
  103739. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  103740. + restart_transfer(pcd, epnum);
  103741. + }
  103742. + } else {
  103743. + /* Restart the transaction */
  103744. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  103745. + restart_transfer(pcd, epnum);
  103746. + }
  103747. + DWC_DEBUGPL(DBG_ANY, "STOPPED!!!\n");
  103748. + }
  103749. + return;
  103750. + }
  103751. +
  103752. + if (core_if->start_predict > 2) { // NP IN EP
  103753. + core_if->start_predict--;
  103754. + return;
  103755. + }
  103756. +
  103757. + core_if->start_predict--;
  103758. +
  103759. + if (core_if->start_predict == 1) { // All NP IN Ep's disabled now
  103760. +
  103761. + predict_nextep_seq(core_if);
  103762. +
  103763. + /* Update all active IN EP's NextEP field based of nextep_seq[] */
  103764. + for ( i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  103765. + depctl.d32 =
  103766. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  103767. + if (core_if->nextep_seq[i] != 0xff) { // Active NP IN EP
  103768. + depctl.b.nextep = core_if->nextep_seq[i];
  103769. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  103770. + }
  103771. + }
  103772. + /* Flush Shared NP TxFIFO */
  103773. + dwc_otg_flush_tx_fifo(core_if, 0);
  103774. + /* Rewind buffers */
  103775. + if (!core_if->dma_desc_enable) {
  103776. + i = core_if->first_in_nextep_seq;
  103777. + do {
  103778. + ep = get_in_ep(pcd, i);
  103779. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  103780. + xfer_size = ep->dwc_ep.total_len - ep->dwc_ep.xfer_count;
  103781. + if (xfer_size > ep->dwc_ep.maxxfer)
  103782. + xfer_size = ep->dwc_ep.maxxfer;
  103783. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  103784. + if (dieptsiz.b.pktcnt != 0) {
  103785. + if (xfer_size == 0) {
  103786. + remain_to_transfer = 0;
  103787. + } else {
  103788. + if ((xfer_size % ep->dwc_ep.maxpacket) == 0) {
  103789. + remain_to_transfer =
  103790. + dieptsiz.b.pktcnt * ep->dwc_ep.maxpacket;
  103791. + } else {
  103792. + remain_to_transfer = ((dieptsiz.b.pktcnt -1) * ep->dwc_ep.maxpacket)
  103793. + + (xfer_size % ep->dwc_ep.maxpacket);
  103794. + }
  103795. + }
  103796. + diepdma = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepdma);
  103797. + dieptsiz.b.xfersize = remain_to_transfer;
  103798. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, dieptsiz.d32);
  103799. + diepdma = ep->dwc_ep.dma_addr + (xfer_size - remain_to_transfer);
  103800. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, diepdma);
  103801. + }
  103802. + i = core_if->nextep_seq[i];
  103803. + } while (i != core_if->first_in_nextep_seq);
  103804. + } else { // dma_desc_enable
  103805. + DWC_PRINTF("%s Learning Queue not supported in DDMA\n", __func__);
  103806. + }
  103807. +
  103808. + /* Restart transfers in predicted sequences */
  103809. + i = core_if->first_in_nextep_seq;
  103810. + do {
  103811. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  103812. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  103813. + if (dieptsiz.b.pktcnt != 0) {
  103814. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  103815. + depctl.b.epena = 1;
  103816. + depctl.b.cnak = 1;
  103817. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  103818. + }
  103819. + i = core_if->nextep_seq[i];
  103820. + } while (i != core_if->first_in_nextep_seq);
  103821. +
  103822. + /* Clear the global non-periodic IN NAK handshake */
  103823. + dctl.d32 = 0;
  103824. + dctl.b.cgnpinnak = 1;
  103825. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  103826. +
  103827. + /* Unmask EP Mismatch interrupt */
  103828. + gintmsk_data.d32 = 0;
  103829. + gintmsk_data.b.epmismatch = 1;
  103830. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk_data.d32);
  103831. +
  103832. + core_if->start_predict = 0;
  103833. +
  103834. + }
  103835. +}
  103836. +
  103837. +/**
  103838. + * Handler for the IN EP timeout handshake interrupt.
  103839. + */
  103840. +static inline void handle_in_ep_timeout_intr(dwc_otg_pcd_t * pcd,
  103841. + const uint32_t epnum)
  103842. +{
  103843. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  103844. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  103845. +
  103846. +#ifdef DEBUG
  103847. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  103848. + uint32_t num = 0;
  103849. +#endif
  103850. + dctl_data_t dctl = {.d32 = 0 };
  103851. + dwc_otg_pcd_ep_t *ep;
  103852. +
  103853. + gintmsk_data_t intr_mask = {.d32 = 0 };
  103854. +
  103855. + ep = get_in_ep(pcd, epnum);
  103856. +
  103857. + /* Disable the NP Tx Fifo Empty Interrrupt */
  103858. + if (!core_if->dma_enable) {
  103859. + intr_mask.b.nptxfempty = 1;
  103860. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  103861. + intr_mask.d32, 0);
  103862. + }
  103863. + /** @todo NGS Check EP type.
  103864. + * Implement for Periodic EPs */
  103865. + /*
  103866. + * Non-periodic EP
  103867. + */
  103868. + /* Enable the Global IN NAK Effective Interrupt */
  103869. + intr_mask.b.ginnakeff = 1;
  103870. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  103871. +
  103872. + /* Set Global IN NAK */
  103873. + dctl.b.sgnpinnak = 1;
  103874. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  103875. +
  103876. + ep->stopped = 1;
  103877. +
  103878. +#ifdef DEBUG
  103879. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[num]->dieptsiz);
  103880. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  103881. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  103882. +#endif
  103883. +
  103884. +#ifdef DISABLE_PERIODIC_EP
  103885. + /*
  103886. + * Set the NAK bit for this EP to
  103887. + * start the disable process.
  103888. + */
  103889. + diepctl.d32 = 0;
  103890. + diepctl.b.snak = 1;
  103891. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[num]->diepctl, diepctl.d32,
  103892. + diepctl.d32);
  103893. + ep->disabling = 1;
  103894. + ep->stopped = 1;
  103895. +#endif
  103896. +}
  103897. +
  103898. +/**
  103899. + * Handler for the IN EP NAK interrupt.
  103900. + */
  103901. +static inline int32_t handle_in_ep_nak_intr(dwc_otg_pcd_t * pcd,
  103902. + const uint32_t epnum)
  103903. +{
  103904. + /** @todo implement ISR */
  103905. + dwc_otg_core_if_t *core_if;
  103906. + diepmsk_data_t intr_mask = {.d32 = 0 };
  103907. +
  103908. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "IN EP NAK");
  103909. + core_if = GET_CORE_IF(pcd);
  103910. + intr_mask.b.nak = 1;
  103911. +
  103912. + if (core_if->multiproc_int_enable) {
  103913. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  103914. + diepeachintmsk[epnum], intr_mask.d32, 0);
  103915. + } else {
  103916. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->diepmsk,
  103917. + intr_mask.d32, 0);
  103918. + }
  103919. +
  103920. + return 1;
  103921. +}
  103922. +
  103923. +/**
  103924. + * Handler for the OUT EP Babble interrupt.
  103925. + */
  103926. +static inline int32_t handle_out_ep_babble_intr(dwc_otg_pcd_t * pcd,
  103927. + const uint32_t epnum)
  103928. +{
  103929. + /** @todo implement ISR */
  103930. + dwc_otg_core_if_t *core_if;
  103931. + doepmsk_data_t intr_mask = {.d32 = 0 };
  103932. +
  103933. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  103934. + "OUT EP Babble");
  103935. + core_if = GET_CORE_IF(pcd);
  103936. + intr_mask.b.babble = 1;
  103937. +
  103938. + if (core_if->multiproc_int_enable) {
  103939. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  103940. + doepeachintmsk[epnum], intr_mask.d32, 0);
  103941. + } else {
  103942. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  103943. + intr_mask.d32, 0);
  103944. + }
  103945. +
  103946. + return 1;
  103947. +}
  103948. +
  103949. +/**
  103950. + * Handler for the OUT EP NAK interrupt.
  103951. + */
  103952. +static inline int32_t handle_out_ep_nak_intr(dwc_otg_pcd_t * pcd,
  103953. + const uint32_t epnum)
  103954. +{
  103955. + /** @todo implement ISR */
  103956. + dwc_otg_core_if_t *core_if;
  103957. + doepmsk_data_t intr_mask = {.d32 = 0 };
  103958. +
  103959. + DWC_DEBUGPL(DBG_ANY, "INTERRUPT Handler not implemented for %s\n", "OUT EP NAK");
  103960. + core_if = GET_CORE_IF(pcd);
  103961. + intr_mask.b.nak = 1;
  103962. +
  103963. + if (core_if->multiproc_int_enable) {
  103964. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  103965. + doepeachintmsk[epnum], intr_mask.d32, 0);
  103966. + } else {
  103967. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  103968. + intr_mask.d32, 0);
  103969. + }
  103970. +
  103971. + return 1;
  103972. +}
  103973. +
  103974. +/**
  103975. + * Handler for the OUT EP NYET interrupt.
  103976. + */
  103977. +static inline int32_t handle_out_ep_nyet_intr(dwc_otg_pcd_t * pcd,
  103978. + const uint32_t epnum)
  103979. +{
  103980. + /** @todo implement ISR */
  103981. + dwc_otg_core_if_t *core_if;
  103982. + doepmsk_data_t intr_mask = {.d32 = 0 };
  103983. +
  103984. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "OUT EP NYET");
  103985. + core_if = GET_CORE_IF(pcd);
  103986. + intr_mask.b.nyet = 1;
  103987. +
  103988. + if (core_if->multiproc_int_enable) {
  103989. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  103990. + doepeachintmsk[epnum], intr_mask.d32, 0);
  103991. + } else {
  103992. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  103993. + intr_mask.d32, 0);
  103994. + }
  103995. +
  103996. + return 1;
  103997. +}
  103998. +
  103999. +/**
  104000. + * This interrupt indicates that an IN EP has a pending Interrupt.
  104001. + * The sequence for handling the IN EP interrupt is shown below:
  104002. + * -# Read the Device All Endpoint Interrupt register
  104003. + * -# Repeat the following for each IN EP interrupt bit set (from
  104004. + * LSB to MSB).
  104005. + * -# Read the Device Endpoint Interrupt (DIEPINTn) register
  104006. + * -# If "Transfer Complete" call the request complete function
  104007. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  104008. + * -# If "AHB Error Interrupt" log error
  104009. + * -# If "Time-out Handshake" log error
  104010. + * -# If "IN Token Received when TxFIFO Empty" write packet to Tx
  104011. + * FIFO.
  104012. + * -# If "IN Token EP Mismatch" (disable, this is handled by EP
  104013. + * Mismatch Interrupt)
  104014. + */
  104015. +static int32_t dwc_otg_pcd_handle_in_ep_intr(dwc_otg_pcd_t * pcd)
  104016. +{
  104017. +#define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \
  104018. +do { \
  104019. + diepint_data_t diepint = {.d32=0}; \
  104020. + diepint.b.__intr = 1; \
  104021. + DWC_WRITE_REG32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \
  104022. + diepint.d32); \
  104023. +} while (0)
  104024. +
  104025. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  104026. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  104027. + diepint_data_t diepint = {.d32 = 0 };
  104028. + depctl_data_t depctl = {.d32 = 0 };
  104029. + uint32_t ep_intr;
  104030. + uint32_t epnum = 0;
  104031. + dwc_otg_pcd_ep_t *ep;
  104032. + dwc_ep_t *dwc_ep;
  104033. + gintmsk_data_t intr_mask = {.d32 = 0 };
  104034. +
  104035. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
  104036. +
  104037. + /* Read in the device interrupt bits */
  104038. + ep_intr = dwc_otg_read_dev_all_in_ep_intr(core_if);
  104039. +
  104040. + /* Service the Device IN interrupts for each endpoint */
  104041. + while (ep_intr) {
  104042. + if (ep_intr & 0x1) {
  104043. + uint32_t empty_msk;
  104044. + /* Get EP pointer */
  104045. + ep = get_in_ep(pcd, epnum);
  104046. + dwc_ep = &ep->dwc_ep;
  104047. +
  104048. + depctl.d32 =
  104049. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  104050. + empty_msk =
  104051. + DWC_READ_REG32(&dev_if->
  104052. + dev_global_regs->dtknqr4_fifoemptymsk);
  104053. +
  104054. + DWC_DEBUGPL(DBG_PCDV,
  104055. + "IN EP INTERRUPT - %d\nepmty_msk - %8x diepctl - %8x\n",
  104056. + epnum, empty_msk, depctl.d32);
  104057. +
  104058. + DWC_DEBUGPL(DBG_PCD,
  104059. + "EP%d-%s: type=%d, mps=%d\n",
  104060. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  104061. + dwc_ep->type, dwc_ep->maxpacket);
  104062. +
  104063. + diepint.d32 =
  104064. + dwc_otg_read_dev_in_ep_intr(core_if, dwc_ep);
  104065. +
  104066. + DWC_DEBUGPL(DBG_PCDV,
  104067. + "EP %d Interrupt Register - 0x%x\n", epnum,
  104068. + diepint.d32);
  104069. + /* Transfer complete */
  104070. + if (diepint.b.xfercompl) {
  104071. + /* Disable the NP Tx FIFO Empty
  104072. + * Interrupt */
  104073. + if (core_if->en_multiple_tx_fifo == 0) {
  104074. + intr_mask.b.nptxfempty = 1;
  104075. + DWC_MODIFY_REG32
  104076. + (&core_if->core_global_regs->gintmsk,
  104077. + intr_mask.d32, 0);
  104078. + } else {
  104079. + /* Disable the Tx FIFO Empty Interrupt for this EP */
  104080. + uint32_t fifoemptymsk =
  104081. + 0x1 << dwc_ep->num;
  104082. + DWC_MODIFY_REG32(&core_if->
  104083. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  104084. + fifoemptymsk, 0);
  104085. + }
  104086. + /* Clear the bit in DIEPINTn for this interrupt */
  104087. + CLEAR_IN_EP_INTR(core_if, epnum, xfercompl);
  104088. +
  104089. + /* Complete the transfer */
  104090. + if (epnum == 0) {
  104091. + handle_ep0(pcd);
  104092. + }
  104093. +#ifdef DWC_EN_ISOC
  104094. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  104095. + if (!ep->stopped)
  104096. + complete_iso_ep(pcd, ep);
  104097. + }
  104098. +#endif /* DWC_EN_ISOC */
  104099. +#ifdef DWC_UTE_PER_IO
  104100. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  104101. + if (!ep->stopped)
  104102. + complete_xiso_ep(ep);
  104103. + }
  104104. +#endif /* DWC_UTE_PER_IO */
  104105. + else {
  104106. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC &&
  104107. + dwc_ep->bInterval > 1) {
  104108. + dwc_ep->frame_num += dwc_ep->bInterval;
  104109. + if (dwc_ep->frame_num > 0x3FFF)
  104110. + {
  104111. + dwc_ep->frm_overrun = 1;
  104112. + dwc_ep->frame_num &= 0x3FFF;
  104113. + } else
  104114. + dwc_ep->frm_overrun = 0;
  104115. + }
  104116. + complete_ep(ep);
  104117. + if(diepint.b.nak)
  104118. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  104119. + }
  104120. + }
  104121. + /* Endpoint disable */
  104122. + if (diepint.b.epdisabled) {
  104123. + DWC_DEBUGPL(DBG_ANY, "EP%d IN disabled\n",
  104124. + epnum);
  104125. + handle_in_ep_disable_intr(pcd, epnum);
  104126. +
  104127. + /* Clear the bit in DIEPINTn for this interrupt */
  104128. + CLEAR_IN_EP_INTR(core_if, epnum, epdisabled);
  104129. + }
  104130. + /* AHB Error */
  104131. + if (diepint.b.ahberr) {
  104132. + DWC_ERROR("EP%d IN AHB Error\n", epnum);
  104133. + /* Clear the bit in DIEPINTn for this interrupt */
  104134. + CLEAR_IN_EP_INTR(core_if, epnum, ahberr);
  104135. + }
  104136. + /* TimeOUT Handshake (non-ISOC IN EPs) */
  104137. + if (diepint.b.timeout) {
  104138. + DWC_ERROR("EP%d IN Time-out\n", epnum);
  104139. + handle_in_ep_timeout_intr(pcd, epnum);
  104140. +
  104141. + CLEAR_IN_EP_INTR(core_if, epnum, timeout);
  104142. + }
  104143. + /** IN Token received with TxF Empty */
  104144. + if (diepint.b.intktxfemp) {
  104145. + DWC_DEBUGPL(DBG_ANY,
  104146. + "EP%d IN TKN TxFifo Empty\n",
  104147. + epnum);
  104148. + if (!ep->stopped && epnum != 0) {
  104149. +
  104150. + diepmsk_data_t diepmsk = {.d32 = 0 };
  104151. + diepmsk.b.intktxfemp = 1;
  104152. +
  104153. + if (core_if->multiproc_int_enable) {
  104154. + DWC_MODIFY_REG32
  104155. + (&dev_if->dev_global_regs->diepeachintmsk
  104156. + [epnum], diepmsk.d32, 0);
  104157. + } else {
  104158. + DWC_MODIFY_REG32
  104159. + (&dev_if->dev_global_regs->diepmsk,
  104160. + diepmsk.d32, 0);
  104161. + }
  104162. + } else if (core_if->dma_desc_enable
  104163. + && epnum == 0
  104164. + && pcd->ep0state ==
  104165. + EP0_OUT_STATUS_PHASE) {
  104166. + // EP0 IN set STALL
  104167. + depctl.d32 =
  104168. + DWC_READ_REG32(&dev_if->in_ep_regs
  104169. + [epnum]->diepctl);
  104170. +
  104171. + /* set the disable and stall bits */
  104172. + if (depctl.b.epena) {
  104173. + depctl.b.epdis = 1;
  104174. + }
  104175. + depctl.b.stall = 1;
  104176. + DWC_WRITE_REG32(&dev_if->in_ep_regs
  104177. + [epnum]->diepctl,
  104178. + depctl.d32);
  104179. + }
  104180. + CLEAR_IN_EP_INTR(core_if, epnum, intktxfemp);
  104181. + }
  104182. + /** IN Token Received with EP mismatch */
  104183. + if (diepint.b.intknepmis) {
  104184. + DWC_DEBUGPL(DBG_ANY,
  104185. + "EP%d IN TKN EP Mismatch\n", epnum);
  104186. + CLEAR_IN_EP_INTR(core_if, epnum, intknepmis);
  104187. + }
  104188. + /** IN Endpoint NAK Effective */
  104189. + if (diepint.b.inepnakeff) {
  104190. + DWC_DEBUGPL(DBG_ANY,
  104191. + "EP%d IN EP NAK Effective\n",
  104192. + epnum);
  104193. + /* Periodic EP */
  104194. + if (ep->disabling) {
  104195. + depctl.d32 = 0;
  104196. + depctl.b.snak = 1;
  104197. + depctl.b.epdis = 1;
  104198. + DWC_MODIFY_REG32(&dev_if->in_ep_regs
  104199. + [epnum]->diepctl,
  104200. + depctl.d32,
  104201. + depctl.d32);
  104202. + }
  104203. + CLEAR_IN_EP_INTR(core_if, epnum, inepnakeff);
  104204. +
  104205. + }
  104206. +
  104207. + /** IN EP Tx FIFO Empty Intr */
  104208. + if (diepint.b.emptyintr) {
  104209. + DWC_DEBUGPL(DBG_ANY,
  104210. + "EP%d Tx FIFO Empty Intr \n",
  104211. + epnum);
  104212. + write_empty_tx_fifo(pcd, epnum);
  104213. +
  104214. + CLEAR_IN_EP_INTR(core_if, epnum, emptyintr);
  104215. +
  104216. + }
  104217. +
  104218. + /** IN EP BNA Intr */
  104219. + if (diepint.b.bna) {
  104220. + CLEAR_IN_EP_INTR(core_if, epnum, bna);
  104221. + if (core_if->dma_desc_enable) {
  104222. +#ifdef DWC_EN_ISOC
  104223. + if (dwc_ep->type ==
  104224. + DWC_OTG_EP_TYPE_ISOC) {
  104225. + /*
  104226. + * This checking is performed to prevent first "false" BNA
  104227. + * handling occuring right after reconnect
  104228. + */
  104229. + if (dwc_ep->next_frame !=
  104230. + 0xffffffff)
  104231. + dwc_otg_pcd_handle_iso_bna(ep);
  104232. + } else
  104233. +#endif /* DWC_EN_ISOC */
  104234. + {
  104235. + dwc_otg_pcd_handle_noniso_bna(ep);
  104236. + }
  104237. + }
  104238. + }
  104239. + /* NAK Interrutp */
  104240. + if (diepint.b.nak) {
  104241. + DWC_DEBUGPL(DBG_ANY, "EP%d IN NAK Interrupt\n",
  104242. + epnum);
  104243. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  104244. + depctl_data_t depctl;
  104245. + if (ep->dwc_ep.frame_num == 0xFFFFFFFF) {
  104246. + ep->dwc_ep.frame_num = core_if->frame_num;
  104247. + if (ep->dwc_ep.bInterval > 1) {
  104248. + depctl.d32 = 0;
  104249. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  104250. + if (ep->dwc_ep.frame_num & 0x1) {
  104251. + depctl.b.setd1pid = 1;
  104252. + depctl.b.setd0pid = 0;
  104253. + } else {
  104254. + depctl.b.setd0pid = 1;
  104255. + depctl.b.setd1pid = 0;
  104256. + }
  104257. + DWC_WRITE_REG32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32);
  104258. + }
  104259. + start_next_request(ep);
  104260. + }
  104261. + ep->dwc_ep.frame_num += ep->dwc_ep.bInterval;
  104262. + if (dwc_ep->frame_num > 0x3FFF) {
  104263. + dwc_ep->frm_overrun = 1;
  104264. + dwc_ep->frame_num &= 0x3FFF;
  104265. + } else
  104266. + dwc_ep->frm_overrun = 0;
  104267. + }
  104268. +
  104269. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  104270. + }
  104271. + }
  104272. + epnum++;
  104273. + ep_intr >>= 1;
  104274. + }
  104275. +
  104276. + return 1;
  104277. +#undef CLEAR_IN_EP_INTR
  104278. +}
  104279. +
  104280. +/**
  104281. + * This interrupt indicates that an OUT EP has a pending Interrupt.
  104282. + * The sequence for handling the OUT EP interrupt is shown below:
  104283. + * -# Read the Device All Endpoint Interrupt register
  104284. + * -# Repeat the following for each OUT EP interrupt bit set (from
  104285. + * LSB to MSB).
  104286. + * -# Read the Device Endpoint Interrupt (DOEPINTn) register
  104287. + * -# If "Transfer Complete" call the request complete function
  104288. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  104289. + * -# If "AHB Error Interrupt" log error
  104290. + * -# If "Setup Phase Done" process Setup Packet (See Standard USB
  104291. + * Command Processing)
  104292. + */
  104293. +static int32_t dwc_otg_pcd_handle_out_ep_intr(dwc_otg_pcd_t * pcd)
  104294. +{
  104295. +#define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \
  104296. +do { \
  104297. + doepint_data_t doepint = {.d32=0}; \
  104298. + doepint.b.__intr = 1; \
  104299. + DWC_WRITE_REG32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \
  104300. + doepint.d32); \
  104301. +} while (0)
  104302. +
  104303. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  104304. + uint32_t ep_intr;
  104305. + doepint_data_t doepint = {.d32 = 0 };
  104306. + uint32_t epnum = 0;
  104307. + dwc_otg_pcd_ep_t *ep;
  104308. + dwc_ep_t *dwc_ep;
  104309. + dctl_data_t dctl = {.d32 = 0 };
  104310. + gintmsk_data_t gintmsk = {.d32 = 0 };
  104311. +
  104312. +
  104313. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  104314. +
  104315. + /* Read in the device interrupt bits */
  104316. + ep_intr = dwc_otg_read_dev_all_out_ep_intr(core_if);
  104317. +
  104318. + while (ep_intr) {
  104319. + if (ep_intr & 0x1) {
  104320. + /* Get EP pointer */
  104321. + ep = get_out_ep(pcd, epnum);
  104322. + dwc_ep = &ep->dwc_ep;
  104323. +
  104324. +#ifdef VERBOSE
  104325. + DWC_DEBUGPL(DBG_PCDV,
  104326. + "EP%d-%s: type=%d, mps=%d\n",
  104327. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  104328. + dwc_ep->type, dwc_ep->maxpacket);
  104329. +#endif
  104330. + doepint.d32 =
  104331. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep);
  104332. + /* Moved this interrupt upper due to core deffect of asserting
  104333. + * OUT EP 0 xfercompl along with stsphsrcvd in BDMA */
  104334. + if (doepint.b.stsphsercvd) {
  104335. + deptsiz0_data_t deptsiz;
  104336. + CLEAR_OUT_EP_INTR(core_if, epnum, stsphsercvd);
  104337. + deptsiz.d32 =
  104338. + DWC_READ_REG32(&core_if->dev_if->
  104339. + out_ep_regs[0]->doeptsiz);
  104340. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  104341. + && core_if->dma_enable
  104342. + && core_if->dma_desc_enable == 0
  104343. + && doepint.b.xfercompl
  104344. + && deptsiz.b.xfersize == 24) {
  104345. + CLEAR_OUT_EP_INTR(core_if, epnum,
  104346. + xfercompl);
  104347. + doepint.b.xfercompl = 0;
  104348. + ep0_out_start(core_if, pcd);
  104349. + }
  104350. + if ((core_if->dma_desc_enable) ||
  104351. + (core_if->dma_enable
  104352. + && core_if->snpsid >=
  104353. + OTG_CORE_REV_3_00a)) {
  104354. + do_setup_in_status_phase(pcd);
  104355. + }
  104356. + }
  104357. + /* Transfer complete */
  104358. + if (doepint.b.xfercompl) {
  104359. +
  104360. + if (epnum == 0) {
  104361. + /* Clear the bit in DOEPINTn for this interrupt */
  104362. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  104363. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  104364. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  104365. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepint),
  104366. + doepint.d32);
  104367. + DWC_DEBUGPL(DBG_PCDV, "DOEPCTL=%x \n",
  104368. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepctl));
  104369. +
  104370. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  104371. + && core_if->dma_enable == 0) {
  104372. + doepint_data_t doepint;
  104373. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  104374. + out_ep_regs[0]->doepint);
  104375. + if (pcd->ep0state == EP0_IDLE && doepint.b.sr) {
  104376. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  104377. + goto exit_xfercompl;
  104378. + }
  104379. + }
  104380. + /* In case of DDMA look at SR bit to go to the Data Stage */
  104381. + if (core_if->dma_desc_enable) {
  104382. + dev_dma_desc_sts_t status = {.d32 = 0};
  104383. + if (pcd->ep0state == EP0_IDLE) {
  104384. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  104385. + dev_if->setup_desc_index]->status.d32;
  104386. + if(pcd->data_terminated) {
  104387. + pcd->data_terminated = 0;
  104388. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  104389. + dwc_memcpy(&pcd->setup_pkt->req, pcd->backup_buf, 8);
  104390. + }
  104391. + if (status.b.sr) {
  104392. + if (doepint.b.setup) {
  104393. + DWC_DEBUGPL(DBG_PCDV, "DMA DESC EP0_IDLE SR=1 setup=1\n");
  104394. + /* Already started data stage, clear setup */
  104395. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  104396. + doepint.b.setup = 0;
  104397. + handle_ep0(pcd);
  104398. + /* Prepare for more setup packets */
  104399. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  104400. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  104401. + ep0_out_start(core_if, pcd);
  104402. + }
  104403. +
  104404. + goto exit_xfercompl;
  104405. + } else {
  104406. + /* Prepare for more setup packets */
  104407. + DWC_DEBUGPL(DBG_PCDV,
  104408. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  104409. + ep0_out_start(core_if, pcd);
  104410. + }
  104411. + }
  104412. + } else {
  104413. + dwc_otg_pcd_request_t *req;
  104414. + dev_dma_desc_sts_t status = {.d32 = 0};
  104415. + diepint_data_t diepint0;
  104416. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  104417. + in_ep_regs[0]->diepint);
  104418. +
  104419. + if (pcd->ep0state == EP0_STALL || pcd->ep0state == EP0_DISCONNECT) {
  104420. + DWC_ERROR("EP0 is stalled/disconnected\n");
  104421. + }
  104422. +
  104423. + /* Clear IN xfercompl if set */
  104424. + if (diepint0.b.xfercompl && (pcd->ep0state == EP0_IN_STATUS_PHASE
  104425. + || pcd->ep0state == EP0_IN_DATA_PHASE)) {
  104426. + DWC_WRITE_REG32(&core_if->dev_if->
  104427. + in_ep_regs[0]->diepint, diepint0.d32);
  104428. + }
  104429. +
  104430. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  104431. + dev_if->setup_desc_index]->status.d32;
  104432. +
  104433. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len
  104434. + && (pcd->ep0state == EP0_OUT_DATA_PHASE))
  104435. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  104436. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE)
  104437. + status.d32 = core_if->dev_if->
  104438. + out_desc_addr->status.d32;
  104439. +
  104440. + if (status.b.sr) {
  104441. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  104442. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  104443. + } else {
  104444. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  104445. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  104446. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  104447. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  104448. + /* Read arrived setup packet from req->buf */
  104449. + dwc_memcpy(&pcd->setup_pkt->req,
  104450. + req->buf + ep->dwc_ep.xfer_count, 8);
  104451. + }
  104452. + req->actual = ep->dwc_ep.xfer_count;
  104453. + dwc_otg_request_done(ep, req, -ECONNRESET);
  104454. + ep->dwc_ep.start_xfer_buff = 0;
  104455. + ep->dwc_ep.xfer_buff = 0;
  104456. + ep->dwc_ep.xfer_len = 0;
  104457. + }
  104458. + pcd->ep0state = EP0_IDLE;
  104459. + if (doepint.b.setup) {
  104460. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  104461. + /* Data stage started, clear setup */
  104462. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  104463. + doepint.b.setup = 0;
  104464. + handle_ep0(pcd);
  104465. + /* Prepare for setup packets if ep0in was enabled*/
  104466. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  104467. + ep0_out_start(core_if, pcd);
  104468. + }
  104469. +
  104470. + goto exit_xfercompl;
  104471. + } else {
  104472. + /* Prepare for more setup packets */
  104473. + DWC_DEBUGPL(DBG_PCDV,
  104474. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  104475. + ep0_out_start(core_if, pcd);
  104476. + }
  104477. + }
  104478. + }
  104479. + }
  104480. + if (core_if->snpsid >= OTG_CORE_REV_2_94a && core_if->dma_enable
  104481. + && core_if->dma_desc_enable == 0) {
  104482. + doepint_data_t doepint_temp = {.d32 = 0};
  104483. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  104484. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  104485. + out_ep_regs[ep->dwc_ep.num]->doepint);
  104486. + doeptsize0.d32 = DWC_READ_REG32(&core_if->dev_if->
  104487. + out_ep_regs[ep->dwc_ep.num]->doeptsiz);
  104488. + if (pcd->ep0state == EP0_IDLE) {
  104489. + if (doepint_temp.b.sr) {
  104490. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  104491. + }
  104492. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  104493. + out_ep_regs[0]->doepint);
  104494. + if (doeptsize0.b.supcnt == 3) {
  104495. + DWC_DEBUGPL(DBG_ANY, "Rolling over!!!!!!!\n");
  104496. + ep->dwc_ep.stp_rollover = 1;
  104497. + }
  104498. + if (doepint.b.setup) {
  104499. +retry:
  104500. + /* Already started data stage, clear setup */
  104501. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  104502. + doepint.b.setup = 0;
  104503. + handle_ep0(pcd);
  104504. + ep->dwc_ep.stp_rollover = 0;
  104505. + /* Prepare for more setup packets */
  104506. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  104507. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  104508. + ep0_out_start(core_if, pcd);
  104509. + }
  104510. + goto exit_xfercompl;
  104511. + } else {
  104512. + /* Prepare for more setup packets */
  104513. + DWC_DEBUGPL(DBG_ANY,
  104514. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  104515. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  104516. + out_ep_regs[0]->doepint);
  104517. + if(doepint.b.setup)
  104518. + goto retry;
  104519. + ep0_out_start(core_if, pcd);
  104520. + }
  104521. + } else {
  104522. + dwc_otg_pcd_request_t *req;
  104523. + diepint_data_t diepint0 = {.d32 = 0};
  104524. + doepint_data_t doepint_temp = {.d32 = 0};
  104525. + depctl_data_t diepctl0;
  104526. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  104527. + in_ep_regs[0]->diepint);
  104528. + diepctl0.d32 = DWC_READ_REG32(&core_if->dev_if->
  104529. + in_ep_regs[0]->diepctl);
  104530. +
  104531. + if (pcd->ep0state == EP0_IN_DATA_PHASE
  104532. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  104533. + if (diepint0.b.xfercompl) {
  104534. + DWC_WRITE_REG32(&core_if->dev_if->
  104535. + in_ep_regs[0]->diepint, diepint0.d32);
  104536. + }
  104537. + if (diepctl0.b.epena) {
  104538. + diepint_data_t diepint = {.d32 = 0};
  104539. + diepctl0.b.snak = 1;
  104540. + DWC_WRITE_REG32(&core_if->dev_if->
  104541. + in_ep_regs[0]->diepctl, diepctl0.d32);
  104542. + do {
  104543. + dwc_udelay(10);
  104544. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  104545. + in_ep_regs[0]->diepint);
  104546. + } while (!diepint.b.inepnakeff);
  104547. + diepint.b.inepnakeff = 1;
  104548. + DWC_WRITE_REG32(&core_if->dev_if->
  104549. + in_ep_regs[0]->diepint, diepint.d32);
  104550. + diepctl0.d32 = 0;
  104551. + diepctl0.b.epdis = 1;
  104552. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl,
  104553. + diepctl0.d32);
  104554. + do {
  104555. + dwc_udelay(10);
  104556. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  104557. + in_ep_regs[0]->diepint);
  104558. + } while (!diepint.b.epdisabled);
  104559. + diepint.b.epdisabled = 1;
  104560. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepint,
  104561. + diepint.d32);
  104562. + }
  104563. + }
  104564. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  104565. + out_ep_regs[ep->dwc_ep.num]->doepint);
  104566. + if (doepint_temp.b.sr) {
  104567. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  104568. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  104569. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  104570. + } else {
  104571. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  104572. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  104573. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  104574. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  104575. + /* Read arrived setup packet from req->buf */
  104576. + dwc_memcpy(&pcd->setup_pkt->req,
  104577. + req->buf + ep->dwc_ep.xfer_count, 8);
  104578. + }
  104579. + req->actual = ep->dwc_ep.xfer_count;
  104580. + dwc_otg_request_done(ep, req, -ECONNRESET);
  104581. + ep->dwc_ep.start_xfer_buff = 0;
  104582. + ep->dwc_ep.xfer_buff = 0;
  104583. + ep->dwc_ep.xfer_len = 0;
  104584. + }
  104585. + pcd->ep0state = EP0_IDLE;
  104586. + if (doepint.b.setup) {
  104587. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  104588. + /* Data stage started, clear setup */
  104589. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  104590. + doepint.b.setup = 0;
  104591. + handle_ep0(pcd);
  104592. + /* Prepare for setup packets if ep0in was enabled*/
  104593. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  104594. + ep0_out_start(core_if, pcd);
  104595. + }
  104596. + goto exit_xfercompl;
  104597. + } else {
  104598. + /* Prepare for more setup packets */
  104599. + DWC_DEBUGPL(DBG_PCDV,
  104600. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  104601. + ep0_out_start(core_if, pcd);
  104602. + }
  104603. + }
  104604. + }
  104605. + }
  104606. + if (core_if->dma_enable == 0 || pcd->ep0state != EP0_IDLE)
  104607. + handle_ep0(pcd);
  104608. +exit_xfercompl:
  104609. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  104610. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep), doepint.d32);
  104611. + } else {
  104612. + if (core_if->dma_desc_enable == 0
  104613. + || pcd->ep0state != EP0_IDLE)
  104614. + handle_ep0(pcd);
  104615. + }
  104616. +#ifdef DWC_EN_ISOC
  104617. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  104618. + if (doepint.b.pktdrpsts == 0) {
  104619. + /* Clear the bit in DOEPINTn for this interrupt */
  104620. + CLEAR_OUT_EP_INTR(core_if,
  104621. + epnum,
  104622. + xfercompl);
  104623. + complete_iso_ep(pcd, ep);
  104624. + } else {
  104625. +
  104626. + doepint_data_t doepint = {.d32 = 0 };
  104627. + doepint.b.xfercompl = 1;
  104628. + doepint.b.pktdrpsts = 1;
  104629. + DWC_WRITE_REG32
  104630. + (&core_if->dev_if->out_ep_regs
  104631. + [epnum]->doepint,
  104632. + doepint.d32);
  104633. + if (handle_iso_out_pkt_dropped
  104634. + (core_if, dwc_ep)) {
  104635. + complete_iso_ep(pcd,
  104636. + ep);
  104637. + }
  104638. + }
  104639. +#endif /* DWC_EN_ISOC */
  104640. +#ifdef DWC_UTE_PER_IO
  104641. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  104642. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  104643. + if (!ep->stopped)
  104644. + complete_xiso_ep(ep);
  104645. +#endif /* DWC_UTE_PER_IO */
  104646. + } else {
  104647. + /* Clear the bit in DOEPINTn for this interrupt */
  104648. + CLEAR_OUT_EP_INTR(core_if, epnum,
  104649. + xfercompl);
  104650. +
  104651. + if (core_if->core_params->dev_out_nak) {
  104652. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[epnum]);
  104653. + pcd->core_if->ep_xfer_info[epnum].state = 0;
  104654. +#ifdef DEBUG
  104655. + print_memory_payload(pcd, dwc_ep);
  104656. +#endif
  104657. + }
  104658. + complete_ep(ep);
  104659. + }
  104660. +
  104661. + }
  104662. +
  104663. + /* Endpoint disable */
  104664. + if (doepint.b.epdisabled) {
  104665. +
  104666. + /* Clear the bit in DOEPINTn for this interrupt */
  104667. + CLEAR_OUT_EP_INTR(core_if, epnum, epdisabled);
  104668. + if (core_if->core_params->dev_out_nak) {
  104669. +#ifdef DEBUG
  104670. + print_memory_payload(pcd, dwc_ep);
  104671. +#endif
  104672. + /* In case of timeout condition */
  104673. + if (core_if->ep_xfer_info[epnum].state == 2) {
  104674. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  104675. + dev_global_regs->dctl);
  104676. + dctl.b.cgoutnak = 1;
  104677. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  104678. + dctl.d32);
  104679. + /* Unmask goutnakeff interrupt which was masked
  104680. + * during handle nak out interrupt */
  104681. + gintmsk.b.goutnakeff = 1;
  104682. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  104683. + 0, gintmsk.d32);
  104684. +
  104685. + complete_ep(ep);
  104686. + }
  104687. + }
  104688. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  104689. + {
  104690. + dctl_data_t dctl;
  104691. + gintmsk_data_t intr_mask = {.d32 = 0};
  104692. + dwc_otg_pcd_request_t *req = 0;
  104693. +
  104694. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  104695. + dev_global_regs->dctl);
  104696. + dctl.b.cgoutnak = 1;
  104697. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  104698. + dctl.d32);
  104699. +
  104700. + intr_mask.d32 = 0;
  104701. + intr_mask.b.incomplisoout = 1;
  104702. +
  104703. + /* Get any pending requests */
  104704. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  104705. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  104706. + if (!req) {
  104707. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  104708. + } else {
  104709. + dwc_otg_request_done(ep, req, 0);
  104710. + start_next_request(ep);
  104711. + }
  104712. + } else {
  104713. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  104714. + }
  104715. + }
  104716. + }
  104717. + /* AHB Error */
  104718. + if (doepint.b.ahberr) {
  104719. + DWC_ERROR("EP%d OUT AHB Error\n", epnum);
  104720. + DWC_ERROR("EP%d DEPDMA=0x%08x \n",
  104721. + epnum, core_if->dev_if->out_ep_regs[epnum]->doepdma);
  104722. + CLEAR_OUT_EP_INTR(core_if, epnum, ahberr);
  104723. + }
  104724. + /* Setup Phase Done (contorl EPs) */
  104725. + if (doepint.b.setup) {
  104726. +#ifdef DEBUG_EP0
  104727. + DWC_DEBUGPL(DBG_PCD, "EP%d SETUP Done\n", epnum);
  104728. +#endif
  104729. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  104730. +
  104731. + handle_ep0(pcd);
  104732. + }
  104733. +
  104734. + /** OUT EP BNA Intr */
  104735. + if (doepint.b.bna) {
  104736. + CLEAR_OUT_EP_INTR(core_if, epnum, bna);
  104737. + if (core_if->dma_desc_enable) {
  104738. +#ifdef DWC_EN_ISOC
  104739. + if (dwc_ep->type ==
  104740. + DWC_OTG_EP_TYPE_ISOC) {
  104741. + /*
  104742. + * This checking is performed to prevent first "false" BNA
  104743. + * handling occuring right after reconnect
  104744. + */
  104745. + if (dwc_ep->next_frame !=
  104746. + 0xffffffff)
  104747. + dwc_otg_pcd_handle_iso_bna(ep);
  104748. + } else
  104749. +#endif /* DWC_EN_ISOC */
  104750. + {
  104751. + dwc_otg_pcd_handle_noniso_bna(ep);
  104752. + }
  104753. + }
  104754. + }
  104755. + /* Babble Interrupt */
  104756. + if (doepint.b.babble) {
  104757. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Babble\n",
  104758. + epnum);
  104759. + handle_out_ep_babble_intr(pcd, epnum);
  104760. +
  104761. + CLEAR_OUT_EP_INTR(core_if, epnum, babble);
  104762. + }
  104763. + if (doepint.b.outtknepdis) {
  104764. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Token received when EP is \
  104765. + disabled\n",epnum);
  104766. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  104767. + doepmsk_data_t doepmsk = {.d32 = 0};
  104768. + ep->dwc_ep.frame_num = core_if->frame_num;
  104769. + if (ep->dwc_ep.bInterval > 1) {
  104770. + depctl_data_t depctl;
  104771. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  104772. + out_ep_regs[epnum]->doepctl);
  104773. + if (ep->dwc_ep.frame_num & 0x1) {
  104774. + depctl.b.setd1pid = 1;
  104775. + depctl.b.setd0pid = 0;
  104776. + } else {
  104777. + depctl.b.setd0pid = 1;
  104778. + depctl.b.setd1pid = 0;
  104779. + }
  104780. + DWC_WRITE_REG32(&core_if->dev_if->
  104781. + out_ep_regs[epnum]->doepctl, depctl.d32);
  104782. + }
  104783. + start_next_request(ep);
  104784. + doepmsk.b.outtknepdis = 1;
  104785. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  104786. + doepmsk.d32, 0);
  104787. + }
  104788. + CLEAR_OUT_EP_INTR(core_if, epnum, outtknepdis);
  104789. + }
  104790. +
  104791. + /* NAK Interrutp */
  104792. + if (doepint.b.nak) {
  104793. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NAK\n", epnum);
  104794. + handle_out_ep_nak_intr(pcd, epnum);
  104795. +
  104796. + CLEAR_OUT_EP_INTR(core_if, epnum, nak);
  104797. + }
  104798. + /* NYET Interrutp */
  104799. + if (doepint.b.nyet) {
  104800. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NYET\n", epnum);
  104801. + handle_out_ep_nyet_intr(pcd, epnum);
  104802. +
  104803. + CLEAR_OUT_EP_INTR(core_if, epnum, nyet);
  104804. + }
  104805. + }
  104806. +
  104807. + epnum++;
  104808. + ep_intr >>= 1;
  104809. + }
  104810. +
  104811. + return 1;
  104812. +
  104813. +#undef CLEAR_OUT_EP_INTR
  104814. +}
  104815. +static int drop_transfer(uint32_t trgt_fr, uint32_t curr_fr, uint8_t frm_overrun)
  104816. +{
  104817. + int retval = 0;
  104818. + if(!frm_overrun && curr_fr >= trgt_fr)
  104819. + retval = 1;
  104820. + else if (frm_overrun
  104821. + && (curr_fr >= trgt_fr && ((curr_fr - trgt_fr) < 0x3FFF / 2)))
  104822. + retval = 1;
  104823. + return retval;
  104824. +}
  104825. +/**
  104826. + * Incomplete ISO IN Transfer Interrupt.
  104827. + * This interrupt indicates one of the following conditions occurred
  104828. + * while transmitting an ISOC transaction.
  104829. + * - Corrupted IN Token for ISOC EP.
  104830. + * - Packet not complete in FIFO.
  104831. + * The follow actions will be taken:
  104832. + * -# Determine the EP
  104833. + * -# Set incomplete flag in dwc_ep structure
  104834. + * -# Disable EP; when "Endpoint Disabled" interrupt is received
  104835. + * Flush FIFO
  104836. + */
  104837. +int32_t dwc_otg_pcd_handle_incomplete_isoc_in_intr(dwc_otg_pcd_t * pcd)
  104838. +{
  104839. + gintsts_data_t gintsts;
  104840. +
  104841. +#ifdef DWC_EN_ISOC
  104842. + dwc_otg_dev_if_t *dev_if;
  104843. + deptsiz_data_t deptsiz = {.d32 = 0 };
  104844. + depctl_data_t depctl = {.d32 = 0 };
  104845. + dsts_data_t dsts = {.d32 = 0 };
  104846. + dwc_ep_t *dwc_ep;
  104847. + int i;
  104848. +
  104849. + dev_if = GET_CORE_IF(pcd)->dev_if;
  104850. +
  104851. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  104852. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  104853. + if (dwc_ep->active && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  104854. + deptsiz.d32 =
  104855. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  104856. + depctl.d32 =
  104857. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  104858. +
  104859. + if (depctl.b.epdis && deptsiz.d32) {
  104860. + set_current_pkt_info(GET_CORE_IF(pcd), dwc_ep);
  104861. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  104862. + dwc_ep->cur_pkt = 0;
  104863. + dwc_ep->proc_buf_num =
  104864. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  104865. +
  104866. + if (dwc_ep->proc_buf_num) {
  104867. + dwc_ep->cur_pkt_addr =
  104868. + dwc_ep->xfer_buff1;
  104869. + dwc_ep->cur_pkt_dma_addr =
  104870. + dwc_ep->dma_addr1;
  104871. + } else {
  104872. + dwc_ep->cur_pkt_addr =
  104873. + dwc_ep->xfer_buff0;
  104874. + dwc_ep->cur_pkt_dma_addr =
  104875. + dwc_ep->dma_addr0;
  104876. + }
  104877. +
  104878. + }
  104879. +
  104880. + dsts.d32 =
  104881. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  104882. + dev_global_regs->dsts);
  104883. + dwc_ep->next_frame = dsts.b.soffn;
  104884. +
  104885. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  104886. + (pcd),
  104887. + dwc_ep);
  104888. + }
  104889. + }
  104890. + }
  104891. +
  104892. +#else
  104893. + depctl_data_t depctl = {.d32 = 0 };
  104894. + dwc_ep_t *dwc_ep;
  104895. + dwc_otg_dev_if_t *dev_if;
  104896. + int i;
  104897. + dev_if = GET_CORE_IF(pcd)->dev_if;
  104898. +
  104899. + DWC_DEBUGPL(DBG_PCD,"Incomplete ISO IN \n");
  104900. +
  104901. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  104902. + dwc_ep = &pcd->in_ep[i-1].dwc_ep;
  104903. + depctl.d32 =
  104904. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  104905. + if (depctl.b.epena && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  104906. + if (drop_transfer(dwc_ep->frame_num, GET_CORE_IF(pcd)->frame_num,
  104907. + dwc_ep->frm_overrun))
  104908. + {
  104909. + depctl.d32 =
  104910. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  104911. + depctl.b.snak = 1;
  104912. + depctl.b.epdis = 1;
  104913. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32, depctl.d32);
  104914. + }
  104915. + }
  104916. + }
  104917. +
  104918. + /*intr_mask.b.incomplisoin = 1;
  104919. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  104920. + intr_mask.d32, 0); */
  104921. +#endif //DWC_EN_ISOC
  104922. +
  104923. + /* Clear interrupt */
  104924. + gintsts.d32 = 0;
  104925. + gintsts.b.incomplisoin = 1;
  104926. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  104927. + gintsts.d32);
  104928. +
  104929. + return 1;
  104930. +}
  104931. +
  104932. +/**
  104933. + * Incomplete ISO OUT Transfer Interrupt.
  104934. + *
  104935. + * This interrupt indicates that the core has dropped an ISO OUT
  104936. + * packet. The following conditions can be the cause:
  104937. + * - FIFO Full, the entire packet would not fit in the FIFO.
  104938. + * - CRC Error
  104939. + * - Corrupted Token
  104940. + * The follow actions will be taken:
  104941. + * -# Determine the EP
  104942. + * -# Set incomplete flag in dwc_ep structure
  104943. + * -# Read any data from the FIFO
  104944. + * -# Disable EP. When "Endpoint Disabled" interrupt is received
  104945. + * re-enable EP.
  104946. + */
  104947. +int32_t dwc_otg_pcd_handle_incomplete_isoc_out_intr(dwc_otg_pcd_t * pcd)
  104948. +{
  104949. +
  104950. + gintsts_data_t gintsts;
  104951. +
  104952. +#ifdef DWC_EN_ISOC
  104953. + dwc_otg_dev_if_t *dev_if;
  104954. + deptsiz_data_t deptsiz = {.d32 = 0 };
  104955. + depctl_data_t depctl = {.d32 = 0 };
  104956. + dsts_data_t dsts = {.d32 = 0 };
  104957. + dwc_ep_t *dwc_ep;
  104958. + int i;
  104959. +
  104960. + dev_if = GET_CORE_IF(pcd)->dev_if;
  104961. +
  104962. + for (i = 1; i <= dev_if->num_out_eps; ++i) {
  104963. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  104964. + if (pcd->out_ep[i].dwc_ep.active &&
  104965. + pcd->out_ep[i].dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  104966. + deptsiz.d32 =
  104967. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doeptsiz);
  104968. + depctl.d32 =
  104969. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  104970. +
  104971. + if (depctl.b.epdis && deptsiz.d32) {
  104972. + set_current_pkt_info(GET_CORE_IF(pcd),
  104973. + &pcd->out_ep[i].dwc_ep);
  104974. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  104975. + dwc_ep->cur_pkt = 0;
  104976. + dwc_ep->proc_buf_num =
  104977. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  104978. +
  104979. + if (dwc_ep->proc_buf_num) {
  104980. + dwc_ep->cur_pkt_addr =
  104981. + dwc_ep->xfer_buff1;
  104982. + dwc_ep->cur_pkt_dma_addr =
  104983. + dwc_ep->dma_addr1;
  104984. + } else {
  104985. + dwc_ep->cur_pkt_addr =
  104986. + dwc_ep->xfer_buff0;
  104987. + dwc_ep->cur_pkt_dma_addr =
  104988. + dwc_ep->dma_addr0;
  104989. + }
  104990. +
  104991. + }
  104992. +
  104993. + dsts.d32 =
  104994. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  104995. + dev_global_regs->dsts);
  104996. + dwc_ep->next_frame = dsts.b.soffn;
  104997. +
  104998. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  104999. + (pcd),
  105000. + dwc_ep);
  105001. + }
  105002. + }
  105003. + }
  105004. +#else
  105005. + /** @todo implement ISR */
  105006. + gintmsk_data_t intr_mask = {.d32 = 0 };
  105007. + dwc_otg_core_if_t *core_if;
  105008. + deptsiz_data_t deptsiz = {.d32 = 0 };
  105009. + depctl_data_t depctl = {.d32 = 0 };
  105010. + dctl_data_t dctl = {.d32 = 0 };
  105011. + dwc_ep_t *dwc_ep = NULL;
  105012. + int i;
  105013. + core_if = GET_CORE_IF(pcd);
  105014. +
  105015. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  105016. + dwc_ep = &pcd->out_ep[i].dwc_ep;
  105017. + depctl.d32 =
  105018. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  105019. + if (depctl.b.epena && depctl.b.dpid == (core_if->frame_num & 0x1)) {
  105020. + core_if->dev_if->isoc_ep = dwc_ep;
  105021. + deptsiz.d32 =
  105022. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz);
  105023. + break;
  105024. + }
  105025. + }
  105026. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  105027. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  105028. + intr_mask.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  105029. +
  105030. + if (!intr_mask.b.goutnakeff) {
  105031. + /* Unmask it */
  105032. + intr_mask.b.goutnakeff = 1;
  105033. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32);
  105034. + }
  105035. + if (!gintsts.b.goutnakeff) {
  105036. + dctl.b.sgoutnak = 1;
  105037. + }
  105038. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  105039. +
  105040. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  105041. + if (depctl.b.epena) {
  105042. + depctl.b.epdis = 1;
  105043. + depctl.b.snak = 1;
  105044. + }
  105045. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl, depctl.d32);
  105046. +
  105047. + intr_mask.d32 = 0;
  105048. + intr_mask.b.incomplisoout = 1;
  105049. +
  105050. +#endif /* DWC_EN_ISOC */
  105051. +
  105052. + /* Clear interrupt */
  105053. + gintsts.d32 = 0;
  105054. + gintsts.b.incomplisoout = 1;
  105055. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  105056. + gintsts.d32);
  105057. +
  105058. + return 1;
  105059. +}
  105060. +
  105061. +/**
  105062. + * This function handles the Global IN NAK Effective interrupt.
  105063. + *
  105064. + */
  105065. +int32_t dwc_otg_pcd_handle_in_nak_effective(dwc_otg_pcd_t * pcd)
  105066. +{
  105067. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  105068. + depctl_data_t diepctl = {.d32 = 0 };
  105069. + gintmsk_data_t intr_mask = {.d32 = 0 };
  105070. + gintsts_data_t gintsts;
  105071. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  105072. + int i;
  105073. +
  105074. + DWC_DEBUGPL(DBG_PCD, "Global IN NAK Effective\n");
  105075. +
  105076. + /* Disable all active IN EPs */
  105077. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  105078. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  105079. + if (!(diepctl.b.eptype & 1) && diepctl.b.epena) {
  105080. + if (core_if->start_predict > 0)
  105081. + core_if->start_predict++;
  105082. + diepctl.b.epdis = 1;
  105083. + diepctl.b.snak = 1;
  105084. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, diepctl.d32);
  105085. + }
  105086. + }
  105087. +
  105088. +
  105089. + /* Disable the Global IN NAK Effective Interrupt */
  105090. + intr_mask.b.ginnakeff = 1;
  105091. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  105092. + intr_mask.d32, 0);
  105093. +
  105094. + /* Clear interrupt */
  105095. + gintsts.d32 = 0;
  105096. + gintsts.b.ginnakeff = 1;
  105097. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  105098. + gintsts.d32);
  105099. +
  105100. + return 1;
  105101. +}
  105102. +
  105103. +/**
  105104. + * OUT NAK Effective.
  105105. + *
  105106. + */
  105107. +int32_t dwc_otg_pcd_handle_out_nak_effective(dwc_otg_pcd_t * pcd)
  105108. +{
  105109. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  105110. + gintmsk_data_t intr_mask = {.d32 = 0 };
  105111. + gintsts_data_t gintsts;
  105112. + depctl_data_t doepctl;
  105113. + int i;
  105114. +
  105115. + /* Disable the Global OUT NAK Effective Interrupt */
  105116. + intr_mask.b.goutnakeff = 1;
  105117. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  105118. + intr_mask.d32, 0);
  105119. +
  105120. + /* If DEV OUT NAK enabled*/
  105121. + if (pcd->core_if->core_params->dev_out_nak) {
  105122. + /* Run over all out endpoints to determine the ep number on
  105123. + * which the timeout has happened
  105124. + */
  105125. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  105126. + if ( pcd->core_if->ep_xfer_info[i].state == 2 )
  105127. + break;
  105128. + }
  105129. + if (i > dev_if->num_out_eps) {
  105130. + dctl_data_t dctl;
  105131. + dctl.d32 =
  105132. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  105133. + dctl.b.cgoutnak = 1;
  105134. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl,
  105135. + dctl.d32);
  105136. + goto out;
  105137. + }
  105138. +
  105139. + /* Disable the endpoint */
  105140. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  105141. + if (doepctl.b.epena) {
  105142. + doepctl.b.epdis = 1;
  105143. + doepctl.b.snak = 1;
  105144. + }
  105145. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  105146. + return 1;
  105147. + }
  105148. + /* We come here from Incomplete ISO OUT handler */
  105149. + if (dev_if->isoc_ep) {
  105150. + dwc_ep_t *dwc_ep = (dwc_ep_t *)dev_if->isoc_ep;
  105151. + uint32_t epnum = dwc_ep->num;
  105152. + doepint_data_t doepint;
  105153. + doepint.d32 =
  105154. + DWC_READ_REG32(&dev_if->out_ep_regs[dwc_ep->num]->doepint);
  105155. + dev_if->isoc_ep = NULL;
  105156. + doepctl.d32 =
  105157. + DWC_READ_REG32(&dev_if->out_ep_regs[epnum]->doepctl);
  105158. + DWC_PRINTF("Before disable DOEPCTL = %08x\n", doepctl.d32);
  105159. + if (doepctl.b.epena) {
  105160. + doepctl.b.epdis = 1;
  105161. + doepctl.b.snak = 1;
  105162. + }
  105163. + DWC_WRITE_REG32(&dev_if->out_ep_regs[epnum]->doepctl,
  105164. + doepctl.d32);
  105165. + return 1;
  105166. + } else
  105167. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  105168. + "Global OUT NAK Effective\n");
  105169. +
  105170. +out:
  105171. + /* Clear interrupt */
  105172. + gintsts.d32 = 0;
  105173. + gintsts.b.goutnakeff = 1;
  105174. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  105175. + gintsts.d32);
  105176. +
  105177. + return 1;
  105178. +}
  105179. +
  105180. +/**
  105181. + * PCD interrupt handler.
  105182. + *
  105183. + * The PCD handles the device interrupts. Many conditions can cause a
  105184. + * device interrupt. When an interrupt occurs, the device interrupt
  105185. + * service routine determines the cause of the interrupt and
  105186. + * dispatches handling to the appropriate function. These interrupt
  105187. + * handling functions are described below.
  105188. + *
  105189. + * All interrupt registers are processed from LSB to MSB.
  105190. + *
  105191. + */
  105192. +int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd)
  105193. +{
  105194. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  105195. +#ifdef VERBOSE
  105196. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  105197. +#endif
  105198. + gintsts_data_t gintr_status;
  105199. + int32_t retval = 0;
  105200. +
  105201. + /* Exit from ISR if core is hibernated */
  105202. + if (core_if->hibernation_suspend == 1) {
  105203. + return retval;
  105204. + }
  105205. +#ifdef VERBOSE
  105206. + DWC_DEBUGPL(DBG_ANY, "%s() gintsts=%08x gintmsk=%08x\n",
  105207. + __func__,
  105208. + DWC_READ_REG32(&global_regs->gintsts),
  105209. + DWC_READ_REG32(&global_regs->gintmsk));
  105210. +#endif
  105211. +
  105212. + if (dwc_otg_is_device_mode(core_if)) {
  105213. + DWC_SPINLOCK(pcd->lock);
  105214. +#ifdef VERBOSE
  105215. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%08x gintmsk=%08x\n",
  105216. + __func__,
  105217. + DWC_READ_REG32(&global_regs->gintsts),
  105218. + DWC_READ_REG32(&global_regs->gintmsk));
  105219. +#endif
  105220. +
  105221. + gintr_status.d32 = dwc_otg_read_core_intr(core_if);
  105222. +
  105223. + DWC_DEBUGPL(DBG_PCDV, "%s: gintsts&gintmsk=%08x\n",
  105224. + __func__, gintr_status.d32);
  105225. +
  105226. + if (gintr_status.b.sofintr) {
  105227. + retval |= dwc_otg_pcd_handle_sof_intr(pcd);
  105228. + }
  105229. + if (gintr_status.b.rxstsqlvl) {
  105230. + retval |=
  105231. + dwc_otg_pcd_handle_rx_status_q_level_intr(pcd);
  105232. + }
  105233. + if (gintr_status.b.nptxfempty) {
  105234. + retval |= dwc_otg_pcd_handle_np_tx_fifo_empty_intr(pcd);
  105235. + }
  105236. + if (gintr_status.b.goutnakeff) {
  105237. + retval |= dwc_otg_pcd_handle_out_nak_effective(pcd);
  105238. + }
  105239. + if (gintr_status.b.i2cintr) {
  105240. + retval |= dwc_otg_pcd_handle_i2c_intr(pcd);
  105241. + }
  105242. + if (gintr_status.b.erlysuspend) {
  105243. + retval |= dwc_otg_pcd_handle_early_suspend_intr(pcd);
  105244. + }
  105245. + if (gintr_status.b.usbreset) {
  105246. + retval |= dwc_otg_pcd_handle_usb_reset_intr(pcd);
  105247. + }
  105248. + if (gintr_status.b.enumdone) {
  105249. + retval |= dwc_otg_pcd_handle_enum_done_intr(pcd);
  105250. + }
  105251. + if (gintr_status.b.isooutdrop) {
  105252. + retval |=
  105253. + dwc_otg_pcd_handle_isoc_out_packet_dropped_intr
  105254. + (pcd);
  105255. + }
  105256. + if (gintr_status.b.eopframe) {
  105257. + retval |=
  105258. + dwc_otg_pcd_handle_end_periodic_frame_intr(pcd);
  105259. + }
  105260. + if (gintr_status.b.inepint) {
  105261. + if (!core_if->multiproc_int_enable) {
  105262. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  105263. + }
  105264. + }
  105265. + if (gintr_status.b.outepintr) {
  105266. + if (!core_if->multiproc_int_enable) {
  105267. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  105268. + }
  105269. + }
  105270. + if (gintr_status.b.epmismatch) {
  105271. + retval |= dwc_otg_pcd_handle_ep_mismatch_intr(pcd);
  105272. + }
  105273. + if (gintr_status.b.fetsusp) {
  105274. + retval |= dwc_otg_pcd_handle_ep_fetsusp_intr(pcd);
  105275. + }
  105276. + if (gintr_status.b.ginnakeff) {
  105277. + retval |= dwc_otg_pcd_handle_in_nak_effective(pcd);
  105278. + }
  105279. + if (gintr_status.b.incomplisoin) {
  105280. + retval |=
  105281. + dwc_otg_pcd_handle_incomplete_isoc_in_intr(pcd);
  105282. + }
  105283. + if (gintr_status.b.incomplisoout) {
  105284. + retval |=
  105285. + dwc_otg_pcd_handle_incomplete_isoc_out_intr(pcd);
  105286. + }
  105287. +
  105288. + /* In MPI mode Device Endpoints interrupts are asserted
  105289. + * without setting outepintr and inepint bits set, so these
  105290. + * Interrupt handlers are called without checking these bit-fields
  105291. + */
  105292. + if (core_if->multiproc_int_enable) {
  105293. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  105294. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  105295. + }
  105296. +#ifdef VERBOSE
  105297. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%0x\n", __func__,
  105298. + DWC_READ_REG32(&global_regs->gintsts));
  105299. +#endif
  105300. + DWC_SPINUNLOCK(pcd->lock);
  105301. + }
  105302. + return retval;
  105303. +}
  105304. +
  105305. +#endif /* DWC_HOST_ONLY */
  105306. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
  105307. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  105308. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 2015-02-09 04:40:29.000000000 +0100
  105309. @@ -0,0 +1,1360 @@
  105310. + /* ==========================================================================
  105311. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_linux.c $
  105312. + * $Revision: #21 $
  105313. + * $Date: 2012/08/10 $
  105314. + * $Change: 2047372 $
  105315. + *
  105316. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  105317. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  105318. + * otherwise expressly agreed to in writing between Synopsys and you.
  105319. + *
  105320. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  105321. + * any End User Software License Agreement or Agreement for Licensed Product
  105322. + * with Synopsys or any supplement thereto. You are permitted to use and
  105323. + * redistribute this Software in source and binary forms, with or without
  105324. + * modification, provided that redistributions of source code must retain this
  105325. + * notice. You may not view, use, disclose, copy or distribute this file or
  105326. + * any information contained herein except pursuant to this license grant from
  105327. + * Synopsys. If you do not agree with this notice, including the disclaimer
  105328. + * below, then you are not authorized to use the Software.
  105329. + *
  105330. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  105331. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  105332. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  105333. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  105334. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  105335. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  105336. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  105337. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  105338. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  105339. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  105340. + * DAMAGE.
  105341. + * ========================================================================== */
  105342. +#ifndef DWC_HOST_ONLY
  105343. +
  105344. +/** @file
  105345. + * This file implements the Peripheral Controller Driver.
  105346. + *
  105347. + * The Peripheral Controller Driver (PCD) is responsible for
  105348. + * translating requests from the Function Driver into the appropriate
  105349. + * actions on the DWC_otg controller. It isolates the Function Driver
  105350. + * from the specifics of the controller by providing an API to the
  105351. + * Function Driver.
  105352. + *
  105353. + * The Peripheral Controller Driver for Linux will implement the
  105354. + * Gadget API, so that the existing Gadget drivers can be used.
  105355. + * (Gadget Driver is the Linux terminology for a Function Driver.)
  105356. + *
  105357. + * The Linux Gadget API is defined in the header file
  105358. + * <code><linux/usb_gadget.h></code>. The USB EP operations API is
  105359. + * defined in the structure <code>usb_ep_ops</code> and the USB
  105360. + * Controller API is defined in the structure
  105361. + * <code>usb_gadget_ops</code>.
  105362. + *
  105363. + */
  105364. +
  105365. +#include "dwc_otg_os_dep.h"
  105366. +#include "dwc_otg_pcd_if.h"
  105367. +#include "dwc_otg_pcd.h"
  105368. +#include "dwc_otg_driver.h"
  105369. +#include "dwc_otg_dbg.h"
  105370. +
  105371. +extern bool fiq_enable;
  105372. +
  105373. +static struct gadget_wrapper {
  105374. + dwc_otg_pcd_t *pcd;
  105375. +
  105376. + struct usb_gadget gadget;
  105377. + struct usb_gadget_driver *driver;
  105378. +
  105379. + struct usb_ep ep0;
  105380. + struct usb_ep in_ep[16];
  105381. + struct usb_ep out_ep[16];
  105382. +
  105383. +} *gadget_wrapper;
  105384. +
  105385. +/* Display the contents of the buffer */
  105386. +extern void dump_msg(const u8 * buf, unsigned int length);
  105387. +/**
  105388. + * Get the dwc_otg_pcd_ep_t* from usb_ep* pointer - NULL in case
  105389. + * if the endpoint is not found
  105390. + */
  105391. +static struct dwc_otg_pcd_ep *ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  105392. +{
  105393. + int i;
  105394. + if (pcd->ep0.priv == handle) {
  105395. + return &pcd->ep0;
  105396. + }
  105397. +
  105398. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  105399. + if (pcd->in_ep[i].priv == handle)
  105400. + return &pcd->in_ep[i];
  105401. + if (pcd->out_ep[i].priv == handle)
  105402. + return &pcd->out_ep[i];
  105403. + }
  105404. +
  105405. + return NULL;
  105406. +}
  105407. +
  105408. +/* USB Endpoint Operations */
  105409. +/*
  105410. + * The following sections briefly describe the behavior of the Gadget
  105411. + * API endpoint operations implemented in the DWC_otg driver
  105412. + * software. Detailed descriptions of the generic behavior of each of
  105413. + * these functions can be found in the Linux header file
  105414. + * include/linux/usb_gadget.h.
  105415. + *
  105416. + * The Gadget API provides wrapper functions for each of the function
  105417. + * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
  105418. + * function, which then calls the underlying PCD function. The
  105419. + * following sections are named according to the wrapper
  105420. + * functions. Within each section, the corresponding DWC_otg PCD
  105421. + * function name is specified.
  105422. + *
  105423. + */
  105424. +
  105425. +/**
  105426. + * This function is called by the Gadget Driver for each EP to be
  105427. + * configured for the current configuration (SET_CONFIGURATION).
  105428. + *
  105429. + * This function initializes the dwc_otg_ep_t data structure, and then
  105430. + * calls dwc_otg_ep_activate.
  105431. + */
  105432. +static int ep_enable(struct usb_ep *usb_ep,
  105433. + const struct usb_endpoint_descriptor *ep_desc)
  105434. +{
  105435. + int retval;
  105436. +
  105437. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, ep_desc);
  105438. +
  105439. + if (!usb_ep || !ep_desc || ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
  105440. + DWC_WARN("%s, bad ep or descriptor\n", __func__);
  105441. + return -EINVAL;
  105442. + }
  105443. + if (usb_ep == &gadget_wrapper->ep0) {
  105444. + DWC_WARN("%s, bad ep(0)\n", __func__);
  105445. + return -EINVAL;
  105446. + }
  105447. +
  105448. + /* Check FIFO size? */
  105449. + if (!ep_desc->wMaxPacketSize) {
  105450. + DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
  105451. + return -ERANGE;
  105452. + }
  105453. +
  105454. + if (!gadget_wrapper->driver ||
  105455. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  105456. + DWC_WARN("%s, bogus device state\n", __func__);
  105457. + return -ESHUTDOWN;
  105458. + }
  105459. +
  105460. + /* Delete after check - MAS */
  105461. +#if 0
  105462. + nat = (uint32_t) ep_desc->wMaxPacketSize;
  105463. + printk(KERN_ALERT "%s: nat (before) =%d\n", __func__, nat);
  105464. + nat = (nat >> 11) & 0x03;
  105465. + printk(KERN_ALERT "%s: nat (after) =%d\n", __func__, nat);
  105466. +#endif
  105467. + retval = dwc_otg_pcd_ep_enable(gadget_wrapper->pcd,
  105468. + (const uint8_t *)ep_desc,
  105469. + (void *)usb_ep);
  105470. + if (retval) {
  105471. + DWC_WARN("dwc_otg_pcd_ep_enable failed\n");
  105472. + return -EINVAL;
  105473. + }
  105474. +
  105475. + usb_ep->maxpacket = le16_to_cpu(ep_desc->wMaxPacketSize);
  105476. +
  105477. + return 0;
  105478. +}
  105479. +
  105480. +/**
  105481. + * This function is called when an EP is disabled due to disconnect or
  105482. + * change in configuration. Any pending requests will terminate with a
  105483. + * status of -ESHUTDOWN.
  105484. + *
  105485. + * This function modifies the dwc_otg_ep_t data structure for this EP,
  105486. + * and then calls dwc_otg_ep_deactivate.
  105487. + */
  105488. +static int ep_disable(struct usb_ep *usb_ep)
  105489. +{
  105490. + int retval;
  105491. +
  105492. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, usb_ep);
  105493. + if (!usb_ep) {
  105494. + DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
  105495. + usb_ep ? usb_ep->name : NULL);
  105496. + return -EINVAL;
  105497. + }
  105498. +
  105499. + retval = dwc_otg_pcd_ep_disable(gadget_wrapper->pcd, usb_ep);
  105500. + if (retval) {
  105501. + retval = -EINVAL;
  105502. + }
  105503. +
  105504. + return retval;
  105505. +}
  105506. +
  105507. +/**
  105508. + * This function allocates a request object to use with the specified
  105509. + * endpoint.
  105510. + *
  105511. + * @param ep The endpoint to be used with with the request
  105512. + * @param gfp_flags the GFP_* flags to use.
  105513. + */
  105514. +static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
  105515. + gfp_t gfp_flags)
  105516. +{
  105517. + struct usb_request *usb_req;
  105518. +
  105519. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d)\n", __func__, ep, gfp_flags);
  105520. + if (0 == ep) {
  105521. + DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
  105522. + return 0;
  105523. + }
  105524. + usb_req = kmalloc(sizeof(*usb_req), gfp_flags);
  105525. + if (0 == usb_req) {
  105526. + DWC_WARN("%s() %s\n", __func__, "request allocation failed!\n");
  105527. + return 0;
  105528. + }
  105529. + memset(usb_req, 0, sizeof(*usb_req));
  105530. + usb_req->dma = DWC_DMA_ADDR_INVALID;
  105531. +
  105532. + return usb_req;
  105533. +}
  105534. +
  105535. +/**
  105536. + * This function frees a request object.
  105537. + *
  105538. + * @param ep The endpoint associated with the request
  105539. + * @param req The request being freed
  105540. + */
  105541. +static void dwc_otg_pcd_free_request(struct usb_ep *ep, struct usb_request *req)
  105542. +{
  105543. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, ep, req);
  105544. +
  105545. + if (0 == ep || 0 == req) {
  105546. + DWC_WARN("%s() %s\n", __func__,
  105547. + "Invalid ep or req argument!\n");
  105548. + return;
  105549. + }
  105550. +
  105551. + kfree(req);
  105552. +}
  105553. +
  105554. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  105555. +/**
  105556. + * This function allocates an I/O buffer to be used for a transfer
  105557. + * to/from the specified endpoint.
  105558. + *
  105559. + * @param usb_ep The endpoint to be used with with the request
  105560. + * @param bytes The desired number of bytes for the buffer
  105561. + * @param dma Pointer to the buffer's DMA address; must be valid
  105562. + * @param gfp_flags the GFP_* flags to use.
  105563. + * @return address of a new buffer or null is buffer could not be allocated.
  105564. + */
  105565. +static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
  105566. + dma_addr_t * dma, gfp_t gfp_flags)
  105567. +{
  105568. + void *buf;
  105569. + dwc_otg_pcd_t *pcd = 0;
  105570. +
  105571. + pcd = gadget_wrapper->pcd;
  105572. +
  105573. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
  105574. + dma, gfp_flags);
  105575. +
  105576. + /* Check dword alignment */
  105577. + if ((bytes & 0x3UL) != 0) {
  105578. + DWC_WARN("%s() Buffer size is not a multiple of"
  105579. + "DWORD size (%d)", __func__, bytes);
  105580. + }
  105581. +
  105582. + buf = dma_alloc_coherent(NULL, bytes, dma, gfp_flags);
  105583. +
  105584. + /* Check dword alignment */
  105585. + if (((int)buf & 0x3UL) != 0) {
  105586. + DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
  105587. + __func__, buf);
  105588. + }
  105589. +
  105590. + return buf;
  105591. +}
  105592. +
  105593. +/**
  105594. + * This function frees an I/O buffer that was allocated by alloc_buffer.
  105595. + *
  105596. + * @param usb_ep the endpoint associated with the buffer
  105597. + * @param buf address of the buffer
  105598. + * @param dma The buffer's DMA address
  105599. + * @param bytes The number of bytes of the buffer
  105600. + */
  105601. +static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
  105602. + dma_addr_t dma, unsigned bytes)
  105603. +{
  105604. + dwc_otg_pcd_t *pcd = 0;
  105605. +
  105606. + pcd = gadget_wrapper->pcd;
  105607. +
  105608. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%0x,%d)\n", __func__, buf, dma, bytes);
  105609. +
  105610. + dma_free_coherent(NULL, bytes, buf, dma);
  105611. +}
  105612. +#endif
  105613. +
  105614. +/**
  105615. + * This function is used to submit an I/O Request to an EP.
  105616. + *
  105617. + * - When the request completes the request's completion callback
  105618. + * is called to return the request to the driver.
  105619. + * - An EP, except control EPs, may have multiple requests
  105620. + * pending.
  105621. + * - Once submitted the request cannot be examined or modified.
  105622. + * - Each request is turned into one or more packets.
  105623. + * - A BULK EP can queue any amount of data; the transfer is
  105624. + * packetized.
  105625. + * - Zero length Packets are specified with the request 'zero'
  105626. + * flag.
  105627. + */
  105628. +static int ep_queue(struct usb_ep *usb_ep, struct usb_request *usb_req,
  105629. + gfp_t gfp_flags)
  105630. +{
  105631. + dwc_otg_pcd_t *pcd;
  105632. + struct dwc_otg_pcd_ep *ep = NULL;
  105633. + int retval = 0, is_isoc_ep = 0;
  105634. + dma_addr_t dma_addr = DWC_DMA_ADDR_INVALID;
  105635. +
  105636. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p,%d)\n",
  105637. + __func__, usb_ep, usb_req, gfp_flags);
  105638. +
  105639. + if (!usb_req || !usb_req->complete || !usb_req->buf) {
  105640. + DWC_WARN("bad params\n");
  105641. + return -EINVAL;
  105642. + }
  105643. +
  105644. + if (!usb_ep) {
  105645. + DWC_WARN("bad ep\n");
  105646. + return -EINVAL;
  105647. + }
  105648. +
  105649. + pcd = gadget_wrapper->pcd;
  105650. + if (!gadget_wrapper->driver ||
  105651. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  105652. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  105653. + gadget_wrapper->gadget.speed);
  105654. + DWC_WARN("bogus device state\n");
  105655. + return -ESHUTDOWN;
  105656. + }
  105657. +
  105658. + DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
  105659. + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
  105660. +
  105661. + usb_req->status = -EINPROGRESS;
  105662. + usb_req->actual = 0;
  105663. +
  105664. + ep = ep_from_handle(pcd, usb_ep);
  105665. + if (ep == NULL)
  105666. + is_isoc_ep = 0;
  105667. + else
  105668. + is_isoc_ep = (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) ? 1 : 0;
  105669. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  105670. + dma_addr = usb_req->dma;
  105671. +#else
  105672. + if (GET_CORE_IF(pcd)->dma_enable) {
  105673. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  105674. + struct device *dev = NULL;
  105675. +
  105676. + if (otg_dev != NULL)
  105677. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  105678. +
  105679. + if (usb_req->length != 0 &&
  105680. + usb_req->dma == DWC_DMA_ADDR_INVALID) {
  105681. + dma_addr = dma_map_single(dev, usb_req->buf,
  105682. + usb_req->length,
  105683. + ep->dwc_ep.is_in ?
  105684. + DMA_TO_DEVICE:
  105685. + DMA_FROM_DEVICE);
  105686. + }
  105687. + }
  105688. +#endif
  105689. +
  105690. +#ifdef DWC_UTE_PER_IO
  105691. + if (is_isoc_ep == 1) {
  105692. + retval = dwc_otg_pcd_xiso_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  105693. + usb_req->length, usb_req->zero, usb_req,
  105694. + gfp_flags == GFP_ATOMIC ? 1 : 0, &usb_req->ext_req);
  105695. + if (retval)
  105696. + return -EINVAL;
  105697. +
  105698. + return 0;
  105699. + }
  105700. +#endif
  105701. + retval = dwc_otg_pcd_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  105702. + usb_req->length, usb_req->zero, usb_req,
  105703. + gfp_flags == GFP_ATOMIC ? 1 : 0);
  105704. + if (retval) {
  105705. + return -EINVAL;
  105706. + }
  105707. +
  105708. + return 0;
  105709. +}
  105710. +
  105711. +/**
  105712. + * This function cancels an I/O request from an EP.
  105713. + */
  105714. +static int ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req)
  105715. +{
  105716. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, usb_req);
  105717. +
  105718. + if (!usb_ep || !usb_req) {
  105719. + DWC_WARN("bad argument\n");
  105720. + return -EINVAL;
  105721. + }
  105722. + if (!gadget_wrapper->driver ||
  105723. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  105724. + DWC_WARN("bogus device state\n");
  105725. + return -ESHUTDOWN;
  105726. + }
  105727. + if (dwc_otg_pcd_ep_dequeue(gadget_wrapper->pcd, usb_ep, usb_req)) {
  105728. + return -EINVAL;
  105729. + }
  105730. +
  105731. + return 0;
  105732. +}
  105733. +
  105734. +/**
  105735. + * usb_ep_set_halt stalls an endpoint.
  105736. + *
  105737. + * usb_ep_clear_halt clears an endpoint halt and resets its data
  105738. + * toggle.
  105739. + *
  105740. + * Both of these functions are implemented with the same underlying
  105741. + * function. The behavior depends on the value argument.
  105742. + *
  105743. + * @param[in] usb_ep the Endpoint to halt or clear halt.
  105744. + * @param[in] value
  105745. + * - 0 means clear_halt.
  105746. + * - 1 means set_halt,
  105747. + * - 2 means clear stall lock flag.
  105748. + * - 3 means set stall lock flag.
  105749. + */
  105750. +static int ep_halt(struct usb_ep *usb_ep, int value)
  105751. +{
  105752. + int retval = 0;
  105753. +
  105754. + DWC_DEBUGPL(DBG_PCD, "HALT %s %d\n", usb_ep->name, value);
  105755. +
  105756. + if (!usb_ep) {
  105757. + DWC_WARN("bad ep\n");
  105758. + return -EINVAL;
  105759. + }
  105760. +
  105761. + retval = dwc_otg_pcd_ep_halt(gadget_wrapper->pcd, usb_ep, value);
  105762. + if (retval == -DWC_E_AGAIN) {
  105763. + return -EAGAIN;
  105764. + } else if (retval) {
  105765. + retval = -EINVAL;
  105766. + }
  105767. +
  105768. + return retval;
  105769. +}
  105770. +
  105771. +//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  105772. +#if 0
  105773. +/**
  105774. + * ep_wedge: sets the halt feature and ignores clear requests
  105775. + *
  105776. + * @usb_ep: the endpoint being wedged
  105777. + *
  105778. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  105779. + * requests. If the gadget driver clears the halt status, it will
  105780. + * automatically unwedge the endpoint.
  105781. + *
  105782. + * Returns zero on success, else negative errno. *
  105783. + * Check usb_ep_set_wedge() at "usb_gadget.h" for details
  105784. + */
  105785. +static int ep_wedge(struct usb_ep *usb_ep)
  105786. +{
  105787. + int retval = 0;
  105788. +
  105789. + DWC_DEBUGPL(DBG_PCD, "WEDGE %s\n", usb_ep->name);
  105790. +
  105791. + if (!usb_ep) {
  105792. + DWC_WARN("bad ep\n");
  105793. + return -EINVAL;
  105794. + }
  105795. +
  105796. + retval = dwc_otg_pcd_ep_wedge(gadget_wrapper->pcd, usb_ep);
  105797. + if (retval == -DWC_E_AGAIN) {
  105798. + retval = -EAGAIN;
  105799. + } else if (retval) {
  105800. + retval = -EINVAL;
  105801. + }
  105802. +
  105803. + return retval;
  105804. +}
  105805. +#endif
  105806. +
  105807. +#ifdef DWC_EN_ISOC
  105808. +/**
  105809. + * This function is used to submit an ISOC Transfer Request to an EP.
  105810. + *
  105811. + * - Every time a sync period completes the request's completion callback
  105812. + * is called to provide data to the gadget driver.
  105813. + * - Once submitted the request cannot be modified.
  105814. + * - Each request is turned into periodic data packets untill ISO
  105815. + * Transfer is stopped..
  105816. + */
  105817. +static int iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
  105818. + gfp_t gfp_flags)
  105819. +{
  105820. + int retval = 0;
  105821. +
  105822. + if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
  105823. + DWC_WARN("bad params\n");
  105824. + return -EINVAL;
  105825. + }
  105826. +
  105827. + if (!usb_ep) {
  105828. + DWC_PRINTF("bad params\n");
  105829. + return -EINVAL;
  105830. + }
  105831. +
  105832. + req->status = -EINPROGRESS;
  105833. +
  105834. + retval =
  105835. + dwc_otg_pcd_iso_ep_start(gadget_wrapper->pcd, usb_ep, req->buf0,
  105836. + req->buf1, req->dma0, req->dma1,
  105837. + req->sync_frame, req->data_pattern_frame,
  105838. + req->data_per_frame,
  105839. + req->
  105840. + flags & USB_REQ_ISO_ASAP ? -1 :
  105841. + req->start_frame, req->buf_proc_intrvl,
  105842. + req, gfp_flags == GFP_ATOMIC ? 1 : 0);
  105843. +
  105844. + if (retval) {
  105845. + return -EINVAL;
  105846. + }
  105847. +
  105848. + return retval;
  105849. +}
  105850. +
  105851. +/**
  105852. + * This function stops ISO EP Periodic Data Transfer.
  105853. + */
  105854. +static int iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
  105855. +{
  105856. + int retval = 0;
  105857. + if (!usb_ep) {
  105858. + DWC_WARN("bad ep\n");
  105859. + }
  105860. +
  105861. + if (!gadget_wrapper->driver ||
  105862. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  105863. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  105864. + gadget_wrapper->gadget.speed);
  105865. + DWC_WARN("bogus device state\n");
  105866. + }
  105867. +
  105868. + dwc_otg_pcd_iso_ep_stop(gadget_wrapper->pcd, usb_ep, req);
  105869. + if (retval) {
  105870. + retval = -EINVAL;
  105871. + }
  105872. +
  105873. + return retval;
  105874. +}
  105875. +
  105876. +static struct usb_iso_request *alloc_iso_request(struct usb_ep *ep,
  105877. + int packets, gfp_t gfp_flags)
  105878. +{
  105879. + struct usb_iso_request *pReq = NULL;
  105880. + uint32_t req_size;
  105881. +
  105882. + req_size = sizeof(struct usb_iso_request);
  105883. + req_size +=
  105884. + (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
  105885. +
  105886. + pReq = kmalloc(req_size, gfp_flags);
  105887. + if (!pReq) {
  105888. + DWC_WARN("Can't allocate Iso Request\n");
  105889. + return 0;
  105890. + }
  105891. + pReq->iso_packet_desc0 = (void *)(pReq + 1);
  105892. +
  105893. + pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
  105894. +
  105895. + return pReq;
  105896. +}
  105897. +
  105898. +static void free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
  105899. +{
  105900. + kfree(req);
  105901. +}
  105902. +
  105903. +static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops = {
  105904. + .ep_ops = {
  105905. + .enable = ep_enable,
  105906. + .disable = ep_disable,
  105907. +
  105908. + .alloc_request = dwc_otg_pcd_alloc_request,
  105909. + .free_request = dwc_otg_pcd_free_request,
  105910. +
  105911. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  105912. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  105913. + .free_buffer = dwc_otg_pcd_free_buffer,
  105914. +#endif
  105915. +
  105916. + .queue = ep_queue,
  105917. + .dequeue = ep_dequeue,
  105918. +
  105919. + .set_halt = ep_halt,
  105920. + .fifo_status = 0,
  105921. + .fifo_flush = 0,
  105922. + },
  105923. + .iso_ep_start = iso_ep_start,
  105924. + .iso_ep_stop = iso_ep_stop,
  105925. + .alloc_iso_request = alloc_iso_request,
  105926. + .free_iso_request = free_iso_request,
  105927. +};
  105928. +
  105929. +#else
  105930. +
  105931. + int (*enable) (struct usb_ep *ep,
  105932. + const struct usb_endpoint_descriptor *desc);
  105933. + int (*disable) (struct usb_ep *ep);
  105934. +
  105935. + struct usb_request *(*alloc_request) (struct usb_ep *ep,
  105936. + gfp_t gfp_flags);
  105937. + void (*free_request) (struct usb_ep *ep, struct usb_request *req);
  105938. +
  105939. + int (*queue) (struct usb_ep *ep, struct usb_request *req,
  105940. + gfp_t gfp_flags);
  105941. + int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
  105942. +
  105943. + int (*set_halt) (struct usb_ep *ep, int value);
  105944. + int (*set_wedge) (struct usb_ep *ep);
  105945. +
  105946. + int (*fifo_status) (struct usb_ep *ep);
  105947. + void (*fifo_flush) (struct usb_ep *ep);
  105948. +static struct usb_ep_ops dwc_otg_pcd_ep_ops = {
  105949. + .enable = ep_enable,
  105950. + .disable = ep_disable,
  105951. +
  105952. + .alloc_request = dwc_otg_pcd_alloc_request,
  105953. + .free_request = dwc_otg_pcd_free_request,
  105954. +
  105955. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  105956. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  105957. + .free_buffer = dwc_otg_pcd_free_buffer,
  105958. +#else
  105959. + /* .set_wedge = ep_wedge, */
  105960. + .set_wedge = NULL, /* uses set_halt instead */
  105961. +#endif
  105962. +
  105963. + .queue = ep_queue,
  105964. + .dequeue = ep_dequeue,
  105965. +
  105966. + .set_halt = ep_halt,
  105967. + .fifo_status = 0,
  105968. + .fifo_flush = 0,
  105969. +
  105970. +};
  105971. +
  105972. +#endif /* _EN_ISOC_ */
  105973. +/* Gadget Operations */
  105974. +/**
  105975. + * The following gadget operations will be implemented in the DWC_otg
  105976. + * PCD. Functions in the API that are not described below are not
  105977. + * implemented.
  105978. + *
  105979. + * The Gadget API provides wrapper functions for each of the function
  105980. + * pointers defined in usb_gadget_ops. The Gadget Driver calls the
  105981. + * wrapper function, which then calls the underlying PCD function. The
  105982. + * following sections are named according to the wrapper functions
  105983. + * (except for ioctl, which doesn't have a wrapper function). Within
  105984. + * each section, the corresponding DWC_otg PCD function name is
  105985. + * specified.
  105986. + *
  105987. + */
  105988. +
  105989. +/**
  105990. + *Gets the USB Frame number of the last SOF.
  105991. + */
  105992. +static int get_frame_number(struct usb_gadget *gadget)
  105993. +{
  105994. + struct gadget_wrapper *d;
  105995. +
  105996. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  105997. +
  105998. + if (gadget == 0) {
  105999. + return -ENODEV;
  106000. + }
  106001. +
  106002. + d = container_of(gadget, struct gadget_wrapper, gadget);
  106003. + return dwc_otg_pcd_get_frame_number(d->pcd);
  106004. +}
  106005. +
  106006. +#ifdef CONFIG_USB_DWC_OTG_LPM
  106007. +static int test_lpm_enabled(struct usb_gadget *gadget)
  106008. +{
  106009. + struct gadget_wrapper *d;
  106010. +
  106011. + d = container_of(gadget, struct gadget_wrapper, gadget);
  106012. +
  106013. + return dwc_otg_pcd_is_lpm_enabled(d->pcd);
  106014. +}
  106015. +#endif
  106016. +
  106017. +/**
  106018. + * Initiates Session Request Protocol (SRP) to wakeup the host if no
  106019. + * session is in progress. If a session is already in progress, but
  106020. + * the device is suspended, remote wakeup signaling is started.
  106021. + *
  106022. + */
  106023. +static int wakeup(struct usb_gadget *gadget)
  106024. +{
  106025. + struct gadget_wrapper *d;
  106026. +
  106027. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  106028. +
  106029. + if (gadget == 0) {
  106030. + return -ENODEV;
  106031. + } else {
  106032. + d = container_of(gadget, struct gadget_wrapper, gadget);
  106033. + }
  106034. + dwc_otg_pcd_wakeup(d->pcd);
  106035. + return 0;
  106036. +}
  106037. +
  106038. +static const struct usb_gadget_ops dwc_otg_pcd_ops = {
  106039. + .get_frame = get_frame_number,
  106040. + .wakeup = wakeup,
  106041. +#ifdef CONFIG_USB_DWC_OTG_LPM
  106042. + .lpm_support = test_lpm_enabled,
  106043. +#endif
  106044. + // current versions must always be self-powered
  106045. +};
  106046. +
  106047. +static int _setup(dwc_otg_pcd_t * pcd, uint8_t * bytes)
  106048. +{
  106049. + int retval = -DWC_E_NOT_SUPPORTED;
  106050. + if (gadget_wrapper->driver && gadget_wrapper->driver->setup) {
  106051. + retval = gadget_wrapper->driver->setup(&gadget_wrapper->gadget,
  106052. + (struct usb_ctrlrequest
  106053. + *)bytes);
  106054. + }
  106055. +
  106056. + if (retval == -ENOTSUPP) {
  106057. + retval = -DWC_E_NOT_SUPPORTED;
  106058. + } else if (retval < 0) {
  106059. + retval = -DWC_E_INVALID;
  106060. + }
  106061. +
  106062. + return retval;
  106063. +}
  106064. +
  106065. +#ifdef DWC_EN_ISOC
  106066. +static int _isoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  106067. + void *req_handle, int proc_buf_num)
  106068. +{
  106069. + int i, packet_count;
  106070. + struct usb_gadget_iso_packet_descriptor *iso_packet = 0;
  106071. + struct usb_iso_request *iso_req = req_handle;
  106072. +
  106073. + if (proc_buf_num) {
  106074. + iso_packet = iso_req->iso_packet_desc1;
  106075. + } else {
  106076. + iso_packet = iso_req->iso_packet_desc0;
  106077. + }
  106078. + packet_count =
  106079. + dwc_otg_pcd_get_iso_packet_count(pcd, ep_handle, req_handle);
  106080. + for (i = 0; i < packet_count; ++i) {
  106081. + int status;
  106082. + int actual;
  106083. + int offset;
  106084. + dwc_otg_pcd_get_iso_packet_params(pcd, ep_handle, req_handle,
  106085. + i, &status, &actual, &offset);
  106086. + switch (status) {
  106087. + case -DWC_E_NO_DATA:
  106088. + status = -ENODATA;
  106089. + break;
  106090. + default:
  106091. + if (status) {
  106092. + DWC_PRINTF("unknown status in isoc packet\n");
  106093. + }
  106094. +
  106095. + }
  106096. + iso_packet[i].status = status;
  106097. + iso_packet[i].offset = offset;
  106098. + iso_packet[i].actual_length = actual;
  106099. + }
  106100. +
  106101. + iso_req->status = 0;
  106102. + iso_req->process_buffer(ep_handle, iso_req);
  106103. +
  106104. + return 0;
  106105. +}
  106106. +#endif /* DWC_EN_ISOC */
  106107. +
  106108. +#ifdef DWC_UTE_PER_IO
  106109. +/**
  106110. + * Copy the contents of the extended request to the Linux usb_request's
  106111. + * extended part and call the gadget's completion.
  106112. + *
  106113. + * @param pcd Pointer to the pcd structure
  106114. + * @param ep_handle Void pointer to the usb_ep structure
  106115. + * @param req_handle Void pointer to the usb_request structure
  106116. + * @param status Request status returned from the portable logic
  106117. + * @param ereq_port Void pointer to the extended request structure
  106118. + * created in the the portable part that contains the
  106119. + * results of the processed iso packets.
  106120. + */
  106121. +static int _xisoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  106122. + void *req_handle, int32_t status, void *ereq_port)
  106123. +{
  106124. + struct dwc_ute_iso_req_ext *ereqorg = NULL;
  106125. + struct dwc_iso_xreq_port *ereqport = NULL;
  106126. + struct dwc_ute_iso_packet_descriptor *desc_org = NULL;
  106127. + int i;
  106128. + struct usb_request *req;
  106129. + //struct dwc_ute_iso_packet_descriptor *
  106130. + //int status = 0;
  106131. +
  106132. + req = (struct usb_request *)req_handle;
  106133. + ereqorg = &req->ext_req;
  106134. + ereqport = (struct dwc_iso_xreq_port *)ereq_port;
  106135. + desc_org = ereqorg->per_io_frame_descs;
  106136. +
  106137. + if (req && req->complete) {
  106138. + /* Copy the request data from the portable logic to our request */
  106139. + for (i = 0; i < ereqport->pio_pkt_count; i++) {
  106140. + desc_org[i].actual_length =
  106141. + ereqport->per_io_frame_descs[i].actual_length;
  106142. + desc_org[i].status =
  106143. + ereqport->per_io_frame_descs[i].status;
  106144. + }
  106145. +
  106146. + switch (status) {
  106147. + case -DWC_E_SHUTDOWN:
  106148. + req->status = -ESHUTDOWN;
  106149. + break;
  106150. + case -DWC_E_RESTART:
  106151. + req->status = -ECONNRESET;
  106152. + break;
  106153. + case -DWC_E_INVALID:
  106154. + req->status = -EINVAL;
  106155. + break;
  106156. + case -DWC_E_TIMEOUT:
  106157. + req->status = -ETIMEDOUT;
  106158. + break;
  106159. + default:
  106160. + req->status = status;
  106161. + }
  106162. +
  106163. + /* And call the gadget's completion */
  106164. + req->complete(ep_handle, req);
  106165. + }
  106166. +
  106167. + return 0;
  106168. +}
  106169. +#endif /* DWC_UTE_PER_IO */
  106170. +
  106171. +static int _complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  106172. + void *req_handle, int32_t status, uint32_t actual)
  106173. +{
  106174. + struct usb_request *req = (struct usb_request *)req_handle;
  106175. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  106176. + struct dwc_otg_pcd_ep *ep = NULL;
  106177. +#endif
  106178. +
  106179. + if (req && req->complete) {
  106180. + switch (status) {
  106181. + case -DWC_E_SHUTDOWN:
  106182. + req->status = -ESHUTDOWN;
  106183. + break;
  106184. + case -DWC_E_RESTART:
  106185. + req->status = -ECONNRESET;
  106186. + break;
  106187. + case -DWC_E_INVALID:
  106188. + req->status = -EINVAL;
  106189. + break;
  106190. + case -DWC_E_TIMEOUT:
  106191. + req->status = -ETIMEDOUT;
  106192. + break;
  106193. + default:
  106194. + req->status = status;
  106195. +
  106196. + }
  106197. +
  106198. + req->actual = actual;
  106199. + DWC_SPINUNLOCK(pcd->lock);
  106200. + req->complete(ep_handle, req);
  106201. + DWC_SPINLOCK(pcd->lock);
  106202. + }
  106203. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  106204. + ep = ep_from_handle(pcd, ep_handle);
  106205. + if (GET_CORE_IF(pcd)->dma_enable) {
  106206. + if (req->length != 0) {
  106207. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  106208. + struct device *dev = NULL;
  106209. +
  106210. + if (otg_dev != NULL)
  106211. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  106212. +
  106213. + dma_unmap_single(dev, req->dma, req->length,
  106214. + ep->dwc_ep.is_in ?
  106215. + DMA_TO_DEVICE: DMA_FROM_DEVICE);
  106216. + }
  106217. + }
  106218. +#endif
  106219. +
  106220. + return 0;
  106221. +}
  106222. +
  106223. +static int _connect(dwc_otg_pcd_t * pcd, int speed)
  106224. +{
  106225. + gadget_wrapper->gadget.speed = speed;
  106226. + return 0;
  106227. +}
  106228. +
  106229. +static int _disconnect(dwc_otg_pcd_t * pcd)
  106230. +{
  106231. + if (gadget_wrapper->driver && gadget_wrapper->driver->disconnect) {
  106232. + gadget_wrapper->driver->disconnect(&gadget_wrapper->gadget);
  106233. + }
  106234. + return 0;
  106235. +}
  106236. +
  106237. +static int _resume(dwc_otg_pcd_t * pcd)
  106238. +{
  106239. + if (gadget_wrapper->driver && gadget_wrapper->driver->resume) {
  106240. + gadget_wrapper->driver->resume(&gadget_wrapper->gadget);
  106241. + }
  106242. +
  106243. + return 0;
  106244. +}
  106245. +
  106246. +static int _suspend(dwc_otg_pcd_t * pcd)
  106247. +{
  106248. + if (gadget_wrapper->driver && gadget_wrapper->driver->suspend) {
  106249. + gadget_wrapper->driver->suspend(&gadget_wrapper->gadget);
  106250. + }
  106251. + return 0;
  106252. +}
  106253. +
  106254. +/**
  106255. + * This function updates the otg values in the gadget structure.
  106256. + */
  106257. +static int _hnp_changed(dwc_otg_pcd_t * pcd)
  106258. +{
  106259. +
  106260. + if (!gadget_wrapper->gadget.is_otg)
  106261. + return 0;
  106262. +
  106263. + gadget_wrapper->gadget.b_hnp_enable = get_b_hnp_enable(pcd);
  106264. + gadget_wrapper->gadget.a_hnp_support = get_a_hnp_support(pcd);
  106265. + gadget_wrapper->gadget.a_alt_hnp_support = get_a_alt_hnp_support(pcd);
  106266. + return 0;
  106267. +}
  106268. +
  106269. +static int _reset(dwc_otg_pcd_t * pcd)
  106270. +{
  106271. + return 0;
  106272. +}
  106273. +
  106274. +#ifdef DWC_UTE_CFI
  106275. +static int _cfi_setup(dwc_otg_pcd_t * pcd, void *cfi_req)
  106276. +{
  106277. + int retval = -DWC_E_INVALID;
  106278. + if (gadget_wrapper->driver->cfi_feature_setup) {
  106279. + retval =
  106280. + gadget_wrapper->driver->
  106281. + cfi_feature_setup(&gadget_wrapper->gadget,
  106282. + (struct cfi_usb_ctrlrequest *)cfi_req);
  106283. + }
  106284. +
  106285. + return retval;
  106286. +}
  106287. +#endif
  106288. +
  106289. +static const struct dwc_otg_pcd_function_ops fops = {
  106290. + .complete = _complete,
  106291. +#ifdef DWC_EN_ISOC
  106292. + .isoc_complete = _isoc_complete,
  106293. +#endif
  106294. + .setup = _setup,
  106295. + .disconnect = _disconnect,
  106296. + .connect = _connect,
  106297. + .resume = _resume,
  106298. + .suspend = _suspend,
  106299. + .hnp_changed = _hnp_changed,
  106300. + .reset = _reset,
  106301. +#ifdef DWC_UTE_CFI
  106302. + .cfi_setup = _cfi_setup,
  106303. +#endif
  106304. +#ifdef DWC_UTE_PER_IO
  106305. + .xisoc_complete = _xisoc_complete,
  106306. +#endif
  106307. +};
  106308. +
  106309. +/**
  106310. + * This function is the top level PCD interrupt handler.
  106311. + */
  106312. +static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev)
  106313. +{
  106314. + dwc_otg_pcd_t *pcd = dev;
  106315. + int32_t retval = IRQ_NONE;
  106316. +
  106317. + retval = dwc_otg_pcd_handle_intr(pcd);
  106318. + if (retval != 0) {
  106319. + S3C2410X_CLEAR_EINTPEND();
  106320. + }
  106321. + return IRQ_RETVAL(retval);
  106322. +}
  106323. +
  106324. +/**
  106325. + * This function initialized the usb_ep structures to there default
  106326. + * state.
  106327. + *
  106328. + * @param d Pointer on gadget_wrapper.
  106329. + */
  106330. +void gadget_add_eps(struct gadget_wrapper *d)
  106331. +{
  106332. + static const char *names[] = {
  106333. +
  106334. + "ep0",
  106335. + "ep1in",
  106336. + "ep2in",
  106337. + "ep3in",
  106338. + "ep4in",
  106339. + "ep5in",
  106340. + "ep6in",
  106341. + "ep7in",
  106342. + "ep8in",
  106343. + "ep9in",
  106344. + "ep10in",
  106345. + "ep11in",
  106346. + "ep12in",
  106347. + "ep13in",
  106348. + "ep14in",
  106349. + "ep15in",
  106350. + "ep1out",
  106351. + "ep2out",
  106352. + "ep3out",
  106353. + "ep4out",
  106354. + "ep5out",
  106355. + "ep6out",
  106356. + "ep7out",
  106357. + "ep8out",
  106358. + "ep9out",
  106359. + "ep10out",
  106360. + "ep11out",
  106361. + "ep12out",
  106362. + "ep13out",
  106363. + "ep14out",
  106364. + "ep15out"
  106365. + };
  106366. +
  106367. + int i;
  106368. + struct usb_ep *ep;
  106369. + int8_t dev_endpoints;
  106370. +
  106371. + DWC_DEBUGPL(DBG_PCDV, "%s\n", __func__);
  106372. +
  106373. + INIT_LIST_HEAD(&d->gadget.ep_list);
  106374. + d->gadget.ep0 = &d->ep0;
  106375. + d->gadget.speed = USB_SPEED_UNKNOWN;
  106376. +
  106377. + INIT_LIST_HEAD(&d->gadget.ep0->ep_list);
  106378. +
  106379. + /**
  106380. + * Initialize the EP0 structure.
  106381. + */
  106382. + ep = &d->ep0;
  106383. +
  106384. + /* Init the usb_ep structure. */
  106385. + ep->name = names[0];
  106386. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  106387. +
  106388. + /**
  106389. + * @todo NGS: What should the max packet size be set to
  106390. + * here? Before EP type is set?
  106391. + */
  106392. + ep->maxpacket = MAX_PACKET_SIZE;
  106393. + dwc_otg_pcd_ep_enable(d->pcd, NULL, ep);
  106394. +
  106395. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  106396. +
  106397. + /**
  106398. + * Initialize the EP structures.
  106399. + */
  106400. + dev_endpoints = d->pcd->core_if->dev_if->num_in_eps;
  106401. +
  106402. + for (i = 0; i < dev_endpoints; i++) {
  106403. + ep = &d->in_ep[i];
  106404. +
  106405. + /* Init the usb_ep structure. */
  106406. + ep->name = names[d->pcd->in_ep[i].dwc_ep.num];
  106407. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  106408. +
  106409. + /**
  106410. + * @todo NGS: What should the max packet size be set to
  106411. + * here? Before EP type is set?
  106412. + */
  106413. + ep->maxpacket = MAX_PACKET_SIZE;
  106414. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  106415. + }
  106416. +
  106417. + dev_endpoints = d->pcd->core_if->dev_if->num_out_eps;
  106418. +
  106419. + for (i = 0; i < dev_endpoints; i++) {
  106420. + ep = &d->out_ep[i];
  106421. +
  106422. + /* Init the usb_ep structure. */
  106423. + ep->name = names[15 + d->pcd->out_ep[i].dwc_ep.num];
  106424. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  106425. +
  106426. + /**
  106427. + * @todo NGS: What should the max packet size be set to
  106428. + * here? Before EP type is set?
  106429. + */
  106430. + ep->maxpacket = MAX_PACKET_SIZE;
  106431. +
  106432. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  106433. + }
  106434. +
  106435. + /* remove ep0 from the list. There is a ep0 pointer. */
  106436. + list_del_init(&d->ep0.ep_list);
  106437. +
  106438. + d->ep0.maxpacket = MAX_EP0_SIZE;
  106439. +}
  106440. +
  106441. +/**
  106442. + * This function releases the Gadget device.
  106443. + * required by device_unregister().
  106444. + *
  106445. + * @todo Should this do something? Should it free the PCD?
  106446. + */
  106447. +static void dwc_otg_pcd_gadget_release(struct device *dev)
  106448. +{
  106449. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, dev);
  106450. +}
  106451. +
  106452. +static struct gadget_wrapper *alloc_wrapper(dwc_bus_dev_t *_dev)
  106453. +{
  106454. + static char pcd_name[] = "dwc_otg_pcd";
  106455. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  106456. + struct gadget_wrapper *d;
  106457. + int retval;
  106458. +
  106459. + d = DWC_ALLOC(sizeof(*d));
  106460. + if (d == NULL) {
  106461. + return NULL;
  106462. + }
  106463. +
  106464. + memset(d, 0, sizeof(*d));
  106465. +
  106466. + d->gadget.name = pcd_name;
  106467. + d->pcd = otg_dev->pcd;
  106468. +
  106469. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  106470. + strcpy(d->gadget.dev.bus_id, "gadget");
  106471. +#else
  106472. + dev_set_name(&d->gadget.dev, "%s", "gadget");
  106473. +#endif
  106474. +
  106475. + d->gadget.dev.parent = &_dev->dev;
  106476. + d->gadget.dev.release = dwc_otg_pcd_gadget_release;
  106477. + d->gadget.ops = &dwc_otg_pcd_ops;
  106478. + d->gadget.max_speed = dwc_otg_pcd_is_dualspeed(otg_dev->pcd) ? USB_SPEED_HIGH:USB_SPEED_FULL;
  106479. + d->gadget.is_otg = dwc_otg_pcd_is_otg(otg_dev->pcd);
  106480. +
  106481. + d->driver = 0;
  106482. + /* Register the gadget device */
  106483. + retval = device_register(&d->gadget.dev);
  106484. + if (retval != 0) {
  106485. + DWC_ERROR("device_register failed\n");
  106486. + DWC_FREE(d);
  106487. + return NULL;
  106488. + }
  106489. +
  106490. + return d;
  106491. +}
  106492. +
  106493. +static void free_wrapper(struct gadget_wrapper *d)
  106494. +{
  106495. + if (d->driver) {
  106496. + /* should have been done already by driver model core */
  106497. + DWC_WARN("driver '%s' is still registered\n",
  106498. + d->driver->driver.name);
  106499. + usb_gadget_unregister_driver(d->driver);
  106500. + }
  106501. +
  106502. + device_unregister(&d->gadget.dev);
  106503. + DWC_FREE(d);
  106504. +}
  106505. +
  106506. +/**
  106507. + * This function initialized the PCD portion of the driver.
  106508. + *
  106509. + */
  106510. +int pcd_init(dwc_bus_dev_t *_dev)
  106511. +{
  106512. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  106513. + int retval = 0;
  106514. +
  106515. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev=%p\n", __func__, _dev, otg_dev);
  106516. +
  106517. + otg_dev->pcd = dwc_otg_pcd_init(otg_dev->core_if);
  106518. +
  106519. + if (!otg_dev->pcd) {
  106520. + DWC_ERROR("dwc_otg_pcd_init failed\n");
  106521. + return -ENOMEM;
  106522. + }
  106523. +
  106524. + otg_dev->pcd->otg_dev = otg_dev;
  106525. + gadget_wrapper = alloc_wrapper(_dev);
  106526. +
  106527. + /*
  106528. + * Initialize EP structures
  106529. + */
  106530. + gadget_add_eps(gadget_wrapper);
  106531. + /*
  106532. + * Setup interupt handler
  106533. + */
  106534. +#ifdef PLATFORM_INTERFACE
  106535. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  106536. + platform_get_irq(_dev, fiq_enable ? 0 : 1));
  106537. + retval = request_irq(platform_get_irq(_dev, fiq_enable ? 0 : 1), dwc_otg_pcd_irq,
  106538. + IRQF_SHARED, gadget_wrapper->gadget.name,
  106539. + otg_dev->pcd);
  106540. + if (retval != 0) {
  106541. + DWC_ERROR("request of irq%d failed\n",
  106542. + platform_get_irq(_dev, fiq_enable ? 0 : 1));
  106543. + free_wrapper(gadget_wrapper);
  106544. + return -EBUSY;
  106545. + }
  106546. +#else
  106547. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  106548. + _dev->irq);
  106549. + retval = request_irq(_dev->irq, dwc_otg_pcd_irq,
  106550. + IRQF_SHARED | IRQF_DISABLED,
  106551. + gadget_wrapper->gadget.name, otg_dev->pcd);
  106552. + if (retval != 0) {
  106553. + DWC_ERROR("request of irq%d failed\n", _dev->irq);
  106554. + free_wrapper(gadget_wrapper);
  106555. + return -EBUSY;
  106556. + }
  106557. +#endif
  106558. +
  106559. + dwc_otg_pcd_start(gadget_wrapper->pcd, &fops);
  106560. +
  106561. + return retval;
  106562. +}
  106563. +
  106564. +/**
  106565. + * Cleanup the PCD.
  106566. + */
  106567. +void pcd_remove(dwc_bus_dev_t *_dev)
  106568. +{
  106569. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  106570. + dwc_otg_pcd_t *pcd = otg_dev->pcd;
  106571. +
  106572. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  106573. +
  106574. + /*
  106575. + * Free the IRQ
  106576. + */
  106577. +#ifdef PLATFORM_INTERFACE
  106578. + free_irq(platform_get_irq(_dev, 0), pcd);
  106579. +#else
  106580. + free_irq(_dev->irq, pcd);
  106581. +#endif
  106582. + dwc_otg_pcd_remove(otg_dev->pcd);
  106583. + free_wrapper(gadget_wrapper);
  106584. + otg_dev->pcd = 0;
  106585. +}
  106586. +
  106587. +/**
  106588. + * This function registers a gadget driver with the PCD.
  106589. + *
  106590. + * When a driver is successfully registered, it will receive control
  106591. + * requests including set_configuration(), which enables non-control
  106592. + * requests. then usb traffic follows until a disconnect is reported.
  106593. + * then a host may connect again, or the driver might get unbound.
  106594. + *
  106595. + * @param driver The driver being registered
  106596. + * @param bind The bind function of gadget driver
  106597. + */
  106598. +
  106599. +int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
  106600. +{
  106601. + int retval;
  106602. +
  106603. + DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n",
  106604. + driver->driver.name);
  106605. +
  106606. + if (!driver || driver->max_speed == USB_SPEED_UNKNOWN ||
  106607. + !driver->bind ||
  106608. + !driver->unbind || !driver->disconnect || !driver->setup) {
  106609. + DWC_DEBUGPL(DBG_PCDV, "EINVAL\n");
  106610. + return -EINVAL;
  106611. + }
  106612. + if (gadget_wrapper == 0) {
  106613. + DWC_DEBUGPL(DBG_PCDV, "ENODEV\n");
  106614. + return -ENODEV;
  106615. + }
  106616. + if (gadget_wrapper->driver != 0) {
  106617. + DWC_DEBUGPL(DBG_PCDV, "EBUSY (%p)\n", gadget_wrapper->driver);
  106618. + return -EBUSY;
  106619. + }
  106620. +
  106621. + /* hook up the driver */
  106622. + gadget_wrapper->driver = driver;
  106623. + gadget_wrapper->gadget.dev.driver = &driver->driver;
  106624. +
  106625. + DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
  106626. + retval = driver->bind(&gadget_wrapper->gadget, gadget_wrapper->driver);
  106627. + if (retval) {
  106628. + DWC_ERROR("bind to driver %s --> error %d\n",
  106629. + driver->driver.name, retval);
  106630. + gadget_wrapper->driver = 0;
  106631. + gadget_wrapper->gadget.dev.driver = 0;
  106632. + return retval;
  106633. + }
  106634. + DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
  106635. + driver->driver.name);
  106636. + return 0;
  106637. +}
  106638. +EXPORT_SYMBOL(usb_gadget_probe_driver);
  106639. +
  106640. +/**
  106641. + * This function unregisters a gadget driver
  106642. + *
  106643. + * @param driver The driver being unregistered
  106644. + */
  106645. +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  106646. +{
  106647. + //DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver);
  106648. +
  106649. + if (gadget_wrapper == 0) {
  106650. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
  106651. + -ENODEV);
  106652. + return -ENODEV;
  106653. + }
  106654. + if (driver == 0 || driver != gadget_wrapper->driver) {
  106655. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
  106656. + -EINVAL);
  106657. + return -EINVAL;
  106658. + }
  106659. +
  106660. + driver->unbind(&gadget_wrapper->gadget);
  106661. + gadget_wrapper->driver = 0;
  106662. +
  106663. + DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n", driver->driver.name);
  106664. + return 0;
  106665. +}
  106666. +
  106667. +EXPORT_SYMBOL(usb_gadget_unregister_driver);
  106668. +
  106669. +#endif /* DWC_HOST_ONLY */
  106670. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_regs.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_regs.h
  106671. --- linux-3.18.6/drivers/usb/host/dwc_otg/dwc_otg_regs.h 1970-01-01 01:00:00.000000000 +0100
  106672. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_regs.h 2015-02-09 04:40:29.000000000 +0100
  106673. @@ -0,0 +1,2550 @@
  106674. +/* ==========================================================================
  106675. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_regs.h $
  106676. + * $Revision: #98 $
  106677. + * $Date: 2012/08/10 $
  106678. + * $Change: 2047372 $
  106679. + *
  106680. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  106681. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  106682. + * otherwise expressly agreed to in writing between Synopsys and you.
  106683. + *
  106684. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  106685. + * any End User Software License Agreement or Agreement for Licensed Product
  106686. + * with Synopsys or any supplement thereto. You are permitted to use and
  106687. + * redistribute this Software in source and binary forms, with or without
  106688. + * modification, provided that redistributions of source code must retain this
  106689. + * notice. You may not view, use, disclose, copy or distribute this file or
  106690. + * any information contained herein except pursuant to this license grant from
  106691. + * Synopsys. If you do not agree with this notice, including the disclaimer
  106692. + * below, then you are not authorized to use the Software.
  106693. + *
  106694. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  106695. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  106696. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  106697. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  106698. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  106699. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  106700. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  106701. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  106702. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  106703. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  106704. + * DAMAGE.
  106705. + * ========================================================================== */
  106706. +
  106707. +#ifndef __DWC_OTG_REGS_H__
  106708. +#define __DWC_OTG_REGS_H__
  106709. +
  106710. +#include "dwc_otg_core_if.h"
  106711. +
  106712. +/**
  106713. + * @file
  106714. + *
  106715. + * This file contains the data structures for accessing the DWC_otg core registers.
  106716. + *
  106717. + * The application interfaces with the HS OTG core by reading from and
  106718. + * writing to the Control and Status Register (CSR) space through the
  106719. + * AHB Slave interface. These registers are 32 bits wide, and the
  106720. + * addresses are 32-bit-block aligned.
  106721. + * CSRs are classified as follows:
  106722. + * - Core Global Registers
  106723. + * - Device Mode Registers
  106724. + * - Device Global Registers
  106725. + * - Device Endpoint Specific Registers
  106726. + * - Host Mode Registers
  106727. + * - Host Global Registers
  106728. + * - Host Port CSRs
  106729. + * - Host Channel Specific Registers
  106730. + *
  106731. + * Only the Core Global registers can be accessed in both Device and
  106732. + * Host modes. When the HS OTG core is operating in one mode, either
  106733. + * Device or Host, the application must not access registers from the
  106734. + * other mode. When the core switches from one mode to another, the
  106735. + * registers in the new mode of operation must be reprogrammed as they
  106736. + * would be after a power-on reset.
  106737. + */
  106738. +
  106739. +/****************************************************************************/
  106740. +/** DWC_otg Core registers .
  106741. + * The dwc_otg_core_global_regs structure defines the size
  106742. + * and relative field offsets for the Core Global registers.
  106743. + */
  106744. +typedef struct dwc_otg_core_global_regs {
  106745. + /** OTG Control and Status Register. <i>Offset: 000h</i> */
  106746. + volatile uint32_t gotgctl;
  106747. + /** OTG Interrupt Register. <i>Offset: 004h</i> */
  106748. + volatile uint32_t gotgint;
  106749. + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
  106750. + volatile uint32_t gahbcfg;
  106751. +
  106752. +#define DWC_GLBINTRMASK 0x0001
  106753. +#define DWC_DMAENABLE 0x0020
  106754. +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
  106755. +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
  106756. +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
  106757. +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
  106758. +
  106759. + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
  106760. + volatile uint32_t gusbcfg;
  106761. + /**Core Reset Register. <i>Offset: 010h</i> */
  106762. + volatile uint32_t grstctl;
  106763. + /**Core Interrupt Register. <i>Offset: 014h</i> */
  106764. + volatile uint32_t gintsts;
  106765. + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
  106766. + volatile uint32_t gintmsk;
  106767. + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
  106768. + volatile uint32_t grxstsr;
  106769. + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
  106770. + volatile uint32_t grxstsp;
  106771. + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
  106772. + volatile uint32_t grxfsiz;
  106773. + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
  106774. + volatile uint32_t gnptxfsiz;
  106775. + /**Non Periodic Transmit FIFO/Queue Status Register (Read
  106776. + * Only). <i>Offset: 02Ch</i> */
  106777. + volatile uint32_t gnptxsts;
  106778. + /**I2C Access Register. <i>Offset: 030h</i> */
  106779. + volatile uint32_t gi2cctl;
  106780. + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
  106781. + volatile uint32_t gpvndctl;
  106782. + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
  106783. + volatile uint32_t ggpio;
  106784. + /**User ID Register. <i>Offset: 03Ch</i> */
  106785. + volatile uint32_t guid;
  106786. + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
  106787. + volatile uint32_t gsnpsid;
  106788. + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
  106789. + volatile uint32_t ghwcfg1;
  106790. + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
  106791. + volatile uint32_t ghwcfg2;
  106792. +#define DWC_SLAVE_ONLY_ARCH 0
  106793. +#define DWC_EXT_DMA_ARCH 1
  106794. +#define DWC_INT_DMA_ARCH 2
  106795. +
  106796. +#define DWC_MODE_HNP_SRP_CAPABLE 0
  106797. +#define DWC_MODE_SRP_ONLY_CAPABLE 1
  106798. +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
  106799. +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
  106800. +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
  106801. +#define DWC_MODE_SRP_CAPABLE_HOST 5
  106802. +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
  106803. +
  106804. + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
  106805. + volatile uint32_t ghwcfg3;
  106806. + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
  106807. + volatile uint32_t ghwcfg4;
  106808. + /** Core LPM Configuration register <i>Offset: 054h</i>*/
  106809. + volatile uint32_t glpmcfg;
  106810. + /** Global PowerDn Register <i>Offset: 058h</i> */
  106811. + volatile uint32_t gpwrdn;
  106812. + /** Global DFIFO SW Config Register <i>Offset: 05Ch</i> */
  106813. + volatile uint32_t gdfifocfg;
  106814. + /** ADP Control Register <i>Offset: 060h</i> */
  106815. + volatile uint32_t adpctl;
  106816. + /** Reserved <i>Offset: 064h-0FFh</i> */
  106817. + volatile uint32_t reserved39[39];
  106818. + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
  106819. + volatile uint32_t hptxfsiz;
  106820. + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
  106821. + otherwise Device Transmit FIFO#n Register.
  106822. + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
  106823. + volatile uint32_t dtxfsiz[15];
  106824. +} dwc_otg_core_global_regs_t;
  106825. +
  106826. +/**
  106827. + * This union represents the bit fields of the Core OTG Control
  106828. + * and Status Register (GOTGCTL). Set the bits using the bit
  106829. + * fields then write the <i>d32</i> value to the register.
  106830. + */
  106831. +typedef union gotgctl_data {
  106832. + /** raw register data */
  106833. + uint32_t d32;
  106834. + /** register bits */
  106835. + struct {
  106836. + unsigned sesreqscs:1;
  106837. + unsigned sesreq:1;
  106838. + unsigned vbvalidoven:1;
  106839. + unsigned vbvalidovval:1;
  106840. + unsigned avalidoven:1;
  106841. + unsigned avalidovval:1;
  106842. + unsigned bvalidoven:1;
  106843. + unsigned bvalidovval:1;
  106844. + unsigned hstnegscs:1;
  106845. + unsigned hnpreq:1;
  106846. + unsigned hstsethnpen:1;
  106847. + unsigned devhnpen:1;
  106848. + unsigned reserved12_15:4;
  106849. + unsigned conidsts:1;
  106850. + unsigned dbnctime:1;
  106851. + unsigned asesvld:1;
  106852. + unsigned bsesvld:1;
  106853. + unsigned otgver:1;
  106854. + unsigned reserved1:1;
  106855. + unsigned multvalidbc:5;
  106856. + unsigned chirpen:1;
  106857. + unsigned reserved28_31:4;
  106858. + } b;
  106859. +} gotgctl_data_t;
  106860. +
  106861. +/**
  106862. + * This union represents the bit fields of the Core OTG Interrupt Register
  106863. + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
  106864. + * value to the register.
  106865. + */
  106866. +typedef union gotgint_data {
  106867. + /** raw register data */
  106868. + uint32_t d32;
  106869. + /** register bits */
  106870. + struct {
  106871. + /** Current Mode */
  106872. + unsigned reserved0_1:2;
  106873. +
  106874. + /** Session End Detected */
  106875. + unsigned sesenddet:1;
  106876. +
  106877. + unsigned reserved3_7:5;
  106878. +
  106879. + /** Session Request Success Status Change */
  106880. + unsigned sesreqsucstschng:1;
  106881. + /** Host Negotiation Success Status Change */
  106882. + unsigned hstnegsucstschng:1;
  106883. +
  106884. + unsigned reserved10_16:7;
  106885. +
  106886. + /** Host Negotiation Detected */
  106887. + unsigned hstnegdet:1;
  106888. + /** A-Device Timeout Change */
  106889. + unsigned adevtoutchng:1;
  106890. + /** Debounce Done */
  106891. + unsigned debdone:1;
  106892. + /** Multi-Valued input changed */
  106893. + unsigned mvic:1;
  106894. +
  106895. + unsigned reserved31_21:11;
  106896. +
  106897. + } b;
  106898. +} gotgint_data_t;
  106899. +
  106900. +/**
  106901. + * This union represents the bit fields of the Core AHB Configuration
  106902. + * Register (GAHBCFG). Set/clear the bits using the bit fields then
  106903. + * write the <i>d32</i> value to the register.
  106904. + */
  106905. +typedef union gahbcfg_data {
  106906. + /** raw register data */
  106907. + uint32_t d32;
  106908. + /** register bits */
  106909. + struct {
  106910. + unsigned glblintrmsk:1;
  106911. +#define DWC_GAHBCFG_GLBINT_ENABLE 1
  106912. +
  106913. + unsigned hburstlen:4;
  106914. +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
  106915. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
  106916. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
  106917. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
  106918. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
  106919. +
  106920. + unsigned dmaenable:1;
  106921. +#define DWC_GAHBCFG_DMAENABLE 1
  106922. + unsigned reserved:1;
  106923. + unsigned nptxfemplvl_txfemplvl:1;
  106924. + unsigned ptxfemplvl:1;
  106925. +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
  106926. +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
  106927. + unsigned reserved9_20:12;
  106928. + unsigned remmemsupp:1;
  106929. + unsigned notialldmawrit:1;
  106930. + unsigned ahbsingle:1;
  106931. + unsigned reserved24_31:8;
  106932. + } b;
  106933. +} gahbcfg_data_t;
  106934. +
  106935. +/**
  106936. + * This union represents the bit fields of the Core USB Configuration
  106937. + * Register (GUSBCFG). Set the bits using the bit fields then write
  106938. + * the <i>d32</i> value to the register.
  106939. + */
  106940. +typedef union gusbcfg_data {
  106941. + /** raw register data */
  106942. + uint32_t d32;
  106943. + /** register bits */
  106944. + struct {
  106945. + unsigned toutcal:3;
  106946. + unsigned phyif:1;
  106947. + unsigned ulpi_utmi_sel:1;
  106948. + unsigned fsintf:1;
  106949. + unsigned physel:1;
  106950. + unsigned ddrsel:1;
  106951. + unsigned srpcap:1;
  106952. + unsigned hnpcap:1;
  106953. + unsigned usbtrdtim:4;
  106954. + unsigned reserved1:1;
  106955. + unsigned phylpwrclksel:1;
  106956. + unsigned otgutmifssel:1;
  106957. + unsigned ulpi_fsls:1;
  106958. + unsigned ulpi_auto_res:1;
  106959. + unsigned ulpi_clk_sus_m:1;
  106960. + unsigned ulpi_ext_vbus_drv:1;
  106961. + unsigned ulpi_int_vbus_indicator:1;
  106962. + unsigned term_sel_dl_pulse:1;
  106963. + unsigned indicator_complement:1;
  106964. + unsigned indicator_pass_through:1;
  106965. + unsigned ulpi_int_prot_dis:1;
  106966. + unsigned ic_usb_cap:1;
  106967. + unsigned ic_traffic_pull_remove:1;
  106968. + unsigned tx_end_delay:1;
  106969. + unsigned force_host_mode:1;
  106970. + unsigned force_dev_mode:1;
  106971. + unsigned reserved31:1;
  106972. + } b;
  106973. +} gusbcfg_data_t;
  106974. +
  106975. +/**
  106976. + * This union represents the bit fields of the Core Reset Register
  106977. + * (GRSTCTL). Set/clear the bits using the bit fields then write the
  106978. + * <i>d32</i> value to the register.
  106979. + */
  106980. +typedef union grstctl_data {
  106981. + /** raw register data */
  106982. + uint32_t d32;
  106983. + /** register bits */
  106984. + struct {
  106985. + /** Core Soft Reset (CSftRst) (Device and Host)
  106986. + *
  106987. + * The application can flush the control logic in the
  106988. + * entire core using this bit. This bit resets the
  106989. + * pipelines in the AHB Clock domain as well as the
  106990. + * PHY Clock domain.
  106991. + *
  106992. + * The state machines are reset to an IDLE state, the
  106993. + * control bits in the CSRs are cleared, all the
  106994. + * transmit FIFOs and the receive FIFO are flushed.
  106995. + *
  106996. + * The status mask bits that control the generation of
  106997. + * the interrupt, are cleared, to clear the
  106998. + * interrupt. The interrupt status bits are not
  106999. + * cleared, so the application can get the status of
  107000. + * any events that occurred in the core after it has
  107001. + * set this bit.
  107002. + *
  107003. + * Any transactions on the AHB are terminated as soon
  107004. + * as possible following the protocol. Any
  107005. + * transactions on the USB are terminated immediately.
  107006. + *
  107007. + * The configuration settings in the CSRs are
  107008. + * unchanged, so the software doesn't have to
  107009. + * reprogram these registers (Device
  107010. + * Configuration/Host Configuration/Core System
  107011. + * Configuration/Core PHY Configuration).
  107012. + *
  107013. + * The application can write to this bit, any time it
  107014. + * wants to reset the core. This is a self clearing
  107015. + * bit and the core clears this bit after all the
  107016. + * necessary logic is reset in the core, which may
  107017. + * take several clocks, depending on the current state
  107018. + * of the core.
  107019. + */
  107020. + unsigned csftrst:1;
  107021. + /** Hclk Soft Reset
  107022. + *
  107023. + * The application uses this bit to reset the control logic in
  107024. + * the AHB clock domain. Only AHB clock domain pipelines are
  107025. + * reset.
  107026. + */
  107027. + unsigned hsftrst:1;
  107028. + /** Host Frame Counter Reset (Host Only)<br>
  107029. + *
  107030. + * The application can reset the (micro)frame number
  107031. + * counter inside the core, using this bit. When the
  107032. + * (micro)frame counter is reset, the subsequent SOF
  107033. + * sent out by the core, will have a (micro)frame
  107034. + * number of 0.
  107035. + */
  107036. + unsigned hstfrm:1;
  107037. + /** In Token Sequence Learning Queue Flush
  107038. + * (INTknQFlsh) (Device Only)
  107039. + */
  107040. + unsigned intknqflsh:1;
  107041. + /** RxFIFO Flush (RxFFlsh) (Device and Host)
  107042. + *
  107043. + * The application can flush the entire Receive FIFO
  107044. + * using this bit. The application must first
  107045. + * ensure that the core is not in the middle of a
  107046. + * transaction. The application should write into
  107047. + * this bit, only after making sure that neither the
  107048. + * DMA engine is reading from the RxFIFO nor the MAC
  107049. + * is writing the data in to the FIFO. The
  107050. + * application should wait until the bit is cleared
  107051. + * before performing any other operations. This bit
  107052. + * will takes 8 clocks (slowest of PHY or AHB clock)
  107053. + * to clear.
  107054. + */
  107055. + unsigned rxfflsh:1;
  107056. + /** TxFIFO Flush (TxFFlsh) (Device and Host).
  107057. + *
  107058. + * This bit is used to selectively flush a single or
  107059. + * all transmit FIFOs. The application must first
  107060. + * ensure that the core is not in the middle of a
  107061. + * transaction. The application should write into
  107062. + * this bit, only after making sure that neither the
  107063. + * DMA engine is writing into the TxFIFO nor the MAC
  107064. + * is reading the data out of the FIFO. The
  107065. + * application should wait until the core clears this
  107066. + * bit, before performing any operations. This bit
  107067. + * will takes 8 clocks (slowest of PHY or AHB clock)
  107068. + * to clear.
  107069. + */
  107070. + unsigned txfflsh:1;
  107071. +
  107072. + /** TxFIFO Number (TxFNum) (Device and Host).
  107073. + *
  107074. + * This is the FIFO number which needs to be flushed,
  107075. + * using the TxFIFO Flush bit. This field should not
  107076. + * be changed until the TxFIFO Flush bit is cleared by
  107077. + * the core.
  107078. + * - 0x0 : Non Periodic TxFIFO Flush
  107079. + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
  107080. + * or Periodic TxFIFO in host mode
  107081. + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
  107082. + * - ...
  107083. + * - 0xF : Periodic TxFIFO #15 Flush in device mode
  107084. + * - 0x10: Flush all the Transmit NonPeriodic and
  107085. + * Transmit Periodic FIFOs in the core
  107086. + */
  107087. + unsigned txfnum:5;
  107088. + /** Reserved */
  107089. + unsigned reserved11_29:19;
  107090. + /** DMA Request Signal. Indicated DMA request is in
  107091. + * probress. Used for debug purpose. */
  107092. + unsigned dmareq:1;
  107093. + /** AHB Master Idle. Indicates the AHB Master State
  107094. + * Machine is in IDLE condition. */
  107095. + unsigned ahbidle:1;
  107096. + } b;
  107097. +} grstctl_t;
  107098. +
  107099. +/**
  107100. + * This union represents the bit fields of the Core Interrupt Mask
  107101. + * Register (GINTMSK). Set/clear the bits using the bit fields then
  107102. + * write the <i>d32</i> value to the register.
  107103. + */
  107104. +typedef union gintmsk_data {
  107105. + /** raw register data */
  107106. + uint32_t d32;
  107107. + /** register bits */
  107108. + struct {
  107109. + unsigned reserved0:1;
  107110. + unsigned modemismatch:1;
  107111. + unsigned otgintr:1;
  107112. + unsigned sofintr:1;
  107113. + unsigned rxstsqlvl:1;
  107114. + unsigned nptxfempty:1;
  107115. + unsigned ginnakeff:1;
  107116. + unsigned goutnakeff:1;
  107117. + unsigned ulpickint:1;
  107118. + unsigned i2cintr:1;
  107119. + unsigned erlysuspend:1;
  107120. + unsigned usbsuspend:1;
  107121. + unsigned usbreset:1;
  107122. + unsigned enumdone:1;
  107123. + unsigned isooutdrop:1;
  107124. + unsigned eopframe:1;
  107125. + unsigned restoredone:1;
  107126. + unsigned epmismatch:1;
  107127. + unsigned inepintr:1;
  107128. + unsigned outepintr:1;
  107129. + unsigned incomplisoin:1;
  107130. + unsigned incomplisoout:1;
  107131. + unsigned fetsusp:1;
  107132. + unsigned resetdet:1;
  107133. + unsigned portintr:1;
  107134. + unsigned hcintr:1;
  107135. + unsigned ptxfempty:1;
  107136. + unsigned lpmtranrcvd:1;
  107137. + unsigned conidstschng:1;
  107138. + unsigned disconnect:1;
  107139. + unsigned sessreqintr:1;
  107140. + unsigned wkupintr:1;
  107141. + } b;
  107142. +} gintmsk_data_t;
  107143. +/**
  107144. + * This union represents the bit fields of the Core Interrupt Register
  107145. + * (GINTSTS). Set/clear the bits using the bit fields then write the
  107146. + * <i>d32</i> value to the register.
  107147. + */
  107148. +typedef union gintsts_data {
  107149. + /** raw register data */
  107150. + uint32_t d32;
  107151. +#define DWC_SOF_INTR_MASK 0x0008
  107152. + /** register bits */
  107153. + struct {
  107154. +#define DWC_HOST_MODE 1
  107155. + unsigned curmode:1;
  107156. + unsigned modemismatch:1;
  107157. + unsigned otgintr:1;
  107158. + unsigned sofintr:1;
  107159. + unsigned rxstsqlvl:1;
  107160. + unsigned nptxfempty:1;
  107161. + unsigned ginnakeff:1;
  107162. + unsigned goutnakeff:1;
  107163. + unsigned ulpickint:1;
  107164. + unsigned i2cintr:1;
  107165. + unsigned erlysuspend:1;
  107166. + unsigned usbsuspend:1;
  107167. + unsigned usbreset:1;
  107168. + unsigned enumdone:1;
  107169. + unsigned isooutdrop:1;
  107170. + unsigned eopframe:1;
  107171. + unsigned restoredone:1;
  107172. + unsigned epmismatch:1;
  107173. + unsigned inepint:1;
  107174. + unsigned outepintr:1;
  107175. + unsigned incomplisoin:1;
  107176. + unsigned incomplisoout:1;
  107177. + unsigned fetsusp:1;
  107178. + unsigned resetdet:1;
  107179. + unsigned portintr:1;
  107180. + unsigned hcintr:1;
  107181. + unsigned ptxfempty:1;
  107182. + unsigned lpmtranrcvd:1;
  107183. + unsigned conidstschng:1;
  107184. + unsigned disconnect:1;
  107185. + unsigned sessreqintr:1;
  107186. + unsigned wkupintr:1;
  107187. + } b;
  107188. +} gintsts_data_t;
  107189. +
  107190. +/**
  107191. + * This union represents the bit fields in the Device Receive Status Read and
  107192. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  107193. + * element then read out the bits using the <i>b</i>it elements.
  107194. + */
  107195. +typedef union device_grxsts_data {
  107196. + /** raw register data */
  107197. + uint32_t d32;
  107198. + /** register bits */
  107199. + struct {
  107200. + unsigned epnum:4;
  107201. + unsigned bcnt:11;
  107202. + unsigned dpid:2;
  107203. +
  107204. +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
  107205. +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
  107206. +
  107207. +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
  107208. +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
  107209. +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
  107210. + unsigned pktsts:4;
  107211. + unsigned fn:4;
  107212. + unsigned reserved25_31:7;
  107213. + } b;
  107214. +} device_grxsts_data_t;
  107215. +
  107216. +/**
  107217. + * This union represents the bit fields in the Host Receive Status Read and
  107218. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  107219. + * element then read out the bits using the <i>b</i>it elements.
  107220. + */
  107221. +typedef union host_grxsts_data {
  107222. + /** raw register data */
  107223. + uint32_t d32;
  107224. + /** register bits */
  107225. + struct {
  107226. + unsigned chnum:4;
  107227. + unsigned bcnt:11;
  107228. + unsigned dpid:2;
  107229. +
  107230. + unsigned pktsts:4;
  107231. +#define DWC_GRXSTS_PKTSTS_IN 0x2
  107232. +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
  107233. +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
  107234. +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
  107235. +
  107236. + unsigned reserved21_31:11;
  107237. + } b;
  107238. +} host_grxsts_data_t;
  107239. +
  107240. +/**
  107241. + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
  107242. + * GNPTXFSIZ, DPTXFSIZn, DIEPTXFn). Read the register into the <i>d32</i> element
  107243. + * then read out the bits using the <i>b</i>it elements.
  107244. + */
  107245. +typedef union fifosize_data {
  107246. + /** raw register data */
  107247. + uint32_t d32;
  107248. + /** register bits */
  107249. + struct {
  107250. + unsigned startaddr:16;
  107251. + unsigned depth:16;
  107252. + } b;
  107253. +} fifosize_data_t;
  107254. +
  107255. +/**
  107256. + * This union represents the bit fields in the Non-Periodic Transmit
  107257. + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
  107258. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  107259. + * elements.
  107260. + */
  107261. +typedef union gnptxsts_data {
  107262. + /** raw register data */
  107263. + uint32_t d32;
  107264. + /** register bits */
  107265. + struct {
  107266. + unsigned nptxfspcavail:16;
  107267. + unsigned nptxqspcavail:8;
  107268. + /** Top of the Non-Periodic Transmit Request Queue
  107269. + * - bit 24 - Terminate (Last entry for the selected
  107270. + * channel/EP)
  107271. + * - bits 26:25 - Token Type
  107272. + * - 2'b00 - IN/OUT
  107273. + * - 2'b01 - Zero Length OUT
  107274. + * - 2'b10 - PING/Complete Split
  107275. + * - 2'b11 - Channel Halt
  107276. + * - bits 30:27 - Channel/EP Number
  107277. + */
  107278. + unsigned nptxqtop_terminate:1;
  107279. + unsigned nptxqtop_token:2;
  107280. + unsigned nptxqtop_chnep:4;
  107281. + unsigned reserved:1;
  107282. + } b;
  107283. +} gnptxsts_data_t;
  107284. +
  107285. +/**
  107286. + * This union represents the bit fields in the Transmit
  107287. + * FIFO Status Register (DTXFSTS). Read the register into the
  107288. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  107289. + * elements.
  107290. + */
  107291. +typedef union dtxfsts_data {
  107292. + /** raw register data */
  107293. + uint32_t d32;
  107294. + /** register bits */
  107295. + struct {
  107296. + unsigned txfspcavail:16;
  107297. + unsigned reserved:16;
  107298. + } b;
  107299. +} dtxfsts_data_t;
  107300. +
  107301. +/**
  107302. + * This union represents the bit fields in the I2C Control Register
  107303. + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
  107304. + * bits using the <i>b</i>it elements.
  107305. + */
  107306. +typedef union gi2cctl_data {
  107307. + /** raw register data */
  107308. + uint32_t d32;
  107309. + /** register bits */
  107310. + struct {
  107311. + unsigned rwdata:8;
  107312. + unsigned regaddr:8;
  107313. + unsigned addr:7;
  107314. + unsigned i2cen:1;
  107315. + unsigned ack:1;
  107316. + unsigned i2csuspctl:1;
  107317. + unsigned i2cdevaddr:2;
  107318. + unsigned i2cdatse0:1;
  107319. + unsigned reserved:1;
  107320. + unsigned rw:1;
  107321. + unsigned bsydne:1;
  107322. + } b;
  107323. +} gi2cctl_data_t;
  107324. +
  107325. +/**
  107326. + * This union represents the bit fields in the PHY Vendor Control Register
  107327. + * (GPVNDCTL). Read the register into the <i>d32</i> element then read out the
  107328. + * bits using the <i>b</i>it elements.
  107329. + */
  107330. +typedef union gpvndctl_data {
  107331. + /** raw register data */
  107332. + uint32_t d32;
  107333. + /** register bits */
  107334. + struct {
  107335. + unsigned regdata:8;
  107336. + unsigned vctrl:8;
  107337. + unsigned regaddr16_21:6;
  107338. + unsigned regwr:1;
  107339. + unsigned reserved23_24:2;
  107340. + unsigned newregreq:1;
  107341. + unsigned vstsbsy:1;
  107342. + unsigned vstsdone:1;
  107343. + unsigned reserved28_30:3;
  107344. + unsigned disulpidrvr:1;
  107345. + } b;
  107346. +} gpvndctl_data_t;
  107347. +
  107348. +/**
  107349. + * This union represents the bit fields in the General Purpose
  107350. + * Input/Output Register (GGPIO).
  107351. + * Read the register into the <i>d32</i> element then read out the
  107352. + * bits using the <i>b</i>it elements.
  107353. + */
  107354. +typedef union ggpio_data {
  107355. + /** raw register data */
  107356. + uint32_t d32;
  107357. + /** register bits */
  107358. + struct {
  107359. + unsigned gpi:16;
  107360. + unsigned gpo:16;
  107361. + } b;
  107362. +} ggpio_data_t;
  107363. +
  107364. +/**
  107365. + * This union represents the bit fields in the User ID Register
  107366. + * (GUID). Read the register into the <i>d32</i> element then read out the
  107367. + * bits using the <i>b</i>it elements.
  107368. + */
  107369. +typedef union guid_data {
  107370. + /** raw register data */
  107371. + uint32_t d32;
  107372. + /** register bits */
  107373. + struct {
  107374. + unsigned rwdata:32;
  107375. + } b;
  107376. +} guid_data_t;
  107377. +
  107378. +/**
  107379. + * This union represents the bit fields in the Synopsys ID Register
  107380. + * (GSNPSID). Read the register into the <i>d32</i> element then read out the
  107381. + * bits using the <i>b</i>it elements.
  107382. + */
  107383. +typedef union gsnpsid_data {
  107384. + /** raw register data */
  107385. + uint32_t d32;
  107386. + /** register bits */
  107387. + struct {
  107388. + unsigned rwdata:32;
  107389. + } b;
  107390. +} gsnpsid_data_t;
  107391. +
  107392. +/**
  107393. + * This union represents the bit fields in the User HW Config1
  107394. + * Register. Read the register into the <i>d32</i> element then read
  107395. + * out the bits using the <i>b</i>it elements.
  107396. + */
  107397. +typedef union hwcfg1_data {
  107398. + /** raw register data */
  107399. + uint32_t d32;
  107400. + /** register bits */
  107401. + struct {
  107402. + unsigned ep_dir0:2;
  107403. + unsigned ep_dir1:2;
  107404. + unsigned ep_dir2:2;
  107405. + unsigned ep_dir3:2;
  107406. + unsigned ep_dir4:2;
  107407. + unsigned ep_dir5:2;
  107408. + unsigned ep_dir6:2;
  107409. + unsigned ep_dir7:2;
  107410. + unsigned ep_dir8:2;
  107411. + unsigned ep_dir9:2;
  107412. + unsigned ep_dir10:2;
  107413. + unsigned ep_dir11:2;
  107414. + unsigned ep_dir12:2;
  107415. + unsigned ep_dir13:2;
  107416. + unsigned ep_dir14:2;
  107417. + unsigned ep_dir15:2;
  107418. + } b;
  107419. +} hwcfg1_data_t;
  107420. +
  107421. +/**
  107422. + * This union represents the bit fields in the User HW Config2
  107423. + * Register. Read the register into the <i>d32</i> element then read
  107424. + * out the bits using the <i>b</i>it elements.
  107425. + */
  107426. +typedef union hwcfg2_data {
  107427. + /** raw register data */
  107428. + uint32_t d32;
  107429. + /** register bits */
  107430. + struct {
  107431. + /* GHWCFG2 */
  107432. + unsigned op_mode:3;
  107433. +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
  107434. +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
  107435. +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
  107436. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
  107437. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
  107438. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
  107439. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
  107440. +
  107441. + unsigned architecture:2;
  107442. + unsigned point2point:1;
  107443. + unsigned hs_phy_type:2;
  107444. +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
  107445. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
  107446. +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
  107447. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
  107448. +
  107449. + unsigned fs_phy_type:2;
  107450. + unsigned num_dev_ep:4;
  107451. + unsigned num_host_chan:4;
  107452. + unsigned perio_ep_supported:1;
  107453. + unsigned dynamic_fifo:1;
  107454. + unsigned multi_proc_int:1;
  107455. + unsigned reserved21:1;
  107456. + unsigned nonperio_tx_q_depth:2;
  107457. + unsigned host_perio_tx_q_depth:2;
  107458. + unsigned dev_token_q_depth:5;
  107459. + unsigned otg_enable_ic_usb:1;
  107460. + } b;
  107461. +} hwcfg2_data_t;
  107462. +
  107463. +/**
  107464. + * This union represents the bit fields in the User HW Config3
  107465. + * Register. Read the register into the <i>d32</i> element then read
  107466. + * out the bits using the <i>b</i>it elements.
  107467. + */
  107468. +typedef union hwcfg3_data {
  107469. + /** raw register data */
  107470. + uint32_t d32;
  107471. + /** register bits */
  107472. + struct {
  107473. + /* GHWCFG3 */
  107474. + unsigned xfer_size_cntr_width:4;
  107475. + unsigned packet_size_cntr_width:3;
  107476. + unsigned otg_func:1;
  107477. + unsigned i2c:1;
  107478. + unsigned vendor_ctrl_if:1;
  107479. + unsigned optional_features:1;
  107480. + unsigned synch_reset_type:1;
  107481. + unsigned adp_supp:1;
  107482. + unsigned otg_enable_hsic:1;
  107483. + unsigned bc_support:1;
  107484. + unsigned otg_lpm_en:1;
  107485. + unsigned dfifo_depth:16;
  107486. + } b;
  107487. +} hwcfg3_data_t;
  107488. +
  107489. +/**
  107490. + * This union represents the bit fields in the User HW Config4
  107491. + * Register. Read the register into the <i>d32</i> element then read
  107492. + * out the bits using the <i>b</i>it elements.
  107493. + */
  107494. +typedef union hwcfg4_data {
  107495. + /** raw register data */
  107496. + uint32_t d32;
  107497. + /** register bits */
  107498. + struct {
  107499. + unsigned num_dev_perio_in_ep:4;
  107500. + unsigned power_optimiz:1;
  107501. + unsigned min_ahb_freq:1;
  107502. + unsigned hiber:1;
  107503. + unsigned xhiber:1;
  107504. + unsigned reserved:6;
  107505. + unsigned utmi_phy_data_width:2;
  107506. + unsigned num_dev_mode_ctrl_ep:4;
  107507. + unsigned iddig_filt_en:1;
  107508. + unsigned vbus_valid_filt_en:1;
  107509. + unsigned a_valid_filt_en:1;
  107510. + unsigned b_valid_filt_en:1;
  107511. + unsigned session_end_filt_en:1;
  107512. + unsigned ded_fifo_en:1;
  107513. + unsigned num_in_eps:4;
  107514. + unsigned desc_dma:1;
  107515. + unsigned desc_dma_dyn:1;
  107516. + } b;
  107517. +} hwcfg4_data_t;
  107518. +
  107519. +/**
  107520. + * This union represents the bit fields of the Core LPM Configuration
  107521. + * Register (GLPMCFG). Set the bits using bit fields then write
  107522. + * the <i>d32</i> value to the register.
  107523. + */
  107524. +typedef union glpmctl_data {
  107525. + /** raw register data */
  107526. + uint32_t d32;
  107527. + /** register bits */
  107528. + struct {
  107529. + /** LPM-Capable (LPMCap) (Device and Host)
  107530. + * The application uses this bit to control
  107531. + * the DWC_otg core LPM capabilities.
  107532. + */
  107533. + unsigned lpm_cap_en:1;
  107534. + /** LPM response programmed by application (AppL1Res) (Device)
  107535. + * Handshake response to LPM token pre-programmed
  107536. + * by device application software.
  107537. + */
  107538. + unsigned appl_resp:1;
  107539. + /** Host Initiated Resume Duration (HIRD) (Device and Host)
  107540. + * In Host mode this field indicates the value of HIRD
  107541. + * to be sent in an LPM transaction.
  107542. + * In Device mode this field is updated with the
  107543. + * Received LPM Token HIRD bmAttribute
  107544. + * when an ACK/NYET/STALL response is sent
  107545. + * to an LPM transaction.
  107546. + */
  107547. + unsigned hird:4;
  107548. + /** RemoteWakeEnable (bRemoteWake) (Device and Host)
  107549. + * In Host mode this bit indicates the value of remote
  107550. + * wake up to be sent in wIndex field of LPM transaction.
  107551. + * In Device mode this field is updated with the
  107552. + * Received LPM Token bRemoteWake bmAttribute
  107553. + * when an ACK/NYET/STALL response is sent
  107554. + * to an LPM transaction.
  107555. + */
  107556. + unsigned rem_wkup_en:1;
  107557. + /** Enable utmi_sleep_n (EnblSlpM) (Device and Host)
  107558. + * The application uses this bit to control
  107559. + * the utmi_sleep_n assertion to the PHY when in L1 state.
  107560. + */
  107561. + unsigned en_utmi_sleep:1;
  107562. + /** HIRD Threshold (HIRD_Thres) (Device and Host)
  107563. + */
  107564. + unsigned hird_thres:5;
  107565. + /** LPM Response (CoreL1Res) (Device and Host)
  107566. + * In Host mode this bit contains handsake response to
  107567. + * LPM transaction.
  107568. + * In Device mode the response of the core to
  107569. + * LPM transaction received is reflected in these two bits.
  107570. + - 0x0 : ERROR (No handshake response)
  107571. + - 0x1 : STALL
  107572. + - 0x2 : NYET
  107573. + - 0x3 : ACK
  107574. + */
  107575. + unsigned lpm_resp:2;
  107576. + /** Port Sleep Status (SlpSts) (Device and Host)
  107577. + * This bit is set as long as a Sleep condition
  107578. + * is present on the USB bus.
  107579. + */
  107580. + unsigned prt_sleep_sts:1;
  107581. + /** Sleep State Resume OK (L1ResumeOK) (Device and Host)
  107582. + * Indicates that the application or host
  107583. + * can start resume from Sleep state.
  107584. + */
  107585. + unsigned sleep_state_resumeok:1;
  107586. + /** LPM channel Index (LPM_Chnl_Indx) (Host)
  107587. + * The channel number on which the LPM transaction
  107588. + * has to be applied while sending
  107589. + * an LPM transaction to the local device.
  107590. + */
  107591. + unsigned lpm_chan_index:4;
  107592. + /** LPM Retry Count (LPM_Retry_Cnt) (Host)
  107593. + * Number host retries that would be performed
  107594. + * if the device response was not valid response.
  107595. + */
  107596. + unsigned retry_count:3;
  107597. + /** Send LPM Transaction (SndLPM) (Host)
  107598. + * When set by application software,
  107599. + * an LPM transaction containing two tokens
  107600. + * is sent.
  107601. + */
  107602. + unsigned send_lpm:1;
  107603. + /** LPM Retry status (LPM_RetryCnt_Sts) (Host)
  107604. + * Number of LPM Host Retries still remaining
  107605. + * to be transmitted for the current LPM sequence
  107606. + */
  107607. + unsigned retry_count_sts:3;
  107608. + unsigned reserved28_29:2;
  107609. + /** In host mode once this bit is set, the host
  107610. + * configures to drive the HSIC Idle state on the bus.
  107611. + * It then waits for the device to initiate the Connect sequence.
  107612. + * In device mode once this bit is set, the device waits for
  107613. + * the HSIC Idle line state on the bus. Upon receving the Idle
  107614. + * line state, it initiates the HSIC Connect sequence.
  107615. + */
  107616. + unsigned hsic_connect:1;
  107617. + /** This bit overrides and functionally inverts
  107618. + * the if_select_hsic input port signal.
  107619. + */
  107620. + unsigned inv_sel_hsic:1;
  107621. + } b;
  107622. +} glpmcfg_data_t;
  107623. +
  107624. +/**
  107625. + * This union represents the bit fields of the Core ADP Timer, Control and
  107626. + * Status Register (ADPTIMCTLSTS). Set the bits using bit fields then write
  107627. + * the <i>d32</i> value to the register.
  107628. + */
  107629. +typedef union adpctl_data {
  107630. + /** raw register data */
  107631. + uint32_t d32;
  107632. + /** register bits */
  107633. + struct {
  107634. + /** Probe Discharge (PRB_DSCHG)
  107635. + * These bits set the times for TADP_DSCHG.
  107636. + * These bits are defined as follows:
  107637. + * 2'b00 - 4 msec
  107638. + * 2'b01 - 8 msec
  107639. + * 2'b10 - 16 msec
  107640. + * 2'b11 - 32 msec
  107641. + */
  107642. + unsigned prb_dschg:2;
  107643. + /** Probe Delta (PRB_DELTA)
  107644. + * These bits set the resolution for RTIM value.
  107645. + * The bits are defined in units of 32 kHz clock cycles as follows:
  107646. + * 2'b00 - 1 cycles
  107647. + * 2'b01 - 2 cycles
  107648. + * 2'b10 - 3 cycles
  107649. + * 2'b11 - 4 cycles
  107650. + * For example if this value is chosen to 2'b01, it means that RTIM
  107651. + * increments for every 3(three) 32Khz clock cycles.
  107652. + */
  107653. + unsigned prb_delta:2;
  107654. + /** Probe Period (PRB_PER)
  107655. + * These bits sets the TADP_PRD as shown in Figure 4 as follows:
  107656. + * 2'b00 - 0.625 to 0.925 sec (typical 0.775 sec)
  107657. + * 2'b01 - 1.25 to 1.85 sec (typical 1.55 sec)
  107658. + * 2'b10 - 1.9 to 2.6 sec (typical 2.275 sec)
  107659. + * 2'b11 - Reserved
  107660. + */
  107661. + unsigned prb_per:2;
  107662. + /** These bits capture the latest time it took for VBUS to ramp from
  107663. + * VADP_SINK to VADP_PRB.
  107664. + * 0x000 - 1 cycles
  107665. + * 0x001 - 2 cycles
  107666. + * 0x002 - 3 cycles
  107667. + * etc
  107668. + * 0x7FF - 2048 cycles
  107669. + * A time of 1024 cycles at 32 kHz corresponds to a time of 32 msec.
  107670. + */
  107671. + unsigned rtim:11;
  107672. + /** Enable Probe (EnaPrb)
  107673. + * When programmed to 1'b1, the core performs a probe operation.
  107674. + * This bit is valid only if OTG_Ver = 1'b1.
  107675. + */
  107676. + unsigned enaprb:1;
  107677. + /** Enable Sense (EnaSns)
  107678. + * When programmed to 1'b1, the core performs a Sense operation.
  107679. + * This bit is valid only if OTG_Ver = 1'b1.
  107680. + */
  107681. + unsigned enasns:1;
  107682. + /** ADP Reset (ADPRes)
  107683. + * When set, ADP controller is reset.
  107684. + * This bit is valid only if OTG_Ver = 1'b1.
  107685. + */
  107686. + unsigned adpres:1;
  107687. + /** ADP Enable (ADPEn)
  107688. + * When set, the core performs either ADP probing or sensing
  107689. + * based on EnaPrb or EnaSns.
  107690. + * This bit is valid only if OTG_Ver = 1'b1.
  107691. + */
  107692. + unsigned adpen:1;
  107693. + /** ADP Probe Interrupt (ADP_PRB_INT)
  107694. + * When this bit is set, it means that the VBUS
  107695. + * voltage is greater than VADP_PRB or VADP_PRB is reached.
  107696. + * This bit is valid only if OTG_Ver = 1'b1.
  107697. + */
  107698. + unsigned adp_prb_int:1;
  107699. + /**
  107700. + * ADP Sense Interrupt (ADP_SNS_INT)
  107701. + * When this bit is set, it means that the VBUS voltage is greater than
  107702. + * VADP_SNS value or VADP_SNS is reached.
  107703. + * This bit is valid only if OTG_Ver = 1'b1.
  107704. + */
  107705. + unsigned adp_sns_int:1;
  107706. + /** ADP Tomeout Interrupt (ADP_TMOUT_INT)
  107707. + * This bit is relevant only for an ADP probe.
  107708. + * When this bit is set, it means that the ramp time has
  107709. + * completed ie ADPCTL.RTIM has reached its terminal value
  107710. + * of 0x7FF. This is a debug feature that allows software
  107711. + * to read the ramp time after each cycle.
  107712. + * This bit is valid only if OTG_Ver = 1'b1.
  107713. + */
  107714. + unsigned adp_tmout_int:1;
  107715. + /** ADP Probe Interrupt Mask (ADP_PRB_INT_MSK)
  107716. + * When this bit is set, it unmasks the interrupt due to ADP_PRB_INT.
  107717. + * This bit is valid only if OTG_Ver = 1'b1.
  107718. + */
  107719. + unsigned adp_prb_int_msk:1;
  107720. + /** ADP Sense Interrupt Mask (ADP_SNS_INT_MSK)
  107721. + * When this bit is set, it unmasks the interrupt due to ADP_SNS_INT.
  107722. + * This bit is valid only if OTG_Ver = 1'b1.
  107723. + */
  107724. + unsigned adp_sns_int_msk:1;
  107725. + /** ADP Timoeout Interrupt Mask (ADP_TMOUT_MSK)
  107726. + * When this bit is set, it unmasks the interrupt due to ADP_TMOUT_INT.
  107727. + * This bit is valid only if OTG_Ver = 1'b1.
  107728. + */
  107729. + unsigned adp_tmout_int_msk:1;
  107730. + /** Access Request
  107731. + * 2'b00 - Read/Write Valid (updated by the core)
  107732. + * 2'b01 - Read
  107733. + * 2'b00 - Write
  107734. + * 2'b00 - Reserved
  107735. + */
  107736. + unsigned ar:2;
  107737. + /** Reserved */
  107738. + unsigned reserved29_31:3;
  107739. + } b;
  107740. +} adpctl_data_t;
  107741. +
  107742. +////////////////////////////////////////////
  107743. +// Device Registers
  107744. +/**
  107745. + * Device Global Registers. <i>Offsets 800h-BFFh</i>
  107746. + *
  107747. + * The following structures define the size and relative field offsets
  107748. + * for the Device Mode Registers.
  107749. + *
  107750. + * <i>These registers are visible only in Device mode and must not be
  107751. + * accessed in Host mode, as the results are unknown.</i>
  107752. + */
  107753. +typedef struct dwc_otg_dev_global_regs {
  107754. + /** Device Configuration Register. <i>Offset 800h</i> */
  107755. + volatile uint32_t dcfg;
  107756. + /** Device Control Register. <i>Offset: 804h</i> */
  107757. + volatile uint32_t dctl;
  107758. + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
  107759. + volatile uint32_t dsts;
  107760. + /** Reserved. <i>Offset: 80Ch</i> */
  107761. + uint32_t unused;
  107762. + /** Device IN Endpoint Common Interrupt Mask
  107763. + * Register. <i>Offset: 810h</i> */
  107764. + volatile uint32_t diepmsk;
  107765. + /** Device OUT Endpoint Common Interrupt Mask
  107766. + * Register. <i>Offset: 814h</i> */
  107767. + volatile uint32_t doepmsk;
  107768. + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
  107769. + volatile uint32_t daint;
  107770. + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
  107771. + * 81Ch</i> */
  107772. + volatile uint32_t daintmsk;
  107773. + /** Device IN Token Queue Read Register-1 (Read Only).
  107774. + * <i>Offset: 820h</i> */
  107775. + volatile uint32_t dtknqr1;
  107776. + /** Device IN Token Queue Read Register-2 (Read Only).
  107777. + * <i>Offset: 824h</i> */
  107778. + volatile uint32_t dtknqr2;
  107779. + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
  107780. + volatile uint32_t dvbusdis;
  107781. + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
  107782. + volatile uint32_t dvbuspulse;
  107783. + /** Device IN Token Queue Read Register-3 (Read Only). /
  107784. + * Device Thresholding control register (Read/Write)
  107785. + * <i>Offset: 830h</i> */
  107786. + volatile uint32_t dtknqr3_dthrctl;
  107787. + /** Device IN Token Queue Read Register-4 (Read Only). /
  107788. + * Device IN EPs empty Inr. Mask Register (Read/Write)
  107789. + * <i>Offset: 834h</i> */
  107790. + volatile uint32_t dtknqr4_fifoemptymsk;
  107791. + /** Device Each Endpoint Interrupt Register (Read Only). /
  107792. + * <i>Offset: 838h</i> */
  107793. + volatile uint32_t deachint;
  107794. + /** Device Each Endpoint Interrupt mask Register (Read/Write). /
  107795. + * <i>Offset: 83Ch</i> */
  107796. + volatile uint32_t deachintmsk;
  107797. + /** Device Each In Endpoint Interrupt mask Register (Read/Write). /
  107798. + * <i>Offset: 840h</i> */
  107799. + volatile uint32_t diepeachintmsk[MAX_EPS_CHANNELS];
  107800. + /** Device Each Out Endpoint Interrupt mask Register (Read/Write). /
  107801. + * <i>Offset: 880h</i> */
  107802. + volatile uint32_t doepeachintmsk[MAX_EPS_CHANNELS];
  107803. +} dwc_otg_device_global_regs_t;
  107804. +
  107805. +/**
  107806. + * This union represents the bit fields in the Device Configuration
  107807. + * Register. Read the register into the <i>d32</i> member then
  107808. + * set/clear the bits using the <i>b</i>it elements. Write the
  107809. + * <i>d32</i> member to the dcfg register.
  107810. + */
  107811. +typedef union dcfg_data {
  107812. + /** raw register data */
  107813. + uint32_t d32;
  107814. + /** register bits */
  107815. + struct {
  107816. + /** Device Speed */
  107817. + unsigned devspd:2;
  107818. + /** Non Zero Length Status OUT Handshake */
  107819. + unsigned nzstsouthshk:1;
  107820. +#define DWC_DCFG_SEND_STALL 1
  107821. +
  107822. + unsigned ena32khzs:1;
  107823. + /** Device Addresses */
  107824. + unsigned devaddr:7;
  107825. + /** Periodic Frame Interval */
  107826. + unsigned perfrint:2;
  107827. +#define DWC_DCFG_FRAME_INTERVAL_80 0
  107828. +#define DWC_DCFG_FRAME_INTERVAL_85 1
  107829. +#define DWC_DCFG_FRAME_INTERVAL_90 2
  107830. +#define DWC_DCFG_FRAME_INTERVAL_95 3
  107831. +
  107832. + /** Enable Device OUT NAK for bulk in DDMA mode */
  107833. + unsigned endevoutnak:1;
  107834. +
  107835. + unsigned reserved14_17:4;
  107836. + /** In Endpoint Mis-match count */
  107837. + unsigned epmscnt:5;
  107838. + /** Enable Descriptor DMA in Device mode */
  107839. + unsigned descdma:1;
  107840. + unsigned perschintvl:2;
  107841. + unsigned resvalid:6;
  107842. + } b;
  107843. +} dcfg_data_t;
  107844. +
  107845. +/**
  107846. + * This union represents the bit fields in the Device Control
  107847. + * Register. Read the register into the <i>d32</i> member then
  107848. + * set/clear the bits using the <i>b</i>it elements.
  107849. + */
  107850. +typedef union dctl_data {
  107851. + /** raw register data */
  107852. + uint32_t d32;
  107853. + /** register bits */
  107854. + struct {
  107855. + /** Remote Wakeup */
  107856. + unsigned rmtwkupsig:1;
  107857. + /** Soft Disconnect */
  107858. + unsigned sftdiscon:1;
  107859. + /** Global Non-Periodic IN NAK Status */
  107860. + unsigned gnpinnaksts:1;
  107861. + /** Global OUT NAK Status */
  107862. + unsigned goutnaksts:1;
  107863. + /** Test Control */
  107864. + unsigned tstctl:3;
  107865. + /** Set Global Non-Periodic IN NAK */
  107866. + unsigned sgnpinnak:1;
  107867. + /** Clear Global Non-Periodic IN NAK */
  107868. + unsigned cgnpinnak:1;
  107869. + /** Set Global OUT NAK */
  107870. + unsigned sgoutnak:1;
  107871. + /** Clear Global OUT NAK */
  107872. + unsigned cgoutnak:1;
  107873. + /** Power-On Programming Done */
  107874. + unsigned pwronprgdone:1;
  107875. + /** Reserved */
  107876. + unsigned reserved:1;
  107877. + /** Global Multi Count */
  107878. + unsigned gmc:2;
  107879. + /** Ignore Frame Number for ISOC EPs */
  107880. + unsigned ifrmnum:1;
  107881. + /** NAK on Babble */
  107882. + unsigned nakonbble:1;
  107883. + /** Enable Continue on BNA */
  107884. + unsigned encontonbna:1;
  107885. +
  107886. + unsigned reserved18_31:14;
  107887. + } b;
  107888. +} dctl_data_t;
  107889. +
  107890. +/**
  107891. + * This union represents the bit fields in the Device Status
  107892. + * Register. Read the register into the <i>d32</i> member then
  107893. + * set/clear the bits using the <i>b</i>it elements.
  107894. + */
  107895. +typedef union dsts_data {
  107896. + /** raw register data */
  107897. + uint32_t d32;
  107898. + /** register bits */
  107899. + struct {
  107900. + /** Suspend Status */
  107901. + unsigned suspsts:1;
  107902. + /** Enumerated Speed */
  107903. + unsigned enumspd:2;
  107904. +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
  107905. +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
  107906. +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
  107907. +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
  107908. + /** Erratic Error */
  107909. + unsigned errticerr:1;
  107910. + unsigned reserved4_7:4;
  107911. + /** Frame or Microframe Number of the received SOF */
  107912. + unsigned soffn:14;
  107913. + unsigned reserved22_31:10;
  107914. + } b;
  107915. +} dsts_data_t;
  107916. +
  107917. +/**
  107918. + * This union represents the bit fields in the Device IN EP Interrupt
  107919. + * Register and the Device IN EP Common Mask Register.
  107920. + *
  107921. + * - Read the register into the <i>d32</i> member then set/clear the
  107922. + * bits using the <i>b</i>it elements.
  107923. + */
  107924. +typedef union diepint_data {
  107925. + /** raw register data */
  107926. + uint32_t d32;
  107927. + /** register bits */
  107928. + struct {
  107929. + /** Transfer complete mask */
  107930. + unsigned xfercompl:1;
  107931. + /** Endpoint disable mask */
  107932. + unsigned epdisabled:1;
  107933. + /** AHB Error mask */
  107934. + unsigned ahberr:1;
  107935. + /** TimeOUT Handshake mask (non-ISOC EPs) */
  107936. + unsigned timeout:1;
  107937. + /** IN Token received with TxF Empty mask */
  107938. + unsigned intktxfemp:1;
  107939. + /** IN Token Received with EP mismatch mask */
  107940. + unsigned intknepmis:1;
  107941. + /** IN Endpoint NAK Effective mask */
  107942. + unsigned inepnakeff:1;
  107943. + /** Reserved */
  107944. + unsigned emptyintr:1;
  107945. +
  107946. + unsigned txfifoundrn:1;
  107947. +
  107948. + /** BNA Interrupt mask */
  107949. + unsigned bna:1;
  107950. +
  107951. + unsigned reserved10_12:3;
  107952. + /** BNA Interrupt mask */
  107953. + unsigned nak:1;
  107954. +
  107955. + unsigned reserved14_31:18;
  107956. + } b;
  107957. +} diepint_data_t;
  107958. +
  107959. +/**
  107960. + * This union represents the bit fields in the Device IN EP
  107961. + * Common/Dedicated Interrupt Mask Register.
  107962. + */
  107963. +typedef union diepint_data diepmsk_data_t;
  107964. +
  107965. +/**
  107966. + * This union represents the bit fields in the Device OUT EP Interrupt
  107967. + * Registerand Device OUT EP Common Interrupt Mask Register.
  107968. + *
  107969. + * - Read the register into the <i>d32</i> member then set/clear the
  107970. + * bits using the <i>b</i>it elements.
  107971. + */
  107972. +typedef union doepint_data {
  107973. + /** raw register data */
  107974. + uint32_t d32;
  107975. + /** register bits */
  107976. + struct {
  107977. + /** Transfer complete */
  107978. + unsigned xfercompl:1;
  107979. + /** Endpoint disable */
  107980. + unsigned epdisabled:1;
  107981. + /** AHB Error */
  107982. + unsigned ahberr:1;
  107983. + /** Setup Phase Done (contorl EPs) */
  107984. + unsigned setup:1;
  107985. + /** OUT Token Received when Endpoint Disabled */
  107986. + unsigned outtknepdis:1;
  107987. +
  107988. + unsigned stsphsercvd:1;
  107989. + /** Back-to-Back SETUP Packets Received */
  107990. + unsigned back2backsetup:1;
  107991. +
  107992. + unsigned reserved7:1;
  107993. + /** OUT packet Error */
  107994. + unsigned outpkterr:1;
  107995. + /** BNA Interrupt */
  107996. + unsigned bna:1;
  107997. +
  107998. + unsigned reserved10:1;
  107999. + /** Packet Drop Status */
  108000. + unsigned pktdrpsts:1;
  108001. + /** Babble Interrupt */
  108002. + unsigned babble:1;
  108003. + /** NAK Interrupt */
  108004. + unsigned nak:1;
  108005. + /** NYET Interrupt */
  108006. + unsigned nyet:1;
  108007. + /** Bit indicating setup packet received */
  108008. + unsigned sr:1;
  108009. +
  108010. + unsigned reserved16_31:16;
  108011. + } b;
  108012. +} doepint_data_t;
  108013. +
  108014. +/**
  108015. + * This union represents the bit fields in the Device OUT EP
  108016. + * Common/Dedicated Interrupt Mask Register.
  108017. + */
  108018. +typedef union doepint_data doepmsk_data_t;
  108019. +
  108020. +/**
  108021. + * This union represents the bit fields in the Device All EP Interrupt
  108022. + * and Mask Registers.
  108023. + * - Read the register into the <i>d32</i> member then set/clear the
  108024. + * bits using the <i>b</i>it elements.
  108025. + */
  108026. +typedef union daint_data {
  108027. + /** raw register data */
  108028. + uint32_t d32;
  108029. + /** register bits */
  108030. + struct {
  108031. + /** IN Endpoint bits */
  108032. + unsigned in:16;
  108033. + /** OUT Endpoint bits */
  108034. + unsigned out:16;
  108035. + } ep;
  108036. + struct {
  108037. + /** IN Endpoint bits */
  108038. + unsigned inep0:1;
  108039. + unsigned inep1:1;
  108040. + unsigned inep2:1;
  108041. + unsigned inep3:1;
  108042. + unsigned inep4:1;
  108043. + unsigned inep5:1;
  108044. + unsigned inep6:1;
  108045. + unsigned inep7:1;
  108046. + unsigned inep8:1;
  108047. + unsigned inep9:1;
  108048. + unsigned inep10:1;
  108049. + unsigned inep11:1;
  108050. + unsigned inep12:1;
  108051. + unsigned inep13:1;
  108052. + unsigned inep14:1;
  108053. + unsigned inep15:1;
  108054. + /** OUT Endpoint bits */
  108055. + unsigned outep0:1;
  108056. + unsigned outep1:1;
  108057. + unsigned outep2:1;
  108058. + unsigned outep3:1;
  108059. + unsigned outep4:1;
  108060. + unsigned outep5:1;
  108061. + unsigned outep6:1;
  108062. + unsigned outep7:1;
  108063. + unsigned outep8:1;
  108064. + unsigned outep9:1;
  108065. + unsigned outep10:1;
  108066. + unsigned outep11:1;
  108067. + unsigned outep12:1;
  108068. + unsigned outep13:1;
  108069. + unsigned outep14:1;
  108070. + unsigned outep15:1;
  108071. + } b;
  108072. +} daint_data_t;
  108073. +
  108074. +/**
  108075. + * This union represents the bit fields in the Device IN Token Queue
  108076. + * Read Registers.
  108077. + * - Read the register into the <i>d32</i> member.
  108078. + * - READ-ONLY Register
  108079. + */
  108080. +typedef union dtknq1_data {
  108081. + /** raw register data */
  108082. + uint32_t d32;
  108083. + /** register bits */
  108084. + struct {
  108085. + /** In Token Queue Write Pointer */
  108086. + unsigned intknwptr:5;
  108087. + /** Reserved */
  108088. + unsigned reserved05_06:2;
  108089. + /** write pointer has wrapped. */
  108090. + unsigned wrap_bit:1;
  108091. + /** EP Numbers of IN Tokens 0 ... 4 */
  108092. + unsigned epnums0_5:24;
  108093. + } b;
  108094. +} dtknq1_data_t;
  108095. +
  108096. +/**
  108097. + * This union represents Threshold control Register
  108098. + * - Read and write the register into the <i>d32</i> member.
  108099. + * - READ-WRITABLE Register
  108100. + */
  108101. +typedef union dthrctl_data {
  108102. + /** raw register data */
  108103. + uint32_t d32;
  108104. + /** register bits */
  108105. + struct {
  108106. + /** non ISO Tx Thr. Enable */
  108107. + unsigned non_iso_thr_en:1;
  108108. + /** ISO Tx Thr. Enable */
  108109. + unsigned iso_thr_en:1;
  108110. + /** Tx Thr. Length */
  108111. + unsigned tx_thr_len:9;
  108112. + /** AHB Threshold ratio */
  108113. + unsigned ahb_thr_ratio:2;
  108114. + /** Reserved */
  108115. + unsigned reserved13_15:3;
  108116. + /** Rx Thr. Enable */
  108117. + unsigned rx_thr_en:1;
  108118. + /** Rx Thr. Length */
  108119. + unsigned rx_thr_len:9;
  108120. + unsigned reserved26:1;
  108121. + /** Arbiter Parking Enable*/
  108122. + unsigned arbprken:1;
  108123. + /** Reserved */
  108124. + unsigned reserved28_31:4;
  108125. + } b;
  108126. +} dthrctl_data_t;
  108127. +
  108128. +/**
  108129. + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
  108130. + * 900h-AFCh</i>
  108131. + *
  108132. + * There will be one set of endpoint registers per logical endpoint
  108133. + * implemented.
  108134. + *
  108135. + * <i>These registers are visible only in Device mode and must not be
  108136. + * accessed in Host mode, as the results are unknown.</i>
  108137. + */
  108138. +typedef struct dwc_otg_dev_in_ep_regs {
  108139. + /** Device IN Endpoint Control Register. <i>Offset:900h +
  108140. + * (ep_num * 20h) + 00h</i> */
  108141. + volatile uint32_t diepctl;
  108142. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
  108143. + uint32_t reserved04;
  108144. + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
  108145. + * (ep_num * 20h) + 08h</i> */
  108146. + volatile uint32_t diepint;
  108147. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
  108148. + uint32_t reserved0C;
  108149. + /** Device IN Endpoint Transfer Size
  108150. + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
  108151. + volatile uint32_t dieptsiz;
  108152. + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
  108153. + * (ep_num * 20h) + 14h</i> */
  108154. + volatile uint32_t diepdma;
  108155. + /** Device IN Endpoint Transmit FIFO Status Register. <i>Offset:900h +
  108156. + * (ep_num * 20h) + 18h</i> */
  108157. + volatile uint32_t dtxfsts;
  108158. + /** Device IN Endpoint DMA Buffer Register. <i>Offset:900h +
  108159. + * (ep_num * 20h) + 1Ch</i> */
  108160. + volatile uint32_t diepdmab;
  108161. +} dwc_otg_dev_in_ep_regs_t;
  108162. +
  108163. +/**
  108164. + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
  108165. + * B00h-CFCh</i>
  108166. + *
  108167. + * There will be one set of endpoint registers per logical endpoint
  108168. + * implemented.
  108169. + *
  108170. + * <i>These registers are visible only in Device mode and must not be
  108171. + * accessed in Host mode, as the results are unknown.</i>
  108172. + */
  108173. +typedef struct dwc_otg_dev_out_ep_regs {
  108174. + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
  108175. + * (ep_num * 20h) + 00h</i> */
  108176. + volatile uint32_t doepctl;
  108177. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 04h</i> */
  108178. + uint32_t reserved04;
  108179. + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
  108180. + * (ep_num * 20h) + 08h</i> */
  108181. + volatile uint32_t doepint;
  108182. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
  108183. + uint32_t reserved0C;
  108184. + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
  108185. + * B00h + (ep_num * 20h) + 10h</i> */
  108186. + volatile uint32_t doeptsiz;
  108187. + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
  108188. + * + (ep_num * 20h) + 14h</i> */
  108189. + volatile uint32_t doepdma;
  108190. + /** Reserved. <i>Offset:B00h + * (ep_num * 20h) + 18h</i> */
  108191. + uint32_t unused;
  108192. + /** Device OUT Endpoint DMA Buffer Register. <i>Offset:B00h
  108193. + * + (ep_num * 20h) + 1Ch</i> */
  108194. + uint32_t doepdmab;
  108195. +} dwc_otg_dev_out_ep_regs_t;
  108196. +
  108197. +/**
  108198. + * This union represents the bit fields in the Device EP Control
  108199. + * Register. Read the register into the <i>d32</i> member then
  108200. + * set/clear the bits using the <i>b</i>it elements.
  108201. + */
  108202. +typedef union depctl_data {
  108203. + /** raw register data */
  108204. + uint32_t d32;
  108205. + /** register bits */
  108206. + struct {
  108207. + /** Maximum Packet Size
  108208. + * IN/OUT EPn
  108209. + * IN/OUT EP0 - 2 bits
  108210. + * 2'b00: 64 Bytes
  108211. + * 2'b01: 32
  108212. + * 2'b10: 16
  108213. + * 2'b11: 8 */
  108214. + unsigned mps:11;
  108215. +#define DWC_DEP0CTL_MPS_64 0
  108216. +#define DWC_DEP0CTL_MPS_32 1
  108217. +#define DWC_DEP0CTL_MPS_16 2
  108218. +#define DWC_DEP0CTL_MPS_8 3
  108219. +
  108220. + /** Next Endpoint
  108221. + * IN EPn/IN EP0
  108222. + * OUT EPn/OUT EP0 - reserved */
  108223. + unsigned nextep:4;
  108224. +
  108225. + /** USB Active Endpoint */
  108226. + unsigned usbactep:1;
  108227. +
  108228. + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
  108229. + * This field contains the PID of the packet going to
  108230. + * be received or transmitted on this endpoint. The
  108231. + * application should program the PID of the first
  108232. + * packet going to be received or transmitted on this
  108233. + * endpoint , after the endpoint is
  108234. + * activated. Application use the SetD1PID and
  108235. + * SetD0PID fields of this register to program either
  108236. + * D0 or D1 PID.
  108237. + *
  108238. + * The encoding for this field is
  108239. + * - 0: D0
  108240. + * - 1: D1
  108241. + */
  108242. + unsigned dpid:1;
  108243. +
  108244. + /** NAK Status */
  108245. + unsigned naksts:1;
  108246. +
  108247. + /** Endpoint Type
  108248. + * 2'b00: Control
  108249. + * 2'b01: Isochronous
  108250. + * 2'b10: Bulk
  108251. + * 2'b11: Interrupt */
  108252. + unsigned eptype:2;
  108253. +
  108254. + /** Snoop Mode
  108255. + * OUT EPn/OUT EP0
  108256. + * IN EPn/IN EP0 - reserved */
  108257. + unsigned snp:1;
  108258. +
  108259. + /** Stall Handshake */
  108260. + unsigned stall:1;
  108261. +
  108262. + /** Tx Fifo Number
  108263. + * IN EPn/IN EP0
  108264. + * OUT EPn/OUT EP0 - reserved */
  108265. + unsigned txfnum:4;
  108266. +
  108267. + /** Clear NAK */
  108268. + unsigned cnak:1;
  108269. + /** Set NAK */
  108270. + unsigned snak:1;
  108271. + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
  108272. + * Writing to this field sets the Endpoint DPID (DPID)
  108273. + * field in this register to DATA0. Set Even
  108274. + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
  108275. + * Writing to this field sets the Even/Odd
  108276. + * (micro)frame (EO_FrNum) field to even (micro)
  108277. + * frame.
  108278. + */
  108279. + unsigned setd0pid:1;
  108280. + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
  108281. + * Writing to this field sets the Endpoint DPID (DPID)
  108282. + * field in this register to DATA1 Set Odd
  108283. + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
  108284. + * Writing to this field sets the Even/Odd
  108285. + * (micro)frame (EO_FrNum) field to odd (micro) frame.
  108286. + */
  108287. + unsigned setd1pid:1;
  108288. +
  108289. + /** Endpoint Disable */
  108290. + unsigned epdis:1;
  108291. + /** Endpoint Enable */
  108292. + unsigned epena:1;
  108293. + } b;
  108294. +} depctl_data_t;
  108295. +
  108296. +/**
  108297. + * This union represents the bit fields in the Device EP Transfer
  108298. + * Size Register. Read the register into the <i>d32</i> member then
  108299. + * set/clear the bits using the <i>b</i>it elements.
  108300. + */
  108301. +typedef union deptsiz_data {
  108302. + /** raw register data */
  108303. + uint32_t d32;
  108304. + /** register bits */
  108305. + struct {
  108306. + /** Transfer size */
  108307. + unsigned xfersize:19;
  108308. +/** Max packet count for EP (pow(2,10)-1) */
  108309. +#define MAX_PKT_CNT 1023
  108310. + /** Packet Count */
  108311. + unsigned pktcnt:10;
  108312. + /** Multi Count - Periodic IN endpoints */
  108313. + unsigned mc:2;
  108314. + unsigned reserved:1;
  108315. + } b;
  108316. +} deptsiz_data_t;
  108317. +
  108318. +/**
  108319. + * This union represents the bit fields in the Device EP 0 Transfer
  108320. + * Size Register. Read the register into the <i>d32</i> member then
  108321. + * set/clear the bits using the <i>b</i>it elements.
  108322. + */
  108323. +typedef union deptsiz0_data {
  108324. + /** raw register data */
  108325. + uint32_t d32;
  108326. + /** register bits */
  108327. + struct {
  108328. + /** Transfer size */
  108329. + unsigned xfersize:7;
  108330. + /** Reserved */
  108331. + unsigned reserved7_18:12;
  108332. + /** Packet Count */
  108333. + unsigned pktcnt:2;
  108334. + /** Reserved */
  108335. + unsigned reserved21_28:8;
  108336. + /**Setup Packet Count (DOEPTSIZ0 Only) */
  108337. + unsigned supcnt:2;
  108338. + unsigned reserved31;
  108339. + } b;
  108340. +} deptsiz0_data_t;
  108341. +
  108342. +/////////////////////////////////////////////////
  108343. +// DMA Descriptor Specific Structures
  108344. +//
  108345. +
  108346. +/** Buffer status definitions */
  108347. +
  108348. +#define BS_HOST_READY 0x0
  108349. +#define BS_DMA_BUSY 0x1
  108350. +#define BS_DMA_DONE 0x2
  108351. +#define BS_HOST_BUSY 0x3
  108352. +
  108353. +/** Receive/Transmit status definitions */
  108354. +
  108355. +#define RTS_SUCCESS 0x0
  108356. +#define RTS_BUFFLUSH 0x1
  108357. +#define RTS_RESERVED 0x2
  108358. +#define RTS_BUFERR 0x3
  108359. +
  108360. +/**
  108361. + * This union represents the bit fields in the DMA Descriptor
  108362. + * status quadlet. Read the quadlet into the <i>d32</i> member then
  108363. + * set/clear the bits using the <i>b</i>it, <i>b_iso_out</i> and
  108364. + * <i>b_iso_in</i> elements.
  108365. + */
  108366. +typedef union dev_dma_desc_sts {
  108367. + /** raw register data */
  108368. + uint32_t d32;
  108369. + /** quadlet bits */
  108370. + struct {
  108371. + /** Received number of bytes */
  108372. + unsigned bytes:16;
  108373. + /** NAK bit - only for OUT EPs */
  108374. + unsigned nak:1;
  108375. + unsigned reserved17_22:6;
  108376. + /** Multiple Transfer - only for OUT EPs */
  108377. + unsigned mtrf:1;
  108378. + /** Setup Packet received - only for OUT EPs */
  108379. + unsigned sr:1;
  108380. + /** Interrupt On Complete */
  108381. + unsigned ioc:1;
  108382. + /** Short Packet */
  108383. + unsigned sp:1;
  108384. + /** Last */
  108385. + unsigned l:1;
  108386. + /** Receive Status */
  108387. + unsigned sts:2;
  108388. + /** Buffer Status */
  108389. + unsigned bs:2;
  108390. + } b;
  108391. +
  108392. +//#ifdef DWC_EN_ISOC
  108393. + /** iso out quadlet bits */
  108394. + struct {
  108395. + /** Received number of bytes */
  108396. + unsigned rxbytes:11;
  108397. +
  108398. + unsigned reserved11:1;
  108399. + /** Frame Number */
  108400. + unsigned framenum:11;
  108401. + /** Received ISO Data PID */
  108402. + unsigned pid:2;
  108403. + /** Interrupt On Complete */
  108404. + unsigned ioc:1;
  108405. + /** Short Packet */
  108406. + unsigned sp:1;
  108407. + /** Last */
  108408. + unsigned l:1;
  108409. + /** Receive Status */
  108410. + unsigned rxsts:2;
  108411. + /** Buffer Status */
  108412. + unsigned bs:2;
  108413. + } b_iso_out;
  108414. +
  108415. + /** iso in quadlet bits */
  108416. + struct {
  108417. + /** Transmited number of bytes */
  108418. + unsigned txbytes:12;
  108419. + /** Frame Number */
  108420. + unsigned framenum:11;
  108421. + /** Transmited ISO Data PID */
  108422. + unsigned pid:2;
  108423. + /** Interrupt On Complete */
  108424. + unsigned ioc:1;
  108425. + /** Short Packet */
  108426. + unsigned sp:1;
  108427. + /** Last */
  108428. + unsigned l:1;
  108429. + /** Transmit Status */
  108430. + unsigned txsts:2;
  108431. + /** Buffer Status */
  108432. + unsigned bs:2;
  108433. + } b_iso_in;
  108434. +//#endif /* DWC_EN_ISOC */
  108435. +} dev_dma_desc_sts_t;
  108436. +
  108437. +/**
  108438. + * DMA Descriptor structure
  108439. + *
  108440. + * DMA Descriptor structure contains two quadlets:
  108441. + * Status quadlet and Data buffer pointer.
  108442. + */
  108443. +typedef struct dwc_otg_dev_dma_desc {
  108444. + /** DMA Descriptor status quadlet */
  108445. + dev_dma_desc_sts_t status;
  108446. + /** DMA Descriptor data buffer pointer */
  108447. + uint32_t buf;
  108448. +} dwc_otg_dev_dma_desc_t;
  108449. +
  108450. +/**
  108451. + * The dwc_otg_dev_if structure contains information needed to manage
  108452. + * the DWC_otg controller acting in device mode. It represents the
  108453. + * programming view of the device-specific aspects of the controller.
  108454. + */
  108455. +typedef struct dwc_otg_dev_if {
  108456. + /** Pointer to device Global registers.
  108457. + * Device Global Registers starting at offset 800h
  108458. + */
  108459. + dwc_otg_device_global_regs_t *dev_global_regs;
  108460. +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
  108461. +
  108462. + /**
  108463. + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
  108464. + */
  108465. + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
  108466. +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
  108467. +#define DWC_EP_REG_OFFSET 0x20
  108468. +
  108469. + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
  108470. + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
  108471. +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
  108472. +
  108473. + /* Device configuration information */
  108474. + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
  108475. + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
  108476. + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
  108477. +
  108478. + /** Size of periodic FIFOs (Bytes) */
  108479. + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
  108480. +
  108481. + /** Size of Tx FIFOs (Bytes) */
  108482. + uint16_t tx_fifo_size[MAX_TX_FIFOS];
  108483. +
  108484. + /** Thresholding enable flags and length varaiables **/
  108485. + uint16_t rx_thr_en;
  108486. + uint16_t iso_tx_thr_en;
  108487. + uint16_t non_iso_tx_thr_en;
  108488. +
  108489. + uint16_t rx_thr_length;
  108490. + uint16_t tx_thr_length;
  108491. +
  108492. + /**
  108493. + * Pointers to the DMA Descriptors for EP0 Control
  108494. + * transfers (virtual and physical)
  108495. + */
  108496. +
  108497. + /** 2 descriptors for SETUP packets */
  108498. + dwc_dma_t dma_setup_desc_addr[2];
  108499. + dwc_otg_dev_dma_desc_t *setup_desc_addr[2];
  108500. +
  108501. + /** Pointer to Descriptor with latest SETUP packet */
  108502. + dwc_otg_dev_dma_desc_t *psetup;
  108503. +
  108504. + /** Index of current SETUP handler descriptor */
  108505. + uint32_t setup_desc_index;
  108506. +
  108507. + /** Descriptor for Data In or Status In phases */
  108508. + dwc_dma_t dma_in_desc_addr;
  108509. + dwc_otg_dev_dma_desc_t *in_desc_addr;
  108510. +
  108511. + /** Descriptor for Data Out or Status Out phases */
  108512. + dwc_dma_t dma_out_desc_addr;
  108513. + dwc_otg_dev_dma_desc_t *out_desc_addr;
  108514. +
  108515. + /** Setup Packet Detected - if set clear NAK when queueing */
  108516. + uint32_t spd;
  108517. + /** Isoc ep pointer on which incomplete happens */
  108518. + void *isoc_ep;
  108519. +
  108520. +} dwc_otg_dev_if_t;
  108521. +
  108522. +/////////////////////////////////////////////////
  108523. +// Host Mode Register Structures
  108524. +//
  108525. +/**
  108526. + * The Host Global Registers structure defines the size and relative
  108527. + * field offsets for the Host Mode Global Registers. Host Global
  108528. + * Registers offsets 400h-7FFh.
  108529. +*/
  108530. +typedef struct dwc_otg_host_global_regs {
  108531. + /** Host Configuration Register. <i>Offset: 400h</i> */
  108532. + volatile uint32_t hcfg;
  108533. + /** Host Frame Interval Register. <i>Offset: 404h</i> */
  108534. + volatile uint32_t hfir;
  108535. + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
  108536. + volatile uint32_t hfnum;
  108537. + /** Reserved. <i>Offset: 40Ch</i> */
  108538. + uint32_t reserved40C;
  108539. + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
  108540. + volatile uint32_t hptxsts;
  108541. + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
  108542. + volatile uint32_t haint;
  108543. + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
  108544. + volatile uint32_t haintmsk;
  108545. + /** Host Frame List Base Address Register . <i>Offset: 41Ch</i> */
  108546. + volatile uint32_t hflbaddr;
  108547. +} dwc_otg_host_global_regs_t;
  108548. +
  108549. +/**
  108550. + * This union represents the bit fields in the Host Configuration Register.
  108551. + * Read the register into the <i>d32</i> member then set/clear the bits using
  108552. + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
  108553. + */
  108554. +typedef union hcfg_data {
  108555. + /** raw register data */
  108556. + uint32_t d32;
  108557. +
  108558. + /** register bits */
  108559. + struct {
  108560. + /** FS/LS Phy Clock Select */
  108561. + unsigned fslspclksel:2;
  108562. +#define DWC_HCFG_30_60_MHZ 0
  108563. +#define DWC_HCFG_48_MHZ 1
  108564. +#define DWC_HCFG_6_MHZ 2
  108565. +
  108566. + /** FS/LS Only Support */
  108567. + unsigned fslssupp:1;
  108568. + unsigned reserved3_6:4;
  108569. + /** Enable 32-KHz Suspend Mode */
  108570. + unsigned ena32khzs:1;
  108571. + /** Resume Validation Periiod */
  108572. + unsigned resvalid:8;
  108573. + unsigned reserved16_22:7;
  108574. + /** Enable Scatter/gather DMA in Host mode */
  108575. + unsigned descdma:1;
  108576. + /** Frame List Entries */
  108577. + unsigned frlisten:2;
  108578. + /** Enable Periodic Scheduling */
  108579. + unsigned perschedena:1;
  108580. + unsigned reserved27_30:4;
  108581. + unsigned modechtimen:1;
  108582. + } b;
  108583. +} hcfg_data_t;
  108584. +
  108585. +/**
  108586. + * This union represents the bit fields in the Host Frame Remaing/Number
  108587. + * Register.
  108588. + */
  108589. +typedef union hfir_data {
  108590. + /** raw register data */
  108591. + uint32_t d32;
  108592. +
  108593. + /** register bits */
  108594. + struct {
  108595. + unsigned frint:16;
  108596. + unsigned hfirrldctrl:1;
  108597. + unsigned reserved:15;
  108598. + } b;
  108599. +} hfir_data_t;
  108600. +
  108601. +/**
  108602. + * This union represents the bit fields in the Host Frame Remaing/Number
  108603. + * Register.
  108604. + */
  108605. +typedef union hfnum_data {
  108606. + /** raw register data */
  108607. + uint32_t d32;
  108608. +
  108609. + /** register bits */
  108610. + struct {
  108611. + unsigned frnum:16;
  108612. +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
  108613. + unsigned frrem:16;
  108614. + } b;
  108615. +} hfnum_data_t;
  108616. +
  108617. +typedef union hptxsts_data {
  108618. + /** raw register data */
  108619. + uint32_t d32;
  108620. +
  108621. + /** register bits */
  108622. + struct {
  108623. + unsigned ptxfspcavail:16;
  108624. + unsigned ptxqspcavail:8;
  108625. + /** Top of the Periodic Transmit Request Queue
  108626. + * - bit 24 - Terminate (last entry for the selected channel)
  108627. + * - bits 26:25 - Token Type
  108628. + * - 2'b00 - Zero length
  108629. + * - 2'b01 - Ping
  108630. + * - 2'b10 - Disable
  108631. + * - bits 30:27 - Channel Number
  108632. + * - bit 31 - Odd/even microframe
  108633. + */
  108634. + unsigned ptxqtop_terminate:1;
  108635. + unsigned ptxqtop_token:2;
  108636. + unsigned ptxqtop_chnum:4;
  108637. + unsigned ptxqtop_odd:1;
  108638. + } b;
  108639. +} hptxsts_data_t;
  108640. +
  108641. +/**
  108642. + * This union represents the bit fields in the Host Port Control and Status
  108643. + * Register. Read the register into the <i>d32</i> member then set/clear the
  108644. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  108645. + * hprt0 register.
  108646. + */
  108647. +typedef union hprt0_data {
  108648. + /** raw register data */
  108649. + uint32_t d32;
  108650. + /** register bits */
  108651. + struct {
  108652. + unsigned prtconnsts:1;
  108653. + unsigned prtconndet:1;
  108654. + unsigned prtena:1;
  108655. + unsigned prtenchng:1;
  108656. + unsigned prtovrcurract:1;
  108657. + unsigned prtovrcurrchng:1;
  108658. + unsigned prtres:1;
  108659. + unsigned prtsusp:1;
  108660. + unsigned prtrst:1;
  108661. + unsigned reserved9:1;
  108662. + unsigned prtlnsts:2;
  108663. + unsigned prtpwr:1;
  108664. + unsigned prttstctl:4;
  108665. + unsigned prtspd:2;
  108666. +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
  108667. +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
  108668. +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
  108669. + unsigned reserved19_31:13;
  108670. + } b;
  108671. +} hprt0_data_t;
  108672. +
  108673. +/**
  108674. + * This union represents the bit fields in the Host All Interrupt
  108675. + * Register.
  108676. + */
  108677. +typedef union haint_data {
  108678. + /** raw register data */
  108679. + uint32_t d32;
  108680. + /** register bits */
  108681. + struct {
  108682. + unsigned ch0:1;
  108683. + unsigned ch1:1;
  108684. + unsigned ch2:1;
  108685. + unsigned ch3:1;
  108686. + unsigned ch4:1;
  108687. + unsigned ch5:1;
  108688. + unsigned ch6:1;
  108689. + unsigned ch7:1;
  108690. + unsigned ch8:1;
  108691. + unsigned ch9:1;
  108692. + unsigned ch10:1;
  108693. + unsigned ch11:1;
  108694. + unsigned ch12:1;
  108695. + unsigned ch13:1;
  108696. + unsigned ch14:1;
  108697. + unsigned ch15:1;
  108698. + unsigned reserved:16;
  108699. + } b;
  108700. +
  108701. + struct {
  108702. + unsigned chint:16;
  108703. + unsigned reserved:16;
  108704. + } b2;
  108705. +} haint_data_t;
  108706. +
  108707. +/**
  108708. + * This union represents the bit fields in the Host All Interrupt
  108709. + * Register.
  108710. + */
  108711. +typedef union haintmsk_data {
  108712. + /** raw register data */
  108713. + uint32_t d32;
  108714. + /** register bits */
  108715. + struct {
  108716. + unsigned ch0:1;
  108717. + unsigned ch1:1;
  108718. + unsigned ch2:1;
  108719. + unsigned ch3:1;
  108720. + unsigned ch4:1;
  108721. + unsigned ch5:1;
  108722. + unsigned ch6:1;
  108723. + unsigned ch7:1;
  108724. + unsigned ch8:1;
  108725. + unsigned ch9:1;
  108726. + unsigned ch10:1;
  108727. + unsigned ch11:1;
  108728. + unsigned ch12:1;
  108729. + unsigned ch13:1;
  108730. + unsigned ch14:1;
  108731. + unsigned ch15:1;
  108732. + unsigned reserved:16;
  108733. + } b;
  108734. +
  108735. + struct {
  108736. + unsigned chint:16;
  108737. + unsigned reserved:16;
  108738. + } b2;
  108739. +} haintmsk_data_t;
  108740. +
  108741. +/**
  108742. + * Host Channel Specific Registers. <i>500h-5FCh</i>
  108743. + */
  108744. +typedef struct dwc_otg_hc_regs {
  108745. + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
  108746. + volatile uint32_t hcchar;
  108747. + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
  108748. + volatile uint32_t hcsplt;
  108749. + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
  108750. + volatile uint32_t hcint;
  108751. + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
  108752. + volatile uint32_t hcintmsk;
  108753. + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
  108754. + volatile uint32_t hctsiz;
  108755. + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
  108756. + volatile uint32_t hcdma;
  108757. + volatile uint32_t reserved;
  108758. + /** Host Channel 0 DMA Buffer Address Register. <i>Offset: 500h + (chan_num * 20h) + 1Ch</i> */
  108759. + volatile uint32_t hcdmab;
  108760. +} dwc_otg_hc_regs_t;
  108761. +
  108762. +/**
  108763. + * This union represents the bit fields in the Host Channel Characteristics
  108764. + * Register. Read the register into the <i>d32</i> member then set/clear the
  108765. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  108766. + * hcchar register.
  108767. + */
  108768. +typedef union hcchar_data {
  108769. + /** raw register data */
  108770. + uint32_t d32;
  108771. +
  108772. + /** register bits */
  108773. + struct {
  108774. + /** Maximum packet size in bytes */
  108775. + unsigned mps:11;
  108776. +
  108777. + /** Endpoint number */
  108778. + unsigned epnum:4;
  108779. +
  108780. + /** 0: OUT, 1: IN */
  108781. + unsigned epdir:1;
  108782. +
  108783. + unsigned reserved:1;
  108784. +
  108785. + /** 0: Full/high speed device, 1: Low speed device */
  108786. + unsigned lspddev:1;
  108787. +
  108788. + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
  108789. + unsigned eptype:2;
  108790. +
  108791. + /** Packets per frame for periodic transfers. 0 is reserved. */
  108792. + unsigned multicnt:2;
  108793. +
  108794. + /** Device address */
  108795. + unsigned devaddr:7;
  108796. +
  108797. + /**
  108798. + * Frame to transmit periodic transaction.
  108799. + * 0: even, 1: odd
  108800. + */
  108801. + unsigned oddfrm:1;
  108802. +
  108803. + /** Channel disable */
  108804. + unsigned chdis:1;
  108805. +
  108806. + /** Channel enable */
  108807. + unsigned chen:1;
  108808. + } b;
  108809. +} hcchar_data_t;
  108810. +
  108811. +typedef union hcsplt_data {
  108812. + /** raw register data */
  108813. + uint32_t d32;
  108814. +
  108815. + /** register bits */
  108816. + struct {
  108817. + /** Port Address */
  108818. + unsigned prtaddr:7;
  108819. +
  108820. + /** Hub Address */
  108821. + unsigned hubaddr:7;
  108822. +
  108823. + /** Transaction Position */
  108824. + unsigned xactpos:2;
  108825. +#define DWC_HCSPLIT_XACTPOS_MID 0
  108826. +#define DWC_HCSPLIT_XACTPOS_END 1
  108827. +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
  108828. +#define DWC_HCSPLIT_XACTPOS_ALL 3
  108829. +
  108830. + /** Do Complete Split */
  108831. + unsigned compsplt:1;
  108832. +
  108833. + /** Reserved */
  108834. + unsigned reserved:14;
  108835. +
  108836. + /** Split Enble */
  108837. + unsigned spltena:1;
  108838. + } b;
  108839. +} hcsplt_data_t;
  108840. +
  108841. +/**
  108842. + * This union represents the bit fields in the Host All Interrupt
  108843. + * Register.
  108844. + */
  108845. +typedef union hcint_data {
  108846. + /** raw register data */
  108847. + uint32_t d32;
  108848. + /** register bits */
  108849. + struct {
  108850. + /** Transfer Complete */
  108851. + unsigned xfercomp:1;
  108852. + /** Channel Halted */
  108853. + unsigned chhltd:1;
  108854. + /** AHB Error */
  108855. + unsigned ahberr:1;
  108856. + /** STALL Response Received */
  108857. + unsigned stall:1;
  108858. + /** NAK Response Received */
  108859. + unsigned nak:1;
  108860. + /** ACK Response Received */
  108861. + unsigned ack:1;
  108862. + /** NYET Response Received */
  108863. + unsigned nyet:1;
  108864. + /** Transaction Err */
  108865. + unsigned xacterr:1;
  108866. + /** Babble Error */
  108867. + unsigned bblerr:1;
  108868. + /** Frame Overrun */
  108869. + unsigned frmovrun:1;
  108870. + /** Data Toggle Error */
  108871. + unsigned datatglerr:1;
  108872. + /** Buffer Not Available (only for DDMA mode) */
  108873. + unsigned bna:1;
  108874. + /** Exessive transaction error (only for DDMA mode) */
  108875. + unsigned xcs_xact:1;
  108876. + /** Frame List Rollover interrupt */
  108877. + unsigned frm_list_roll:1;
  108878. + /** Reserved */
  108879. + unsigned reserved14_31:18;
  108880. + } b;
  108881. +} hcint_data_t;
  108882. +
  108883. +/**
  108884. + * This union represents the bit fields in the Host Channel Interrupt Mask
  108885. + * Register. Read the register into the <i>d32</i> member then set/clear the
  108886. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  108887. + * hcintmsk register.
  108888. + */
  108889. +typedef union hcintmsk_data {
  108890. + /** raw register data */
  108891. + uint32_t d32;
  108892. +
  108893. + /** register bits */
  108894. + struct {
  108895. + unsigned xfercompl:1;
  108896. + unsigned chhltd:1;
  108897. + unsigned ahberr:1;
  108898. + unsigned stall:1;
  108899. + unsigned nak:1;
  108900. + unsigned ack:1;
  108901. + unsigned nyet:1;
  108902. + unsigned xacterr:1;
  108903. + unsigned bblerr:1;
  108904. + unsigned frmovrun:1;
  108905. + unsigned datatglerr:1;
  108906. + unsigned bna:1;
  108907. + unsigned xcs_xact:1;
  108908. + unsigned frm_list_roll:1;
  108909. + unsigned reserved14_31:18;
  108910. + } b;
  108911. +} hcintmsk_data_t;
  108912. +
  108913. +/**
  108914. + * This union represents the bit fields in the Host Channel Transfer Size
  108915. + * Register. Read the register into the <i>d32</i> member then set/clear the
  108916. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  108917. + * hcchar register.
  108918. + */
  108919. +
  108920. +typedef union hctsiz_data {
  108921. + /** raw register data */
  108922. + uint32_t d32;
  108923. +
  108924. + /** register bits */
  108925. + struct {
  108926. + /** Total transfer size in bytes */
  108927. + unsigned xfersize:19;
  108928. +
  108929. + /** Data packets to transfer */
  108930. + unsigned pktcnt:10;
  108931. +
  108932. + /**
  108933. + * Packet ID for next data packet
  108934. + * 0: DATA0
  108935. + * 1: DATA2
  108936. + * 2: DATA1
  108937. + * 3: MDATA (non-Control), SETUP (Control)
  108938. + */
  108939. + unsigned pid:2;
  108940. +#define DWC_HCTSIZ_DATA0 0
  108941. +#define DWC_HCTSIZ_DATA1 2
  108942. +#define DWC_HCTSIZ_DATA2 1
  108943. +#define DWC_HCTSIZ_MDATA 3
  108944. +#define DWC_HCTSIZ_SETUP 3
  108945. +
  108946. + /** Do PING protocol when 1 */
  108947. + unsigned dopng:1;
  108948. + } b;
  108949. +
  108950. + /** register bits */
  108951. + struct {
  108952. + /** Scheduling information */
  108953. + unsigned schinfo:8;
  108954. +
  108955. + /** Number of transfer descriptors.
  108956. + * Max value:
  108957. + * 64 in general,
  108958. + * 256 only for HS isochronous endpoint.
  108959. + */
  108960. + unsigned ntd:8;
  108961. +
  108962. + /** Data packets to transfer */
  108963. + unsigned reserved16_28:13;
  108964. +
  108965. + /**
  108966. + * Packet ID for next data packet
  108967. + * 0: DATA0
  108968. + * 1: DATA2
  108969. + * 2: DATA1
  108970. + * 3: MDATA (non-Control)
  108971. + */
  108972. + unsigned pid:2;
  108973. +
  108974. + /** Do PING protocol when 1 */
  108975. + unsigned dopng:1;
  108976. + } b_ddma;
  108977. +} hctsiz_data_t;
  108978. +
  108979. +/**
  108980. + * This union represents the bit fields in the Host DMA Address
  108981. + * Register used in Descriptor DMA mode.
  108982. + */
  108983. +typedef union hcdma_data {
  108984. + /** raw register data */
  108985. + uint32_t d32;
  108986. + /** register bits */
  108987. + struct {
  108988. + unsigned reserved0_2:3;
  108989. + /** Current Transfer Descriptor. Not used for ISOC */
  108990. + unsigned ctd:8;
  108991. + /** Start Address of Descriptor List */
  108992. + unsigned dma_addr:21;
  108993. + } b;
  108994. +} hcdma_data_t;
  108995. +
  108996. +/**
  108997. + * This union represents the bit fields in the DMA Descriptor
  108998. + * status quadlet for host mode. Read the quadlet into the <i>d32</i> member then
  108999. + * set/clear the bits using the <i>b</i>it elements.
  109000. + */
  109001. +typedef union host_dma_desc_sts {
  109002. + /** raw register data */
  109003. + uint32_t d32;
  109004. + /** quadlet bits */
  109005. +
  109006. + /* for non-isochronous */
  109007. + struct {
  109008. + /** Number of bytes */
  109009. + unsigned n_bytes:17;
  109010. + /** QTD offset to jump when Short Packet received - only for IN EPs */
  109011. + unsigned qtd_offset:6;
  109012. + /**
  109013. + * Set to request the core to jump to alternate QTD if
  109014. + * Short Packet received - only for IN EPs
  109015. + */
  109016. + unsigned a_qtd:1;
  109017. + /**
  109018. + * Setup Packet bit. When set indicates that buffer contains
  109019. + * setup packet.
  109020. + */
  109021. + unsigned sup:1;
  109022. + /** Interrupt On Complete */
  109023. + unsigned ioc:1;
  109024. + /** End of List */
  109025. + unsigned eol:1;
  109026. + unsigned reserved27:1;
  109027. + /** Rx/Tx Status */
  109028. + unsigned sts:2;
  109029. +#define DMA_DESC_STS_PKTERR 1
  109030. + unsigned reserved30:1;
  109031. + /** Active Bit */
  109032. + unsigned a:1;
  109033. + } b;
  109034. + /* for isochronous */
  109035. + struct {
  109036. + /** Number of bytes */
  109037. + unsigned n_bytes:12;
  109038. + unsigned reserved12_24:13;
  109039. + /** Interrupt On Complete */
  109040. + unsigned ioc:1;
  109041. + unsigned reserved26_27:2;
  109042. + /** Rx/Tx Status */
  109043. + unsigned sts:2;
  109044. + unsigned reserved30:1;
  109045. + /** Active Bit */
  109046. + unsigned a:1;
  109047. + } b_isoc;
  109048. +} host_dma_desc_sts_t;
  109049. +
  109050. +#define MAX_DMA_DESC_SIZE 131071
  109051. +#define MAX_DMA_DESC_NUM_GENERIC 64
  109052. +#define MAX_DMA_DESC_NUM_HS_ISOC 256
  109053. +#define MAX_FRLIST_EN_NUM 64
  109054. +/**
  109055. + * Host-mode DMA Descriptor structure
  109056. + *
  109057. + * DMA Descriptor structure contains two quadlets:
  109058. + * Status quadlet and Data buffer pointer.
  109059. + */
  109060. +typedef struct dwc_otg_host_dma_desc {
  109061. + /** DMA Descriptor status quadlet */
  109062. + host_dma_desc_sts_t status;
  109063. + /** DMA Descriptor data buffer pointer */
  109064. + uint32_t buf;
  109065. +} dwc_otg_host_dma_desc_t;
  109066. +
  109067. +/** OTG Host Interface Structure.
  109068. + *
  109069. + * The OTG Host Interface Structure structure contains information
  109070. + * needed to manage the DWC_otg controller acting in host mode. It
  109071. + * represents the programming view of the host-specific aspects of the
  109072. + * controller.
  109073. + */
  109074. +typedef struct dwc_otg_host_if {
  109075. + /** Host Global Registers starting at offset 400h.*/
  109076. + dwc_otg_host_global_regs_t *host_global_regs;
  109077. +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
  109078. +
  109079. + /** Host Port 0 Control and Status Register */
  109080. + volatile uint32_t *hprt0;
  109081. +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
  109082. +
  109083. + /** Host Channel Specific Registers at offsets 500h-5FCh. */
  109084. + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
  109085. +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
  109086. +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
  109087. +
  109088. + /* Host configuration information */
  109089. + /** Number of Host Channels (range: 1-16) */
  109090. + uint8_t num_host_channels;
  109091. + /** Periodic EPs supported (0: no, 1: yes) */
  109092. + uint8_t perio_eps_supported;
  109093. + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
  109094. + uint16_t perio_tx_fifo_size;
  109095. +
  109096. +} dwc_otg_host_if_t;
  109097. +
  109098. +/**
  109099. + * This union represents the bit fields in the Power and Clock Gating Control
  109100. + * Register. Read the register into the <i>d32</i> member then set/clear the
  109101. + * bits using the <i>b</i>it elements.
  109102. + */
  109103. +typedef union pcgcctl_data {
  109104. + /** raw register data */
  109105. + uint32_t d32;
  109106. +
  109107. + /** register bits */
  109108. + struct {
  109109. + /** Stop Pclk */
  109110. + unsigned stoppclk:1;
  109111. + /** Gate Hclk */
  109112. + unsigned gatehclk:1;
  109113. + /** Power Clamp */
  109114. + unsigned pwrclmp:1;
  109115. + /** Reset Power Down Modules */
  109116. + unsigned rstpdwnmodule:1;
  109117. + /** Reserved */
  109118. + unsigned reserved:1;
  109119. + /** Enable Sleep Clock Gating (Enbl_L1Gating) */
  109120. + unsigned enbl_sleep_gating:1;
  109121. + /** PHY In Sleep (PhySleep) */
  109122. + unsigned phy_in_sleep:1;
  109123. + /** Deep Sleep*/
  109124. + unsigned deep_sleep:1;
  109125. + unsigned resetaftsusp:1;
  109126. + unsigned restoremode:1;
  109127. + unsigned enbl_extnd_hiber:1;
  109128. + unsigned extnd_hiber_pwrclmp:1;
  109129. + unsigned extnd_hiber_switch:1;
  109130. + unsigned ess_reg_restored:1;
  109131. + unsigned prt_clk_sel:2;
  109132. + unsigned port_power:1;
  109133. + unsigned max_xcvrselect:2;
  109134. + unsigned max_termsel:1;
  109135. + unsigned mac_dev_addr:7;
  109136. + unsigned p2hd_dev_enum_spd:2;
  109137. + unsigned p2hd_prt_spd:2;
  109138. + unsigned if_dev_mode:1;
  109139. + } b;
  109140. +} pcgcctl_data_t;
  109141. +
  109142. +/**
  109143. + * This union represents the bit fields in the Global Data FIFO Software
  109144. + * Configuration Register. Read the register into the <i>d32</i> member then
  109145. + * set/clear the bits using the <i>b</i>it elements.
  109146. + */
  109147. +typedef union gdfifocfg_data {
  109148. + /* raw register data */
  109149. + uint32_t d32;
  109150. + /** register bits */
  109151. + struct {
  109152. + /** OTG Data FIFO depth */
  109153. + unsigned gdfifocfg:16;
  109154. + /** Start address of EP info controller */
  109155. + unsigned epinfobase:16;
  109156. + } b;
  109157. +} gdfifocfg_data_t;
  109158. +
  109159. +/**
  109160. + * This union represents the bit fields in the Global Power Down Register
  109161. + * Register. Read the register into the <i>d32</i> member then set/clear the
  109162. + * bits using the <i>b</i>it elements.
  109163. + */
  109164. +typedef union gpwrdn_data {
  109165. + /* raw register data */
  109166. + uint32_t d32;
  109167. +
  109168. + /** register bits */
  109169. + struct {
  109170. + /** PMU Interrupt Select */
  109171. + unsigned pmuintsel:1;
  109172. + /** PMU Active */
  109173. + unsigned pmuactv:1;
  109174. + /** Restore */
  109175. + unsigned restore:1;
  109176. + /** Power Down Clamp */
  109177. + unsigned pwrdnclmp:1;
  109178. + /** Power Down Reset */
  109179. + unsigned pwrdnrstn:1;
  109180. + /** Power Down Switch */
  109181. + unsigned pwrdnswtch:1;
  109182. + /** Disable VBUS */
  109183. + unsigned dis_vbus:1;
  109184. + /** Line State Change */
  109185. + unsigned lnstschng:1;
  109186. + /** Line state change mask */
  109187. + unsigned lnstchng_msk:1;
  109188. + /** Reset Detected */
  109189. + unsigned rst_det:1;
  109190. + /** Reset Detect mask */
  109191. + unsigned rst_det_msk:1;
  109192. + /** Disconnect Detected */
  109193. + unsigned disconn_det:1;
  109194. + /** Disconnect Detect mask */
  109195. + unsigned disconn_det_msk:1;
  109196. + /** Connect Detected*/
  109197. + unsigned connect_det:1;
  109198. + /** Connect Detected Mask*/
  109199. + unsigned connect_det_msk:1;
  109200. + /** SRP Detected */
  109201. + unsigned srp_det:1;
  109202. + /** SRP Detect mask */
  109203. + unsigned srp_det_msk:1;
  109204. + /** Status Change Interrupt */
  109205. + unsigned sts_chngint:1;
  109206. + /** Status Change Interrupt Mask */
  109207. + unsigned sts_chngint_msk:1;
  109208. + /** Line State */
  109209. + unsigned linestate:2;
  109210. + /** Indicates current mode(status of IDDIG signal) */
  109211. + unsigned idsts:1;
  109212. + /** B Session Valid signal status*/
  109213. + unsigned bsessvld:1;
  109214. + /** ADP Event Detected */
  109215. + unsigned adp_int:1;
  109216. + /** Multi Valued ID pin */
  109217. + unsigned mult_val_id_bc:5;
  109218. + /** Reserved 24_31 */
  109219. + unsigned reserved29_31:3;
  109220. + } b;
  109221. +} gpwrdn_data_t;
  109222. +
  109223. +#endif
  109224. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/Makefile linux-rpi/drivers/usb/host/dwc_otg/Makefile
  109225. --- linux-3.18.6/drivers/usb/host/dwc_otg/Makefile 1970-01-01 01:00:00.000000000 +0100
  109226. +++ linux-rpi/drivers/usb/host/dwc_otg/Makefile 2015-02-09 04:40:28.000000000 +0100
  109227. @@ -0,0 +1,82 @@
  109228. +#
  109229. +# Makefile for DWC_otg Highspeed USB controller driver
  109230. +#
  109231. +
  109232. +ifneq ($(KERNELRELEASE),)
  109233. +
  109234. +# Use the BUS_INTERFACE variable to compile the software for either
  109235. +# PCI(PCI_INTERFACE) or LM(LM_INTERFACE) bus.
  109236. +ifeq ($(BUS_INTERFACE),)
  109237. +# BUS_INTERFACE = -DPCI_INTERFACE
  109238. +# BUS_INTERFACE = -DLM_INTERFACE
  109239. + BUS_INTERFACE = -DPLATFORM_INTERFACE
  109240. +endif
  109241. +
  109242. +#ccflags-y += -DDEBUG
  109243. +#ccflags-y += -DDWC_OTG_DEBUGLEV=1 # reduce common debug msgs
  109244. +
  109245. +# Use one of the following flags to compile the software in host-only or
  109246. +# device-only mode.
  109247. +#ccflags-y += -DDWC_HOST_ONLY
  109248. +#ccflags-y += -DDWC_DEVICE_ONLY
  109249. +
  109250. +ccflags-y += -Dlinux -DDWC_HS_ELECT_TST
  109251. +#ccflags-y += -DDWC_EN_ISOC
  109252. +ccflags-y += -I$(obj)/../dwc_common_port
  109253. +#ccflags-y += -I$(PORTLIB)
  109254. +ccflags-y += -DDWC_LINUX
  109255. +ccflags-y += $(CFI)
  109256. +ccflags-y += $(BUS_INTERFACE)
  109257. +#ccflags-y += -DDWC_DEV_SRPCAP
  109258. +
  109259. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg.o
  109260. +
  109261. +dwc_otg-objs := dwc_otg_driver.o dwc_otg_attr.o
  109262. +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
  109263. +dwc_otg-objs += dwc_otg_pcd_linux.o dwc_otg_pcd.o dwc_otg_pcd_intr.o
  109264. +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
  109265. +dwc_otg-objs += dwc_otg_adp.o
  109266. +dwc_otg-objs += dwc_otg_fiq_fsm.o
  109267. +dwc_otg-objs += dwc_otg_fiq_stub.o
  109268. +ifneq ($(CFI),)
  109269. +dwc_otg-objs += dwc_otg_cfi.o
  109270. +endif
  109271. +
  109272. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  109273. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  109274. +
  109275. +ifneq ($(kernrel3),2.6.20)
  109276. +ccflags-y += $(CPPFLAGS)
  109277. +endif
  109278. +
  109279. +else
  109280. +
  109281. +PWD := $(shell pwd)
  109282. +PORTLIB := $(PWD)/../dwc_common_port
  109283. +
  109284. +# Command paths
  109285. +CTAGS := $(CTAGS)
  109286. +DOXYGEN := $(DOXYGEN)
  109287. +
  109288. +default: portlib
  109289. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  109290. +
  109291. +install: default
  109292. + $(MAKE) -C$(KDIR) M=$(PORTLIB) modules_install
  109293. + $(MAKE) -C$(KDIR) M=$(PWD) modules_install
  109294. +
  109295. +portlib:
  109296. + $(MAKE) -C$(KDIR) M=$(PORTLIB) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  109297. + cp $(PORTLIB)/Module.symvers $(PWD)/
  109298. +
  109299. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  109300. + $(DOXYGEN) doc/doxygen.cfg
  109301. +
  109302. +tags: $(wildcard *.[hc])
  109303. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  109304. +
  109305. +
  109306. +clean:
  109307. + rm -rf *.o *.ko .*cmd *.mod.c .tmp_versions Module.symvers
  109308. +
  109309. +endif
  109310. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm linux-rpi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm
  109311. --- linux-3.18.6/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 1970-01-01 01:00:00.000000000 +0100
  109312. +++ linux-rpi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 2015-02-09 04:40:29.000000000 +0100
  109313. @@ -0,0 +1,337 @@
  109314. +package dwc_otg_test;
  109315. +
  109316. +use strict;
  109317. +use Exporter ();
  109318. +
  109319. +use vars qw(@ISA @EXPORT
  109320. +$sysfsdir $paramdir $errors $params
  109321. +);
  109322. +
  109323. +@ISA = qw(Exporter);
  109324. +
  109325. +#
  109326. +# Globals
  109327. +#
  109328. +$sysfsdir = "/sys/devices/lm0";
  109329. +$paramdir = "/sys/module/dwc_otg";
  109330. +$errors = 0;
  109331. +
  109332. +$params = [
  109333. + {
  109334. + NAME => "otg_cap",
  109335. + DEFAULT => 0,
  109336. + ENUM => [],
  109337. + LOW => 0,
  109338. + HIGH => 2
  109339. + },
  109340. + {
  109341. + NAME => "dma_enable",
  109342. + DEFAULT => 0,
  109343. + ENUM => [],
  109344. + LOW => 0,
  109345. + HIGH => 1
  109346. + },
  109347. + {
  109348. + NAME => "dma_burst_size",
  109349. + DEFAULT => 32,
  109350. + ENUM => [1, 4, 8, 16, 32, 64, 128, 256],
  109351. + LOW => 1,
  109352. + HIGH => 256
  109353. + },
  109354. + {
  109355. + NAME => "host_speed",
  109356. + DEFAULT => 0,
  109357. + ENUM => [],
  109358. + LOW => 0,
  109359. + HIGH => 1
  109360. + },
  109361. + {
  109362. + NAME => "host_support_fs_ls_low_power",
  109363. + DEFAULT => 0,
  109364. + ENUM => [],
  109365. + LOW => 0,
  109366. + HIGH => 1
  109367. + },
  109368. + {
  109369. + NAME => "host_ls_low_power_phy_clk",
  109370. + DEFAULT => 0,
  109371. + ENUM => [],
  109372. + LOW => 0,
  109373. + HIGH => 1
  109374. + },
  109375. + {
  109376. + NAME => "dev_speed",
  109377. + DEFAULT => 0,
  109378. + ENUM => [],
  109379. + LOW => 0,
  109380. + HIGH => 1
  109381. + },
  109382. + {
  109383. + NAME => "enable_dynamic_fifo",
  109384. + DEFAULT => 1,
  109385. + ENUM => [],
  109386. + LOW => 0,
  109387. + HIGH => 1
  109388. + },
  109389. + {
  109390. + NAME => "data_fifo_size",
  109391. + DEFAULT => 8192,
  109392. + ENUM => [],
  109393. + LOW => 32,
  109394. + HIGH => 32768
  109395. + },
  109396. + {
  109397. + NAME => "dev_rx_fifo_size",
  109398. + DEFAULT => 1064,
  109399. + ENUM => [],
  109400. + LOW => 16,
  109401. + HIGH => 32768
  109402. + },
  109403. + {
  109404. + NAME => "dev_nperio_tx_fifo_size",
  109405. + DEFAULT => 1024,
  109406. + ENUM => [],
  109407. + LOW => 16,
  109408. + HIGH => 32768
  109409. + },
  109410. + {
  109411. + NAME => "dev_perio_tx_fifo_size_1",
  109412. + DEFAULT => 256,
  109413. + ENUM => [],
  109414. + LOW => 4,
  109415. + HIGH => 768
  109416. + },
  109417. + {
  109418. + NAME => "dev_perio_tx_fifo_size_2",
  109419. + DEFAULT => 256,
  109420. + ENUM => [],
  109421. + LOW => 4,
  109422. + HIGH => 768
  109423. + },
  109424. + {
  109425. + NAME => "dev_perio_tx_fifo_size_3",
  109426. + DEFAULT => 256,
  109427. + ENUM => [],
  109428. + LOW => 4,
  109429. + HIGH => 768
  109430. + },
  109431. + {
  109432. + NAME => "dev_perio_tx_fifo_size_4",
  109433. + DEFAULT => 256,
  109434. + ENUM => [],
  109435. + LOW => 4,
  109436. + HIGH => 768
  109437. + },
  109438. + {
  109439. + NAME => "dev_perio_tx_fifo_size_5",
  109440. + DEFAULT => 256,
  109441. + ENUM => [],
  109442. + LOW => 4,
  109443. + HIGH => 768
  109444. + },
  109445. + {
  109446. + NAME => "dev_perio_tx_fifo_size_6",
  109447. + DEFAULT => 256,
  109448. + ENUM => [],
  109449. + LOW => 4,
  109450. + HIGH => 768
  109451. + },
  109452. + {
  109453. + NAME => "dev_perio_tx_fifo_size_7",
  109454. + DEFAULT => 256,
  109455. + ENUM => [],
  109456. + LOW => 4,
  109457. + HIGH => 768
  109458. + },
  109459. + {
  109460. + NAME => "dev_perio_tx_fifo_size_8",
  109461. + DEFAULT => 256,
  109462. + ENUM => [],
  109463. + LOW => 4,
  109464. + HIGH => 768
  109465. + },
  109466. + {
  109467. + NAME => "dev_perio_tx_fifo_size_9",
  109468. + DEFAULT => 256,
  109469. + ENUM => [],
  109470. + LOW => 4,
  109471. + HIGH => 768
  109472. + },
  109473. + {
  109474. + NAME => "dev_perio_tx_fifo_size_10",
  109475. + DEFAULT => 256,
  109476. + ENUM => [],
  109477. + LOW => 4,
  109478. + HIGH => 768
  109479. + },
  109480. + {
  109481. + NAME => "dev_perio_tx_fifo_size_11",
  109482. + DEFAULT => 256,
  109483. + ENUM => [],
  109484. + LOW => 4,
  109485. + HIGH => 768
  109486. + },
  109487. + {
  109488. + NAME => "dev_perio_tx_fifo_size_12",
  109489. + DEFAULT => 256,
  109490. + ENUM => [],
  109491. + LOW => 4,
  109492. + HIGH => 768
  109493. + },
  109494. + {
  109495. + NAME => "dev_perio_tx_fifo_size_13",
  109496. + DEFAULT => 256,
  109497. + ENUM => [],
  109498. + LOW => 4,
  109499. + HIGH => 768
  109500. + },
  109501. + {
  109502. + NAME => "dev_perio_tx_fifo_size_14",
  109503. + DEFAULT => 256,
  109504. + ENUM => [],
  109505. + LOW => 4,
  109506. + HIGH => 768
  109507. + },
  109508. + {
  109509. + NAME => "dev_perio_tx_fifo_size_15",
  109510. + DEFAULT => 256,
  109511. + ENUM => [],
  109512. + LOW => 4,
  109513. + HIGH => 768
  109514. + },
  109515. + {
  109516. + NAME => "host_rx_fifo_size",
  109517. + DEFAULT => 1024,
  109518. + ENUM => [],
  109519. + LOW => 16,
  109520. + HIGH => 32768
  109521. + },
  109522. + {
  109523. + NAME => "host_nperio_tx_fifo_size",
  109524. + DEFAULT => 1024,
  109525. + ENUM => [],
  109526. + LOW => 16,
  109527. + HIGH => 32768
  109528. + },
  109529. + {
  109530. + NAME => "host_perio_tx_fifo_size",
  109531. + DEFAULT => 1024,
  109532. + ENUM => [],
  109533. + LOW => 16,
  109534. + HIGH => 32768
  109535. + },
  109536. + {
  109537. + NAME => "max_transfer_size",
  109538. + DEFAULT => 65535,
  109539. + ENUM => [],
  109540. + LOW => 2047,
  109541. + HIGH => 65535
  109542. + },
  109543. + {
  109544. + NAME => "max_packet_count",
  109545. + DEFAULT => 511,
  109546. + ENUM => [],
  109547. + LOW => 15,
  109548. + HIGH => 511
  109549. + },
  109550. + {
  109551. + NAME => "host_channels",
  109552. + DEFAULT => 12,
  109553. + ENUM => [],
  109554. + LOW => 1,
  109555. + HIGH => 16
  109556. + },
  109557. + {
  109558. + NAME => "dev_endpoints",
  109559. + DEFAULT => 6,
  109560. + ENUM => [],
  109561. + LOW => 1,
  109562. + HIGH => 15
  109563. + },
  109564. + {
  109565. + NAME => "phy_type",
  109566. + DEFAULT => 1,
  109567. + ENUM => [],
  109568. + LOW => 0,
  109569. + HIGH => 2
  109570. + },
  109571. + {
  109572. + NAME => "phy_utmi_width",
  109573. + DEFAULT => 16,
  109574. + ENUM => [8, 16],
  109575. + LOW => 8,
  109576. + HIGH => 16
  109577. + },
  109578. + {
  109579. + NAME => "phy_ulpi_ddr",
  109580. + DEFAULT => 0,
  109581. + ENUM => [],
  109582. + LOW => 0,
  109583. + HIGH => 1
  109584. + },
  109585. + ];
  109586. +
  109587. +
  109588. +#
  109589. +#
  109590. +sub check_arch {
  109591. + $_ = `uname -m`;
  109592. + chomp;
  109593. + unless (m/armv4tl/) {
  109594. + warn "# \n# Can't execute on $_. Run on integrator platform.\n# \n";
  109595. + return 0;
  109596. + }
  109597. + return 1;
  109598. +}
  109599. +
  109600. +#
  109601. +#
  109602. +sub load_module {
  109603. + my $params = shift;
  109604. + print "\nRemoving Module\n";
  109605. + system "rmmod dwc_otg";
  109606. + print "Loading Module\n";
  109607. + if ($params ne "") {
  109608. + print "Module Parameters: $params\n";
  109609. + }
  109610. + if (system("modprobe dwc_otg $params")) {
  109611. + warn "Unable to load module\n";
  109612. + return 0;
  109613. + }
  109614. + return 1;
  109615. +}
  109616. +
  109617. +#
  109618. +#
  109619. +sub test_status {
  109620. + my $arg = shift;
  109621. +
  109622. + print "\n";
  109623. +
  109624. + if (defined $arg) {
  109625. + warn "WARNING: $arg\n";
  109626. + }
  109627. +
  109628. + if ($errors > 0) {
  109629. + warn "TEST FAILED with $errors errors\n";
  109630. + return 0;
  109631. + } else {
  109632. + print "TEST PASSED\n";
  109633. + return 0 if (defined $arg);
  109634. + }
  109635. + return 1;
  109636. +}
  109637. +
  109638. +#
  109639. +#
  109640. +@EXPORT = qw(
  109641. +$sysfsdir
  109642. +$paramdir
  109643. +$params
  109644. +$errors
  109645. +check_arch
  109646. +load_module
  109647. +test_status
  109648. +);
  109649. +
  109650. +1;
  109651. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/test/Makefile linux-rpi/drivers/usb/host/dwc_otg/test/Makefile
  109652. --- linux-3.18.6/drivers/usb/host/dwc_otg/test/Makefile 1970-01-01 01:00:00.000000000 +0100
  109653. +++ linux-rpi/drivers/usb/host/dwc_otg/test/Makefile 2015-02-09 04:40:29.000000000 +0100
  109654. @@ -0,0 +1,16 @@
  109655. +
  109656. +PERL=/usr/bin/perl
  109657. +PL_TESTS=test_sysfs.pl test_mod_param.pl
  109658. +
  109659. +.PHONY : test
  109660. +test : perl_tests
  109661. +
  109662. +perl_tests :
  109663. + @echo
  109664. + @echo Running perl tests
  109665. + @for test in $(PL_TESTS); do \
  109666. + if $(PERL) ./$$test ; then \
  109667. + echo "=======> $$test, PASSED" ; \
  109668. + else echo "=======> $$test, FAILED" ; \
  109669. + fi \
  109670. + done
  109671. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/test/test_mod_param.pl linux-rpi/drivers/usb/host/dwc_otg/test/test_mod_param.pl
  109672. --- linux-3.18.6/drivers/usb/host/dwc_otg/test/test_mod_param.pl 1970-01-01 01:00:00.000000000 +0100
  109673. +++ linux-rpi/drivers/usb/host/dwc_otg/test/test_mod_param.pl 2015-02-09 04:40:29.000000000 +0100
  109674. @@ -0,0 +1,133 @@
  109675. +#!/usr/bin/perl -w
  109676. +#
  109677. +# Run this program on the integrator.
  109678. +#
  109679. +# - Tests module parameter default values.
  109680. +# - Tests setting of valid module parameter values via modprobe.
  109681. +# - Tests invalid module parameter values.
  109682. +# -----------------------------------------------------------------------------
  109683. +use strict;
  109684. +use dwc_otg_test;
  109685. +
  109686. +check_arch() or die;
  109687. +
  109688. +#
  109689. +#
  109690. +sub test {
  109691. + my ($param,$expected) = @_;
  109692. + my $value = get($param);
  109693. +
  109694. + if ($value == $expected) {
  109695. + print "$param = $value, okay\n";
  109696. + }
  109697. +
  109698. + else {
  109699. + warn "ERROR: value of $param != $expected, $value\n";
  109700. + $errors ++;
  109701. + }
  109702. +}
  109703. +
  109704. +#
  109705. +#
  109706. +sub get {
  109707. + my $param = shift;
  109708. + my $tmp = `cat $paramdir/$param`;
  109709. + chomp $tmp;
  109710. + return $tmp;
  109711. +}
  109712. +
  109713. +#
  109714. +#
  109715. +sub test_main {
  109716. +
  109717. + print "\nTesting Module Parameters\n";
  109718. +
  109719. + load_module("") or die;
  109720. +
  109721. + # Test initial values
  109722. + print "\nTesting Default Values\n";
  109723. + foreach (@{$params}) {
  109724. + test ($_->{NAME}, $_->{DEFAULT});
  109725. + }
  109726. +
  109727. + # Test low value
  109728. + print "\nTesting Low Value\n";
  109729. + my $cmd_params = "";
  109730. + foreach (@{$params}) {
  109731. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{LOW} ";
  109732. + }
  109733. + load_module($cmd_params) or die;
  109734. +
  109735. + foreach (@{$params}) {
  109736. + test ($_->{NAME}, $_->{LOW});
  109737. + }
  109738. +
  109739. + # Test high value
  109740. + print "\nTesting High Value\n";
  109741. + $cmd_params = "";
  109742. + foreach (@{$params}) {
  109743. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{HIGH} ";
  109744. + }
  109745. + load_module($cmd_params) or die;
  109746. +
  109747. + foreach (@{$params}) {
  109748. + test ($_->{NAME}, $_->{HIGH});
  109749. + }
  109750. +
  109751. + # Test Enum
  109752. + print "\nTesting Enumerated\n";
  109753. + foreach (@{$params}) {
  109754. + if (defined $_->{ENUM}) {
  109755. + my $value;
  109756. + foreach $value (@{$_->{ENUM}}) {
  109757. + $cmd_params = "$_->{NAME}=$value";
  109758. + load_module($cmd_params) or die;
  109759. + test ($_->{NAME}, $value);
  109760. + }
  109761. + }
  109762. + }
  109763. +
  109764. + # Test Invalid Values
  109765. + print "\nTesting Invalid Values\n";
  109766. + $cmd_params = "";
  109767. + foreach (@{$params}) {
  109768. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{LOW}-1;
  109769. + }
  109770. + load_module($cmd_params) or die;
  109771. +
  109772. + foreach (@{$params}) {
  109773. + test ($_->{NAME}, $_->{DEFAULT});
  109774. + }
  109775. +
  109776. + $cmd_params = "";
  109777. + foreach (@{$params}) {
  109778. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{HIGH}+1;
  109779. + }
  109780. + load_module($cmd_params) or die;
  109781. +
  109782. + foreach (@{$params}) {
  109783. + test ($_->{NAME}, $_->{DEFAULT});
  109784. + }
  109785. +
  109786. + print "\nTesting Enumerated\n";
  109787. + foreach (@{$params}) {
  109788. + if (defined $_->{ENUM}) {
  109789. + my $value;
  109790. + foreach $value (@{$_->{ENUM}}) {
  109791. + $value = $value + 1;
  109792. + $cmd_params = "$_->{NAME}=$value";
  109793. + load_module($cmd_params) or die;
  109794. + test ($_->{NAME}, $_->{DEFAULT});
  109795. + $value = $value - 2;
  109796. + $cmd_params = "$_->{NAME}=$value";
  109797. + load_module($cmd_params) or die;
  109798. + test ($_->{NAME}, $_->{DEFAULT});
  109799. + }
  109800. + }
  109801. + }
  109802. +
  109803. + test_status() or die;
  109804. +}
  109805. +
  109806. +test_main();
  109807. +0;
  109808. diff -Nur linux-3.18.6/drivers/usb/host/dwc_otg/test/test_sysfs.pl linux-rpi/drivers/usb/host/dwc_otg/test/test_sysfs.pl
  109809. --- linux-3.18.6/drivers/usb/host/dwc_otg/test/test_sysfs.pl 1970-01-01 01:00:00.000000000 +0100
  109810. +++ linux-rpi/drivers/usb/host/dwc_otg/test/test_sysfs.pl 2015-02-09 04:40:29.000000000 +0100
  109811. @@ -0,0 +1,193 @@
  109812. +#!/usr/bin/perl -w
  109813. +#
  109814. +# Run this program on the integrator
  109815. +# - Tests select sysfs attributes.
  109816. +# - Todo ... test more attributes, hnp/srp, buspower/bussuspend, etc.
  109817. +# -----------------------------------------------------------------------------
  109818. +use strict;
  109819. +use dwc_otg_test;
  109820. +
  109821. +check_arch() or die;
  109822. +
  109823. +#
  109824. +#
  109825. +sub test {
  109826. + my ($attr,$expected) = @_;
  109827. + my $string = get($attr);
  109828. +
  109829. + if ($string eq $expected) {
  109830. + printf("$attr = $string, okay\n");
  109831. + }
  109832. + else {
  109833. + warn "ERROR: value of $attr != $expected, $string\n";
  109834. + $errors ++;
  109835. + }
  109836. +}
  109837. +
  109838. +#
  109839. +#
  109840. +sub set {
  109841. + my ($reg, $value) = @_;
  109842. + system "echo $value > $sysfsdir/$reg";
  109843. +}
  109844. +
  109845. +#
  109846. +#
  109847. +sub get {
  109848. + my $attr = shift;
  109849. + my $string = `cat $sysfsdir/$attr`;
  109850. + chomp $string;
  109851. + if ($string =~ m/\s\=\s/) {
  109852. + my $tmp;
  109853. + ($tmp, $string) = split /\s=\s/, $string;
  109854. + }
  109855. + return $string;
  109856. +}
  109857. +
  109858. +#
  109859. +#
  109860. +sub test_main {
  109861. + print("\nTesting Sysfs Attributes\n");
  109862. +
  109863. + load_module("") or die;
  109864. +
  109865. + # Test initial values of regoffset/regvalue/guid/gsnpsid
  109866. + print("\nTesting Default Values\n");
  109867. +
  109868. + test("regoffset", "0xffffffff");
  109869. + test("regvalue", "invalid offset");
  109870. + test("guid", "0x12345678"); # this will fail if it has been changed
  109871. + test("gsnpsid", "0x4f54200a");
  109872. +
  109873. + # Test operation of regoffset/regvalue
  109874. + print("\nTesting regoffset\n");
  109875. + set('regoffset', '5a5a5a5a');
  109876. + test("regoffset", "0xffffffff");
  109877. +
  109878. + set('regoffset', '0');
  109879. + test("regoffset", "0x00000000");
  109880. +
  109881. + set('regoffset', '40000');
  109882. + test("regoffset", "0x00000000");
  109883. +
  109884. + set('regoffset', '3ffff');
  109885. + test("regoffset", "0x0003ffff");
  109886. +
  109887. + set('regoffset', '1');
  109888. + test("regoffset", "0x00000001");
  109889. +
  109890. + print("\nTesting regvalue\n");
  109891. + set('regoffset', '3c');
  109892. + test("regvalue", "0x12345678");
  109893. + set('regvalue', '5a5a5a5a');
  109894. + test("regvalue", "0x5a5a5a5a");
  109895. + set('regvalue','a5a5a5a5');
  109896. + test("regvalue", "0xa5a5a5a5");
  109897. + set('guid','12345678');
  109898. +
  109899. + # Test HNP Capable
  109900. + print("\nTesting HNP Capable bit\n");
  109901. + set('hnpcapable', '1');
  109902. + test("hnpcapable", "0x1");
  109903. + set('hnpcapable','0');
  109904. + test("hnpcapable", "0x0");
  109905. +
  109906. + set('regoffset','0c');
  109907. +
  109908. + my $old = get('gusbcfg');
  109909. + print("setting hnpcapable\n");
  109910. + set('hnpcapable', '1');
  109911. + test("hnpcapable", "0x1");
  109912. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<9)));
  109913. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<9)));
  109914. +
  109915. + $old = get('gusbcfg');
  109916. + print("clearing hnpcapable\n");
  109917. + set('hnpcapable', '0');
  109918. + test("hnpcapable", "0x0");
  109919. + test ('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  109920. + test ('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  109921. +
  109922. + # Test SRP Capable
  109923. + print("\nTesting SRP Capable bit\n");
  109924. + set('srpcapable', '1');
  109925. + test("srpcapable", "0x1");
  109926. + set('srpcapable','0');
  109927. + test("srpcapable", "0x0");
  109928. +
  109929. + set('regoffset','0c');
  109930. +
  109931. + $old = get('gusbcfg');
  109932. + print("setting srpcapable\n");
  109933. + set('srpcapable', '1');
  109934. + test("srpcapable", "0x1");
  109935. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<8)));
  109936. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<8)));
  109937. +
  109938. + $old = get('gusbcfg');
  109939. + print("clearing srpcapable\n");
  109940. + set('srpcapable', '0');
  109941. + test("srpcapable", "0x0");
  109942. + test('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  109943. + test('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  109944. +
  109945. + # Test GGPIO
  109946. + print("\nTesting GGPIO\n");
  109947. + set('ggpio','5a5a5a5a');
  109948. + test('ggpio','0x5a5a0000');
  109949. + set('ggpio','a5a5a5a5');
  109950. + test('ggpio','0xa5a50000');
  109951. + set('ggpio','11110000');
  109952. + test('ggpio','0x11110000');
  109953. + set('ggpio','00001111');
  109954. + test('ggpio','0x00000000');
  109955. +
  109956. + # Test DEVSPEED
  109957. + print("\nTesting DEVSPEED\n");
  109958. + set('regoffset','800');
  109959. + $old = get('regvalue');
  109960. + set('devspeed','0');
  109961. + test('devspeed','0x0');
  109962. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  109963. + set('devspeed','1');
  109964. + test('devspeed','0x1');
  109965. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  109966. + set('devspeed','2');
  109967. + test('devspeed','0x2');
  109968. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 2));
  109969. + set('devspeed','3');
  109970. + test('devspeed','0x3');
  109971. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 3));
  109972. + set('devspeed','4');
  109973. + test('devspeed','0x0');
  109974. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  109975. + set('devspeed','5');
  109976. + test('devspeed','0x1');
  109977. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  109978. +
  109979. +
  109980. + # mode Returns the current mode:0 for device mode1 for host mode Read
  109981. + # hnp Initiate the Host Negotiation Protocol. Read returns the status. Read/Write
  109982. + # srp Initiate the Session Request Protocol. Read returns the status. Read/Write
  109983. + # buspower Get or Set the Power State of the bus (0 - Off or 1 - On) Read/Write
  109984. + # bussuspend Suspend the USB bus. Read/Write
  109985. + # busconnected Get the connection status of the bus Read
  109986. +
  109987. + # gotgctl Get or set the Core Control Status Register. Read/Write
  109988. + ## gusbcfg Get or set the Core USB Configuration Register Read/Write
  109989. + # grxfsiz Get or set the Receive FIFO Size Register Read/Write
  109990. + # gnptxfsiz Get or set the non-periodic Transmit Size Register Read/Write
  109991. + # gpvndctl Get or set the PHY Vendor Control Register Read/Write
  109992. + ## ggpio Get the value in the lower 16-bits of the General Purpose IO Register or Set the upper 16 bits. Read/Write
  109993. + ## guid Get or set the value of the User ID Register Read/Write
  109994. + ## gsnpsid Get the value of the Synopsys ID Regester Read
  109995. + ## devspeed Get or set the device speed setting in the DCFG register Read/Write
  109996. + # enumspeed Gets the device enumeration Speed. Read
  109997. + # hptxfsiz Get the value of the Host Periodic Transmit FIFO Read
  109998. + # hprt0 Get or Set the value in the Host Port Control and Status Register Read/Write
  109999. +
  110000. + test_status("TEST NYI") or die;
  110001. +}
  110002. +
  110003. +test_main();
  110004. +0;
  110005. diff -Nur linux-3.18.6/drivers/usb/host/Kconfig linux-rpi/drivers/usb/host/Kconfig
  110006. --- linux-3.18.6/drivers/usb/host/Kconfig 2015-02-06 15:53:48.000000000 +0100
  110007. +++ linux-rpi/drivers/usb/host/Kconfig 2015-02-09 04:40:28.000000000 +0100
  110008. @@ -744,6 +744,19 @@
  110009. To compile this driver a module, choose M here: the module
  110010. will be called "hwa-hc".
  110011. +config USB_DWCOTG
  110012. + tristate "Synopsis DWC host support"
  110013. + depends on USB
  110014. + help
  110015. + The Synopsis DWC controller is a dual-role
  110016. + host/peripheral/OTG ("On The Go") USB controllers.
  110017. +
  110018. + Enable this option to support this IP in host controller mode.
  110019. + If unsure, say N.
  110020. +
  110021. + To compile this driver as a module, choose M here: the
  110022. + modules built will be called dwc_otg and dwc_common_port.
  110023. +
  110024. config USB_IMX21_HCD
  110025. tristate "i.MX21 HCD support"
  110026. depends on ARM && ARCH_MXC
  110027. diff -Nur linux-3.18.6/drivers/usb/host/Makefile linux-rpi/drivers/usb/host/Makefile
  110028. --- linux-3.18.6/drivers/usb/host/Makefile 2015-02-06 15:53:48.000000000 +0100
  110029. +++ linux-rpi/drivers/usb/host/Makefile 2015-02-09 04:40:28.000000000 +0100
  110030. @@ -71,6 +71,8 @@
  110031. obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
  110032. obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
  110033. obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
  110034. +
  110035. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg/ dwc_common_port/
  110036. obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
  110037. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
  110038. obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
  110039. diff -Nur linux-3.18.6/drivers/usb/Makefile linux-rpi/drivers/usb/Makefile
  110040. --- linux-3.18.6/drivers/usb/Makefile 2015-02-06 15:53:48.000000000 +0100
  110041. +++ linux-rpi/drivers/usb/Makefile 2015-02-09 04:40:28.000000000 +0100
  110042. @@ -24,6 +24,7 @@
  110043. obj-$(CONFIG_USB_R8A66597_HCD) += host/
  110044. obj-$(CONFIG_USB_HWA_HCD) += host/
  110045. obj-$(CONFIG_USB_ISP1760_HCD) += host/
  110046. +obj-$(CONFIG_USB_DWCOTG) += host/
  110047. obj-$(CONFIG_USB_IMX21_HCD) += host/
  110048. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/
  110049. obj-$(CONFIG_USB_FUSBH200_HCD) += host/
  110050. diff -Nur linux-3.18.6/drivers/video/fbdev/bcm2708_fb.c linux-rpi/drivers/video/fbdev/bcm2708_fb.c
  110051. --- linux-3.18.6/drivers/video/fbdev/bcm2708_fb.c 1970-01-01 01:00:00.000000000 +0100
  110052. +++ linux-rpi/drivers/video/fbdev/bcm2708_fb.c 2015-02-09 04:40:30.000000000 +0100
  110053. @@ -0,0 +1,818 @@
  110054. +/*
  110055. + * linux/drivers/video/bcm2708_fb.c
  110056. + *
  110057. + * Copyright (C) 2010 Broadcom
  110058. + *
  110059. + * This file is subject to the terms and conditions of the GNU General Public
  110060. + * License. See the file COPYING in the main directory of this archive
  110061. + * for more details.
  110062. + *
  110063. + * Broadcom simple framebuffer driver
  110064. + *
  110065. + * This file is derived from cirrusfb.c
  110066. + * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
  110067. + *
  110068. + */
  110069. +#include <linux/module.h>
  110070. +#include <linux/kernel.h>
  110071. +#include <linux/errno.h>
  110072. +#include <linux/string.h>
  110073. +#include <linux/slab.h>
  110074. +#include <linux/mm.h>
  110075. +#include <linux/fb.h>
  110076. +#include <linux/init.h>
  110077. +#include <linux/interrupt.h>
  110078. +#include <linux/ioport.h>
  110079. +#include <linux/list.h>
  110080. +#include <linux/platform_device.h>
  110081. +#include <linux/clk.h>
  110082. +#include <linux/printk.h>
  110083. +#include <linux/console.h>
  110084. +#include <linux/debugfs.h>
  110085. +
  110086. +#include <mach/dma.h>
  110087. +#include <mach/platform.h>
  110088. +#include <mach/vcio.h>
  110089. +
  110090. +#include <asm/sizes.h>
  110091. +#include <linux/io.h>
  110092. +#include <linux/dma-mapping.h>
  110093. +
  110094. +//#define BCM2708_FB_DEBUG
  110095. +#define MODULE_NAME "bcm2708_fb"
  110096. +
  110097. +#ifdef BCM2708_FB_DEBUG
  110098. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  110099. +#else
  110100. +#define print_debug(fmt,...)
  110101. +#endif
  110102. +
  110103. +/* This is limited to 16 characters when displayed by X startup */
  110104. +static const char *bcm2708_name = "BCM2708 FB";
  110105. +
  110106. +#define DRIVER_NAME "bcm2708_fb"
  110107. +
  110108. +static int fbwidth = 800; /* module parameter */
  110109. +static int fbheight = 480; /* module parameter */
  110110. +static int fbdepth = 16; /* module parameter */
  110111. +static int fbswap = 0; /* module parameter */
  110112. +
  110113. +static u32 dma_busy_wait_threshold = 1<<15;
  110114. +module_param(dma_busy_wait_threshold, int, 0644);
  110115. +MODULE_PARM_DESC(dma_busy_wait_threshold, "Busy-wait for DMA completion below this area");
  110116. +
  110117. +/* this data structure describes each frame buffer device we find */
  110118. +
  110119. +struct fbinfo_s {
  110120. + u32 xres, yres, xres_virtual, yres_virtual;
  110121. + u32 pitch, bpp;
  110122. + u32 xoffset, yoffset;
  110123. + u32 base;
  110124. + u32 screen_size;
  110125. + u16 cmap[256];
  110126. +};
  110127. +
  110128. +struct bcm2708_fb_stats {
  110129. + struct debugfs_regset32 regset;
  110130. + u32 dma_copies;
  110131. + u32 dma_irqs;
  110132. +};
  110133. +
  110134. +struct bcm2708_fb {
  110135. + struct fb_info fb;
  110136. + struct platform_device *dev;
  110137. + struct fbinfo_s *info;
  110138. + dma_addr_t dma;
  110139. + u32 cmap[16];
  110140. + int dma_chan;
  110141. + int dma_irq;
  110142. + void __iomem *dma_chan_base;
  110143. + void *cb_base; /* DMA control blocks */
  110144. + dma_addr_t cb_handle;
  110145. + struct dentry *debugfs_dir;
  110146. + wait_queue_head_t dma_waitq;
  110147. + struct bcm2708_fb_stats stats;
  110148. + unsigned long fb_bus_address;
  110149. +};
  110150. +
  110151. +#define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
  110152. +
  110153. +static void bcm2708_fb_debugfs_deinit(struct bcm2708_fb *fb)
  110154. +{
  110155. + debugfs_remove_recursive(fb->debugfs_dir);
  110156. + fb->debugfs_dir = NULL;
  110157. +}
  110158. +
  110159. +static int bcm2708_fb_debugfs_init(struct bcm2708_fb *fb)
  110160. +{
  110161. + static struct debugfs_reg32 stats_registers[] = {
  110162. + {
  110163. + "dma_copies",
  110164. + offsetof(struct bcm2708_fb_stats, dma_copies)
  110165. + },
  110166. + {
  110167. + "dma_irqs",
  110168. + offsetof(struct bcm2708_fb_stats, dma_irqs)
  110169. + },
  110170. + };
  110171. +
  110172. + fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
  110173. + if (!fb->debugfs_dir) {
  110174. + pr_warn("%s: could not create debugfs entry\n",
  110175. + __func__);
  110176. + return -EFAULT;
  110177. + }
  110178. +
  110179. + fb->stats.regset.regs = stats_registers;
  110180. + fb->stats.regset.nregs = ARRAY_SIZE(stats_registers);
  110181. + fb->stats.regset.base = &fb->stats;
  110182. +
  110183. + if (!debugfs_create_regset32(
  110184. + "stats", 0444, fb->debugfs_dir, &fb->stats.regset)) {
  110185. + pr_warn("%s: could not create statistics registers\n",
  110186. + __func__);
  110187. + goto fail;
  110188. + }
  110189. + return 0;
  110190. +
  110191. +fail:
  110192. + bcm2708_fb_debugfs_deinit(fb);
  110193. + return -EFAULT;
  110194. +}
  110195. +
  110196. +static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
  110197. +{
  110198. + int ret = 0;
  110199. +
  110200. + memset(&var->transp, 0, sizeof(var->transp));
  110201. +
  110202. + var->red.msb_right = 0;
  110203. + var->green.msb_right = 0;
  110204. + var->blue.msb_right = 0;
  110205. +
  110206. + switch (var->bits_per_pixel) {
  110207. + case 1:
  110208. + case 2:
  110209. + case 4:
  110210. + case 8:
  110211. + var->red.length = var->bits_per_pixel;
  110212. + var->red.offset = 0;
  110213. + var->green.length = var->bits_per_pixel;
  110214. + var->green.offset = 0;
  110215. + var->blue.length = var->bits_per_pixel;
  110216. + var->blue.offset = 0;
  110217. + break;
  110218. + case 16:
  110219. + var->red.length = 5;
  110220. + var->blue.length = 5;
  110221. + /*
  110222. + * Green length can be 5 or 6 depending whether
  110223. + * we're operating in RGB555 or RGB565 mode.
  110224. + */
  110225. + if (var->green.length != 5 && var->green.length != 6)
  110226. + var->green.length = 6;
  110227. + break;
  110228. + case 24:
  110229. + var->red.length = 8;
  110230. + var->blue.length = 8;
  110231. + var->green.length = 8;
  110232. + break;
  110233. + case 32:
  110234. + var->red.length = 8;
  110235. + var->green.length = 8;
  110236. + var->blue.length = 8;
  110237. + var->transp.length = 8;
  110238. + break;
  110239. + default:
  110240. + ret = -EINVAL;
  110241. + break;
  110242. + }
  110243. +
  110244. + /*
  110245. + * >= 16bpp displays have separate colour component bitfields
  110246. + * encoded in the pixel data. Calculate their position from
  110247. + * the bitfield length defined above.
  110248. + */
  110249. + if (ret == 0 && var->bits_per_pixel >= 24 && fbswap) {
  110250. + var->blue.offset = 0;
  110251. + var->green.offset = var->blue.offset + var->blue.length;
  110252. + var->red.offset = var->green.offset + var->green.length;
  110253. + var->transp.offset = var->red.offset + var->red.length;
  110254. + } else if (ret == 0 && var->bits_per_pixel >= 24) {
  110255. + var->red.offset = 0;
  110256. + var->green.offset = var->red.offset + var->red.length;
  110257. + var->blue.offset = var->green.offset + var->green.length;
  110258. + var->transp.offset = var->blue.offset + var->blue.length;
  110259. + } else if (ret == 0 && var->bits_per_pixel >= 16) {
  110260. + var->blue.offset = 0;
  110261. + var->green.offset = var->blue.offset + var->blue.length;
  110262. + var->red.offset = var->green.offset + var->green.length;
  110263. + var->transp.offset = var->red.offset + var->red.length;
  110264. + }
  110265. +
  110266. + return ret;
  110267. +}
  110268. +
  110269. +static int bcm2708_fb_check_var(struct fb_var_screeninfo *var,
  110270. + struct fb_info *info)
  110271. +{
  110272. + /* info input, var output */
  110273. + int yres;
  110274. +
  110275. + /* info input, var output */
  110276. + print_debug("bcm2708_fb_check_var info(%p) %dx%d (%dx%d), %d, %d\n", info,
  110277. + info->var.xres, info->var.yres, info->var.xres_virtual,
  110278. + info->var.yres_virtual, (int)info->screen_size,
  110279. + info->var.bits_per_pixel);
  110280. + print_debug("bcm2708_fb_check_var var(%p) %dx%d (%dx%d), %d\n", var,
  110281. + var->xres, var->yres, var->xres_virtual, var->yres_virtual,
  110282. + var->bits_per_pixel);
  110283. +
  110284. + if (!var->bits_per_pixel)
  110285. + var->bits_per_pixel = 16;
  110286. +
  110287. + if (bcm2708_fb_set_bitfields(var) != 0) {
  110288. + pr_err("bcm2708_fb_check_var: invalid bits_per_pixel %d\n",
  110289. + var->bits_per_pixel);
  110290. + return -EINVAL;
  110291. + }
  110292. +
  110293. +
  110294. + if (var->xres_virtual < var->xres)
  110295. + var->xres_virtual = var->xres;
  110296. + /* use highest possible virtual resolution */
  110297. + if (var->yres_virtual == -1) {
  110298. + var->yres_virtual = 480;
  110299. +
  110300. + pr_err
  110301. + ("bcm2708_fb_check_var: virtual resolution set to maximum of %dx%d\n",
  110302. + var->xres_virtual, var->yres_virtual);
  110303. + }
  110304. + if (var->yres_virtual < var->yres)
  110305. + var->yres_virtual = var->yres;
  110306. +
  110307. + if (var->xoffset < 0)
  110308. + var->xoffset = 0;
  110309. + if (var->yoffset < 0)
  110310. + var->yoffset = 0;
  110311. +
  110312. + /* truncate xoffset and yoffset to maximum if too high */
  110313. + if (var->xoffset > var->xres_virtual - var->xres)
  110314. + var->xoffset = var->xres_virtual - var->xres - 1;
  110315. + if (var->yoffset > var->yres_virtual - var->yres)
  110316. + var->yoffset = var->yres_virtual - var->yres - 1;
  110317. +
  110318. + yres = var->yres;
  110319. + if (var->vmode & FB_VMODE_DOUBLE)
  110320. + yres *= 2;
  110321. + else if (var->vmode & FB_VMODE_INTERLACED)
  110322. + yres = (yres + 1) / 2;
  110323. +
  110324. + return 0;
  110325. +}
  110326. +
  110327. +static int bcm2708_fb_set_par(struct fb_info *info)
  110328. +{
  110329. + uint32_t val = 0;
  110330. + struct bcm2708_fb *fb = to_bcm2708(info);
  110331. + volatile struct fbinfo_s *fbinfo = fb->info;
  110332. + fbinfo->xres = info->var.xres;
  110333. + fbinfo->yres = info->var.yres;
  110334. + fbinfo->xres_virtual = info->var.xres_virtual;
  110335. + fbinfo->yres_virtual = info->var.yres_virtual;
  110336. + fbinfo->bpp = info->var.bits_per_pixel;
  110337. + fbinfo->xoffset = info->var.xoffset;
  110338. + fbinfo->yoffset = info->var.yoffset;
  110339. + fbinfo->base = 0; /* filled in by VC */
  110340. + fbinfo->pitch = 0; /* filled in by VC */
  110341. +
  110342. + print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
  110343. + info->var.xres, info->var.yres, info->var.xres_virtual,
  110344. + info->var.yres_virtual, (int)info->screen_size,
  110345. + info->var.bits_per_pixel);
  110346. +
  110347. + /* ensure last write to fbinfo is visible to GPU */
  110348. + wmb();
  110349. +
  110350. + /* inform vc about new framebuffer */
  110351. + bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
  110352. +
  110353. + /* TODO: replace fb driver with vchiq version */
  110354. + /* wait for response */
  110355. + bcm_mailbox_read(MBOX_CHAN_FB, &val);
  110356. +
  110357. + /* ensure GPU writes are visible to us */
  110358. + rmb();
  110359. +
  110360. + if (val == 0) {
  110361. + fb->fb.fix.line_length = fbinfo->pitch;
  110362. +
  110363. + if (info->var.bits_per_pixel <= 8)
  110364. + fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  110365. + else
  110366. + fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  110367. +
  110368. + fb->fb_bus_address = fbinfo->base;
  110369. + fbinfo->base &= ~0xc0000000;
  110370. + fb->fb.fix.smem_start = fbinfo->base;
  110371. + fb->fb.fix.smem_len = fbinfo->pitch * fbinfo->yres_virtual;
  110372. + fb->fb.screen_size = fbinfo->screen_size;
  110373. + if (fb->fb.screen_base)
  110374. + iounmap(fb->fb.screen_base);
  110375. + fb->fb.screen_base =
  110376. + (void *)ioremap_wc(fbinfo->base, fb->fb.screen_size);
  110377. + if (!fb->fb.screen_base) {
  110378. + /* the console may currently be locked */
  110379. + console_trylock();
  110380. + console_unlock();
  110381. +
  110382. + BUG(); /* what can we do here */
  110383. + }
  110384. + }
  110385. + print_debug
  110386. + ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d success=%d\n",
  110387. + (void *)fb->fb.screen_base, (void *)fb->fb_bus_address,
  110388. + fbinfo->xres, fbinfo->yres, fbinfo->bpp,
  110389. + fbinfo->pitch, (int)fb->fb.screen_size, val);
  110390. +
  110391. + return val;
  110392. +}
  110393. +
  110394. +static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
  110395. +{
  110396. + unsigned int mask = (1 << bf->length) - 1;
  110397. +
  110398. + return (val >> (16 - bf->length) & mask) << bf->offset;
  110399. +}
  110400. +
  110401. +
  110402. +static int bcm2708_fb_setcolreg(unsigned int regno, unsigned int red,
  110403. + unsigned int green, unsigned int blue,
  110404. + unsigned int transp, struct fb_info *info)
  110405. +{
  110406. + struct bcm2708_fb *fb = to_bcm2708(info);
  110407. +
  110408. + /*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
  110409. + if (fb->fb.var.bits_per_pixel <= 8) {
  110410. + if (regno < 256) {
  110411. + /* blue [0:4], green [5:10], red [11:15] */
  110412. + fb->info->cmap[regno] = ((red >> (16-5)) & 0x1f) << 11 |
  110413. + ((green >> (16-6)) & 0x3f) << 5 |
  110414. + ((blue >> (16-5)) & 0x1f) << 0;
  110415. + }
  110416. + /* 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 */
  110417. + /* So just call it for what looks like the last colour in a list for now. */
  110418. + if (regno == 15 || regno == 255)
  110419. + bcm2708_fb_set_par(info);
  110420. + } else if (regno < 16) {
  110421. + fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
  110422. + convert_bitfield(blue, &fb->fb.var.blue) |
  110423. + convert_bitfield(green, &fb->fb.var.green) |
  110424. + convert_bitfield(red, &fb->fb.var.red);
  110425. + }
  110426. + return regno > 255;
  110427. +}
  110428. +
  110429. +static int bcm2708_fb_blank(int blank_mode, struct fb_info *info)
  110430. +{
  110431. + s32 result = -1;
  110432. + u32 p[7];
  110433. + if ( (blank_mode == FB_BLANK_NORMAL) ||
  110434. + (blank_mode == FB_BLANK_UNBLANK)) {
  110435. +
  110436. + p[0] = 28; // size = sizeof u32 * length of p
  110437. + p[1] = VCMSG_PROCESS_REQUEST; // process request
  110438. + p[2] = VCMSG_SET_BLANK_SCREEN; // (the tag id)
  110439. + p[3] = 4; // (size of the response buffer)
  110440. + p[4] = 4; // (size of the request data)
  110441. + p[5] = blank_mode;
  110442. + p[6] = VCMSG_PROPERTY_END; // end tag
  110443. +
  110444. + bcm_mailbox_property(&p, p[0]);
  110445. +
  110446. + if ( p[1] == VCMSG_REQUEST_SUCCESSFUL )
  110447. + result = 0;
  110448. + else
  110449. + pr_err("bcm2708_fb_blank(%d) returns=%d p[1]=0x%x\n", blank_mode, p[5], p[1]);
  110450. + }
  110451. + return result;
  110452. +}
  110453. +
  110454. +static int bcm2708_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  110455. +{
  110456. + s32 result = -1;
  110457. + info->var.xoffset = var->xoffset;
  110458. + info->var.yoffset = var->yoffset;
  110459. + result = bcm2708_fb_set_par(info);
  110460. + if (result != 0)
  110461. + pr_err("bcm2708_fb_pan_display(%d,%d) returns=%d\n", var->xoffset, var->yoffset, result);
  110462. + return result;
  110463. +}
  110464. +
  110465. +static int bcm2708_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
  110466. +{
  110467. + s32 result = -1;
  110468. + u32 p[7];
  110469. + if (cmd == FBIO_WAITFORVSYNC) {
  110470. + p[0] = 28; // size = sizeof u32 * length of p
  110471. + p[1] = VCMSG_PROCESS_REQUEST; // process request
  110472. + p[2] = VCMSG_SET_VSYNC; // (the tag id)
  110473. + p[3] = 4; // (size of the response buffer)
  110474. + p[4] = 4; // (size of the request data)
  110475. + p[5] = 0; // dummy
  110476. + p[6] = VCMSG_PROPERTY_END; // end tag
  110477. +
  110478. + bcm_mailbox_property(&p, p[0]);
  110479. +
  110480. + pr_info("bcm2708_fb_ioctl %x,%lx returns=%d p[1]=0x%x\n", cmd, arg, p[5], p[1]);
  110481. +
  110482. + if ( p[1] == VCMSG_REQUEST_SUCCESSFUL )
  110483. + result = 0;
  110484. + }
  110485. + return result;
  110486. +}
  110487. +static void bcm2708_fb_fillrect(struct fb_info *info,
  110488. + const struct fb_fillrect *rect)
  110489. +{
  110490. + /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
  110491. + cfb_fillrect(info, rect);
  110492. +}
  110493. +
  110494. +/* A helper function for configuring dma control block */
  110495. +static void set_dma_cb(struct bcm2708_dma_cb *cb,
  110496. + int burst_size,
  110497. + dma_addr_t dst,
  110498. + int dst_stride,
  110499. + dma_addr_t src,
  110500. + int src_stride,
  110501. + int w,
  110502. + int h)
  110503. +{
  110504. + cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
  110505. + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
  110506. + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
  110507. + cb->dst = dst;
  110508. + cb->src = src;
  110509. + /*
  110510. + * This is not really obvious from the DMA documentation,
  110511. + * but the top 16 bits must be programmmed to "height -1"
  110512. + * and not "height" in 2D mode.
  110513. + */
  110514. + cb->length = ((h - 1) << 16) | w;
  110515. + cb->stride = ((dst_stride - w) << 16) | (u16)(src_stride - w);
  110516. + cb->pad[0] = 0;
  110517. + cb->pad[1] = 0;
  110518. +}
  110519. +
  110520. +static void bcm2708_fb_copyarea(struct fb_info *info,
  110521. + const struct fb_copyarea *region)
  110522. +{
  110523. + struct bcm2708_fb *fb = to_bcm2708(info);
  110524. + struct bcm2708_dma_cb *cb = fb->cb_base;
  110525. + int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
  110526. + /* Channel 0 supports larger bursts and is a bit faster */
  110527. + int burst_size = (fb->dma_chan == 0) ? 8 : 2;
  110528. + int pixels = region->width * region->height;
  110529. +
  110530. + /* Fallback to cfb_copyarea() if we don't like something */
  110531. + if (in_atomic() ||
  110532. + bytes_per_pixel > 4 ||
  110533. + info->var.xres * info->var.yres > 1920 * 1200 ||
  110534. + region->width <= 0 || region->width > info->var.xres ||
  110535. + region->height <= 0 || region->height > info->var.yres ||
  110536. + region->sx < 0 || region->sx >= info->var.xres ||
  110537. + region->sy < 0 || region->sy >= info->var.yres ||
  110538. + region->dx < 0 || region->dx >= info->var.xres ||
  110539. + region->dy < 0 || region->dy >= info->var.yres ||
  110540. + region->sx + region->width > info->var.xres ||
  110541. + region->dx + region->width > info->var.xres ||
  110542. + region->sy + region->height > info->var.yres ||
  110543. + region->dy + region->height > info->var.yres) {
  110544. + cfb_copyarea(info, region);
  110545. + return;
  110546. + }
  110547. +
  110548. + if (region->dy == region->sy && region->dx > region->sx) {
  110549. + /*
  110550. + * A difficult case of overlapped copy. Because DMA can't
  110551. + * copy individual scanlines in backwards direction, we need
  110552. + * two-pass processing. We do it by programming a chain of dma
  110553. + * control blocks in the first 16K part of the buffer and use
  110554. + * the remaining 48K as the intermediate temporary scratch
  110555. + * buffer. The buffer size is sufficient to handle up to
  110556. + * 1920x1200 resolution at 32bpp pixel depth.
  110557. + */
  110558. + int y;
  110559. + dma_addr_t control_block_pa = fb->cb_handle;
  110560. + dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
  110561. + int scanline_size = bytes_per_pixel * region->width;
  110562. + int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
  110563. +
  110564. + for (y = 0; y < region->height; y += scanlines_per_cb) {
  110565. + dma_addr_t src =
  110566. + fb->fb_bus_address +
  110567. + bytes_per_pixel * region->sx +
  110568. + (region->sy + y) * fb->fb.fix.line_length;
  110569. + dma_addr_t dst =
  110570. + fb->fb_bus_address +
  110571. + bytes_per_pixel * region->dx +
  110572. + (region->dy + y) * fb->fb.fix.line_length;
  110573. +
  110574. + if (region->height - y < scanlines_per_cb)
  110575. + scanlines_per_cb = region->height - y;
  110576. +
  110577. + set_dma_cb(cb, burst_size, scratchbuf, scanline_size,
  110578. + src, fb->fb.fix.line_length,
  110579. + scanline_size, scanlines_per_cb);
  110580. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  110581. + cb->next = control_block_pa;
  110582. + cb++;
  110583. +
  110584. + set_dma_cb(cb, burst_size, dst, fb->fb.fix.line_length,
  110585. + scratchbuf, scanline_size,
  110586. + scanline_size, scanlines_per_cb);
  110587. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  110588. + cb->next = control_block_pa;
  110589. + cb++;
  110590. + }
  110591. + /* move the pointer back to the last dma control block */
  110592. + cb--;
  110593. + } else {
  110594. + /* A single dma control block is enough. */
  110595. + int sy, dy, stride;
  110596. + if (region->dy <= region->sy) {
  110597. + /* processing from top to bottom */
  110598. + dy = region->dy;
  110599. + sy = region->sy;
  110600. + stride = fb->fb.fix.line_length;
  110601. + } else {
  110602. + /* processing from bottom to top */
  110603. + dy = region->dy + region->height - 1;
  110604. + sy = region->sy + region->height - 1;
  110605. + stride = -fb->fb.fix.line_length;
  110606. + }
  110607. + set_dma_cb(cb, burst_size,
  110608. + fb->fb_bus_address + dy * fb->fb.fix.line_length +
  110609. + bytes_per_pixel * region->dx,
  110610. + stride,
  110611. + fb->fb_bus_address + sy * fb->fb.fix.line_length +
  110612. + bytes_per_pixel * region->sx,
  110613. + stride,
  110614. + region->width * bytes_per_pixel,
  110615. + region->height);
  110616. + }
  110617. +
  110618. + /* end of dma control blocks chain */
  110619. + cb->next = 0;
  110620. +
  110621. +
  110622. + if (pixels < dma_busy_wait_threshold) {
  110623. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  110624. + bcm_dma_wait_idle(fb->dma_chan_base);
  110625. + } else {
  110626. + void __iomem *dma_chan = fb->dma_chan_base;
  110627. + cb->info |= BCM2708_DMA_INT_EN;
  110628. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  110629. + while (bcm_dma_is_busy(dma_chan)) {
  110630. + wait_event_interruptible(
  110631. + fb->dma_waitq,
  110632. + !bcm_dma_is_busy(dma_chan));
  110633. + }
  110634. + fb->stats.dma_irqs++;
  110635. + }
  110636. + fb->stats.dma_copies++;
  110637. +}
  110638. +
  110639. +static void bcm2708_fb_imageblit(struct fb_info *info,
  110640. + const struct fb_image *image)
  110641. +{
  110642. + /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
  110643. + cfb_imageblit(info, image);
  110644. +}
  110645. +
  110646. +static irqreturn_t bcm2708_fb_dma_irq(int irq, void *cxt)
  110647. +{
  110648. + struct bcm2708_fb *fb = cxt;
  110649. +
  110650. + /* FIXME: should read status register to check if this is
  110651. + * actually interrupting us or not, in case this interrupt
  110652. + * ever becomes shared amongst several DMA channels
  110653. + *
  110654. + * readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_IRQ;
  110655. + */
  110656. +
  110657. + /* acknowledge the interrupt */
  110658. + writel(BCM2708_DMA_INT, fb->dma_chan_base + BCM2708_DMA_CS);
  110659. +
  110660. + wake_up(&fb->dma_waitq);
  110661. + return IRQ_HANDLED;
  110662. +}
  110663. +
  110664. +static struct fb_ops bcm2708_fb_ops = {
  110665. + .owner = THIS_MODULE,
  110666. + .fb_check_var = bcm2708_fb_check_var,
  110667. + .fb_set_par = bcm2708_fb_set_par,
  110668. + .fb_setcolreg = bcm2708_fb_setcolreg,
  110669. + .fb_blank = bcm2708_fb_blank,
  110670. + .fb_fillrect = bcm2708_fb_fillrect,
  110671. + .fb_copyarea = bcm2708_fb_copyarea,
  110672. + .fb_imageblit = bcm2708_fb_imageblit,
  110673. + .fb_pan_display = bcm2708_fb_pan_display,
  110674. + .fb_ioctl = bcm2708_ioctl,
  110675. +};
  110676. +
  110677. +static int bcm2708_fb_register(struct bcm2708_fb *fb)
  110678. +{
  110679. + int ret;
  110680. + dma_addr_t dma;
  110681. + void *mem;
  110682. +
  110683. + mem =
  110684. + dma_alloc_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), &dma,
  110685. + GFP_KERNEL);
  110686. +
  110687. + if (NULL == mem) {
  110688. + pr_err(": unable to allocate fbinfo buffer\n");
  110689. + ret = -ENOMEM;
  110690. + } else {
  110691. + fb->info = (struct fbinfo_s *)mem;
  110692. + fb->dma = dma;
  110693. + }
  110694. + fb->fb.fbops = &bcm2708_fb_ops;
  110695. + fb->fb.flags = FBINFO_FLAG_DEFAULT | FBINFO_HWACCEL_COPYAREA;
  110696. + fb->fb.pseudo_palette = fb->cmap;
  110697. +
  110698. + strncpy(fb->fb.fix.id, bcm2708_name, sizeof(fb->fb.fix.id));
  110699. + fb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  110700. + fb->fb.fix.type_aux = 0;
  110701. + fb->fb.fix.xpanstep = 1;
  110702. + fb->fb.fix.ypanstep = 1;
  110703. + fb->fb.fix.ywrapstep = 0;
  110704. + fb->fb.fix.accel = FB_ACCEL_NONE;
  110705. +
  110706. + fb->fb.var.xres = fbwidth;
  110707. + fb->fb.var.yres = fbheight;
  110708. + fb->fb.var.xres_virtual = fbwidth;
  110709. + fb->fb.var.yres_virtual = fbheight;
  110710. + fb->fb.var.bits_per_pixel = fbdepth;
  110711. + fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
  110712. + fb->fb.var.activate = FB_ACTIVATE_NOW;
  110713. + fb->fb.var.nonstd = 0;
  110714. + fb->fb.var.height = -1; /* height of picture in mm */
  110715. + fb->fb.var.width = -1; /* width of picture in mm */
  110716. + fb->fb.var.accel_flags = 0;
  110717. +
  110718. + fb->fb.monspecs.hfmin = 0;
  110719. + fb->fb.monspecs.hfmax = 100000;
  110720. + fb->fb.monspecs.vfmin = 0;
  110721. + fb->fb.monspecs.vfmax = 400;
  110722. + fb->fb.monspecs.dclkmin = 1000000;
  110723. + fb->fb.monspecs.dclkmax = 100000000;
  110724. +
  110725. + bcm2708_fb_set_bitfields(&fb->fb.var);
  110726. + init_waitqueue_head(&fb->dma_waitq);
  110727. +
  110728. + /*
  110729. + * Allocate colourmap.
  110730. + */
  110731. +
  110732. + fb_set_var(&fb->fb, &fb->fb.var);
  110733. + bcm2708_fb_set_par(&fb->fb);
  110734. +
  110735. + print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n", fbwidth
  110736. + fbheight, fbdepth, fbswap);
  110737. +
  110738. + ret = register_framebuffer(&fb->fb);
  110739. + print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
  110740. + if (ret == 0)
  110741. + goto out;
  110742. +
  110743. + print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
  110744. +out:
  110745. + return ret;
  110746. +}
  110747. +
  110748. +static int bcm2708_fb_probe(struct platform_device *dev)
  110749. +{
  110750. + struct bcm2708_fb *fb;
  110751. + int ret;
  110752. +
  110753. + fb = kzalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
  110754. + if (!fb) {
  110755. + dev_err(&dev->dev,
  110756. + "could not allocate new bcm2708_fb struct\n");
  110757. + ret = -ENOMEM;
  110758. + goto free_region;
  110759. + }
  110760. +
  110761. + bcm2708_fb_debugfs_init(fb);
  110762. +
  110763. + fb->cb_base = dma_alloc_writecombine(&dev->dev, SZ_64K,
  110764. + &fb->cb_handle, GFP_KERNEL);
  110765. + if (!fb->cb_base) {
  110766. + dev_err(&dev->dev, "cannot allocate DMA CBs\n");
  110767. + ret = -ENOMEM;
  110768. + goto free_fb;
  110769. + }
  110770. +
  110771. + pr_info("BCM2708FB: allocated DMA memory %08x\n",
  110772. + fb->cb_handle);
  110773. +
  110774. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
  110775. + &fb->dma_chan_base, &fb->dma_irq);
  110776. + if (ret < 0) {
  110777. + dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
  110778. + goto free_cb;
  110779. + }
  110780. + fb->dma_chan = ret;
  110781. +
  110782. + ret = request_irq(fb->dma_irq, bcm2708_fb_dma_irq,
  110783. + 0, "bcm2708_fb dma", fb);
  110784. + if (ret) {
  110785. + pr_err("%s: failed to request DMA irq\n", __func__);
  110786. + goto free_dma_chan;
  110787. + }
  110788. +
  110789. +
  110790. + pr_info("BCM2708FB: allocated DMA channel %d @ %p\n",
  110791. + fb->dma_chan, fb->dma_chan_base);
  110792. +
  110793. + fb->dev = dev;
  110794. +
  110795. + ret = bcm2708_fb_register(fb);
  110796. + if (ret == 0) {
  110797. + platform_set_drvdata(dev, fb);
  110798. + goto out;
  110799. + }
  110800. +
  110801. +free_dma_chan:
  110802. + bcm_dma_chan_free(fb->dma_chan);
  110803. +free_cb:
  110804. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  110805. +free_fb:
  110806. + kfree(fb);
  110807. +free_region:
  110808. + dev_err(&dev->dev, "probe failed, err %d\n", ret);
  110809. +out:
  110810. + return ret;
  110811. +}
  110812. +
  110813. +static int bcm2708_fb_remove(struct platform_device *dev)
  110814. +{
  110815. + struct bcm2708_fb *fb = platform_get_drvdata(dev);
  110816. +
  110817. + platform_set_drvdata(dev, NULL);
  110818. +
  110819. + if (fb->fb.screen_base)
  110820. + iounmap(fb->fb.screen_base);
  110821. + unregister_framebuffer(&fb->fb);
  110822. +
  110823. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  110824. + bcm_dma_chan_free(fb->dma_chan);
  110825. +
  110826. + dma_free_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), (void *)fb->info,
  110827. + fb->dma);
  110828. + bcm2708_fb_debugfs_deinit(fb);
  110829. +
  110830. + free_irq(fb->dma_irq, fb);
  110831. +
  110832. + kfree(fb);
  110833. +
  110834. + return 0;
  110835. +}
  110836. +
  110837. +static struct platform_driver bcm2708_fb_driver = {
  110838. + .probe = bcm2708_fb_probe,
  110839. + .remove = bcm2708_fb_remove,
  110840. + .driver = {
  110841. + .name = DRIVER_NAME,
  110842. + .owner = THIS_MODULE,
  110843. + },
  110844. +};
  110845. +
  110846. +static int __init bcm2708_fb_init(void)
  110847. +{
  110848. + return platform_driver_register(&bcm2708_fb_driver);
  110849. +}
  110850. +
  110851. +module_init(bcm2708_fb_init);
  110852. +
  110853. +static void __exit bcm2708_fb_exit(void)
  110854. +{
  110855. + platform_driver_unregister(&bcm2708_fb_driver);
  110856. +}
  110857. +
  110858. +module_exit(bcm2708_fb_exit);
  110859. +
  110860. +module_param(fbwidth, int, 0644);
  110861. +module_param(fbheight, int, 0644);
  110862. +module_param(fbdepth, int, 0644);
  110863. +module_param(fbswap, int, 0644);
  110864. +
  110865. +MODULE_DESCRIPTION("BCM2708 framebuffer driver");
  110866. +MODULE_LICENSE("GPL");
  110867. +
  110868. +MODULE_PARM_DESC(fbwidth, "Width of ARM Framebuffer");
  110869. +MODULE_PARM_DESC(fbheight, "Height of ARM Framebuffer");
  110870. +MODULE_PARM_DESC(fbdepth, "Bit depth of ARM Framebuffer");
  110871. +MODULE_PARM_DESC(fbswap, "Swap order of red and blue in 24 and 32 bit modes");
  110872. diff -Nur linux-3.18.6/drivers/video/fbdev/core/cfbimgblt.c linux-rpi/drivers/video/fbdev/core/cfbimgblt.c
  110873. --- linux-3.18.6/drivers/video/fbdev/core/cfbimgblt.c 2015-02-06 15:53:48.000000000 +0100
  110874. +++ linux-rpi/drivers/video/fbdev/core/cfbimgblt.c 2015-02-09 04:40:30.000000000 +0100
  110875. @@ -28,6 +28,11 @@
  110876. *
  110877. * Also need to add code to deal with cards endians that are different than
  110878. * the native cpu endians. I also need to deal with MSB position in the word.
  110879. + * Modified by Harm Hanemaaijer (fgenfb@yahoo.com) 2013:
  110880. + * - Provide optimized versions of fast_imageblit for 16 and 32bpp that are
  110881. + * significantly faster than the previous implementation.
  110882. + * - Simplify the fast/slow_imageblit selection code, avoiding integer
  110883. + * divides.
  110884. */
  110885. #include <linux/module.h>
  110886. #include <linux/string.h>
  110887. @@ -262,6 +267,133 @@
  110888. }
  110889. }
  110890. +/*
  110891. + * Optimized fast_imageblit for bpp == 16. ppw = 2, bit_mask = 3 folded
  110892. + * into the code, main loop unrolled.
  110893. + */
  110894. +
  110895. +static inline void fast_imageblit16(const struct fb_image *image,
  110896. + struct fb_info *p, u8 __iomem * dst1,
  110897. + u32 fgcolor, u32 bgcolor)
  110898. +{
  110899. + u32 fgx = fgcolor, bgx = bgcolor;
  110900. + u32 spitch = (image->width + 7) / 8;
  110901. + u32 end_mask, eorx;
  110902. + const char *s = image->data, *src;
  110903. + u32 __iomem *dst;
  110904. + const u32 *tab = NULL;
  110905. + int i, j, k;
  110906. +
  110907. + tab = fb_be_math(p) ? cfb_tab16_be : cfb_tab16_le;
  110908. +
  110909. + fgx <<= 16;
  110910. + bgx <<= 16;
  110911. + fgx |= fgcolor;
  110912. + bgx |= bgcolor;
  110913. +
  110914. + eorx = fgx ^ bgx;
  110915. + k = image->width / 2;
  110916. +
  110917. + for (i = image->height; i--;) {
  110918. + dst = (u32 __iomem *) dst1;
  110919. + src = s;
  110920. +
  110921. + j = k;
  110922. + while (j >= 4) {
  110923. + u8 bits = *src;
  110924. + end_mask = tab[(bits >> 6) & 3];
  110925. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  110926. + end_mask = tab[(bits >> 4) & 3];
  110927. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  110928. + end_mask = tab[(bits >> 2) & 3];
  110929. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  110930. + end_mask = tab[bits & 3];
  110931. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  110932. + src++;
  110933. + j -= 4;
  110934. + }
  110935. + if (j != 0) {
  110936. + u8 bits = *src;
  110937. + end_mask = tab[(bits >> 6) & 3];
  110938. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  110939. + if (j >= 2) {
  110940. + end_mask = tab[(bits >> 4) & 3];
  110941. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  110942. + if (j == 3) {
  110943. + end_mask = tab[(bits >> 2) & 3];
  110944. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  110945. + }
  110946. + }
  110947. + }
  110948. + dst1 += p->fix.line_length;
  110949. + s += spitch;
  110950. + }
  110951. +}
  110952. +
  110953. +/*
  110954. + * Optimized fast_imageblit for bpp == 32. ppw = 1, bit_mask = 1 folded
  110955. + * into the code, main loop unrolled.
  110956. + */
  110957. +
  110958. +static inline void fast_imageblit32(const struct fb_image *image,
  110959. + struct fb_info *p, u8 __iomem * dst1,
  110960. + u32 fgcolor, u32 bgcolor)
  110961. +{
  110962. + u32 fgx = fgcolor, bgx = bgcolor;
  110963. + u32 spitch = (image->width + 7) / 8;
  110964. + u32 end_mask, eorx;
  110965. + const char *s = image->data, *src;
  110966. + u32 __iomem *dst;
  110967. + const u32 *tab = NULL;
  110968. + int i, j, k;
  110969. +
  110970. + tab = cfb_tab32;
  110971. +
  110972. + eorx = fgx ^ bgx;
  110973. + k = image->width;
  110974. +
  110975. + for (i = image->height; i--;) {
  110976. + dst = (u32 __iomem *) dst1;
  110977. + src = s;
  110978. +
  110979. + j = k;
  110980. + while (j >= 8) {
  110981. + u8 bits = *src;
  110982. + end_mask = tab[(bits >> 7) & 1];
  110983. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  110984. + end_mask = tab[(bits >> 6) & 1];
  110985. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  110986. + end_mask = tab[(bits >> 5) & 1];
  110987. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  110988. + end_mask = tab[(bits >> 4) & 1];
  110989. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  110990. + end_mask = tab[(bits >> 3) & 1];
  110991. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  110992. + end_mask = tab[(bits >> 2) & 1];
  110993. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  110994. + end_mask = tab[(bits >> 1) & 1];
  110995. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  110996. + end_mask = tab[bits & 1];
  110997. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  110998. + src++;
  110999. + j -= 8;
  111000. + }
  111001. + if (j != 0) {
  111002. + u32 bits = (u32) * src;
  111003. + while (j > 1) {
  111004. + end_mask = tab[(bits >> 7) & 1];
  111005. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111006. + bits <<= 1;
  111007. + j--;
  111008. + }
  111009. + end_mask = tab[(bits >> 7) & 1];
  111010. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  111011. + }
  111012. + dst1 += p->fix.line_length;
  111013. + s += spitch;
  111014. + }
  111015. +}
  111016. +
  111017. void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
  111018. {
  111019. u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
  111020. @@ -294,11 +426,21 @@
  111021. bgcolor = image->bg_color;
  111022. }
  111023. - if (32 % bpp == 0 && !start_index && !pitch_index &&
  111024. - ((width & (32/bpp-1)) == 0) &&
  111025. - bpp >= 8 && bpp <= 32)
  111026. - fast_imageblit(image, p, dst1, fgcolor, bgcolor);
  111027. - else
  111028. + if (!start_index && !pitch_index) {
  111029. + if (bpp == 32)
  111030. + fast_imageblit32(image, p, dst1, fgcolor,
  111031. + bgcolor);
  111032. + else if (bpp == 16 && (width & 1) == 0)
  111033. + fast_imageblit16(image, p, dst1, fgcolor,
  111034. + bgcolor);
  111035. + else if (bpp == 8 && (width & 3) == 0)
  111036. + fast_imageblit(image, p, dst1, fgcolor,
  111037. + bgcolor);
  111038. + else
  111039. + slow_imageblit(image, p, dst1, fgcolor,
  111040. + bgcolor,
  111041. + start_index, pitch_index);
  111042. + } else
  111043. slow_imageblit(image, p, dst1, fgcolor, bgcolor,
  111044. start_index, pitch_index);
  111045. } else
  111046. diff -Nur linux-3.18.6/drivers/video/fbdev/core/fbmem.c linux-rpi/drivers/video/fbdev/core/fbmem.c
  111047. --- linux-3.18.6/drivers/video/fbdev/core/fbmem.c 2015-02-06 15:53:48.000000000 +0100
  111048. +++ linux-rpi/drivers/video/fbdev/core/fbmem.c 2015-02-09 04:40:30.000000000 +0100
  111049. @@ -1084,6 +1084,25 @@
  111050. }
  111051. EXPORT_SYMBOL(fb_blank);
  111052. +static int fb_copyarea_user(struct fb_info *info,
  111053. + struct fb_copyarea *copy)
  111054. +{
  111055. + int ret = 0;
  111056. + if (!lock_fb_info(info))
  111057. + return -ENODEV;
  111058. + if (copy->dx + copy->width > info->var.xres ||
  111059. + copy->sx + copy->width > info->var.xres ||
  111060. + copy->dy + copy->height > info->var.yres ||
  111061. + copy->sy + copy->height > info->var.yres) {
  111062. + ret = -EINVAL;
  111063. + goto out;
  111064. + }
  111065. + info->fbops->fb_copyarea(info, copy);
  111066. +out:
  111067. + unlock_fb_info(info);
  111068. + return ret;
  111069. +}
  111070. +
  111071. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  111072. unsigned long arg)
  111073. {
  111074. @@ -1094,6 +1113,7 @@
  111075. struct fb_cmap cmap_from;
  111076. struct fb_cmap_user cmap;
  111077. struct fb_event event;
  111078. + struct fb_copyarea copy;
  111079. void __user *argp = (void __user *)arg;
  111080. long ret = 0;
  111081. @@ -1211,6 +1231,15 @@
  111082. unlock_fb_info(info);
  111083. console_unlock();
  111084. break;
  111085. + case FBIOCOPYAREA:
  111086. + if (info->flags & FBINFO_HWACCEL_COPYAREA) {
  111087. + /* only provide this ioctl if it is accelerated */
  111088. + if (copy_from_user(&copy, argp, sizeof(copy)))
  111089. + return -EFAULT;
  111090. + ret = fb_copyarea_user(info, &copy);
  111091. + break;
  111092. + }
  111093. + /* fall through */
  111094. default:
  111095. if (!lock_fb_info(info))
  111096. return -ENODEV;
  111097. @@ -1365,6 +1394,7 @@
  111098. case FBIOPAN_DISPLAY:
  111099. case FBIOGET_CON2FBMAP:
  111100. case FBIOPUT_CON2FBMAP:
  111101. + case FBIOCOPYAREA:
  111102. arg = (unsigned long) compat_ptr(arg);
  111103. case FBIOBLANK:
  111104. ret = do_fb_ioctl(info, cmd, arg);
  111105. diff -Nur linux-3.18.6/drivers/video/fbdev/Kconfig linux-rpi/drivers/video/fbdev/Kconfig
  111106. --- linux-3.18.6/drivers/video/fbdev/Kconfig 2015-02-06 15:53:48.000000000 +0100
  111107. +++ linux-rpi/drivers/video/fbdev/Kconfig 2015-02-09 04:40:30.000000000 +0100
  111108. @@ -224,6 +224,20 @@
  111109. comment "Frame buffer hardware drivers"
  111110. depends on FB
  111111. +config FB_BCM2708
  111112. + tristate "BCM2708 framebuffer support"
  111113. + depends on FB && ARM
  111114. + select FB_CFB_FILLRECT
  111115. + select FB_CFB_COPYAREA
  111116. + select FB_CFB_IMAGEBLIT
  111117. + help
  111118. + This framebuffer device driver is for the BCM2708 framebuffer.
  111119. +
  111120. + If you want to compile this as a module (=code which can be
  111121. + inserted into and removed from the running kernel), say M
  111122. + here and read <file:Documentation/kbuild/modules.txt>. The module
  111123. + will be called bcm2708_fb.
  111124. +
  111125. config FB_GRVGA
  111126. tristate "Aeroflex Gaisler framebuffer support"
  111127. depends on FB && SPARC
  111128. diff -Nur linux-3.18.6/drivers/video/fbdev/Makefile linux-rpi/drivers/video/fbdev/Makefile
  111129. --- linux-3.18.6/drivers/video/fbdev/Makefile 2015-02-06 15:53:48.000000000 +0100
  111130. +++ linux-rpi/drivers/video/fbdev/Makefile 2015-02-09 04:40:30.000000000 +0100
  111131. @@ -12,6 +12,7 @@
  111132. obj-$(CONFIG_FB_WMT_GE_ROPS) += wmt_ge_rops.o
  111133. # Hardware specific drivers go first
  111134. +obj-$(CONFIG_FB_BCM2708) += bcm2708_fb.o
  111135. obj-$(CONFIG_FB_AMIGA) += amifb.o c2p_planar.o
  111136. obj-$(CONFIG_FB_ARC) += arcfb.o
  111137. obj-$(CONFIG_FB_CLPS711X) += clps711x-fb.o
  111138. diff -Nur linux-3.18.6/drivers/video/logo/logo_linux_clut224.ppm linux-rpi/drivers/video/logo/logo_linux_clut224.ppm
  111139. --- linux-3.18.6/drivers/video/logo/logo_linux_clut224.ppm 2015-02-06 15:53:48.000000000 +0100
  111140. +++ linux-rpi/drivers/video/logo/logo_linux_clut224.ppm 2015-02-09 04:40:31.000000000 +0100
  111141. @@ -1,1604 +1,883 @@
  111142. P3
  111143. -# Standard 224-color Linux logo
  111144. -80 80
  111145. +63 80
  111146. 255
  111147. - 0 0 0 0 0 0 0 0 0 0 0 0
  111148. - 0 0 0 0 0 0 0 0 0 0 0 0
  111149. - 0 0 0 0 0 0 0 0 0 0 0 0
  111150. - 0 0 0 0 0 0 0 0 0 0 0 0
  111151. - 0 0 0 0 0 0 0 0 0 0 0 0
  111152. - 0 0 0 0 0 0 0 0 0 0 0 0
  111153. - 0 0 0 0 0 0 0 0 0 0 0 0
  111154. - 0 0 0 0 0 0 0 0 0 0 0 0
  111155. - 0 0 0 0 0 0 0 0 0 0 0 0
  111156. - 6 6 6 6 6 6 10 10 10 10 10 10
  111157. - 10 10 10 6 6 6 6 6 6 6 6 6
  111158. - 0 0 0 0 0 0 0 0 0 0 0 0
  111159. - 0 0 0 0 0 0 0 0 0 0 0 0
  111160. - 0 0 0 0 0 0 0 0 0 0 0 0
  111161. - 0 0 0 0 0 0 0 0 0 0 0 0
  111162. - 0 0 0 0 0 0 0 0 0 0 0 0
  111163. - 0 0 0 0 0 0 0 0 0 0 0 0
  111164. - 0 0 0 0 0 0 0 0 0 0 0 0
  111165. - 0 0 0 0 0 0 0 0 0 0 0 0
  111166. - 0 0 0 0 0 0 0 0 0 0 0 0
  111167. - 0 0 0 0 0 0 0 0 0 0 0 0
  111168. - 0 0 0 0 0 0 0 0 0 0 0 0
  111169. - 0 0 0 0 0 0 0 0 0 0 0 0
  111170. - 0 0 0 0 0 0 0 0 0 0 0 0
  111171. - 0 0 0 0 0 0 0 0 0 0 0 0
  111172. - 0 0 0 0 0 0 0 0 0 0 0 0
  111173. - 0 0 0 0 0 0 0 0 0 0 0 0
  111174. - 0 0 0 0 0 0 0 0 0 0 0 0
  111175. - 0 0 0 6 6 6 10 10 10 14 14 14
  111176. - 22 22 22 26 26 26 30 30 30 34 34 34
  111177. - 30 30 30 30 30 30 26 26 26 18 18 18
  111178. - 14 14 14 10 10 10 6 6 6 0 0 0
  111179. - 0 0 0 0 0 0 0 0 0 0 0 0
  111180. - 0 0 0 0 0 0 0 0 0 0 0 0
  111181. - 0 0 0 0 0 0 0 0 0 0 0 0
  111182. - 0 0 0 0 0 0 0 0 0 0 0 0
  111183. - 0 0 0 0 0 0 0 0 0 0 0 0
  111184. - 0 0 0 0 0 0 0 0 0 0 0 0
  111185. - 0 0 0 0 0 0 0 0 0 0 0 0
  111186. - 0 0 0 0 0 0 0 0 0 0 0 0
  111187. - 0 0 0 0 0 0 0 0 0 0 0 0
  111188. - 0 0 0 0 0 1 0 0 1 0 0 0
  111189. - 0 0 0 0 0 0 0 0 0 0 0 0
  111190. - 0 0 0 0 0 0 0 0 0 0 0 0
  111191. - 0 0 0 0 0 0 0 0 0 0 0 0
  111192. - 0 0 0 0 0 0 0 0 0 0 0 0
  111193. - 0 0 0 0 0 0 0 0 0 0 0 0
  111194. - 0 0 0 0 0 0 0 0 0 0 0 0
  111195. - 6 6 6 14 14 14 26 26 26 42 42 42
  111196. - 54 54 54 66 66 66 78 78 78 78 78 78
  111197. - 78 78 78 74 74 74 66 66 66 54 54 54
  111198. - 42 42 42 26 26 26 18 18 18 10 10 10
  111199. - 6 6 6 0 0 0 0 0 0 0 0 0
  111200. - 0 0 0 0 0 0 0 0 0 0 0 0
  111201. - 0 0 0 0 0 0 0 0 0 0 0 0
  111202. - 0 0 0 0 0 0 0 0 0 0 0 0
  111203. - 0 0 0 0 0 0 0 0 0 0 0 0
  111204. - 0 0 0 0 0 0 0 0 0 0 0 0
  111205. - 0 0 0 0 0 0 0 0 0 0 0 0
  111206. - 0 0 0 0 0 0 0 0 0 0 0 0
  111207. - 0 0 0 0 0 0 0 0 0 0 0 0
  111208. - 0 0 1 0 0 0 0 0 0 0 0 0
  111209. - 0 0 0 0 0 0 0 0 0 0 0 0
  111210. - 0 0 0 0 0 0 0 0 0 0 0 0
  111211. - 0 0 0 0 0 0 0 0 0 0 0 0
  111212. - 0 0 0 0 0 0 0 0 0 0 0 0
  111213. - 0 0 0 0 0 0 0 0 0 0 0 0
  111214. - 0 0 0 0 0 0 0 0 0 10 10 10
  111215. - 22 22 22 42 42 42 66 66 66 86 86 86
  111216. - 66 66 66 38 38 38 38 38 38 22 22 22
  111217. - 26 26 26 34 34 34 54 54 54 66 66 66
  111218. - 86 86 86 70 70 70 46 46 46 26 26 26
  111219. - 14 14 14 6 6 6 0 0 0 0 0 0
  111220. - 0 0 0 0 0 0 0 0 0 0 0 0
  111221. - 0 0 0 0 0 0 0 0 0 0 0 0
  111222. - 0 0 0 0 0 0 0 0 0 0 0 0
  111223. - 0 0 0 0 0 0 0 0 0 0 0 0
  111224. - 0 0 0 0 0 0 0 0 0 0 0 0
  111225. - 0 0 0 0 0 0 0 0 0 0 0 0
  111226. - 0 0 0 0 0 0 0 0 0 0 0 0
  111227. - 0 0 0 0 0 0 0 0 0 0 0 0
  111228. - 0 0 1 0 0 1 0 0 1 0 0 0
  111229. - 0 0 0 0 0 0 0 0 0 0 0 0
  111230. - 0 0 0 0 0 0 0 0 0 0 0 0
  111231. - 0 0 0 0 0 0 0 0 0 0 0 0
  111232. - 0 0 0 0 0 0 0 0 0 0 0 0
  111233. - 0 0 0 0 0 0 0 0 0 0 0 0
  111234. - 0 0 0 0 0 0 10 10 10 26 26 26
  111235. - 50 50 50 82 82 82 58 58 58 6 6 6
  111236. - 2 2 6 2 2 6 2 2 6 2 2 6
  111237. - 2 2 6 2 2 6 2 2 6 2 2 6
  111238. - 6 6 6 54 54 54 86 86 86 66 66 66
  111239. - 38 38 38 18 18 18 6 6 6 0 0 0
  111240. - 0 0 0 0 0 0 0 0 0 0 0 0
  111241. - 0 0 0 0 0 0 0 0 0 0 0 0
  111242. - 0 0 0 0 0 0 0 0 0 0 0 0
  111243. - 0 0 0 0 0 0 0 0 0 0 0 0
  111244. - 0 0 0 0 0 0 0 0 0 0 0 0
  111245. - 0 0 0 0 0 0 0 0 0 0 0 0
  111246. - 0 0 0 0 0 0 0 0 0 0 0 0
  111247. - 0 0 0 0 0 0 0 0 0 0 0 0
  111248. - 0 0 0 0 0 0 0 0 0 0 0 0
  111249. - 0 0 0 0 0 0 0 0 0 0 0 0
  111250. - 0 0 0 0 0 0 0 0 0 0 0 0
  111251. - 0 0 0 0 0 0 0 0 0 0 0 0
  111252. - 0 0 0 0 0 0 0 0 0 0 0 0
  111253. - 0 0 0 0 0 0 0 0 0 0 0 0
  111254. - 0 0 0 6 6 6 22 22 22 50 50 50
  111255. - 78 78 78 34 34 34 2 2 6 2 2 6
  111256. - 2 2 6 2 2 6 2 2 6 2 2 6
  111257. - 2 2 6 2 2 6 2 2 6 2 2 6
  111258. - 2 2 6 2 2 6 6 6 6 70 70 70
  111259. - 78 78 78 46 46 46 22 22 22 6 6 6
  111260. - 0 0 0 0 0 0 0 0 0 0 0 0
  111261. - 0 0 0 0 0 0 0 0 0 0 0 0
  111262. - 0 0 0 0 0 0 0 0 0 0 0 0
  111263. - 0 0 0 0 0 0 0 0 0 0 0 0
  111264. - 0 0 0 0 0 0 0 0 0 0 0 0
  111265. - 0 0 0 0 0 0 0 0 0 0 0 0
  111266. - 0 0 0 0 0 0 0 0 0 0 0 0
  111267. - 0 0 0 0 0 0 0 0 0 0 0 0
  111268. - 0 0 1 0 0 1 0 0 1 0 0 0
  111269. - 0 0 0 0 0 0 0 0 0 0 0 0
  111270. - 0 0 0 0 0 0 0 0 0 0 0 0
  111271. - 0 0 0 0 0 0 0 0 0 0 0 0
  111272. - 0 0 0 0 0 0 0 0 0 0 0 0
  111273. - 0 0 0 0 0 0 0 0 0 0 0 0
  111274. - 6 6 6 18 18 18 42 42 42 82 82 82
  111275. - 26 26 26 2 2 6 2 2 6 2 2 6
  111276. - 2 2 6 2 2 6 2 2 6 2 2 6
  111277. - 2 2 6 2 2 6 2 2 6 14 14 14
  111278. - 46 46 46 34 34 34 6 6 6 2 2 6
  111279. - 42 42 42 78 78 78 42 42 42 18 18 18
  111280. - 6 6 6 0 0 0 0 0 0 0 0 0
  111281. - 0 0 0 0 0 0 0 0 0 0 0 0
  111282. - 0 0 0 0 0 0 0 0 0 0 0 0
  111283. - 0 0 0 0 0 0 0 0 0 0 0 0
  111284. - 0 0 0 0 0 0 0 0 0 0 0 0
  111285. - 0 0 0 0 0 0 0 0 0 0 0 0
  111286. - 0 0 0 0 0 0 0 0 0 0 0 0
  111287. - 0 0 0 0 0 0 0 0 0 0 0 0
  111288. - 0 0 1 0 0 0 0 0 1 0 0 0
  111289. - 0 0 0 0 0 0 0 0 0 0 0 0
  111290. - 0 0 0 0 0 0 0 0 0 0 0 0
  111291. - 0 0 0 0 0 0 0 0 0 0 0 0
  111292. - 0 0 0 0 0 0 0 0 0 0 0 0
  111293. - 0 0 0 0 0 0 0 0 0 0 0 0
  111294. - 10 10 10 30 30 30 66 66 66 58 58 58
  111295. - 2 2 6 2 2 6 2 2 6 2 2 6
  111296. - 2 2 6 2 2 6 2 2 6 2 2 6
  111297. - 2 2 6 2 2 6 2 2 6 26 26 26
  111298. - 86 86 86 101 101 101 46 46 46 10 10 10
  111299. - 2 2 6 58 58 58 70 70 70 34 34 34
  111300. - 10 10 10 0 0 0 0 0 0 0 0 0
  111301. - 0 0 0 0 0 0 0 0 0 0 0 0
  111302. - 0 0 0 0 0 0 0 0 0 0 0 0
  111303. - 0 0 0 0 0 0 0 0 0 0 0 0
  111304. - 0 0 0 0 0 0 0 0 0 0 0 0
  111305. - 0 0 0 0 0 0 0 0 0 0 0 0
  111306. - 0 0 0 0 0 0 0 0 0 0 0 0
  111307. - 0 0 0 0 0 0 0 0 0 0 0 0
  111308. - 0 0 1 0 0 1 0 0 1 0 0 0
  111309. - 0 0 0 0 0 0 0 0 0 0 0 0
  111310. - 0 0 0 0 0 0 0 0 0 0 0 0
  111311. - 0 0 0 0 0 0 0 0 0 0 0 0
  111312. - 0 0 0 0 0 0 0 0 0 0 0 0
  111313. - 0 0 0 0 0 0 0 0 0 0 0 0
  111314. - 14 14 14 42 42 42 86 86 86 10 10 10
  111315. - 2 2 6 2 2 6 2 2 6 2 2 6
  111316. - 2 2 6 2 2 6 2 2 6 2 2 6
  111317. - 2 2 6 2 2 6 2 2 6 30 30 30
  111318. - 94 94 94 94 94 94 58 58 58 26 26 26
  111319. - 2 2 6 6 6 6 78 78 78 54 54 54
  111320. - 22 22 22 6 6 6 0 0 0 0 0 0
  111321. - 0 0 0 0 0 0 0 0 0 0 0 0
  111322. - 0 0 0 0 0 0 0 0 0 0 0 0
  111323. - 0 0 0 0 0 0 0 0 0 0 0 0
  111324. - 0 0 0 0 0 0 0 0 0 0 0 0
  111325. - 0 0 0 0 0 0 0 0 0 0 0 0
  111326. - 0 0 0 0 0 0 0 0 0 0 0 0
  111327. - 0 0 0 0 0 0 0 0 0 0 0 0
  111328. - 0 0 0 0 0 0 0 0 0 0 0 0
  111329. - 0 0 0 0 0 0 0 0 0 0 0 0
  111330. - 0 0 0 0 0 0 0 0 0 0 0 0
  111331. - 0 0 0 0 0 0 0 0 0 0 0 0
  111332. - 0 0 0 0 0 0 0 0 0 0 0 0
  111333. - 0 0 0 0 0 0 0 0 0 6 6 6
  111334. - 22 22 22 62 62 62 62 62 62 2 2 6
  111335. - 2 2 6 2 2 6 2 2 6 2 2 6
  111336. - 2 2 6 2 2 6 2 2 6 2 2 6
  111337. - 2 2 6 2 2 6 2 2 6 26 26 26
  111338. - 54 54 54 38 38 38 18 18 18 10 10 10
  111339. - 2 2 6 2 2 6 34 34 34 82 82 82
  111340. - 38 38 38 14 14 14 0 0 0 0 0 0
  111341. - 0 0 0 0 0 0 0 0 0 0 0 0
  111342. - 0 0 0 0 0 0 0 0 0 0 0 0
  111343. - 0 0 0 0 0 0 0 0 0 0 0 0
  111344. - 0 0 0 0 0 0 0 0 0 0 0 0
  111345. - 0 0 0 0 0 0 0 0 0 0 0 0
  111346. - 0 0 0 0 0 0 0 0 0 0 0 0
  111347. - 0 0 0 0 0 0 0 0 0 0 0 0
  111348. - 0 0 0 0 0 1 0 0 1 0 0 0
  111349. - 0 0 0 0 0 0 0 0 0 0 0 0
  111350. - 0 0 0 0 0 0 0 0 0 0 0 0
  111351. - 0 0 0 0 0 0 0 0 0 0 0 0
  111352. - 0 0 0 0 0 0 0 0 0 0 0 0
  111353. - 0 0 0 0 0 0 0 0 0 6 6 6
  111354. - 30 30 30 78 78 78 30 30 30 2 2 6
  111355. - 2 2 6 2 2 6 2 2 6 2 2 6
  111356. - 2 2 6 2 2 6 2 2 6 2 2 6
  111357. - 2 2 6 2 2 6 2 2 6 10 10 10
  111358. - 10 10 10 2 2 6 2 2 6 2 2 6
  111359. - 2 2 6 2 2 6 2 2 6 78 78 78
  111360. - 50 50 50 18 18 18 6 6 6 0 0 0
  111361. - 0 0 0 0 0 0 0 0 0 0 0 0
  111362. - 0 0 0 0 0 0 0 0 0 0 0 0
  111363. - 0 0 0 0 0 0 0 0 0 0 0 0
  111364. - 0 0 0 0 0 0 0 0 0 0 0 0
  111365. - 0 0 0 0 0 0 0 0 0 0 0 0
  111366. - 0 0 0 0 0 0 0 0 0 0 0 0
  111367. - 0 0 0 0 0 0 0 0 0 0 0 0
  111368. - 0 0 1 0 0 0 0 0 0 0 0 0
  111369. - 0 0 0 0 0 0 0 0 0 0 0 0
  111370. - 0 0 0 0 0 0 0 0 0 0 0 0
  111371. - 0 0 0 0 0 0 0 0 0 0 0 0
  111372. - 0 0 0 0 0 0 0 0 0 0 0 0
  111373. - 0 0 0 0 0 0 0 0 0 10 10 10
  111374. - 38 38 38 86 86 86 14 14 14 2 2 6
  111375. - 2 2 6 2 2 6 2 2 6 2 2 6
  111376. - 2 2 6 2 2 6 2 2 6 2 2 6
  111377. - 2 2 6 2 2 6 2 2 6 2 2 6
  111378. - 2 2 6 2 2 6 2 2 6 2 2 6
  111379. - 2 2 6 2 2 6 2 2 6 54 54 54
  111380. - 66 66 66 26 26 26 6 6 6 0 0 0
  111381. - 0 0 0 0 0 0 0 0 0 0 0 0
  111382. - 0 0 0 0 0 0 0 0 0 0 0 0
  111383. - 0 0 0 0 0 0 0 0 0 0 0 0
  111384. - 0 0 0 0 0 0 0 0 0 0 0 0
  111385. - 0 0 0 0 0 0 0 0 0 0 0 0
  111386. - 0 0 0 0 0 0 0 0 0 0 0 0
  111387. - 0 0 0 0 0 0 0 0 0 0 0 0
  111388. - 0 0 0 0 0 1 0 0 1 0 0 0
  111389. - 0 0 0 0 0 0 0 0 0 0 0 0
  111390. - 0 0 0 0 0 0 0 0 0 0 0 0
  111391. - 0 0 0 0 0 0 0 0 0 0 0 0
  111392. - 0 0 0 0 0 0 0 0 0 0 0 0
  111393. - 0 0 0 0 0 0 0 0 0 14 14 14
  111394. - 42 42 42 82 82 82 2 2 6 2 2 6
  111395. - 2 2 6 6 6 6 10 10 10 2 2 6
  111396. - 2 2 6 2 2 6 2 2 6 2 2 6
  111397. - 2 2 6 2 2 6 2 2 6 6 6 6
  111398. - 14 14 14 10 10 10 2 2 6 2 2 6
  111399. - 2 2 6 2 2 6 2 2 6 18 18 18
  111400. - 82 82 82 34 34 34 10 10 10 0 0 0
  111401. - 0 0 0 0 0 0 0 0 0 0 0 0
  111402. - 0 0 0 0 0 0 0 0 0 0 0 0
  111403. - 0 0 0 0 0 0 0 0 0 0 0 0
  111404. - 0 0 0 0 0 0 0 0 0 0 0 0
  111405. - 0 0 0 0 0 0 0 0 0 0 0 0
  111406. - 0 0 0 0 0 0 0 0 0 0 0 0
  111407. - 0 0 0 0 0 0 0 0 0 0 0 0
  111408. - 0 0 1 0 0 0 0 0 0 0 0 0
  111409. - 0 0 0 0 0 0 0 0 0 0 0 0
  111410. - 0 0 0 0 0 0 0 0 0 0 0 0
  111411. - 0 0 0 0 0 0 0 0 0 0 0 0
  111412. - 0 0 0 0 0 0 0 0 0 0 0 0
  111413. - 0 0 0 0 0 0 0 0 0 14 14 14
  111414. - 46 46 46 86 86 86 2 2 6 2 2 6
  111415. - 6 6 6 6 6 6 22 22 22 34 34 34
  111416. - 6 6 6 2 2 6 2 2 6 2 2 6
  111417. - 2 2 6 2 2 6 18 18 18 34 34 34
  111418. - 10 10 10 50 50 50 22 22 22 2 2 6
  111419. - 2 2 6 2 2 6 2 2 6 10 10 10
  111420. - 86 86 86 42 42 42 14 14 14 0 0 0
  111421. - 0 0 0 0 0 0 0 0 0 0 0 0
  111422. - 0 0 0 0 0 0 0 0 0 0 0 0
  111423. - 0 0 0 0 0 0 0 0 0 0 0 0
  111424. - 0 0 0 0 0 0 0 0 0 0 0 0
  111425. - 0 0 0 0 0 0 0 0 0 0 0 0
  111426. - 0 0 0 0 0 0 0 0 0 0 0 0
  111427. - 0 0 0 0 0 0 0 0 0 0 0 0
  111428. - 0 0 1 0 0 1 0 0 1 0 0 0
  111429. - 0 0 0 0 0 0 0 0 0 0 0 0
  111430. - 0 0 0 0 0 0 0 0 0 0 0 0
  111431. - 0 0 0 0 0 0 0 0 0 0 0 0
  111432. - 0 0 0 0 0 0 0 0 0 0 0 0
  111433. - 0 0 0 0 0 0 0 0 0 14 14 14
  111434. - 46 46 46 86 86 86 2 2 6 2 2 6
  111435. - 38 38 38 116 116 116 94 94 94 22 22 22
  111436. - 22 22 22 2 2 6 2 2 6 2 2 6
  111437. - 14 14 14 86 86 86 138 138 138 162 162 162
  111438. -154 154 154 38 38 38 26 26 26 6 6 6
  111439. - 2 2 6 2 2 6 2 2 6 2 2 6
  111440. - 86 86 86 46 46 46 14 14 14 0 0 0
  111441. - 0 0 0 0 0 0 0 0 0 0 0 0
  111442. - 0 0 0 0 0 0 0 0 0 0 0 0
  111443. - 0 0 0 0 0 0 0 0 0 0 0 0
  111444. - 0 0 0 0 0 0 0 0 0 0 0 0
  111445. - 0 0 0 0 0 0 0 0 0 0 0 0
  111446. - 0 0 0 0 0 0 0 0 0 0 0 0
  111447. - 0 0 0 0 0 0 0 0 0 0 0 0
  111448. - 0 0 0 0 0 0 0 0 0 0 0 0
  111449. - 0 0 0 0 0 0 0 0 0 0 0 0
  111450. - 0 0 0 0 0 0 0 0 0 0 0 0
  111451. - 0 0 0 0 0 0 0 0 0 0 0 0
  111452. - 0 0 0 0 0 0 0 0 0 0 0 0
  111453. - 0 0 0 0 0 0 0 0 0 14 14 14
  111454. - 46 46 46 86 86 86 2 2 6 14 14 14
  111455. -134 134 134 198 198 198 195 195 195 116 116 116
  111456. - 10 10 10 2 2 6 2 2 6 6 6 6
  111457. -101 98 89 187 187 187 210 210 210 218 218 218
  111458. -214 214 214 134 134 134 14 14 14 6 6 6
  111459. - 2 2 6 2 2 6 2 2 6 2 2 6
  111460. - 86 86 86 50 50 50 18 18 18 6 6 6
  111461. - 0 0 0 0 0 0 0 0 0 0 0 0
  111462. - 0 0 0 0 0 0 0 0 0 0 0 0
  111463. - 0 0 0 0 0 0 0 0 0 0 0 0
  111464. - 0 0 0 0 0 0 0 0 0 0 0 0
  111465. - 0 0 0 0 0 0 0 0 0 0 0 0
  111466. - 0 0 0 0 0 0 0 0 0 0 0 0
  111467. - 0 0 0 0 0 0 0 0 1 0 0 0
  111468. - 0 0 1 0 0 1 0 0 1 0 0 0
  111469. - 0 0 0 0 0 0 0 0 0 0 0 0
  111470. - 0 0 0 0 0 0 0 0 0 0 0 0
  111471. - 0 0 0 0 0 0 0 0 0 0 0 0
  111472. - 0 0 0 0 0 0 0 0 0 0 0 0
  111473. - 0 0 0 0 0 0 0 0 0 14 14 14
  111474. - 46 46 46 86 86 86 2 2 6 54 54 54
  111475. -218 218 218 195 195 195 226 226 226 246 246 246
  111476. - 58 58 58 2 2 6 2 2 6 30 30 30
  111477. -210 210 210 253 253 253 174 174 174 123 123 123
  111478. -221 221 221 234 234 234 74 74 74 2 2 6
  111479. - 2 2 6 2 2 6 2 2 6 2 2 6
  111480. - 70 70 70 58 58 58 22 22 22 6 6 6
  111481. - 0 0 0 0 0 0 0 0 0 0 0 0
  111482. - 0 0 0 0 0 0 0 0 0 0 0 0
  111483. - 0 0 0 0 0 0 0 0 0 0 0 0
  111484. - 0 0 0 0 0 0 0 0 0 0 0 0
  111485. - 0 0 0 0 0 0 0 0 0 0 0 0
  111486. - 0 0 0 0 0 0 0 0 0 0 0 0
  111487. - 0 0 0 0 0 0 0 0 0 0 0 0
  111488. - 0 0 0 0 0 0 0 0 0 0 0 0
  111489. - 0 0 0 0 0 0 0 0 0 0 0 0
  111490. - 0 0 0 0 0 0 0 0 0 0 0 0
  111491. - 0 0 0 0 0 0 0 0 0 0 0 0
  111492. - 0 0 0 0 0 0 0 0 0 0 0 0
  111493. - 0 0 0 0 0 0 0 0 0 14 14 14
  111494. - 46 46 46 82 82 82 2 2 6 106 106 106
  111495. -170 170 170 26 26 26 86 86 86 226 226 226
  111496. -123 123 123 10 10 10 14 14 14 46 46 46
  111497. -231 231 231 190 190 190 6 6 6 70 70 70
  111498. - 90 90 90 238 238 238 158 158 158 2 2 6
  111499. - 2 2 6 2 2 6 2 2 6 2 2 6
  111500. - 70 70 70 58 58 58 22 22 22 6 6 6
  111501. - 0 0 0 0 0 0 0 0 0 0 0 0
  111502. - 0 0 0 0 0 0 0 0 0 0 0 0
  111503. - 0 0 0 0 0 0 0 0 0 0 0 0
  111504. - 0 0 0 0 0 0 0 0 0 0 0 0
  111505. - 0 0 0 0 0 0 0 0 0 0 0 0
  111506. - 0 0 0 0 0 0 0 0 0 0 0 0
  111507. - 0 0 0 0 0 0 0 0 1 0 0 0
  111508. - 0 0 1 0 0 1 0 0 1 0 0 0
  111509. - 0 0 0 0 0 0 0 0 0 0 0 0
  111510. - 0 0 0 0 0 0 0 0 0 0 0 0
  111511. - 0 0 0 0 0 0 0 0 0 0 0 0
  111512. - 0 0 0 0 0 0 0 0 0 0 0 0
  111513. - 0 0 0 0 0 0 0 0 0 14 14 14
  111514. - 42 42 42 86 86 86 6 6 6 116 116 116
  111515. -106 106 106 6 6 6 70 70 70 149 149 149
  111516. -128 128 128 18 18 18 38 38 38 54 54 54
  111517. -221 221 221 106 106 106 2 2 6 14 14 14
  111518. - 46 46 46 190 190 190 198 198 198 2 2 6
  111519. - 2 2 6 2 2 6 2 2 6 2 2 6
  111520. - 74 74 74 62 62 62 22 22 22 6 6 6
  111521. - 0 0 0 0 0 0 0 0 0 0 0 0
  111522. - 0 0 0 0 0 0 0 0 0 0 0 0
  111523. - 0 0 0 0 0 0 0 0 0 0 0 0
  111524. - 0 0 0 0 0 0 0 0 0 0 0 0
  111525. - 0 0 0 0 0 0 0 0 0 0 0 0
  111526. - 0 0 0 0 0 0 0 0 0 0 0 0
  111527. - 0 0 0 0 0 0 0 0 1 0 0 0
  111528. - 0 0 1 0 0 0 0 0 1 0 0 0
  111529. - 0 0 0 0 0 0 0 0 0 0 0 0
  111530. - 0 0 0 0 0 0 0 0 0 0 0 0
  111531. - 0 0 0 0 0 0 0 0 0 0 0 0
  111532. - 0 0 0 0 0 0 0 0 0 0 0 0
  111533. - 0 0 0 0 0 0 0 0 0 14 14 14
  111534. - 42 42 42 94 94 94 14 14 14 101 101 101
  111535. -128 128 128 2 2 6 18 18 18 116 116 116
  111536. -118 98 46 121 92 8 121 92 8 98 78 10
  111537. -162 162 162 106 106 106 2 2 6 2 2 6
  111538. - 2 2 6 195 195 195 195 195 195 6 6 6
  111539. - 2 2 6 2 2 6 2 2 6 2 2 6
  111540. - 74 74 74 62 62 62 22 22 22 6 6 6
  111541. - 0 0 0 0 0 0 0 0 0 0 0 0
  111542. - 0 0 0 0 0 0 0 0 0 0 0 0
  111543. - 0 0 0 0 0 0 0 0 0 0 0 0
  111544. - 0 0 0 0 0 0 0 0 0 0 0 0
  111545. - 0 0 0 0 0 0 0 0 0 0 0 0
  111546. - 0 0 0 0 0 0 0 0 0 0 0 0
  111547. - 0 0 0 0 0 0 0 0 1 0 0 1
  111548. - 0 0 1 0 0 0 0 0 1 0 0 0
  111549. - 0 0 0 0 0 0 0 0 0 0 0 0
  111550. - 0 0 0 0 0 0 0 0 0 0 0 0
  111551. - 0 0 0 0 0 0 0 0 0 0 0 0
  111552. - 0 0 0 0 0 0 0 0 0 0 0 0
  111553. - 0 0 0 0 0 0 0 0 0 10 10 10
  111554. - 38 38 38 90 90 90 14 14 14 58 58 58
  111555. -210 210 210 26 26 26 54 38 6 154 114 10
  111556. -226 170 11 236 186 11 225 175 15 184 144 12
  111557. -215 174 15 175 146 61 37 26 9 2 2 6
  111558. - 70 70 70 246 246 246 138 138 138 2 2 6
  111559. - 2 2 6 2 2 6 2 2 6 2 2 6
  111560. - 70 70 70 66 66 66 26 26 26 6 6 6
  111561. - 0 0 0 0 0 0 0 0 0 0 0 0
  111562. - 0 0 0 0 0 0 0 0 0 0 0 0
  111563. - 0 0 0 0 0 0 0 0 0 0 0 0
  111564. - 0 0 0 0 0 0 0 0 0 0 0 0
  111565. - 0 0 0 0 0 0 0 0 0 0 0 0
  111566. - 0 0 0 0 0 0 0 0 0 0 0 0
  111567. - 0 0 0 0 0 0 0 0 0 0 0 0
  111568. - 0 0 0 0 0 0 0 0 0 0 0 0
  111569. - 0 0 0 0 0 0 0 0 0 0 0 0
  111570. - 0 0 0 0 0 0 0 0 0 0 0 0
  111571. - 0 0 0 0 0 0 0 0 0 0 0 0
  111572. - 0 0 0 0 0 0 0 0 0 0 0 0
  111573. - 0 0 0 0 0 0 0 0 0 10 10 10
  111574. - 38 38 38 86 86 86 14 14 14 10 10 10
  111575. -195 195 195 188 164 115 192 133 9 225 175 15
  111576. -239 182 13 234 190 10 232 195 16 232 200 30
  111577. -245 207 45 241 208 19 232 195 16 184 144 12
  111578. -218 194 134 211 206 186 42 42 42 2 2 6
  111579. - 2 2 6 2 2 6 2 2 6 2 2 6
  111580. - 50 50 50 74 74 74 30 30 30 6 6 6
  111581. - 0 0 0 0 0 0 0 0 0 0 0 0
  111582. - 0 0 0 0 0 0 0 0 0 0 0 0
  111583. - 0 0 0 0 0 0 0 0 0 0 0 0
  111584. - 0 0 0 0 0 0 0 0 0 0 0 0
  111585. - 0 0 0 0 0 0 0 0 0 0 0 0
  111586. - 0 0 0 0 0 0 0 0 0 0 0 0
  111587. - 0 0 0 0 0 0 0 0 0 0 0 0
  111588. - 0 0 0 0 0 0 0 0 0 0 0 0
  111589. - 0 0 0 0 0 0 0 0 0 0 0 0
  111590. - 0 0 0 0 0 0 0 0 0 0 0 0
  111591. - 0 0 0 0 0 0 0 0 0 0 0 0
  111592. - 0 0 0 0 0 0 0 0 0 0 0 0
  111593. - 0 0 0 0 0 0 0 0 0 10 10 10
  111594. - 34 34 34 86 86 86 14 14 14 2 2 6
  111595. -121 87 25 192 133 9 219 162 10 239 182 13
  111596. -236 186 11 232 195 16 241 208 19 244 214 54
  111597. -246 218 60 246 218 38 246 215 20 241 208 19
  111598. -241 208 19 226 184 13 121 87 25 2 2 6
  111599. - 2 2 6 2 2 6 2 2 6 2 2 6
  111600. - 50 50 50 82 82 82 34 34 34 10 10 10
  111601. - 0 0 0 0 0 0 0 0 0 0 0 0
  111602. - 0 0 0 0 0 0 0 0 0 0 0 0
  111603. - 0 0 0 0 0 0 0 0 0 0 0 0
  111604. - 0 0 0 0 0 0 0 0 0 0 0 0
  111605. - 0 0 0 0 0 0 0 0 0 0 0 0
  111606. - 0 0 0 0 0 0 0 0 0 0 0 0
  111607. - 0 0 0 0 0 0 0 0 0 0 0 0
  111608. - 0 0 0 0 0 0 0 0 0 0 0 0
  111609. - 0 0 0 0 0 0 0 0 0 0 0 0
  111610. - 0 0 0 0 0 0 0 0 0 0 0 0
  111611. - 0 0 0 0 0 0 0 0 0 0 0 0
  111612. - 0 0 0 0 0 0 0 0 0 0 0 0
  111613. - 0 0 0 0 0 0 0 0 0 10 10 10
  111614. - 34 34 34 82 82 82 30 30 30 61 42 6
  111615. -180 123 7 206 145 10 230 174 11 239 182 13
  111616. -234 190 10 238 202 15 241 208 19 246 218 74
  111617. -246 218 38 246 215 20 246 215 20 246 215 20
  111618. -226 184 13 215 174 15 184 144 12 6 6 6
  111619. - 2 2 6 2 2 6 2 2 6 2 2 6
  111620. - 26 26 26 94 94 94 42 42 42 14 14 14
  111621. - 0 0 0 0 0 0 0 0 0 0 0 0
  111622. - 0 0 0 0 0 0 0 0 0 0 0 0
  111623. - 0 0 0 0 0 0 0 0 0 0 0 0
  111624. - 0 0 0 0 0 0 0 0 0 0 0 0
  111625. - 0 0 0 0 0 0 0 0 0 0 0 0
  111626. - 0 0 0 0 0 0 0 0 0 0 0 0
  111627. - 0 0 0 0 0 0 0 0 0 0 0 0
  111628. - 0 0 0 0 0 0 0 0 0 0 0 0
  111629. - 0 0 0 0 0 0 0 0 0 0 0 0
  111630. - 0 0 0 0 0 0 0 0 0 0 0 0
  111631. - 0 0 0 0 0 0 0 0 0 0 0 0
  111632. - 0 0 0 0 0 0 0 0 0 0 0 0
  111633. - 0 0 0 0 0 0 0 0 0 10 10 10
  111634. - 30 30 30 78 78 78 50 50 50 104 69 6
  111635. -192 133 9 216 158 10 236 178 12 236 186 11
  111636. -232 195 16 241 208 19 244 214 54 245 215 43
  111637. -246 215 20 246 215 20 241 208 19 198 155 10
  111638. -200 144 11 216 158 10 156 118 10 2 2 6
  111639. - 2 2 6 2 2 6 2 2 6 2 2 6
  111640. - 6 6 6 90 90 90 54 54 54 18 18 18
  111641. - 6 6 6 0 0 0 0 0 0 0 0 0
  111642. - 0 0 0 0 0 0 0 0 0 0 0 0
  111643. - 0 0 0 0 0 0 0 0 0 0 0 0
  111644. - 0 0 0 0 0 0 0 0 0 0 0 0
  111645. - 0 0 0 0 0 0 0 0 0 0 0 0
  111646. - 0 0 0 0 0 0 0 0 0 0 0 0
  111647. - 0 0 0 0 0 0 0 0 0 0 0 0
  111648. - 0 0 0 0 0 0 0 0 0 0 0 0
  111649. - 0 0 0 0 0 0 0 0 0 0 0 0
  111650. - 0 0 0 0 0 0 0 0 0 0 0 0
  111651. - 0 0 0 0 0 0 0 0 0 0 0 0
  111652. - 0 0 0 0 0 0 0 0 0 0 0 0
  111653. - 0 0 0 0 0 0 0 0 0 10 10 10
  111654. - 30 30 30 78 78 78 46 46 46 22 22 22
  111655. -137 92 6 210 162 10 239 182 13 238 190 10
  111656. -238 202 15 241 208 19 246 215 20 246 215 20
  111657. -241 208 19 203 166 17 185 133 11 210 150 10
  111658. -216 158 10 210 150 10 102 78 10 2 2 6
  111659. - 6 6 6 54 54 54 14 14 14 2 2 6
  111660. - 2 2 6 62 62 62 74 74 74 30 30 30
  111661. - 10 10 10 0 0 0 0 0 0 0 0 0
  111662. - 0 0 0 0 0 0 0 0 0 0 0 0
  111663. - 0 0 0 0 0 0 0 0 0 0 0 0
  111664. - 0 0 0 0 0 0 0 0 0 0 0 0
  111665. - 0 0 0 0 0 0 0 0 0 0 0 0
  111666. - 0 0 0 0 0 0 0 0 0 0 0 0
  111667. - 0 0 0 0 0 0 0 0 0 0 0 0
  111668. - 0 0 0 0 0 0 0 0 0 0 0 0
  111669. - 0 0 0 0 0 0 0 0 0 0 0 0
  111670. - 0 0 0 0 0 0 0 0 0 0 0 0
  111671. - 0 0 0 0 0 0 0 0 0 0 0 0
  111672. - 0 0 0 0 0 0 0 0 0 0 0 0
  111673. - 0 0 0 0 0 0 0 0 0 10 10 10
  111674. - 34 34 34 78 78 78 50 50 50 6 6 6
  111675. - 94 70 30 139 102 15 190 146 13 226 184 13
  111676. -232 200 30 232 195 16 215 174 15 190 146 13
  111677. -168 122 10 192 133 9 210 150 10 213 154 11
  111678. -202 150 34 182 157 106 101 98 89 2 2 6
  111679. - 2 2 6 78 78 78 116 116 116 58 58 58
  111680. - 2 2 6 22 22 22 90 90 90 46 46 46
  111681. - 18 18 18 6 6 6 0 0 0 0 0 0
  111682. - 0 0 0 0 0 0 0 0 0 0 0 0
  111683. - 0 0 0 0 0 0 0 0 0 0 0 0
  111684. - 0 0 0 0 0 0 0 0 0 0 0 0
  111685. - 0 0 0 0 0 0 0 0 0 0 0 0
  111686. - 0 0 0 0 0 0 0 0 0 0 0 0
  111687. - 0 0 0 0 0 0 0 0 0 0 0 0
  111688. - 0 0 0 0 0 0 0 0 0 0 0 0
  111689. - 0 0 0 0 0 0 0 0 0 0 0 0
  111690. - 0 0 0 0 0 0 0 0 0 0 0 0
  111691. - 0 0 0 0 0 0 0 0 0 0 0 0
  111692. - 0 0 0 0 0 0 0 0 0 0 0 0
  111693. - 0 0 0 0 0 0 0 0 0 10 10 10
  111694. - 38 38 38 86 86 86 50 50 50 6 6 6
  111695. -128 128 128 174 154 114 156 107 11 168 122 10
  111696. -198 155 10 184 144 12 197 138 11 200 144 11
  111697. -206 145 10 206 145 10 197 138 11 188 164 115
  111698. -195 195 195 198 198 198 174 174 174 14 14 14
  111699. - 2 2 6 22 22 22 116 116 116 116 116 116
  111700. - 22 22 22 2 2 6 74 74 74 70 70 70
  111701. - 30 30 30 10 10 10 0 0 0 0 0 0
  111702. - 0 0 0 0 0 0 0 0 0 0 0 0
  111703. - 0 0 0 0 0 0 0 0 0 0 0 0
  111704. - 0 0 0 0 0 0 0 0 0 0 0 0
  111705. - 0 0 0 0 0 0 0 0 0 0 0 0
  111706. - 0 0 0 0 0 0 0 0 0 0 0 0
  111707. - 0 0 0 0 0 0 0 0 0 0 0 0
  111708. - 0 0 0 0 0 0 0 0 0 0 0 0
  111709. - 0 0 0 0 0 0 0 0 0 0 0 0
  111710. - 0 0 0 0 0 0 0 0 0 0 0 0
  111711. - 0 0 0 0 0 0 0 0 0 0 0 0
  111712. - 0 0 0 0 0 0 0 0 0 0 0 0
  111713. - 0 0 0 0 0 0 6 6 6 18 18 18
  111714. - 50 50 50 101 101 101 26 26 26 10 10 10
  111715. -138 138 138 190 190 190 174 154 114 156 107 11
  111716. -197 138 11 200 144 11 197 138 11 192 133 9
  111717. -180 123 7 190 142 34 190 178 144 187 187 187
  111718. -202 202 202 221 221 221 214 214 214 66 66 66
  111719. - 2 2 6 2 2 6 50 50 50 62 62 62
  111720. - 6 6 6 2 2 6 10 10 10 90 90 90
  111721. - 50 50 50 18 18 18 6 6 6 0 0 0
  111722. - 0 0 0 0 0 0 0 0 0 0 0 0
  111723. - 0 0 0 0 0 0 0 0 0 0 0 0
  111724. - 0 0 0 0 0 0 0 0 0 0 0 0
  111725. - 0 0 0 0 0 0 0 0 0 0 0 0
  111726. - 0 0 0 0 0 0 0 0 0 0 0 0
  111727. - 0 0 0 0 0 0 0 0 0 0 0 0
  111728. - 0 0 0 0 0 0 0 0 0 0 0 0
  111729. - 0 0 0 0 0 0 0 0 0 0 0 0
  111730. - 0 0 0 0 0 0 0 0 0 0 0 0
  111731. - 0 0 0 0 0 0 0 0 0 0 0 0
  111732. - 0 0 0 0 0 0 0 0 0 0 0 0
  111733. - 0 0 0 0 0 0 10 10 10 34 34 34
  111734. - 74 74 74 74 74 74 2 2 6 6 6 6
  111735. -144 144 144 198 198 198 190 190 190 178 166 146
  111736. -154 121 60 156 107 11 156 107 11 168 124 44
  111737. -174 154 114 187 187 187 190 190 190 210 210 210
  111738. -246 246 246 253 253 253 253 253 253 182 182 182
  111739. - 6 6 6 2 2 6 2 2 6 2 2 6
  111740. - 2 2 6 2 2 6 2 2 6 62 62 62
  111741. - 74 74 74 34 34 34 14 14 14 0 0 0
  111742. - 0 0 0 0 0 0 0 0 0 0 0 0
  111743. - 0 0 0 0 0 0 0 0 0 0 0 0
  111744. - 0 0 0 0 0 0 0 0 0 0 0 0
  111745. - 0 0 0 0 0 0 0 0 0 0 0 0
  111746. - 0 0 0 0 0 0 0 0 0 0 0 0
  111747. - 0 0 0 0 0 0 0 0 0 0 0 0
  111748. - 0 0 0 0 0 0 0 0 0 0 0 0
  111749. - 0 0 0 0 0 0 0 0 0 0 0 0
  111750. - 0 0 0 0 0 0 0 0 0 0 0 0
  111751. - 0 0 0 0 0 0 0 0 0 0 0 0
  111752. - 0 0 0 0 0 0 0 0 0 0 0 0
  111753. - 0 0 0 10 10 10 22 22 22 54 54 54
  111754. - 94 94 94 18 18 18 2 2 6 46 46 46
  111755. -234 234 234 221 221 221 190 190 190 190 190 190
  111756. -190 190 190 187 187 187 187 187 187 190 190 190
  111757. -190 190 190 195 195 195 214 214 214 242 242 242
  111758. -253 253 253 253 253 253 253 253 253 253 253 253
  111759. - 82 82 82 2 2 6 2 2 6 2 2 6
  111760. - 2 2 6 2 2 6 2 2 6 14 14 14
  111761. - 86 86 86 54 54 54 22 22 22 6 6 6
  111762. - 0 0 0 0 0 0 0 0 0 0 0 0
  111763. - 0 0 0 0 0 0 0 0 0 0 0 0
  111764. - 0 0 0 0 0 0 0 0 0 0 0 0
  111765. - 0 0 0 0 0 0 0 0 0 0 0 0
  111766. - 0 0 0 0 0 0 0 0 0 0 0 0
  111767. - 0 0 0 0 0 0 0 0 0 0 0 0
  111768. - 0 0 0 0 0 0 0 0 0 0 0 0
  111769. - 0 0 0 0 0 0 0 0 0 0 0 0
  111770. - 0 0 0 0 0 0 0 0 0 0 0 0
  111771. - 0 0 0 0 0 0 0 0 0 0 0 0
  111772. - 0 0 0 0 0 0 0 0 0 0 0 0
  111773. - 6 6 6 18 18 18 46 46 46 90 90 90
  111774. - 46 46 46 18 18 18 6 6 6 182 182 182
  111775. -253 253 253 246 246 246 206 206 206 190 190 190
  111776. -190 190 190 190 190 190 190 190 190 190 190 190
  111777. -206 206 206 231 231 231 250 250 250 253 253 253
  111778. -253 253 253 253 253 253 253 253 253 253 253 253
  111779. -202 202 202 14 14 14 2 2 6 2 2 6
  111780. - 2 2 6 2 2 6 2 2 6 2 2 6
  111781. - 42 42 42 86 86 86 42 42 42 18 18 18
  111782. - 6 6 6 0 0 0 0 0 0 0 0 0
  111783. - 0 0 0 0 0 0 0 0 0 0 0 0
  111784. - 0 0 0 0 0 0 0 0 0 0 0 0
  111785. - 0 0 0 0 0 0 0 0 0 0 0 0
  111786. - 0 0 0 0 0 0 0 0 0 0 0 0
  111787. - 0 0 0 0 0 0 0 0 0 0 0 0
  111788. - 0 0 0 0 0 0 0 0 0 0 0 0
  111789. - 0 0 0 0 0 0 0 0 0 0 0 0
  111790. - 0 0 0 0 0 0 0 0 0 0 0 0
  111791. - 0 0 0 0 0 0 0 0 0 0 0 0
  111792. - 0 0 0 0 0 0 0 0 0 6 6 6
  111793. - 14 14 14 38 38 38 74 74 74 66 66 66
  111794. - 2 2 6 6 6 6 90 90 90 250 250 250
  111795. -253 253 253 253 253 253 238 238 238 198 198 198
  111796. -190 190 190 190 190 190 195 195 195 221 221 221
  111797. -246 246 246 253 253 253 253 253 253 253 253 253
  111798. -253 253 253 253 253 253 253 253 253 253 253 253
  111799. -253 253 253 82 82 82 2 2 6 2 2 6
  111800. - 2 2 6 2 2 6 2 2 6 2 2 6
  111801. - 2 2 6 78 78 78 70 70 70 34 34 34
  111802. - 14 14 14 6 6 6 0 0 0 0 0 0
  111803. - 0 0 0 0 0 0 0 0 0 0 0 0
  111804. - 0 0 0 0 0 0 0 0 0 0 0 0
  111805. - 0 0 0 0 0 0 0 0 0 0 0 0
  111806. - 0 0 0 0 0 0 0 0 0 0 0 0
  111807. - 0 0 0 0 0 0 0 0 0 0 0 0
  111808. - 0 0 0 0 0 0 0 0 0 0 0 0
  111809. - 0 0 0 0 0 0 0 0 0 0 0 0
  111810. - 0 0 0 0 0 0 0 0 0 0 0 0
  111811. - 0 0 0 0 0 0 0 0 0 0 0 0
  111812. - 0 0 0 0 0 0 0 0 0 14 14 14
  111813. - 34 34 34 66 66 66 78 78 78 6 6 6
  111814. - 2 2 6 18 18 18 218 218 218 253 253 253
  111815. -253 253 253 253 253 253 253 253 253 246 246 246
  111816. -226 226 226 231 231 231 246 246 246 253 253 253
  111817. -253 253 253 253 253 253 253 253 253 253 253 253
  111818. -253 253 253 253 253 253 253 253 253 253 253 253
  111819. -253 253 253 178 178 178 2 2 6 2 2 6
  111820. - 2 2 6 2 2 6 2 2 6 2 2 6
  111821. - 2 2 6 18 18 18 90 90 90 62 62 62
  111822. - 30 30 30 10 10 10 0 0 0 0 0 0
  111823. - 0 0 0 0 0 0 0 0 0 0 0 0
  111824. - 0 0 0 0 0 0 0 0 0 0 0 0
  111825. - 0 0 0 0 0 0 0 0 0 0 0 0
  111826. - 0 0 0 0 0 0 0 0 0 0 0 0
  111827. - 0 0 0 0 0 0 0 0 0 0 0 0
  111828. - 0 0 0 0 0 0 0 0 0 0 0 0
  111829. - 0 0 0 0 0 0 0 0 0 0 0 0
  111830. - 0 0 0 0 0 0 0 0 0 0 0 0
  111831. - 0 0 0 0 0 0 0 0 0 0 0 0
  111832. - 0 0 0 0 0 0 10 10 10 26 26 26
  111833. - 58 58 58 90 90 90 18 18 18 2 2 6
  111834. - 2 2 6 110 110 110 253 253 253 253 253 253
  111835. -253 253 253 253 253 253 253 253 253 253 253 253
  111836. -250 250 250 253 253 253 253 253 253 253 253 253
  111837. -253 253 253 253 253 253 253 253 253 253 253 253
  111838. -253 253 253 253 253 253 253 253 253 253 253 253
  111839. -253 253 253 231 231 231 18 18 18 2 2 6
  111840. - 2 2 6 2 2 6 2 2 6 2 2 6
  111841. - 2 2 6 2 2 6 18 18 18 94 94 94
  111842. - 54 54 54 26 26 26 10 10 10 0 0 0
  111843. - 0 0 0 0 0 0 0 0 0 0 0 0
  111844. - 0 0 0 0 0 0 0 0 0 0 0 0
  111845. - 0 0 0 0 0 0 0 0 0 0 0 0
  111846. - 0 0 0 0 0 0 0 0 0 0 0 0
  111847. - 0 0 0 0 0 0 0 0 0 0 0 0
  111848. - 0 0 0 0 0 0 0 0 0 0 0 0
  111849. - 0 0 0 0 0 0 0 0 0 0 0 0
  111850. - 0 0 0 0 0 0 0 0 0 0 0 0
  111851. - 0 0 0 0 0 0 0 0 0 0 0 0
  111852. - 0 0 0 6 6 6 22 22 22 50 50 50
  111853. - 90 90 90 26 26 26 2 2 6 2 2 6
  111854. - 14 14 14 195 195 195 250 250 250 253 253 253
  111855. -253 253 253 253 253 253 253 253 253 253 253 253
  111856. -253 253 253 253 253 253 253 253 253 253 253 253
  111857. -253 253 253 253 253 253 253 253 253 253 253 253
  111858. -253 253 253 253 253 253 253 253 253 253 253 253
  111859. -250 250 250 242 242 242 54 54 54 2 2 6
  111860. - 2 2 6 2 2 6 2 2 6 2 2 6
  111861. - 2 2 6 2 2 6 2 2 6 38 38 38
  111862. - 86 86 86 50 50 50 22 22 22 6 6 6
  111863. - 0 0 0 0 0 0 0 0 0 0 0 0
  111864. - 0 0 0 0 0 0 0 0 0 0 0 0
  111865. - 0 0 0 0 0 0 0 0 0 0 0 0
  111866. - 0 0 0 0 0 0 0 0 0 0 0 0
  111867. - 0 0 0 0 0 0 0 0 0 0 0 0
  111868. - 0 0 0 0 0 0 0 0 0 0 0 0
  111869. - 0 0 0 0 0 0 0 0 0 0 0 0
  111870. - 0 0 0 0 0 0 0 0 0 0 0 0
  111871. - 0 0 0 0 0 0 0 0 0 0 0 0
  111872. - 6 6 6 14 14 14 38 38 38 82 82 82
  111873. - 34 34 34 2 2 6 2 2 6 2 2 6
  111874. - 42 42 42 195 195 195 246 246 246 253 253 253
  111875. -253 253 253 253 253 253 253 253 253 250 250 250
  111876. -242 242 242 242 242 242 250 250 250 253 253 253
  111877. -253 253 253 253 253 253 253 253 253 253 253 253
  111878. -253 253 253 250 250 250 246 246 246 238 238 238
  111879. -226 226 226 231 231 231 101 101 101 6 6 6
  111880. - 2 2 6 2 2 6 2 2 6 2 2 6
  111881. - 2 2 6 2 2 6 2 2 6 2 2 6
  111882. - 38 38 38 82 82 82 42 42 42 14 14 14
  111883. - 6 6 6 0 0 0 0 0 0 0 0 0
  111884. - 0 0 0 0 0 0 0 0 0 0 0 0
  111885. - 0 0 0 0 0 0 0 0 0 0 0 0
  111886. - 0 0 0 0 0 0 0 0 0 0 0 0
  111887. - 0 0 0 0 0 0 0 0 0 0 0 0
  111888. - 0 0 0 0 0 0 0 0 0 0 0 0
  111889. - 0 0 0 0 0 0 0 0 0 0 0 0
  111890. - 0 0 0 0 0 0 0 0 0 0 0 0
  111891. - 0 0 0 0 0 0 0 0 0 0 0 0
  111892. - 10 10 10 26 26 26 62 62 62 66 66 66
  111893. - 2 2 6 2 2 6 2 2 6 6 6 6
  111894. - 70 70 70 170 170 170 206 206 206 234 234 234
  111895. -246 246 246 250 250 250 250 250 250 238 238 238
  111896. -226 226 226 231 231 231 238 238 238 250 250 250
  111897. -250 250 250 250 250 250 246 246 246 231 231 231
  111898. -214 214 214 206 206 206 202 202 202 202 202 202
  111899. -198 198 198 202 202 202 182 182 182 18 18 18
  111900. - 2 2 6 2 2 6 2 2 6 2 2 6
  111901. - 2 2 6 2 2 6 2 2 6 2 2 6
  111902. - 2 2 6 62 62 62 66 66 66 30 30 30
  111903. - 10 10 10 0 0 0 0 0 0 0 0 0
  111904. - 0 0 0 0 0 0 0 0 0 0 0 0
  111905. - 0 0 0 0 0 0 0 0 0 0 0 0
  111906. - 0 0 0 0 0 0 0 0 0 0 0 0
  111907. - 0 0 0 0 0 0 0 0 0 0 0 0
  111908. - 0 0 0 0 0 0 0 0 0 0 0 0
  111909. - 0 0 0 0 0 0 0 0 0 0 0 0
  111910. - 0 0 0 0 0 0 0 0 0 0 0 0
  111911. - 0 0 0 0 0 0 0 0 0 0 0 0
  111912. - 14 14 14 42 42 42 82 82 82 18 18 18
  111913. - 2 2 6 2 2 6 2 2 6 10 10 10
  111914. - 94 94 94 182 182 182 218 218 218 242 242 242
  111915. -250 250 250 253 253 253 253 253 253 250 250 250
  111916. -234 234 234 253 253 253 253 253 253 253 253 253
  111917. -253 253 253 253 253 253 253 253 253 246 246 246
  111918. -238 238 238 226 226 226 210 210 210 202 202 202
  111919. -195 195 195 195 195 195 210 210 210 158 158 158
  111920. - 6 6 6 14 14 14 50 50 50 14 14 14
  111921. - 2 2 6 2 2 6 2 2 6 2 2 6
  111922. - 2 2 6 6 6 6 86 86 86 46 46 46
  111923. - 18 18 18 6 6 6 0 0 0 0 0 0
  111924. - 0 0 0 0 0 0 0 0 0 0 0 0
  111925. - 0 0 0 0 0 0 0 0 0 0 0 0
  111926. - 0 0 0 0 0 0 0 0 0 0 0 0
  111927. - 0 0 0 0 0 0 0 0 0 0 0 0
  111928. - 0 0 0 0 0 0 0 0 0 0 0 0
  111929. - 0 0 0 0 0 0 0 0 0 0 0 0
  111930. - 0 0 0 0 0 0 0 0 0 0 0 0
  111931. - 0 0 0 0 0 0 0 0 0 6 6 6
  111932. - 22 22 22 54 54 54 70 70 70 2 2 6
  111933. - 2 2 6 10 10 10 2 2 6 22 22 22
  111934. -166 166 166 231 231 231 250 250 250 253 253 253
  111935. -253 253 253 253 253 253 253 253 253 250 250 250
  111936. -242 242 242 253 253 253 253 253 253 253 253 253
  111937. -253 253 253 253 253 253 253 253 253 253 253 253
  111938. -253 253 253 253 253 253 253 253 253 246 246 246
  111939. -231 231 231 206 206 206 198 198 198 226 226 226
  111940. - 94 94 94 2 2 6 6 6 6 38 38 38
  111941. - 30 30 30 2 2 6 2 2 6 2 2 6
  111942. - 2 2 6 2 2 6 62 62 62 66 66 66
  111943. - 26 26 26 10 10 10 0 0 0 0 0 0
  111944. - 0 0 0 0 0 0 0 0 0 0 0 0
  111945. - 0 0 0 0 0 0 0 0 0 0 0 0
  111946. - 0 0 0 0 0 0 0 0 0 0 0 0
  111947. - 0 0 0 0 0 0 0 0 0 0 0 0
  111948. - 0 0 0 0 0 0 0 0 0 0 0 0
  111949. - 0 0 0 0 0 0 0 0 0 0 0 0
  111950. - 0 0 0 0 0 0 0 0 0 0 0 0
  111951. - 0 0 0 0 0 0 0 0 0 10 10 10
  111952. - 30 30 30 74 74 74 50 50 50 2 2 6
  111953. - 26 26 26 26 26 26 2 2 6 106 106 106
  111954. -238 238 238 253 253 253 253 253 253 253 253 253
  111955. -253 253 253 253 253 253 253 253 253 253 253 253
  111956. -253 253 253 253 253 253 253 253 253 253 253 253
  111957. -253 253 253 253 253 253 253 253 253 253 253 253
  111958. -253 253 253 253 253 253 253 253 253 253 253 253
  111959. -253 253 253 246 246 246 218 218 218 202 202 202
  111960. -210 210 210 14 14 14 2 2 6 2 2 6
  111961. - 30 30 30 22 22 22 2 2 6 2 2 6
  111962. - 2 2 6 2 2 6 18 18 18 86 86 86
  111963. - 42 42 42 14 14 14 0 0 0 0 0 0
  111964. - 0 0 0 0 0 0 0 0 0 0 0 0
  111965. - 0 0 0 0 0 0 0 0 0 0 0 0
  111966. - 0 0 0 0 0 0 0 0 0 0 0 0
  111967. - 0 0 0 0 0 0 0 0 0 0 0 0
  111968. - 0 0 0 0 0 0 0 0 0 0 0 0
  111969. - 0 0 0 0 0 0 0 0 0 0 0 0
  111970. - 0 0 0 0 0 0 0 0 0 0 0 0
  111971. - 0 0 0 0 0 0 0 0 0 14 14 14
  111972. - 42 42 42 90 90 90 22 22 22 2 2 6
  111973. - 42 42 42 2 2 6 18 18 18 218 218 218
  111974. -253 253 253 253 253 253 253 253 253 253 253 253
  111975. -253 253 253 253 253 253 253 253 253 253 253 253
  111976. -253 253 253 253 253 253 253 253 253 253 253 253
  111977. -253 253 253 253 253 253 253 253 253 253 253 253
  111978. -253 253 253 253 253 253 253 253 253 253 253 253
  111979. -253 253 253 253 253 253 250 250 250 221 221 221
  111980. -218 218 218 101 101 101 2 2 6 14 14 14
  111981. - 18 18 18 38 38 38 10 10 10 2 2 6
  111982. - 2 2 6 2 2 6 2 2 6 78 78 78
  111983. - 58 58 58 22 22 22 6 6 6 0 0 0
  111984. - 0 0 0 0 0 0 0 0 0 0 0 0
  111985. - 0 0 0 0 0 0 0 0 0 0 0 0
  111986. - 0 0 0 0 0 0 0 0 0 0 0 0
  111987. - 0 0 0 0 0 0 0 0 0 0 0 0
  111988. - 0 0 0 0 0 0 0 0 0 0 0 0
  111989. - 0 0 0 0 0 0 0 0 0 0 0 0
  111990. - 0 0 0 0 0 0 0 0 0 0 0 0
  111991. - 0 0 0 0 0 0 6 6 6 18 18 18
  111992. - 54 54 54 82 82 82 2 2 6 26 26 26
  111993. - 22 22 22 2 2 6 123 123 123 253 253 253
  111994. -253 253 253 253 253 253 253 253 253 253 253 253
  111995. -253 253 253 253 253 253 253 253 253 253 253 253
  111996. -253 253 253 253 253 253 253 253 253 253 253 253
  111997. -253 253 253 253 253 253 253 253 253 253 253 253
  111998. -253 253 253 253 253 253 253 253 253 253 253 253
  111999. -253 253 253 253 253 253 253 253 253 250 250 250
  112000. -238 238 238 198 198 198 6 6 6 38 38 38
  112001. - 58 58 58 26 26 26 38 38 38 2 2 6
  112002. - 2 2 6 2 2 6 2 2 6 46 46 46
  112003. - 78 78 78 30 30 30 10 10 10 0 0 0
  112004. - 0 0 0 0 0 0 0 0 0 0 0 0
  112005. - 0 0 0 0 0 0 0 0 0 0 0 0
  112006. - 0 0 0 0 0 0 0 0 0 0 0 0
  112007. - 0 0 0 0 0 0 0 0 0 0 0 0
  112008. - 0 0 0 0 0 0 0 0 0 0 0 0
  112009. - 0 0 0 0 0 0 0 0 0 0 0 0
  112010. - 0 0 0 0 0 0 0 0 0 0 0 0
  112011. - 0 0 0 0 0 0 10 10 10 30 30 30
  112012. - 74 74 74 58 58 58 2 2 6 42 42 42
  112013. - 2 2 6 22 22 22 231 231 231 253 253 253
  112014. -253 253 253 253 253 253 253 253 253 253 253 253
  112015. -253 253 253 253 253 253 253 253 253 250 250 250
  112016. -253 253 253 253 253 253 253 253 253 253 253 253
  112017. -253 253 253 253 253 253 253 253 253 253 253 253
  112018. -253 253 253 253 253 253 253 253 253 253 253 253
  112019. -253 253 253 253 253 253 253 253 253 253 253 253
  112020. -253 253 253 246 246 246 46 46 46 38 38 38
  112021. - 42 42 42 14 14 14 38 38 38 14 14 14
  112022. - 2 2 6 2 2 6 2 2 6 6 6 6
  112023. - 86 86 86 46 46 46 14 14 14 0 0 0
  112024. - 0 0 0 0 0 0 0 0 0 0 0 0
  112025. - 0 0 0 0 0 0 0 0 0 0 0 0
  112026. - 0 0 0 0 0 0 0 0 0 0 0 0
  112027. - 0 0 0 0 0 0 0 0 0 0 0 0
  112028. - 0 0 0 0 0 0 0 0 0 0 0 0
  112029. - 0 0 0 0 0 0 0 0 0 0 0 0
  112030. - 0 0 0 0 0 0 0 0 0 0 0 0
  112031. - 0 0 0 6 6 6 14 14 14 42 42 42
  112032. - 90 90 90 18 18 18 18 18 18 26 26 26
  112033. - 2 2 6 116 116 116 253 253 253 253 253 253
  112034. -253 253 253 253 253 253 253 253 253 253 253 253
  112035. -253 253 253 253 253 253 250 250 250 238 238 238
  112036. -253 253 253 253 253 253 253 253 253 253 253 253
  112037. -253 253 253 253 253 253 253 253 253 253 253 253
  112038. -253 253 253 253 253 253 253 253 253 253 253 253
  112039. -253 253 253 253 253 253 253 253 253 253 253 253
  112040. -253 253 253 253 253 253 94 94 94 6 6 6
  112041. - 2 2 6 2 2 6 10 10 10 34 34 34
  112042. - 2 2 6 2 2 6 2 2 6 2 2 6
  112043. - 74 74 74 58 58 58 22 22 22 6 6 6
  112044. - 0 0 0 0 0 0 0 0 0 0 0 0
  112045. - 0 0 0 0 0 0 0 0 0 0 0 0
  112046. - 0 0 0 0 0 0 0 0 0 0 0 0
  112047. - 0 0 0 0 0 0 0 0 0 0 0 0
  112048. - 0 0 0 0 0 0 0 0 0 0 0 0
  112049. - 0 0 0 0 0 0 0 0 0 0 0 0
  112050. - 0 0 0 0 0 0 0 0 0 0 0 0
  112051. - 0 0 0 10 10 10 26 26 26 66 66 66
  112052. - 82 82 82 2 2 6 38 38 38 6 6 6
  112053. - 14 14 14 210 210 210 253 253 253 253 253 253
  112054. -253 253 253 253 253 253 253 253 253 253 253 253
  112055. -253 253 253 253 253 253 246 246 246 242 242 242
  112056. -253 253 253 253 253 253 253 253 253 253 253 253
  112057. -253 253 253 253 253 253 253 253 253 253 253 253
  112058. -253 253 253 253 253 253 253 253 253 253 253 253
  112059. -253 253 253 253 253 253 253 253 253 253 253 253
  112060. -253 253 253 253 253 253 144 144 144 2 2 6
  112061. - 2 2 6 2 2 6 2 2 6 46 46 46
  112062. - 2 2 6 2 2 6 2 2 6 2 2 6
  112063. - 42 42 42 74 74 74 30 30 30 10 10 10
  112064. - 0 0 0 0 0 0 0 0 0 0 0 0
  112065. - 0 0 0 0 0 0 0 0 0 0 0 0
  112066. - 0 0 0 0 0 0 0 0 0 0 0 0
  112067. - 0 0 0 0 0 0 0 0 0 0 0 0
  112068. - 0 0 0 0 0 0 0 0 0 0 0 0
  112069. - 0 0 0 0 0 0 0 0 0 0 0 0
  112070. - 0 0 0 0 0 0 0 0 0 0 0 0
  112071. - 6 6 6 14 14 14 42 42 42 90 90 90
  112072. - 26 26 26 6 6 6 42 42 42 2 2 6
  112073. - 74 74 74 250 250 250 253 253 253 253 253 253
  112074. -253 253 253 253 253 253 253 253 253 253 253 253
  112075. -253 253 253 253 253 253 242 242 242 242 242 242
  112076. -253 253 253 253 253 253 253 253 253 253 253 253
  112077. -253 253 253 253 253 253 253 253 253 253 253 253
  112078. -253 253 253 253 253 253 253 253 253 253 253 253
  112079. -253 253 253 253 253 253 253 253 253 253 253 253
  112080. -253 253 253 253 253 253 182 182 182 2 2 6
  112081. - 2 2 6 2 2 6 2 2 6 46 46 46
  112082. - 2 2 6 2 2 6 2 2 6 2 2 6
  112083. - 10 10 10 86 86 86 38 38 38 10 10 10
  112084. - 0 0 0 0 0 0 0 0 0 0 0 0
  112085. - 0 0 0 0 0 0 0 0 0 0 0 0
  112086. - 0 0 0 0 0 0 0 0 0 0 0 0
  112087. - 0 0 0 0 0 0 0 0 0 0 0 0
  112088. - 0 0 0 0 0 0 0 0 0 0 0 0
  112089. - 0 0 0 0 0 0 0 0 0 0 0 0
  112090. - 0 0 0 0 0 0 0 0 0 0 0 0
  112091. - 10 10 10 26 26 26 66 66 66 82 82 82
  112092. - 2 2 6 22 22 22 18 18 18 2 2 6
  112093. -149 149 149 253 253 253 253 253 253 253 253 253
  112094. -253 253 253 253 253 253 253 253 253 253 253 253
  112095. -253 253 253 253 253 253 234 234 234 242 242 242
  112096. -253 253 253 253 253 253 253 253 253 253 253 253
  112097. -253 253 253 253 253 253 253 253 253 253 253 253
  112098. -253 253 253 253 253 253 253 253 253 253 253 253
  112099. -253 253 253 253 253 253 253 253 253 253 253 253
  112100. -253 253 253 253 253 253 206 206 206 2 2 6
  112101. - 2 2 6 2 2 6 2 2 6 38 38 38
  112102. - 2 2 6 2 2 6 2 2 6 2 2 6
  112103. - 6 6 6 86 86 86 46 46 46 14 14 14
  112104. - 0 0 0 0 0 0 0 0 0 0 0 0
  112105. - 0 0 0 0 0 0 0 0 0 0 0 0
  112106. - 0 0 0 0 0 0 0 0 0 0 0 0
  112107. - 0 0 0 0 0 0 0 0 0 0 0 0
  112108. - 0 0 0 0 0 0 0 0 0 0 0 0
  112109. - 0 0 0 0 0 0 0 0 0 0 0 0
  112110. - 0 0 0 0 0 0 0 0 0 6 6 6
  112111. - 18 18 18 46 46 46 86 86 86 18 18 18
  112112. - 2 2 6 34 34 34 10 10 10 6 6 6
  112113. -210 210 210 253 253 253 253 253 253 253 253 253
  112114. -253 253 253 253 253 253 253 253 253 253 253 253
  112115. -253 253 253 253 253 253 234 234 234 242 242 242
  112116. -253 253 253 253 253 253 253 253 253 253 253 253
  112117. -253 253 253 253 253 253 253 253 253 253 253 253
  112118. -253 253 253 253 253 253 253 253 253 253 253 253
  112119. -253 253 253 253 253 253 253 253 253 253 253 253
  112120. -253 253 253 253 253 253 221 221 221 6 6 6
  112121. - 2 2 6 2 2 6 6 6 6 30 30 30
  112122. - 2 2 6 2 2 6 2 2 6 2 2 6
  112123. - 2 2 6 82 82 82 54 54 54 18 18 18
  112124. - 6 6 6 0 0 0 0 0 0 0 0 0
  112125. - 0 0 0 0 0 0 0 0 0 0 0 0
  112126. - 0 0 0 0 0 0 0 0 0 0 0 0
  112127. - 0 0 0 0 0 0 0 0 0 0 0 0
  112128. - 0 0 0 0 0 0 0 0 0 0 0 0
  112129. - 0 0 0 0 0 0 0 0 0 0 0 0
  112130. - 0 0 0 0 0 0 0 0 0 10 10 10
  112131. - 26 26 26 66 66 66 62 62 62 2 2 6
  112132. - 2 2 6 38 38 38 10 10 10 26 26 26
  112133. -238 238 238 253 253 253 253 253 253 253 253 253
  112134. -253 253 253 253 253 253 253 253 253 253 253 253
  112135. -253 253 253 253 253 253 231 231 231 238 238 238
  112136. -253 253 253 253 253 253 253 253 253 253 253 253
  112137. -253 253 253 253 253 253 253 253 253 253 253 253
  112138. -253 253 253 253 253 253 253 253 253 253 253 253
  112139. -253 253 253 253 253 253 253 253 253 253 253 253
  112140. -253 253 253 253 253 253 231 231 231 6 6 6
  112141. - 2 2 6 2 2 6 10 10 10 30 30 30
  112142. - 2 2 6 2 2 6 2 2 6 2 2 6
  112143. - 2 2 6 66 66 66 58 58 58 22 22 22
  112144. - 6 6 6 0 0 0 0 0 0 0 0 0
  112145. - 0 0 0 0 0 0 0 0 0 0 0 0
  112146. - 0 0 0 0 0 0 0 0 0 0 0 0
  112147. - 0 0 0 0 0 0 0 0 0 0 0 0
  112148. - 0 0 0 0 0 0 0 0 0 0 0 0
  112149. - 0 0 0 0 0 0 0 0 0 0 0 0
  112150. - 0 0 0 0 0 0 0 0 0 10 10 10
  112151. - 38 38 38 78 78 78 6 6 6 2 2 6
  112152. - 2 2 6 46 46 46 14 14 14 42 42 42
  112153. -246 246 246 253 253 253 253 253 253 253 253 253
  112154. -253 253 253 253 253 253 253 253 253 253 253 253
  112155. -253 253 253 253 253 253 231 231 231 242 242 242
  112156. -253 253 253 253 253 253 253 253 253 253 253 253
  112157. -253 253 253 253 253 253 253 253 253 253 253 253
  112158. -253 253 253 253 253 253 253 253 253 253 253 253
  112159. -253 253 253 253 253 253 253 253 253 253 253 253
  112160. -253 253 253 253 253 253 234 234 234 10 10 10
  112161. - 2 2 6 2 2 6 22 22 22 14 14 14
  112162. - 2 2 6 2 2 6 2 2 6 2 2 6
  112163. - 2 2 6 66 66 66 62 62 62 22 22 22
  112164. - 6 6 6 0 0 0 0 0 0 0 0 0
  112165. - 0 0 0 0 0 0 0 0 0 0 0 0
  112166. - 0 0 0 0 0 0 0 0 0 0 0 0
  112167. - 0 0 0 0 0 0 0 0 0 0 0 0
  112168. - 0 0 0 0 0 0 0 0 0 0 0 0
  112169. - 0 0 0 0 0 0 0 0 0 0 0 0
  112170. - 0 0 0 0 0 0 6 6 6 18 18 18
  112171. - 50 50 50 74 74 74 2 2 6 2 2 6
  112172. - 14 14 14 70 70 70 34 34 34 62 62 62
  112173. -250 250 250 253 253 253 253 253 253 253 253 253
  112174. -253 253 253 253 253 253 253 253 253 253 253 253
  112175. -253 253 253 253 253 253 231 231 231 246 246 246
  112176. -253 253 253 253 253 253 253 253 253 253 253 253
  112177. -253 253 253 253 253 253 253 253 253 253 253 253
  112178. -253 253 253 253 253 253 253 253 253 253 253 253
  112179. -253 253 253 253 253 253 253 253 253 253 253 253
  112180. -253 253 253 253 253 253 234 234 234 14 14 14
  112181. - 2 2 6 2 2 6 30 30 30 2 2 6
  112182. - 2 2 6 2 2 6 2 2 6 2 2 6
  112183. - 2 2 6 66 66 66 62 62 62 22 22 22
  112184. - 6 6 6 0 0 0 0 0 0 0 0 0
  112185. - 0 0 0 0 0 0 0 0 0 0 0 0
  112186. - 0 0 0 0 0 0 0 0 0 0 0 0
  112187. - 0 0 0 0 0 0 0 0 0 0 0 0
  112188. - 0 0 0 0 0 0 0 0 0 0 0 0
  112189. - 0 0 0 0 0 0 0 0 0 0 0 0
  112190. - 0 0 0 0 0 0 6 6 6 18 18 18
  112191. - 54 54 54 62 62 62 2 2 6 2 2 6
  112192. - 2 2 6 30 30 30 46 46 46 70 70 70
  112193. -250 250 250 253 253 253 253 253 253 253 253 253
  112194. -253 253 253 253 253 253 253 253 253 253 253 253
  112195. -253 253 253 253 253 253 231 231 231 246 246 246
  112196. -253 253 253 253 253 253 253 253 253 253 253 253
  112197. -253 253 253 253 253 253 253 253 253 253 253 253
  112198. -253 253 253 253 253 253 253 253 253 253 253 253
  112199. -253 253 253 253 253 253 253 253 253 253 253 253
  112200. -253 253 253 253 253 253 226 226 226 10 10 10
  112201. - 2 2 6 6 6 6 30 30 30 2 2 6
  112202. - 2 2 6 2 2 6 2 2 6 2 2 6
  112203. - 2 2 6 66 66 66 58 58 58 22 22 22
  112204. - 6 6 6 0 0 0 0 0 0 0 0 0
  112205. - 0 0 0 0 0 0 0 0 0 0 0 0
  112206. - 0 0 0 0 0 0 0 0 0 0 0 0
  112207. - 0 0 0 0 0 0 0 0 0 0 0 0
  112208. - 0 0 0 0 0 0 0 0 0 0 0 0
  112209. - 0 0 0 0 0 0 0 0 0 0 0 0
  112210. - 0 0 0 0 0 0 6 6 6 22 22 22
  112211. - 58 58 58 62 62 62 2 2 6 2 2 6
  112212. - 2 2 6 2 2 6 30 30 30 78 78 78
  112213. -250 250 250 253 253 253 253 253 253 253 253 253
  112214. -253 253 253 253 253 253 253 253 253 253 253 253
  112215. -253 253 253 253 253 253 231 231 231 246 246 246
  112216. -253 253 253 253 253 253 253 253 253 253 253 253
  112217. -253 253 253 253 253 253 253 253 253 253 253 253
  112218. -253 253 253 253 253 253 253 253 253 253 253 253
  112219. -253 253 253 253 253 253 253 253 253 253 253 253
  112220. -253 253 253 253 253 253 206 206 206 2 2 6
  112221. - 22 22 22 34 34 34 18 14 6 22 22 22
  112222. - 26 26 26 18 18 18 6 6 6 2 2 6
  112223. - 2 2 6 82 82 82 54 54 54 18 18 18
  112224. - 6 6 6 0 0 0 0 0 0 0 0 0
  112225. - 0 0 0 0 0 0 0 0 0 0 0 0
  112226. - 0 0 0 0 0 0 0 0 0 0 0 0
  112227. - 0 0 0 0 0 0 0 0 0 0 0 0
  112228. - 0 0 0 0 0 0 0 0 0 0 0 0
  112229. - 0 0 0 0 0 0 0 0 0 0 0 0
  112230. - 0 0 0 0 0 0 6 6 6 26 26 26
  112231. - 62 62 62 106 106 106 74 54 14 185 133 11
  112232. -210 162 10 121 92 8 6 6 6 62 62 62
  112233. -238 238 238 253 253 253 253 253 253 253 253 253
  112234. -253 253 253 253 253 253 253 253 253 253 253 253
  112235. -253 253 253 253 253 253 231 231 231 246 246 246
  112236. -253 253 253 253 253 253 253 253 253 253 253 253
  112237. -253 253 253 253 253 253 253 253 253 253 253 253
  112238. -253 253 253 253 253 253 253 253 253 253 253 253
  112239. -253 253 253 253 253 253 253 253 253 253 253 253
  112240. -253 253 253 253 253 253 158 158 158 18 18 18
  112241. - 14 14 14 2 2 6 2 2 6 2 2 6
  112242. - 6 6 6 18 18 18 66 66 66 38 38 38
  112243. - 6 6 6 94 94 94 50 50 50 18 18 18
  112244. - 6 6 6 0 0 0 0 0 0 0 0 0
  112245. - 0 0 0 0 0 0 0 0 0 0 0 0
  112246. - 0 0 0 0 0 0 0 0 0 0 0 0
  112247. - 0 0 0 0 0 0 0 0 0 0 0 0
  112248. - 0 0 0 0 0 0 0 0 0 0 0 0
  112249. - 0 0 0 0 0 0 0 0 0 6 6 6
  112250. - 10 10 10 10 10 10 18 18 18 38 38 38
  112251. - 78 78 78 142 134 106 216 158 10 242 186 14
  112252. -246 190 14 246 190 14 156 118 10 10 10 10
  112253. - 90 90 90 238 238 238 253 253 253 253 253 253
  112254. -253 253 253 253 253 253 253 253 253 253 253 253
  112255. -253 253 253 253 253 253 231 231 231 250 250 250
  112256. -253 253 253 253 253 253 253 253 253 253 253 253
  112257. -253 253 253 253 253 253 253 253 253 253 253 253
  112258. -253 253 253 253 253 253 253 253 253 253 253 253
  112259. -253 253 253 253 253 253 253 253 253 246 230 190
  112260. -238 204 91 238 204 91 181 142 44 37 26 9
  112261. - 2 2 6 2 2 6 2 2 6 2 2 6
  112262. - 2 2 6 2 2 6 38 38 38 46 46 46
  112263. - 26 26 26 106 106 106 54 54 54 18 18 18
  112264. - 6 6 6 0 0 0 0 0 0 0 0 0
  112265. - 0 0 0 0 0 0 0 0 0 0 0 0
  112266. - 0 0 0 0 0 0 0 0 0 0 0 0
  112267. - 0 0 0 0 0 0 0 0 0 0 0 0
  112268. - 0 0 0 0 0 0 0 0 0 0 0 0
  112269. - 0 0 0 6 6 6 14 14 14 22 22 22
  112270. - 30 30 30 38 38 38 50 50 50 70 70 70
  112271. -106 106 106 190 142 34 226 170 11 242 186 14
  112272. -246 190 14 246 190 14 246 190 14 154 114 10
  112273. - 6 6 6 74 74 74 226 226 226 253 253 253
  112274. -253 253 253 253 253 253 253 253 253 253 253 253
  112275. -253 253 253 253 253 253 231 231 231 250 250 250
  112276. -253 253 253 253 253 253 253 253 253 253 253 253
  112277. -253 253 253 253 253 253 253 253 253 253 253 253
  112278. -253 253 253 253 253 253 253 253 253 253 253 253
  112279. -253 253 253 253 253 253 253 253 253 228 184 62
  112280. -241 196 14 241 208 19 232 195 16 38 30 10
  112281. - 2 2 6 2 2 6 2 2 6 2 2 6
  112282. - 2 2 6 6 6 6 30 30 30 26 26 26
  112283. -203 166 17 154 142 90 66 66 66 26 26 26
  112284. - 6 6 6 0 0 0 0 0 0 0 0 0
  112285. - 0 0 0 0 0 0 0 0 0 0 0 0
  112286. - 0 0 0 0 0 0 0 0 0 0 0 0
  112287. - 0 0 0 0 0 0 0 0 0 0 0 0
  112288. - 0 0 0 0 0 0 0 0 0 0 0 0
  112289. - 6 6 6 18 18 18 38 38 38 58 58 58
  112290. - 78 78 78 86 86 86 101 101 101 123 123 123
  112291. -175 146 61 210 150 10 234 174 13 246 186 14
  112292. -246 190 14 246 190 14 246 190 14 238 190 10
  112293. -102 78 10 2 2 6 46 46 46 198 198 198
  112294. -253 253 253 253 253 253 253 253 253 253 253 253
  112295. -253 253 253 253 253 253 234 234 234 242 242 242
  112296. -253 253 253 253 253 253 253 253 253 253 253 253
  112297. -253 253 253 253 253 253 253 253 253 253 253 253
  112298. -253 253 253 253 253 253 253 253 253 253 253 253
  112299. -253 253 253 253 253 253 253 253 253 224 178 62
  112300. -242 186 14 241 196 14 210 166 10 22 18 6
  112301. - 2 2 6 2 2 6 2 2 6 2 2 6
  112302. - 2 2 6 2 2 6 6 6 6 121 92 8
  112303. -238 202 15 232 195 16 82 82 82 34 34 34
  112304. - 10 10 10 0 0 0 0 0 0 0 0 0
  112305. - 0 0 0 0 0 0 0 0 0 0 0 0
  112306. - 0 0 0 0 0 0 0 0 0 0 0 0
  112307. - 0 0 0 0 0 0 0 0 0 0 0 0
  112308. - 0 0 0 0 0 0 0 0 0 0 0 0
  112309. - 14 14 14 38 38 38 70 70 70 154 122 46
  112310. -190 142 34 200 144 11 197 138 11 197 138 11
  112311. -213 154 11 226 170 11 242 186 14 246 190 14
  112312. -246 190 14 246 190 14 246 190 14 246 190 14
  112313. -225 175 15 46 32 6 2 2 6 22 22 22
  112314. -158 158 158 250 250 250 253 253 253 253 253 253
  112315. -253 253 253 253 253 253 253 253 253 253 253 253
  112316. -253 253 253 253 253 253 253 253 253 253 253 253
  112317. -253 253 253 253 253 253 253 253 253 253 253 253
  112318. -253 253 253 253 253 253 253 253 253 253 253 253
  112319. -253 253 253 250 250 250 242 242 242 224 178 62
  112320. -239 182 13 236 186 11 213 154 11 46 32 6
  112321. - 2 2 6 2 2 6 2 2 6 2 2 6
  112322. - 2 2 6 2 2 6 61 42 6 225 175 15
  112323. -238 190 10 236 186 11 112 100 78 42 42 42
  112324. - 14 14 14 0 0 0 0 0 0 0 0 0
  112325. - 0 0 0 0 0 0 0 0 0 0 0 0
  112326. - 0 0 0 0 0 0 0 0 0 0 0 0
  112327. - 0 0 0 0 0 0 0 0 0 0 0 0
  112328. - 0 0 0 0 0 0 0 0 0 6 6 6
  112329. - 22 22 22 54 54 54 154 122 46 213 154 11
  112330. -226 170 11 230 174 11 226 170 11 226 170 11
  112331. -236 178 12 242 186 14 246 190 14 246 190 14
  112332. -246 190 14 246 190 14 246 190 14 246 190 14
  112333. -241 196 14 184 144 12 10 10 10 2 2 6
  112334. - 6 6 6 116 116 116 242 242 242 253 253 253
  112335. -253 253 253 253 253 253 253 253 253 253 253 253
  112336. -253 253 253 253 253 253 253 253 253 253 253 253
  112337. -253 253 253 253 253 253 253 253 253 253 253 253
  112338. -253 253 253 253 253 253 253 253 253 253 253 253
  112339. -253 253 253 231 231 231 198 198 198 214 170 54
  112340. -236 178 12 236 178 12 210 150 10 137 92 6
  112341. - 18 14 6 2 2 6 2 2 6 2 2 6
  112342. - 6 6 6 70 47 6 200 144 11 236 178 12
  112343. -239 182 13 239 182 13 124 112 88 58 58 58
  112344. - 22 22 22 6 6 6 0 0 0 0 0 0
  112345. - 0 0 0 0 0 0 0 0 0 0 0 0
  112346. - 0 0 0 0 0 0 0 0 0 0 0 0
  112347. - 0 0 0 0 0 0 0 0 0 0 0 0
  112348. - 0 0 0 0 0 0 0 0 0 10 10 10
  112349. - 30 30 30 70 70 70 180 133 36 226 170 11
  112350. -239 182 13 242 186 14 242 186 14 246 186 14
  112351. -246 190 14 246 190 14 246 190 14 246 190 14
  112352. -246 190 14 246 190 14 246 190 14 246 190 14
  112353. -246 190 14 232 195 16 98 70 6 2 2 6
  112354. - 2 2 6 2 2 6 66 66 66 221 221 221
  112355. -253 253 253 253 253 253 253 253 253 253 253 253
  112356. -253 253 253 253 253 253 253 253 253 253 253 253
  112357. -253 253 253 253 253 253 253 253 253 253 253 253
  112358. -253 253 253 253 253 253 253 253 253 253 253 253
  112359. -253 253 253 206 206 206 198 198 198 214 166 58
  112360. -230 174 11 230 174 11 216 158 10 192 133 9
  112361. -163 110 8 116 81 8 102 78 10 116 81 8
  112362. -167 114 7 197 138 11 226 170 11 239 182 13
  112363. -242 186 14 242 186 14 162 146 94 78 78 78
  112364. - 34 34 34 14 14 14 6 6 6 0 0 0
  112365. - 0 0 0 0 0 0 0 0 0 0 0 0
  112366. - 0 0 0 0 0 0 0 0 0 0 0 0
  112367. - 0 0 0 0 0 0 0 0 0 0 0 0
  112368. - 0 0 0 0 0 0 0 0 0 6 6 6
  112369. - 30 30 30 78 78 78 190 142 34 226 170 11
  112370. -239 182 13 246 190 14 246 190 14 246 190 14
  112371. -246 190 14 246 190 14 246 190 14 246 190 14
  112372. -246 190 14 246 190 14 246 190 14 246 190 14
  112373. -246 190 14 241 196 14 203 166 17 22 18 6
  112374. - 2 2 6 2 2 6 2 2 6 38 38 38
  112375. -218 218 218 253 253 253 253 253 253 253 253 253
  112376. -253 253 253 253 253 253 253 253 253 253 253 253
  112377. -253 253 253 253 253 253 253 253 253 253 253 253
  112378. -253 253 253 253 253 253 253 253 253 253 253 253
  112379. -250 250 250 206 206 206 198 198 198 202 162 69
  112380. -226 170 11 236 178 12 224 166 10 210 150 10
  112381. -200 144 11 197 138 11 192 133 9 197 138 11
  112382. -210 150 10 226 170 11 242 186 14 246 190 14
  112383. -246 190 14 246 186 14 225 175 15 124 112 88
  112384. - 62 62 62 30 30 30 14 14 14 6 6 6
  112385. - 0 0 0 0 0 0 0 0 0 0 0 0
  112386. - 0 0 0 0 0 0 0 0 0 0 0 0
  112387. - 0 0 0 0 0 0 0 0 0 0 0 0
  112388. - 0 0 0 0 0 0 0 0 0 10 10 10
  112389. - 30 30 30 78 78 78 174 135 50 224 166 10
  112390. -239 182 13 246 190 14 246 190 14 246 190 14
  112391. -246 190 14 246 190 14 246 190 14 246 190 14
  112392. -246 190 14 246 190 14 246 190 14 246 190 14
  112393. -246 190 14 246 190 14 241 196 14 139 102 15
  112394. - 2 2 6 2 2 6 2 2 6 2 2 6
  112395. - 78 78 78 250 250 250 253 253 253 253 253 253
  112396. -253 253 253 253 253 253 253 253 253 253 253 253
  112397. -253 253 253 253 253 253 253 253 253 253 253 253
  112398. -253 253 253 253 253 253 253 253 253 253 253 253
  112399. -250 250 250 214 214 214 198 198 198 190 150 46
  112400. -219 162 10 236 178 12 234 174 13 224 166 10
  112401. -216 158 10 213 154 11 213 154 11 216 158 10
  112402. -226 170 11 239 182 13 246 190 14 246 190 14
  112403. -246 190 14 246 190 14 242 186 14 206 162 42
  112404. -101 101 101 58 58 58 30 30 30 14 14 14
  112405. - 6 6 6 0 0 0 0 0 0 0 0 0
  112406. - 0 0 0 0 0 0 0 0 0 0 0 0
  112407. - 0 0 0 0 0 0 0 0 0 0 0 0
  112408. - 0 0 0 0 0 0 0 0 0 10 10 10
  112409. - 30 30 30 74 74 74 174 135 50 216 158 10
  112410. -236 178 12 246 190 14 246 190 14 246 190 14
  112411. -246 190 14 246 190 14 246 190 14 246 190 14
  112412. -246 190 14 246 190 14 246 190 14 246 190 14
  112413. -246 190 14 246 190 14 241 196 14 226 184 13
  112414. - 61 42 6 2 2 6 2 2 6 2 2 6
  112415. - 22 22 22 238 238 238 253 253 253 253 253 253
  112416. -253 253 253 253 253 253 253 253 253 253 253 253
  112417. -253 253 253 253 253 253 253 253 253 253 253 253
  112418. -253 253 253 253 253 253 253 253 253 253 253 253
  112419. -253 253 253 226 226 226 187 187 187 180 133 36
  112420. -216 158 10 236 178 12 239 182 13 236 178 12
  112421. -230 174 11 226 170 11 226 170 11 230 174 11
  112422. -236 178 12 242 186 14 246 190 14 246 190 14
  112423. -246 190 14 246 190 14 246 186 14 239 182 13
  112424. -206 162 42 106 106 106 66 66 66 34 34 34
  112425. - 14 14 14 6 6 6 0 0 0 0 0 0
  112426. - 0 0 0 0 0 0 0 0 0 0 0 0
  112427. - 0 0 0 0 0 0 0 0 0 0 0 0
  112428. - 0 0 0 0 0 0 0 0 0 6 6 6
  112429. - 26 26 26 70 70 70 163 133 67 213 154 11
  112430. -236 178 12 246 190 14 246 190 14 246 190 14
  112431. -246 190 14 246 190 14 246 190 14 246 190 14
  112432. -246 190 14 246 190 14 246 190 14 246 190 14
  112433. -246 190 14 246 190 14 246 190 14 241 196 14
  112434. -190 146 13 18 14 6 2 2 6 2 2 6
  112435. - 46 46 46 246 246 246 253 253 253 253 253 253
  112436. -253 253 253 253 253 253 253 253 253 253 253 253
  112437. -253 253 253 253 253 253 253 253 253 253 253 253
  112438. -253 253 253 253 253 253 253 253 253 253 253 253
  112439. -253 253 253 221 221 221 86 86 86 156 107 11
  112440. -216 158 10 236 178 12 242 186 14 246 186 14
  112441. -242 186 14 239 182 13 239 182 13 242 186 14
  112442. -242 186 14 246 186 14 246 190 14 246 190 14
  112443. -246 190 14 246 190 14 246 190 14 246 190 14
  112444. -242 186 14 225 175 15 142 122 72 66 66 66
  112445. - 30 30 30 10 10 10 0 0 0 0 0 0
  112446. - 0 0 0 0 0 0 0 0 0 0 0 0
  112447. - 0 0 0 0 0 0 0 0 0 0 0 0
  112448. - 0 0 0 0 0 0 0 0 0 6 6 6
  112449. - 26 26 26 70 70 70 163 133 67 210 150 10
  112450. -236 178 12 246 190 14 246 190 14 246 190 14
  112451. -246 190 14 246 190 14 246 190 14 246 190 14
  112452. -246 190 14 246 190 14 246 190 14 246 190 14
  112453. -246 190 14 246 190 14 246 190 14 246 190 14
  112454. -232 195 16 121 92 8 34 34 34 106 106 106
  112455. -221 221 221 253 253 253 253 253 253 253 253 253
  112456. -253 253 253 253 253 253 253 253 253 253 253 253
  112457. -253 253 253 253 253 253 253 253 253 253 253 253
  112458. -253 253 253 253 253 253 253 253 253 253 253 253
  112459. -242 242 242 82 82 82 18 14 6 163 110 8
  112460. -216 158 10 236 178 12 242 186 14 246 190 14
  112461. -246 190 14 246 190 14 246 190 14 246 190 14
  112462. -246 190 14 246 190 14 246 190 14 246 190 14
  112463. -246 190 14 246 190 14 246 190 14 246 190 14
  112464. -246 190 14 246 190 14 242 186 14 163 133 67
  112465. - 46 46 46 18 18 18 6 6 6 0 0 0
  112466. - 0 0 0 0 0 0 0 0 0 0 0 0
  112467. - 0 0 0 0 0 0 0 0 0 0 0 0
  112468. - 0 0 0 0 0 0 0 0 0 10 10 10
  112469. - 30 30 30 78 78 78 163 133 67 210 150 10
  112470. -236 178 12 246 186 14 246 190 14 246 190 14
  112471. -246 190 14 246 190 14 246 190 14 246 190 14
  112472. -246 190 14 246 190 14 246 190 14 246 190 14
  112473. -246 190 14 246 190 14 246 190 14 246 190 14
  112474. -241 196 14 215 174 15 190 178 144 253 253 253
  112475. -253 253 253 253 253 253 253 253 253 253 253 253
  112476. -253 253 253 253 253 253 253 253 253 253 253 253
  112477. -253 253 253 253 253 253 253 253 253 253 253 253
  112478. -253 253 253 253 253 253 253 253 253 218 218 218
  112479. - 58 58 58 2 2 6 22 18 6 167 114 7
  112480. -216 158 10 236 178 12 246 186 14 246 190 14
  112481. -246 190 14 246 190 14 246 190 14 246 190 14
  112482. -246 190 14 246 190 14 246 190 14 246 190 14
  112483. -246 190 14 246 190 14 246 190 14 246 190 14
  112484. -246 190 14 246 186 14 242 186 14 190 150 46
  112485. - 54 54 54 22 22 22 6 6 6 0 0 0
  112486. - 0 0 0 0 0 0 0 0 0 0 0 0
  112487. - 0 0 0 0 0 0 0 0 0 0 0 0
  112488. - 0 0 0 0 0 0 0 0 0 14 14 14
  112489. - 38 38 38 86 86 86 180 133 36 213 154 11
  112490. -236 178 12 246 186 14 246 190 14 246 190 14
  112491. -246 190 14 246 190 14 246 190 14 246 190 14
  112492. -246 190 14 246 190 14 246 190 14 246 190 14
  112493. -246 190 14 246 190 14 246 190 14 246 190 14
  112494. -246 190 14 232 195 16 190 146 13 214 214 214
  112495. -253 253 253 253 253 253 253 253 253 253 253 253
  112496. -253 253 253 253 253 253 253 253 253 253 253 253
  112497. -253 253 253 253 253 253 253 253 253 253 253 253
  112498. -253 253 253 250 250 250 170 170 170 26 26 26
  112499. - 2 2 6 2 2 6 37 26 9 163 110 8
  112500. -219 162 10 239 182 13 246 186 14 246 190 14
  112501. -246 190 14 246 190 14 246 190 14 246 190 14
  112502. -246 190 14 246 190 14 246 190 14 246 190 14
  112503. -246 190 14 246 190 14 246 190 14 246 190 14
  112504. -246 186 14 236 178 12 224 166 10 142 122 72
  112505. - 46 46 46 18 18 18 6 6 6 0 0 0
  112506. - 0 0 0 0 0 0 0 0 0 0 0 0
  112507. - 0 0 0 0 0 0 0 0 0 0 0 0
  112508. - 0 0 0 0 0 0 6 6 6 18 18 18
  112509. - 50 50 50 109 106 95 192 133 9 224 166 10
  112510. -242 186 14 246 190 14 246 190 14 246 190 14
  112511. -246 190 14 246 190 14 246 190 14 246 190 14
  112512. -246 190 14 246 190 14 246 190 14 246 190 14
  112513. -246 190 14 246 190 14 246 190 14 246 190 14
  112514. -242 186 14 226 184 13 210 162 10 142 110 46
  112515. -226 226 226 253 253 253 253 253 253 253 253 253
  112516. -253 253 253 253 253 253 253 253 253 253 253 253
  112517. -253 253 253 253 253 253 253 253 253 253 253 253
  112518. -198 198 198 66 66 66 2 2 6 2 2 6
  112519. - 2 2 6 2 2 6 50 34 6 156 107 11
  112520. -219 162 10 239 182 13 246 186 14 246 190 14
  112521. -246 190 14 246 190 14 246 190 14 246 190 14
  112522. -246 190 14 246 190 14 246 190 14 246 190 14
  112523. -246 190 14 246 190 14 246 190 14 242 186 14
  112524. -234 174 13 213 154 11 154 122 46 66 66 66
  112525. - 30 30 30 10 10 10 0 0 0 0 0 0
  112526. - 0 0 0 0 0 0 0 0 0 0 0 0
  112527. - 0 0 0 0 0 0 0 0 0 0 0 0
  112528. - 0 0 0 0 0 0 6 6 6 22 22 22
  112529. - 58 58 58 154 121 60 206 145 10 234 174 13
  112530. -242 186 14 246 186 14 246 190 14 246 190 14
  112531. -246 190 14 246 190 14 246 190 14 246 190 14
  112532. -246 190 14 246 190 14 246 190 14 246 190 14
  112533. -246 190 14 246 190 14 246 190 14 246 190 14
  112534. -246 186 14 236 178 12 210 162 10 163 110 8
  112535. - 61 42 6 138 138 138 218 218 218 250 250 250
  112536. -253 253 253 253 253 253 253 253 253 250 250 250
  112537. -242 242 242 210 210 210 144 144 144 66 66 66
  112538. - 6 6 6 2 2 6 2 2 6 2 2 6
  112539. - 2 2 6 2 2 6 61 42 6 163 110 8
  112540. -216 158 10 236 178 12 246 190 14 246 190 14
  112541. -246 190 14 246 190 14 246 190 14 246 190 14
  112542. -246 190 14 246 190 14 246 190 14 246 190 14
  112543. -246 190 14 239 182 13 230 174 11 216 158 10
  112544. -190 142 34 124 112 88 70 70 70 38 38 38
  112545. - 18 18 18 6 6 6 0 0 0 0 0 0
  112546. - 0 0 0 0 0 0 0 0 0 0 0 0
  112547. - 0 0 0 0 0 0 0 0 0 0 0 0
  112548. - 0 0 0 0 0 0 6 6 6 22 22 22
  112549. - 62 62 62 168 124 44 206 145 10 224 166 10
  112550. -236 178 12 239 182 13 242 186 14 242 186 14
  112551. -246 186 14 246 190 14 246 190 14 246 190 14
  112552. -246 190 14 246 190 14 246 190 14 246 190 14
  112553. -246 190 14 246 190 14 246 190 14 246 190 14
  112554. -246 190 14 236 178 12 216 158 10 175 118 6
  112555. - 80 54 7 2 2 6 6 6 6 30 30 30
  112556. - 54 54 54 62 62 62 50 50 50 38 38 38
  112557. - 14 14 14 2 2 6 2 2 6 2 2 6
  112558. - 2 2 6 2 2 6 2 2 6 2 2 6
  112559. - 2 2 6 6 6 6 80 54 7 167 114 7
  112560. -213 154 11 236 178 12 246 190 14 246 190 14
  112561. -246 190 14 246 190 14 246 190 14 246 190 14
  112562. -246 190 14 242 186 14 239 182 13 239 182 13
  112563. -230 174 11 210 150 10 174 135 50 124 112 88
  112564. - 82 82 82 54 54 54 34 34 34 18 18 18
  112565. - 6 6 6 0 0 0 0 0 0 0 0 0
  112566. - 0 0 0 0 0 0 0 0 0 0 0 0
  112567. - 0 0 0 0 0 0 0 0 0 0 0 0
  112568. - 0 0 0 0 0 0 6 6 6 18 18 18
  112569. - 50 50 50 158 118 36 192 133 9 200 144 11
  112570. -216 158 10 219 162 10 224 166 10 226 170 11
  112571. -230 174 11 236 178 12 239 182 13 239 182 13
  112572. -242 186 14 246 186 14 246 190 14 246 190 14
  112573. -246 190 14 246 190 14 246 190 14 246 190 14
  112574. -246 186 14 230 174 11 210 150 10 163 110 8
  112575. -104 69 6 10 10 10 2 2 6 2 2 6
  112576. - 2 2 6 2 2 6 2 2 6 2 2 6
  112577. - 2 2 6 2 2 6 2 2 6 2 2 6
  112578. - 2 2 6 2 2 6 2 2 6 2 2 6
  112579. - 2 2 6 6 6 6 91 60 6 167 114 7
  112580. -206 145 10 230 174 11 242 186 14 246 190 14
  112581. -246 190 14 246 190 14 246 186 14 242 186 14
  112582. -239 182 13 230 174 11 224 166 10 213 154 11
  112583. -180 133 36 124 112 88 86 86 86 58 58 58
  112584. - 38 38 38 22 22 22 10 10 10 6 6 6
  112585. - 0 0 0 0 0 0 0 0 0 0 0 0
  112586. - 0 0 0 0 0 0 0 0 0 0 0 0
  112587. - 0 0 0 0 0 0 0 0 0 0 0 0
  112588. - 0 0 0 0 0 0 0 0 0 14 14 14
  112589. - 34 34 34 70 70 70 138 110 50 158 118 36
  112590. -167 114 7 180 123 7 192 133 9 197 138 11
  112591. -200 144 11 206 145 10 213 154 11 219 162 10
  112592. -224 166 10 230 174 11 239 182 13 242 186 14
  112593. -246 186 14 246 186 14 246 186 14 246 186 14
  112594. -239 182 13 216 158 10 185 133 11 152 99 6
  112595. -104 69 6 18 14 6 2 2 6 2 2 6
  112596. - 2 2 6 2 2 6 2 2 6 2 2 6
  112597. - 2 2 6 2 2 6 2 2 6 2 2 6
  112598. - 2 2 6 2 2 6 2 2 6 2 2 6
  112599. - 2 2 6 6 6 6 80 54 7 152 99 6
  112600. -192 133 9 219 162 10 236 178 12 239 182 13
  112601. -246 186 14 242 186 14 239 182 13 236 178 12
  112602. -224 166 10 206 145 10 192 133 9 154 121 60
  112603. - 94 94 94 62 62 62 42 42 42 22 22 22
  112604. - 14 14 14 6 6 6 0 0 0 0 0 0
  112605. - 0 0 0 0 0 0 0 0 0 0 0 0
  112606. - 0 0 0 0 0 0 0 0 0 0 0 0
  112607. - 0 0 0 0 0 0 0 0 0 0 0 0
  112608. - 0 0 0 0 0 0 0 0 0 6 6 6
  112609. - 18 18 18 34 34 34 58 58 58 78 78 78
  112610. -101 98 89 124 112 88 142 110 46 156 107 11
  112611. -163 110 8 167 114 7 175 118 6 180 123 7
  112612. -185 133 11 197 138 11 210 150 10 219 162 10
  112613. -226 170 11 236 178 12 236 178 12 234 174 13
  112614. -219 162 10 197 138 11 163 110 8 130 83 6
  112615. - 91 60 6 10 10 10 2 2 6 2 2 6
  112616. - 18 18 18 38 38 38 38 38 38 38 38 38
  112617. - 38 38 38 38 38 38 38 38 38 38 38 38
  112618. - 38 38 38 38 38 38 26 26 26 2 2 6
  112619. - 2 2 6 6 6 6 70 47 6 137 92 6
  112620. -175 118 6 200 144 11 219 162 10 230 174 11
  112621. -234 174 13 230 174 11 219 162 10 210 150 10
  112622. -192 133 9 163 110 8 124 112 88 82 82 82
  112623. - 50 50 50 30 30 30 14 14 14 6 6 6
  112624. - 0 0 0 0 0 0 0 0 0 0 0 0
  112625. - 0 0 0 0 0 0 0 0 0 0 0 0
  112626. - 0 0 0 0 0 0 0 0 0 0 0 0
  112627. - 0 0 0 0 0 0 0 0 0 0 0 0
  112628. - 0 0 0 0 0 0 0 0 0 0 0 0
  112629. - 6 6 6 14 14 14 22 22 22 34 34 34
  112630. - 42 42 42 58 58 58 74 74 74 86 86 86
  112631. -101 98 89 122 102 70 130 98 46 121 87 25
  112632. -137 92 6 152 99 6 163 110 8 180 123 7
  112633. -185 133 11 197 138 11 206 145 10 200 144 11
  112634. -180 123 7 156 107 11 130 83 6 104 69 6
  112635. - 50 34 6 54 54 54 110 110 110 101 98 89
  112636. - 86 86 86 82 82 82 78 78 78 78 78 78
  112637. - 78 78 78 78 78 78 78 78 78 78 78 78
  112638. - 78 78 78 82 82 82 86 86 86 94 94 94
  112639. -106 106 106 101 101 101 86 66 34 124 80 6
  112640. -156 107 11 180 123 7 192 133 9 200 144 11
  112641. -206 145 10 200 144 11 192 133 9 175 118 6
  112642. -139 102 15 109 106 95 70 70 70 42 42 42
  112643. - 22 22 22 10 10 10 0 0 0 0 0 0
  112644. - 0 0 0 0 0 0 0 0 0 0 0 0
  112645. - 0 0 0 0 0 0 0 0 0 0 0 0
  112646. - 0 0 0 0 0 0 0 0 0 0 0 0
  112647. - 0 0 0 0 0 0 0 0 0 0 0 0
  112648. - 0 0 0 0 0 0 0 0 0 0 0 0
  112649. - 0 0 0 0 0 0 6 6 6 10 10 10
  112650. - 14 14 14 22 22 22 30 30 30 38 38 38
  112651. - 50 50 50 62 62 62 74 74 74 90 90 90
  112652. -101 98 89 112 100 78 121 87 25 124 80 6
  112653. -137 92 6 152 99 6 152 99 6 152 99 6
  112654. -138 86 6 124 80 6 98 70 6 86 66 30
  112655. -101 98 89 82 82 82 58 58 58 46 46 46
  112656. - 38 38 38 34 34 34 34 34 34 34 34 34
  112657. - 34 34 34 34 34 34 34 34 34 34 34 34
  112658. - 34 34 34 34 34 34 38 38 38 42 42 42
  112659. - 54 54 54 82 82 82 94 86 76 91 60 6
  112660. -134 86 6 156 107 11 167 114 7 175 118 6
  112661. -175 118 6 167 114 7 152 99 6 121 87 25
  112662. -101 98 89 62 62 62 34 34 34 18 18 18
  112663. - 6 6 6 0 0 0 0 0 0 0 0 0
  112664. - 0 0 0 0 0 0 0 0 0 0 0 0
  112665. - 0 0 0 0 0 0 0 0 0 0 0 0
  112666. - 0 0 0 0 0 0 0 0 0 0 0 0
  112667. - 0 0 0 0 0 0 0 0 0 0 0 0
  112668. - 0 0 0 0 0 0 0 0 0 0 0 0
  112669. - 0 0 0 0 0 0 0 0 0 0 0 0
  112670. - 0 0 0 6 6 6 6 6 6 10 10 10
  112671. - 18 18 18 22 22 22 30 30 30 42 42 42
  112672. - 50 50 50 66 66 66 86 86 86 101 98 89
  112673. -106 86 58 98 70 6 104 69 6 104 69 6
  112674. -104 69 6 91 60 6 82 62 34 90 90 90
  112675. - 62 62 62 38 38 38 22 22 22 14 14 14
  112676. - 10 10 10 10 10 10 10 10 10 10 10 10
  112677. - 10 10 10 10 10 10 6 6 6 10 10 10
  112678. - 10 10 10 10 10 10 10 10 10 14 14 14
  112679. - 22 22 22 42 42 42 70 70 70 89 81 66
  112680. - 80 54 7 104 69 6 124 80 6 137 92 6
  112681. -134 86 6 116 81 8 100 82 52 86 86 86
  112682. - 58 58 58 30 30 30 14 14 14 6 6 6
  112683. - 0 0 0 0 0 0 0 0 0 0 0 0
  112684. - 0 0 0 0 0 0 0 0 0 0 0 0
  112685. - 0 0 0 0 0 0 0 0 0 0 0 0
  112686. - 0 0 0 0 0 0 0 0 0 0 0 0
  112687. - 0 0 0 0 0 0 0 0 0 0 0 0
  112688. - 0 0 0 0 0 0 0 0 0 0 0 0
  112689. - 0 0 0 0 0 0 0 0 0 0 0 0
  112690. - 0 0 0 0 0 0 0 0 0 0 0 0
  112691. - 0 0 0 6 6 6 10 10 10 14 14 14
  112692. - 18 18 18 26 26 26 38 38 38 54 54 54
  112693. - 70 70 70 86 86 86 94 86 76 89 81 66
  112694. - 89 81 66 86 86 86 74 74 74 50 50 50
  112695. - 30 30 30 14 14 14 6 6 6 0 0 0
  112696. - 0 0 0 0 0 0 0 0 0 0 0 0
  112697. - 0 0 0 0 0 0 0 0 0 0 0 0
  112698. - 0 0 0 0 0 0 0 0 0 0 0 0
  112699. - 6 6 6 18 18 18 34 34 34 58 58 58
  112700. - 82 82 82 89 81 66 89 81 66 89 81 66
  112701. - 94 86 66 94 86 76 74 74 74 50 50 50
  112702. - 26 26 26 14 14 14 6 6 6 0 0 0
  112703. - 0 0 0 0 0 0 0 0 0 0 0 0
  112704. - 0 0 0 0 0 0 0 0 0 0 0 0
  112705. - 0 0 0 0 0 0 0 0 0 0 0 0
  112706. - 0 0 0 0 0 0 0 0 0 0 0 0
  112707. - 0 0 0 0 0 0 0 0 0 0 0 0
  112708. - 0 0 0 0 0 0 0 0 0 0 0 0
  112709. - 0 0 0 0 0 0 0 0 0 0 0 0
  112710. - 0 0 0 0 0 0 0 0 0 0 0 0
  112711. - 0 0 0 0 0 0 0 0 0 0 0 0
  112712. - 6 6 6 6 6 6 14 14 14 18 18 18
  112713. - 30 30 30 38 38 38 46 46 46 54 54 54
  112714. - 50 50 50 42 42 42 30 30 30 18 18 18
  112715. - 10 10 10 0 0 0 0 0 0 0 0 0
  112716. - 0 0 0 0 0 0 0 0 0 0 0 0
  112717. - 0 0 0 0 0 0 0 0 0 0 0 0
  112718. - 0 0 0 0 0 0 0 0 0 0 0 0
  112719. - 0 0 0 6 6 6 14 14 14 26 26 26
  112720. - 38 38 38 50 50 50 58 58 58 58 58 58
  112721. - 54 54 54 42 42 42 30 30 30 18 18 18
  112722. - 10 10 10 0 0 0 0 0 0 0 0 0
  112723. - 0 0 0 0 0 0 0 0 0 0 0 0
  112724. - 0 0 0 0 0 0 0 0 0 0 0 0
  112725. - 0 0 0 0 0 0 0 0 0 0 0 0
  112726. - 0 0 0 0 0 0 0 0 0 0 0 0
  112727. - 0 0 0 0 0 0 0 0 0 0 0 0
  112728. - 0 0 0 0 0 0 0 0 0 0 0 0
  112729. - 0 0 0 0 0 0 0 0 0 0 0 0
  112730. - 0 0 0 0 0 0 0 0 0 0 0 0
  112731. - 0 0 0 0 0 0 0 0 0 0 0 0
  112732. - 0 0 0 0 0 0 0 0 0 6 6 6
  112733. - 6 6 6 10 10 10 14 14 14 18 18 18
  112734. - 18 18 18 14 14 14 10 10 10 6 6 6
  112735. - 0 0 0 0 0 0 0 0 0 0 0 0
  112736. - 0 0 0 0 0 0 0 0 0 0 0 0
  112737. - 0 0 0 0 0 0 0 0 0 0 0 0
  112738. - 0 0 0 0 0 0 0 0 0 0 0 0
  112739. - 0 0 0 0 0 0 0 0 0 6 6 6
  112740. - 14 14 14 18 18 18 22 22 22 22 22 22
  112741. - 18 18 18 14 14 14 10 10 10 6 6 6
  112742. - 0 0 0 0 0 0 0 0 0 0 0 0
  112743. - 0 0 0 0 0 0 0 0 0 0 0 0
  112744. - 0 0 0 0 0 0 0 0 0 0 0 0
  112745. - 0 0 0 0 0 0 0 0 0 0 0 0
  112746. - 0 0 0 0 0 0 0 0 0 0 0 0
  112747. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112748. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112749. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112750. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112751. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112752. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112753. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112754. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112755. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112756. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112757. +0 0 0 0 0 0 0 0 0
  112758. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112759. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112760. +0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0
  112761. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112762. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112763. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112764. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112765. +0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
  112766. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112767. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112768. +0 0 0 0 0 0 0 0 0
  112769. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112770. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  112771. +10 15 3 2 3 1 12 18 4 42 61 14 19 27 6 11 16 4
  112772. +38 55 13 10 15 3 3 4 1 10 15 3 0 0 0 0 0 0
  112773. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112774. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112775. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 1
  112776. +12 18 4 1 1 0 23 34 8 31 45 11 10 15 3 32 47 11
  112777. +34 49 12 3 4 1 3 4 1 3 4 1 0 0 0 0 0 0
  112778. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112779. +0 0 0 0 0 0 0 0 0
  112780. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112781. +0 0 0 0 0 0 10 15 3 29 42 10 26 37 9 12 18 4
  112782. +55 80 19 81 118 28 55 80 19 92 132 31 106 153 36 69 100 23
  112783. +100 144 34 80 116 27 42 61 14 81 118 28 23 34 8 27 40 9
  112784. +15 21 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112785. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112786. +0 0 0 0 0 0 1 1 0 29 42 10 15 21 5 50 72 17
  112787. +74 107 25 45 64 15 102 148 35 80 116 27 84 121 28 111 160 38
  112788. +69 100 23 65 94 22 81 118 28 29 42 10 17 25 6 29 42 10
  112789. +23 34 8 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  112790. +0 0 0 0 0 0 0 0 0
  112791. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  112792. +15 21 5 15 21 5 34 49 12 101 146 34 111 161 38 97 141 33
  112793. +97 141 33 119 172 41 117 170 40 116 167 40 118 170 40 118 171 40
  112794. +117 169 40 118 170 40 111 160 38 118 170 40 96 138 32 89 128 30
  112795. +81 118 28 11 16 4 10 15 3 1 1 0 0 0 0 0 0 0
  112796. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112797. +3 4 1 3 4 1 34 49 12 101 146 34 79 115 27 111 160 38
  112798. +114 165 39 113 163 39 118 170 40 117 169 40 118 171 40 117 169 40
  112799. +116 167 40 119 172 41 113 163 39 92 132 31 105 151 36 113 163 39
  112800. +75 109 26 19 27 6 16 23 5 11 16 4 0 1 0 0 0 0
  112801. +0 0 0 0 0 0 0 0 0
  112802. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  112803. +80 116 27 106 153 36 105 151 36 114 165 39 118 170 40 118 171 40
  112804. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112805. +117 169 40 117 169 40 117 170 40 117 169 40 118 170 40 118 170 40
  112806. +117 170 40 75 109 26 75 109 26 34 49 12 0 0 0 0 0 0
  112807. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  112808. +64 92 22 65 94 22 100 144 34 118 171 40 118 170 40 117 169 40
  112809. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112810. +117 169 40 117 169 40 117 169 40 118 171 41 118 170 40 117 169 40
  112811. +109 158 37 105 151 36 104 150 35 47 69 16 0 0 0 0 0 0
  112812. +0 0 0 0 0 0 0 0 0
  112813. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112814. +42 61 14 115 167 39 118 170 40 117 169 40 117 169 40 117 169 40
  112815. +117 170 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  112816. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112817. +117 169 40 117 169 40 118 170 40 96 138 32 17 25 6 0 0 0
  112818. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 69 16
  112819. +114 165 39 117 168 40 117 170 40 117 169 40 117 169 40 117 169 40
  112820. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112821. +117 169 40 117 169 40 118 170 40 117 169 40 117 169 40 117 169 40
  112822. +117 170 40 119 172 41 96 138 32 12 18 4 0 0 0 0 0 0
  112823. +0 0 0 0 0 0 0 0 0
  112824. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  112825. +32 47 11 105 151 36 118 170 40 117 169 40 117 169 40 116 168 40
  112826. +109 157 37 111 160 38 117 169 40 118 171 40 117 169 40 117 169 40
  112827. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112828. +117 169 40 117 169 40 117 169 40 118 171 40 69 100 23 2 3 1
  112829. +0 0 0 0 0 0 0 0 0 0 0 0 19 27 6 101 146 34
  112830. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112831. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 170 40
  112832. +118 171 40 115 166 39 107 154 36 111 161 38 117 169 40 117 169 40
  112833. +117 169 40 118 171 40 75 109 26 19 27 6 2 3 1 0 0 0
  112834. +0 0 0 0 0 0 0 0 0
  112835. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 23 5
  112836. +89 128 30 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112837. +111 160 38 92 132 31 79 115 27 96 138 32 115 166 39 119 171 41
  112838. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112839. +117 169 40 117 169 40 117 169 40 118 170 40 109 157 37 26 37 9
  112840. +0 0 0 0 0 0 0 0 0 0 0 0 64 92 22 118 171 40
  112841. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112842. +117 169 40 117 169 40 117 169 40 118 170 40 118 171 40 109 157 37
  112843. +89 128 30 81 118 28 100 144 34 115 166 39 117 169 40 117 169 40
  112844. +117 169 40 117 170 40 113 163 39 60 86 20 1 1 0 0 0 0
  112845. +0 0 0 0 0 0 0 0 0
  112846. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112847. +27 40 9 96 138 32 118 170 40 117 169 40 117 169 40 117 169 40
  112848. +117 170 40 117 169 40 101 146 34 67 96 23 55 80 19 84 121 28
  112849. +113 163 39 119 171 41 117 169 40 117 169 40 117 169 40 117 169 40
  112850. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 65 94 22
  112851. +0 0 0 0 0 0 0 0 0 15 21 5 101 146 34 118 171 40
  112852. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112853. +117 169 40 118 170 40 118 171 40 104 150 35 69 100 23 53 76 18
  112854. +81 118 28 111 160 38 118 170 40 117 169 40 117 169 40 117 169 40
  112855. +117 169 40 114 165 39 69 100 23 10 15 3 0 0 0 0 0 0
  112856. +0 0 0 0 0 0 0 0 0
  112857. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  112858. +31 45 11 77 111 26 117 169 40 117 169 40 117 169 40 117 169 40
  112859. +117 169 40 117 169 40 118 170 40 116 168 40 92 132 31 47 69 16
  112860. +38 55 13 81 118 28 113 163 39 119 171 41 117 169 40 117 169 40
  112861. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 41 92 132 31
  112862. +10 15 3 0 0 0 0 0 0 36 52 12 115 166 39 117 169 40
  112863. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  112864. +118 171 40 102 148 35 64 92 22 34 49 12 65 94 22 106 153 36
  112865. +118 171 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  112866. +118 170 40 107 154 36 55 80 19 15 21 5 0 0 0 0 0 0
  112867. +0 0 0 0 0 0 0 0 0
  112868. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112869. +29 42 10 101 146 34 118 171 40 117 169 40 117 169 40 117 169 40
  112870. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 113 163 39
  112871. +75 109 26 27 40 9 36 52 12 89 128 30 116 167 40 118 171 40
  112872. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 104 150 35
  112873. +16 23 5 0 0 0 0 0 0 53 76 18 118 171 40 117 169 40
  112874. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 109 157 37
  112875. +67 96 23 23 34 8 42 61 14 96 138 32 118 170 40 118 170 40
  112876. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112877. +117 169 40 117 169 40 74 107 25 10 15 3 0 0 0 0 0 0
  112878. +0 0 0 0 0 0 0 0 0
  112879. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112880. +0 0 0 31 45 11 101 146 34 118 170 40 117 169 40 117 169 40
  112881. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112882. +119 171 41 102 148 35 47 69 16 14 20 5 50 72 17 102 148 35
  112883. +118 171 40 117 169 40 117 169 40 117 169 40 118 170 40 102 148 35
  112884. +15 21 5 0 0 0 0 0 0 50 72 17 118 170 40 117 169 40
  112885. +117 169 40 117 169 40 118 170 40 116 167 40 84 121 28 27 40 9
  112886. +19 27 6 74 107 25 114 165 39 118 171 40 117 169 40 117 169 40
  112887. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112888. +117 169 40 75 109 26 10 15 4 0 0 0 0 0 0 0 0 0
  112889. +0 0 0 0 0 0 0 0 0
  112890. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112891. +0 0 0 38 55 13 102 148 35 118 171 40 117 169 40 117 169 40
  112892. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112893. +117 169 40 118 170 40 115 167 39 77 111 26 17 25 6 19 27 6
  112894. +77 111 26 115 166 39 118 170 40 117 169 40 119 172 41 81 118 28
  112895. +3 4 1 0 0 0 0 0 0 27 40 9 111 160 38 118 170 40
  112896. +117 169 40 118 171 40 105 151 36 50 72 17 10 15 3 38 55 13
  112897. +100 144 34 118 171 40 117 169 40 117 169 40 117 169 40 117 169 40
  112898. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112899. +117 169 40 79 115 27 15 21 5 0 0 0 0 0 0 0 0 0
  112900. +0 0 0 0 0 0 0 0 0
  112901. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112902. +0 0 0 10 15 3 64 92 22 111 160 38 117 169 40 117 169 40
  112903. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112904. +117 169 40 117 169 40 117 169 40 118 171 40 96 138 32 32 47 11
  112905. +3 4 1 50 72 17 107 154 36 120 173 41 105 151 36 31 45 11
  112906. +0 0 0 0 0 0 0 0 0 3 4 1 65 94 22 117 169 40
  112907. +118 170 40 89 128 30 26 37 9 3 4 1 60 86 20 111 161 38
  112908. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112909. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112910. +97 141 33 36 52 12 1 1 0 0 0 0 0 0 0 0 0 0
  112911. +0 0 0 0 0 0 0 0 0
  112912. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112913. +0 0 0 0 0 0 14 20 5 75 109 26 117 168 40 117 169 40
  112914. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112915. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 107 154 36
  112916. +45 64 15 2 3 1 31 45 11 75 109 26 32 47 11 0 1 0
  112917. +0 0 0 0 0 0 0 0 0 0 0 0 10 15 3 55 80 19
  112918. +65 94 22 11 16 4 11 16 4 75 109 26 116 168 40 118 170 40
  112919. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112920. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 107 154 36
  112921. +47 69 16 3 4 1 0 0 0 0 0 0 0 0 0 0 0 0
  112922. +0 0 0 0 0 0 0 0 0
  112923. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112924. +0 0 0 0 0 0 12 18 4 69 100 23 111 161 38 118 171 40
  112925. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112926. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  112927. +111 160 38 50 72 17 2 3 1 2 3 1 0 0 0 0 0 0
  112928. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  112929. +1 1 0 12 18 4 81 118 28 118 170 40 117 169 40 117 169 40
  112930. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112931. +117 169 40 117 169 40 117 169 40 117 170 40 118 171 40 101 146 34
  112932. +42 61 14 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  112933. +0 0 0 0 0 0 0 0 0
  112934. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112935. +0 0 0 0 0 0 0 0 0 3 4 1 36 52 12 89 128 30
  112936. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112937. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112938. +118 171 41 101 146 34 14 20 5 0 0 0 0 0 0 0 0 0
  112939. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112940. +0 0 0 47 69 16 118 170 40 117 169 40 117 169 40 117 169 40
  112941. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112942. +117 169 40 117 169 40 117 170 40 111 160 38 69 100 23 19 27 6
  112943. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112944. +0 0 0 0 0 0 0 0 0
  112945. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112946. +0 0 0 0 0 0 0 0 0 0 0 0 11 16 4 69 100 23
  112947. +115 167 39 119 172 41 117 169 40 117 169 40 117 169 40 117 169 40
  112948. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112949. +119 172 41 75 109 26 3 4 1 0 0 0 0 0 0 0 0 0
  112950. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112951. +0 0 0 23 34 8 106 153 36 118 170 40 117 169 40 117 169 40
  112952. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112953. +117 169 40 118 170 40 119 172 41 105 151 36 42 61 14 2 3 1
  112954. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112955. +0 0 0 0 0 0 0 0 0
  112956. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112957. +0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 15 21 5
  112958. +45 64 15 80 116 27 114 165 39 118 170 40 117 169 40 117 169 40
  112959. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 119 172 41
  112960. +97 141 33 20 30 7 0 0 0 0 0 0 0 0 0 0 0 0
  112961. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112962. +0 0 0 1 1 0 53 76 18 114 165 39 118 171 40 117 169 40
  112963. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  112964. +118 171 40 104 150 35 64 92 22 31 45 11 10 15 3 0 0 0
  112965. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112966. +0 0 0 0 0 0 0 0 0
  112967. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112968. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112969. +0 0 0 36 52 12 97 141 33 109 158 37 113 163 39 116 168 40
  112970. +117 169 40 117 170 40 118 170 40 119 172 41 115 167 39 84 121 28
  112971. +23 34 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112972. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112973. +0 0 0 0 0 0 3 4 1 50 72 17 102 148 35 118 171 40
  112974. +119 171 41 118 170 40 117 169 40 117 169 40 115 166 39 111 161 38
  112975. +109 157 37 79 115 27 12 18 4 0 0 0 0 0 0 0 0 0
  112976. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112977. +0 0 0 0 0 0 0 0 0
  112978. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112979. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112980. +0 0 0 3 4 1 15 21 5 23 34 8 45 64 15 106 153 36
  112981. +116 167 40 111 160 38 101 146 34 79 115 27 42 61 14 10 15 3
  112982. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112983. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112984. +0 0 0 0 0 0 0 0 0 1 1 0 20 30 7 60 86 20
  112985. +89 128 30 106 153 36 113 163 39 117 169 40 84 121 28 29 42 10
  112986. +19 27 6 10 15 3 2 3 1 0 0 0 0 0 0 0 0 0
  112987. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112988. +0 0 0 0 0 0 0 0 0
  112989. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112990. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112991. +0 0 0 0 0 0 0 0 0 0 0 0 16 23 5 38 55 13
  112992. +36 52 12 26 37 9 12 18 4 2 3 1 0 0 0 0 0 0
  112993. +0 0 0 0 0 0 0 0 0 1 0 0 19 2 7 52 5 18
  112994. +78 7 27 88 8 31 81 7 29 56 5 19 25 2 9 3 0 1
  112995. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112996. +3 4 1 19 27 6 31 45 11 38 55 13 32 47 11 3 4 1
  112997. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112998. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112999. +0 0 0 0 0 0 0 0 0
  113000. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113001. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113002. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  113003. +9 0 3 12 1 4 9 0 3 4 0 1 0 0 0 0 0 0
  113004. +0 0 0 0 0 0 28 3 10 99 9 35 156 14 55 182 16 64
  113005. +189 17 66 190 17 67 189 17 66 184 17 65 166 15 58 118 13 41
  113006. +45 4 16 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  113007. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113008. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113009. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113010. +0 0 0 0 0 0 0 0 0
  113011. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113012. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113013. +0 0 0 0 0 0 11 1 4 52 5 18 101 9 35 134 12 47
  113014. +151 14 53 154 14 54 151 14 53 113 10 40 11 1 4 0 0 0
  113015. +3 0 1 67 6 24 159 14 56 190 17 67 190 17 67 188 17 66
  113016. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 191 17 67
  113017. +174 16 61 101 9 35 14 1 5 0 0 0 35 3 12 108 10 38
  113018. +122 11 43 122 11 43 112 10 39 87 8 30 50 5 17 13 1 5
  113019. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113020. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113021. +0 0 0 0 0 0 0 0 0
  113022. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113023. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113024. +3 0 1 56 5 19 141 13 49 182 16 64 191 17 67 191 17 67
  113025. +190 17 67 190 17 67 191 17 67 113 10 40 3 0 1 1 0 0
  113026. +79 7 28 180 16 63 190 17 67 188 17 66 188 17 66 188 17 66
  113027. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113028. +189 17 66 188 17 66 122 11 43 11 1 4 41 4 14 176 16 62
  113029. +191 17 67 191 17 67 191 17 67 190 17 67 181 16 63 146 13 51
  113030. +75 7 26 10 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  113031. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113032. +0 0 0 0 0 0 0 0 0
  113033. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113034. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 1 2
  113035. +90 8 32 178 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  113036. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 41 4 14
  113037. +173 16 61 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  113038. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113039. +188 17 66 188 17 66 188 17 66 88 8 31 1 0 0 89 8 31
  113040. +185 17 65 189 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  113041. +186 17 65 124 11 43 25 2 9 0 0 0 0 0 0 0 0 0
  113042. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113043. +0 0 0 0 0 0 0 0 0
  113044. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113045. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 89 8 31
  113046. +184 17 65 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113047. +190 17 67 151 14 53 34 3 12 0 0 0 0 0 0 79 7 28
  113048. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113049. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113050. +188 17 66 188 17 66 191 17 67 146 13 51 9 1 3 7 1 2
  113051. +108 10 38 187 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  113052. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 0 0 0
  113053. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113054. +0 0 0 0 0 0 0 0 0
  113055. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113056. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 176 16 62
  113057. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  113058. +151 14 53 38 3 13 0 0 0 0 0 0 0 0 0 50 5 17
  113059. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113060. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113061. +188 17 66 188 17 66 191 17 67 141 13 49 7 1 3 0 0 0
  113062. +11 1 4 112 10 39 187 17 66 189 17 66 188 17 66 188 17 66
  113063. +188 17 66 188 17 66 190 17 67 113 10 40 5 0 2 0 0 0
  113064. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113065. +0 0 0 0 0 0 0 0 0
  113066. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113067. +0 0 0 0 0 0 0 0 0 7 1 3 132 12 46 191 17 67
  113068. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 146 13 51
  113069. +35 3 12 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  113070. +101 9 35 185 17 65 190 17 67 188 17 66 188 17 66 188 17 66
  113071. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113072. +188 17 66 190 17 67 180 16 63 67 6 24 0 0 0 0 0 0
  113073. +0 0 0 11 1 4 108 10 38 186 17 65 189 17 66 188 17 66
  113074. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  113075. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113076. +0 0 0 0 0 0 0 0 0
  113077. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113078. +0 0 0 0 0 0 0 0 0 44 4 15 177 16 62 189 17 66
  113079. +188 17 66 188 17 66 189 17 66 189 17 66 134 12 47 28 3 10
  113080. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113081. +8 1 3 79 7 28 159 14 56 188 17 66 191 17 67 190 17 67
  113082. +189 17 66 189 17 66 189 17 66 189 17 66 190 17 67 191 17 67
  113083. +188 17 66 158 14 55 72 7 25 4 0 1 0 0 0 0 0 0
  113084. +0 0 0 0 0 0 8 1 3 95 9 33 182 16 64 189 17 67
  113085. +188 17 66 188 17 66 188 17 66 191 17 67 122 11 43 3 0 1
  113086. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113087. +0 0 0 0 0 0 0 0 0
  113088. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113089. +0 0 0 0 0 0 0 0 0 88 8 31 190 17 67 188 17 66
  113090. +188 17 66 189 17 66 185 17 65 113 10 40 18 2 6 0 0 0
  113091. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113092. +0 0 0 1 0 0 24 2 8 77 7 27 124 11 43 154 14 54
  113093. +168 15 59 173 16 61 173 16 61 168 15 59 154 14 54 124 11 43
  113094. +77 7 27 22 2 8 0 0 0 0 0 0 0 0 0 0 0 0
  113095. +0 0 0 0 0 0 0 0 0 5 0 2 77 7 27 173 16 61
  113096. +190 17 67 188 17 66 188 17 66 190 17 67 164 15 57 23 2 8
  113097. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113098. +0 0 0 0 0 0 0 0 0
  113099. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113100. +0 0 0 0 0 0 1 0 0 118 13 41 191 17 67 188 17 66
  113101. +190 17 67 174 16 61 87 8 30 8 1 3 0 0 0 0 0 0
  113102. +0 0 0 0 0 0 10 1 4 29 3 10 40 4 14 36 3 13
  113103. +18 2 6 2 0 1 0 0 0 0 0 0 3 0 1 14 1 5
  113104. +26 2 9 33 3 11 32 3 11 25 2 9 13 1 5 3 0 1
  113105. +0 0 0 14 1 5 56 5 19 95 9 33 109 10 38 101 9 35
  113106. +77 7 27 35 3 12 5 0 2 0 0 0 1 0 0 56 5 19
  113107. +156 14 55 190 17 67 188 17 66 188 17 66 182 16 64 50 5 17
  113108. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113109. +0 0 0 0 0 0 0 0 0
  113110. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113111. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 189 17 66
  113112. +151 14 53 52 5 18 2 0 1 0 0 0 0 0 0 1 0 0
  113113. +28 3 10 90 8 32 146 13 51 170 15 60 178 16 62 174 16 61
  113114. +158 14 55 112 10 39 40 4 14 1 0 0 0 0 0 0 0 0
  113115. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  113116. +56 5 19 146 13 51 183 17 64 191 17 67 191 17 67 191 17 67
  113117. +188 17 66 173 16 61 122 11 43 41 4 14 1 0 0 0 0 0
  113118. +30 3 10 124 11 43 185 17 65 190 17 67 187 17 66 67 6 24
  113119. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113120. +0 0 0 0 0 0 0 0 0
  113121. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113122. +0 0 0 0 0 0 6 1 2 134 12 47 168 15 59 99 9 35
  113123. +21 2 7 0 0 0 0 0 0 0 0 0 6 1 2 77 7 27
  113124. +162 15 57 190 17 67 191 17 67 189 17 66 189 17 66 189 17 66
  113125. +190 17 67 191 17 67 169 15 59 75 7 26 3 0 1 0 0 0
  113126. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 79 7 28
  113127. +178 16 62 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  113128. +188 17 66 189 17 66 191 17 67 170 15 60 79 7 28 5 0 2
  113129. +0 0 0 10 1 3 78 7 27 159 14 56 188 17 66 75 7 26
  113130. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113131. +0 0 0 0 0 0 0 0 0
  113132. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113133. +0 0 0 0 0 0 1 0 0 35 3 12 29 3 10 2 0 1
  113134. +0 0 0 0 0 0 0 0 0 9 1 3 101 9 35 183 17 64
  113135. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113136. +188 17 66 188 17 66 190 17 67 178 16 63 67 6 23 0 0 0
  113137. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 174 16 61
  113138. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113139. +188 17 66 188 17 66 188 17 66 190 17 67 182 16 64 89 8 31
  113140. +4 0 1 0 0 0 0 0 0 25 2 9 73 7 26 31 3 11
  113141. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113142. +0 0 0 0 0 0 0 0 0
  113143. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113144. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113145. +0 0 0 0 0 0 4 0 1 98 9 34 187 17 66 189 17 66
  113146. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113147. +188 17 66 188 17 66 188 17 66 190 17 67 158 14 55 25 2 9
  113148. +0 0 0 0 0 0 0 0 0 8 1 3 134 12 47 191 17 67
  113149. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113150. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 180 16 63
  113151. +68 6 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113152. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113153. +0 0 0 0 0 0 0 0 0
  113154. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113155. +0 0 0 6 1 2 19 2 7 3 0 1 0 0 0 0 0 0
  113156. +0 0 0 0 0 0 65 6 23 180 16 63 189 17 66 188 17 66
  113157. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113158. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 83 8 29
  113159. +0 0 0 0 0 0 0 0 0 41 4 14 177 16 62 189 17 66
  113160. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113161. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  113162. +159 14 56 28 3 10 0 0 0 0 0 0 0 0 0 23 2 8
  113163. +41 4 14 5 0 2 0 0 0 0 0 0 0 0 0 0 0 0
  113164. +0 0 0 0 0 0 0 0 0
  113165. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113166. +23 2 8 113 10 40 159 14 56 65 6 23 0 0 0 0 0 0
  113167. +0 0 0 16 1 6 146 13 51 191 17 67 188 17 66 188 17 66
  113168. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113169. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 132 12 46
  113170. +5 0 2 0 0 0 0 0 0 77 7 27 189 17 66 188 17 66
  113171. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113172. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113173. +190 17 67 98 9 34 0 0 0 0 0 0 12 1 4 134 12 47
  113174. +178 16 63 108 10 38 16 1 6 0 0 0 0 0 0 0 0 0
  113175. +0 0 0 0 0 0 0 0 0
  113176. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 3 10
  113177. +141 13 49 190 17 67 191 17 67 134 12 47 6 1 2 0 0 0
  113178. +0 0 0 68 6 24 186 17 65 188 17 66 188 17 66 188 17 66
  113179. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113180. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 156 14 55
  113181. +14 1 5 0 0 0 0 0 0 98 9 34 191 17 67 188 17 66
  113182. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113183. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113184. +190 17 67 156 14 55 19 2 7 0 0 0 47 4 16 181 16 63
  113185. +190 17 67 189 17 66 126 14 44 17 2 6 0 0 0 0 0 0
  113186. +0 0 0 0 0 0 0 0 0
  113187. +0 0 0 0 0 0 0 0 0 0 0 0 16 1 6 134 12 47
  113188. +191 17 67 188 17 66 190 17 67 162 15 57 19 2 7 0 0 0
  113189. +3 0 1 123 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  113190. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113191. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 163 15 57
  113192. +20 2 7 0 0 0 0 0 0 101 9 35 191 17 67 188 17 66
  113193. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113194. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113195. +188 17 66 182 16 64 52 5 18 0 0 0 73 7 26 188 17 66
  113196. +188 17 66 188 17 66 189 17 66 109 10 38 5 0 2 0 0 0
  113197. +0 0 0 0 0 0 0 0 0
  113198. +0 0 0 0 0 0 0 0 0 0 0 0 95 9 33 189 17 66
  113199. +188 17 66 188 17 66 189 17 66 171 15 60 29 3 10 0 0 0
  113200. +16 1 6 156 14 55 190 17 67 188 17 66 188 17 66 188 17 66
  113201. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113202. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 158 14 55
  113203. +17 2 6 0 0 0 0 0 0 85 8 30 190 17 67 188 17 66
  113204. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113205. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113206. +188 17 66 189 17 66 81 7 29 0 0 0 85 8 30 190 17 67
  113207. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  113208. +0 0 0 0 0 0 0 0 0
  113209. +0 0 0 0 0 0 0 0 0 25 2 9 162 15 57 190 17 67
  113210. +188 17 66 188 17 66 189 17 66 173 16 61 31 3 11 0 0 0
  113211. +30 3 10 171 15 60 189 17 66 188 17 66 188 17 66 188 17 66
  113212. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113213. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 141 13 49
  113214. +7 1 2 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  113215. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113216. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113217. +188 17 66 191 17 67 98 9 34 0 0 0 88 8 31 190 17 67
  113218. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 5 0 2
  113219. +0 0 0 0 0 0 0 0 0
  113220. +0 0 0 0 0 0 0 0 0 68 6 24 187 17 66 188 17 66
  113221. +188 17 66 188 17 66 189 17 66 170 15 60 28 3 10 0 0 0
  113222. +34 3 12 174 16 61 189 17 66 188 17 66 188 17 66 188 17 66
  113223. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113224. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 101 9 35
  113225. +0 0 0 0 0 0 0 0 0 21 2 7 159 14 56 190 17 67
  113226. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113227. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113228. +188 17 66 191 17 67 98 9 34 0 0 0 81 7 29 189 17 66
  113229. +188 17 66 188 17 66 188 17 66 189 17 66 168 15 59 28 3 10
  113230. +0 0 0 0 0 0 0 0 0
  113231. +0 0 0 0 0 0 0 0 0 109 10 38 191 17 67 188 17 66
  113232. +188 17 66 188 17 66 190 17 67 163 15 57 21 2 7 0 0 0
  113233. +26 2 9 168 15 59 189 17 66 188 17 66 188 17 66 188 17 66
  113234. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113235. +188 17 66 188 17 66 188 17 66 189 17 66 180 16 63 47 4 16
  113236. +0 0 0 0 0 0 0 0 0 0 0 0 108 10 38 190 17 67
  113237. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113238. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113239. +188 17 66 189 17 66 78 7 27 0 0 0 68 6 24 187 17 66
  113240. +188 17 66 188 17 66 188 17 66 188 17 66 183 17 64 56 5 19
  113241. +0 0 0 0 0 0 0 0 0
  113242. +0 0 0 0 0 0 3 0 1 131 12 46 191 17 67 188 17 66
  113243. +188 17 66 188 17 66 190 17 67 151 14 53 12 1 4 0 0 0
  113244. +11 1 4 146 13 51 190 17 67 188 17 66 188 17 66 188 17 66
  113245. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113246. +188 17 66 188 17 66 188 17 66 191 17 67 126 14 44 7 1 2
  113247. +0 0 0 0 0 0 0 0 0 0 0 0 32 3 11 164 15 58
  113248. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113249. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113250. +189 17 66 178 16 62 44 4 15 0 0 0 50 5 17 182 16 64
  113251. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  113252. +0 0 0 0 0 0 0 0 0
  113253. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 188 17 66
  113254. +188 17 66 188 17 66 191 17 67 131 12 46 3 0 1 0 0 0
  113255. +0 0 0 101 9 35 190 17 67 188 17 66 188 17 66 188 17 66
  113256. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113257. +188 17 66 188 17 66 190 17 67 170 15 60 44 4 15 0 0 0
  113258. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 7 27
  113259. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113260. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113261. +191 17 67 134 12 47 9 1 3 0 0 0 31 3 11 171 15 60
  113262. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  113263. +0 0 0 0 0 0 0 0 0
  113264. +0 0 0 0 0 0 2 0 1 124 11 43 191 17 67 188 17 66
  113265. +188 17 66 188 17 66 191 17 67 101 9 35 0 0 0 0 0 0
  113266. +0 0 0 35 3 12 168 15 59 190 17 67 188 17 66 188 17 66
  113267. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113268. +188 17 66 189 17 66 182 16 64 77 7 27 0 0 0 0 0 0
  113269. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2
  113270. +99 9 35 185 17 65 189 17 66 188 17 66 188 17 66 188 17 66
  113271. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  113272. +177 16 62 56 5 19 0 0 0 0 0 0 13 1 5 151 14 53
  113273. +190 17 67 188 17 66 188 17 66 188 17 66 185 17 65 56 5 19
  113274. +0 0 0 0 0 0 0 0 0
  113275. +0 0 0 0 0 0 0 0 0 99 9 35 191 17 67 188 17 66
  113276. +188 17 66 188 17 66 186 17 65 65 6 23 0 0 0 0 0 0
  113277. +0 0 0 0 0 0 79 7 28 182 16 64 190 17 67 188 17 66
  113278. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113279. +191 17 67 177 16 62 83 8 29 4 0 1 0 0 0 0 0 0
  113280. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113281. +8 1 3 89 8 31 175 16 62 191 17 67 189 17 66 188 17 66
  113282. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 181 16 63
  113283. +85 8 30 3 0 1 0 0 0 0 0 0 1 0 0 118 13 41
  113284. +191 17 67 188 17 66 188 17 66 189 17 66 173 16 61 34 3 12
  113285. +0 0 0 0 0 0 0 0 0
  113286. +0 0 0 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  113287. +188 17 66 189 17 66 169 15 59 30 3 10 0 0 0 0 0 0
  113288. +0 0 0 0 0 0 5 0 2 83 8 29 173 16 61 191 17 67
  113289. +190 17 67 189 17 66 189 17 66 190 17 67 191 17 67 187 17 66
  113290. +151 14 53 56 5 19 3 0 1 0 0 0 16 1 6 50 5 17
  113291. +79 7 28 95 9 33 95 9 33 75 7 26 41 4 14 10 1 4
  113292. +0 0 0 2 0 1 50 5 17 132 12 46 178 16 62 190 17 67
  113293. +191 17 67 191 17 67 191 17 67 186 17 65 154 14 54 68 6 24
  113294. +4 0 1 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  113295. +187 17 66 188 17 66 188 17 66 191 17 67 141 13 49 9 1 3
  113296. +0 0 0 0 0 0 0 0 0
  113297. +0 0 0 0 0 0 0 0 0 14 1 5 151 14 53 190 17 67
  113298. +188 17 66 191 17 67 131 12 46 5 0 2 0 0 0 0 0 0
  113299. +0 0 0 0 0 0 0 0 0 2 0 1 44 4 15 113 10 40
  113300. +156 14 55 173 16 61 174 16 61 164 15 58 134 12 47 77 7 27
  113301. +18 2 6 0 0 0 16 1 6 85 8 30 151 14 53 182 16 64
  113302. +189 17 66 191 17 67 190 17 67 188 17 66 177 16 62 141 13 49
  113303. +68 6 24 8 1 3 0 0 0 8 1 3 44 4 15 88 8 31
  113304. +113 10 40 122 11 43 108 10 38 67 6 24 20 2 7 0 0 0
  113305. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 3 10
  113306. +166 15 58 190 17 67 188 17 66 187 17 66 79 7 28 0 0 0
  113307. +0 0 0 0 0 0 0 0 0
  113308. +0 0 0 0 0 0 0 0 0 0 0 0 73 7 26 185 17 65
  113309. +189 17 66 184 17 65 65 6 23 0 0 0 0 0 0 0 0 0
  113310. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1
  113311. +17 2 6 32 3 11 34 3 12 22 2 8 6 1 2 0 0 0
  113312. +0 0 0 38 3 13 141 13 49 188 17 66 190 17 67 188 17 66
  113313. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  113314. +184 17 65 122 11 43 21 2 7 0 0 0 0 0 0 0 0 0
  113315. +0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113316. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  113317. +108 10 38 191 17 67 191 17 67 141 13 49 16 1 6 0 0 0
  113318. +0 0 0 0 0 0 0 0 0
  113319. +0 0 0 0 0 0 0 0 0 0 0 0 8 1 3 112 10 39
  113320. +186 17 65 124 11 43 10 1 4 0 0 0 0 0 0 0 0 0
  113321. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113322. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113323. +36 3 13 156 14 55 191 17 67 188 17 66 188 17 66 188 17 66
  113324. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113325. +189 17 66 190 17 67 134 12 47 18 2 6 0 0 0 0 0 0
  113326. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113327. +0 0 0 7 1 2 41 4 14 75 7 26 66 5 23 19 2 7
  113328. +26 2 9 144 13 50 154 14 54 40 4 14 0 0 0 0 0 0
  113329. +0 0 0 0 0 0 0 0 0
  113330. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  113331. +56 5 19 19 2 7 0 0 0 7 1 2 29 3 10 35 3 12
  113332. +19 2 7 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  113333. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  113334. +134 12 47 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  113335. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113336. +188 17 66 188 17 66 189 17 67 108 10 38 3 0 1 0 0 0
  113337. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  113338. +40 4 14 124 11 43 177 16 62 188 17 66 187 17 66 144 13 50
  113339. +24 2 8 17 2 6 22 2 8 0 0 0 0 0 0 0 0 0
  113340. +0 0 0 0 0 0 0 0 0
  113341. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113342. +0 0 0 0 0 0 19 2 7 122 11 43 171 15 60 175 16 62
  113343. +159 14 56 112 10 39 40 4 14 2 0 1 0 0 0 0 0 0
  113344. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  113345. +186 17 65 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113346. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113347. +188 17 66 188 17 66 189 17 66 174 16 61 41 4 14 0 0 0
  113348. +0 0 0 0 0 0 0 0 0 0 0 0 3 0 1 72 7 25
  113349. +168 15 59 191 17 67 189 17 66 188 17 66 188 17 66 190 17 67
  113350. +95 9 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113351. +0 0 0 0 0 0 0 0 0
  113352. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113353. +0 0 0 0 0 0 95 9 33 191 17 67 189 17 66 189 17 66
  113354. +190 17 67 191 17 67 171 15 60 90 8 32 12 1 4 0 0 0
  113355. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 132 12 46
  113356. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113357. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113358. +188 17 66 188 17 66 188 17 66 190 17 67 98 9 34 0 0 0
  113359. +0 0 0 0 0 0 0 0 0 5 0 2 88 8 31 180 16 63
  113360. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 191 17 67
  113361. +146 13 51 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  113362. +0 0 0 0 0 0 0 0 0
  113363. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113364. +0 0 0 9 1 3 144 13 50 191 17 67 188 17 66 188 17 66
  113365. +188 17 66 188 17 66 189 17 66 187 17 66 123 11 43 20 2 7
  113366. +0 0 0 0 0 0 0 0 0 0 0 0 21 2 7 163 15 57
  113367. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113368. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113369. +188 17 66 188 17 66 188 17 66 191 17 67 134 12 47 5 0 2
  113370. +0 0 0 0 0 0 3 0 1 88 8 31 182 16 64 189 17 66
  113371. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  113372. +171 15 60 31 3 11 0 0 0 0 0 0 0 0 0 0 0 0
  113373. +0 0 0 0 0 0 0 0 0
  113374. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113375. +0 0 0 20 2 7 162 15 57 190 17 67 188 17 66 188 17 66
  113376. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 132 12 46
  113377. +20 2 7 0 0 0 0 0 0 0 0 0 32 3 11 173 16 61
  113378. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113379. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113380. +188 17 66 188 17 66 188 17 66 190 17 67 151 14 53 12 1 4
  113381. +0 0 0 0 0 0 72 7 25 180 16 63 189 17 66 188 17 66
  113382. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113383. +181 16 63 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  113384. +0 0 0 0 0 0 0 0 0
  113385. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113386. +0 0 0 21 2 7 163 15 57 190 17 67 188 17 66 188 17 66
  113387. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  113388. +122 11 43 9 1 3 0 0 0 0 0 0 30 3 10 171 15 60
  113389. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113390. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113391. +188 17 66 188 17 66 188 17 66 190 17 67 146 13 51 10 1 4
  113392. +0 0 0 38 3 13 166 15 58 190 17 67 188 17 66 188 17 66
  113393. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113394. +183 17 64 52 5 18 0 0 0 0 0 0 0 0 0 0 0 0
  113395. +0 0 0 0 0 0 0 0 0
  113396. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113397. +0 0 0 13 1 5 154 14 54 190 17 67 188 17 66 188 17 66
  113398. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113399. +186 17 65 79 7 28 0 0 0 0 0 0 14 1 5 156 14 54
  113400. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113401. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113402. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 2 0 1
  113403. +5 0 2 122 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  113404. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113405. +182 16 64 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  113406. +0 0 0 0 0 0 0 0 0
  113407. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113408. +0 0 0 3 0 1 126 14 44 191 17 67 188 17 66 188 17 66
  113409. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113410. +190 17 67 158 14 55 23 2 8 0 0 0 1 0 0 113 10 40
  113411. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113412. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113413. +188 17 66 188 17 66 188 17 66 188 17 66 78 7 27 0 0 0
  113414. +47 4 16 177 16 62 189 17 66 188 17 66 188 17 66 188 17 66
  113415. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  113416. +173 16 61 34 3 12 0 0 0 0 0 0 0 0 0 0 0 0
  113417. +0 0 0 0 0 0 0 0 0
  113418. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113419. +0 0 0 0 0 0 85 8 30 189 17 66 188 17 66 188 17 66
  113420. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113421. +188 17 66 188 17 66 79 7 28 0 0 0 0 0 0 47 4 16
  113422. +175 16 62 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113423. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113424. +188 17 66 188 17 66 190 17 67 156 14 55 22 2 8 0 0 0
  113425. +109 10 38 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  113426. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  113427. +151 14 53 13 1 5 0 0 0 0 0 0 0 0 0 0 0 0
  113428. +0 0 0 0 0 0 0 0 0
  113429. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113430. +0 0 0 0 0 0 35 3 12 173 16 61 189 17 66 188 17 66
  113431. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113432. +188 17 66 191 17 67 134 12 47 7 1 2 0 0 0 3 0 1
  113433. +99 9 35 188 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  113434. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113435. +188 17 66 189 17 66 181 16 63 68 6 24 0 0 0 18 2 6
  113436. +156 14 55 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  113437. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  113438. +101 9 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113439. +0 0 0 0 0 0 0 0 0
  113440. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113441. +0 0 0 0 0 0 3 0 1 118 13 41 191 17 67 188 17 66
  113442. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113443. +188 17 66 189 17 66 168 15 59 28 3 10 0 0 0 0 0 0
  113444. +12 1 4 113 10 40 187 17 66 189 17 67 188 17 66 188 17 66
  113445. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113446. +190 17 67 180 16 63 88 8 31 4 0 1 0 0 0 47 4 16
  113447. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113448. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 168 15 59
  113449. +36 3 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113450. +0 0 0 0 0 0 0 0 0
  113451. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113452. +0 0 0 0 0 0 0 0 0 38 3 13 164 15 58 190 17 67
  113453. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113454. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  113455. +0 0 0 11 1 4 90 8 32 169 15 59 190 17 67 190 17 67
  113456. +189 17 66 189 17 66 189 17 66 189 17 66 191 17 67 189 17 66
  113457. +158 14 55 68 6 24 4 0 1 0 0 0 0 0 0 73 7 26
  113458. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113459. +188 17 66 188 17 66 188 17 66 189 17 66 185 17 65 83 8 29
  113460. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113461. +0 0 0 0 0 0 0 0 0
  113462. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113463. +0 0 0 0 0 0 0 0 0 0 0 0 65 6 23 174 16 61
  113464. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113465. +188 17 66 188 17 66 185 17 65 56 5 19 0 0 0 0 0 0
  113466. +0 0 0 0 0 0 2 0 1 35 3 12 99 9 35 146 13 51
  113467. +170 15 60 177 16 62 177 16 62 166 15 58 141 13 49 85 8 30
  113468. +24 2 8 0 0 0 0 0 0 0 0 0 0 0 0 85 8 30
  113469. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113470. +188 17 66 188 17 66 188 17 66 189 17 66 112 10 39 8 1 3
  113471. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113472. +0 0 0 0 0 0 0 0 0
  113473. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113474. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 68 6 24
  113475. +170 15 60 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  113476. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  113477. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 11 1 4
  113478. +28 3 10 40 4 14 38 3 13 25 2 9 8 1 3 0 0 0
  113479. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 78 7 27
  113480. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113481. +188 17 66 189 17 66 187 17 66 113 10 40 14 1 5 0 0 0
  113482. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113483. +0 0 0 0 0 0 0 0 0
  113484. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113485. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  113486. +47 4 16 141 13 49 186 17 65 191 17 67 190 17 67 189 17 66
  113487. +189 17 66 191 17 67 156 14 55 20 2 7 0 0 0 0 0 0
  113488. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113489. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113490. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 4 15
  113491. +178 16 62 190 17 67 188 17 66 188 17 66 188 17 66 190 17 67
  113492. +191 17 67 173 16 61 90 8 32 10 1 4 0 0 0 0 0 0
  113493. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113494. +0 0 0 0 0 0 0 0 0
  113495. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113496. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113497. +0 0 0 14 1 5 68 6 24 131 12 46 162 15 57 174 16 61
  113498. +171 15 60 146 13 51 56 5 19 0 0 0 0 0 0 0 0 0
  113499. +0 0 0 0 0 0 0 0 0 3 0 1 14 1 5 29 3 10
  113500. +41 4 14 47 4 16 50 5 17 45 4 16 34 3 12 18 2 6
  113501. +5 0 2 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  113502. +90 8 32 169 15 59 185 17 65 187 17 66 182 16 64 163 15 57
  113503. +113 10 40 41 4 14 2 0 1 0 0 0 0 0 0 0 0 0
  113504. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113505. +0 0 0 0 0 0 0 0 0
  113506. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113507. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113508. +0 0 0 0 0 0 0 0 0 5 0 2 21 2 7 34 3 12
  113509. +29 3 10 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  113510. +3 0 1 32 3 11 79 7 28 124 11 43 154 14 54 171 15 60
  113511. +180 16 63 182 16 64 182 16 64 180 16 63 174 16 61 159 14 56
  113512. +132 12 46 88 8 31 34 3 12 3 0 1 0 0 0 0 0 0
  113513. +3 0 1 29 3 10 56 5 19 65 6 23 50 5 17 23 2 8
  113514. +3 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113515. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113516. +0 0 0 0 0 0 0 0 0
  113517. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113518. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113519. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113520. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 2 9
  113521. +109 10 38 169 15 59 189 17 66 191 17 67 190 17 67 189 17 66
  113522. +189 17 66 188 17 66 188 17 66 188 17 66 189 17 66 190 17 67
  113523. +191 17 67 190 17 67 171 15 60 98 9 34 10 1 3 0 0 0
  113524. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113525. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113526. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113527. +0 0 0 0 0 0 0 0 0
  113528. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113529. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113530. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113531. +0 0 0 0 0 0 0 0 0 0 0 0 14 1 5 141 13 49
  113532. +191 17 67 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113533. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113534. +188 17 66 188 17 66 189 17 67 186 17 65 65 6 23 0 0 0
  113535. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113536. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113537. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113538. +0 0 0 0 0 0 0 0 0
  113539. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113540. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113541. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113542. +0 0 0 0 0 0 0 0 0 0 0 0 23 2 8 166 15 58
  113543. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113544. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113545. +188 17 66 188 17 66 189 17 66 176 16 62 45 4 16 0 0 0
  113546. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113547. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113548. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113549. +0 0 0 0 0 0 0 0 0
  113550. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113551. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113552. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113553. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 83 8 29
  113554. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113555. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113556. +188 17 66 189 17 66 185 17 65 95 9 33 3 0 1 0 0 0
  113557. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113558. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113559. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113560. +0 0 0 0 0 0 0 0 0
  113561. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113562. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113563. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113564. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  113565. +85 8 30 176 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  113566. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113567. +191 17 67 180 16 63 95 9 33 7 1 3 0 0 0 0 0 0
  113568. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113569. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113570. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113571. +0 0 0 0 0 0 0 0 0
  113572. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113573. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113574. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113575. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113576. +2 0 1 52 5 18 141 13 49 185 17 65 191 17 67 189 17 67
  113577. +189 17 66 188 17 66 188 17 66 189 17 66 191 17 67 187 17 66
  113578. +146 13 51 56 5 19 4 0 1 0 0 0 0 0 0 0 0 0
  113579. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113580. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113581. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113582. +0 0 0 0 0 0 0 0 0
  113583. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113584. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113585. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113586. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113587. +0 0 0 0 0 0 14 1 5 68 6 24 131 12 46 166 15 58
  113588. +180 16 63 183 17 64 180 16 63 168 15 59 134 12 47 75 7 26
  113589. +17 2 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113590. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113591. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113592. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113593. +0 0 0 0 0 0 0 0 0
  113594. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113595. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113596. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113597. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113598. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 24 2 8
  113599. +44 4 15 52 5 18 45 4 16 26 2 9 6 1 2 0 0 0
  113600. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113601. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113602. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113603. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113604. +0 0 0 0 0 0 0 0 0
  113605. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113606. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113607. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113608. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113609. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113610. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113611. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113612. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113613. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113614. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113615. +0 0 0 0 0 0 0 0 0
  113616. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113617. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113618. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113619. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113620. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113621. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113622. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113623. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113624. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113625. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113626. +0 0 0 0 0 0 0 0 0
  113627. diff -Nur linux-3.18.6/drivers/w1/masters/w1-gpio.c linux-rpi/drivers/w1/masters/w1-gpio.c
  113628. --- linux-3.18.6/drivers/w1/masters/w1-gpio.c 2015-02-06 15:53:48.000000000 +0100
  113629. +++ linux-rpi/drivers/w1/masters/w1-gpio.c 2015-02-09 04:40:31.000000000 +0100
  113630. @@ -23,6 +23,19 @@
  113631. #include "../w1.h"
  113632. #include "../w1_int.h"
  113633. +static int w1_gpio_pullup = 0;
  113634. +static int w1_gpio_pullup_orig = 0;
  113635. +module_param_named(pullup, w1_gpio_pullup, int, 0);
  113636. +MODULE_PARM_DESC(pullup, "Enable parasitic power (power on data) mode");
  113637. +static int w1_gpio_pullup_pin = -1;
  113638. +static int w1_gpio_pullup_pin_orig = -1;
  113639. +module_param_named(extpullup, w1_gpio_pullup_pin, int, 0);
  113640. +MODULE_PARM_DESC(extpullup, "GPIO external pullup pin number");
  113641. +static int w1_gpio_pin = -1;
  113642. +static int w1_gpio_pin_orig = -1;
  113643. +module_param_named(gpiopin, w1_gpio_pin, int, 0);
  113644. +MODULE_PARM_DESC(gpiopin, "GPIO pin number");
  113645. +
  113646. static u8 w1_gpio_set_pullup(void *data, int delay)
  113647. {
  113648. struct w1_gpio_platform_data *pdata = data;
  113649. @@ -67,6 +80,16 @@
  113650. return gpio_get_value(pdata->pin) ? 1 : 0;
  113651. }
  113652. +static void w1_gpio_bitbang_pullup(void *data, u8 on)
  113653. +{
  113654. + struct w1_gpio_platform_data *pdata = data;
  113655. +
  113656. + if (on)
  113657. + gpio_direction_output(pdata->pin, 1);
  113658. + else
  113659. + gpio_direction_input(pdata->pin);
  113660. +}
  113661. +
  113662. #if defined(CONFIG_OF)
  113663. static struct of_device_id w1_gpio_dt_ids[] = {
  113664. { .compatible = "w1-gpio" },
  113665. @@ -80,6 +103,7 @@
  113666. struct w1_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
  113667. struct device_node *np = pdev->dev.of_node;
  113668. int gpio;
  113669. + u32 value;
  113670. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  113671. if (!pdata)
  113672. @@ -88,6 +112,9 @@
  113673. if (of_get_property(np, "linux,open-drain", NULL))
  113674. pdata->is_open_drain = 1;
  113675. + if (of_property_read_u32(np, "rpi,parasitic-power", &value) == 0)
  113676. + pdata->parasitic_power = (value != 0);
  113677. +
  113678. gpio = of_get_gpio(np, 0);
  113679. if (gpio < 0) {
  113680. if (gpio != -EPROBE_DEFER)
  113681. @@ -103,7 +130,7 @@
  113682. if (gpio == -EPROBE_DEFER)
  113683. return gpio;
  113684. /* ignore other errors as the pullup gpio is optional */
  113685. - pdata->ext_pullup_enable_pin = gpio;
  113686. + pdata->ext_pullup_enable_pin = (gpio >= 0) ? gpio : -1;
  113687. pdev->dev.platform_data = pdata;
  113688. @@ -113,13 +140,15 @@
  113689. static int w1_gpio_probe(struct platform_device *pdev)
  113690. {
  113691. struct w1_bus_master *master;
  113692. - struct w1_gpio_platform_data *pdata;
  113693. + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
  113694. int err;
  113695. - if (of_have_populated_dt()) {
  113696. - err = w1_gpio_probe_dt(pdev);
  113697. - if (err < 0)
  113698. - return err;
  113699. + if(pdata == NULL) {
  113700. + if (of_have_populated_dt()) {
  113701. + err = w1_gpio_probe_dt(pdev);
  113702. + if (err < 0)
  113703. + return err;
  113704. + }
  113705. }
  113706. pdata = dev_get_platdata(&pdev->dev);
  113707. @@ -136,6 +165,22 @@
  113708. return -ENOMEM;
  113709. }
  113710. + w1_gpio_pin_orig = pdata->pin;
  113711. + w1_gpio_pullup_pin_orig = pdata->ext_pullup_enable_pin;
  113712. + w1_gpio_pullup_orig = pdata->parasitic_power;
  113713. +
  113714. + if(gpio_is_valid(w1_gpio_pin)) {
  113715. + pdata->pin = w1_gpio_pin;
  113716. + pdata->ext_pullup_enable_pin = -1;
  113717. + pdata->parasitic_power = -1;
  113718. + }
  113719. + pdata->parasitic_power |= w1_gpio_pullup;
  113720. + if(gpio_is_valid(w1_gpio_pullup_pin)) {
  113721. + pdata->ext_pullup_enable_pin = w1_gpio_pullup_pin;
  113722. + }
  113723. +
  113724. + dev_info(&pdev->dev, "gpio pin %d, external pullup pin %d, parasitic power %d\n", pdata->pin, pdata->ext_pullup_enable_pin, pdata->parasitic_power);
  113725. +
  113726. err = devm_gpio_request(&pdev->dev, pdata->pin, "w1");
  113727. if (err) {
  113728. dev_err(&pdev->dev, "gpio_request (pin) failed\n");
  113729. @@ -165,6 +210,14 @@
  113730. master->set_pullup = w1_gpio_set_pullup;
  113731. }
  113732. + if (pdata->parasitic_power) {
  113733. + if (pdata->is_open_drain)
  113734. + printk(KERN_ERR "w1-gpio 'pullup'(parasitic power) "
  113735. + "option doesn't work with open drain GPIO\n");
  113736. + else
  113737. + master->bitbang_pullup = w1_gpio_bitbang_pullup;
  113738. + }
  113739. +
  113740. err = w1_add_master_device(master);
  113741. if (err) {
  113742. dev_err(&pdev->dev, "w1_add_master device failed\n");
  113743. @@ -195,6 +248,10 @@
  113744. w1_remove_master_device(master);
  113745. + pdata->pin = w1_gpio_pin_orig;
  113746. + pdata->ext_pullup_enable_pin = w1_gpio_pullup_pin_orig;
  113747. + pdata->parasitic_power = w1_gpio_pullup_orig;
  113748. +
  113749. return 0;
  113750. }
  113751. diff -Nur linux-3.18.6/drivers/w1/w1.h linux-rpi/drivers/w1/w1.h
  113752. --- linux-3.18.6/drivers/w1/w1.h 2015-02-06 15:53:48.000000000 +0100
  113753. +++ linux-rpi/drivers/w1/w1.h 2015-02-09 04:40:31.000000000 +0100
  113754. @@ -171,6 +171,12 @@
  113755. u8 (*set_pullup)(void *, int);
  113756. + /**
  113757. + * Turns the pullup on/off in bitbanging mode, takes an on/off argument.
  113758. + * @return -1=Error, 0=completed
  113759. + */
  113760. + void (*bitbang_pullup) (void *, u8);
  113761. +
  113762. void (*search)(void *, struct w1_master *,
  113763. u8, w1_slave_found_callback);
  113764. };
  113765. diff -Nur linux-3.18.6/drivers/w1/w1_int.c linux-rpi/drivers/w1/w1_int.c
  113766. --- linux-3.18.6/drivers/w1/w1_int.c 2015-02-06 15:53:48.000000000 +0100
  113767. +++ linux-rpi/drivers/w1/w1_int.c 2015-02-09 04:40:31.000000000 +0100
  113768. @@ -123,6 +123,20 @@
  113769. return(-EINVAL);
  113770. }
  113771. + /* bitbanging hardware uses bitbang_pullup, other hardware uses set_pullup
  113772. + * and takes care of timing itself */
  113773. + if (!master->write_byte && !master->touch_bit && master->set_pullup) {
  113774. + printk(KERN_ERR "w1_add_master_device: set_pullup requires "
  113775. + "write_byte or touch_bit, disabling\n");
  113776. + master->set_pullup = NULL;
  113777. + }
  113778. +
  113779. + if (master->set_pullup && master->bitbang_pullup) {
  113780. + printk(KERN_ERR "w1_add_master_device: set_pullup should not "
  113781. + "be set when bitbang_pullup is used, disabling\n");
  113782. + master->set_pullup = NULL;
  113783. + }
  113784. +
  113785. /* Lock until the device is added (or not) to w1_masters. */
  113786. mutex_lock(&w1_mlock);
  113787. /* Search for the first available id (starting at 1). */
  113788. diff -Nur linux-3.18.6/drivers/w1/w1_io.c linux-rpi/drivers/w1/w1_io.c
  113789. --- linux-3.18.6/drivers/w1/w1_io.c 2015-02-06 15:53:48.000000000 +0100
  113790. +++ linux-rpi/drivers/w1/w1_io.c 2015-02-09 04:40:31.000000000 +0100
  113791. @@ -134,10 +134,22 @@
  113792. static void w1_post_write(struct w1_master *dev)
  113793. {
  113794. if (dev->pullup_duration) {
  113795. - if (dev->enable_pullup && dev->bus_master->set_pullup)
  113796. - dev->bus_master->set_pullup(dev->bus_master->data, 0);
  113797. - else
  113798. + if (dev->enable_pullup) {
  113799. + if (dev->bus_master->set_pullup) {
  113800. + dev->bus_master->set_pullup(dev->
  113801. + bus_master->data,
  113802. + 0);
  113803. + } else if (dev->bus_master->bitbang_pullup) {
  113804. + dev->bus_master->
  113805. + bitbang_pullup(dev->bus_master->data, 1);
  113806. msleep(dev->pullup_duration);
  113807. + dev->bus_master->
  113808. + bitbang_pullup(dev->bus_master->data, 0);
  113809. + }
  113810. + } else {
  113811. + msleep(dev->pullup_duration);
  113812. + }
  113813. +
  113814. dev->pullup_duration = 0;
  113815. }
  113816. }
  113817. diff -Nur linux-3.18.6/drivers/watchdog/bcm2708_wdog.c linux-rpi/drivers/watchdog/bcm2708_wdog.c
  113818. --- linux-3.18.6/drivers/watchdog/bcm2708_wdog.c 1970-01-01 01:00:00.000000000 +0100
  113819. +++ linux-rpi/drivers/watchdog/bcm2708_wdog.c 2015-02-09 04:40:31.000000000 +0100
  113820. @@ -0,0 +1,382 @@
  113821. +/*
  113822. + * Broadcom BCM2708 watchdog driver.
  113823. + *
  113824. + * (c) Copyright 2010 Broadcom Europe Ltd
  113825. + *
  113826. + * This program is free software; you can redistribute it and/or
  113827. + * modify it under the terms of the GNU General Public License
  113828. + * as published by the Free Software Foundation; either version
  113829. + * 2 of the License, or (at your option) any later version.
  113830. + *
  113831. + * BCM2708 watchdog driver. Loosely based on wdt driver.
  113832. + */
  113833. +
  113834. +#include <linux/interrupt.h>
  113835. +#include <linux/module.h>
  113836. +#include <linux/moduleparam.h>
  113837. +#include <linux/types.h>
  113838. +#include <linux/miscdevice.h>
  113839. +#include <linux/watchdog.h>
  113840. +#include <linux/fs.h>
  113841. +#include <linux/ioport.h>
  113842. +#include <linux/notifier.h>
  113843. +#include <linux/reboot.h>
  113844. +#include <linux/init.h>
  113845. +#include <linux/io.h>
  113846. +#include <linux/uaccess.h>
  113847. +#include <mach/platform.h>
  113848. +
  113849. +#define SECS_TO_WDOG_TICKS(x) ((x) << 16)
  113850. +#define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
  113851. +
  113852. +static unsigned long wdog_is_open;
  113853. +static uint32_t wdog_ticks; /* Ticks to load into wdog timer */
  113854. +static char expect_close;
  113855. +
  113856. +/*
  113857. + * Module parameters
  113858. + */
  113859. +
  113860. +#define WD_TIMO 10 /* Default heartbeat = 60 seconds */
  113861. +static int heartbeat = WD_TIMO; /* Heartbeat in seconds */
  113862. +
  113863. +module_param(heartbeat, int, 0);
  113864. +MODULE_PARM_DESC(heartbeat,
  113865. + "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default="
  113866. + __MODULE_STRING(WD_TIMO) ")");
  113867. +
  113868. +static int nowayout = WATCHDOG_NOWAYOUT;
  113869. +module_param(nowayout, int, 0);
  113870. +MODULE_PARM_DESC(nowayout,
  113871. + "Watchdog cannot be stopped once started (default="
  113872. + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  113873. +
  113874. +static DEFINE_SPINLOCK(wdog_lock);
  113875. +
  113876. +/**
  113877. + * Start the watchdog driver.
  113878. + */
  113879. +
  113880. +static int wdog_start(unsigned long timeout)
  113881. +{
  113882. + uint32_t cur;
  113883. + unsigned long flags;
  113884. + spin_lock_irqsave(&wdog_lock, flags);
  113885. +
  113886. + /* enable the watchdog */
  113887. + iowrite32(PM_PASSWORD | (timeout & PM_WDOG_TIME_SET),
  113888. + __io_address(PM_WDOG));
  113889. + cur = ioread32(__io_address(PM_RSTC));
  113890. + iowrite32(PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) |
  113891. + PM_RSTC_WRCFG_FULL_RESET, __io_address(PM_RSTC));
  113892. +
  113893. + spin_unlock_irqrestore(&wdog_lock, flags);
  113894. + return 0;
  113895. +}
  113896. +
  113897. +/**
  113898. + * Stop the watchdog driver.
  113899. + */
  113900. +
  113901. +static int wdog_stop(void)
  113902. +{
  113903. + iowrite32(PM_PASSWORD | PM_RSTC_RESET, __io_address(PM_RSTC));
  113904. + printk(KERN_INFO "watchdog stopped\n");
  113905. + return 0;
  113906. +}
  113907. +
  113908. +/**
  113909. + * Reload counter one with the watchdog heartbeat. We don't bother
  113910. + * reloading the cascade counter.
  113911. + */
  113912. +
  113913. +static void wdog_ping(void)
  113914. +{
  113915. + wdog_start(wdog_ticks);
  113916. +}
  113917. +
  113918. +/**
  113919. + * @t: the new heartbeat value that needs to be set.
  113920. + *
  113921. + * Set a new heartbeat value for the watchdog device. If the heartbeat
  113922. + * value is incorrect we keep the old value and return -EINVAL. If
  113923. + * successful we return 0.
  113924. + */
  113925. +
  113926. +static int wdog_set_heartbeat(int t)
  113927. +{
  113928. + if (t < 1 || t > WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET))
  113929. + return -EINVAL;
  113930. +
  113931. + heartbeat = t;
  113932. + wdog_ticks = SECS_TO_WDOG_TICKS(t);
  113933. + return 0;
  113934. +}
  113935. +
  113936. +/**
  113937. + * @file: file handle to the watchdog
  113938. + * @buf: buffer to write (unused as data does not matter here
  113939. + * @count: count of bytes
  113940. + * @ppos: pointer to the position to write. No seeks allowed
  113941. + *
  113942. + * A write to a watchdog device is defined as a keepalive signal.
  113943. + *
  113944. + * if 'nowayout' is set then normally a close() is ignored. But
  113945. + * if you write 'V' first then the close() will stop the timer.
  113946. + */
  113947. +
  113948. +static ssize_t wdog_write(struct file *file, const char __user *buf,
  113949. + size_t count, loff_t *ppos)
  113950. +{
  113951. + if (count) {
  113952. + if (!nowayout) {
  113953. + size_t i;
  113954. +
  113955. + /* In case it was set long ago */
  113956. + expect_close = 0;
  113957. +
  113958. + for (i = 0; i != count; i++) {
  113959. + char c;
  113960. + if (get_user(c, buf + i))
  113961. + return -EFAULT;
  113962. + if (c == 'V')
  113963. + expect_close = 42;
  113964. + }
  113965. + }
  113966. + wdog_ping();
  113967. + }
  113968. + return count;
  113969. +}
  113970. +
  113971. +static int wdog_get_status(void)
  113972. +{
  113973. + unsigned long flags;
  113974. + int status = 0;
  113975. + spin_lock_irqsave(&wdog_lock, flags);
  113976. + /* FIXME: readback reset reason */
  113977. + spin_unlock_irqrestore(&wdog_lock, flags);
  113978. + return status;
  113979. +}
  113980. +
  113981. +static uint32_t wdog_get_remaining(void)
  113982. +{
  113983. + uint32_t ret = ioread32(__io_address(PM_WDOG));
  113984. + return ret & PM_WDOG_TIME_SET;
  113985. +}
  113986. +
  113987. +/**
  113988. + * @file: file handle to the device
  113989. + * @cmd: watchdog command
  113990. + * @arg: argument pointer
  113991. + *
  113992. + * The watchdog API defines a common set of functions for all watchdogs
  113993. + * according to their available features. We only actually usefully support
  113994. + * querying capabilities and current status.
  113995. + */
  113996. +
  113997. +static long wdog_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  113998. +{
  113999. + void __user *argp = (void __user *)arg;
  114000. + int __user *p = argp;
  114001. + int new_heartbeat;
  114002. + int status;
  114003. + int options;
  114004. + uint32_t remaining;
  114005. +
  114006. + struct watchdog_info ident = {
  114007. + .options = WDIOF_SETTIMEOUT|
  114008. + WDIOF_MAGICCLOSE|
  114009. + WDIOF_KEEPALIVEPING,
  114010. + .firmware_version = 1,
  114011. + .identity = "BCM2708",
  114012. + };
  114013. +
  114014. + switch (cmd) {
  114015. + case WDIOC_GETSUPPORT:
  114016. + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  114017. + case WDIOC_GETSTATUS:
  114018. + status = wdog_get_status();
  114019. + return put_user(status, p);
  114020. + case WDIOC_GETBOOTSTATUS:
  114021. + return put_user(0, p);
  114022. + case WDIOC_KEEPALIVE:
  114023. + wdog_ping();
  114024. + return 0;
  114025. + case WDIOC_SETTIMEOUT:
  114026. + if (get_user(new_heartbeat, p))
  114027. + return -EFAULT;
  114028. + if (wdog_set_heartbeat(new_heartbeat))
  114029. + return -EINVAL;
  114030. + wdog_ping();
  114031. + /* Fall */
  114032. + case WDIOC_GETTIMEOUT:
  114033. + return put_user(heartbeat, p);
  114034. + case WDIOC_GETTIMELEFT:
  114035. + remaining = WDOG_TICKS_TO_SECS(wdog_get_remaining());
  114036. + return put_user(remaining, p);
  114037. + case WDIOC_SETOPTIONS:
  114038. + if (get_user(options, p))
  114039. + return -EFAULT;
  114040. + if (options & WDIOS_DISABLECARD)
  114041. + wdog_stop();
  114042. + if (options & WDIOS_ENABLECARD)
  114043. + wdog_start(wdog_ticks);
  114044. + return 0;
  114045. + default:
  114046. + return -ENOTTY;
  114047. + }
  114048. +}
  114049. +
  114050. +/**
  114051. + * @inode: inode of device
  114052. + * @file: file handle to device
  114053. + *
  114054. + * The watchdog device has been opened. The watchdog device is single
  114055. + * open and on opening we load the counters.
  114056. + */
  114057. +
  114058. +static int wdog_open(struct inode *inode, struct file *file)
  114059. +{
  114060. + if (test_and_set_bit(0, &wdog_is_open))
  114061. + return -EBUSY;
  114062. + /*
  114063. + * Activate
  114064. + */
  114065. + wdog_start(wdog_ticks);
  114066. + return nonseekable_open(inode, file);
  114067. +}
  114068. +
  114069. +/**
  114070. + * @inode: inode to board
  114071. + * @file: file handle to board
  114072. + *
  114073. + * The watchdog has a configurable API. There is a religious dispute
  114074. + * between people who want their watchdog to be able to shut down and
  114075. + * those who want to be sure if the watchdog manager dies the machine
  114076. + * reboots. In the former case we disable the counters, in the latter
  114077. + * case you have to open it again very soon.
  114078. + */
  114079. +
  114080. +static int wdog_release(struct inode *inode, struct file *file)
  114081. +{
  114082. + if (expect_close == 42) {
  114083. + wdog_stop();
  114084. + } else {
  114085. + printk(KERN_CRIT
  114086. + "wdt: WDT device closed unexpectedly. WDT will not stop!\n");
  114087. + wdog_ping();
  114088. + }
  114089. + clear_bit(0, &wdog_is_open);
  114090. + expect_close = 0;
  114091. + return 0;
  114092. +}
  114093. +
  114094. +/**
  114095. + * @this: our notifier block
  114096. + * @code: the event being reported
  114097. + * @unused: unused
  114098. + *
  114099. + * Our notifier is called on system shutdowns. Turn the watchdog
  114100. + * off so that it does not fire during the next reboot.
  114101. + */
  114102. +
  114103. +static int wdog_notify_sys(struct notifier_block *this, unsigned long code,
  114104. + void *unused)
  114105. +{
  114106. + if (code == SYS_DOWN || code == SYS_HALT)
  114107. + wdog_stop();
  114108. + return NOTIFY_DONE;
  114109. +}
  114110. +
  114111. +/*
  114112. + * Kernel Interfaces
  114113. + */
  114114. +
  114115. +
  114116. +static const struct file_operations wdog_fops = {
  114117. + .owner = THIS_MODULE,
  114118. + .llseek = no_llseek,
  114119. + .write = wdog_write,
  114120. + .unlocked_ioctl = wdog_ioctl,
  114121. + .open = wdog_open,
  114122. + .release = wdog_release,
  114123. +};
  114124. +
  114125. +static struct miscdevice wdog_miscdev = {
  114126. + .minor = WATCHDOG_MINOR,
  114127. + .name = "watchdog",
  114128. + .fops = &wdog_fops,
  114129. +};
  114130. +
  114131. +/*
  114132. + * The WDT card needs to learn about soft shutdowns in order to
  114133. + * turn the timebomb registers off.
  114134. + */
  114135. +
  114136. +static struct notifier_block wdog_notifier = {
  114137. + .notifier_call = wdog_notify_sys,
  114138. +};
  114139. +
  114140. +/**
  114141. + * cleanup_module:
  114142. + *
  114143. + * Unload the watchdog. You cannot do this with any file handles open.
  114144. + * If your watchdog is set to continue ticking on close and you unload
  114145. + * it, well it keeps ticking. We won't get the interrupt but the board
  114146. + * will not touch PC memory so all is fine. You just have to load a new
  114147. + * module in 60 seconds or reboot.
  114148. + */
  114149. +
  114150. +static void __exit wdog_exit(void)
  114151. +{
  114152. + misc_deregister(&wdog_miscdev);
  114153. + unregister_reboot_notifier(&wdog_notifier);
  114154. +}
  114155. +
  114156. +static int __init wdog_init(void)
  114157. +{
  114158. + int ret;
  114159. +
  114160. + /* Check that the heartbeat value is within it's range;
  114161. + if not reset to the default */
  114162. + if (wdog_set_heartbeat(heartbeat)) {
  114163. + wdog_set_heartbeat(WD_TIMO);
  114164. + printk(KERN_INFO "bcm2708_wdog: heartbeat value must be "
  114165. + "0 < heartbeat < %d, using %d\n",
  114166. + WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET),
  114167. + WD_TIMO);
  114168. + }
  114169. +
  114170. + ret = register_reboot_notifier(&wdog_notifier);
  114171. + if (ret) {
  114172. + printk(KERN_ERR
  114173. + "wdt: cannot register reboot notifier (err=%d)\n", ret);
  114174. + goto out_reboot;
  114175. + }
  114176. +
  114177. + ret = misc_register(&wdog_miscdev);
  114178. + if (ret) {
  114179. + printk(KERN_ERR
  114180. + "wdt: cannot register miscdev on minor=%d (err=%d)\n",
  114181. + WATCHDOG_MINOR, ret);
  114182. + goto out_misc;
  114183. + }
  114184. +
  114185. + printk(KERN_INFO "bcm2708 watchdog, heartbeat=%d sec (nowayout=%d)\n",
  114186. + heartbeat, nowayout);
  114187. + return 0;
  114188. +
  114189. +out_misc:
  114190. + unregister_reboot_notifier(&wdog_notifier);
  114191. +out_reboot:
  114192. + return ret;
  114193. +}
  114194. +
  114195. +module_init(wdog_init);
  114196. +module_exit(wdog_exit);
  114197. +
  114198. +MODULE_AUTHOR("Luke Diamand");
  114199. +MODULE_DESCRIPTION("Driver for BCM2708 watchdog");
  114200. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  114201. +MODULE_ALIAS_MISCDEV(TEMP_MINOR);
  114202. +MODULE_LICENSE("GPL");
  114203. diff -Nur linux-3.18.6/drivers/watchdog/Kconfig linux-rpi/drivers/watchdog/Kconfig
  114204. --- linux-3.18.6/drivers/watchdog/Kconfig 2015-02-06 15:53:48.000000000 +0100
  114205. +++ linux-rpi/drivers/watchdog/Kconfig 2015-02-09 04:40:31.000000000 +0100
  114206. @@ -452,6 +452,12 @@
  114207. To compile this driver as a module, choose M here: the
  114208. module will be called retu_wdt.
  114209. +config BCM2708_WDT
  114210. + tristate "BCM2708 Watchdog"
  114211. + depends on ARCH_BCM2708 || ARCH_BCM2709
  114212. + help
  114213. + Enables BCM2708 watchdog support.
  114214. +
  114215. config MOXART_WDT
  114216. tristate "MOXART watchdog"
  114217. depends on ARCH_MOXART
  114218. diff -Nur linux-3.18.6/drivers/watchdog/Makefile linux-rpi/drivers/watchdog/Makefile
  114219. --- linux-3.18.6/drivers/watchdog/Makefile 2015-02-06 15:53:48.000000000 +0100
  114220. +++ linux-rpi/drivers/watchdog/Makefile 2015-02-09 04:40:31.000000000 +0100
  114221. @@ -56,6 +56,7 @@
  114222. obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
  114223. obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
  114224. obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
  114225. +obj-$(CONFIG_BCM2708_WDT) += bcm2708_wdog.o
  114226. obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
  114227. obj-$(CONFIG_MOXART_WDT) += moxart_wdt.o
  114228. obj-$(CONFIG_SIRFSOC_WATCHDOG) += sirfsoc_wdt.o
  114229. diff -Nur linux-3.18.6/include/linux/broadcom/vc_cma.h linux-rpi/include/linux/broadcom/vc_cma.h
  114230. --- linux-3.18.6/include/linux/broadcom/vc_cma.h 1970-01-01 01:00:00.000000000 +0100
  114231. +++ linux-rpi/include/linux/broadcom/vc_cma.h 2015-02-09 04:40:45.000000000 +0100
  114232. @@ -0,0 +1,29 @@
  114233. +/*****************************************************************************
  114234. +* Copyright 2012 Broadcom Corporation. All rights reserved.
  114235. +*
  114236. +* Unless you and Broadcom execute a separate written software license
  114237. +* agreement governing use of this software, this software is licensed to you
  114238. +* under the terms of the GNU General Public License version 2, available at
  114239. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  114240. +*
  114241. +* Notwithstanding the above, under no circumstances may you combine this
  114242. +* software in any way with any other Broadcom software provided under a
  114243. +* license other than the GPL, without Broadcom's express prior written
  114244. +* consent.
  114245. +*****************************************************************************/
  114246. +
  114247. +#if !defined( VC_CMA_H )
  114248. +#define VC_CMA_H
  114249. +
  114250. +#include <linux/ioctl.h>
  114251. +
  114252. +#define VC_CMA_IOC_MAGIC 0xc5
  114253. +
  114254. +#define VC_CMA_IOC_RESERVE _IO(VC_CMA_IOC_MAGIC, 0)
  114255. +
  114256. +#ifdef __KERNEL__
  114257. +extern void __init vc_cma_early_init(void);
  114258. +extern void __init vc_cma_reserve(void);
  114259. +#endif
  114260. +
  114261. +#endif /* VC_CMA_H */
  114262. diff -Nur linux-3.18.6/include/linux/mmc/host.h linux-rpi/include/linux/mmc/host.h
  114263. --- linux-3.18.6/include/linux/mmc/host.h 2015-02-06 15:53:48.000000000 +0100
  114264. +++ linux-rpi/include/linux/mmc/host.h 2015-02-09 04:40:46.000000000 +0100
  114265. @@ -290,6 +290,7 @@
  114266. #define MMC_CAP2_HS400 (MMC_CAP2_HS400_1_8V | \
  114267. MMC_CAP2_HS400_1_2V)
  114268. #define MMC_CAP2_SDIO_IRQ_NOTHREAD (1 << 17)
  114269. +#define MMC_CAP2_FORCE_MULTIBLOCK (1 << 31) /* Always use multiblock transfers */
  114270. mmc_pm_flag_t pm_caps; /* supported pm features */
  114271. diff -Nur linux-3.18.6/include/linux/mmc/sdhci.h linux-rpi/include/linux/mmc/sdhci.h
  114272. --- linux-3.18.6/include/linux/mmc/sdhci.h 2015-02-06 15:53:48.000000000 +0100
  114273. +++ linux-rpi/include/linux/mmc/sdhci.h 2015-02-09 04:40:46.000000000 +0100
  114274. @@ -130,6 +130,7 @@
  114275. #define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  114276. #define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
  114277. #define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
  114278. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  114279. unsigned int version; /* SDHCI spec. version */
  114280. diff -Nur linux-3.18.6/include/linux/platform_data/bcm2708.h linux-rpi/include/linux/platform_data/bcm2708.h
  114281. --- linux-3.18.6/include/linux/platform_data/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  114282. +++ linux-rpi/include/linux/platform_data/bcm2708.h 2015-02-09 04:40:46.000000000 +0100
  114283. @@ -0,0 +1,23 @@
  114284. +/*
  114285. + * include/linux/platform_data/bcm2708.h
  114286. + *
  114287. + * This program is free software; you can redistribute it and/or modify
  114288. + * it under the terms of the GNU General Public License version 2 as
  114289. + * published by the Free Software Foundation.
  114290. + *
  114291. + * (C) 2014 Julian Scheel <julian@jusst.de>
  114292. + *
  114293. + */
  114294. +#ifndef __BCM2708_H_
  114295. +#define __BCM2708_H_
  114296. +
  114297. +typedef enum {
  114298. + BCM2708_PULL_OFF,
  114299. + BCM2708_PULL_UP,
  114300. + BCM2708_PULL_DOWN
  114301. +} bcm2708_gpio_pull_t;
  114302. +
  114303. +extern int bcm2708_gpio_setpull(struct gpio_chip *gc, unsigned offset,
  114304. + bcm2708_gpio_pull_t value);
  114305. +
  114306. +#endif
  114307. diff -Nur linux-3.18.6/include/linux/vmstat.h linux-rpi/include/linux/vmstat.h
  114308. --- linux-3.18.6/include/linux/vmstat.h 2015-02-06 15:53:48.000000000 +0100
  114309. +++ linux-rpi/include/linux/vmstat.h 2015-02-09 04:40:46.000000000 +0100
  114310. @@ -241,7 +241,11 @@
  114311. static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
  114312. {
  114313. atomic_long_dec(&zone->vm_stat[item]);
  114314. + if (item == NR_FILE_DIRTY && unlikely(atomic_long_read(&zone->vm_stat[item]) < 0))
  114315. + atomic_long_set(&zone->vm_stat[item], 0);
  114316. atomic_long_dec(&vm_stat[item]);
  114317. + if (item == NR_FILE_DIRTY && unlikely(atomic_long_read(&vm_stat[item]) < 0))
  114318. + atomic_long_set(&vm_stat[item], 0);
  114319. }
  114320. static inline void __inc_zone_page_state(struct page *page,
  114321. diff -Nur linux-3.18.6/include/linux/w1-gpio.h linux-rpi/include/linux/w1-gpio.h
  114322. --- linux-3.18.6/include/linux/w1-gpio.h 2015-02-06 15:53:48.000000000 +0100
  114323. +++ linux-rpi/include/linux/w1-gpio.h 2015-02-09 04:40:46.000000000 +0100
  114324. @@ -18,6 +18,7 @@
  114325. struct w1_gpio_platform_data {
  114326. unsigned int pin;
  114327. unsigned int is_open_drain:1;
  114328. + unsigned int parasitic_power:1;
  114329. void (*enable_external_pullup)(int enable);
  114330. unsigned int ext_pullup_enable_pin;
  114331. unsigned int pullup_duration;
  114332. diff -Nur linux-3.18.6/include/uapi/linux/fb.h linux-rpi/include/uapi/linux/fb.h
  114333. --- linux-3.18.6/include/uapi/linux/fb.h 2015-02-06 15:53:48.000000000 +0100
  114334. +++ linux-rpi/include/uapi/linux/fb.h 2015-02-09 04:40:46.000000000 +0100
  114335. @@ -34,6 +34,11 @@
  114336. #define FBIOPUT_MODEINFO 0x4617
  114337. #define FBIOGET_DISPINFO 0x4618
  114338. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  114339. +/*
  114340. + * HACK: use 'z' in order not to clash with any other ioctl numbers which might
  114341. + * be concurrently added to the mainline kernel
  114342. + */
  114343. +#define FBIOCOPYAREA _IOW('z', 0x21, struct fb_copyarea)
  114344. #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
  114345. #define FB_TYPE_PLANES 1 /* Non interleaved planes */
  114346. diff -Nur linux-3.18.6/kernel/cgroup.c linux-rpi/kernel/cgroup.c
  114347. --- linux-3.18.6/kernel/cgroup.c 2015-02-06 15:53:48.000000000 +0100
  114348. +++ linux-rpi/kernel/cgroup.c 2015-02-09 04:40:46.000000000 +0100
  114349. @@ -5322,6 +5322,29 @@
  114350. }
  114351. __setup("cgroup_disable=", cgroup_disable);
  114352. +static int __init cgroup_enable(char *str)
  114353. +{
  114354. + struct cgroup_subsys *ss;
  114355. + char *token;
  114356. + int i;
  114357. +
  114358. + while ((token = strsep(&str, ",")) != NULL) {
  114359. + if (!*token)
  114360. + continue;
  114361. +
  114362. + for_each_subsys(ss, i) {
  114363. + if (!strcmp(token, ss->name)) {
  114364. + ss->disabled = 0;
  114365. + printk(KERN_INFO "Enabling %s control group"
  114366. + " subsystem\n", ss->name);
  114367. + break;
  114368. + }
  114369. + }
  114370. + }
  114371. + return 1;
  114372. +}
  114373. +__setup("cgroup_enable=", cgroup_enable);
  114374. +
  114375. static int __init cgroup_set_legacy_files_on_dfl(char *str)
  114376. {
  114377. printk("cgroup: using legacy files on the default hierarchy\n");
  114378. diff -Nur linux-3.18.6/kernel/time/ntp.c linux-rpi/kernel/time/ntp.c
  114379. --- linux-3.18.6/kernel/time/ntp.c 2015-02-06 15:53:48.000000000 +0100
  114380. +++ linux-rpi/kernel/time/ntp.c 2015-02-09 04:40:46.000000000 +0100
  114381. @@ -634,9 +634,9 @@
  114382. return -EPERM;
  114383. if (txc->modes & ADJ_FREQUENCY) {
  114384. - if (LONG_MIN / PPM_SCALE > txc->freq)
  114385. + if (LLONG_MIN / PPM_SCALE > txc->freq)
  114386. return -EINVAL;
  114387. - if (LONG_MAX / PPM_SCALE < txc->freq)
  114388. + if (LLONG_MAX / PPM_SCALE < txc->freq)
  114389. return -EINVAL;
  114390. }
  114391. diff -Nur linux-3.18.6/mm/memcontrol.c linux-rpi/mm/memcontrol.c
  114392. --- linux-3.18.6/mm/memcontrol.c 2015-02-06 15:53:48.000000000 +0100
  114393. +++ linux-rpi/mm/memcontrol.c 2015-02-09 04:40:47.000000000 +0100
  114394. @@ -6207,6 +6207,7 @@
  114395. .bind = mem_cgroup_bind,
  114396. .legacy_cftypes = mem_cgroup_files,
  114397. .early_init = 0,
  114398. + .disabled = 1,
  114399. };
  114400. #ifdef CONFIG_MEMCG_SWAP
  114401. diff -Nur linux-3.18.6/scripts/dtc/checks.c linux-rpi/scripts/dtc/checks.c
  114402. --- linux-3.18.6/scripts/dtc/checks.c 2015-02-06 15:53:48.000000000 +0100
  114403. +++ linux-rpi/scripts/dtc/checks.c 2015-02-09 04:40:47.000000000 +0100
  114404. @@ -53,7 +53,7 @@
  114405. void *data;
  114406. bool warn, error;
  114407. enum checkstatus status;
  114408. - int inprogress;
  114409. + bool inprogress;
  114410. int num_prereqs;
  114411. struct check **prereq;
  114412. };
  114413. @@ -113,6 +113,7 @@
  114414. vfprintf(stderr, fmt, ap);
  114415. fprintf(stderr, "\n");
  114416. }
  114417. + va_end(ap);
  114418. }
  114419. #define FAIL(c, ...) \
  114420. @@ -141,9 +142,9 @@
  114421. check_nodes_props(c, dt, child);
  114422. }
  114423. -static int run_check(struct check *c, struct node *dt)
  114424. +static bool run_check(struct check *c, struct node *dt)
  114425. {
  114426. - int error = 0;
  114427. + bool error = false;
  114428. int i;
  114429. assert(!c->inprogress);
  114430. @@ -151,11 +152,11 @@
  114431. if (c->status != UNCHECKED)
  114432. goto out;
  114433. - c->inprogress = 1;
  114434. + c->inprogress = true;
  114435. for (i = 0; i < c->num_prereqs; i++) {
  114436. struct check *prq = c->prereq[i];
  114437. - error |= run_check(prq, dt);
  114438. + error = error || run_check(prq, dt);
  114439. if (prq->status != PASSED) {
  114440. c->status = PREREQ;
  114441. check_msg(c, "Failed prerequisite '%s'",
  114442. @@ -177,9 +178,9 @@
  114443. TRACE(c, "\tCompleted, status %d", c->status);
  114444. out:
  114445. - c->inprogress = 0;
  114446. + c->inprogress = false;
  114447. if ((c->status != PASSED) && (c->error))
  114448. - error = 1;
  114449. + error = true;
  114450. return error;
  114451. }
  114452. @@ -457,22 +458,93 @@
  114453. struct node *node, struct property *prop)
  114454. {
  114455. struct marker *m = prop->val.markers;
  114456. + struct fixup *f, **fp;
  114457. + struct fixup_entry *fe, **fep;
  114458. struct node *refnode;
  114459. cell_t phandle;
  114460. + int has_phandle_refs;
  114461. +
  114462. + has_phandle_refs = 0;
  114463. + for_each_marker_of_type(m, REF_PHANDLE) {
  114464. + has_phandle_refs = 1;
  114465. + break;
  114466. + }
  114467. +
  114468. + if (!has_phandle_refs)
  114469. + return;
  114470. for_each_marker_of_type(m, REF_PHANDLE) {
  114471. assert(m->offset + sizeof(cell_t) <= prop->val.len);
  114472. refnode = get_node_by_ref(dt, m->ref);
  114473. - if (! refnode) {
  114474. + if (!refnode && !symbol_fixup_support) {
  114475. FAIL(c, "Reference to non-existent node or label \"%s\"\n",
  114476. - m->ref);
  114477. + m->ref);
  114478. continue;
  114479. }
  114480. - phandle = get_node_phandle(dt, refnode);
  114481. - *((cell_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
  114482. + if (!refnode) {
  114483. + /* allocate fixup entry */
  114484. + fe = xmalloc(sizeof(*fe));
  114485. +
  114486. + fe->node = node;
  114487. + fe->prop = prop;
  114488. + fe->offset = m->offset;
  114489. + fe->next = NULL;
  114490. +
  114491. + /* search for an already existing fixup */
  114492. + for_each_fixup(dt, f)
  114493. + if (strcmp(f->ref, m->ref) == 0)
  114494. + break;
  114495. +
  114496. + /* no fixup found, add new */
  114497. + if (f == NULL) {
  114498. + f = xmalloc(sizeof(*f));
  114499. + f->ref = m->ref;
  114500. + f->entries = NULL;
  114501. + f->next = NULL;
  114502. +
  114503. + /* add it to the tree */
  114504. + fp = &dt->fixups;
  114505. + while (*fp)
  114506. + fp = &(*fp)->next;
  114507. + *fp = f;
  114508. + }
  114509. +
  114510. + /* and now append fixup entry */
  114511. + fep = &f->entries;
  114512. + while (*fep)
  114513. + fep = &(*fep)->next;
  114514. + *fep = fe;
  114515. +
  114516. + /* mark the entry as unresolved */
  114517. + phandle = 0xdeadbeef;
  114518. + } else {
  114519. + phandle = get_node_phandle(dt, refnode);
  114520. +
  114521. + /* if it's a plugin, we need to record it */
  114522. + if (symbol_fixup_support && dt->is_plugin) {
  114523. +
  114524. + /* allocate a new local fixup entry */
  114525. + fe = xmalloc(sizeof(*fe));
  114526. +
  114527. + fe->node = node;
  114528. + fe->prop = prop;
  114529. + fe->offset = m->offset;
  114530. + fe->next = NULL;
  114531. +
  114532. + /* append it to the local fixups */
  114533. + fep = &dt->local_fixups;
  114534. + while (*fep)
  114535. + fep = &(*fep)->next;
  114536. + *fep = fe;
  114537. + }
  114538. + }
  114539. +
  114540. + *((cell_t *)(prop->val.val + m->offset)) =
  114541. + cpu_to_fdt32(phandle);
  114542. }
  114543. +
  114544. }
  114545. ERROR(phandle_references, NULL, NULL, fixup_phandle_references, NULL,
  114546. &duplicate_node_names, &explicit_phandles);
  114547. @@ -624,11 +696,11 @@
  114548. if (!reg && !ranges)
  114549. return;
  114550. - if ((node->parent->addr_cells == -1))
  114551. + if (node->parent->addr_cells == -1)
  114552. FAIL(c, "Relying on default #address-cells value for %s",
  114553. node->fullpath);
  114554. - if ((node->parent->size_cells == -1))
  114555. + if (node->parent->size_cells == -1)
  114556. FAIL(c, "Relying on default #size-cells value for %s",
  114557. node->fullpath);
  114558. }
  114559. @@ -651,6 +723,45 @@
  114560. }
  114561. TREE_WARNING(obsolete_chosen_interrupt_controller, NULL);
  114562. +static void check_auto_label_phandles(struct check *c, struct node *dt,
  114563. + struct node *node)
  114564. +{
  114565. + struct label *l;
  114566. + struct symbol *s, **sp;
  114567. + int has_label;
  114568. +
  114569. + if (!symbol_fixup_support)
  114570. + return;
  114571. +
  114572. + has_label = 0;
  114573. + for_each_label(node->labels, l) {
  114574. + has_label = 1;
  114575. + break;
  114576. + }
  114577. +
  114578. + if (!has_label)
  114579. + return;
  114580. +
  114581. + /* force allocation of a phandle for this node */
  114582. + (void)get_node_phandle(dt, node);
  114583. +
  114584. + /* add the symbol */
  114585. + for_each_label(node->labels, l) {
  114586. +
  114587. + s = xmalloc(sizeof(*s));
  114588. + s->label = l;
  114589. + s->node = node;
  114590. + s->next = NULL;
  114591. +
  114592. + /* add it to the symbols list */
  114593. + sp = &dt->symbols;
  114594. + while (*sp)
  114595. + sp = &((*sp)->next);
  114596. + *sp = s;
  114597. + }
  114598. +}
  114599. +NODE_WARNING(auto_label_phandles, NULL);
  114600. +
  114601. static struct check *check_table[] = {
  114602. &duplicate_node_names, &duplicate_property_names,
  114603. &node_name_chars, &node_name_format, &property_name_chars,
  114604. @@ -669,6 +780,8 @@
  114605. &avoid_default_addr_size,
  114606. &obsolete_chosen_interrupt_controller,
  114607. + &auto_label_phandles,
  114608. +
  114609. &always_fail,
  114610. };
  114611. @@ -706,15 +819,15 @@
  114612. c->error = c->error && !error;
  114613. }
  114614. -void parse_checks_option(bool warn, bool error, const char *optarg)
  114615. +void parse_checks_option(bool warn, bool error, const char *arg)
  114616. {
  114617. int i;
  114618. - const char *name = optarg;
  114619. + const char *name = arg;
  114620. bool enable = true;
  114621. - if ((strncmp(optarg, "no-", 3) == 0)
  114622. - || (strncmp(optarg, "no_", 3) == 0)) {
  114623. - name = optarg + 3;
  114624. + if ((strncmp(arg, "no-", 3) == 0)
  114625. + || (strncmp(arg, "no_", 3) == 0)) {
  114626. + name = arg + 3;
  114627. enable = false;
  114628. }
  114629. @@ -733,7 +846,7 @@
  114630. die("Unrecognized check name \"%s\"\n", name);
  114631. }
  114632. -void process_checks(int force, struct boot_info *bi)
  114633. +void process_checks(bool force, struct boot_info *bi)
  114634. {
  114635. struct node *dt = bi->dt;
  114636. int i;
  114637. diff -Nur linux-3.18.6/scripts/dtc/data.c linux-rpi/scripts/dtc/data.c
  114638. --- linux-3.18.6/scripts/dtc/data.c 2015-02-06 15:53:48.000000000 +0100
  114639. +++ linux-rpi/scripts/dtc/data.c 2015-02-09 04:40:47.000000000 +0100
  114640. @@ -74,7 +74,7 @@
  114641. struct data d;
  114642. char *q;
  114643. - d = data_grow_for(empty_data, strlen(s)+1);
  114644. + d = data_grow_for(empty_data, len + 1);
  114645. q = d.val;
  114646. while (i < len) {
  114647. @@ -250,20 +250,20 @@
  114648. return data_append_markers(d, m);
  114649. }
  114650. -int data_is_one_string(struct data d)
  114651. +bool data_is_one_string(struct data d)
  114652. {
  114653. int i;
  114654. int len = d.len;
  114655. if (len == 0)
  114656. - return 0;
  114657. + return false;
  114658. for (i = 0; i < len-1; i++)
  114659. if (d.val[i] == '\0')
  114660. - return 0;
  114661. + return false;
  114662. if (d.val[len-1] != '\0')
  114663. - return 0;
  114664. + return false;
  114665. - return 1;
  114666. + return true;
  114667. }
  114668. diff -Nur linux-3.18.6/scripts/dtc/dtc.c linux-rpi/scripts/dtc/dtc.c
  114669. --- linux-3.18.6/scripts/dtc/dtc.c 2015-02-06 15:53:48.000000000 +0100
  114670. +++ linux-rpi/scripts/dtc/dtc.c 2015-02-09 04:40:47.000000000 +0100
  114671. @@ -29,6 +29,7 @@
  114672. int minsize; /* Minimum blob size */
  114673. int padsize; /* Additional padding to blob */
  114674. int phandle_format = PHANDLE_BOTH; /* Use linux,phandle or phandle properties */
  114675. +int symbol_fixup_support = 0;
  114676. static void fill_fullpaths(struct node *tree, const char *prefix)
  114677. {
  114678. @@ -48,8 +49,10 @@
  114679. }
  114680. /* Usage related data. */
  114681. +#define FDT_VERSION(version) _FDT_VERSION(version)
  114682. +#define _FDT_VERSION(version) #version
  114683. static const char usage_synopsis[] = "dtc [options] <input file>";
  114684. -static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv";
  114685. +static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv@";
  114686. static struct option const usage_long_opts[] = {
  114687. {"quiet", no_argument, NULL, 'q'},
  114688. {"in-format", a_argument, NULL, 'I'},
  114689. @@ -67,6 +70,7 @@
  114690. {"phandle", a_argument, NULL, 'H'},
  114691. {"warning", a_argument, NULL, 'W'},
  114692. {"error", a_argument, NULL, 'E'},
  114693. + {"symbols", a_argument, NULL, '@'},
  114694. {"help", no_argument, NULL, 'h'},
  114695. {"version", no_argument, NULL, 'v'},
  114696. {NULL, no_argument, NULL, 0x0},
  114697. @@ -82,9 +86,9 @@
  114698. "\t\tdts - device tree source text\n"
  114699. "\t\tdtb - device tree blob\n"
  114700. "\t\tasm - assembler source",
  114701. - "\n\tBlob version to produce, defaults to %d (for dtb and asm output)", //, DEFAULT_FDT_VERSION);
  114702. + "\n\tBlob version to produce, defaults to "FDT_VERSION(DEFAULT_FDT_VERSION)" (for dtb and asm output)",
  114703. "\n\tOutput dependency file",
  114704. - "\n\ttMake space for <number> reserve map entries (for dtb and asm output)",
  114705. + "\n\tMake space for <number> reserve map entries (for dtb and asm output)",
  114706. "\n\tMake the blob at least <bytes> long (extra space)",
  114707. "\n\tAdd padding to the blob of <bytes> long (extra space)",
  114708. "\n\tSet the physical boot cpu",
  114709. @@ -97,6 +101,7 @@
  114710. "\t\tboth - Both \"linux,phandle\" and \"phandle\" properties",
  114711. "\n\tEnable/disable warnings (prefix with \"no-\")",
  114712. "\n\tEnable/disable errors (prefix with \"no-\")",
  114713. + "\n\tSymbols and Fixups support",
  114714. "\n\tPrint this help and exit",
  114715. "\n\tPrint version and exit",
  114716. NULL,
  114717. @@ -109,7 +114,7 @@
  114718. const char *outform = "dts";
  114719. const char *outname = "-";
  114720. const char *depname = NULL;
  114721. - int force = 0, sort = 0;
  114722. + bool force = false, sort = false;
  114723. const char *arg;
  114724. int opt;
  114725. FILE *outf = NULL;
  114726. @@ -148,7 +153,7 @@
  114727. padsize = strtol(optarg, NULL, 0);
  114728. break;
  114729. case 'f':
  114730. - force = 1;
  114731. + force = true;
  114732. break;
  114733. case 'q':
  114734. quiet++;
  114735. @@ -174,7 +179,7 @@
  114736. break;
  114737. case 's':
  114738. - sort = 1;
  114739. + sort = true;
  114740. break;
  114741. case 'W':
  114742. @@ -184,7 +189,9 @@
  114743. case 'E':
  114744. parse_checks_option(false, true, optarg);
  114745. break;
  114746. -
  114747. + case '@':
  114748. + symbol_fixup_support = 1;
  114749. + break;
  114750. case 'h':
  114751. usage(NULL);
  114752. default:
  114753. @@ -237,7 +244,7 @@
  114754. if (streq(outname, "-")) {
  114755. outf = stdout;
  114756. } else {
  114757. - outf = fopen(outname, "w");
  114758. + outf = fopen(outname, "wb");
  114759. if (! outf)
  114760. die("Couldn't open output file %s: %s\n",
  114761. outname, strerror(errno));
  114762. diff -Nur linux-3.18.6/scripts/dtc/dtc.h linux-rpi/scripts/dtc/dtc.h
  114763. --- linux-3.18.6/scripts/dtc/dtc.h 2015-02-06 15:53:48.000000000 +0100
  114764. +++ linux-rpi/scripts/dtc/dtc.h 2015-02-09 04:40:47.000000000 +0100
  114765. @@ -38,9 +38,9 @@
  114766. #include "util.h"
  114767. #ifdef DEBUG
  114768. -#define debug(fmt,args...) printf(fmt, ##args)
  114769. +#define debug(...) printf(__VA_ARGS__)
  114770. #else
  114771. -#define debug(fmt,args...)
  114772. +#define debug(...)
  114773. #endif
  114774. @@ -54,6 +54,7 @@
  114775. extern int minsize; /* Minimum blob size */
  114776. extern int padsize; /* Additional padding to blob */
  114777. extern int phandle_format; /* Use linux,phandle or phandle properties */
  114778. +extern int symbol_fixup_support;/* enable symbols & fixup support */
  114779. #define PHANDLE_LEGACY 0x1
  114780. #define PHANDLE_EPAPR 0x2
  114781. @@ -88,7 +89,7 @@
  114782. };
  114783. -#define empty_data ((struct data){ /* all .members = 0 or NULL */ })
  114784. +#define empty_data ((struct data){ 0 /* all .members = 0 or NULL */ })
  114785. #define for_each_marker(m) \
  114786. for (; (m); (m) = (m)->next)
  114787. @@ -118,7 +119,7 @@
  114788. struct data data_add_marker(struct data d, enum markertype type, char *ref);
  114789. -int data_is_one_string(struct data d);
  114790. +bool data_is_one_string(struct data d);
  114791. /* DT constraints */
  114792. @@ -127,13 +128,32 @@
  114793. /* Live trees */
  114794. struct label {
  114795. - int deleted;
  114796. + bool deleted;
  114797. char *label;
  114798. struct label *next;
  114799. };
  114800. +struct fixup_entry {
  114801. + int offset;
  114802. + struct node *node;
  114803. + struct property *prop;
  114804. + struct fixup_entry *next;
  114805. +};
  114806. +
  114807. +struct fixup {
  114808. + char *ref;
  114809. + struct fixup_entry *entries;
  114810. + struct fixup *next;
  114811. +};
  114812. +
  114813. +struct symbol {
  114814. + struct label *label;
  114815. + struct node *node;
  114816. + struct symbol *next;
  114817. +};
  114818. +
  114819. struct property {
  114820. - int deleted;
  114821. + bool deleted;
  114822. char *name;
  114823. struct data val;
  114824. @@ -143,7 +163,7 @@
  114825. };
  114826. struct node {
  114827. - int deleted;
  114828. + bool deleted;
  114829. char *name;
  114830. struct property *proplist;
  114831. struct node *children;
  114832. @@ -158,6 +178,12 @@
  114833. int addr_cells, size_cells;
  114834. struct label *labels;
  114835. +
  114836. + int is_root;
  114837. + int is_plugin;
  114838. + struct fixup *fixups;
  114839. + struct symbol *symbols;
  114840. + struct fixup_entry *local_fixups;
  114841. };
  114842. #define for_each_label_withdel(l0, l) \
  114843. @@ -181,6 +207,18 @@
  114844. for_each_child_withdel(n, c) \
  114845. if (!(c)->deleted)
  114846. +#define for_each_fixup(n, f) \
  114847. + for ((f) = (n)->fixups; (f); (f) = (f)->next)
  114848. +
  114849. +#define for_each_fixup_entry(f, fe) \
  114850. + for ((fe) = (f)->entries; (fe); (fe) = (fe)->next)
  114851. +
  114852. +#define for_each_symbol(n, s) \
  114853. + for ((s) = (n)->symbols; (s); (s) = (s)->next)
  114854. +
  114855. +#define for_each_local_fixup_entry(n, fe) \
  114856. + for ((fe) = (n)->local_fixups; (fe); (fe) = (fe)->next)
  114857. +
  114858. void add_label(struct label **labels, char *label);
  114859. void delete_labels(struct label **labels);
  114860. @@ -247,8 +285,8 @@
  114861. /* Checks */
  114862. -void parse_checks_option(bool warn, bool error, const char *optarg);
  114863. -void process_checks(int force, struct boot_info *bi);
  114864. +void parse_checks_option(bool warn, bool error, const char *arg);
  114865. +void process_checks(bool force, struct boot_info *bi);
  114866. /* Flattened trees */
  114867. diff -Nur linux-3.18.6/scripts/dtc/dtc-lexer.l linux-rpi/scripts/dtc/dtc-lexer.l
  114868. --- linux-3.18.6/scripts/dtc/dtc-lexer.l 2015-02-06 15:53:48.000000000 +0100
  114869. +++ linux-rpi/scripts/dtc/dtc-lexer.l 2015-02-09 04:40:47.000000000 +0100
  114870. @@ -20,7 +20,6 @@
  114871. %option noyywrap nounput noinput never-interactive
  114872. -%x INCLUDE
  114873. %x BYTESTRING
  114874. %x PROPNODENAME
  114875. %s V1
  114876. @@ -40,6 +39,7 @@
  114877. #include "dtc-parser.tab.h"
  114878. YYLTYPE yylloc;
  114879. +extern bool treesource_error;
  114880. /* CAUTION: this will stop working if we ever use yyless() or yyunput() */
  114881. #define YY_USER_ACTION \
  114882. @@ -61,7 +61,8 @@
  114883. BEGIN(V1); \
  114884. static void push_input_file(const char *filename);
  114885. -static int pop_input_file(void);
  114886. +static bool pop_input_file(void);
  114887. +static void lexical_error(const char *fmt, ...);
  114888. %}
  114889. %%
  114890. @@ -75,11 +76,11 @@
  114891. char *line, *tmp, *fn;
  114892. /* skip text before line # */
  114893. line = yytext;
  114894. - while (!isdigit(*line))
  114895. + while (!isdigit((unsigned char)*line))
  114896. line++;
  114897. /* skip digits in line # */
  114898. tmp = line;
  114899. - while (!isspace(*tmp))
  114900. + while (!isspace((unsigned char)*tmp))
  114901. tmp++;
  114902. /* "NULL"-terminate line # */
  114903. *tmp = '\0';
  114904. @@ -112,6 +113,11 @@
  114905. return DT_V1;
  114906. }
  114907. +<*>"/plugin/" {
  114908. + DPRINT("Keyword: /plugin/\n");
  114909. + return DT_PLUGIN;
  114910. + }
  114911. +
  114912. <*>"/memreserve/" {
  114913. DPRINT("Keyword: /memreserve/\n");
  114914. BEGIN_DEFAULT();
  114915. @@ -146,15 +152,42 @@
  114916. }
  114917. <V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
  114918. - yylval.literal = xstrdup(yytext);
  114919. - DPRINT("Literal: '%s'\n", yylval.literal);
  114920. + char *e;
  114921. + DPRINT("Integer Literal: '%s'\n", yytext);
  114922. +
  114923. + errno = 0;
  114924. + yylval.integer = strtoull(yytext, &e, 0);
  114925. +
  114926. + assert(!(*e) || !e[strspn(e, "UL")]);
  114927. +
  114928. + if (errno == ERANGE)
  114929. + lexical_error("Integer literal '%s' out of range",
  114930. + yytext);
  114931. + else
  114932. + /* ERANGE is the only strtoull error triggerable
  114933. + * by strings matching the pattern */
  114934. + assert(errno == 0);
  114935. return DT_LITERAL;
  114936. }
  114937. <*>{CHAR_LITERAL} {
  114938. - yytext[yyleng-1] = '\0';
  114939. - yylval.literal = xstrdup(yytext+1);
  114940. - DPRINT("Character literal: %s\n", yylval.literal);
  114941. + struct data d;
  114942. + DPRINT("Character literal: %s\n", yytext);
  114943. +
  114944. + d = data_copy_escape_string(yytext+1, yyleng-2);
  114945. + if (d.len == 1) {
  114946. + lexical_error("Empty character literal");
  114947. + yylval.integer = 0;
  114948. + return DT_CHAR_LITERAL;
  114949. + }
  114950. +
  114951. + yylval.integer = (unsigned char)d.val[0];
  114952. +
  114953. + if (d.len > 2)
  114954. + lexical_error("Character literal has %d"
  114955. + " characters instead of 1",
  114956. + d.len - 1);
  114957. +
  114958. return DT_CHAR_LITERAL;
  114959. }
  114960. @@ -164,7 +197,7 @@
  114961. return DT_REF;
  114962. }
  114963. -<*>"&{/"{PATHCHAR}+\} { /* new-style path reference */
  114964. +<*>"&{/"{PATHCHAR}*\} { /* new-style path reference */
  114965. yytext[yyleng-1] = '\0';
  114966. DPRINT("Ref: %s\n", yytext+2);
  114967. yylval.labelref = xstrdup(yytext+2);
  114968. @@ -238,13 +271,24 @@
  114969. }
  114970. -static int pop_input_file(void)
  114971. +static bool pop_input_file(void)
  114972. {
  114973. if (srcfile_pop() == 0)
  114974. - return 0;
  114975. + return false;
  114976. yypop_buffer_state();
  114977. yyin = current_srcfile->f;
  114978. - return 1;
  114979. + return true;
  114980. +}
  114981. +
  114982. +static void lexical_error(const char *fmt, ...)
  114983. +{
  114984. + va_list ap;
  114985. +
  114986. + va_start(ap, fmt);
  114987. + srcpos_verror(&yylloc, "Lexical error", fmt, ap);
  114988. + va_end(ap);
  114989. +
  114990. + treesource_error = true;
  114991. }
  114992. diff -Nur linux-3.18.6/scripts/dtc/dtc-lexer.lex.c_shipped linux-rpi/scripts/dtc/dtc-lexer.lex.c_shipped
  114993. --- linux-3.18.6/scripts/dtc/dtc-lexer.lex.c_shipped 2015-02-06 15:53:48.000000000 +0100
  114994. +++ linux-rpi/scripts/dtc/dtc-lexer.lex.c_shipped 2015-02-09 04:40:47.000000000 +0100
  114995. @@ -372,8 +372,8 @@
  114996. *yy_cp = '\0'; \
  114997. (yy_c_buf_p) = yy_cp;
  114998. -#define YY_NUM_RULES 30
  114999. -#define YY_END_OF_BUFFER 31
  115000. +#define YY_NUM_RULES 31
  115001. +#define YY_END_OF_BUFFER 32
  115002. /* This struct is not used in this scanner,
  115003. but its presence is necessary. */
  115004. struct yy_trans_info
  115005. @@ -381,25 +381,26 @@
  115006. flex_int32_t yy_verify;
  115007. flex_int32_t yy_nxt;
  115008. };
  115009. -static yyconst flex_int16_t yy_accept[161] =
  115010. +static yyconst flex_int16_t yy_accept[166] =
  115011. { 0,
  115012. + 0, 0, 0, 0, 0, 0, 0, 0, 32, 30,
  115013. + 19, 19, 30, 30, 30, 30, 30, 30, 30, 30,
  115014. + 30, 30, 30, 30, 30, 30, 16, 17, 17, 30,
  115015. + 17, 11, 11, 19, 27, 0, 3, 0, 28, 13,
  115016. + 0, 0, 12, 0, 0, 0, 0, 0, 0, 0,
  115017. + 0, 22, 24, 26, 25, 23, 0, 10, 29, 0,
  115018. + 0, 0, 15, 15, 17, 17, 17, 11, 11, 11,
  115019. + 0, 13, 0, 12, 0, 0, 0, 21, 0, 0,
  115020. + 0, 0, 0, 0, 0, 0, 0, 17, 11, 11,
  115021. + 11, 0, 14, 20, 0, 0, 0, 0, 0, 0,
  115022. +
  115023. + 0, 0, 0, 0, 17, 0, 0, 0, 0, 0,
  115024. + 0, 0, 0, 0, 0, 17, 7, 0, 0, 0,
  115025. + 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
  115026. + 0, 0, 0, 0, 4, 18, 0, 0, 5, 2,
  115027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115028. - 31, 29, 18, 18, 29, 29, 29, 29, 29, 29,
  115029. - 29, 29, 29, 29, 29, 29, 29, 29, 15, 16,
  115030. - 16, 29, 16, 10, 10, 18, 26, 0, 3, 0,
  115031. - 27, 12, 0, 0, 11, 0, 0, 0, 0, 0,
  115032. - 0, 0, 21, 23, 25, 24, 22, 0, 9, 28,
  115033. - 0, 0, 0, 14, 14, 16, 16, 16, 10, 10,
  115034. - 10, 0, 12, 0, 11, 0, 0, 0, 20, 0,
  115035. - 0, 0, 0, 0, 0, 0, 0, 16, 10, 10,
  115036. - 10, 0, 19, 0, 0, 0, 0, 0, 0, 0,
  115037. -
  115038. - 0, 0, 16, 13, 0, 0, 0, 0, 0, 0,
  115039. - 0, 0, 0, 16, 6, 0, 0, 0, 0, 0,
  115040. - 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
  115041. - 4, 17, 0, 0, 2, 0, 0, 0, 0, 0,
  115042. - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
  115043. - 0, 0, 5, 8, 0, 0, 0, 0, 7, 0
  115044. + 0, 0, 1, 0, 0, 0, 0, 6, 9, 0,
  115045. + 0, 0, 0, 8, 0
  115046. } ;
  115047. static yyconst flex_int32_t yy_ec[256] =
  115048. @@ -415,9 +416,9 @@
  115049. 22, 22, 22, 22, 24, 22, 22, 25, 22, 22,
  115050. 1, 26, 27, 1, 22, 1, 21, 28, 29, 30,
  115051. - 31, 21, 22, 22, 32, 22, 22, 33, 34, 35,
  115052. - 36, 37, 22, 38, 39, 40, 41, 42, 22, 25,
  115053. - 43, 22, 44, 45, 46, 1, 1, 1, 1, 1,
  115054. + 31, 21, 32, 22, 33, 22, 22, 34, 35, 36,
  115055. + 37, 38, 22, 39, 40, 41, 42, 43, 22, 25,
  115056. + 44, 22, 45, 46, 47, 1, 1, 1, 1, 1,
  115057. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  115058. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  115059. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  115060. @@ -434,163 +435,165 @@
  115061. 1, 1, 1, 1, 1
  115062. } ;
  115063. -static yyconst flex_int32_t yy_meta[47] =
  115064. +static yyconst flex_int32_t yy_meta[48] =
  115065. { 0,
  115066. 1, 1, 1, 1, 1, 1, 2, 3, 1, 2,
  115067. 2, 2, 4, 5, 5, 5, 6, 1, 1, 1,
  115068. 7, 8, 8, 8, 8, 1, 1, 7, 7, 7,
  115069. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  115070. - 8, 8, 8, 3, 1, 1
  115071. + 8, 8, 8, 8, 3, 1, 4
  115072. } ;
  115073. -static yyconst flex_int16_t yy_base[175] =
  115074. +static yyconst flex_int16_t yy_base[180] =
  115075. { 0,
  115076. - 0, 385, 378, 40, 41, 383, 72, 382, 34, 44,
  115077. - 388, 393, 61, 117, 368, 116, 115, 115, 115, 48,
  115078. - 367, 107, 368, 339, 127, 120, 0, 147, 393, 0,
  115079. - 127, 0, 133, 156, 168, 153, 393, 125, 393, 380,
  115080. - 393, 0, 369, 127, 393, 160, 371, 377, 347, 21,
  115081. - 343, 346, 393, 393, 393, 393, 393, 359, 393, 393,
  115082. - 183, 343, 339, 393, 356, 0, 183, 340, 187, 348,
  115083. - 347, 0, 0, 0, 178, 359, 195, 365, 354, 326,
  115084. - 332, 325, 334, 328, 204, 326, 331, 324, 393, 335,
  115085. - 150, 311, 343, 342, 315, 322, 340, 179, 313, 207,
  115086. -
  115087. - 319, 316, 317, 393, 337, 333, 305, 302, 311, 301,
  115088. - 310, 190, 338, 337, 393, 307, 322, 301, 305, 277,
  115089. - 208, 311, 307, 278, 271, 270, 248, 246, 213, 130,
  115090. - 393, 393, 263, 235, 207, 221, 218, 229, 213, 213,
  115091. - 206, 234, 218, 210, 208, 193, 219, 393, 223, 204,
  115092. - 176, 157, 393, 393, 120, 106, 97, 119, 393, 393,
  115093. - 245, 251, 259, 263, 267, 273, 280, 284, 292, 300,
  115094. - 304, 310, 318, 326
  115095. + 0, 393, 35, 392, 66, 391, 38, 107, 397, 401,
  115096. + 55, 113, 377, 112, 111, 111, 114, 42, 376, 106,
  115097. + 377, 347, 126, 120, 0, 147, 401, 0, 124, 0,
  115098. + 137, 158, 170, 163, 401, 153, 401, 389, 401, 0,
  115099. + 378, 120, 401, 131, 380, 386, 355, 139, 351, 355,
  115100. + 351, 401, 401, 401, 401, 401, 367, 401, 401, 185,
  115101. + 350, 346, 401, 364, 0, 185, 347, 189, 356, 355,
  115102. + 0, 0, 330, 180, 366, 141, 372, 361, 332, 338,
  115103. + 331, 341, 334, 326, 205, 331, 337, 329, 401, 341,
  115104. + 167, 316, 401, 349, 348, 320, 328, 346, 180, 318,
  115105. +
  115106. + 324, 209, 324, 320, 322, 342, 338, 309, 306, 315,
  115107. + 305, 315, 312, 192, 342, 341, 401, 293, 306, 282,
  115108. + 268, 252, 255, 203, 285, 282, 272, 268, 252, 233,
  115109. + 232, 239, 208, 107, 401, 401, 238, 211, 401, 211,
  115110. + 212, 208, 228, 203, 215, 207, 233, 222, 212, 211,
  115111. + 203, 227, 401, 237, 225, 204, 185, 401, 401, 149,
  115112. + 128, 88, 42, 401, 401, 253, 259, 267, 271, 275,
  115113. + 281, 288, 292, 300, 308, 312, 318, 326, 334
  115114. } ;
  115115. -static yyconst flex_int16_t yy_def[175] =
  115116. +static yyconst flex_int16_t yy_def[180] =
  115117. { 0,
  115118. - 160, 1, 1, 1, 1, 5, 160, 7, 1, 1,
  115119. - 160, 160, 160, 160, 160, 161, 162, 163, 160, 160,
  115120. - 160, 160, 164, 160, 160, 160, 165, 164, 160, 166,
  115121. - 167, 166, 166, 160, 160, 160, 160, 161, 160, 161,
  115122. - 160, 168, 160, 163, 160, 163, 169, 170, 160, 160,
  115123. - 160, 160, 160, 160, 160, 160, 160, 164, 160, 160,
  115124. - 160, 160, 160, 160, 164, 166, 167, 166, 160, 160,
  115125. - 160, 171, 168, 172, 163, 169, 169, 170, 160, 160,
  115126. - 160, 160, 160, 160, 160, 160, 160, 166, 160, 160,
  115127. - 171, 172, 160, 160, 160, 160, 160, 160, 160, 160,
  115128. -
  115129. - 160, 160, 166, 160, 160, 160, 160, 160, 160, 160,
  115130. - 160, 173, 160, 166, 160, 160, 160, 160, 160, 160,
  115131. - 173, 160, 173, 160, 160, 160, 160, 160, 160, 160,
  115132. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  115133. - 160, 160, 174, 160, 160, 160, 174, 160, 174, 160,
  115134. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 0,
  115135. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  115136. - 160, 160, 160, 160
  115137. + 165, 1, 1, 3, 165, 5, 1, 1, 165, 165,
  115138. + 165, 165, 165, 166, 167, 168, 165, 165, 165, 165,
  115139. + 169, 165, 165, 165, 170, 169, 165, 171, 172, 171,
  115140. + 171, 165, 165, 165, 165, 166, 165, 166, 165, 173,
  115141. + 165, 168, 165, 168, 174, 175, 165, 165, 165, 165,
  115142. + 165, 165, 165, 165, 165, 165, 169, 165, 165, 165,
  115143. + 165, 165, 165, 169, 171, 172, 171, 165, 165, 165,
  115144. + 176, 173, 177, 168, 174, 174, 175, 165, 165, 165,
  115145. + 165, 165, 165, 165, 165, 165, 165, 171, 165, 165,
  115146. + 176, 177, 165, 165, 165, 165, 165, 165, 165, 165,
  115147. +
  115148. + 165, 165, 165, 165, 171, 165, 165, 165, 165, 165,
  115149. + 165, 165, 165, 178, 165, 171, 165, 165, 165, 165,
  115150. + 165, 165, 165, 178, 165, 178, 165, 165, 165, 165,
  115151. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  115152. + 165, 165, 165, 165, 165, 165, 165, 179, 165, 165,
  115153. + 165, 179, 165, 179, 165, 165, 165, 165, 165, 165,
  115154. + 165, 165, 165, 165, 0, 165, 165, 165, 165, 165,
  115155. + 165, 165, 165, 165, 165, 165, 165, 165, 165
  115156. } ;
  115157. -static yyconst flex_int16_t yy_nxt[440] =
  115158. +static yyconst flex_int16_t yy_nxt[449] =
  115159. { 0,
  115160. - 12, 13, 14, 13, 15, 16, 12, 17, 18, 12,
  115161. - 12, 12, 19, 12, 12, 12, 12, 20, 21, 22,
  115162. - 23, 23, 23, 23, 23, 12, 12, 23, 23, 23,
  115163. - 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  115164. - 23, 23, 23, 12, 24, 12, 25, 34, 35, 35,
  115165. - 25, 81, 26, 26, 27, 27, 27, 34, 35, 35,
  115166. - 82, 28, 36, 36, 36, 53, 54, 29, 28, 28,
  115167. - 28, 28, 12, 13, 14, 13, 15, 16, 30, 17,
  115168. - 18, 30, 30, 30, 26, 30, 30, 30, 12, 20,
  115169. - 21, 22, 31, 31, 31, 31, 31, 32, 12, 31,
  115170. -
  115171. - 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
  115172. - 31, 31, 31, 31, 31, 12, 24, 12, 36, 36,
  115173. - 36, 39, 41, 45, 47, 56, 57, 48, 61, 47,
  115174. - 39, 159, 48, 66, 61, 45, 66, 66, 66, 158,
  115175. - 46, 40, 49, 59, 50, 157, 51, 49, 52, 50,
  115176. - 40, 63, 46, 52, 36, 36, 36, 156, 43, 62,
  115177. - 65, 65, 65, 59, 136, 68, 137, 65, 75, 69,
  115178. - 69, 69, 70, 71, 65, 65, 65, 65, 70, 71,
  115179. - 72, 69, 69, 69, 61, 46, 45, 155, 154, 66,
  115180. - 70, 71, 66, 66, 66, 122, 85, 85, 85, 59,
  115181. -
  115182. - 69, 69, 69, 46, 77, 100, 109, 93, 100, 70,
  115183. - 71, 110, 112, 122, 129, 123, 153, 85, 85, 85,
  115184. - 135, 135, 135, 148, 148, 160, 135, 135, 135, 152,
  115185. - 142, 142, 142, 123, 143, 142, 142, 142, 151, 143,
  115186. - 150, 146, 145, 149, 149, 38, 38, 38, 38, 38,
  115187. - 38, 38, 38, 42, 144, 141, 140, 42, 42, 44,
  115188. - 44, 44, 44, 44, 44, 44, 44, 58, 58, 58,
  115189. - 58, 64, 139, 64, 66, 138, 134, 66, 133, 66,
  115190. - 66, 67, 132, 131, 67, 67, 67, 67, 73, 130,
  115191. - 73, 73, 76, 76, 76, 76, 76, 76, 76, 76,
  115192. -
  115193. - 78, 78, 78, 78, 78, 78, 78, 78, 91, 160,
  115194. - 91, 92, 129, 92, 92, 128, 92, 92, 121, 121,
  115195. - 121, 121, 121, 121, 121, 121, 147, 147, 147, 147,
  115196. - 147, 147, 147, 147, 127, 126, 125, 124, 61, 61,
  115197. - 120, 119, 118, 117, 116, 115, 47, 114, 110, 113,
  115198. - 111, 108, 107, 106, 48, 105, 104, 89, 103, 102,
  115199. - 101, 99, 98, 97, 96, 95, 94, 79, 77, 90,
  115200. - 89, 88, 59, 87, 86, 59, 84, 83, 80, 79,
  115201. - 77, 74, 160, 60, 59, 55, 37, 160, 33, 25,
  115202. - 26, 25, 11, 160, 160, 160, 160, 160, 160, 160,
  115203. -
  115204. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  115205. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  115206. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  115207. - 160, 160, 160, 160, 160, 160, 160, 160, 160
  115208. + 10, 11, 12, 11, 13, 14, 10, 15, 16, 10,
  115209. + 10, 10, 17, 10, 10, 10, 10, 18, 19, 20,
  115210. + 21, 21, 21, 21, 21, 10, 10, 21, 21, 21,
  115211. + 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
  115212. + 21, 21, 21, 21, 10, 22, 10, 24, 25, 25,
  115213. + 25, 32, 33, 33, 164, 26, 34, 34, 34, 52,
  115214. + 53, 27, 26, 26, 26, 26, 10, 11, 12, 11,
  115215. + 13, 14, 28, 15, 16, 28, 28, 28, 24, 28,
  115216. + 28, 28, 10, 18, 19, 20, 29, 29, 29, 29,
  115217. + 29, 30, 10, 29, 29, 29, 29, 29, 29, 29,
  115218. +
  115219. + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  115220. + 10, 22, 10, 23, 34, 34, 34, 37, 39, 43,
  115221. + 32, 33, 33, 45, 55, 56, 46, 60, 43, 45,
  115222. + 65, 163, 46, 65, 65, 65, 44, 38, 60, 74,
  115223. + 58, 47, 141, 48, 142, 44, 49, 47, 50, 48,
  115224. + 76, 51, 62, 94, 50, 41, 44, 51, 37, 61,
  115225. + 64, 64, 64, 58, 34, 34, 34, 64, 162, 80,
  115226. + 67, 68, 68, 68, 64, 64, 64, 64, 38, 81,
  115227. + 69, 70, 71, 68, 68, 68, 60, 161, 43, 69,
  115228. + 70, 65, 69, 70, 65, 65, 65, 125, 85, 85,
  115229. +
  115230. + 85, 58, 68, 68, 68, 44, 102, 110, 125, 133,
  115231. + 102, 69, 70, 111, 114, 160, 159, 126, 85, 85,
  115232. + 85, 140, 140, 140, 140, 140, 140, 153, 126, 147,
  115233. + 147, 147, 153, 148, 147, 147, 147, 158, 148, 165,
  115234. + 157, 156, 155, 151, 150, 149, 146, 154, 145, 144,
  115235. + 143, 139, 154, 36, 36, 36, 36, 36, 36, 36,
  115236. + 36, 40, 138, 137, 136, 40, 40, 42, 42, 42,
  115237. + 42, 42, 42, 42, 42, 57, 57, 57, 57, 63,
  115238. + 135, 63, 65, 134, 165, 65, 133, 65, 65, 66,
  115239. + 132, 131, 66, 66, 66, 66, 72, 130, 72, 72,
  115240. +
  115241. + 75, 75, 75, 75, 75, 75, 75, 75, 77, 77,
  115242. + 77, 77, 77, 77, 77, 77, 91, 129, 91, 92,
  115243. + 128, 92, 92, 127, 92, 92, 124, 124, 124, 124,
  115244. + 124, 124, 124, 124, 152, 152, 152, 152, 152, 152,
  115245. + 152, 152, 60, 60, 123, 122, 121, 120, 119, 118,
  115246. + 117, 45, 116, 111, 115, 113, 112, 109, 108, 107,
  115247. + 46, 106, 93, 89, 105, 104, 103, 101, 100, 99,
  115248. + 98, 97, 96, 95, 78, 76, 93, 90, 89, 88,
  115249. + 58, 87, 86, 58, 84, 83, 82, 79, 78, 76,
  115250. + 73, 165, 59, 58, 54, 35, 165, 31, 23, 23,
  115251. +
  115252. + 9, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  115253. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  115254. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  115255. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  115256. + 165, 165, 165, 165, 165, 165, 165, 165
  115257. } ;
  115258. -static yyconst flex_int16_t yy_chk[440] =
  115259. +static yyconst flex_int16_t yy_chk[449] =
  115260. { 0,
  115261. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  115262. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  115263. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  115264. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  115265. - 1, 1, 1, 1, 1, 1, 4, 9, 9, 9,
  115266. - 10, 50, 4, 5, 5, 5, 5, 10, 10, 10,
  115267. - 50, 5, 13, 13, 13, 20, 20, 5, 5, 5,
  115268. - 5, 5, 7, 7, 7, 7, 7, 7, 7, 7,
  115269. - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  115270. - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  115271. -
  115272. - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  115273. - 7, 7, 7, 7, 7, 7, 7, 7, 14, 14,
  115274. - 14, 16, 17, 18, 19, 22, 22, 19, 25, 26,
  115275. - 38, 158, 26, 31, 33, 44, 31, 31, 31, 157,
  115276. - 18, 16, 19, 31, 19, 156, 19, 26, 19, 26,
  115277. - 38, 26, 44, 26, 36, 36, 36, 155, 17, 25,
  115278. - 28, 28, 28, 28, 130, 33, 130, 28, 46, 34,
  115279. - 34, 34, 91, 91, 28, 28, 28, 28, 34, 34,
  115280. - 34, 35, 35, 35, 61, 46, 75, 152, 151, 67,
  115281. - 35, 35, 67, 67, 67, 112, 61, 61, 61, 67,
  115282. -
  115283. - 69, 69, 69, 75, 77, 85, 98, 77, 100, 69,
  115284. - 69, 98, 100, 121, 129, 112, 150, 85, 85, 85,
  115285. - 135, 135, 135, 143, 147, 149, 129, 129, 129, 146,
  115286. - 138, 138, 138, 121, 138, 142, 142, 142, 145, 142,
  115287. - 144, 141, 140, 143, 147, 161, 161, 161, 161, 161,
  115288. - 161, 161, 161, 162, 139, 137, 136, 162, 162, 163,
  115289. - 163, 163, 163, 163, 163, 163, 163, 164, 164, 164,
  115290. - 164, 165, 134, 165, 166, 133, 128, 166, 127, 166,
  115291. - 166, 167, 126, 125, 167, 167, 167, 167, 168, 124,
  115292. - 168, 168, 169, 169, 169, 169, 169, 169, 169, 169,
  115293. -
  115294. - 170, 170, 170, 170, 170, 170, 170, 170, 171, 123,
  115295. - 171, 172, 122, 172, 172, 120, 172, 172, 173, 173,
  115296. - 173, 173, 173, 173, 173, 173, 174, 174, 174, 174,
  115297. - 174, 174, 174, 174, 119, 118, 117, 116, 114, 113,
  115298. - 111, 110, 109, 108, 107, 106, 105, 103, 102, 101,
  115299. - 99, 97, 96, 95, 94, 93, 92, 90, 88, 87,
  115300. - 86, 84, 83, 82, 81, 80, 79, 78, 76, 71,
  115301. - 70, 68, 65, 63, 62, 58, 52, 51, 49, 48,
  115302. - 47, 43, 40, 24, 23, 21, 15, 11, 8, 6,
  115303. - 3, 2, 160, 160, 160, 160, 160, 160, 160, 160,
  115304. -
  115305. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  115306. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  115307. - 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
  115308. - 160, 160, 160, 160, 160, 160, 160, 160, 160
  115309. + 1, 1, 1, 1, 1, 1, 1, 3, 3, 3,
  115310. + 3, 7, 7, 7, 163, 3, 11, 11, 11, 18,
  115311. + 18, 3, 3, 3, 3, 3, 5, 5, 5, 5,
  115312. + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  115313. + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  115314. + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  115315. +
  115316. + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  115317. + 5, 5, 5, 8, 12, 12, 12, 14, 15, 16,
  115318. + 8, 8, 8, 17, 20, 20, 17, 23, 42, 24,
  115319. + 29, 162, 24, 29, 29, 29, 16, 14, 31, 44,
  115320. + 29, 17, 134, 17, 134, 42, 17, 24, 17, 24,
  115321. + 76, 17, 24, 76, 24, 15, 44, 24, 36, 23,
  115322. + 26, 26, 26, 26, 34, 34, 34, 26, 161, 48,
  115323. + 31, 32, 32, 32, 26, 26, 26, 26, 36, 48,
  115324. + 32, 32, 32, 33, 33, 33, 60, 160, 74, 91,
  115325. + 91, 66, 33, 33, 66, 66, 66, 114, 60, 60,
  115326. +
  115327. + 60, 66, 68, 68, 68, 74, 85, 99, 124, 133,
  115328. + 102, 68, 68, 99, 102, 157, 156, 114, 85, 85,
  115329. + 85, 133, 133, 133, 140, 140, 140, 148, 124, 143,
  115330. + 143, 143, 152, 143, 147, 147, 147, 155, 147, 154,
  115331. + 151, 150, 149, 146, 145, 144, 142, 148, 141, 138,
  115332. + 137, 132, 152, 166, 166, 166, 166, 166, 166, 166,
  115333. + 166, 167, 131, 130, 129, 167, 167, 168, 168, 168,
  115334. + 168, 168, 168, 168, 168, 169, 169, 169, 169, 170,
  115335. + 128, 170, 171, 127, 126, 171, 125, 171, 171, 172,
  115336. + 123, 122, 172, 172, 172, 172, 173, 121, 173, 173,
  115337. +
  115338. + 174, 174, 174, 174, 174, 174, 174, 174, 175, 175,
  115339. + 175, 175, 175, 175, 175, 175, 176, 120, 176, 177,
  115340. + 119, 177, 177, 118, 177, 177, 178, 178, 178, 178,
  115341. + 178, 178, 178, 178, 179, 179, 179, 179, 179, 179,
  115342. + 179, 179, 116, 115, 113, 112, 111, 110, 109, 108,
  115343. + 107, 106, 105, 104, 103, 101, 100, 98, 97, 96,
  115344. + 95, 94, 92, 90, 88, 87, 86, 84, 83, 82,
  115345. + 81, 80, 79, 78, 77, 75, 73, 70, 69, 67,
  115346. + 64, 62, 61, 57, 51, 50, 49, 47, 46, 45,
  115347. + 41, 38, 22, 21, 19, 13, 9, 6, 4, 2,
  115348. +
  115349. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  115350. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  115351. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  115352. + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
  115353. + 165, 165, 165, 165, 165, 165, 165, 165
  115354. } ;
  115355. static yy_state_type yy_last_accepting_state;
  115356. @@ -631,13 +634,13 @@
  115357. -
  115358. -#line 38 "dtc-lexer.l"
  115359. +#line 37 "dtc-lexer.l"
  115360. #include "dtc.h"
  115361. #include "srcpos.h"
  115362. #include "dtc-parser.tab.h"
  115363. YYLTYPE yylloc;
  115364. +extern bool treesource_error;
  115365. /* CAUTION: this will stop working if we ever use yyless() or yyunput() */
  115366. #define YY_USER_ACTION \
  115367. @@ -659,14 +662,14 @@
  115368. BEGIN(V1); \
  115369. static void push_input_file(const char *filename);
  115370. -static int pop_input_file(void);
  115371. -#line 664 "dtc-lexer.lex.c"
  115372. +static bool pop_input_file(void);
  115373. +static void lexical_error(const char *fmt, ...);
  115374. +#line 668 "dtc-lexer.lex.c"
  115375. #define INITIAL 0
  115376. -#define INCLUDE 1
  115377. -#define BYTESTRING 2
  115378. -#define PROPNODENAME 3
  115379. -#define V1 4
  115380. +#define BYTESTRING 1
  115381. +#define PROPNODENAME 2
  115382. +#define V1 3
  115383. #ifndef YY_NO_UNISTD_H
  115384. /* Special case for "unistd.h", since it is non-ANSI. We include it way
  115385. @@ -852,9 +855,9 @@
  115386. register char *yy_cp, *yy_bp;
  115387. register int yy_act;
  115388. -#line 67 "dtc-lexer.l"
  115389. +#line 68 "dtc-lexer.l"
  115390. -#line 858 "dtc-lexer.lex.c"
  115391. +#line 861 "dtc-lexer.lex.c"
  115392. if ( !(yy_init) )
  115393. {
  115394. @@ -908,13 +911,13 @@
  115395. while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  115396. {
  115397. yy_current_state = (int) yy_def[yy_current_state];
  115398. - if ( yy_current_state >= 161 )
  115399. + if ( yy_current_state >= 166 )
  115400. yy_c = yy_meta[(unsigned int) yy_c];
  115401. }
  115402. yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
  115403. ++yy_cp;
  115404. }
  115405. - while ( yy_current_state != 160 );
  115406. + while ( yy_current_state != 165 );
  115407. yy_cp = (yy_last_accepting_cpos);
  115408. yy_current_state = (yy_last_accepting_state);
  115409. @@ -937,7 +940,7 @@
  115410. case 1:
  115411. /* rule 1 can match eol */
  115412. YY_RULE_SETUP
  115413. -#line 68 "dtc-lexer.l"
  115414. +#line 69 "dtc-lexer.l"
  115415. {
  115416. char *name = strchr(yytext, '\"') + 1;
  115417. yytext[yyleng-1] = '\0';
  115418. @@ -947,16 +950,16 @@
  115419. case 2:
  115420. /* rule 2 can match eol */
  115421. YY_RULE_SETUP
  115422. -#line 74 "dtc-lexer.l"
  115423. +#line 75 "dtc-lexer.l"
  115424. {
  115425. char *line, *tmp, *fn;
  115426. /* skip text before line # */
  115427. line = yytext;
  115428. - while (!isdigit(*line))
  115429. + while (!isdigit((unsigned char)*line))
  115430. line++;
  115431. /* skip digits in line # */
  115432. tmp = line;
  115433. - while (!isspace(*tmp))
  115434. + while (!isspace((unsigned char)*tmp))
  115435. tmp++;
  115436. /* "NULL"-terminate line # */
  115437. *tmp = '\0';
  115438. @@ -970,11 +973,10 @@
  115439. }
  115440. YY_BREAK
  115441. case YY_STATE_EOF(INITIAL):
  115442. -case YY_STATE_EOF(INCLUDE):
  115443. case YY_STATE_EOF(BYTESTRING):
  115444. case YY_STATE_EOF(PROPNODENAME):
  115445. case YY_STATE_EOF(V1):
  115446. -#line 95 "dtc-lexer.l"
  115447. +#line 96 "dtc-lexer.l"
  115448. {
  115449. if (!pop_input_file()) {
  115450. yyterminate();
  115451. @@ -984,7 +986,7 @@
  115452. case 3:
  115453. /* rule 3 can match eol */
  115454. YY_RULE_SETUP
  115455. -#line 101 "dtc-lexer.l"
  115456. +#line 102 "dtc-lexer.l"
  115457. {
  115458. DPRINT("String: %s\n", yytext);
  115459. yylval.data = data_copy_escape_string(yytext+1,
  115460. @@ -994,7 +996,7 @@
  115461. YY_BREAK
  115462. case 4:
  115463. YY_RULE_SETUP
  115464. -#line 108 "dtc-lexer.l"
  115465. +#line 109 "dtc-lexer.l"
  115466. {
  115467. DPRINT("Keyword: /dts-v1/\n");
  115468. dts_version = 1;
  115469. @@ -1004,25 +1006,33 @@
  115470. YY_BREAK
  115471. case 5:
  115472. YY_RULE_SETUP
  115473. -#line 115 "dtc-lexer.l"
  115474. +#line 116 "dtc-lexer.l"
  115475. +{
  115476. + DPRINT("Keyword: /plugin/\n");
  115477. + return DT_PLUGIN;
  115478. + }
  115479. + YY_BREAK
  115480. +case 6:
  115481. +YY_RULE_SETUP
  115482. +#line 121 "dtc-lexer.l"
  115483. {
  115484. DPRINT("Keyword: /memreserve/\n");
  115485. BEGIN_DEFAULT();
  115486. return DT_MEMRESERVE;
  115487. }
  115488. YY_BREAK
  115489. -case 6:
  115490. +case 7:
  115491. YY_RULE_SETUP
  115492. -#line 121 "dtc-lexer.l"
  115493. +#line 127 "dtc-lexer.l"
  115494. {
  115495. DPRINT("Keyword: /bits/\n");
  115496. BEGIN_DEFAULT();
  115497. return DT_BITS;
  115498. }
  115499. YY_BREAK
  115500. -case 7:
  115501. +case 8:
  115502. YY_RULE_SETUP
  115503. -#line 127 "dtc-lexer.l"
  115504. +#line 133 "dtc-lexer.l"
  115505. {
  115506. DPRINT("Keyword: /delete-property/\n");
  115507. DPRINT("<PROPNODENAME>\n");
  115508. @@ -1030,9 +1040,9 @@
  115509. return DT_DEL_PROP;
  115510. }
  115511. YY_BREAK
  115512. -case 8:
  115513. +case 9:
  115514. YY_RULE_SETUP
  115515. -#line 134 "dtc-lexer.l"
  115516. +#line 140 "dtc-lexer.l"
  115517. {
  115518. DPRINT("Keyword: /delete-node/\n");
  115519. DPRINT("<PROPNODENAME>\n");
  115520. @@ -1040,9 +1050,9 @@
  115521. return DT_DEL_NODE;
  115522. }
  115523. YY_BREAK
  115524. -case 9:
  115525. +case 10:
  115526. YY_RULE_SETUP
  115527. -#line 141 "dtc-lexer.l"
  115528. +#line 147 "dtc-lexer.l"
  115529. {
  115530. DPRINT("Label: %s\n", yytext);
  115531. yylval.labelref = xstrdup(yytext);
  115532. @@ -1050,38 +1060,65 @@
  115533. return DT_LABEL;
  115534. }
  115535. YY_BREAK
  115536. -case 10:
  115537. +case 11:
  115538. YY_RULE_SETUP
  115539. -#line 148 "dtc-lexer.l"
  115540. +#line 154 "dtc-lexer.l"
  115541. {
  115542. - yylval.literal = xstrdup(yytext);
  115543. - DPRINT("Literal: '%s'\n", yylval.literal);
  115544. + char *e;
  115545. + DPRINT("Integer Literal: '%s'\n", yytext);
  115546. +
  115547. + errno = 0;
  115548. + yylval.integer = strtoull(yytext, &e, 0);
  115549. +
  115550. + assert(!(*e) || !e[strspn(e, "UL")]);
  115551. +
  115552. + if (errno == ERANGE)
  115553. + lexical_error("Integer literal '%s' out of range",
  115554. + yytext);
  115555. + else
  115556. + /* ERANGE is the only strtoull error triggerable
  115557. + * by strings matching the pattern */
  115558. + assert(errno == 0);
  115559. return DT_LITERAL;
  115560. }
  115561. YY_BREAK
  115562. -case 11:
  115563. -/* rule 11 can match eol */
  115564. +case 12:
  115565. +/* rule 12 can match eol */
  115566. YY_RULE_SETUP
  115567. -#line 154 "dtc-lexer.l"
  115568. +#line 173 "dtc-lexer.l"
  115569. {
  115570. - yytext[yyleng-1] = '\0';
  115571. - yylval.literal = xstrdup(yytext+1);
  115572. - DPRINT("Character literal: %s\n", yylval.literal);
  115573. + struct data d;
  115574. + DPRINT("Character literal: %s\n", yytext);
  115575. +
  115576. + d = data_copy_escape_string(yytext+1, yyleng-2);
  115577. + if (d.len == 1) {
  115578. + lexical_error("Empty character literal");
  115579. + yylval.integer = 0;
  115580. + return DT_CHAR_LITERAL;
  115581. + }
  115582. +
  115583. + yylval.integer = (unsigned char)d.val[0];
  115584. +
  115585. + if (d.len > 2)
  115586. + lexical_error("Character literal has %d"
  115587. + " characters instead of 1",
  115588. + d.len - 1);
  115589. +
  115590. return DT_CHAR_LITERAL;
  115591. }
  115592. YY_BREAK
  115593. -case 12:
  115594. +case 13:
  115595. YY_RULE_SETUP
  115596. -#line 161 "dtc-lexer.l"
  115597. +#line 194 "dtc-lexer.l"
  115598. { /* label reference */
  115599. DPRINT("Ref: %s\n", yytext+1);
  115600. yylval.labelref = xstrdup(yytext+1);
  115601. return DT_REF;
  115602. }
  115603. YY_BREAK
  115604. -case 13:
  115605. +case 14:
  115606. YY_RULE_SETUP
  115607. -#line 167 "dtc-lexer.l"
  115608. +#line 200 "dtc-lexer.l"
  115609. { /* new-style path reference */
  115610. yytext[yyleng-1] = '\0';
  115611. DPRINT("Ref: %s\n", yytext+2);
  115612. @@ -1089,27 +1126,27 @@
  115613. return DT_REF;
  115614. }
  115615. YY_BREAK
  115616. -case 14:
  115617. +case 15:
  115618. YY_RULE_SETUP
  115619. -#line 174 "dtc-lexer.l"
  115620. +#line 207 "dtc-lexer.l"
  115621. {
  115622. yylval.byte = strtol(yytext, NULL, 16);
  115623. DPRINT("Byte: %02x\n", (int)yylval.byte);
  115624. return DT_BYTE;
  115625. }
  115626. YY_BREAK
  115627. -case 15:
  115628. +case 16:
  115629. YY_RULE_SETUP
  115630. -#line 180 "dtc-lexer.l"
  115631. +#line 213 "dtc-lexer.l"
  115632. {
  115633. DPRINT("/BYTESTRING\n");
  115634. BEGIN_DEFAULT();
  115635. return ']';
  115636. }
  115637. YY_BREAK
  115638. -case 16:
  115639. +case 17:
  115640. YY_RULE_SETUP
  115641. -#line 186 "dtc-lexer.l"
  115642. +#line 219 "dtc-lexer.l"
  115643. {
  115644. DPRINT("PropNodeName: %s\n", yytext);
  115645. yylval.propnodename = xstrdup((yytext[0] == '\\') ?
  115646. @@ -1118,75 +1155,75 @@
  115647. return DT_PROPNODENAME;
  115648. }
  115649. YY_BREAK
  115650. -case 17:
  115651. +case 18:
  115652. YY_RULE_SETUP
  115653. -#line 194 "dtc-lexer.l"
  115654. +#line 227 "dtc-lexer.l"
  115655. {
  115656. DPRINT("Binary Include\n");
  115657. return DT_INCBIN;
  115658. }
  115659. YY_BREAK
  115660. -case 18:
  115661. -/* rule 18 can match eol */
  115662. -YY_RULE_SETUP
  115663. -#line 199 "dtc-lexer.l"
  115664. -/* eat whitespace */
  115665. - YY_BREAK
  115666. case 19:
  115667. /* rule 19 can match eol */
  115668. YY_RULE_SETUP
  115669. -#line 200 "dtc-lexer.l"
  115670. -/* eat C-style comments */
  115671. +#line 232 "dtc-lexer.l"
  115672. +/* eat whitespace */
  115673. YY_BREAK
  115674. case 20:
  115675. /* rule 20 can match eol */
  115676. YY_RULE_SETUP
  115677. -#line 201 "dtc-lexer.l"
  115678. -/* eat C++-style comments */
  115679. +#line 233 "dtc-lexer.l"
  115680. +/* eat C-style comments */
  115681. YY_BREAK
  115682. case 21:
  115683. +/* rule 21 can match eol */
  115684. YY_RULE_SETUP
  115685. -#line 203 "dtc-lexer.l"
  115686. -{ return DT_LSHIFT; };
  115687. +#line 234 "dtc-lexer.l"
  115688. +/* eat C++-style comments */
  115689. YY_BREAK
  115690. case 22:
  115691. YY_RULE_SETUP
  115692. -#line 204 "dtc-lexer.l"
  115693. -{ return DT_RSHIFT; };
  115694. +#line 236 "dtc-lexer.l"
  115695. +{ return DT_LSHIFT; };
  115696. YY_BREAK
  115697. case 23:
  115698. YY_RULE_SETUP
  115699. -#line 205 "dtc-lexer.l"
  115700. -{ return DT_LE; };
  115701. +#line 237 "dtc-lexer.l"
  115702. +{ return DT_RSHIFT; };
  115703. YY_BREAK
  115704. case 24:
  115705. YY_RULE_SETUP
  115706. -#line 206 "dtc-lexer.l"
  115707. -{ return DT_GE; };
  115708. +#line 238 "dtc-lexer.l"
  115709. +{ return DT_LE; };
  115710. YY_BREAK
  115711. case 25:
  115712. YY_RULE_SETUP
  115713. -#line 207 "dtc-lexer.l"
  115714. -{ return DT_EQ; };
  115715. +#line 239 "dtc-lexer.l"
  115716. +{ return DT_GE; };
  115717. YY_BREAK
  115718. case 26:
  115719. YY_RULE_SETUP
  115720. -#line 208 "dtc-lexer.l"
  115721. -{ return DT_NE; };
  115722. +#line 240 "dtc-lexer.l"
  115723. +{ return DT_EQ; };
  115724. YY_BREAK
  115725. case 27:
  115726. YY_RULE_SETUP
  115727. -#line 209 "dtc-lexer.l"
  115728. -{ return DT_AND; };
  115729. +#line 241 "dtc-lexer.l"
  115730. +{ return DT_NE; };
  115731. YY_BREAK
  115732. case 28:
  115733. YY_RULE_SETUP
  115734. -#line 210 "dtc-lexer.l"
  115735. -{ return DT_OR; };
  115736. +#line 242 "dtc-lexer.l"
  115737. +{ return DT_AND; };
  115738. YY_BREAK
  115739. case 29:
  115740. YY_RULE_SETUP
  115741. -#line 212 "dtc-lexer.l"
  115742. +#line 243 "dtc-lexer.l"
  115743. +{ return DT_OR; };
  115744. + YY_BREAK
  115745. +case 30:
  115746. +YY_RULE_SETUP
  115747. +#line 245 "dtc-lexer.l"
  115748. {
  115749. DPRINT("Char: %c (\\x%02x)\n", yytext[0],
  115750. (unsigned)yytext[0]);
  115751. @@ -1202,12 +1239,12 @@
  115752. return yytext[0];
  115753. }
  115754. YY_BREAK
  115755. -case 30:
  115756. +case 31:
  115757. YY_RULE_SETUP
  115758. -#line 227 "dtc-lexer.l"
  115759. +#line 260 "dtc-lexer.l"
  115760. ECHO;
  115761. YY_BREAK
  115762. -#line 1211 "dtc-lexer.lex.c"
  115763. +#line 1248 "dtc-lexer.lex.c"
  115764. case YY_END_OF_BUFFER:
  115765. {
  115766. @@ -1499,7 +1536,7 @@
  115767. while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  115768. {
  115769. yy_current_state = (int) yy_def[yy_current_state];
  115770. - if ( yy_current_state >= 161 )
  115771. + if ( yy_current_state >= 166 )
  115772. yy_c = yy_meta[(unsigned int) yy_c];
  115773. }
  115774. yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
  115775. @@ -1527,11 +1564,11 @@
  115776. while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  115777. {
  115778. yy_current_state = (int) yy_def[yy_current_state];
  115779. - if ( yy_current_state >= 161 )
  115780. + if ( yy_current_state >= 166 )
  115781. yy_c = yy_meta[(unsigned int) yy_c];
  115782. }
  115783. yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
  115784. - yy_is_jam = (yy_current_state == 160);
  115785. + yy_is_jam = (yy_current_state == 165);
  115786. return yy_is_jam ? 0 : yy_current_state;
  115787. }
  115788. @@ -2166,7 +2203,7 @@
  115789. #define YYTABLES_NAME "yytables"
  115790. -#line 227 "dtc-lexer.l"
  115791. +#line 260 "dtc-lexer.l"
  115792. @@ -2182,14 +2219,25 @@
  115793. }
  115794. -static int pop_input_file(void)
  115795. +static bool pop_input_file(void)
  115796. {
  115797. if (srcfile_pop() == 0)
  115798. - return 0;
  115799. + return false;
  115800. yypop_buffer_state();
  115801. yyin = current_srcfile->f;
  115802. - return 1;
  115803. + return true;
  115804. +}
  115805. +
  115806. +static void lexical_error(const char *fmt, ...)
  115807. +{
  115808. + va_list ap;
  115809. +
  115810. + va_start(ap, fmt);
  115811. + srcpos_verror(&yylloc, "Lexical error", fmt, ap);
  115812. + va_end(ap);
  115813. +
  115814. + treesource_error = true;
  115815. }
  115816. diff -Nur linux-3.18.6/scripts/dtc/dtc-parser.tab.c_shipped linux-rpi/scripts/dtc/dtc-parser.tab.c_shipped
  115817. --- linux-3.18.6/scripts/dtc/dtc-parser.tab.c_shipped 2015-02-06 15:53:48.000000000 +0100
  115818. +++ linux-rpi/scripts/dtc/dtc-parser.tab.c_shipped 2015-02-09 04:40:47.000000000 +0100
  115819. @@ -1,19 +1,19 @@
  115820. -/* A Bison parser, made by GNU Bison 2.7.12-4996. */
  115821. +/* A Bison parser, made by GNU Bison 3.0.2. */
  115822. /* Bison implementation for Yacc-like parsers in C
  115823. -
  115824. - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
  115825. -
  115826. +
  115827. + Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
  115828. +
  115829. This program is free software: you can redistribute it and/or modify
  115830. it under the terms of the GNU General Public License as published by
  115831. the Free Software Foundation, either version 3 of the License, or
  115832. (at your option) any later version.
  115833. -
  115834. +
  115835. This program is distributed in the hope that it will be useful,
  115836. but WITHOUT ANY WARRANTY; without even the implied warranty of
  115837. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  115838. GNU General Public License for more details.
  115839. -
  115840. +
  115841. You should have received a copy of the GNU General Public License
  115842. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  115843. @@ -26,7 +26,7 @@
  115844. special exception, which will cause the skeleton and the resulting
  115845. Bison output files to be licensed under the GNU General Public
  115846. License without this special exception.
  115847. -
  115848. +
  115849. This special exception was added by the Free Software Foundation in
  115850. version 2.2 of Bison. */
  115851. @@ -44,7 +44,7 @@
  115852. #define YYBISON 1
  115853. /* Bison version. */
  115854. -#define YYBISON_VERSION "2.7.12-4996"
  115855. +#define YYBISON_VERSION "3.0.2"
  115856. /* Skeleton name. */
  115857. #define YYSKELETON_NAME "yacc.c"
  115858. @@ -62,34 +62,32 @@
  115859. /* Copy the first part of user declarations. */
  115860. -/* Line 371 of yacc.c */
  115861. -#line 21 "dtc-parser.y"
  115862. +#line 20 "dtc-parser.y" /* yacc.c:339 */
  115863. #include <stdio.h>
  115864. +#include <inttypes.h>
  115865. #include "dtc.h"
  115866. #include "srcpos.h"
  115867. -YYLTYPE yylloc;
  115868. -
  115869. extern int yylex(void);
  115870. -extern void print_error(char const *fmt, ...);
  115871. extern void yyerror(char const *s);
  115872. +#define ERROR(loc, ...) \
  115873. + do { \
  115874. + srcpos_error((loc), "Error", __VA_ARGS__); \
  115875. + treesource_error = true; \
  115876. + } while (0)
  115877. extern struct boot_info *the_boot_info;
  115878. -extern int treesource_error;
  115879. -
  115880. -static unsigned long long eval_literal(const char *s, int base, int bits);
  115881. -static unsigned char eval_char_literal(const char *s);
  115882. +extern bool treesource_error;
  115883. -/* Line 371 of yacc.c */
  115884. -#line 87 "dtc-parser.tab.c"
  115885. +#line 85 "dtc-parser.tab.c" /* yacc.c:339 */
  115886. -# ifndef YY_NULL
  115887. +# ifndef YY_NULLPTR
  115888. # if defined __cplusplus && 201103L <= __cplusplus
  115889. -# define YY_NULL nullptr
  115890. +# define YY_NULLPTR nullptr
  115891. # else
  115892. -# define YY_NULL 0
  115893. +# define YY_NULLPTR 0
  115894. # endif
  115895. # endif
  115896. @@ -105,7 +103,7 @@
  115897. by #include "dtc-parser.tab.h". */
  115898. #ifndef YY_YY_DTC_PARSER_TAB_H_INCLUDED
  115899. # define YY_YY_DTC_PARSER_TAB_H_INCLUDED
  115900. -/* Enabling traces. */
  115901. +/* Debug traces. */
  115902. #ifndef YYDEBUG
  115903. # define YYDEBUG 0
  115904. #endif
  115905. @@ -113,48 +111,45 @@
  115906. extern int yydebug;
  115907. #endif
  115908. -/* Tokens. */
  115909. +/* Token type. */
  115910. #ifndef YYTOKENTYPE
  115911. # define YYTOKENTYPE
  115912. - /* Put the tokens into the symbol table, so that GDB and other debuggers
  115913. - know about them. */
  115914. - enum yytokentype {
  115915. - DT_V1 = 258,
  115916. - DT_MEMRESERVE = 259,
  115917. - DT_LSHIFT = 260,
  115918. - DT_RSHIFT = 261,
  115919. - DT_LE = 262,
  115920. - DT_GE = 263,
  115921. - DT_EQ = 264,
  115922. - DT_NE = 265,
  115923. - DT_AND = 266,
  115924. - DT_OR = 267,
  115925. - DT_BITS = 268,
  115926. - DT_DEL_PROP = 269,
  115927. - DT_DEL_NODE = 270,
  115928. - DT_PROPNODENAME = 271,
  115929. - DT_LITERAL = 272,
  115930. - DT_CHAR_LITERAL = 273,
  115931. - DT_BASE = 274,
  115932. - DT_BYTE = 275,
  115933. - DT_STRING = 276,
  115934. - DT_LABEL = 277,
  115935. - DT_REF = 278,
  115936. - DT_INCBIN = 279
  115937. - };
  115938. + enum yytokentype
  115939. + {
  115940. + DT_V1 = 258,
  115941. + DT_PLUGIN = 259,
  115942. + DT_MEMRESERVE = 260,
  115943. + DT_LSHIFT = 261,
  115944. + DT_RSHIFT = 262,
  115945. + DT_LE = 263,
  115946. + DT_GE = 264,
  115947. + DT_EQ = 265,
  115948. + DT_NE = 266,
  115949. + DT_AND = 267,
  115950. + DT_OR = 268,
  115951. + DT_BITS = 269,
  115952. + DT_DEL_PROP = 270,
  115953. + DT_DEL_NODE = 271,
  115954. + DT_PROPNODENAME = 272,
  115955. + DT_LITERAL = 273,
  115956. + DT_CHAR_LITERAL = 274,
  115957. + DT_BYTE = 275,
  115958. + DT_STRING = 276,
  115959. + DT_LABEL = 277,
  115960. + DT_REF = 278,
  115961. + DT_INCBIN = 279
  115962. + };
  115963. #endif
  115964. -
  115965. +/* Value type. */
  115966. #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
  115967. -typedef union YYSTYPE
  115968. +typedef union YYSTYPE YYSTYPE;
  115969. +union YYSTYPE
  115970. {
  115971. -/* Line 387 of yacc.c */
  115972. -#line 40 "dtc-parser.y"
  115973. +#line 39 "dtc-parser.y" /* yacc.c:355 */
  115974. char *propnodename;
  115975. - char *literal;
  115976. char *labelref;
  115977. - unsigned int cbase;
  115978. uint8_t byte;
  115979. struct data data;
  115980. @@ -169,38 +164,38 @@
  115981. struct node *nodelist;
  115982. struct reserve_info *re;
  115983. uint64_t integer;
  115984. + int is_plugin;
  115985. -
  115986. -/* Line 387 of yacc.c */
  115987. -#line 176 "dtc-parser.tab.c"
  115988. -} YYSTYPE;
  115989. +#line 170 "dtc-parser.tab.c" /* yacc.c:355 */
  115990. +};
  115991. # define YYSTYPE_IS_TRIVIAL 1
  115992. -# define yystype YYSTYPE /* obsolescent; will be withdrawn */
  115993. # define YYSTYPE_IS_DECLARED 1
  115994. #endif
  115995. -extern YYSTYPE yylval;
  115996. -
  115997. -#ifdef YYPARSE_PARAM
  115998. -#if defined __STDC__ || defined __cplusplus
  115999. -int yyparse (void *YYPARSE_PARAM);
  116000. -#else
  116001. -int yyparse ();
  116002. +/* Location type. */
  116003. +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
  116004. +typedef struct YYLTYPE YYLTYPE;
  116005. +struct YYLTYPE
  116006. +{
  116007. + int first_line;
  116008. + int first_column;
  116009. + int last_line;
  116010. + int last_column;
  116011. +};
  116012. +# define YYLTYPE_IS_DECLARED 1
  116013. +# define YYLTYPE_IS_TRIVIAL 1
  116014. #endif
  116015. -#else /* ! YYPARSE_PARAM */
  116016. -#if defined __STDC__ || defined __cplusplus
  116017. +
  116018. +
  116019. +extern YYSTYPE yylval;
  116020. +extern YYLTYPE yylloc;
  116021. int yyparse (void);
  116022. -#else
  116023. -int yyparse ();
  116024. -#endif
  116025. -#endif /* ! YYPARSE_PARAM */
  116026. #endif /* !YY_YY_DTC_PARSER_TAB_H_INCLUDED */
  116027. /* Copy the second part of user declarations. */
  116028. -/* Line 390 of yacc.c */
  116029. -#line 204 "dtc-parser.tab.c"
  116030. +#line 199 "dtc-parser.tab.c" /* yacc.c:358 */
  116031. #ifdef short
  116032. # undef short
  116033. @@ -214,11 +209,8 @@
  116034. #ifdef YYTYPE_INT8
  116035. typedef YYTYPE_INT8 yytype_int8;
  116036. -#elif (defined __STDC__ || defined __C99__FUNC__ \
  116037. - || defined __cplusplus || defined _MSC_VER)
  116038. -typedef signed char yytype_int8;
  116039. #else
  116040. -typedef short int yytype_int8;
  116041. +typedef signed char yytype_int8;
  116042. #endif
  116043. #ifdef YYTYPE_UINT16
  116044. @@ -238,8 +230,7 @@
  116045. # define YYSIZE_T __SIZE_TYPE__
  116046. # elif defined size_t
  116047. # define YYSIZE_T size_t
  116048. -# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
  116049. - || defined __cplusplus || defined _MSC_VER)
  116050. +# elif ! defined YYSIZE_T
  116051. # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
  116052. # define YYSIZE_T size_t
  116053. # else
  116054. @@ -261,11 +252,30 @@
  116055. # endif
  116056. #endif
  116057. -#ifndef __attribute__
  116058. -/* This feature is available in gcc versions 2.5 and later. */
  116059. -# if (! defined __GNUC__ || __GNUC__ < 2 \
  116060. - || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
  116061. -# define __attribute__(Spec) /* empty */
  116062. +#ifndef YY_ATTRIBUTE
  116063. +# if (defined __GNUC__ \
  116064. + && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
  116065. + || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
  116066. +# define YY_ATTRIBUTE(Spec) __attribute__(Spec)
  116067. +# else
  116068. +# define YY_ATTRIBUTE(Spec) /* empty */
  116069. +# endif
  116070. +#endif
  116071. +
  116072. +#ifndef YY_ATTRIBUTE_PURE
  116073. +# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
  116074. +#endif
  116075. +
  116076. +#ifndef YY_ATTRIBUTE_UNUSED
  116077. +# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
  116078. +#endif
  116079. +
  116080. +#if !defined _Noreturn \
  116081. + && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
  116082. +# if defined _MSC_VER && 1200 <= _MSC_VER
  116083. +# define _Noreturn __declspec (noreturn)
  116084. +# else
  116085. +# define _Noreturn YY_ATTRIBUTE ((__noreturn__))
  116086. # endif
  116087. #endif
  116088. @@ -276,24 +286,25 @@
  116089. # define YYUSE(E) /* empty */
  116090. #endif
  116091. -
  116092. -/* Identity function, used to suppress warnings about constant conditions. */
  116093. -#ifndef lint
  116094. -# define YYID(N) (N)
  116095. -#else
  116096. -#if (defined __STDC__ || defined __C99__FUNC__ \
  116097. - || defined __cplusplus || defined _MSC_VER)
  116098. -static int
  116099. -YYID (int yyi)
  116100. +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
  116101. +/* Suppress an incorrect diagnostic about yylval being uninitialized. */
  116102. +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
  116103. + _Pragma ("GCC diagnostic push") \
  116104. + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
  116105. + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
  116106. +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
  116107. + _Pragma ("GCC diagnostic pop")
  116108. #else
  116109. -static int
  116110. -YYID (yyi)
  116111. - int yyi;
  116112. +# define YY_INITIAL_VALUE(Value) Value
  116113. #endif
  116114. -{
  116115. - return yyi;
  116116. -}
  116117. +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  116118. +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  116119. +# define YY_IGNORE_MAYBE_UNINITIALIZED_END
  116120. #endif
  116121. +#ifndef YY_INITIAL_VALUE
  116122. +# define YY_INITIAL_VALUE(Value) /* Nothing. */
  116123. +#endif
  116124. +
  116125. #if ! defined yyoverflow || YYERROR_VERBOSE
  116126. @@ -312,8 +323,7 @@
  116127. # define alloca _alloca
  116128. # else
  116129. # define YYSTACK_ALLOC alloca
  116130. -# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
  116131. - || defined __cplusplus || defined _MSC_VER)
  116132. +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
  116133. # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  116134. /* Use EXIT_SUCCESS as a witness for stdlib.h. */
  116135. # ifndef EXIT_SUCCESS
  116136. @@ -325,8 +335,8 @@
  116137. # endif
  116138. # ifdef YYSTACK_ALLOC
  116139. - /* Pacify GCC's `empty if-body' warning. */
  116140. -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
  116141. + /* Pacify GCC's 'empty if-body' warning. */
  116142. +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
  116143. # ifndef YYSTACK_ALLOC_MAXIMUM
  116144. /* The OS might guarantee only one guard page at the bottom of the stack,
  116145. and a page size can be as small as 4096 bytes. So we cannot safely
  116146. @@ -342,7 +352,7 @@
  116147. # endif
  116148. # if (defined __cplusplus && ! defined EXIT_SUCCESS \
  116149. && ! ((defined YYMALLOC || defined malloc) \
  116150. - && (defined YYFREE || defined free)))
  116151. + && (defined YYFREE || defined free)))
  116152. # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  116153. # ifndef EXIT_SUCCESS
  116154. # define EXIT_SUCCESS 0
  116155. @@ -350,15 +360,13 @@
  116156. # endif
  116157. # ifndef YYMALLOC
  116158. # define YYMALLOC malloc
  116159. -# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
  116160. - || defined __cplusplus || defined _MSC_VER)
  116161. +# if ! defined malloc && ! defined EXIT_SUCCESS
  116162. void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
  116163. # endif
  116164. # endif
  116165. # ifndef YYFREE
  116166. # define YYFREE free
  116167. -# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
  116168. - || defined __cplusplus || defined _MSC_VER)
  116169. +# if ! defined free && ! defined EXIT_SUCCESS
  116170. void free (void *); /* INFRINGES ON USER NAME SPACE */
  116171. # endif
  116172. # endif
  116173. @@ -368,13 +376,15 @@
  116174. #if (! defined yyoverflow \
  116175. && (! defined __cplusplus \
  116176. - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
  116177. + || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
  116178. + && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
  116179. /* A type that is properly aligned for any stack member. */
  116180. union yyalloc
  116181. {
  116182. yytype_int16 yyss_alloc;
  116183. YYSTYPE yyvs_alloc;
  116184. + YYLTYPE yyls_alloc;
  116185. };
  116186. /* The size of the maximum gap between one aligned stack and the next. */
  116187. @@ -383,8 +393,8 @@
  116188. /* The size of an array large to enough to hold all stacks, each with
  116189. N elements. */
  116190. # define YYSTACK_BYTES(N) \
  116191. - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
  116192. - + YYSTACK_GAP_MAXIMUM)
  116193. + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
  116194. + + 2 * YYSTACK_GAP_MAXIMUM)
  116195. # define YYCOPY_NEEDED 1
  116196. @@ -393,16 +403,16 @@
  116197. elements in the stack, and YYPTR gives the new location of the
  116198. stack. Advance YYPTR to a properly aligned location for the next
  116199. stack. */
  116200. -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
  116201. - do \
  116202. - { \
  116203. - YYSIZE_T yynewbytes; \
  116204. - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
  116205. - Stack = &yyptr->Stack_alloc; \
  116206. - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
  116207. - yyptr += yynewbytes / sizeof (*yyptr); \
  116208. - } \
  116209. - while (YYID (0))
  116210. +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
  116211. + do \
  116212. + { \
  116213. + YYSIZE_T yynewbytes; \
  116214. + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
  116215. + Stack = &yyptr->Stack_alloc; \
  116216. + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
  116217. + yyptr += yynewbytes / sizeof (*yyptr); \
  116218. + } \
  116219. + while (0)
  116220. #endif
  116221. @@ -421,7 +431,7 @@
  116222. for (yyi = 0; yyi < (Count); yyi++) \
  116223. (Dst)[yyi] = (Src)[yyi]; \
  116224. } \
  116225. - while (YYID (0))
  116226. + while (0)
  116227. # endif
  116228. # endif
  116229. #endif /* !YYCOPY_NEEDED */
  116230. @@ -429,25 +439,27 @@
  116231. /* YYFINAL -- State number of the termination state. */
  116232. #define YYFINAL 4
  116233. /* YYLAST -- Last index in YYTABLE. */
  116234. -#define YYLAST 133
  116235. +#define YYLAST 135
  116236. /* YYNTOKENS -- Number of terminals. */
  116237. #define YYNTOKENS 48
  116238. /* YYNNTS -- Number of nonterminals. */
  116239. -#define YYNNTS 28
  116240. +#define YYNNTS 29
  116241. /* YYNRULES -- Number of rules. */
  116242. -#define YYNRULES 79
  116243. -/* YYNRULES -- Number of states. */
  116244. -#define YYNSTATES 141
  116245. +#define YYNRULES 81
  116246. +/* YYNSTATES -- Number of states. */
  116247. +#define YYNSTATES 144
  116248. -/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
  116249. +/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
  116250. + by yylex, with out-of-bounds checking. */
  116251. #define YYUNDEFTOK 2
  116252. #define YYMAXUTOK 279
  116253. -#define YYTRANSLATE(YYX) \
  116254. +#define YYTRANSLATE(YYX) \
  116255. ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
  116256. -/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
  116257. +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
  116258. + as returned by yylex, without out-of-bounds checking. */
  116259. static const yytype_uint8 yytranslate[] =
  116260. {
  116261. 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  116262. @@ -481,63 +493,18 @@
  116263. };
  116264. #if YYDEBUG
  116265. -/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
  116266. - YYRHS. */
  116267. -static const yytype_uint16 yyprhs[] =
  116268. -{
  116269. - 0, 0, 3, 8, 9, 12, 17, 20, 23, 27,
  116270. - 31, 36, 42, 43, 46, 51, 54, 58, 61, 64,
  116271. - 68, 73, 76, 86, 92, 95, 96, 99, 102, 106,
  116272. - 108, 111, 114, 117, 119, 121, 125, 127, 129, 135,
  116273. - 137, 141, 143, 147, 149, 153, 155, 159, 161, 165,
  116274. - 167, 171, 175, 177, 181, 185, 189, 193, 197, 201,
  116275. - 203, 207, 211, 213, 217, 221, 225, 227, 229, 232,
  116276. - 235, 238, 239, 242, 245, 246, 249, 252, 255, 259
  116277. -};
  116278. -
  116279. -/* YYRHS -- A `-1'-separated list of the rules' RHS. */
  116280. -static const yytype_int8 yyrhs[] =
  116281. -{
  116282. - 49, 0, -1, 3, 25, 50, 52, -1, -1, 51,
  116283. - 50, -1, 4, 59, 59, 25, -1, 22, 51, -1,
  116284. - 26, 53, -1, 52, 26, 53, -1, 52, 23, 53,
  116285. - -1, 52, 15, 23, 25, -1, 27, 54, 74, 28,
  116286. - 25, -1, -1, 54, 55, -1, 16, 29, 56, 25,
  116287. - -1, 16, 25, -1, 14, 16, 25, -1, 22, 55,
  116288. - -1, 57, 21, -1, 57, 58, 30, -1, 57, 31,
  116289. - 73, 32, -1, 57, 23, -1, 57, 24, 33, 21,
  116290. - 34, 59, 34, 59, 35, -1, 57, 24, 33, 21,
  116291. - 35, -1, 56, 22, -1, -1, 56, 34, -1, 57,
  116292. - 22, -1, 13, 17, 36, -1, 36, -1, 58, 59,
  116293. - -1, 58, 23, -1, 58, 22, -1, 17, -1, 18,
  116294. - -1, 33, 60, 35, -1, 61, -1, 62, -1, 62,
  116295. - 37, 60, 38, 61, -1, 63, -1, 62, 12, 63,
  116296. - -1, 64, -1, 63, 11, 64, -1, 65, -1, 64,
  116297. - 39, 65, -1, 66, -1, 65, 40, 66, -1, 67,
  116298. - -1, 66, 41, 67, -1, 68, -1, 67, 9, 68,
  116299. - -1, 67, 10, 68, -1, 69, -1, 68, 36, 69,
  116300. - -1, 68, 30, 69, -1, 68, 7, 69, -1, 68,
  116301. - 8, 69, -1, 69, 5, 70, -1, 69, 6, 70,
  116302. - -1, 70, -1, 70, 42, 71, -1, 70, 43, 71,
  116303. - -1, 71, -1, 71, 44, 72, -1, 71, 26, 72,
  116304. - -1, 71, 45, 72, -1, 72, -1, 59, -1, 43,
  116305. - 72, -1, 46, 72, -1, 47, 72, -1, -1, 73,
  116306. - 20, -1, 73, 22, -1, -1, 75, 74, -1, 75,
  116307. - 55, -1, 16, 53, -1, 15, 16, 25, -1, 22,
  116308. - 75, -1
  116309. -};
  116310. -
  116311. -/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
  116312. + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
  116313. static const yytype_uint16 yyrline[] =
  116314. {
  116315. - 0, 109, 109, 118, 121, 128, 132, 140, 144, 148,
  116316. - 158, 172, 180, 183, 190, 194, 198, 202, 210, 214,
  116317. - 218, 222, 226, 243, 253, 261, 264, 268, 275, 290,
  116318. - 295, 315, 329, 336, 340, 344, 351, 355, 356, 360,
  116319. - 361, 365, 366, 370, 371, 375, 376, 380, 381, 385,
  116320. - 386, 387, 391, 392, 393, 394, 395, 399, 400, 401,
  116321. - 405, 406, 407, 411, 412, 413, 414, 418, 419, 420,
  116322. - 421, 426, 429, 433, 441, 444, 448, 456, 460, 464
  116323. + 0, 108, 108, 119, 122, 130, 133, 140, 144, 152,
  116324. + 156, 160, 170, 185, 193, 196, 203, 207, 211, 215,
  116325. + 223, 227, 231, 235, 239, 255, 265, 273, 276, 280,
  116326. + 287, 303, 308, 327, 341, 348, 349, 350, 357, 361,
  116327. + 362, 366, 367, 371, 372, 376, 377, 381, 382, 386,
  116328. + 387, 391, 392, 393, 397, 398, 399, 400, 401, 405,
  116329. + 406, 407, 411, 412, 413, 417, 418, 419, 420, 424,
  116330. + 425, 426, 427, 432, 435, 439, 447, 450, 454, 462,
  116331. + 466, 470
  116332. };
  116333. #endif
  116334. @@ -546,25 +513,25 @@
  116335. First, the terminals, then, starting at YYNTOKENS, nonterminals. */
  116336. static const char *const yytname[] =
  116337. {
  116338. - "$end", "error", "$undefined", "DT_V1", "DT_MEMRESERVE", "DT_LSHIFT",
  116339. - "DT_RSHIFT", "DT_LE", "DT_GE", "DT_EQ", "DT_NE", "DT_AND", "DT_OR",
  116340. - "DT_BITS", "DT_DEL_PROP", "DT_DEL_NODE", "DT_PROPNODENAME", "DT_LITERAL",
  116341. - "DT_CHAR_LITERAL", "DT_BASE", "DT_BYTE", "DT_STRING", "DT_LABEL",
  116342. + "$end", "error", "$undefined", "DT_V1", "DT_PLUGIN", "DT_MEMRESERVE",
  116343. + "DT_LSHIFT", "DT_RSHIFT", "DT_LE", "DT_GE", "DT_EQ", "DT_NE", "DT_AND",
  116344. + "DT_OR", "DT_BITS", "DT_DEL_PROP", "DT_DEL_NODE", "DT_PROPNODENAME",
  116345. + "DT_LITERAL", "DT_CHAR_LITERAL", "DT_BYTE", "DT_STRING", "DT_LABEL",
  116346. "DT_REF", "DT_INCBIN", "';'", "'/'", "'{'", "'}'", "'='", "'>'", "'['",
  116347. "']'", "'('", "','", "')'", "'<'", "'?'", "':'", "'|'", "'^'", "'&'",
  116348. "'+'", "'-'", "'*'", "'%'", "'~'", "'!'", "$accept", "sourcefile",
  116349. - "memreserves", "memreserve", "devicetree", "nodedef", "proplist",
  116350. - "propdef", "propdata", "propdataprefix", "arrayprefix", "integer_prim",
  116351. - "integer_expr", "integer_trinary", "integer_or", "integer_and",
  116352. - "integer_bitor", "integer_bitxor", "integer_bitand", "integer_eq",
  116353. - "integer_rela", "integer_shift", "integer_add", "integer_mul",
  116354. - "integer_unary", "bytestring", "subnodes", "subnode", YY_NULL
  116355. + "plugindecl", "memreserves", "memreserve", "devicetree", "nodedef",
  116356. + "proplist", "propdef", "propdata", "propdataprefix", "arrayprefix",
  116357. + "integer_prim", "integer_expr", "integer_trinary", "integer_or",
  116358. + "integer_and", "integer_bitor", "integer_bitxor", "integer_bitand",
  116359. + "integer_eq", "integer_rela", "integer_shift", "integer_add",
  116360. + "integer_mul", "integer_unary", "bytestring", "subnodes", "subnode", YY_NULLPTR
  116361. };
  116362. #endif
  116363. # ifdef YYPRINT
  116364. -/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
  116365. - token YYLEX-NUM. */
  116366. +/* YYTOKNUM[NUM] -- (External) token number corresponding to the
  116367. + (internal) symbol number NUM (which must be that of a token). */
  116368. static const yytype_uint16 yytoknum[] =
  116369. {
  116370. 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
  116371. @@ -575,183 +542,173 @@
  116372. };
  116373. # endif
  116374. -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
  116375. -static const yytype_uint8 yyr1[] =
  116376. -{
  116377. - 0, 48, 49, 50, 50, 51, 51, 52, 52, 52,
  116378. - 52, 53, 54, 54, 55, 55, 55, 55, 56, 56,
  116379. - 56, 56, 56, 56, 56, 57, 57, 57, 58, 58,
  116380. - 58, 58, 58, 59, 59, 59, 60, 61, 61, 62,
  116381. - 62, 63, 63, 64, 64, 65, 65, 66, 66, 67,
  116382. - 67, 67, 68, 68, 68, 68, 68, 69, 69, 69,
  116383. - 70, 70, 70, 71, 71, 71, 71, 72, 72, 72,
  116384. - 72, 73, 73, 73, 74, 74, 74, 75, 75, 75
  116385. -};
  116386. +#define YYPACT_NINF -41
  116387. -/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
  116388. -static const yytype_uint8 yyr2[] =
  116389. +#define yypact_value_is_default(Yystate) \
  116390. + (!!((Yystate) == (-41)))
  116391. +
  116392. +#define YYTABLE_NINF -1
  116393. +
  116394. +#define yytable_value_is_error(Yytable_value) \
  116395. + 0
  116396. +
  116397. + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
  116398. + STATE-NUM. */
  116399. +static const yytype_int8 yypact[] =
  116400. {
  116401. - 0, 2, 4, 0, 2, 4, 2, 2, 3, 3,
  116402. - 4, 5, 0, 2, 4, 2, 3, 2, 2, 3,
  116403. - 4, 2, 9, 5, 2, 0, 2, 2, 3, 1,
  116404. - 2, 2, 2, 1, 1, 3, 1, 1, 5, 1,
  116405. - 3, 1, 3, 1, 3, 1, 3, 1, 3, 1,
  116406. - 3, 3, 1, 3, 3, 3, 3, 3, 3, 1,
  116407. - 3, 3, 1, 3, 3, 3, 1, 1, 2, 2,
  116408. - 2, 0, 2, 2, 0, 2, 2, 2, 3, 2
  116409. + 37, 10, 24, 78, -41, 20, 9, -41, 8, 9,
  116410. + 59, 9, -41, -41, -10, 8, -41, 60, 39, -41,
  116411. + -10, -10, -10, -41, 51, -41, -7, 76, 50, 52,
  116412. + 53, 49, 2, 65, 32, -1, -41, 66, -41, -41,
  116413. + 67, 60, 60, -41, -41, -41, -41, -10, -10, -10,
  116414. + -10, -10, -10, -10, -10, -10, -10, -10, -10, -10,
  116415. + -10, -10, -10, -10, -10, -10, -41, 41, 68, -41,
  116416. + -41, 76, 57, 50, 52, 53, 49, 2, 2, 65,
  116417. + 65, 65, 65, 32, 32, -1, -1, -41, -41, -41,
  116418. + 79, 80, -12, 41, -41, 70, 41, -41, -10, 74,
  116419. + 75, -41, -41, -41, -41, -41, 77, -41, -41, -41,
  116420. + -41, -41, 17, -2, -41, -41, -41, -41, 83, -41,
  116421. + -41, -41, 71, -41, -41, 31, 69, 82, -4, -41,
  116422. + -41, -41, -41, -41, 42, -41, -41, -41, 8, -41,
  116423. + 72, 8, 73, -41
  116424. };
  116425. -/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
  116426. - Performed when YYTABLE doesn't specify something else to do. Zero
  116427. - means the default is an error. */
  116428. + /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
  116429. + Performed when YYTABLE does not specify something else to do. Zero
  116430. + means the default is an error. */
  116431. static const yytype_uint8 yydefact[] =
  116432. {
  116433. - 0, 0, 0, 3, 1, 0, 0, 0, 3, 33,
  116434. - 34, 0, 0, 6, 0, 2, 4, 0, 0, 0,
  116435. - 67, 0, 36, 37, 39, 41, 43, 45, 47, 49,
  116436. - 52, 59, 62, 66, 0, 12, 7, 0, 0, 0,
  116437. - 68, 69, 70, 35, 0, 0, 0, 0, 0, 0,
  116438. + 0, 0, 0, 3, 1, 0, 5, 4, 0, 0,
  116439. + 0, 5, 35, 36, 0, 0, 8, 0, 2, 6,
  116440. + 0, 0, 0, 69, 0, 38, 39, 41, 43, 45,
  116441. + 47, 49, 51, 54, 61, 64, 68, 0, 14, 9,
  116442. + 0, 0, 0, 70, 71, 72, 37, 0, 0, 0,
  116443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116444. - 0, 0, 0, 5, 74, 0, 9, 8, 40, 0,
  116445. - 42, 44, 46, 48, 50, 51, 55, 56, 54, 53,
  116446. - 57, 58, 60, 61, 64, 63, 65, 0, 0, 0,
  116447. - 0, 13, 0, 74, 10, 0, 0, 0, 15, 25,
  116448. - 77, 17, 79, 0, 76, 75, 38, 16, 78, 0,
  116449. - 0, 11, 24, 14, 26, 0, 18, 27, 21, 0,
  116450. - 71, 29, 0, 0, 0, 0, 32, 31, 19, 30,
  116451. - 28, 0, 72, 73, 20, 0, 23, 0, 0, 0,
  116452. - 22
  116453. + 0, 0, 0, 0, 0, 0, 7, 76, 0, 11,
  116454. + 10, 42, 0, 44, 46, 48, 50, 52, 53, 57,
  116455. + 58, 56, 55, 59, 60, 62, 63, 66, 65, 67,
  116456. + 0, 0, 0, 0, 15, 0, 76, 12, 0, 0,
  116457. + 0, 17, 27, 79, 19, 81, 0, 78, 77, 40,
  116458. + 18, 80, 0, 0, 13, 26, 16, 28, 0, 20,
  116459. + 29, 23, 0, 73, 31, 0, 0, 0, 0, 34,
  116460. + 33, 21, 32, 30, 0, 74, 75, 22, 0, 25,
  116461. + 0, 0, 0, 24
  116462. };
  116463. -/* YYDEFGOTO[NTERM-NUM]. */
  116464. -static const yytype_int8 yydefgoto[] =
  116465. + /* YYPGOTO[NTERM-NUM]. */
  116466. +static const yytype_int8 yypgoto[] =
  116467. {
  116468. - -1, 2, 7, 8, 15, 36, 64, 91, 109, 110,
  116469. - 122, 20, 21, 22, 23, 24, 25, 26, 27, 28,
  116470. - 29, 30, 31, 32, 33, 125, 92, 93
  116471. + -41, -41, -41, 96, 100, -41, -40, -41, -23, -41,
  116472. + -41, -41, -8, 62, 13, -41, 81, 63, 64, 84,
  116473. + 61, 25, 11, 21, 22, -17, -41, 19, 23
  116474. };
  116475. -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
  116476. - STATE-NUM. */
  116477. -#define YYPACT_NINF -78
  116478. -static const yytype_int8 yypact[] =
  116479. + /* YYDEFGOTO[NTERM-NUM]. */
  116480. +static const yytype_int16 yydefgoto[] =
  116481. {
  116482. - 22, 11, 51, 10, -78, 23, 10, 2, 10, -78,
  116483. - -78, -9, 23, -78, 30, 38, -78, -9, -9, -9,
  116484. - -78, 35, -78, -6, 52, 29, 48, 49, 33, 3,
  116485. - 71, 36, 0, -78, 64, -78, -78, 68, 30, 30,
  116486. - -78, -78, -78, -78, -9, -9, -9, -9, -9, -9,
  116487. - -9, -9, -9, -9, -9, -9, -9, -9, -9, -9,
  116488. - -9, -9, -9, -78, 44, 67, -78, -78, 52, 55,
  116489. - 29, 48, 49, 33, 3, 3, 71, 71, 71, 71,
  116490. - 36, 36, 0, 0, -78, -78, -78, 78, 79, 42,
  116491. - 44, -78, 69, 44, -78, -9, 73, 74, -78, -78,
  116492. - -78, -78, -78, 75, -78, -78, -78, -78, -78, -7,
  116493. - -1, -78, -78, -78, -78, 84, -78, -78, -78, 63,
  116494. - -78, -78, 32, 66, 82, -3, -78, -78, -78, -78,
  116495. - -78, 46, -78, -78, -78, 23, -78, 70, 23, 72,
  116496. - -78
  116497. + -1, 2, 6, 10, 11, 18, 39, 67, 94, 112,
  116498. + 113, 125, 23, 24, 25, 26, 27, 28, 29, 30,
  116499. + 31, 32, 33, 34, 35, 36, 128, 95, 96
  116500. };
  116501. -/* YYPGOTO[NTERM-NUM]. */
  116502. -static const yytype_int8 yypgoto[] =
  116503. + /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
  116504. + positive, shift that token. If negative, reduce the rule whose
  116505. + number is the opposite. If YYTABLE_NINF, syntax error. */
  116506. +static const yytype_uint8 yytable[] =
  116507. {
  116508. - -78, -78, 97, 100, -78, -37, -78, -77, -78, -78,
  116509. - -78, -5, 65, 13, -78, 76, 77, 62, 80, 83,
  116510. - 34, 20, 26, 28, -14, -78, 18, 24
  116511. + 15, 69, 70, 43, 44, 45, 47, 37, 12, 13,
  116512. + 55, 56, 118, 101, 8, 38, 135, 102, 136, 119,
  116513. + 120, 121, 122, 14, 4, 63, 12, 13, 137, 123,
  116514. + 48, 9, 57, 20, 124, 3, 21, 22, 58, 115,
  116515. + 1, 14, 116, 64, 65, 7, 87, 88, 89, 12,
  116516. + 13, 117, 103, 129, 130, 40, 90, 91, 92, 53,
  116517. + 54, 131, 41, 93, 14, 42, 79, 80, 81, 82,
  116518. + 104, 59, 60, 107, 61, 62, 138, 139, 77, 78,
  116519. + 83, 84, 5, 85, 86, 17, 46, 38, 49, 50,
  116520. + 68, 66, 51, 97, 52, 98, 99, 100, 106, 110,
  116521. + 111, 126, 114, 134, 127, 133, 141, 19, 143, 16,
  116522. + 72, 109, 73, 76, 74, 108, 105, 132, 0, 0,
  116523. + 0, 0, 0, 0, 0, 0, 0, 0, 71, 0,
  116524. + 140, 0, 0, 142, 0, 75
  116525. };
  116526. -/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
  116527. - positive, shift that token. If negative, reduce the rule which
  116528. - number is the opposite. If YYTABLE_NINF, syntax error. */
  116529. -#define YYTABLE_NINF -1
  116530. -static const yytype_uint8 yytable[] =
  116531. +static const yytype_int16 yycheck[] =
  116532. {
  116533. - 12, 66, 67, 40, 41, 42, 44, 34, 9, 10,
  116534. - 52, 53, 115, 101, 5, 112, 104, 132, 113, 133,
  116535. - 116, 117, 118, 119, 11, 1, 60, 114, 14, 134,
  116536. - 120, 45, 6, 54, 17, 121, 3, 18, 19, 55,
  116537. - 9, 10, 50, 51, 61, 62, 84, 85, 86, 9,
  116538. - 10, 4, 100, 37, 126, 127, 11, 35, 87, 88,
  116539. - 89, 38, 128, 46, 39, 11, 90, 98, 47, 35,
  116540. - 43, 99, 76, 77, 78, 79, 56, 57, 58, 59,
  116541. - 135, 136, 80, 81, 74, 75, 82, 83, 48, 63,
  116542. - 49, 65, 94, 95, 96, 97, 124, 103, 107, 108,
  116543. - 111, 123, 130, 131, 138, 16, 13, 140, 106, 71,
  116544. - 69, 105, 0, 0, 102, 0, 0, 129, 0, 0,
  116545. - 68, 0, 0, 70, 0, 0, 0, 0, 72, 0,
  116546. - 137, 0, 73, 139
  116547. + 8, 41, 42, 20, 21, 22, 13, 15, 18, 19,
  116548. + 8, 9, 14, 25, 5, 27, 20, 29, 22, 21,
  116549. + 22, 23, 24, 33, 0, 26, 18, 19, 32, 31,
  116550. + 37, 22, 30, 43, 36, 25, 46, 47, 36, 22,
  116551. + 3, 33, 25, 44, 45, 25, 63, 64, 65, 18,
  116552. + 19, 34, 92, 22, 23, 16, 15, 16, 17, 10,
  116553. + 11, 30, 23, 22, 33, 26, 55, 56, 57, 58,
  116554. + 93, 6, 7, 96, 42, 43, 34, 35, 53, 54,
  116555. + 59, 60, 4, 61, 62, 26, 35, 27, 12, 39,
  116556. + 23, 25, 40, 25, 41, 38, 17, 17, 28, 25,
  116557. + 25, 18, 25, 21, 33, 36, 34, 11, 35, 9,
  116558. + 48, 98, 49, 52, 50, 96, 93, 125, -1, -1,
  116559. + -1, -1, -1, -1, -1, -1, -1, -1, 47, -1,
  116560. + 138, -1, -1, 141, -1, 51
  116561. };
  116562. -#define yypact_value_is_default(Yystate) \
  116563. - (!!((Yystate) == (-78)))
  116564. -
  116565. -#define yytable_value_is_error(Yytable_value) \
  116566. - YYID (0)
  116567. + /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
  116568. + symbol of state STATE-NUM. */
  116569. +static const yytype_uint8 yystos[] =
  116570. +{
  116571. + 0, 3, 49, 25, 0, 4, 50, 25, 5, 22,
  116572. + 51, 52, 18, 19, 33, 60, 52, 26, 53, 51,
  116573. + 43, 46, 47, 60, 61, 62, 63, 64, 65, 66,
  116574. + 67, 68, 69, 70, 71, 72, 73, 60, 27, 54,
  116575. + 16, 23, 26, 73, 73, 73, 35, 13, 37, 12,
  116576. + 39, 40, 41, 10, 11, 8, 9, 30, 36, 6,
  116577. + 7, 42, 43, 26, 44, 45, 25, 55, 23, 54,
  116578. + 54, 64, 61, 65, 66, 67, 68, 69, 69, 70,
  116579. + 70, 70, 70, 71, 71, 72, 72, 73, 73, 73,
  116580. + 15, 16, 17, 22, 56, 75, 76, 25, 38, 17,
  116581. + 17, 25, 29, 54, 56, 76, 28, 56, 75, 62,
  116582. + 25, 25, 57, 58, 25, 22, 25, 34, 14, 21,
  116583. + 22, 23, 24, 31, 36, 59, 18, 33, 74, 22,
  116584. + 23, 30, 60, 36, 21, 20, 22, 32, 34, 35,
  116585. + 60, 34, 60, 35
  116586. +};
  116587. -static const yytype_int16 yycheck[] =
  116588. + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
  116589. +static const yytype_uint8 yyr1[] =
  116590. {
  116591. - 5, 38, 39, 17, 18, 19, 12, 12, 17, 18,
  116592. - 7, 8, 13, 90, 4, 22, 93, 20, 25, 22,
  116593. - 21, 22, 23, 24, 33, 3, 26, 34, 26, 32,
  116594. - 31, 37, 22, 30, 43, 36, 25, 46, 47, 36,
  116595. - 17, 18, 9, 10, 44, 45, 60, 61, 62, 17,
  116596. - 18, 0, 89, 15, 22, 23, 33, 27, 14, 15,
  116597. - 16, 23, 30, 11, 26, 33, 22, 25, 39, 27,
  116598. - 35, 29, 52, 53, 54, 55, 5, 6, 42, 43,
  116599. - 34, 35, 56, 57, 50, 51, 58, 59, 40, 25,
  116600. - 41, 23, 25, 38, 16, 16, 33, 28, 25, 25,
  116601. - 25, 17, 36, 21, 34, 8, 6, 35, 95, 47,
  116602. - 45, 93, -1, -1, 90, -1, -1, 122, -1, -1,
  116603. - 44, -1, -1, 46, -1, -1, -1, -1, 48, -1,
  116604. - 135, -1, 49, 138
  116605. + 0, 48, 49, 50, 50, 51, 51, 52, 52, 53,
  116606. + 53, 53, 53, 54, 55, 55, 56, 56, 56, 56,
  116607. + 57, 57, 57, 57, 57, 57, 57, 58, 58, 58,
  116608. + 59, 59, 59, 59, 59, 60, 60, 60, 61, 62,
  116609. + 62, 63, 63, 64, 64, 65, 65, 66, 66, 67,
  116610. + 67, 68, 68, 68, 69, 69, 69, 69, 69, 70,
  116611. + 70, 70, 71, 71, 71, 72, 72, 72, 72, 73,
  116612. + 73, 73, 73, 74, 74, 74, 75, 75, 75, 76,
  116613. + 76, 76
  116614. };
  116615. -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
  116616. - symbol of state STATE-NUM. */
  116617. -static const yytype_uint8 yystos[] =
  116618. + /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
  116619. +static const yytype_uint8 yyr2[] =
  116620. {
  116621. - 0, 3, 49, 25, 0, 4, 22, 50, 51, 17,
  116622. - 18, 33, 59, 51, 26, 52, 50, 43, 46, 47,
  116623. - 59, 60, 61, 62, 63, 64, 65, 66, 67, 68,
  116624. - 69, 70, 71, 72, 59, 27, 53, 15, 23, 26,
  116625. - 72, 72, 72, 35, 12, 37, 11, 39, 40, 41,
  116626. - 9, 10, 7, 8, 30, 36, 5, 6, 42, 43,
  116627. - 26, 44, 45, 25, 54, 23, 53, 53, 63, 60,
  116628. - 64, 65, 66, 67, 68, 68, 69, 69, 69, 69,
  116629. - 70, 70, 71, 71, 72, 72, 72, 14, 15, 16,
  116630. - 22, 55, 74, 75, 25, 38, 16, 16, 25, 29,
  116631. - 53, 55, 75, 28, 55, 74, 61, 25, 25, 56,
  116632. - 57, 25, 22, 25, 34, 13, 21, 22, 23, 24,
  116633. - 31, 36, 58, 17, 33, 73, 22, 23, 30, 59,
  116634. - 36, 21, 20, 22, 32, 34, 35, 59, 34, 59,
  116635. - 35
  116636. + 0, 2, 5, 0, 2, 0, 2, 4, 2, 2,
  116637. + 3, 3, 4, 5, 0, 2, 4, 2, 3, 2,
  116638. + 2, 3, 4, 2, 9, 5, 2, 0, 2, 2,
  116639. + 3, 1, 2, 2, 2, 1, 1, 3, 1, 1,
  116640. + 5, 1, 3, 1, 3, 1, 3, 1, 3, 1,
  116641. + 3, 1, 3, 3, 1, 3, 3, 3, 3, 3,
  116642. + 3, 1, 3, 3, 1, 3, 3, 3, 1, 1,
  116643. + 2, 2, 2, 0, 2, 2, 0, 2, 2, 2,
  116644. + 3, 2
  116645. };
  116646. -#define yyerrok (yyerrstatus = 0)
  116647. -#define yyclearin (yychar = YYEMPTY)
  116648. -#define YYEMPTY (-2)
  116649. -#define YYEOF 0
  116650. -
  116651. -#define YYACCEPT goto yyacceptlab
  116652. -#define YYABORT goto yyabortlab
  116653. -#define YYERROR goto yyerrorlab
  116654. -
  116655. -
  116656. -/* Like YYERROR except do call yyerror. This remains here temporarily
  116657. - to ease the transition to the new meaning of YYERROR, for GCC.
  116658. - Once GCC version 2 has supplanted version 1, this can go. However,
  116659. - YYFAIL appears to be in use. Nevertheless, it is formally deprecated
  116660. - in Bison 2.4.2's NEWS entry, where a plan to phase it out is
  116661. - discussed. */
  116662. -
  116663. -#define YYFAIL goto yyerrlab
  116664. -#if defined YYFAIL
  116665. - /* This is here to suppress warnings from the GCC cpp's
  116666. - -Wunused-macros. Normally we don't worry about that warning, but
  116667. - some users do, and we want to make it easy for users to remove
  116668. - YYFAIL uses, which will produce warnings from Bison 2.5. */
  116669. -#endif
  116670. +
  116671. +#define yyerrok (yyerrstatus = 0)
  116672. +#define yyclearin (yychar = YYEMPTY)
  116673. +#define YYEMPTY (-2)
  116674. +#define YYEOF 0
  116675. +
  116676. +#define YYACCEPT goto yyacceptlab
  116677. +#define YYABORT goto yyabortlab
  116678. +#define YYERROR goto yyerrorlab
  116679. +
  116680. #define YYRECOVERING() (!!yyerrstatus)
  116681. @@ -768,27 +725,41 @@
  116682. else \
  116683. { \
  116684. yyerror (YY_("syntax error: cannot back up")); \
  116685. - YYERROR; \
  116686. - } \
  116687. -while (YYID (0))
  116688. + YYERROR; \
  116689. + } \
  116690. +while (0)
  116691. /* Error token number */
  116692. -#define YYTERROR 1
  116693. -#define YYERRCODE 256
  116694. +#define YYTERROR 1
  116695. +#define YYERRCODE 256
  116696. -/* This macro is provided for backward compatibility. */
  116697. -#ifndef YY_LOCATION_PRINT
  116698. -# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
  116699. +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
  116700. + If N is 0, then set CURRENT to the empty location which ends
  116701. + the previous symbol: RHS[0] (always defined). */
  116702. +
  116703. +#ifndef YYLLOC_DEFAULT
  116704. +# define YYLLOC_DEFAULT(Current, Rhs, N) \
  116705. + do \
  116706. + if (N) \
  116707. + { \
  116708. + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
  116709. + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
  116710. + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
  116711. + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
  116712. + } \
  116713. + else \
  116714. + { \
  116715. + (Current).first_line = (Current).last_line = \
  116716. + YYRHSLOC (Rhs, 0).last_line; \
  116717. + (Current).first_column = (Current).last_column = \
  116718. + YYRHSLOC (Rhs, 0).last_column; \
  116719. + } \
  116720. + while (0)
  116721. #endif
  116722. +#define YYRHSLOC(Rhs, K) ((Rhs)[K])
  116723. -/* YYLEX -- calling `yylex' with the right arguments. */
  116724. -#ifdef YYLEX_PARAM
  116725. -# define YYLEX yylex (YYLEX_PARAM)
  116726. -#else
  116727. -# define YYLEX yylex ()
  116728. -#endif
  116729. /* Enable debugging if requested. */
  116730. #if YYDEBUG
  116731. @@ -798,50 +769,84 @@
  116732. # define YYFPRINTF fprintf
  116733. # endif
  116734. -# define YYDPRINTF(Args) \
  116735. -do { \
  116736. - if (yydebug) \
  116737. - YYFPRINTF Args; \
  116738. -} while (YYID (0))
  116739. -
  116740. -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
  116741. -do { \
  116742. - if (yydebug) \
  116743. - { \
  116744. - YYFPRINTF (stderr, "%s ", Title); \
  116745. - yy_symbol_print (stderr, \
  116746. - Type, Value); \
  116747. - YYFPRINTF (stderr, "\n"); \
  116748. - } \
  116749. -} while (YYID (0))
  116750. +# define YYDPRINTF(Args) \
  116751. +do { \
  116752. + if (yydebug) \
  116753. + YYFPRINTF Args; \
  116754. +} while (0)
  116755. -/*--------------------------------.
  116756. -| Print this symbol on YYOUTPUT. |
  116757. -`--------------------------------*/
  116758. +/* YY_LOCATION_PRINT -- Print the location on the stream.
  116759. + This macro was not mandated originally: define only if we know
  116760. + we won't break user code: when these are the locations we know. */
  116761. -/*ARGSUSED*/
  116762. -#if (defined __STDC__ || defined __C99__FUNC__ \
  116763. - || defined __cplusplus || defined _MSC_VER)
  116764. -static void
  116765. -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
  116766. -#else
  116767. -static void
  116768. -yy_symbol_value_print (yyoutput, yytype, yyvaluep)
  116769. - FILE *yyoutput;
  116770. - int yytype;
  116771. - YYSTYPE const * const yyvaluep;
  116772. +#ifndef YY_LOCATION_PRINT
  116773. +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
  116774. +
  116775. +/* Print *YYLOCP on YYO. Private, do not rely on its existence. */
  116776. +
  116777. +YY_ATTRIBUTE_UNUSED
  116778. +static unsigned
  116779. +yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
  116780. +{
  116781. + unsigned res = 0;
  116782. + int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
  116783. + if (0 <= yylocp->first_line)
  116784. + {
  116785. + res += YYFPRINTF (yyo, "%d", yylocp->first_line);
  116786. + if (0 <= yylocp->first_column)
  116787. + res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
  116788. + }
  116789. + if (0 <= yylocp->last_line)
  116790. + {
  116791. + if (yylocp->first_line < yylocp->last_line)
  116792. + {
  116793. + res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
  116794. + if (0 <= end_col)
  116795. + res += YYFPRINTF (yyo, ".%d", end_col);
  116796. + }
  116797. + else if (0 <= end_col && yylocp->first_column < end_col)
  116798. + res += YYFPRINTF (yyo, "-%d", end_col);
  116799. + }
  116800. + return res;
  116801. + }
  116802. +
  116803. +# define YY_LOCATION_PRINT(File, Loc) \
  116804. + yy_location_print_ (File, &(Loc))
  116805. +
  116806. +# else
  116807. +# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
  116808. +# endif
  116809. #endif
  116810. +
  116811. +
  116812. +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
  116813. +do { \
  116814. + if (yydebug) \
  116815. + { \
  116816. + YYFPRINTF (stderr, "%s ", Title); \
  116817. + yy_symbol_print (stderr, \
  116818. + Type, Value, Location); \
  116819. + YYFPRINTF (stderr, "\n"); \
  116820. + } \
  116821. +} while (0)
  116822. +
  116823. +
  116824. +/*----------------------------------------.
  116825. +| Print this symbol's value on YYOUTPUT. |
  116826. +`----------------------------------------*/
  116827. +
  116828. +static void
  116829. +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
  116830. {
  116831. FILE *yyo = yyoutput;
  116832. YYUSE (yyo);
  116833. + YYUSE (yylocationp);
  116834. if (!yyvaluep)
  116835. return;
  116836. # ifdef YYPRINT
  116837. if (yytype < YYNTOKENS)
  116838. YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
  116839. -# else
  116840. - YYUSE (yyoutput);
  116841. # endif
  116842. YYUSE (yytype);
  116843. }
  116844. @@ -851,24 +856,15 @@
  116845. | Print this symbol on YYOUTPUT. |
  116846. `--------------------------------*/
  116847. -#if (defined __STDC__ || defined __C99__FUNC__ \
  116848. - || defined __cplusplus || defined _MSC_VER)
  116849. -static void
  116850. -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
  116851. -#else
  116852. static void
  116853. -yy_symbol_print (yyoutput, yytype, yyvaluep)
  116854. - FILE *yyoutput;
  116855. - int yytype;
  116856. - YYSTYPE const * const yyvaluep;
  116857. -#endif
  116858. +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
  116859. {
  116860. - if (yytype < YYNTOKENS)
  116861. - YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
  116862. - else
  116863. - YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
  116864. + YYFPRINTF (yyoutput, "%s %s (",
  116865. + yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
  116866. - yy_symbol_value_print (yyoutput, yytype, yyvaluep);
  116867. + YY_LOCATION_PRINT (yyoutput, *yylocationp);
  116868. + YYFPRINTF (yyoutput, ": ");
  116869. + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
  116870. YYFPRINTF (yyoutput, ")");
  116871. }
  116872. @@ -877,16 +873,8 @@
  116873. | TOP (included). |
  116874. `------------------------------------------------------------------*/
  116875. -#if (defined __STDC__ || defined __C99__FUNC__ \
  116876. - || defined __cplusplus || defined _MSC_VER)
  116877. static void
  116878. yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
  116879. -#else
  116880. -static void
  116881. -yy_stack_print (yybottom, yytop)
  116882. - yytype_int16 *yybottom;
  116883. - yytype_int16 *yytop;
  116884. -#endif
  116885. {
  116886. YYFPRINTF (stderr, "Stack now");
  116887. for (; yybottom <= yytop; yybottom++)
  116888. @@ -897,49 +885,42 @@
  116889. YYFPRINTF (stderr, "\n");
  116890. }
  116891. -# define YY_STACK_PRINT(Bottom, Top) \
  116892. -do { \
  116893. - if (yydebug) \
  116894. - yy_stack_print ((Bottom), (Top)); \
  116895. -} while (YYID (0))
  116896. +# define YY_STACK_PRINT(Bottom, Top) \
  116897. +do { \
  116898. + if (yydebug) \
  116899. + yy_stack_print ((Bottom), (Top)); \
  116900. +} while (0)
  116901. /*------------------------------------------------.
  116902. | Report that the YYRULE is going to be reduced. |
  116903. `------------------------------------------------*/
  116904. -#if (defined __STDC__ || defined __C99__FUNC__ \
  116905. - || defined __cplusplus || defined _MSC_VER)
  116906. -static void
  116907. -yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
  116908. -#else
  116909. static void
  116910. -yy_reduce_print (yyvsp, yyrule)
  116911. - YYSTYPE *yyvsp;
  116912. - int yyrule;
  116913. -#endif
  116914. +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
  116915. {
  116916. + unsigned long int yylno = yyrline[yyrule];
  116917. int yynrhs = yyr2[yyrule];
  116918. int yyi;
  116919. - unsigned long int yylno = yyrline[yyrule];
  116920. YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
  116921. - yyrule - 1, yylno);
  116922. + yyrule - 1, yylno);
  116923. /* The symbols being reduced. */
  116924. for (yyi = 0; yyi < yynrhs; yyi++)
  116925. {
  116926. YYFPRINTF (stderr, " $%d = ", yyi + 1);
  116927. - yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
  116928. - &(yyvsp[(yyi + 1) - (yynrhs)])
  116929. - );
  116930. + yy_symbol_print (stderr,
  116931. + yystos[yyssp[yyi + 1 - yynrhs]],
  116932. + &(yyvsp[(yyi + 1) - (yynrhs)])
  116933. + , &(yylsp[(yyi + 1) - (yynrhs)]) );
  116934. YYFPRINTF (stderr, "\n");
  116935. }
  116936. }
  116937. -# define YY_REDUCE_PRINT(Rule) \
  116938. -do { \
  116939. - if (yydebug) \
  116940. - yy_reduce_print (yyvsp, Rule); \
  116941. -} while (YYID (0))
  116942. +# define YY_REDUCE_PRINT(Rule) \
  116943. +do { \
  116944. + if (yydebug) \
  116945. + yy_reduce_print (yyssp, yyvsp, yylsp, Rule); \
  116946. +} while (0)
  116947. /* Nonzero means print parse trace. It is left uninitialized so that
  116948. multiple parsers can coexist. */
  116949. @@ -953,7 +934,7 @@
  116950. /* YYINITDEPTH -- initial size of the parser's stacks. */
  116951. -#ifndef YYINITDEPTH
  116952. +#ifndef YYINITDEPTH
  116953. # define YYINITDEPTH 200
  116954. #endif
  116955. @@ -976,15 +957,8 @@
  116956. # define yystrlen strlen
  116957. # else
  116958. /* Return the length of YYSTR. */
  116959. -#if (defined __STDC__ || defined __C99__FUNC__ \
  116960. - || defined __cplusplus || defined _MSC_VER)
  116961. static YYSIZE_T
  116962. yystrlen (const char *yystr)
  116963. -#else
  116964. -static YYSIZE_T
  116965. -yystrlen (yystr)
  116966. - const char *yystr;
  116967. -#endif
  116968. {
  116969. YYSIZE_T yylen;
  116970. for (yylen = 0; yystr[yylen]; yylen++)
  116971. @@ -1000,16 +974,8 @@
  116972. # else
  116973. /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
  116974. YYDEST. */
  116975. -#if (defined __STDC__ || defined __C99__FUNC__ \
  116976. - || defined __cplusplus || defined _MSC_VER)
  116977. static char *
  116978. yystpcpy (char *yydest, const char *yysrc)
  116979. -#else
  116980. -static char *
  116981. -yystpcpy (yydest, yysrc)
  116982. - char *yydest;
  116983. - const char *yysrc;
  116984. -#endif
  116985. {
  116986. char *yyd = yydest;
  116987. const char *yys = yysrc;
  116988. @@ -1039,27 +1005,27 @@
  116989. char const *yyp = yystr;
  116990. for (;;)
  116991. - switch (*++yyp)
  116992. - {
  116993. - case '\'':
  116994. - case ',':
  116995. - goto do_not_strip_quotes;
  116996. -
  116997. - case '\\':
  116998. - if (*++yyp != '\\')
  116999. - goto do_not_strip_quotes;
  117000. - /* Fall through. */
  117001. - default:
  117002. - if (yyres)
  117003. - yyres[yyn] = *yyp;
  117004. - yyn++;
  117005. - break;
  117006. -
  117007. - case '"':
  117008. - if (yyres)
  117009. - yyres[yyn] = '\0';
  117010. - return yyn;
  117011. - }
  117012. + switch (*++yyp)
  117013. + {
  117014. + case '\'':
  117015. + case ',':
  117016. + goto do_not_strip_quotes;
  117017. +
  117018. + case '\\':
  117019. + if (*++yyp != '\\')
  117020. + goto do_not_strip_quotes;
  117021. + /* Fall through. */
  117022. + default:
  117023. + if (yyres)
  117024. + yyres[yyn] = *yyp;
  117025. + yyn++;
  117026. + break;
  117027. +
  117028. + case '"':
  117029. + if (yyres)
  117030. + yyres[yyn] = '\0';
  117031. + return yyn;
  117032. + }
  117033. do_not_strip_quotes: ;
  117034. }
  117035. @@ -1082,11 +1048,11 @@
  117036. yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
  117037. yytype_int16 *yyssp, int yytoken)
  117038. {
  117039. - YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
  117040. + YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
  117041. YYSIZE_T yysize = yysize0;
  117042. enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  117043. /* Internationalized format string. */
  117044. - const char *yyformat = YY_NULL;
  117045. + const char *yyformat = YY_NULLPTR;
  117046. /* Arguments of yyformat. */
  117047. char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
  117048. /* Number of reported tokens (one for the "unexpected", one per
  117049. @@ -1094,10 +1060,6 @@
  117050. int yycount = 0;
  117051. /* There are many possibilities here to consider:
  117052. - - Assume YYFAIL is not used. It's too flawed to consider. See
  117053. - <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
  117054. - for details. YYERROR is fine as it does not invoke this
  117055. - function.
  117056. - If this state is a consistent state with a default action, then
  117057. the only way this function was invoked is if the default action
  117058. is an error action. In that case, don't check for expected
  117059. @@ -1147,7 +1109,7 @@
  117060. }
  117061. yyarg[yycount++] = yytname[yyx];
  117062. {
  117063. - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
  117064. + YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
  117065. if (! (yysize <= yysize1
  117066. && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
  117067. return 2;
  117068. @@ -1214,26 +1176,18 @@
  117069. | Release the memory associated to this symbol. |
  117070. `-----------------------------------------------*/
  117071. -/*ARGSUSED*/
  117072. -#if (defined __STDC__ || defined __C99__FUNC__ \
  117073. - || defined __cplusplus || defined _MSC_VER)
  117074. -static void
  117075. -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
  117076. -#else
  117077. static void
  117078. -yydestruct (yymsg, yytype, yyvaluep)
  117079. - const char *yymsg;
  117080. - int yytype;
  117081. - YYSTYPE *yyvaluep;
  117082. -#endif
  117083. +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
  117084. {
  117085. YYUSE (yyvaluep);
  117086. -
  117087. + YYUSE (yylocationp);
  117088. if (!yymsg)
  117089. yymsg = "Deleting";
  117090. YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
  117091. + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  117092. YYUSE (yytype);
  117093. + YY_IGNORE_MAYBE_UNINITIALIZED_END
  117094. }
  117095. @@ -1242,18 +1196,14 @@
  117096. /* The lookahead symbol. */
  117097. int yychar;
  117098. -
  117099. -#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  117100. -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  117101. -# define YY_IGNORE_MAYBE_UNINITIALIZED_END
  117102. -#endif
  117103. -#ifndef YY_INITIAL_VALUE
  117104. -# define YY_INITIAL_VALUE(Value) /* Nothing. */
  117105. -#endif
  117106. -
  117107. /* The semantic value of the lookahead symbol. */
  117108. -YYSTYPE yylval YY_INITIAL_VALUE(yyval_default);
  117109. -
  117110. +YYSTYPE yylval;
  117111. +/* Location data for the lookahead symbol. */
  117112. +YYLTYPE yylloc
  117113. +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
  117114. + = { 1, 1, 1, 1 }
  117115. +# endif
  117116. +;
  117117. /* Number of syntax errors so far. */
  117118. int yynerrs;
  117119. @@ -1262,35 +1212,17 @@
  117120. | yyparse. |
  117121. `----------*/
  117122. -#ifdef YYPARSE_PARAM
  117123. -#if (defined __STDC__ || defined __C99__FUNC__ \
  117124. - || defined __cplusplus || defined _MSC_VER)
  117125. -int
  117126. -yyparse (void *YYPARSE_PARAM)
  117127. -#else
  117128. -int
  117129. -yyparse (YYPARSE_PARAM)
  117130. - void *YYPARSE_PARAM;
  117131. -#endif
  117132. -#else /* ! YYPARSE_PARAM */
  117133. -#if (defined __STDC__ || defined __C99__FUNC__ \
  117134. - || defined __cplusplus || defined _MSC_VER)
  117135. int
  117136. yyparse (void)
  117137. -#else
  117138. -int
  117139. -yyparse ()
  117140. -
  117141. -#endif
  117142. -#endif
  117143. {
  117144. int yystate;
  117145. /* Number of tokens to shift before error messages enabled. */
  117146. int yyerrstatus;
  117147. /* The stacks and their tools:
  117148. - `yyss': related to states.
  117149. - `yyvs': related to semantic values.
  117150. + 'yyss': related to states.
  117151. + 'yyvs': related to semantic values.
  117152. + 'yyls': related to locations.
  117153. Refer to the stacks through separate pointers, to allow yyoverflow
  117154. to reallocate them elsewhere. */
  117155. @@ -1305,6 +1237,14 @@
  117156. YYSTYPE *yyvs;
  117157. YYSTYPE *yyvsp;
  117158. + /* The location stack. */
  117159. + YYLTYPE yylsa[YYINITDEPTH];
  117160. + YYLTYPE *yyls;
  117161. + YYLTYPE *yylsp;
  117162. +
  117163. + /* The locations where the error started and ended. */
  117164. + YYLTYPE yyerror_range[3];
  117165. +
  117166. YYSIZE_T yystacksize;
  117167. int yyn;
  117168. @@ -1314,6 +1254,7 @@
  117169. /* The variables used to return semantic value and location from the
  117170. action routines. */
  117171. YYSTYPE yyval;
  117172. + YYLTYPE yyloc;
  117173. #if YYERROR_VERBOSE
  117174. /* Buffer for error messages, and its allocated size. */
  117175. @@ -1322,7 +1263,7 @@
  117176. YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
  117177. #endif
  117178. -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
  117179. +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
  117180. /* The number of symbols on the RHS of the reduced rule.
  117181. Keep to zero when no symbol should be popped. */
  117182. @@ -1330,6 +1271,7 @@
  117183. yyssp = yyss = yyssa;
  117184. yyvsp = yyvs = yyvsa;
  117185. + yylsp = yyls = yylsa;
  117186. yystacksize = YYINITDEPTH;
  117187. YYDPRINTF ((stderr, "Starting parse\n"));
  117188. @@ -1338,6 +1280,7 @@
  117189. yyerrstatus = 0;
  117190. yynerrs = 0;
  117191. yychar = YYEMPTY; /* Cause a token to be read. */
  117192. + yylsp[0] = yylloc;
  117193. goto yysetstate;
  117194. /*------------------------------------------------------------.
  117195. @@ -1358,23 +1301,26 @@
  117196. #ifdef yyoverflow
  117197. {
  117198. - /* Give user a chance to reallocate the stack. Use copies of
  117199. - these so that the &'s don't force the real ones into
  117200. - memory. */
  117201. - YYSTYPE *yyvs1 = yyvs;
  117202. - yytype_int16 *yyss1 = yyss;
  117203. -
  117204. - /* Each stack pointer address is followed by the size of the
  117205. - data in use in that stack, in bytes. This used to be a
  117206. - conditional around just the two extra args, but that might
  117207. - be undefined if yyoverflow is a macro. */
  117208. - yyoverflow (YY_("memory exhausted"),
  117209. - &yyss1, yysize * sizeof (*yyssp),
  117210. - &yyvs1, yysize * sizeof (*yyvsp),
  117211. - &yystacksize);
  117212. -
  117213. - yyss = yyss1;
  117214. - yyvs = yyvs1;
  117215. + /* Give user a chance to reallocate the stack. Use copies of
  117216. + these so that the &'s don't force the real ones into
  117217. + memory. */
  117218. + YYSTYPE *yyvs1 = yyvs;
  117219. + yytype_int16 *yyss1 = yyss;
  117220. + YYLTYPE *yyls1 = yyls;
  117221. +
  117222. + /* Each stack pointer address is followed by the size of the
  117223. + data in use in that stack, in bytes. This used to be a
  117224. + conditional around just the two extra args, but that might
  117225. + be undefined if yyoverflow is a macro. */
  117226. + yyoverflow (YY_("memory exhausted"),
  117227. + &yyss1, yysize * sizeof (*yyssp),
  117228. + &yyvs1, yysize * sizeof (*yyvsp),
  117229. + &yyls1, yysize * sizeof (*yylsp),
  117230. + &yystacksize);
  117231. +
  117232. + yyls = yyls1;
  117233. + yyss = yyss1;
  117234. + yyvs = yyvs1;
  117235. }
  117236. #else /* no yyoverflow */
  117237. # ifndef YYSTACK_RELOCATE
  117238. @@ -1382,34 +1328,36 @@
  117239. # else
  117240. /* Extend the stack our own way. */
  117241. if (YYMAXDEPTH <= yystacksize)
  117242. - goto yyexhaustedlab;
  117243. + goto yyexhaustedlab;
  117244. yystacksize *= 2;
  117245. if (YYMAXDEPTH < yystacksize)
  117246. - yystacksize = YYMAXDEPTH;
  117247. + yystacksize = YYMAXDEPTH;
  117248. {
  117249. - yytype_int16 *yyss1 = yyss;
  117250. - union yyalloc *yyptr =
  117251. - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
  117252. - if (! yyptr)
  117253. - goto yyexhaustedlab;
  117254. - YYSTACK_RELOCATE (yyss_alloc, yyss);
  117255. - YYSTACK_RELOCATE (yyvs_alloc, yyvs);
  117256. + yytype_int16 *yyss1 = yyss;
  117257. + union yyalloc *yyptr =
  117258. + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
  117259. + if (! yyptr)
  117260. + goto yyexhaustedlab;
  117261. + YYSTACK_RELOCATE (yyss_alloc, yyss);
  117262. + YYSTACK_RELOCATE (yyvs_alloc, yyvs);
  117263. + YYSTACK_RELOCATE (yyls_alloc, yyls);
  117264. # undef YYSTACK_RELOCATE
  117265. - if (yyss1 != yyssa)
  117266. - YYSTACK_FREE (yyss1);
  117267. + if (yyss1 != yyssa)
  117268. + YYSTACK_FREE (yyss1);
  117269. }
  117270. # endif
  117271. #endif /* no yyoverflow */
  117272. yyssp = yyss + yysize - 1;
  117273. yyvsp = yyvs + yysize - 1;
  117274. + yylsp = yyls + yysize - 1;
  117275. YYDPRINTF ((stderr, "Stack size increased to %lu\n",
  117276. - (unsigned long int) yystacksize));
  117277. + (unsigned long int) yystacksize));
  117278. if (yyss + yystacksize - 1 <= yyssp)
  117279. - YYABORT;
  117280. + YYABORT;
  117281. }
  117282. YYDPRINTF ((stderr, "Entering state %d\n", yystate));
  117283. @@ -1438,7 +1386,7 @@
  117284. if (yychar == YYEMPTY)
  117285. {
  117286. YYDPRINTF ((stderr, "Reading a token: "));
  117287. - yychar = YYLEX;
  117288. + yychar = yylex ();
  117289. }
  117290. if (yychar <= YYEOF)
  117291. @@ -1481,7 +1429,7 @@
  117292. YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  117293. *++yyvsp = yylval;
  117294. YY_IGNORE_MAYBE_UNINITIALIZED_END
  117295. -
  117296. + *++yylsp = yylloc;
  117297. goto yynewstate;
  117298. @@ -1503,7 +1451,7 @@
  117299. yylen = yyr2[yyn];
  117300. /* If YYLEN is nonzero, implement the default value of the action:
  117301. - `$$ = $1'.
  117302. + '$$ = $1'.
  117303. Otherwise, the following line sets YYVAL to garbage.
  117304. This behavior is undocumented and Bison
  117305. @@ -1512,287 +1460,306 @@
  117306. GCC warning that YYVAL may be used uninitialized. */
  117307. yyval = yyvsp[1-yylen];
  117308. -
  117309. + /* Default location. */
  117310. + YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
  117311. YY_REDUCE_PRINT (yyn);
  117312. switch (yyn)
  117313. {
  117314. case 2:
  117315. -/* Line 1787 of yacc.c */
  117316. -#line 110 "dtc-parser.y"
  117317. +#line 109 "dtc-parser.y" /* yacc.c:1646 */
  117318. {
  117319. - the_boot_info = build_boot_info((yyvsp[(3) - (4)].re), (yyvsp[(4) - (4)].node),
  117320. - guess_boot_cpuid((yyvsp[(4) - (4)].node)));
  117321. + (yyvsp[0].node)->is_plugin = (yyvsp[-2].is_plugin);
  117322. + (yyvsp[0].node)->is_root = 1;
  117323. + the_boot_info = build_boot_info((yyvsp[-1].re), (yyvsp[0].node),
  117324. + guess_boot_cpuid((yyvsp[0].node)));
  117325. }
  117326. +#line 1477 "dtc-parser.tab.c" /* yacc.c:1646 */
  117327. break;
  117328. case 3:
  117329. -/* Line 1787 of yacc.c */
  117330. -#line 118 "dtc-parser.y"
  117331. +#line 119 "dtc-parser.y" /* yacc.c:1646 */
  117332. {
  117333. - (yyval.re) = NULL;
  117334. + (yyval.is_plugin) = 0;
  117335. }
  117336. +#line 1485 "dtc-parser.tab.c" /* yacc.c:1646 */
  117337. break;
  117338. case 4:
  117339. -/* Line 1787 of yacc.c */
  117340. -#line 122 "dtc-parser.y"
  117341. +#line 123 "dtc-parser.y" /* yacc.c:1646 */
  117342. {
  117343. - (yyval.re) = chain_reserve_entry((yyvsp[(1) - (2)].re), (yyvsp[(2) - (2)].re));
  117344. + (yyval.is_plugin) = 1;
  117345. }
  117346. +#line 1493 "dtc-parser.tab.c" /* yacc.c:1646 */
  117347. break;
  117348. case 5:
  117349. -/* Line 1787 of yacc.c */
  117350. -#line 129 "dtc-parser.y"
  117351. +#line 130 "dtc-parser.y" /* yacc.c:1646 */
  117352. {
  117353. - (yyval.re) = build_reserve_entry((yyvsp[(2) - (4)].integer), (yyvsp[(3) - (4)].integer));
  117354. + (yyval.re) = NULL;
  117355. }
  117356. +#line 1501 "dtc-parser.tab.c" /* yacc.c:1646 */
  117357. break;
  117358. case 6:
  117359. -/* Line 1787 of yacc.c */
  117360. -#line 133 "dtc-parser.y"
  117361. +#line 134 "dtc-parser.y" /* yacc.c:1646 */
  117362. {
  117363. - add_label(&(yyvsp[(2) - (2)].re)->labels, (yyvsp[(1) - (2)].labelref));
  117364. - (yyval.re) = (yyvsp[(2) - (2)].re);
  117365. + (yyval.re) = chain_reserve_entry((yyvsp[-1].re), (yyvsp[0].re));
  117366. }
  117367. +#line 1509 "dtc-parser.tab.c" /* yacc.c:1646 */
  117368. break;
  117369. case 7:
  117370. -/* Line 1787 of yacc.c */
  117371. -#line 141 "dtc-parser.y"
  117372. +#line 141 "dtc-parser.y" /* yacc.c:1646 */
  117373. {
  117374. - (yyval.node) = name_node((yyvsp[(2) - (2)].node), "");
  117375. + (yyval.re) = build_reserve_entry((yyvsp[-2].integer), (yyvsp[-1].integer));
  117376. }
  117377. +#line 1517 "dtc-parser.tab.c" /* yacc.c:1646 */
  117378. break;
  117379. case 8:
  117380. -/* Line 1787 of yacc.c */
  117381. -#line 145 "dtc-parser.y"
  117382. +#line 145 "dtc-parser.y" /* yacc.c:1646 */
  117383. {
  117384. - (yyval.node) = merge_nodes((yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node));
  117385. + add_label(&(yyvsp[0].re)->labels, (yyvsp[-1].labelref));
  117386. + (yyval.re) = (yyvsp[0].re);
  117387. }
  117388. +#line 1526 "dtc-parser.tab.c" /* yacc.c:1646 */
  117389. break;
  117390. case 9:
  117391. -/* Line 1787 of yacc.c */
  117392. -#line 149 "dtc-parser.y"
  117393. +#line 153 "dtc-parser.y" /* yacc.c:1646 */
  117394. {
  117395. - struct node *target = get_node_by_ref((yyvsp[(1) - (3)].node), (yyvsp[(2) - (3)].labelref));
  117396. -
  117397. - if (target)
  117398. - merge_nodes(target, (yyvsp[(3) - (3)].node));
  117399. - else
  117400. - print_error("label or path, '%s', not found", (yyvsp[(2) - (3)].labelref));
  117401. - (yyval.node) = (yyvsp[(1) - (3)].node);
  117402. + (yyval.node) = name_node((yyvsp[0].node), "");
  117403. }
  117404. +#line 1534 "dtc-parser.tab.c" /* yacc.c:1646 */
  117405. break;
  117406. case 10:
  117407. -/* Line 1787 of yacc.c */
  117408. -#line 159 "dtc-parser.y"
  117409. +#line 157 "dtc-parser.y" /* yacc.c:1646 */
  117410. {
  117411. - struct node *target = get_node_by_ref((yyvsp[(1) - (4)].node), (yyvsp[(3) - (4)].labelref));
  117412. -
  117413. - if (!target)
  117414. - print_error("label or path, '%s', not found", (yyvsp[(3) - (4)].labelref));
  117415. - else
  117416. - delete_node(target);
  117417. -
  117418. - (yyval.node) = (yyvsp[(1) - (4)].node);
  117419. + (yyval.node) = merge_nodes((yyvsp[-2].node), (yyvsp[0].node));
  117420. }
  117421. +#line 1542 "dtc-parser.tab.c" /* yacc.c:1646 */
  117422. break;
  117423. case 11:
  117424. -/* Line 1787 of yacc.c */
  117425. -#line 173 "dtc-parser.y"
  117426. +#line 161 "dtc-parser.y" /* yacc.c:1646 */
  117427. {
  117428. - (yyval.node) = build_node((yyvsp[(2) - (5)].proplist), (yyvsp[(3) - (5)].nodelist));
  117429. + struct node *target = get_node_by_ref((yyvsp[-2].node), (yyvsp[-1].labelref));
  117430. +
  117431. + if (target)
  117432. + merge_nodes(target, (yyvsp[0].node));
  117433. + else
  117434. + ERROR(&(yylsp[-1]), "Label or path %s not found", (yyvsp[-1].labelref));
  117435. + (yyval.node) = (yyvsp[-2].node);
  117436. }
  117437. +#line 1556 "dtc-parser.tab.c" /* yacc.c:1646 */
  117438. break;
  117439. case 12:
  117440. -/* Line 1787 of yacc.c */
  117441. -#line 180 "dtc-parser.y"
  117442. +#line 171 "dtc-parser.y" /* yacc.c:1646 */
  117443. {
  117444. - (yyval.proplist) = NULL;
  117445. + struct node *target = get_node_by_ref((yyvsp[-3].node), (yyvsp[-1].labelref));
  117446. +
  117447. + if (target)
  117448. + delete_node(target);
  117449. + else
  117450. + ERROR(&(yylsp[-1]), "Label or path %s not found", (yyvsp[-1].labelref));
  117451. +
  117452. +
  117453. + (yyval.node) = (yyvsp[-3].node);
  117454. }
  117455. +#line 1572 "dtc-parser.tab.c" /* yacc.c:1646 */
  117456. break;
  117457. case 13:
  117458. -/* Line 1787 of yacc.c */
  117459. -#line 184 "dtc-parser.y"
  117460. +#line 186 "dtc-parser.y" /* yacc.c:1646 */
  117461. {
  117462. - (yyval.proplist) = chain_property((yyvsp[(2) - (2)].prop), (yyvsp[(1) - (2)].proplist));
  117463. + (yyval.node) = build_node((yyvsp[-3].proplist), (yyvsp[-2].nodelist));
  117464. }
  117465. +#line 1580 "dtc-parser.tab.c" /* yacc.c:1646 */
  117466. break;
  117467. case 14:
  117468. -/* Line 1787 of yacc.c */
  117469. -#line 191 "dtc-parser.y"
  117470. +#line 193 "dtc-parser.y" /* yacc.c:1646 */
  117471. {
  117472. - (yyval.prop) = build_property((yyvsp[(1) - (4)].propnodename), (yyvsp[(3) - (4)].data));
  117473. + (yyval.proplist) = NULL;
  117474. }
  117475. +#line 1588 "dtc-parser.tab.c" /* yacc.c:1646 */
  117476. break;
  117477. case 15:
  117478. -/* Line 1787 of yacc.c */
  117479. -#line 195 "dtc-parser.y"
  117480. +#line 197 "dtc-parser.y" /* yacc.c:1646 */
  117481. {
  117482. - (yyval.prop) = build_property((yyvsp[(1) - (2)].propnodename), empty_data);
  117483. + (yyval.proplist) = chain_property((yyvsp[0].prop), (yyvsp[-1].proplist));
  117484. }
  117485. +#line 1596 "dtc-parser.tab.c" /* yacc.c:1646 */
  117486. break;
  117487. case 16:
  117488. -/* Line 1787 of yacc.c */
  117489. -#line 199 "dtc-parser.y"
  117490. +#line 204 "dtc-parser.y" /* yacc.c:1646 */
  117491. {
  117492. - (yyval.prop) = build_property_delete((yyvsp[(2) - (3)].propnodename));
  117493. + (yyval.prop) = build_property((yyvsp[-3].propnodename), (yyvsp[-1].data));
  117494. }
  117495. +#line 1604 "dtc-parser.tab.c" /* yacc.c:1646 */
  117496. break;
  117497. case 17:
  117498. -/* Line 1787 of yacc.c */
  117499. -#line 203 "dtc-parser.y"
  117500. +#line 208 "dtc-parser.y" /* yacc.c:1646 */
  117501. {
  117502. - add_label(&(yyvsp[(2) - (2)].prop)->labels, (yyvsp[(1) - (2)].labelref));
  117503. - (yyval.prop) = (yyvsp[(2) - (2)].prop);
  117504. + (yyval.prop) = build_property((yyvsp[-1].propnodename), empty_data);
  117505. }
  117506. +#line 1612 "dtc-parser.tab.c" /* yacc.c:1646 */
  117507. break;
  117508. case 18:
  117509. -/* Line 1787 of yacc.c */
  117510. -#line 211 "dtc-parser.y"
  117511. +#line 212 "dtc-parser.y" /* yacc.c:1646 */
  117512. {
  117513. - (yyval.data) = data_merge((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].data));
  117514. + (yyval.prop) = build_property_delete((yyvsp[-1].propnodename));
  117515. }
  117516. +#line 1620 "dtc-parser.tab.c" /* yacc.c:1646 */
  117517. break;
  117518. case 19:
  117519. -/* Line 1787 of yacc.c */
  117520. -#line 215 "dtc-parser.y"
  117521. +#line 216 "dtc-parser.y" /* yacc.c:1646 */
  117522. {
  117523. - (yyval.data) = data_merge((yyvsp[(1) - (3)].data), (yyvsp[(2) - (3)].array).data);
  117524. + add_label(&(yyvsp[0].prop)->labels, (yyvsp[-1].labelref));
  117525. + (yyval.prop) = (yyvsp[0].prop);
  117526. }
  117527. +#line 1629 "dtc-parser.tab.c" /* yacc.c:1646 */
  117528. break;
  117529. case 20:
  117530. -/* Line 1787 of yacc.c */
  117531. -#line 219 "dtc-parser.y"
  117532. +#line 224 "dtc-parser.y" /* yacc.c:1646 */
  117533. {
  117534. - (yyval.data) = data_merge((yyvsp[(1) - (4)].data), (yyvsp[(3) - (4)].data));
  117535. + (yyval.data) = data_merge((yyvsp[-1].data), (yyvsp[0].data));
  117536. }
  117537. +#line 1637 "dtc-parser.tab.c" /* yacc.c:1646 */
  117538. break;
  117539. case 21:
  117540. -/* Line 1787 of yacc.c */
  117541. -#line 223 "dtc-parser.y"
  117542. +#line 228 "dtc-parser.y" /* yacc.c:1646 */
  117543. {
  117544. - (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), REF_PATH, (yyvsp[(2) - (2)].labelref));
  117545. + (yyval.data) = data_merge((yyvsp[-2].data), (yyvsp[-1].array).data);
  117546. }
  117547. +#line 1645 "dtc-parser.tab.c" /* yacc.c:1646 */
  117548. break;
  117549. case 22:
  117550. -/* Line 1787 of yacc.c */
  117551. -#line 227 "dtc-parser.y"
  117552. +#line 232 "dtc-parser.y" /* yacc.c:1646 */
  117553. {
  117554. - FILE *f = srcfile_relative_open((yyvsp[(4) - (9)].data).val, NULL);
  117555. + (yyval.data) = data_merge((yyvsp[-3].data), (yyvsp[-1].data));
  117556. + }
  117557. +#line 1653 "dtc-parser.tab.c" /* yacc.c:1646 */
  117558. + break;
  117559. +
  117560. + case 23:
  117561. +#line 236 "dtc-parser.y" /* yacc.c:1646 */
  117562. + {
  117563. + (yyval.data) = data_add_marker((yyvsp[-1].data), REF_PATH, (yyvsp[0].labelref));
  117564. + }
  117565. +#line 1661 "dtc-parser.tab.c" /* yacc.c:1646 */
  117566. + break;
  117567. +
  117568. + case 24:
  117569. +#line 240 "dtc-parser.y" /* yacc.c:1646 */
  117570. + {
  117571. + FILE *f = srcfile_relative_open((yyvsp[-5].data).val, NULL);
  117572. struct data d;
  117573. - if ((yyvsp[(6) - (9)].integer) != 0)
  117574. - if (fseek(f, (yyvsp[(6) - (9)].integer), SEEK_SET) != 0)
  117575. - print_error("Couldn't seek to offset %llu in \"%s\": %s",
  117576. - (unsigned long long)(yyvsp[(6) - (9)].integer),
  117577. - (yyvsp[(4) - (9)].data).val,
  117578. - strerror(errno));
  117579. + if ((yyvsp[-3].integer) != 0)
  117580. + if (fseek(f, (yyvsp[-3].integer), SEEK_SET) != 0)
  117581. + die("Couldn't seek to offset %llu in \"%s\": %s",
  117582. + (unsigned long long)(yyvsp[-3].integer), (yyvsp[-5].data).val,
  117583. + strerror(errno));
  117584. - d = data_copy_file(f, (yyvsp[(8) - (9)].integer));
  117585. + d = data_copy_file(f, (yyvsp[-1].integer));
  117586. - (yyval.data) = data_merge((yyvsp[(1) - (9)].data), d);
  117587. + (yyval.data) = data_merge((yyvsp[-8].data), d);
  117588. fclose(f);
  117589. }
  117590. +#line 1681 "dtc-parser.tab.c" /* yacc.c:1646 */
  117591. break;
  117592. - case 23:
  117593. -/* Line 1787 of yacc.c */
  117594. -#line 244 "dtc-parser.y"
  117595. + case 25:
  117596. +#line 256 "dtc-parser.y" /* yacc.c:1646 */
  117597. {
  117598. - FILE *f = srcfile_relative_open((yyvsp[(4) - (5)].data).val, NULL);
  117599. + FILE *f = srcfile_relative_open((yyvsp[-1].data).val, NULL);
  117600. struct data d = empty_data;
  117601. d = data_copy_file(f, -1);
  117602. - (yyval.data) = data_merge((yyvsp[(1) - (5)].data), d);
  117603. + (yyval.data) = data_merge((yyvsp[-4].data), d);
  117604. fclose(f);
  117605. }
  117606. +#line 1695 "dtc-parser.tab.c" /* yacc.c:1646 */
  117607. break;
  117608. - case 24:
  117609. -/* Line 1787 of yacc.c */
  117610. -#line 254 "dtc-parser.y"
  117611. + case 26:
  117612. +#line 266 "dtc-parser.y" /* yacc.c:1646 */
  117613. {
  117614. - (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref));
  117615. + (yyval.data) = data_add_marker((yyvsp[-1].data), LABEL, (yyvsp[0].labelref));
  117616. }
  117617. +#line 1703 "dtc-parser.tab.c" /* yacc.c:1646 */
  117618. break;
  117619. - case 25:
  117620. -/* Line 1787 of yacc.c */
  117621. -#line 261 "dtc-parser.y"
  117622. + case 27:
  117623. +#line 273 "dtc-parser.y" /* yacc.c:1646 */
  117624. {
  117625. (yyval.data) = empty_data;
  117626. }
  117627. +#line 1711 "dtc-parser.tab.c" /* yacc.c:1646 */
  117628. break;
  117629. - case 26:
  117630. -/* Line 1787 of yacc.c */
  117631. -#line 265 "dtc-parser.y"
  117632. + case 28:
  117633. +#line 277 "dtc-parser.y" /* yacc.c:1646 */
  117634. {
  117635. - (yyval.data) = (yyvsp[(1) - (2)].data);
  117636. + (yyval.data) = (yyvsp[-1].data);
  117637. }
  117638. +#line 1719 "dtc-parser.tab.c" /* yacc.c:1646 */
  117639. break;
  117640. - case 27:
  117641. -/* Line 1787 of yacc.c */
  117642. -#line 269 "dtc-parser.y"
  117643. + case 29:
  117644. +#line 281 "dtc-parser.y" /* yacc.c:1646 */
  117645. {
  117646. - (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref));
  117647. + (yyval.data) = data_add_marker((yyvsp[-1].data), LABEL, (yyvsp[0].labelref));
  117648. }
  117649. +#line 1727 "dtc-parser.tab.c" /* yacc.c:1646 */
  117650. break;
  117651. - case 28:
  117652. -/* Line 1787 of yacc.c */
  117653. -#line 276 "dtc-parser.y"
  117654. + case 30:
  117655. +#line 288 "dtc-parser.y" /* yacc.c:1646 */
  117656. {
  117657. - (yyval.array).data = empty_data;
  117658. - (yyval.array).bits = eval_literal((yyvsp[(2) - (3)].literal), 0, 7);
  117659. + unsigned long long bits;
  117660. - if (((yyval.array).bits != 8) &&
  117661. - ((yyval.array).bits != 16) &&
  117662. - ((yyval.array).bits != 32) &&
  117663. - ((yyval.array).bits != 64))
  117664. - {
  117665. - print_error("Only 8, 16, 32 and 64-bit elements"
  117666. - " are currently supported");
  117667. - (yyval.array).bits = 32;
  117668. + bits = (yyvsp[-1].integer);
  117669. +
  117670. + if ((bits != 8) && (bits != 16) &&
  117671. + (bits != 32) && (bits != 64)) {
  117672. + ERROR(&(yylsp[-1]), "Array elements must be"
  117673. + " 8, 16, 32 or 64-bits");
  117674. + bits = 32;
  117675. }
  117676. +
  117677. + (yyval.array).data = empty_data;
  117678. + (yyval.array).bits = bits;
  117679. }
  117680. +#line 1747 "dtc-parser.tab.c" /* yacc.c:1646 */
  117681. break;
  117682. - case 29:
  117683. -/* Line 1787 of yacc.c */
  117684. -#line 291 "dtc-parser.y"
  117685. + case 31:
  117686. +#line 304 "dtc-parser.y" /* yacc.c:1646 */
  117687. {
  117688. (yyval.array).data = empty_data;
  117689. (yyval.array).bits = 32;
  117690. }
  117691. +#line 1756 "dtc-parser.tab.c" /* yacc.c:1646 */
  117692. break;
  117693. - case 30:
  117694. -/* Line 1787 of yacc.c */
  117695. -#line 296 "dtc-parser.y"
  117696. + case 32:
  117697. +#line 309 "dtc-parser.y" /* yacc.c:1646 */
  117698. {
  117699. - if ((yyvsp[(1) - (2)].array).bits < 64) {
  117700. - uint64_t mask = (1ULL << (yyvsp[(1) - (2)].array).bits) - 1;
  117701. + if ((yyvsp[-1].array).bits < 64) {
  117702. + uint64_t mask = (1ULL << (yyvsp[-1].array).bits) - 1;
  117703. /*
  117704. * Bits above mask must either be all zero
  117705. * (positive within range of mask) or all one
  117706. @@ -1801,275 +1768,258 @@
  117707. * within the mask to one (i.e. | in the
  117708. * mask), all bits are one.
  117709. */
  117710. - if (((yyvsp[(2) - (2)].integer) > mask) && (((yyvsp[(2) - (2)].integer) | mask) != -1ULL))
  117711. - print_error(
  117712. - "integer value out of range "
  117713. - "%016lx (%d bits)", (yyvsp[(1) - (2)].array).bits);
  117714. + if (((yyvsp[0].integer) > mask) && (((yyvsp[0].integer) | mask) != -1ULL))
  117715. + ERROR(&(yylsp[0]), "Value out of range for"
  117716. + " %d-bit array element", (yyvsp[-1].array).bits);
  117717. }
  117718. - (yyval.array).data = data_append_integer((yyvsp[(1) - (2)].array).data, (yyvsp[(2) - (2)].integer), (yyvsp[(1) - (2)].array).bits);
  117719. + (yyval.array).data = data_append_integer((yyvsp[-1].array).data, (yyvsp[0].integer), (yyvsp[-1].array).bits);
  117720. }
  117721. +#line 1779 "dtc-parser.tab.c" /* yacc.c:1646 */
  117722. break;
  117723. - case 31:
  117724. -/* Line 1787 of yacc.c */
  117725. -#line 316 "dtc-parser.y"
  117726. + case 33:
  117727. +#line 328 "dtc-parser.y" /* yacc.c:1646 */
  117728. {
  117729. - uint64_t val = ~0ULL >> (64 - (yyvsp[(1) - (2)].array).bits);
  117730. + uint64_t val = ~0ULL >> (64 - (yyvsp[-1].array).bits);
  117731. - if ((yyvsp[(1) - (2)].array).bits == 32)
  117732. - (yyvsp[(1) - (2)].array).data = data_add_marker((yyvsp[(1) - (2)].array).data,
  117733. + if ((yyvsp[-1].array).bits == 32)
  117734. + (yyvsp[-1].array).data = data_add_marker((yyvsp[-1].array).data,
  117735. REF_PHANDLE,
  117736. - (yyvsp[(2) - (2)].labelref));
  117737. + (yyvsp[0].labelref));
  117738. else
  117739. - print_error("References are only allowed in "
  117740. + ERROR(&(yylsp[0]), "References are only allowed in "
  117741. "arrays with 32-bit elements.");
  117742. - (yyval.array).data = data_append_integer((yyvsp[(1) - (2)].array).data, val, (yyvsp[(1) - (2)].array).bits);
  117743. - }
  117744. - break;
  117745. -
  117746. - case 32:
  117747. -/* Line 1787 of yacc.c */
  117748. -#line 330 "dtc-parser.y"
  117749. - {
  117750. - (yyval.array).data = data_add_marker((yyvsp[(1) - (2)].array).data, LABEL, (yyvsp[(2) - (2)].labelref));
  117751. - }
  117752. - break;
  117753. -
  117754. - case 33:
  117755. -/* Line 1787 of yacc.c */
  117756. -#line 337 "dtc-parser.y"
  117757. - {
  117758. - (yyval.integer) = eval_literal((yyvsp[(1) - (1)].literal), 0, 64);
  117759. + (yyval.array).data = data_append_integer((yyvsp[-1].array).data, val, (yyvsp[-1].array).bits);
  117760. }
  117761. +#line 1797 "dtc-parser.tab.c" /* yacc.c:1646 */
  117762. break;
  117763. case 34:
  117764. -/* Line 1787 of yacc.c */
  117765. -#line 341 "dtc-parser.y"
  117766. +#line 342 "dtc-parser.y" /* yacc.c:1646 */
  117767. {
  117768. - (yyval.integer) = eval_char_literal((yyvsp[(1) - (1)].literal));
  117769. + (yyval.array).data = data_add_marker((yyvsp[-1].array).data, LABEL, (yyvsp[0].labelref));
  117770. }
  117771. +#line 1805 "dtc-parser.tab.c" /* yacc.c:1646 */
  117772. break;
  117773. - case 35:
  117774. -/* Line 1787 of yacc.c */
  117775. -#line 345 "dtc-parser.y"
  117776. + case 37:
  117777. +#line 351 "dtc-parser.y" /* yacc.c:1646 */
  117778. {
  117779. - (yyval.integer) = (yyvsp[(2) - (3)].integer);
  117780. + (yyval.integer) = (yyvsp[-1].integer);
  117781. }
  117782. - break;
  117783. -
  117784. - case 38:
  117785. -/* Line 1787 of yacc.c */
  117786. -#line 356 "dtc-parser.y"
  117787. - { (yyval.integer) = (yyvsp[(1) - (5)].integer) ? (yyvsp[(3) - (5)].integer) : (yyvsp[(5) - (5)].integer); }
  117788. +#line 1813 "dtc-parser.tab.c" /* yacc.c:1646 */
  117789. break;
  117790. case 40:
  117791. -/* Line 1787 of yacc.c */
  117792. -#line 361 "dtc-parser.y"
  117793. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) || (yyvsp[(3) - (3)].integer); }
  117794. +#line 362 "dtc-parser.y" /* yacc.c:1646 */
  117795. + { (yyval.integer) = (yyvsp[-4].integer) ? (yyvsp[-2].integer) : (yyvsp[0].integer); }
  117796. +#line 1819 "dtc-parser.tab.c" /* yacc.c:1646 */
  117797. break;
  117798. case 42:
  117799. -/* Line 1787 of yacc.c */
  117800. -#line 366 "dtc-parser.y"
  117801. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) && (yyvsp[(3) - (3)].integer); }
  117802. +#line 367 "dtc-parser.y" /* yacc.c:1646 */
  117803. + { (yyval.integer) = (yyvsp[-2].integer) || (yyvsp[0].integer); }
  117804. +#line 1825 "dtc-parser.tab.c" /* yacc.c:1646 */
  117805. break;
  117806. case 44:
  117807. -/* Line 1787 of yacc.c */
  117808. -#line 371 "dtc-parser.y"
  117809. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) | (yyvsp[(3) - (3)].integer); }
  117810. +#line 372 "dtc-parser.y" /* yacc.c:1646 */
  117811. + { (yyval.integer) = (yyvsp[-2].integer) && (yyvsp[0].integer); }
  117812. +#line 1831 "dtc-parser.tab.c" /* yacc.c:1646 */
  117813. break;
  117814. case 46:
  117815. -/* Line 1787 of yacc.c */
  117816. -#line 376 "dtc-parser.y"
  117817. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) ^ (yyvsp[(3) - (3)].integer); }
  117818. +#line 377 "dtc-parser.y" /* yacc.c:1646 */
  117819. + { (yyval.integer) = (yyvsp[-2].integer) | (yyvsp[0].integer); }
  117820. +#line 1837 "dtc-parser.tab.c" /* yacc.c:1646 */
  117821. break;
  117822. case 48:
  117823. -/* Line 1787 of yacc.c */
  117824. -#line 381 "dtc-parser.y"
  117825. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) & (yyvsp[(3) - (3)].integer); }
  117826. +#line 382 "dtc-parser.y" /* yacc.c:1646 */
  117827. + { (yyval.integer) = (yyvsp[-2].integer) ^ (yyvsp[0].integer); }
  117828. +#line 1843 "dtc-parser.tab.c" /* yacc.c:1646 */
  117829. break;
  117830. case 50:
  117831. -/* Line 1787 of yacc.c */
  117832. -#line 386 "dtc-parser.y"
  117833. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) == (yyvsp[(3) - (3)].integer); }
  117834. +#line 387 "dtc-parser.y" /* yacc.c:1646 */
  117835. + { (yyval.integer) = (yyvsp[-2].integer) & (yyvsp[0].integer); }
  117836. +#line 1849 "dtc-parser.tab.c" /* yacc.c:1646 */
  117837. break;
  117838. - case 51:
  117839. -/* Line 1787 of yacc.c */
  117840. -#line 387 "dtc-parser.y"
  117841. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) != (yyvsp[(3) - (3)].integer); }
  117842. + case 52:
  117843. +#line 392 "dtc-parser.y" /* yacc.c:1646 */
  117844. + { (yyval.integer) = (yyvsp[-2].integer) == (yyvsp[0].integer); }
  117845. +#line 1855 "dtc-parser.tab.c" /* yacc.c:1646 */
  117846. break;
  117847. case 53:
  117848. -/* Line 1787 of yacc.c */
  117849. -#line 392 "dtc-parser.y"
  117850. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) < (yyvsp[(3) - (3)].integer); }
  117851. - break;
  117852. -
  117853. - case 54:
  117854. -/* Line 1787 of yacc.c */
  117855. -#line 393 "dtc-parser.y"
  117856. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) > (yyvsp[(3) - (3)].integer); }
  117857. +#line 393 "dtc-parser.y" /* yacc.c:1646 */
  117858. + { (yyval.integer) = (yyvsp[-2].integer) != (yyvsp[0].integer); }
  117859. +#line 1861 "dtc-parser.tab.c" /* yacc.c:1646 */
  117860. break;
  117861. case 55:
  117862. -/* Line 1787 of yacc.c */
  117863. -#line 394 "dtc-parser.y"
  117864. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) <= (yyvsp[(3) - (3)].integer); }
  117865. +#line 398 "dtc-parser.y" /* yacc.c:1646 */
  117866. + { (yyval.integer) = (yyvsp[-2].integer) < (yyvsp[0].integer); }
  117867. +#line 1867 "dtc-parser.tab.c" /* yacc.c:1646 */
  117868. break;
  117869. case 56:
  117870. -/* Line 1787 of yacc.c */
  117871. -#line 395 "dtc-parser.y"
  117872. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) >= (yyvsp[(3) - (3)].integer); }
  117873. +#line 399 "dtc-parser.y" /* yacc.c:1646 */
  117874. + { (yyval.integer) = (yyvsp[-2].integer) > (yyvsp[0].integer); }
  117875. +#line 1873 "dtc-parser.tab.c" /* yacc.c:1646 */
  117876. break;
  117877. case 57:
  117878. -/* Line 1787 of yacc.c */
  117879. -#line 399 "dtc-parser.y"
  117880. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) << (yyvsp[(3) - (3)].integer); }
  117881. +#line 400 "dtc-parser.y" /* yacc.c:1646 */
  117882. + { (yyval.integer) = (yyvsp[-2].integer) <= (yyvsp[0].integer); }
  117883. +#line 1879 "dtc-parser.tab.c" /* yacc.c:1646 */
  117884. break;
  117885. case 58:
  117886. -/* Line 1787 of yacc.c */
  117887. -#line 400 "dtc-parser.y"
  117888. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) >> (yyvsp[(3) - (3)].integer); }
  117889. +#line 401 "dtc-parser.y" /* yacc.c:1646 */
  117890. + { (yyval.integer) = (yyvsp[-2].integer) >= (yyvsp[0].integer); }
  117891. +#line 1885 "dtc-parser.tab.c" /* yacc.c:1646 */
  117892. break;
  117893. - case 60:
  117894. -/* Line 1787 of yacc.c */
  117895. -#line 405 "dtc-parser.y"
  117896. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) + (yyvsp[(3) - (3)].integer); }
  117897. + case 59:
  117898. +#line 405 "dtc-parser.y" /* yacc.c:1646 */
  117899. + { (yyval.integer) = (yyvsp[-2].integer) << (yyvsp[0].integer); }
  117900. +#line 1891 "dtc-parser.tab.c" /* yacc.c:1646 */
  117901. break;
  117902. - case 61:
  117903. -/* Line 1787 of yacc.c */
  117904. -#line 406 "dtc-parser.y"
  117905. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) - (yyvsp[(3) - (3)].integer); }
  117906. + case 60:
  117907. +#line 406 "dtc-parser.y" /* yacc.c:1646 */
  117908. + { (yyval.integer) = (yyvsp[-2].integer) >> (yyvsp[0].integer); }
  117909. +#line 1897 "dtc-parser.tab.c" /* yacc.c:1646 */
  117910. break;
  117911. - case 63:
  117912. -/* Line 1787 of yacc.c */
  117913. -#line 411 "dtc-parser.y"
  117914. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) * (yyvsp[(3) - (3)].integer); }
  117915. + case 62:
  117916. +#line 411 "dtc-parser.y" /* yacc.c:1646 */
  117917. + { (yyval.integer) = (yyvsp[-2].integer) + (yyvsp[0].integer); }
  117918. +#line 1903 "dtc-parser.tab.c" /* yacc.c:1646 */
  117919. break;
  117920. - case 64:
  117921. -/* Line 1787 of yacc.c */
  117922. -#line 412 "dtc-parser.y"
  117923. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) / (yyvsp[(3) - (3)].integer); }
  117924. + case 63:
  117925. +#line 412 "dtc-parser.y" /* yacc.c:1646 */
  117926. + { (yyval.integer) = (yyvsp[-2].integer) - (yyvsp[0].integer); }
  117927. +#line 1909 "dtc-parser.tab.c" /* yacc.c:1646 */
  117928. break;
  117929. case 65:
  117930. -/* Line 1787 of yacc.c */
  117931. -#line 413 "dtc-parser.y"
  117932. - { (yyval.integer) = (yyvsp[(1) - (3)].integer) % (yyvsp[(3) - (3)].integer); }
  117933. +#line 417 "dtc-parser.y" /* yacc.c:1646 */
  117934. + { (yyval.integer) = (yyvsp[-2].integer) * (yyvsp[0].integer); }
  117935. +#line 1915 "dtc-parser.tab.c" /* yacc.c:1646 */
  117936. break;
  117937. - case 68:
  117938. -/* Line 1787 of yacc.c */
  117939. -#line 419 "dtc-parser.y"
  117940. - { (yyval.integer) = -(yyvsp[(2) - (2)].integer); }
  117941. + case 66:
  117942. +#line 418 "dtc-parser.y" /* yacc.c:1646 */
  117943. + { (yyval.integer) = (yyvsp[-2].integer) / (yyvsp[0].integer); }
  117944. +#line 1921 "dtc-parser.tab.c" /* yacc.c:1646 */
  117945. break;
  117946. - case 69:
  117947. -/* Line 1787 of yacc.c */
  117948. -#line 420 "dtc-parser.y"
  117949. - { (yyval.integer) = ~(yyvsp[(2) - (2)].integer); }
  117950. + case 67:
  117951. +#line 419 "dtc-parser.y" /* yacc.c:1646 */
  117952. + { (yyval.integer) = (yyvsp[-2].integer) % (yyvsp[0].integer); }
  117953. +#line 1927 "dtc-parser.tab.c" /* yacc.c:1646 */
  117954. break;
  117955. case 70:
  117956. -/* Line 1787 of yacc.c */
  117957. -#line 421 "dtc-parser.y"
  117958. - { (yyval.integer) = !(yyvsp[(2) - (2)].integer); }
  117959. +#line 425 "dtc-parser.y" /* yacc.c:1646 */
  117960. + { (yyval.integer) = -(yyvsp[0].integer); }
  117961. +#line 1933 "dtc-parser.tab.c" /* yacc.c:1646 */
  117962. break;
  117963. case 71:
  117964. -/* Line 1787 of yacc.c */
  117965. -#line 426 "dtc-parser.y"
  117966. - {
  117967. - (yyval.data) = empty_data;
  117968. - }
  117969. +#line 426 "dtc-parser.y" /* yacc.c:1646 */
  117970. + { (yyval.integer) = ~(yyvsp[0].integer); }
  117971. +#line 1939 "dtc-parser.tab.c" /* yacc.c:1646 */
  117972. break;
  117973. case 72:
  117974. -/* Line 1787 of yacc.c */
  117975. -#line 430 "dtc-parser.y"
  117976. - {
  117977. - (yyval.data) = data_append_byte((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].byte));
  117978. - }
  117979. +#line 427 "dtc-parser.y" /* yacc.c:1646 */
  117980. + { (yyval.integer) = !(yyvsp[0].integer); }
  117981. +#line 1945 "dtc-parser.tab.c" /* yacc.c:1646 */
  117982. break;
  117983. case 73:
  117984. -/* Line 1787 of yacc.c */
  117985. -#line 434 "dtc-parser.y"
  117986. +#line 432 "dtc-parser.y" /* yacc.c:1646 */
  117987. {
  117988. - (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref));
  117989. + (yyval.data) = empty_data;
  117990. }
  117991. +#line 1953 "dtc-parser.tab.c" /* yacc.c:1646 */
  117992. break;
  117993. case 74:
  117994. -/* Line 1787 of yacc.c */
  117995. -#line 441 "dtc-parser.y"
  117996. +#line 436 "dtc-parser.y" /* yacc.c:1646 */
  117997. {
  117998. - (yyval.nodelist) = NULL;
  117999. + (yyval.data) = data_append_byte((yyvsp[-1].data), (yyvsp[0].byte));
  118000. }
  118001. +#line 1961 "dtc-parser.tab.c" /* yacc.c:1646 */
  118002. break;
  118003. case 75:
  118004. -/* Line 1787 of yacc.c */
  118005. -#line 445 "dtc-parser.y"
  118006. +#line 440 "dtc-parser.y" /* yacc.c:1646 */
  118007. {
  118008. - (yyval.nodelist) = chain_node((yyvsp[(1) - (2)].node), (yyvsp[(2) - (2)].nodelist));
  118009. + (yyval.data) = data_add_marker((yyvsp[-1].data), LABEL, (yyvsp[0].labelref));
  118010. }
  118011. +#line 1969 "dtc-parser.tab.c" /* yacc.c:1646 */
  118012. break;
  118013. case 76:
  118014. -/* Line 1787 of yacc.c */
  118015. -#line 449 "dtc-parser.y"
  118016. +#line 447 "dtc-parser.y" /* yacc.c:1646 */
  118017. {
  118018. - print_error("syntax error: properties must precede subnodes");
  118019. - YYERROR;
  118020. + (yyval.nodelist) = NULL;
  118021. }
  118022. +#line 1977 "dtc-parser.tab.c" /* yacc.c:1646 */
  118023. break;
  118024. case 77:
  118025. -/* Line 1787 of yacc.c */
  118026. -#line 457 "dtc-parser.y"
  118027. +#line 451 "dtc-parser.y" /* yacc.c:1646 */
  118028. {
  118029. - (yyval.node) = name_node((yyvsp[(2) - (2)].node), (yyvsp[(1) - (2)].propnodename));
  118030. + (yyval.nodelist) = chain_node((yyvsp[-1].node), (yyvsp[0].nodelist));
  118031. }
  118032. +#line 1985 "dtc-parser.tab.c" /* yacc.c:1646 */
  118033. break;
  118034. case 78:
  118035. -/* Line 1787 of yacc.c */
  118036. -#line 461 "dtc-parser.y"
  118037. +#line 455 "dtc-parser.y" /* yacc.c:1646 */
  118038. {
  118039. - (yyval.node) = name_node(build_node_delete(), (yyvsp[(2) - (3)].propnodename));
  118040. + ERROR(&(yylsp[0]), "Properties must precede subnodes");
  118041. + YYERROR;
  118042. }
  118043. +#line 1994 "dtc-parser.tab.c" /* yacc.c:1646 */
  118044. break;
  118045. case 79:
  118046. -/* Line 1787 of yacc.c */
  118047. -#line 465 "dtc-parser.y"
  118048. +#line 463 "dtc-parser.y" /* yacc.c:1646 */
  118049. {
  118050. - add_label(&(yyvsp[(2) - (2)].node)->labels, (yyvsp[(1) - (2)].labelref));
  118051. - (yyval.node) = (yyvsp[(2) - (2)].node);
  118052. + (yyval.node) = name_node((yyvsp[0].node), (yyvsp[-1].propnodename));
  118053. }
  118054. +#line 2002 "dtc-parser.tab.c" /* yacc.c:1646 */
  118055. break;
  118056. + case 80:
  118057. +#line 467 "dtc-parser.y" /* yacc.c:1646 */
  118058. + {
  118059. + (yyval.node) = name_node(build_node_delete(), (yyvsp[-1].propnodename));
  118060. + }
  118061. +#line 2010 "dtc-parser.tab.c" /* yacc.c:1646 */
  118062. + break;
  118063. +
  118064. + case 81:
  118065. +#line 471 "dtc-parser.y" /* yacc.c:1646 */
  118066. + {
  118067. + add_label(&(yyvsp[0].node)->labels, (yyvsp[-1].labelref));
  118068. + (yyval.node) = (yyvsp[0].node);
  118069. + }
  118070. +#line 2019 "dtc-parser.tab.c" /* yacc.c:1646 */
  118071. + break;
  118072. -/* Line 1787 of yacc.c */
  118073. -#line 2073 "dtc-parser.tab.c"
  118074. +
  118075. +#line 2023 "dtc-parser.tab.c" /* yacc.c:1646 */
  118076. default: break;
  118077. }
  118078. /* User semantic actions sometimes alter yychar, and that requires
  118079. @@ -2090,8 +2040,9 @@
  118080. YY_STACK_PRINT (yyss, yyssp);
  118081. *++yyvsp = yyval;
  118082. + *++yylsp = yyloc;
  118083. - /* Now `shift' the result of the reduction. Determine what state
  118084. + /* Now 'shift' the result of the reduction. Determine what state
  118085. that goes to, based on the state we popped back to and the rule
  118086. number reduced by. */
  118087. @@ -2106,9 +2057,9 @@
  118088. goto yynewstate;
  118089. -/*------------------------------------.
  118090. -| yyerrlab -- here on detecting error |
  118091. -`------------------------------------*/
  118092. +/*--------------------------------------.
  118093. +| yyerrlab -- here on detecting error. |
  118094. +`--------------------------------------*/
  118095. yyerrlab:
  118096. /* Make sure we have latest lookahead translation. See comments at
  118097. user semantic actions for why this is necessary. */
  118098. @@ -2154,25 +2105,25 @@
  118099. #endif
  118100. }
  118101. -
  118102. + yyerror_range[1] = yylloc;
  118103. if (yyerrstatus == 3)
  118104. {
  118105. /* If just tried and failed to reuse lookahead token after an
  118106. - error, discard it. */
  118107. + error, discard it. */
  118108. if (yychar <= YYEOF)
  118109. - {
  118110. - /* Return failure if at end of input. */
  118111. - if (yychar == YYEOF)
  118112. - YYABORT;
  118113. - }
  118114. + {
  118115. + /* Return failure if at end of input. */
  118116. + if (yychar == YYEOF)
  118117. + YYABORT;
  118118. + }
  118119. else
  118120. - {
  118121. - yydestruct ("Error: discarding",
  118122. - yytoken, &yylval);
  118123. - yychar = YYEMPTY;
  118124. - }
  118125. + {
  118126. + yydestruct ("Error: discarding",
  118127. + yytoken, &yylval, &yylloc);
  118128. + yychar = YYEMPTY;
  118129. + }
  118130. }
  118131. /* Else will try to reuse lookahead token after shifting the error
  118132. @@ -2191,7 +2142,8 @@
  118133. if (/*CONSTCOND*/ 0)
  118134. goto yyerrorlab;
  118135. - /* Do not reclaim the symbols of the rule which action triggered
  118136. + yyerror_range[1] = yylsp[1-yylen];
  118137. + /* Do not reclaim the symbols of the rule whose action triggered
  118138. this YYERROR. */
  118139. YYPOPSTACK (yylen);
  118140. yylen = 0;
  118141. @@ -2204,29 +2156,29 @@
  118142. | yyerrlab1 -- common code for both syntax error and YYERROR. |
  118143. `-------------------------------------------------------------*/
  118144. yyerrlab1:
  118145. - yyerrstatus = 3; /* Each real token shifted decrements this. */
  118146. + yyerrstatus = 3; /* Each real token shifted decrements this. */
  118147. for (;;)
  118148. {
  118149. yyn = yypact[yystate];
  118150. if (!yypact_value_is_default (yyn))
  118151. - {
  118152. - yyn += YYTERROR;
  118153. - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
  118154. - {
  118155. - yyn = yytable[yyn];
  118156. - if (0 < yyn)
  118157. - break;
  118158. - }
  118159. - }
  118160. + {
  118161. + yyn += YYTERROR;
  118162. + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
  118163. + {
  118164. + yyn = yytable[yyn];
  118165. + if (0 < yyn)
  118166. + break;
  118167. + }
  118168. + }
  118169. /* Pop the current state because it cannot handle the error token. */
  118170. if (yyssp == yyss)
  118171. - YYABORT;
  118172. -
  118173. + YYABORT;
  118174. + yyerror_range[1] = *yylsp;
  118175. yydestruct ("Error: popping",
  118176. - yystos[yystate], yyvsp);
  118177. + yystos[yystate], yyvsp, yylsp);
  118178. YYPOPSTACK (1);
  118179. yystate = *yyssp;
  118180. YY_STACK_PRINT (yyss, yyssp);
  118181. @@ -2236,6 +2188,11 @@
  118182. *++yyvsp = yylval;
  118183. YY_IGNORE_MAYBE_UNINITIALIZED_END
  118184. + yyerror_range[2] = yylloc;
  118185. + /* Using YYLLOC is tempting, but would change the location of
  118186. + the lookahead. YYLOC is available though. */
  118187. + YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
  118188. + *++yylsp = yyloc;
  118189. /* Shift the error token. */
  118190. YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
  118191. @@ -2275,16 +2232,16 @@
  118192. user semantic actions for why this is necessary. */
  118193. yytoken = YYTRANSLATE (yychar);
  118194. yydestruct ("Cleanup: discarding lookahead",
  118195. - yytoken, &yylval);
  118196. + yytoken, &yylval, &yylloc);
  118197. }
  118198. - /* Do not reclaim the symbols of the rule which action triggered
  118199. + /* Do not reclaim the symbols of the rule whose action triggered
  118200. this YYABORT or YYACCEPT. */
  118201. YYPOPSTACK (yylen);
  118202. YY_STACK_PRINT (yyss, yyssp);
  118203. while (yyssp != yyss)
  118204. {
  118205. yydestruct ("Cleanup: popping",
  118206. - yystos[*yyssp], yyvsp);
  118207. + yystos[*yyssp], yyvsp, yylsp);
  118208. YYPOPSTACK (1);
  118209. }
  118210. #ifndef yyoverflow
  118211. @@ -2295,72 +2252,12 @@
  118212. if (yymsg != yymsgbuf)
  118213. YYSTACK_FREE (yymsg);
  118214. #endif
  118215. - /* Make sure YYID is used. */
  118216. - return YYID (yyresult);
  118217. + return yyresult;
  118218. }
  118219. +#line 477 "dtc-parser.y" /* yacc.c:1906 */
  118220. -/* Line 2050 of yacc.c */
  118221. -#line 471 "dtc-parser.y"
  118222. -
  118223. -
  118224. -void print_error(char const *fmt, ...)
  118225. +void yyerror(char const *s)
  118226. {
  118227. - va_list va;
  118228. -
  118229. - va_start(va, fmt);
  118230. - srcpos_verror(&yylloc, fmt, va);
  118231. - va_end(va);
  118232. -
  118233. - treesource_error = 1;
  118234. -}
  118235. -
  118236. -void yyerror(char const *s) {
  118237. - print_error("%s", s);
  118238. -}
  118239. -
  118240. -static unsigned long long eval_literal(const char *s, int base, int bits)
  118241. -{
  118242. - unsigned long long val;
  118243. - char *e;
  118244. -
  118245. - errno = 0;
  118246. - val = strtoull(s, &e, base);
  118247. - if (*e) {
  118248. - size_t uls = strspn(e, "UL");
  118249. - if (e[uls])
  118250. - print_error("bad characters in literal");
  118251. - }
  118252. - if ((errno == ERANGE)
  118253. - || ((bits < 64) && (val >= (1ULL << bits))))
  118254. - print_error("literal out of range");
  118255. - else if (errno != 0)
  118256. - print_error("bad literal");
  118257. - return val;
  118258. -}
  118259. -
  118260. -static unsigned char eval_char_literal(const char *s)
  118261. -{
  118262. - int i = 1;
  118263. - char c = s[0];
  118264. -
  118265. - if (c == '\0')
  118266. - {
  118267. - print_error("empty character literal");
  118268. - return 0;
  118269. - }
  118270. -
  118271. - /*
  118272. - * If the first character in the character literal is a \ then process
  118273. - * the remaining characters as an escape encoding. If the first
  118274. - * character is neither an escape or a terminator it should be the only
  118275. - * character in the literal and will be returned.
  118276. - */
  118277. - if (c == '\\')
  118278. - c = get_escape_char(s, &i);
  118279. -
  118280. - if (s[i] != '\0')
  118281. - print_error("malformed character literal");
  118282. -
  118283. - return c;
  118284. + ERROR(&yylloc, "%s", s);
  118285. }
  118286. diff -Nur linux-3.18.6/scripts/dtc/dtc-parser.tab.h_shipped linux-rpi/scripts/dtc/dtc-parser.tab.h_shipped
  118287. --- linux-3.18.6/scripts/dtc/dtc-parser.tab.h_shipped 2015-02-06 15:53:48.000000000 +0100
  118288. +++ linux-rpi/scripts/dtc/dtc-parser.tab.h_shipped 2015-02-09 04:40:47.000000000 +0100
  118289. @@ -1,19 +1,19 @@
  118290. -/* A Bison parser, made by GNU Bison 2.7.12-4996. */
  118291. +/* A Bison parser, made by GNU Bison 3.0.2. */
  118292. /* Bison interface for Yacc-like parsers in C
  118293. -
  118294. - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
  118295. -
  118296. +
  118297. + Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
  118298. +
  118299. This program is free software: you can redistribute it and/or modify
  118300. it under the terms of the GNU General Public License as published by
  118301. the Free Software Foundation, either version 3 of the License, or
  118302. (at your option) any later version.
  118303. -
  118304. +
  118305. This program is distributed in the hope that it will be useful,
  118306. but WITHOUT ANY WARRANTY; without even the implied warranty of
  118307. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  118308. GNU General Public License for more details.
  118309. -
  118310. +
  118311. You should have received a copy of the GNU General Public License
  118312. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  118313. @@ -26,13 +26,13 @@
  118314. special exception, which will cause the skeleton and the resulting
  118315. Bison output files to be licensed under the GNU General Public
  118316. License without this special exception.
  118317. -
  118318. +
  118319. This special exception was added by the Free Software Foundation in
  118320. version 2.2 of Bison. */
  118321. #ifndef YY_YY_DTC_PARSER_TAB_H_INCLUDED
  118322. # define YY_YY_DTC_PARSER_TAB_H_INCLUDED
  118323. -/* Enabling traces. */
  118324. +/* Debug traces. */
  118325. #ifndef YYDEBUG
  118326. # define YYDEBUG 0
  118327. #endif
  118328. @@ -40,48 +40,45 @@
  118329. extern int yydebug;
  118330. #endif
  118331. -/* Tokens. */
  118332. +/* Token type. */
  118333. #ifndef YYTOKENTYPE
  118334. # define YYTOKENTYPE
  118335. - /* Put the tokens into the symbol table, so that GDB and other debuggers
  118336. - know about them. */
  118337. - enum yytokentype {
  118338. - DT_V1 = 258,
  118339. - DT_MEMRESERVE = 259,
  118340. - DT_LSHIFT = 260,
  118341. - DT_RSHIFT = 261,
  118342. - DT_LE = 262,
  118343. - DT_GE = 263,
  118344. - DT_EQ = 264,
  118345. - DT_NE = 265,
  118346. - DT_AND = 266,
  118347. - DT_OR = 267,
  118348. - DT_BITS = 268,
  118349. - DT_DEL_PROP = 269,
  118350. - DT_DEL_NODE = 270,
  118351. - DT_PROPNODENAME = 271,
  118352. - DT_LITERAL = 272,
  118353. - DT_CHAR_LITERAL = 273,
  118354. - DT_BASE = 274,
  118355. - DT_BYTE = 275,
  118356. - DT_STRING = 276,
  118357. - DT_LABEL = 277,
  118358. - DT_REF = 278,
  118359. - DT_INCBIN = 279
  118360. - };
  118361. + enum yytokentype
  118362. + {
  118363. + DT_V1 = 258,
  118364. + DT_PLUGIN = 259,
  118365. + DT_MEMRESERVE = 260,
  118366. + DT_LSHIFT = 261,
  118367. + DT_RSHIFT = 262,
  118368. + DT_LE = 263,
  118369. + DT_GE = 264,
  118370. + DT_EQ = 265,
  118371. + DT_NE = 266,
  118372. + DT_AND = 267,
  118373. + DT_OR = 268,
  118374. + DT_BITS = 269,
  118375. + DT_DEL_PROP = 270,
  118376. + DT_DEL_NODE = 271,
  118377. + DT_PROPNODENAME = 272,
  118378. + DT_LITERAL = 273,
  118379. + DT_CHAR_LITERAL = 274,
  118380. + DT_BYTE = 275,
  118381. + DT_STRING = 276,
  118382. + DT_LABEL = 277,
  118383. + DT_REF = 278,
  118384. + DT_INCBIN = 279
  118385. + };
  118386. #endif
  118387. -
  118388. +/* Value type. */
  118389. #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
  118390. -typedef union YYSTYPE
  118391. +typedef union YYSTYPE YYSTYPE;
  118392. +union YYSTYPE
  118393. {
  118394. -/* Line 2053 of yacc.c */
  118395. -#line 40 "dtc-parser.y"
  118396. +#line 39 "dtc-parser.y" /* yacc.c:1909 */
  118397. char *propnodename;
  118398. - char *literal;
  118399. char *labelref;
  118400. - unsigned int cbase;
  118401. uint8_t byte;
  118402. struct data data;
  118403. @@ -96,30 +93,31 @@
  118404. struct node *nodelist;
  118405. struct reserve_info *re;
  118406. uint64_t integer;
  118407. + int is_plugin;
  118408. -
  118409. -/* Line 2053 of yacc.c */
  118410. -#line 103 "dtc-parser.tab.h"
  118411. -} YYSTYPE;
  118412. +#line 99 "dtc-parser.tab.h" /* yacc.c:1909 */
  118413. +};
  118414. # define YYSTYPE_IS_TRIVIAL 1
  118415. -# define yystype YYSTYPE /* obsolescent; will be withdrawn */
  118416. # define YYSTYPE_IS_DECLARED 1
  118417. #endif
  118418. -extern YYSTYPE yylval;
  118419. -
  118420. -#ifdef YYPARSE_PARAM
  118421. -#if defined __STDC__ || defined __cplusplus
  118422. -int yyparse (void *YYPARSE_PARAM);
  118423. -#else
  118424. -int yyparse ();
  118425. +/* Location type. */
  118426. +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
  118427. +typedef struct YYLTYPE YYLTYPE;
  118428. +struct YYLTYPE
  118429. +{
  118430. + int first_line;
  118431. + int first_column;
  118432. + int last_line;
  118433. + int last_column;
  118434. +};
  118435. +# define YYLTYPE_IS_DECLARED 1
  118436. +# define YYLTYPE_IS_TRIVIAL 1
  118437. #endif
  118438. -#else /* ! YYPARSE_PARAM */
  118439. -#if defined __STDC__ || defined __cplusplus
  118440. +
  118441. +
  118442. +extern YYSTYPE yylval;
  118443. +extern YYLTYPE yylloc;
  118444. int yyparse (void);
  118445. -#else
  118446. -int yyparse ();
  118447. -#endif
  118448. -#endif /* ! YYPARSE_PARAM */
  118449. #endif /* !YY_YY_DTC_PARSER_TAB_H_INCLUDED */
  118450. diff -Nur linux-3.18.6/scripts/dtc/dtc-parser.y linux-rpi/scripts/dtc/dtc-parser.y
  118451. --- linux-3.18.6/scripts/dtc/dtc-parser.y 2015-02-06 15:53:48.000000000 +0100
  118452. +++ linux-rpi/scripts/dtc/dtc-parser.y 2015-02-09 04:40:47.000000000 +0100
  118453. @@ -17,31 +17,28 @@
  118454. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  118455. * USA
  118456. */
  118457. -
  118458. %{
  118459. #include <stdio.h>
  118460. +#include <inttypes.h>
  118461. #include "dtc.h"
  118462. #include "srcpos.h"
  118463. -YYLTYPE yylloc;
  118464. -
  118465. extern int yylex(void);
  118466. -extern void print_error(char const *fmt, ...);
  118467. extern void yyerror(char const *s);
  118468. +#define ERROR(loc, ...) \
  118469. + do { \
  118470. + srcpos_error((loc), "Error", __VA_ARGS__); \
  118471. + treesource_error = true; \
  118472. + } while (0)
  118473. extern struct boot_info *the_boot_info;
  118474. -extern int treesource_error;
  118475. -
  118476. -static unsigned long long eval_literal(const char *s, int base, int bits);
  118477. -static unsigned char eval_char_literal(const char *s);
  118478. +extern bool treesource_error;
  118479. %}
  118480. %union {
  118481. char *propnodename;
  118482. - char *literal;
  118483. char *labelref;
  118484. - unsigned int cbase;
  118485. uint8_t byte;
  118486. struct data data;
  118487. @@ -56,18 +53,19 @@
  118488. struct node *nodelist;
  118489. struct reserve_info *re;
  118490. uint64_t integer;
  118491. + int is_plugin;
  118492. }
  118493. %token DT_V1
  118494. +%token DT_PLUGIN
  118495. %token DT_MEMRESERVE
  118496. %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR
  118497. %token DT_BITS
  118498. %token DT_DEL_PROP
  118499. %token DT_DEL_NODE
  118500. %token <propnodename> DT_PROPNODENAME
  118501. -%token <literal> DT_LITERAL
  118502. -%token <literal> DT_CHAR_LITERAL
  118503. -%token <cbase> DT_BASE
  118504. +%token <integer> DT_LITERAL
  118505. +%token <integer> DT_CHAR_LITERAL
  118506. %token <byte> DT_BYTE
  118507. %token <data> DT_STRING
  118508. %token <labelref> DT_LABEL
  118509. @@ -76,6 +74,7 @@
  118510. %type <data> propdata
  118511. %type <data> propdataprefix
  118512. +%type <is_plugin> plugindecl
  118513. %type <re> memreserve
  118514. %type <re> memreserves
  118515. %type <array> arrayprefix
  118516. @@ -106,10 +105,23 @@
  118517. %%
  118518. sourcefile:
  118519. - DT_V1 ';' memreserves devicetree
  118520. + DT_V1 ';' plugindecl memreserves devicetree
  118521. + {
  118522. + $5->is_plugin = $3;
  118523. + $5->is_root = 1;
  118524. + the_boot_info = build_boot_info($4, $5,
  118525. + guess_boot_cpuid($5));
  118526. + }
  118527. + ;
  118528. +
  118529. +plugindecl:
  118530. + /* empty */
  118531. + {
  118532. + $$ = 0;
  118533. + }
  118534. + | DT_PLUGIN ';'
  118535. {
  118536. - the_boot_info = build_boot_info($3, $4,
  118537. - guess_boot_cpuid($4));
  118538. + $$ = 1;
  118539. }
  118540. ;
  118541. @@ -152,17 +164,18 @@
  118542. if (target)
  118543. merge_nodes(target, $3);
  118544. else
  118545. - print_error("label or path, '%s', not found", $2);
  118546. + ERROR(&@2, "Label or path %s not found", $2);
  118547. $$ = $1;
  118548. }
  118549. | devicetree DT_DEL_NODE DT_REF ';'
  118550. {
  118551. struct node *target = get_node_by_ref($1, $3);
  118552. - if (!target)
  118553. - print_error("label or path, '%s', not found", $3);
  118554. - else
  118555. + if (target)
  118556. delete_node(target);
  118557. + else
  118558. + ERROR(&@3, "Label or path %s not found", $3);
  118559. +
  118560. $$ = $1;
  118561. }
  118562. @@ -230,10 +243,9 @@
  118563. if ($6 != 0)
  118564. if (fseek(f, $6, SEEK_SET) != 0)
  118565. - print_error("Couldn't seek to offset %llu in \"%s\": %s",
  118566. - (unsigned long long)$6,
  118567. - $4.val,
  118568. - strerror(errno));
  118569. + die("Couldn't seek to offset %llu in \"%s\": %s",
  118570. + (unsigned long long)$6, $4.val,
  118571. + strerror(errno));
  118572. d = data_copy_file(f, $8);
  118573. @@ -274,18 +286,19 @@
  118574. arrayprefix:
  118575. DT_BITS DT_LITERAL '<'
  118576. {
  118577. - $$.data = empty_data;
  118578. - $$.bits = eval_literal($2, 0, 7);
  118579. + unsigned long long bits;
  118580. - if (($$.bits != 8) &&
  118581. - ($$.bits != 16) &&
  118582. - ($$.bits != 32) &&
  118583. - ($$.bits != 64))
  118584. - {
  118585. - print_error("Only 8, 16, 32 and 64-bit elements"
  118586. - " are currently supported");
  118587. - $$.bits = 32;
  118588. + bits = $2;
  118589. +
  118590. + if ((bits != 8) && (bits != 16) &&
  118591. + (bits != 32) && (bits != 64)) {
  118592. + ERROR(&@2, "Array elements must be"
  118593. + " 8, 16, 32 or 64-bits");
  118594. + bits = 32;
  118595. }
  118596. +
  118597. + $$.data = empty_data;
  118598. + $$.bits = bits;
  118599. }
  118600. | '<'
  118601. {
  118602. @@ -305,9 +318,8 @@
  118603. * mask), all bits are one.
  118604. */
  118605. if (($2 > mask) && (($2 | mask) != -1ULL))
  118606. - print_error(
  118607. - "integer value out of range "
  118608. - "%016lx (%d bits)", $1.bits);
  118609. + ERROR(&@2, "Value out of range for"
  118610. + " %d-bit array element", $1.bits);
  118611. }
  118612. $$.data = data_append_integer($1.data, $2, $1.bits);
  118613. @@ -321,7 +333,7 @@
  118614. REF_PHANDLE,
  118615. $2);
  118616. else
  118617. - print_error("References are only allowed in "
  118618. + ERROR(&@2, "References are only allowed in "
  118619. "arrays with 32-bit elements.");
  118620. $$.data = data_append_integer($1.data, val, $1.bits);
  118621. @@ -334,13 +346,7 @@
  118622. integer_prim:
  118623. DT_LITERAL
  118624. - {
  118625. - $$ = eval_literal($1, 0, 64);
  118626. - }
  118627. | DT_CHAR_LITERAL
  118628. - {
  118629. - $$ = eval_char_literal($1);
  118630. - }
  118631. | '(' integer_expr ')'
  118632. {
  118633. $$ = $2;
  118634. @@ -447,7 +453,7 @@
  118635. }
  118636. | subnode propdef
  118637. {
  118638. - print_error("syntax error: properties must precede subnodes");
  118639. + ERROR(&@2, "Properties must precede subnodes");
  118640. YYERROR;
  118641. }
  118642. ;
  118643. @@ -470,63 +476,7 @@
  118644. %%
  118645. -void print_error(char const *fmt, ...)
  118646. +void yyerror(char const *s)
  118647. {
  118648. - va_list va;
  118649. -
  118650. - va_start(va, fmt);
  118651. - srcpos_verror(&yylloc, fmt, va);
  118652. - va_end(va);
  118653. -
  118654. - treesource_error = 1;
  118655. -}
  118656. -
  118657. -void yyerror(char const *s) {
  118658. - print_error("%s", s);
  118659. -}
  118660. -
  118661. -static unsigned long long eval_literal(const char *s, int base, int bits)
  118662. -{
  118663. - unsigned long long val;
  118664. - char *e;
  118665. -
  118666. - errno = 0;
  118667. - val = strtoull(s, &e, base);
  118668. - if (*e) {
  118669. - size_t uls = strspn(e, "UL");
  118670. - if (e[uls])
  118671. - print_error("bad characters in literal");
  118672. - }
  118673. - if ((errno == ERANGE)
  118674. - || ((bits < 64) && (val >= (1ULL << bits))))
  118675. - print_error("literal out of range");
  118676. - else if (errno != 0)
  118677. - print_error("bad literal");
  118678. - return val;
  118679. -}
  118680. -
  118681. -static unsigned char eval_char_literal(const char *s)
  118682. -{
  118683. - int i = 1;
  118684. - char c = s[0];
  118685. -
  118686. - if (c == '\0')
  118687. - {
  118688. - print_error("empty character literal");
  118689. - return 0;
  118690. - }
  118691. -
  118692. - /*
  118693. - * If the first character in the character literal is a \ then process
  118694. - * the remaining characters as an escape encoding. If the first
  118695. - * character is neither an escape or a terminator it should be the only
  118696. - * character in the literal and will be returned.
  118697. - */
  118698. - if (c == '\\')
  118699. - c = get_escape_char(s, &i);
  118700. -
  118701. - if (s[i] != '\0')
  118702. - print_error("malformed character literal");
  118703. -
  118704. - return c;
  118705. + ERROR(&yylloc, "%s", s);
  118706. }
  118707. diff -Nur linux-3.18.6/scripts/dtc/flattree.c linux-rpi/scripts/dtc/flattree.c
  118708. --- linux-3.18.6/scripts/dtc/flattree.c 2015-02-06 15:53:48.000000000 +0100
  118709. +++ linux-rpi/scripts/dtc/flattree.c 2015-02-09 04:40:47.000000000 +0100
  118710. @@ -261,7 +261,13 @@
  118711. {
  118712. struct property *prop;
  118713. struct node *child;
  118714. - int seen_name_prop = 0;
  118715. + bool seen_name_prop = false;
  118716. + struct symbol *sym;
  118717. + struct fixup *f;
  118718. + struct fixup_entry *fe;
  118719. + char *name, *s;
  118720. + const char *fullpath;
  118721. + int namesz, nameoff, vallen;
  118722. if (tree->deleted)
  118723. return;
  118724. @@ -276,10 +282,8 @@
  118725. emit->align(etarget, sizeof(cell_t));
  118726. for_each_property(tree, prop) {
  118727. - int nameoff;
  118728. -
  118729. if (streq(prop->name, "name"))
  118730. - seen_name_prop = 1;
  118731. + seen_name_prop = true;
  118732. nameoff = stringtable_insert(strbuf, prop->name);
  118733. @@ -310,6 +314,139 @@
  118734. flatten_tree(child, emit, etarget, strbuf, vi);
  118735. }
  118736. + if (!symbol_fixup_support)
  118737. + goto no_symbols;
  118738. +
  118739. + /* add the symbol nodes (if any) */
  118740. + if (tree->symbols) {
  118741. +
  118742. + emit->beginnode(etarget, NULL);
  118743. + emit->string(etarget, "__symbols__", 0);
  118744. + emit->align(etarget, sizeof(cell_t));
  118745. +
  118746. + for_each_symbol(tree, sym) {
  118747. +
  118748. + vallen = strlen(sym->node->fullpath);
  118749. +
  118750. + nameoff = stringtable_insert(strbuf, sym->label->label);
  118751. +
  118752. + emit->property(etarget, NULL);
  118753. + emit->cell(etarget, vallen + 1);
  118754. + emit->cell(etarget, nameoff);
  118755. +
  118756. + if ((vi->flags & FTF_VARALIGN) && vallen >= 8)
  118757. + emit->align(etarget, 8);
  118758. +
  118759. + emit->string(etarget, sym->node->fullpath,
  118760. + strlen(sym->node->fullpath));
  118761. + emit->align(etarget, sizeof(cell_t));
  118762. + }
  118763. +
  118764. + emit->endnode(etarget, NULL);
  118765. + }
  118766. +
  118767. + /* add the fixup nodes */
  118768. + if (tree->fixups) {
  118769. +
  118770. + /* emit the external fixups */
  118771. + emit->beginnode(etarget, NULL);
  118772. + emit->string(etarget, "__fixups__", 0);
  118773. + emit->align(etarget, sizeof(cell_t));
  118774. +
  118775. + for_each_fixup(tree, f) {
  118776. +
  118777. + namesz = 0;
  118778. + for_each_fixup_entry(f, fe) {
  118779. + fullpath = fe->node->fullpath;
  118780. + if (fullpath[0] == '\0')
  118781. + fullpath = "/";
  118782. + namesz += strlen(fullpath) + 1;
  118783. + namesz += strlen(fe->prop->name) + 1;
  118784. + namesz += 32; /* space for :<number> + '\0' */
  118785. + }
  118786. +
  118787. + name = xmalloc(namesz);
  118788. +
  118789. + s = name;
  118790. + for_each_fixup_entry(f, fe) {
  118791. + fullpath = fe->node->fullpath;
  118792. + if (fullpath[0] == '\0')
  118793. + fullpath = "/";
  118794. + snprintf(s, name + namesz - s, "%s:%s:%d",
  118795. + fullpath,
  118796. + fe->prop->name, fe->offset);
  118797. + s += strlen(s) + 1;
  118798. + }
  118799. +
  118800. + nameoff = stringtable_insert(strbuf, f->ref);
  118801. + vallen = s - name - 1;
  118802. +
  118803. + emit->property(etarget, NULL);
  118804. + emit->cell(etarget, vallen + 1);
  118805. + emit->cell(etarget, nameoff);
  118806. +
  118807. + if ((vi->flags & FTF_VARALIGN) && vallen >= 8)
  118808. + emit->align(etarget, 8);
  118809. +
  118810. + emit->string(etarget, name, vallen);
  118811. + emit->align(etarget, sizeof(cell_t));
  118812. +
  118813. + free(name);
  118814. + }
  118815. +
  118816. + emit->endnode(etarget, tree->labels);
  118817. + }
  118818. +
  118819. + /* add the local fixup property */
  118820. + if (tree->local_fixups) {
  118821. +
  118822. + /* emit the external fixups */
  118823. + emit->beginnode(etarget, NULL);
  118824. + emit->string(etarget, "__local_fixups__", 0);
  118825. + emit->align(etarget, sizeof(cell_t));
  118826. +
  118827. + namesz = 0;
  118828. + for_each_local_fixup_entry(tree, fe) {
  118829. + fullpath = fe->node->fullpath;
  118830. + if (fullpath[0] == '\0')
  118831. + fullpath = "/";
  118832. + namesz += strlen(fullpath) + 1;
  118833. + namesz += strlen(fe->prop->name) + 1;
  118834. + namesz += 32; /* space for :<number> + '\0' */
  118835. + }
  118836. +
  118837. + name = xmalloc(namesz);
  118838. +
  118839. + s = name;
  118840. + for_each_local_fixup_entry(tree, fe) {
  118841. + fullpath = fe->node->fullpath;
  118842. + if (fullpath[0] == '\0')
  118843. + fullpath = "/";
  118844. + snprintf(s, name + namesz - s, "%s:%s:%d",
  118845. + fullpath, fe->prop->name,
  118846. + fe->offset);
  118847. + s += strlen(s) + 1;
  118848. + }
  118849. +
  118850. + nameoff = stringtable_insert(strbuf, "fixup");
  118851. + vallen = s - name - 1;
  118852. +
  118853. + emit->property(etarget, NULL);
  118854. + emit->cell(etarget, vallen + 1);
  118855. + emit->cell(etarget, nameoff);
  118856. +
  118857. + if ((vi->flags & FTF_VARALIGN) && vallen >= 8)
  118858. + emit->align(etarget, 8);
  118859. +
  118860. + emit->string(etarget, name, vallen);
  118861. + emit->align(etarget, sizeof(cell_t));
  118862. +
  118863. + free(name);
  118864. +
  118865. + emit->endnode(etarget, tree->labels);
  118866. + }
  118867. +
  118868. +no_symbols:
  118869. emit->endnode(etarget, tree->labels);
  118870. }
  118871. diff -Nur linux-3.18.6/scripts/dtc/fstree.c linux-rpi/scripts/dtc/fstree.c
  118872. --- linux-3.18.6/scripts/dtc/fstree.c 2015-02-06 15:53:48.000000000 +0100
  118873. +++ linux-rpi/scripts/dtc/fstree.c 2015-02-09 04:40:47.000000000 +0100
  118874. @@ -37,26 +37,26 @@
  118875. tree = build_node(NULL, NULL);
  118876. while ((de = readdir(d)) != NULL) {
  118877. - char *tmpnam;
  118878. + char *tmpname;
  118879. if (streq(de->d_name, ".")
  118880. || streq(de->d_name, ".."))
  118881. continue;
  118882. - tmpnam = join_path(dirname, de->d_name);
  118883. + tmpname = join_path(dirname, de->d_name);
  118884. - if (lstat(tmpnam, &st) < 0)
  118885. - die("stat(%s): %s\n", tmpnam, strerror(errno));
  118886. + if (lstat(tmpname, &st) < 0)
  118887. + die("stat(%s): %s\n", tmpname, strerror(errno));
  118888. if (S_ISREG(st.st_mode)) {
  118889. struct property *prop;
  118890. FILE *pfile;
  118891. - pfile = fopen(tmpnam, "r");
  118892. + pfile = fopen(tmpname, "rb");
  118893. if (! pfile) {
  118894. fprintf(stderr,
  118895. "WARNING: Cannot open %s: %s\n",
  118896. - tmpnam, strerror(errno));
  118897. + tmpname, strerror(errno));
  118898. } else {
  118899. prop = build_property(xstrdup(de->d_name),
  118900. data_copy_file(pfile,
  118901. @@ -67,12 +67,12 @@
  118902. } else if (S_ISDIR(st.st_mode)) {
  118903. struct node *newchild;
  118904. - newchild = read_fstree(tmpnam);
  118905. + newchild = read_fstree(tmpname);
  118906. newchild = name_node(newchild, xstrdup(de->d_name));
  118907. add_child(tree, newchild);
  118908. }
  118909. - free(tmpnam);
  118910. + free(tmpname);
  118911. }
  118912. closedir(d);
  118913. diff -Nur linux-3.18.6/scripts/dtc/livetree.c linux-rpi/scripts/dtc/livetree.c
  118914. --- linux-3.18.6/scripts/dtc/livetree.c 2015-02-06 15:53:48.000000000 +0100
  118915. +++ linux-rpi/scripts/dtc/livetree.c 2015-02-09 04:40:47.000000000 +0100
  118916. @@ -511,7 +511,9 @@
  118917. struct node *get_node_by_ref(struct node *tree, const char *ref)
  118918. {
  118919. - if (ref[0] == '/')
  118920. + if (streq(ref, "/"))
  118921. + return tree;
  118922. + else if (ref[0] == '/')
  118923. return get_node_by_path(tree, ref);
  118924. else
  118925. return get_node_by_label(tree, ref);
  118926. diff -Nur linux-3.18.6/scripts/dtc/srcpos.c linux-rpi/scripts/dtc/srcpos.c
  118927. --- linux-3.18.6/scripts/dtc/srcpos.c 2015-02-06 15:53:48.000000000 +0100
  118928. +++ linux-rpi/scripts/dtc/srcpos.c 2015-02-09 04:40:47.000000000 +0100
  118929. @@ -34,7 +34,7 @@
  118930. static struct search_path *search_path_head, **search_path_tail;
  118931. -static char *dirname(const char *path)
  118932. +static char *get_dirname(const char *path)
  118933. {
  118934. const char *slash = strrchr(path, '/');
  118935. @@ -77,7 +77,7 @@
  118936. else
  118937. fullname = join_path(dirname, fname);
  118938. - *fp = fopen(fullname, "r");
  118939. + *fp = fopen(fullname, "rb");
  118940. if (!*fp) {
  118941. free(fullname);
  118942. fullname = NULL;
  118943. @@ -150,7 +150,7 @@
  118944. srcfile = xmalloc(sizeof(*srcfile));
  118945. srcfile->f = srcfile_relative_open(fname, &srcfile->name);
  118946. - srcfile->dir = dirname(srcfile->name);
  118947. + srcfile->dir = get_dirname(srcfile->name);
  118948. srcfile->prev = current_srcfile;
  118949. srcfile->lineno = 1;
  118950. @@ -159,7 +159,7 @@
  118951. current_srcfile = srcfile;
  118952. }
  118953. -int srcfile_pop(void)
  118954. +bool srcfile_pop(void)
  118955. {
  118956. struct srcfile_state *srcfile = current_srcfile;
  118957. @@ -177,7 +177,7 @@
  118958. * fix this we could either allocate all the files from a
  118959. * table, or use a pool allocator. */
  118960. - return current_srcfile ? 1 : 0;
  118961. + return current_srcfile ? true : false;
  118962. }
  118963. void srcfile_add_search_path(const char *dirname)
  118964. @@ -290,42 +290,27 @@
  118965. return pos_str;
  118966. }
  118967. -void
  118968. -srcpos_verror(struct srcpos *pos, char const *fmt, va_list va)
  118969. +void srcpos_verror(struct srcpos *pos, const char *prefix,
  118970. + const char *fmt, va_list va)
  118971. {
  118972. - const char *srcstr;
  118973. -
  118974. - srcstr = srcpos_string(pos);
  118975. + char *srcstr;
  118976. - fprintf(stderr, "Error: %s ", srcstr);
  118977. - vfprintf(stderr, fmt, va);
  118978. - fprintf(stderr, "\n");
  118979. -}
  118980. + srcstr = srcpos_string(pos);
  118981. -void
  118982. -srcpos_error(struct srcpos *pos, char const *fmt, ...)
  118983. -{
  118984. - va_list va;
  118985. + fprintf(stderr, "%s: %s ", prefix, srcstr);
  118986. + vfprintf(stderr, fmt, va);
  118987. + fprintf(stderr, "\n");
  118988. - va_start(va, fmt);
  118989. - srcpos_verror(pos, fmt, va);
  118990. - va_end(va);
  118991. + free(srcstr);
  118992. }
  118993. -
  118994. -void
  118995. -srcpos_warn(struct srcpos *pos, char const *fmt, ...)
  118996. +void srcpos_error(struct srcpos *pos, const char *prefix,
  118997. + const char *fmt, ...)
  118998. {
  118999. - const char *srcstr;
  119000. va_list va;
  119001. - va_start(va, fmt);
  119002. -
  119003. - srcstr = srcpos_string(pos);
  119004. -
  119005. - fprintf(stderr, "Warning: %s ", srcstr);
  119006. - vfprintf(stderr, fmt, va);
  119007. - fprintf(stderr, "\n");
  119008. + va_start(va, fmt);
  119009. + srcpos_verror(pos, prefix, fmt, va);
  119010. va_end(va);
  119011. }
  119012. diff -Nur linux-3.18.6/scripts/dtc/srcpos.h linux-rpi/scripts/dtc/srcpos.h
  119013. --- linux-3.18.6/scripts/dtc/srcpos.h 2015-02-06 15:53:48.000000000 +0100
  119014. +++ linux-rpi/scripts/dtc/srcpos.h 2015-02-09 04:40:47.000000000 +0100
  119015. @@ -21,6 +21,7 @@
  119016. #define _SRCPOS_H_
  119017. #include <stdio.h>
  119018. +#include <stdbool.h>
  119019. struct srcfile_state {
  119020. FILE *f;
  119021. @@ -55,7 +56,7 @@
  119022. FILE *srcfile_relative_open(const char *fname, char **fullnamep);
  119023. void srcfile_push(const char *fname);
  119024. -int srcfile_pop(void);
  119025. +bool srcfile_pop(void);
  119026. /**
  119027. * Add a new directory to the search path for input files
  119028. @@ -106,12 +107,12 @@
  119029. extern char *srcpos_string(struct srcpos *pos);
  119030. extern void srcpos_dump(struct srcpos *pos);
  119031. -extern void srcpos_verror(struct srcpos *pos, char const *, va_list va)
  119032. - __attribute__((format(printf, 2, 0)));
  119033. -extern void srcpos_error(struct srcpos *pos, char const *, ...)
  119034. - __attribute__((format(printf, 2, 3)));
  119035. -extern void srcpos_warn(struct srcpos *pos, char const *, ...)
  119036. - __attribute__((format(printf, 2, 3)));
  119037. +extern void srcpos_verror(struct srcpos *pos, const char *prefix,
  119038. + const char *fmt, va_list va)
  119039. + __attribute__((format(printf, 3, 0)));
  119040. +extern void srcpos_error(struct srcpos *pos, const char *prefix,
  119041. + const char *fmt, ...)
  119042. + __attribute__((format(printf, 3, 4)));
  119043. extern void srcpos_set_line(char *f, int l);
  119044. diff -Nur linux-3.18.6/scripts/dtc/treesource.c linux-rpi/scripts/dtc/treesource.c
  119045. --- linux-3.18.6/scripts/dtc/treesource.c 2015-02-06 15:53:48.000000000 +0100
  119046. +++ linux-rpi/scripts/dtc/treesource.c 2015-02-09 04:40:47.000000000 +0100
  119047. @@ -26,12 +26,12 @@
  119048. extern YYLTYPE yylloc;
  119049. struct boot_info *the_boot_info;
  119050. -int treesource_error;
  119051. +bool treesource_error;
  119052. struct boot_info *dt_from_source(const char *fname)
  119053. {
  119054. the_boot_info = NULL;
  119055. - treesource_error = 0;
  119056. + treesource_error = false;
  119057. srcfile_push(fname);
  119058. yyin = current_srcfile->f;
  119059. @@ -54,9 +54,9 @@
  119060. fputc('\t', f);
  119061. }
  119062. -static int isstring(char c)
  119063. +static bool isstring(char c)
  119064. {
  119065. - return (isprint(c)
  119066. + return (isprint((unsigned char)c)
  119067. || (c == '\0')
  119068. || strchr("\a\b\t\n\v\f\r", c));
  119069. }
  119070. @@ -109,7 +109,7 @@
  119071. break;
  119072. case '\0':
  119073. fprintf(f, "\", ");
  119074. - while (m && (m->offset < i)) {
  119075. + while (m && (m->offset <= (i + 1))) {
  119076. if (m->type == LABEL) {
  119077. assert(m->offset == (i+1));
  119078. fprintf(f, "%s: ", m->ref);
  119079. @@ -119,7 +119,7 @@
  119080. fprintf(f, "\"");
  119081. break;
  119082. default:
  119083. - if (isprint(c))
  119084. + if (isprint((unsigned char)c))
  119085. fprintf(f, "%c", c);
  119086. else
  119087. fprintf(f, "\\x%02hhx", c);
  119088. @@ -178,7 +178,7 @@
  119089. m = m->next;
  119090. }
  119091. - fprintf(f, "%02hhx", *bp++);
  119092. + fprintf(f, "%02hhx", (unsigned char)(*bp++));
  119093. if ((const void *)bp >= propend)
  119094. break;
  119095. fprintf(f, " ");
  119096. diff -Nur linux-3.18.6/scripts/dtc/util.c linux-rpi/scripts/dtc/util.c
  119097. --- linux-3.18.6/scripts/dtc/util.c 2015-02-06 15:53:48.000000000 +0100
  119098. +++ linux-rpi/scripts/dtc/util.c 2015-02-09 04:40:47.000000000 +0100
  119099. @@ -39,11 +39,11 @@
  119100. char *xstrdup(const char *s)
  119101. {
  119102. int len = strlen(s) + 1;
  119103. - char *dup = xmalloc(len);
  119104. + char *d = xmalloc(len);
  119105. - memcpy(dup, s, len);
  119106. + memcpy(d, s, len);
  119107. - return dup;
  119108. + return d;
  119109. }
  119110. char *join_path(const char *path, const char *name)
  119111. @@ -70,7 +70,7 @@
  119112. return str;
  119113. }
  119114. -int util_is_printable_string(const void *data, int len)
  119115. +bool util_is_printable_string(const void *data, int len)
  119116. {
  119117. const char *s = data;
  119118. const char *ss, *se;
  119119. @@ -87,7 +87,7 @@
  119120. while (s < se) {
  119121. ss = s;
  119122. - while (s < se && *s && isprint(*s))
  119123. + while (s < se && *s && isprint((unsigned char)*s))
  119124. s++;
  119125. /* not zero, or not done yet */
  119126. @@ -219,10 +219,6 @@
  119127. if (offset == bufsize) {
  119128. bufsize *= 2;
  119129. buf = xrealloc(buf, bufsize);
  119130. - if (!buf) {
  119131. - ret = ENOMEM;
  119132. - break;
  119133. - }
  119134. }
  119135. ret = read(fd, &buf[offset], bufsize - offset);
  119136. @@ -375,9 +371,9 @@
  119137. const uint32_t *cell = (const uint32_t *)data;
  119138. printf(" = <");
  119139. - for (i = 0; i < len; i += 4)
  119140. + for (i = 0, len /= 4; i < len; i++)
  119141. printf("0x%08x%s", fdt32_to_cpu(cell[i]),
  119142. - i < (len - 4) ? " " : "");
  119143. + i < (len - 1) ? " " : "");
  119144. printf(">");
  119145. } else {
  119146. printf(" = [");
  119147. diff -Nur linux-3.18.6/scripts/dtc/util.h linux-rpi/scripts/dtc/util.h
  119148. --- linux-3.18.6/scripts/dtc/util.h 2015-02-06 15:53:48.000000000 +0100
  119149. +++ linux-rpi/scripts/dtc/util.h 2015-02-09 04:40:47.000000000 +0100
  119150. @@ -2,6 +2,7 @@
  119151. #define _UTIL_H
  119152. #include <stdarg.h>
  119153. +#include <stdbool.h>
  119154. #include <getopt.h>
  119155. /*
  119156. @@ -33,6 +34,7 @@
  119157. va_start(ap, str);
  119158. fprintf(stderr, "FATAL ERROR: ");
  119159. vfprintf(stderr, str, ap);
  119160. + va_end(ap);
  119161. exit(1);
  119162. }
  119163. @@ -68,7 +70,7 @@
  119164. * @param len The string length including terminator
  119165. * @return 1 if a valid printable string, 0 if not
  119166. */
  119167. -int util_is_printable_string(const void *data, int len);
  119168. +bool util_is_printable_string(const void *data, int len);
  119169. /*
  119170. * Parse an escaped character starting at index i in string s. The resulting
  119171. diff -Nur linux-3.18.6/scripts/dtc/version_gen.h linux-rpi/scripts/dtc/version_gen.h
  119172. --- linux-3.18.6/scripts/dtc/version_gen.h 2015-02-06 15:53:48.000000000 +0100
  119173. +++ linux-rpi/scripts/dtc/version_gen.h 2015-02-09 04:40:47.000000000 +0100
  119174. @@ -1 +1 @@
  119175. -#define DTC_VERSION "DTC 1.4.0-dirty"
  119176. +#define DTC_VERSION "DTC 1.4.1-g36c70742"
  119177. diff -Nur linux-3.18.6/sound/arm/bcm2835.c linux-rpi/sound/arm/bcm2835.c
  119178. --- linux-3.18.6/sound/arm/bcm2835.c 1970-01-01 01:00:00.000000000 +0100
  119179. +++ linux-rpi/sound/arm/bcm2835.c 2015-02-09 04:40:47.000000000 +0100
  119180. @@ -0,0 +1,420 @@
  119181. +/*****************************************************************************
  119182. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  119183. +*
  119184. +* Unless you and Broadcom execute a separate written software license
  119185. +* agreement governing use of this software, this software is licensed to you
  119186. +* under the terms of the GNU General Public License version 2, available at
  119187. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  119188. +*
  119189. +* Notwithstanding the above, under no circumstances may you combine this
  119190. +* software in any way with any other Broadcom software provided under a
  119191. +* license other than the GPL, without Broadcom's express prior written
  119192. +* consent.
  119193. +*****************************************************************************/
  119194. +
  119195. +#include <linux/platform_device.h>
  119196. +
  119197. +#include <linux/init.h>
  119198. +#include <linux/slab.h>
  119199. +#include <linux/module.h>
  119200. +
  119201. +#include "bcm2835.h"
  119202. +
  119203. +/* module parameters (see "Module Parameters") */
  119204. +/* SNDRV_CARDS: maximum number of cards supported by this module */
  119205. +static int index[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = -1 };
  119206. +static char *id[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = NULL };
  119207. +static int enable[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = 1 };
  119208. +
  119209. +/* HACKY global pointers needed for successive probes to work : ssp
  119210. + * But compared against the changes we will have to do in VC audio_ipc code
  119211. + * to export 8 audio_ipc devices as a single IPC device and then monitor all
  119212. + * four devices in a thread, this gets things done quickly and should be easier
  119213. + * to debug if we run into issues
  119214. + */
  119215. +
  119216. +static struct snd_card *g_card = NULL;
  119217. +static bcm2835_chip_t *g_chip = NULL;
  119218. +
  119219. +static int snd_bcm2835_free(bcm2835_chip_t * chip)
  119220. +{
  119221. + kfree(chip);
  119222. + return 0;
  119223. +}
  119224. +
  119225. +/* component-destructor
  119226. + * (see "Management of Cards and Components")
  119227. + */
  119228. +static int snd_bcm2835_dev_free(struct snd_device *device)
  119229. +{
  119230. + return snd_bcm2835_free(device->device_data);
  119231. +}
  119232. +
  119233. +/* chip-specific constructor
  119234. + * (see "Management of Cards and Components")
  119235. + */
  119236. +static int snd_bcm2835_create(struct snd_card *card,
  119237. + struct platform_device *pdev,
  119238. + bcm2835_chip_t ** rchip)
  119239. +{
  119240. + bcm2835_chip_t *chip;
  119241. + int err;
  119242. + static struct snd_device_ops ops = {
  119243. + .dev_free = snd_bcm2835_dev_free,
  119244. + };
  119245. +
  119246. + *rchip = NULL;
  119247. +
  119248. + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  119249. + if (chip == NULL)
  119250. + return -ENOMEM;
  119251. +
  119252. + chip->card = card;
  119253. +
  119254. + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  119255. + if (err < 0) {
  119256. + snd_bcm2835_free(chip);
  119257. + return err;
  119258. + }
  119259. +
  119260. + *rchip = chip;
  119261. + return 0;
  119262. +}
  119263. +
  119264. +static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
  119265. +{
  119266. + static int dev;
  119267. + bcm2835_chip_t *chip;
  119268. + struct snd_card *card;
  119269. + int err;
  119270. +
  119271. + if (dev >= MAX_SUBSTREAMS)
  119272. + return -ENODEV;
  119273. +
  119274. + if (!enable[dev]) {
  119275. + dev++;
  119276. + return -ENOENT;
  119277. + }
  119278. +
  119279. + if (dev > 0)
  119280. + goto add_register_map;
  119281. +
  119282. + err = snd_card_new(NULL, index[dev], id[dev], THIS_MODULE, 0, &g_card);
  119283. + if (err < 0)
  119284. + goto out;
  119285. +
  119286. + snd_card_set_dev(g_card, &pdev->dev);
  119287. + strcpy(g_card->driver, "bcm2835");
  119288. + strcpy(g_card->shortname, "bcm2835 ALSA");
  119289. + sprintf(g_card->longname, "%s", g_card->shortname);
  119290. +
  119291. + err = snd_bcm2835_create(g_card, pdev, &chip);
  119292. + if (err < 0) {
  119293. + dev_err(&pdev->dev, "Failed to create bcm2835 chip\n");
  119294. + goto out_bcm2835_create;
  119295. + }
  119296. +
  119297. + g_chip = chip;
  119298. + err = snd_bcm2835_new_pcm(chip);
  119299. + if (err < 0) {
  119300. + dev_err(&pdev->dev, "Failed to create new BCM2835 pcm device\n");
  119301. + goto out_bcm2835_new_pcm;
  119302. + }
  119303. +
  119304. + err = snd_bcm2835_new_spdif_pcm(chip);
  119305. + if (err < 0) {
  119306. + dev_err(&pdev->dev, "Failed to create new BCM2835 spdif pcm device\n");
  119307. + goto out_bcm2835_new_spdif;
  119308. + }
  119309. +
  119310. + err = snd_bcm2835_new_ctl(chip);
  119311. + if (err < 0) {
  119312. + dev_err(&pdev->dev, "Failed to create new BCM2835 ctl\n");
  119313. + goto out_bcm2835_new_ctl;
  119314. + }
  119315. +
  119316. +add_register_map:
  119317. + card = g_card;
  119318. + chip = g_chip;
  119319. +
  119320. + BUG_ON(!(card && chip));
  119321. +
  119322. + chip->avail_substreams |= (1 << dev);
  119323. + chip->pdev[dev] = pdev;
  119324. +
  119325. + if (dev == 0) {
  119326. + err = snd_card_register(card);
  119327. + if (err < 0) {
  119328. + dev_err(&pdev->dev,
  119329. + "Failed to register bcm2835 ALSA card \n");
  119330. + goto out_card_register;
  119331. + }
  119332. + platform_set_drvdata(pdev, card);
  119333. + audio_info("bcm2835 ALSA card created!\n");
  119334. + } else {
  119335. + audio_info("bcm2835 ALSA chip created!\n");
  119336. + platform_set_drvdata(pdev, (void *)dev);
  119337. + }
  119338. +
  119339. + dev++;
  119340. +
  119341. + return 0;
  119342. +
  119343. +out_card_register:
  119344. +out_bcm2835_new_ctl:
  119345. +out_bcm2835_new_spdif:
  119346. +out_bcm2835_new_pcm:
  119347. +out_bcm2835_create:
  119348. + BUG_ON(!g_card);
  119349. + if (snd_card_free(g_card))
  119350. + dev_err(&pdev->dev, "Failed to free Registered alsa card\n");
  119351. + g_card = NULL;
  119352. +out:
  119353. + dev = SNDRV_CARDS; /* stop more avail_substreams from being probed */
  119354. + dev_err(&pdev->dev, "BCM2835 ALSA Probe failed !!\n");
  119355. + return err;
  119356. +}
  119357. +
  119358. +static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
  119359. +{
  119360. + uint32_t idx;
  119361. + void *drv_data;
  119362. +
  119363. + drv_data = platform_get_drvdata(pdev);
  119364. +
  119365. + if (drv_data == (void *)g_card) {
  119366. + /* This is the card device */
  119367. + snd_card_free((struct snd_card *)drv_data);
  119368. + g_card = NULL;
  119369. + g_chip = NULL;
  119370. + } else {
  119371. + idx = (uint32_t) drv_data;
  119372. + if (g_card != NULL) {
  119373. + BUG_ON(!g_chip);
  119374. + /* We pass chip device numbers in audio ipc devices
  119375. + * other than the one we registered our card with
  119376. + */
  119377. + idx = (uint32_t) drv_data;
  119378. + BUG_ON(!idx || idx > MAX_SUBSTREAMS);
  119379. + g_chip->avail_substreams &= ~(1 << idx);
  119380. + /* There should be atleast one substream registered
  119381. + * after we are done here, as it wil be removed when
  119382. + * the *remove* is called for the card device
  119383. + */
  119384. + BUG_ON(!g_chip->avail_substreams);
  119385. + }
  119386. + }
  119387. +
  119388. + platform_set_drvdata(pdev, NULL);
  119389. +
  119390. + return 0;
  119391. +}
  119392. +
  119393. +#ifdef CONFIG_PM
  119394. +static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
  119395. + pm_message_t state)
  119396. +{
  119397. + return 0;
  119398. +}
  119399. +
  119400. +static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
  119401. +{
  119402. + return 0;
  119403. +}
  119404. +
  119405. +#endif
  119406. +
  119407. +static struct platform_driver bcm2835_alsa0_driver = {
  119408. + .probe = snd_bcm2835_alsa_probe,
  119409. + .remove = snd_bcm2835_alsa_remove,
  119410. +#ifdef CONFIG_PM
  119411. + .suspend = snd_bcm2835_alsa_suspend,
  119412. + .resume = snd_bcm2835_alsa_resume,
  119413. +#endif
  119414. + .driver = {
  119415. + .name = "bcm2835_AUD0",
  119416. + .owner = THIS_MODULE,
  119417. + },
  119418. +};
  119419. +
  119420. +static struct platform_driver bcm2835_alsa1_driver = {
  119421. + .probe = snd_bcm2835_alsa_probe,
  119422. + .remove = snd_bcm2835_alsa_remove,
  119423. +#ifdef CONFIG_PM
  119424. + .suspend = snd_bcm2835_alsa_suspend,
  119425. + .resume = snd_bcm2835_alsa_resume,
  119426. +#endif
  119427. + .driver = {
  119428. + .name = "bcm2835_AUD1",
  119429. + .owner = THIS_MODULE,
  119430. + },
  119431. +};
  119432. +
  119433. +static struct platform_driver bcm2835_alsa2_driver = {
  119434. + .probe = snd_bcm2835_alsa_probe,
  119435. + .remove = snd_bcm2835_alsa_remove,
  119436. +#ifdef CONFIG_PM
  119437. + .suspend = snd_bcm2835_alsa_suspend,
  119438. + .resume = snd_bcm2835_alsa_resume,
  119439. +#endif
  119440. + .driver = {
  119441. + .name = "bcm2835_AUD2",
  119442. + .owner = THIS_MODULE,
  119443. + },
  119444. +};
  119445. +
  119446. +static struct platform_driver bcm2835_alsa3_driver = {
  119447. + .probe = snd_bcm2835_alsa_probe,
  119448. + .remove = snd_bcm2835_alsa_remove,
  119449. +#ifdef CONFIG_PM
  119450. + .suspend = snd_bcm2835_alsa_suspend,
  119451. + .resume = snd_bcm2835_alsa_resume,
  119452. +#endif
  119453. + .driver = {
  119454. + .name = "bcm2835_AUD3",
  119455. + .owner = THIS_MODULE,
  119456. + },
  119457. +};
  119458. +
  119459. +static struct platform_driver bcm2835_alsa4_driver = {
  119460. + .probe = snd_bcm2835_alsa_probe,
  119461. + .remove = snd_bcm2835_alsa_remove,
  119462. +#ifdef CONFIG_PM
  119463. + .suspend = snd_bcm2835_alsa_suspend,
  119464. + .resume = snd_bcm2835_alsa_resume,
  119465. +#endif
  119466. + .driver = {
  119467. + .name = "bcm2835_AUD4",
  119468. + .owner = THIS_MODULE,
  119469. + },
  119470. +};
  119471. +
  119472. +static struct platform_driver bcm2835_alsa5_driver = {
  119473. + .probe = snd_bcm2835_alsa_probe,
  119474. + .remove = snd_bcm2835_alsa_remove,
  119475. +#ifdef CONFIG_PM
  119476. + .suspend = snd_bcm2835_alsa_suspend,
  119477. + .resume = snd_bcm2835_alsa_resume,
  119478. +#endif
  119479. + .driver = {
  119480. + .name = "bcm2835_AUD5",
  119481. + .owner = THIS_MODULE,
  119482. + },
  119483. +};
  119484. +
  119485. +static struct platform_driver bcm2835_alsa6_driver = {
  119486. + .probe = snd_bcm2835_alsa_probe,
  119487. + .remove = snd_bcm2835_alsa_remove,
  119488. +#ifdef CONFIG_PM
  119489. + .suspend = snd_bcm2835_alsa_suspend,
  119490. + .resume = snd_bcm2835_alsa_resume,
  119491. +#endif
  119492. + .driver = {
  119493. + .name = "bcm2835_AUD6",
  119494. + .owner = THIS_MODULE,
  119495. + },
  119496. +};
  119497. +
  119498. +static struct platform_driver bcm2835_alsa7_driver = {
  119499. + .probe = snd_bcm2835_alsa_probe,
  119500. + .remove = snd_bcm2835_alsa_remove,
  119501. +#ifdef CONFIG_PM
  119502. + .suspend = snd_bcm2835_alsa_suspend,
  119503. + .resume = snd_bcm2835_alsa_resume,
  119504. +#endif
  119505. + .driver = {
  119506. + .name = "bcm2835_AUD7",
  119507. + .owner = THIS_MODULE,
  119508. + },
  119509. +};
  119510. +
  119511. +static int bcm2835_alsa_device_init(void)
  119512. +{
  119513. + int err;
  119514. + err = platform_driver_register(&bcm2835_alsa0_driver);
  119515. + if (err) {
  119516. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  119517. + goto out;
  119518. + }
  119519. +
  119520. + err = platform_driver_register(&bcm2835_alsa1_driver);
  119521. + if (err) {
  119522. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  119523. + goto unregister_0;
  119524. + }
  119525. +
  119526. + err = platform_driver_register(&bcm2835_alsa2_driver);
  119527. + if (err) {
  119528. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  119529. + goto unregister_1;
  119530. + }
  119531. +
  119532. + err = platform_driver_register(&bcm2835_alsa3_driver);
  119533. + if (err) {
  119534. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  119535. + goto unregister_2;
  119536. + }
  119537. +
  119538. + err = platform_driver_register(&bcm2835_alsa4_driver);
  119539. + if (err) {
  119540. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  119541. + goto unregister_3;
  119542. + }
  119543. +
  119544. + err = platform_driver_register(&bcm2835_alsa5_driver);
  119545. + if (err) {
  119546. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  119547. + goto unregister_4;
  119548. + }
  119549. +
  119550. + err = platform_driver_register(&bcm2835_alsa6_driver);
  119551. + if (err) {
  119552. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  119553. + goto unregister_5;
  119554. + }
  119555. +
  119556. + err = platform_driver_register(&bcm2835_alsa7_driver);
  119557. + if (err) {
  119558. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  119559. + goto unregister_6;
  119560. + }
  119561. +
  119562. + return 0;
  119563. +
  119564. +unregister_6:
  119565. + platform_driver_unregister(&bcm2835_alsa6_driver);
  119566. +unregister_5:
  119567. + platform_driver_unregister(&bcm2835_alsa5_driver);
  119568. +unregister_4:
  119569. + platform_driver_unregister(&bcm2835_alsa4_driver);
  119570. +unregister_3:
  119571. + platform_driver_unregister(&bcm2835_alsa3_driver);
  119572. +unregister_2:
  119573. + platform_driver_unregister(&bcm2835_alsa2_driver);
  119574. +unregister_1:
  119575. + platform_driver_unregister(&bcm2835_alsa1_driver);
  119576. +unregister_0:
  119577. + platform_driver_unregister(&bcm2835_alsa0_driver);
  119578. +out:
  119579. + return err;
  119580. +}
  119581. +
  119582. +static void bcm2835_alsa_device_exit(void)
  119583. +{
  119584. + platform_driver_unregister(&bcm2835_alsa0_driver);
  119585. + platform_driver_unregister(&bcm2835_alsa1_driver);
  119586. + platform_driver_unregister(&bcm2835_alsa2_driver);
  119587. + platform_driver_unregister(&bcm2835_alsa3_driver);
  119588. + platform_driver_unregister(&bcm2835_alsa4_driver);
  119589. + platform_driver_unregister(&bcm2835_alsa5_driver);
  119590. + platform_driver_unregister(&bcm2835_alsa6_driver);
  119591. + platform_driver_unregister(&bcm2835_alsa7_driver);
  119592. +}
  119593. +
  119594. +late_initcall(bcm2835_alsa_device_init);
  119595. +module_exit(bcm2835_alsa_device_exit);
  119596. +
  119597. +MODULE_AUTHOR("Dom Cobley");
  119598. +MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
  119599. +MODULE_LICENSE("GPL");
  119600. +MODULE_ALIAS("platform:bcm2835_alsa");
  119601. diff -Nur linux-3.18.6/sound/arm/bcm2835-ctl.c linux-rpi/sound/arm/bcm2835-ctl.c
  119602. --- linux-3.18.6/sound/arm/bcm2835-ctl.c 1970-01-01 01:00:00.000000000 +0100
  119603. +++ linux-rpi/sound/arm/bcm2835-ctl.c 2015-02-09 04:40:47.000000000 +0100
  119604. @@ -0,0 +1,323 @@
  119605. +/*****************************************************************************
  119606. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  119607. +*
  119608. +* Unless you and Broadcom execute a separate written software license
  119609. +* agreement governing use of this software, this software is licensed to you
  119610. +* under the terms of the GNU General Public License version 2, available at
  119611. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  119612. +*
  119613. +* Notwithstanding the above, under no circumstances may you combine this
  119614. +* software in any way with any other Broadcom software provided under a
  119615. +* license other than the GPL, without Broadcom's express prior written
  119616. +* consent.
  119617. +*****************************************************************************/
  119618. +
  119619. +#include <linux/platform_device.h>
  119620. +#include <linux/init.h>
  119621. +#include <linux/io.h>
  119622. +#include <linux/jiffies.h>
  119623. +#include <linux/slab.h>
  119624. +#include <linux/time.h>
  119625. +#include <linux/wait.h>
  119626. +#include <linux/delay.h>
  119627. +#include <linux/moduleparam.h>
  119628. +#include <linux/sched.h>
  119629. +
  119630. +#include <sound/core.h>
  119631. +#include <sound/control.h>
  119632. +#include <sound/pcm.h>
  119633. +#include <sound/pcm_params.h>
  119634. +#include <sound/rawmidi.h>
  119635. +#include <sound/initval.h>
  119636. +#include <sound/tlv.h>
  119637. +#include <sound/asoundef.h>
  119638. +
  119639. +#include "bcm2835.h"
  119640. +
  119641. +/* volume maximum and minimum in terms of 0.01dB */
  119642. +#define CTRL_VOL_MAX 400
  119643. +#define CTRL_VOL_MIN -10239 /* originally -10240 */
  119644. +
  119645. +
  119646. +static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
  119647. + struct snd_ctl_elem_info *uinfo)
  119648. +{
  119649. + audio_info(" ... IN\n");
  119650. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  119651. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  119652. + uinfo->count = 1;
  119653. + uinfo->value.integer.min = CTRL_VOL_MIN;
  119654. + uinfo->value.integer.max = CTRL_VOL_MAX; /* 2303 */
  119655. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  119656. + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  119657. + uinfo->count = 1;
  119658. + uinfo->value.integer.min = 0;
  119659. + uinfo->value.integer.max = 1;
  119660. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  119661. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  119662. + uinfo->count = 1;
  119663. + uinfo->value.integer.min = 0;
  119664. + uinfo->value.integer.max = AUDIO_DEST_MAX-1;
  119665. + }
  119666. + audio_info(" ... OUT\n");
  119667. + return 0;
  119668. +}
  119669. +
  119670. +/* toggles mute on or off depending on the value of nmute, and returns
  119671. + * 1 if the mute value was changed, otherwise 0
  119672. + */
  119673. +static int toggle_mute(struct bcm2835_chip *chip, int nmute)
  119674. +{
  119675. + /* if settings are ok, just return 0 */
  119676. + if(chip->mute == nmute)
  119677. + return 0;
  119678. +
  119679. + /* if the sound is muted then we need to unmute */
  119680. + if(chip->mute == CTRL_VOL_MUTE)
  119681. + {
  119682. + chip->volume = chip->old_volume; /* copy the old volume back */
  119683. + audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  119684. + }
  119685. + else /* otherwise we mute */
  119686. + {
  119687. + chip->old_volume = chip->volume;
  119688. + chip->volume = 26214; /* set volume to minimum level AKA mute */
  119689. + audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  119690. + }
  119691. +
  119692. + chip->mute = nmute;
  119693. + return 1;
  119694. +}
  119695. +
  119696. +static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
  119697. + struct snd_ctl_elem_value *ucontrol)
  119698. +{
  119699. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  119700. +
  119701. + BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
  119702. +
  119703. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
  119704. + ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
  119705. + else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
  119706. + ucontrol->value.integer.value[0] = chip->mute;
  119707. + else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
  119708. + ucontrol->value.integer.value[0] = chip->dest;
  119709. +
  119710. + return 0;
  119711. +}
  119712. +
  119713. +static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
  119714. + struct snd_ctl_elem_value *ucontrol)
  119715. +{
  119716. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  119717. + int changed = 0;
  119718. +
  119719. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  119720. + audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]);
  119721. + if (chip->mute == CTRL_VOL_MUTE) {
  119722. + /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
  119723. + return 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
  119724. + }
  119725. + if (changed
  119726. + || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
  119727. +
  119728. + chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
  119729. + changed = 1;
  119730. + }
  119731. +
  119732. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  119733. + /* Now implemented */
  119734. + audio_info(" Mute attempted\n");
  119735. + changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
  119736. +
  119737. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  119738. + if (ucontrol->value.integer.value[0] != chip->dest) {
  119739. + chip->dest = ucontrol->value.integer.value[0];
  119740. + changed = 1;
  119741. + }
  119742. + }
  119743. +
  119744. + if (changed) {
  119745. + if (bcm2835_audio_set_ctls(chip))
  119746. + printk(KERN_ERR "Failed to set ALSA controls..\n");
  119747. + }
  119748. +
  119749. + return changed;
  119750. +}
  119751. +
  119752. +static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
  119753. +
  119754. +static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
  119755. + {
  119756. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  119757. + .name = "PCM Playback Volume",
  119758. + .index = 0,
  119759. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  119760. + .private_value = PCM_PLAYBACK_VOLUME,
  119761. + .info = snd_bcm2835_ctl_info,
  119762. + .get = snd_bcm2835_ctl_get,
  119763. + .put = snd_bcm2835_ctl_put,
  119764. + .count = 1,
  119765. + .tlv = {.p = snd_bcm2835_db_scale}
  119766. + },
  119767. + {
  119768. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  119769. + .name = "PCM Playback Switch",
  119770. + .index = 0,
  119771. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  119772. + .private_value = PCM_PLAYBACK_MUTE,
  119773. + .info = snd_bcm2835_ctl_info,
  119774. + .get = snd_bcm2835_ctl_get,
  119775. + .put = snd_bcm2835_ctl_put,
  119776. + .count = 1,
  119777. + },
  119778. + {
  119779. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  119780. + .name = "PCM Playback Route",
  119781. + .index = 0,
  119782. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  119783. + .private_value = PCM_PLAYBACK_DEVICE,
  119784. + .info = snd_bcm2835_ctl_info,
  119785. + .get = snd_bcm2835_ctl_get,
  119786. + .put = snd_bcm2835_ctl_put,
  119787. + .count = 1,
  119788. + },
  119789. +};
  119790. +
  119791. +static int snd_bcm2835_spdif_default_info(struct snd_kcontrol *kcontrol,
  119792. + struct snd_ctl_elem_info *uinfo)
  119793. +{
  119794. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  119795. + uinfo->count = 1;
  119796. + return 0;
  119797. +}
  119798. +
  119799. +static int snd_bcm2835_spdif_default_get(struct snd_kcontrol *kcontrol,
  119800. + struct snd_ctl_elem_value *ucontrol)
  119801. +{
  119802. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  119803. + int i;
  119804. +
  119805. + for (i = 0; i < 4; i++)
  119806. + ucontrol->value.iec958.status[i] =
  119807. + (chip->spdif_status >> (i * 8)) && 0xff;
  119808. +
  119809. + return 0;
  119810. +}
  119811. +
  119812. +static int snd_bcm2835_spdif_default_put(struct snd_kcontrol *kcontrol,
  119813. + struct snd_ctl_elem_value *ucontrol)
  119814. +{
  119815. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  119816. + unsigned int val = 0;
  119817. + int i, change;
  119818. +
  119819. + for (i = 0; i < 4; i++)
  119820. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  119821. +
  119822. + change = val != chip->spdif_status;
  119823. + chip->spdif_status = val;
  119824. +
  119825. + return change;
  119826. +}
  119827. +
  119828. +static int snd_bcm2835_spdif_mask_info(struct snd_kcontrol *kcontrol,
  119829. + struct snd_ctl_elem_info *uinfo)
  119830. +{
  119831. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  119832. + uinfo->count = 1;
  119833. + return 0;
  119834. +}
  119835. +
  119836. +static int snd_bcm2835_spdif_mask_get(struct snd_kcontrol *kcontrol,
  119837. + struct snd_ctl_elem_value *ucontrol)
  119838. +{
  119839. + /* bcm2835 supports only consumer mode and sets all other format flags
  119840. + * automatically. So the only thing left is signalling non-audio
  119841. + * content */
  119842. + ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO;
  119843. + return 0;
  119844. +}
  119845. +
  119846. +static int snd_bcm2835_spdif_stream_info(struct snd_kcontrol *kcontrol,
  119847. + struct snd_ctl_elem_info *uinfo)
  119848. +{
  119849. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  119850. + uinfo->count = 1;
  119851. + return 0;
  119852. +}
  119853. +
  119854. +static int snd_bcm2835_spdif_stream_get(struct snd_kcontrol *kcontrol,
  119855. + struct snd_ctl_elem_value *ucontrol)
  119856. +{
  119857. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  119858. + int i;
  119859. +
  119860. + for (i = 0; i < 4; i++)
  119861. + ucontrol->value.iec958.status[i] =
  119862. + (chip->spdif_status >> (i * 8)) & 0xff;
  119863. + return 0;
  119864. +}
  119865. +
  119866. +static int snd_bcm2835_spdif_stream_put(struct snd_kcontrol *kcontrol,
  119867. + struct snd_ctl_elem_value *ucontrol)
  119868. +{
  119869. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  119870. + unsigned int val = 0;
  119871. + int i, change;
  119872. +
  119873. + for (i = 0; i < 4; i++)
  119874. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  119875. + change = val != chip->spdif_status;
  119876. + chip->spdif_status = val;
  119877. +
  119878. + return change;
  119879. +}
  119880. +
  119881. +static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
  119882. + {
  119883. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  119884. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  119885. + .info = snd_bcm2835_spdif_default_info,
  119886. + .get = snd_bcm2835_spdif_default_get,
  119887. + .put = snd_bcm2835_spdif_default_put
  119888. + },
  119889. + {
  119890. + .access = SNDRV_CTL_ELEM_ACCESS_READ,
  119891. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  119892. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
  119893. + .info = snd_bcm2835_spdif_mask_info,
  119894. + .get = snd_bcm2835_spdif_mask_get,
  119895. + },
  119896. + {
  119897. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  119898. + SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  119899. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  119900. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
  119901. + .info = snd_bcm2835_spdif_stream_info,
  119902. + .get = snd_bcm2835_spdif_stream_get,
  119903. + .put = snd_bcm2835_spdif_stream_put,
  119904. + },
  119905. +};
  119906. +
  119907. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip)
  119908. +{
  119909. + int err;
  119910. + unsigned int idx;
  119911. +
  119912. + strcpy(chip->card->mixername, "Broadcom Mixer");
  119913. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
  119914. + err =
  119915. + snd_ctl_add(chip->card,
  119916. + snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
  119917. + if (err < 0)
  119918. + return err;
  119919. + }
  119920. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_spdif); idx++) {
  119921. + err = snd_ctl_add(chip->card,
  119922. + snd_ctl_new1(&snd_bcm2835_spdif[idx], chip));
  119923. + if (err < 0)
  119924. + return err;
  119925. + }
  119926. + return 0;
  119927. +}
  119928. diff -Nur linux-3.18.6/sound/arm/bcm2835.h linux-rpi/sound/arm/bcm2835.h
  119929. --- linux-3.18.6/sound/arm/bcm2835.h 1970-01-01 01:00:00.000000000 +0100
  119930. +++ linux-rpi/sound/arm/bcm2835.h 2015-02-09 04:40:47.000000000 +0100
  119931. @@ -0,0 +1,167 @@
  119932. +/*****************************************************************************
  119933. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  119934. +*
  119935. +* Unless you and Broadcom execute a separate written software license
  119936. +* agreement governing use of this software, this software is licensed to you
  119937. +* under the terms of the GNU General Public License version 2, available at
  119938. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  119939. +*
  119940. +* Notwithstanding the above, under no circumstances may you combine this
  119941. +* software in any way with any other Broadcom software provided under a
  119942. +* license other than the GPL, without Broadcom's express prior written
  119943. +* consent.
  119944. +*****************************************************************************/
  119945. +
  119946. +#ifndef __SOUND_ARM_BCM2835_H
  119947. +#define __SOUND_ARM_BCM2835_H
  119948. +
  119949. +#include <linux/device.h>
  119950. +#include <linux/list.h>
  119951. +#include <linux/interrupt.h>
  119952. +#include <linux/wait.h>
  119953. +#include <sound/core.h>
  119954. +#include <sound/initval.h>
  119955. +#include <sound/pcm.h>
  119956. +#include <sound/pcm_params.h>
  119957. +#include <sound/pcm-indirect.h>
  119958. +#include <linux/workqueue.h>
  119959. +
  119960. +/*
  119961. +#define AUDIO_DEBUG_ENABLE
  119962. +#define AUDIO_VERBOSE_DEBUG_ENABLE
  119963. +*/
  119964. +
  119965. +/* Debug macros */
  119966. +
  119967. +#ifdef AUDIO_DEBUG_ENABLE
  119968. +#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
  119969. +
  119970. +#define audio_debug(fmt, arg...) \
  119971. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  119972. +
  119973. +#define audio_info(fmt, arg...) \
  119974. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  119975. +
  119976. +#else
  119977. +
  119978. +#define audio_debug(fmt, arg...)
  119979. +
  119980. +#define audio_info(fmt, arg...)
  119981. +
  119982. +#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
  119983. +
  119984. +#else
  119985. +
  119986. +#define audio_debug(fmt, arg...)
  119987. +
  119988. +#define audio_info(fmt, arg...)
  119989. +
  119990. +#endif /* AUDIO_DEBUG_ENABLE */
  119991. +
  119992. +#define audio_error(fmt, arg...) \
  119993. + printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
  119994. +
  119995. +#define audio_warning(fmt, arg...) \
  119996. + printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
  119997. +
  119998. +#define audio_alert(fmt, arg...) \
  119999. + printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
  120000. +
  120001. +#define MAX_SUBSTREAMS (8)
  120002. +#define AVAIL_SUBSTREAMS_MASK (0xff)
  120003. +enum {
  120004. + CTRL_VOL_MUTE,
  120005. + CTRL_VOL_UNMUTE
  120006. +};
  120007. +
  120008. +/* macros for alsa2chip and chip2alsa, instead of functions */
  120009. +
  120010. +#define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
  120011. +#define chip2alsa(vol) -((vol * 100) >> 8) /* convert chip to alsa volume */
  120012. +
  120013. +/* Some constants for values .. */
  120014. +typedef enum {
  120015. + AUDIO_DEST_AUTO = 0,
  120016. + AUDIO_DEST_HEADPHONES = 1,
  120017. + AUDIO_DEST_HDMI = 2,
  120018. + AUDIO_DEST_MAX,
  120019. +} SND_BCM2835_ROUTE_T;
  120020. +
  120021. +typedef enum {
  120022. + PCM_PLAYBACK_VOLUME,
  120023. + PCM_PLAYBACK_MUTE,
  120024. + PCM_PLAYBACK_DEVICE,
  120025. +} SND_BCM2835_CTRL_T;
  120026. +
  120027. +/* definition of the chip-specific record */
  120028. +typedef struct bcm2835_chip {
  120029. + struct snd_card *card;
  120030. + struct snd_pcm *pcm;
  120031. + struct snd_pcm *pcm_spdif;
  120032. + /* Bitmat for valid reg_base and irq numbers */
  120033. + uint32_t avail_substreams;
  120034. + struct platform_device *pdev[MAX_SUBSTREAMS];
  120035. + struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
  120036. +
  120037. + int volume;
  120038. + int old_volume; /* stores the volume value whist muted */
  120039. + int dest;
  120040. + int mute;
  120041. +
  120042. + unsigned int opened;
  120043. + unsigned int spdif_status;
  120044. + struct mutex audio_mutex;
  120045. +} bcm2835_chip_t;
  120046. +
  120047. +typedef struct bcm2835_alsa_stream {
  120048. + bcm2835_chip_t *chip;
  120049. + struct snd_pcm_substream *substream;
  120050. + struct snd_pcm_indirect pcm_indirect;
  120051. +
  120052. + struct semaphore buffers_update_sem;
  120053. + struct semaphore control_sem;
  120054. + spinlock_t lock;
  120055. + volatile uint32_t control;
  120056. + volatile uint32_t status;
  120057. +
  120058. + int open;
  120059. + int running;
  120060. + int draining;
  120061. +
  120062. + int channels;
  120063. + int params_rate;
  120064. + int pcm_format_width;
  120065. +
  120066. + unsigned int pos;
  120067. + unsigned int buffer_size;
  120068. + unsigned int period_size;
  120069. +
  120070. + uint32_t enable_fifo_irq;
  120071. + irq_handler_t fifo_irq_handler;
  120072. +
  120073. + atomic_t retrieved;
  120074. + struct opaque_AUDIO_INSTANCE_T *instance;
  120075. + struct workqueue_struct *my_wq;
  120076. + int idx;
  120077. +} bcm2835_alsa_stream_t;
  120078. +
  120079. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip);
  120080. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip);
  120081. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip);
  120082. +
  120083. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream);
  120084. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream);
  120085. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  120086. + uint32_t channels, uint32_t samplerate,
  120087. + uint32_t bps);
  120088. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream);
  120089. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream);
  120090. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream);
  120091. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip);
  120092. +int bcm2835_audio_write(bcm2835_alsa_stream_t * alsa_stream, uint32_t count,
  120093. + void *src);
  120094. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream);
  120095. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream);
  120096. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream);
  120097. +
  120098. +#endif /* __SOUND_ARM_BCM2835_H */
  120099. diff -Nur linux-3.18.6/sound/arm/bcm2835-pcm.c linux-rpi/sound/arm/bcm2835-pcm.c
  120100. --- linux-3.18.6/sound/arm/bcm2835-pcm.c 1970-01-01 01:00:00.000000000 +0100
  120101. +++ linux-rpi/sound/arm/bcm2835-pcm.c 2015-02-09 04:40:47.000000000 +0100
  120102. @@ -0,0 +1,552 @@
  120103. +/*****************************************************************************
  120104. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  120105. +*
  120106. +* Unless you and Broadcom execute a separate written software license
  120107. +* agreement governing use of this software, this software is licensed to you
  120108. +* under the terms of the GNU General Public License version 2, available at
  120109. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  120110. +*
  120111. +* Notwithstanding the above, under no circumstances may you combine this
  120112. +* software in any way with any other Broadcom software provided under a
  120113. +* license other than the GPL, without Broadcom's express prior written
  120114. +* consent.
  120115. +*****************************************************************************/
  120116. +
  120117. +#include <linux/interrupt.h>
  120118. +#include <linux/slab.h>
  120119. +
  120120. +#include <sound/asoundef.h>
  120121. +
  120122. +#include "bcm2835.h"
  120123. +
  120124. +/* hardware definition */
  120125. +static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
  120126. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  120127. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  120128. + .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  120129. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  120130. + .rate_min = 8000,
  120131. + .rate_max = 48000,
  120132. + .channels_min = 1,
  120133. + .channels_max = 2,
  120134. + .buffer_bytes_max = 128 * 1024,
  120135. + .period_bytes_min = 1 * 1024,
  120136. + .period_bytes_max = 128 * 1024,
  120137. + .periods_min = 1,
  120138. + .periods_max = 128,
  120139. +};
  120140. +
  120141. +static struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
  120142. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  120143. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  120144. + .formats = SNDRV_PCM_FMTBIT_S16_LE,
  120145. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 |
  120146. + SNDRV_PCM_RATE_48000,
  120147. + .rate_min = 44100,
  120148. + .rate_max = 48000,
  120149. + .channels_min = 2,
  120150. + .channels_max = 2,
  120151. + .buffer_bytes_max = 128 * 1024,
  120152. + .period_bytes_min = 1 * 1024,
  120153. + .period_bytes_max = 128 * 1024,
  120154. + .periods_min = 1,
  120155. + .periods_max = 128,
  120156. +};
  120157. +
  120158. +static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
  120159. +{
  120160. + audio_info("Freeing up alsa stream here ..\n");
  120161. + if (runtime->private_data)
  120162. + kfree(runtime->private_data);
  120163. + runtime->private_data = NULL;
  120164. +}
  120165. +
  120166. +static irqreturn_t bcm2835_playback_fifo_irq(int irq, void *dev_id)
  120167. +{
  120168. + bcm2835_alsa_stream_t *alsa_stream = (bcm2835_alsa_stream_t *) dev_id;
  120169. + uint32_t consumed = 0;
  120170. + int new_period = 0;
  120171. +
  120172. + audio_info(" .. IN\n");
  120173. +
  120174. + audio_info("alsa_stream=%p substream=%p\n", alsa_stream,
  120175. + alsa_stream ? alsa_stream->substream : 0);
  120176. +
  120177. + if (alsa_stream->open)
  120178. + consumed = bcm2835_audio_retrieve_buffers(alsa_stream);
  120179. +
  120180. + /* We get called only if playback was triggered, So, the number of buffers we retrieve in
  120181. + * each iteration are the buffers that have been played out already
  120182. + */
  120183. +
  120184. + if (alsa_stream->period_size) {
  120185. + if ((alsa_stream->pos / alsa_stream->period_size) !=
  120186. + ((alsa_stream->pos + consumed) / alsa_stream->period_size))
  120187. + new_period = 1;
  120188. + }
  120189. + audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
  120190. + alsa_stream->pos,
  120191. + consumed,
  120192. + alsa_stream->buffer_size,
  120193. + (int)(alsa_stream->period_size*alsa_stream->substream->runtime->periods),
  120194. + frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
  120195. + new_period);
  120196. + if (alsa_stream->buffer_size) {
  120197. + alsa_stream->pos += consumed &~ (1<<30);
  120198. + alsa_stream->pos %= alsa_stream->buffer_size;
  120199. + }
  120200. +
  120201. + if (alsa_stream->substream) {
  120202. + if (new_period)
  120203. + snd_pcm_period_elapsed(alsa_stream->substream);
  120204. + } else {
  120205. + audio_warning(" unexpected NULL substream\n");
  120206. + }
  120207. + audio_info(" .. OUT\n");
  120208. +
  120209. + return IRQ_HANDLED;
  120210. +}
  120211. +
  120212. +/* open callback */
  120213. +static int snd_bcm2835_playback_open_generic(
  120214. + struct snd_pcm_substream *substream, int spdif)
  120215. +{
  120216. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  120217. + struct snd_pcm_runtime *runtime = substream->runtime;
  120218. + bcm2835_alsa_stream_t *alsa_stream;
  120219. + int idx;
  120220. + int err;
  120221. +
  120222. + audio_info(" .. IN (%d)\n", substream->number);
  120223. +
  120224. + if(mutex_lock_interruptible(&chip->audio_mutex))
  120225. + {
  120226. + audio_error("Interrupted whilst waiting for lock\n");
  120227. + return -EINTR;
  120228. + }
  120229. + audio_info("Alsa open (%d)\n", substream->number);
  120230. + idx = substream->number;
  120231. +
  120232. + if (spdif && chip->opened != 0)
  120233. + return -EBUSY;
  120234. + else if (!spdif && (chip->opened & (1 << idx)))
  120235. + return -EBUSY;
  120236. +
  120237. + if (idx > MAX_SUBSTREAMS) {
  120238. + audio_error
  120239. + ("substream(%d) device doesn't exist max(%d) substreams allowed\n",
  120240. + idx, MAX_SUBSTREAMS);
  120241. + err = -ENODEV;
  120242. + goto out;
  120243. + }
  120244. +
  120245. + /* Check if we are ready */
  120246. + if (!(chip->avail_substreams & (1 << idx))) {
  120247. + /* We are not ready yet */
  120248. + audio_error("substream(%d) device is not ready yet\n", idx);
  120249. + err = -EAGAIN;
  120250. + goto out;
  120251. + }
  120252. +
  120253. + alsa_stream = kzalloc(sizeof(bcm2835_alsa_stream_t), GFP_KERNEL);
  120254. + if (alsa_stream == NULL) {
  120255. + err = -ENOMEM;
  120256. + goto out;
  120257. + }
  120258. +
  120259. + /* Initialise alsa_stream */
  120260. + alsa_stream->chip = chip;
  120261. + alsa_stream->substream = substream;
  120262. + alsa_stream->idx = idx;
  120263. +
  120264. + sema_init(&alsa_stream->buffers_update_sem, 0);
  120265. + sema_init(&alsa_stream->control_sem, 0);
  120266. + spin_lock_init(&alsa_stream->lock);
  120267. +
  120268. + /* Enabled in start trigger, called on each "fifo irq" after that */
  120269. + alsa_stream->enable_fifo_irq = 0;
  120270. + alsa_stream->fifo_irq_handler = bcm2835_playback_fifo_irq;
  120271. +
  120272. + err = bcm2835_audio_open(alsa_stream);
  120273. + if (err != 0) {
  120274. + kfree(alsa_stream);
  120275. + return err;
  120276. + }
  120277. + runtime->private_data = alsa_stream;
  120278. + runtime->private_free = snd_bcm2835_playback_free;
  120279. + if (spdif) {
  120280. + runtime->hw = snd_bcm2835_playback_spdif_hw;
  120281. + } else {
  120282. + /* clear spdif status, as we are not in spdif mode */
  120283. + chip->spdif_status = 0;
  120284. + runtime->hw = snd_bcm2835_playback_hw;
  120285. + }
  120286. + /* minimum 16 bytes alignment (for vchiq bulk transfers) */
  120287. + snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  120288. + 16);
  120289. +
  120290. + chip->alsa_stream[idx] = alsa_stream;
  120291. +
  120292. + chip->opened |= (1 << idx);
  120293. + alsa_stream->open = 1;
  120294. + alsa_stream->draining = 1;
  120295. +
  120296. +out:
  120297. + mutex_unlock(&chip->audio_mutex);
  120298. +
  120299. + audio_info(" .. OUT =%d\n", err);
  120300. +
  120301. + return err;
  120302. +}
  120303. +
  120304. +static int snd_bcm2835_playback_open(struct snd_pcm_substream *substream)
  120305. +{
  120306. + return snd_bcm2835_playback_open_generic(substream, 0);
  120307. +}
  120308. +
  120309. +static int snd_bcm2835_playback_spdif_open(struct snd_pcm_substream *substream)
  120310. +{
  120311. + return snd_bcm2835_playback_open_generic(substream, 1);
  120312. +}
  120313. +
  120314. +/* close callback */
  120315. +static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
  120316. +{
  120317. + /* the hardware-specific codes will be here */
  120318. +
  120319. + bcm2835_chip_t *chip;
  120320. + struct snd_pcm_runtime *runtime;
  120321. + bcm2835_alsa_stream_t *alsa_stream;
  120322. +
  120323. + audio_info(" .. IN\n");
  120324. +
  120325. + chip = snd_pcm_substream_chip(substream);
  120326. + if(mutex_lock_interruptible(&chip->audio_mutex))
  120327. + {
  120328. + audio_error("Interrupted whilst waiting for lock\n");
  120329. + return -EINTR;
  120330. + }
  120331. + runtime = substream->runtime;
  120332. + alsa_stream = runtime->private_data;
  120333. +
  120334. + audio_info("Alsa close\n");
  120335. +
  120336. + /*
  120337. + * Call stop if it's still running. This happens when app
  120338. + * is force killed and we don't get a stop trigger.
  120339. + */
  120340. + if (alsa_stream->running) {
  120341. + int err;
  120342. + err = bcm2835_audio_stop(alsa_stream);
  120343. + alsa_stream->running = 0;
  120344. + if (err != 0)
  120345. + audio_error(" Failed to STOP alsa device\n");
  120346. + }
  120347. +
  120348. + alsa_stream->period_size = 0;
  120349. + alsa_stream->buffer_size = 0;
  120350. +
  120351. + if (alsa_stream->open) {
  120352. + alsa_stream->open = 0;
  120353. + bcm2835_audio_close(alsa_stream);
  120354. + }
  120355. + if (alsa_stream->chip)
  120356. + alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
  120357. + /*
  120358. + * Do not free up alsa_stream here, it will be freed up by
  120359. + * runtime->private_free callback we registered in *_open above
  120360. + */
  120361. +
  120362. + chip->opened &= ~(1 << substream->number);
  120363. +
  120364. + mutex_unlock(&chip->audio_mutex);
  120365. + audio_info(" .. OUT\n");
  120366. +
  120367. + return 0;
  120368. +}
  120369. +
  120370. +/* hw_params callback */
  120371. +static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
  120372. + struct snd_pcm_hw_params *params)
  120373. +{
  120374. + struct snd_pcm_runtime *runtime = substream->runtime;
  120375. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  120376. + int err;
  120377. +
  120378. + audio_info(" .. IN\n");
  120379. +
  120380. + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  120381. + if (err < 0) {
  120382. + audio_error
  120383. + (" pcm_lib_malloc failed to allocated pages for buffers\n");
  120384. + return err;
  120385. + }
  120386. +
  120387. + alsa_stream->channels = params_channels(params);
  120388. + alsa_stream->params_rate = params_rate(params);
  120389. + alsa_stream->pcm_format_width = snd_pcm_format_width(params_format (params));
  120390. + audio_info(" .. OUT\n");
  120391. +
  120392. + return err;
  120393. +}
  120394. +
  120395. +/* hw_free callback */
  120396. +static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
  120397. +{
  120398. + audio_info(" .. IN\n");
  120399. + return snd_pcm_lib_free_pages(substream);
  120400. +}
  120401. +
  120402. +/* prepare callback */
  120403. +static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
  120404. +{
  120405. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  120406. + struct snd_pcm_runtime *runtime = substream->runtime;
  120407. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  120408. + int channels;
  120409. + int err;
  120410. +
  120411. + audio_info(" .. IN\n");
  120412. +
  120413. + /* notify the vchiq that it should enter spdif passthrough mode by
  120414. + * setting channels=0 (see
  120415. + * https://github.com/raspberrypi/linux/issues/528) */
  120416. + if (chip->spdif_status & IEC958_AES0_NONAUDIO)
  120417. + channels = 0;
  120418. + else
  120419. + channels = alsa_stream->channels;
  120420. +
  120421. + err = bcm2835_audio_set_params(alsa_stream, channels,
  120422. + alsa_stream->params_rate,
  120423. + alsa_stream->pcm_format_width);
  120424. + if (err < 0) {
  120425. + audio_error(" error setting hw params\n");
  120426. + }
  120427. +
  120428. + bcm2835_audio_setup(alsa_stream);
  120429. +
  120430. + /* in preparation of the stream, set the controls (volume level) of the stream */
  120431. + bcm2835_audio_set_ctls(alsa_stream->chip);
  120432. +
  120433. +
  120434. + memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
  120435. +
  120436. + alsa_stream->pcm_indirect.hw_buffer_size =
  120437. + alsa_stream->pcm_indirect.sw_buffer_size =
  120438. + snd_pcm_lib_buffer_bytes(substream);
  120439. +
  120440. + alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
  120441. + alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
  120442. + alsa_stream->pos = 0;
  120443. +
  120444. + audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n",
  120445. + alsa_stream->buffer_size, alsa_stream->period_size,
  120446. + alsa_stream->pos, runtime->frame_bits);
  120447. +
  120448. + audio_info(" .. OUT\n");
  120449. + return 0;
  120450. +}
  120451. +
  120452. +static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
  120453. + struct snd_pcm_indirect *rec, size_t bytes)
  120454. +{
  120455. + struct snd_pcm_runtime *runtime = substream->runtime;
  120456. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  120457. + void *src = (void *)(substream->runtime->dma_area + rec->sw_data);
  120458. + int err;
  120459. +
  120460. + err = bcm2835_audio_write(alsa_stream, bytes, src);
  120461. + if (err)
  120462. + audio_error(" Failed to transfer to alsa device (%d)\n", err);
  120463. +
  120464. +}
  120465. +
  120466. +static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
  120467. +{
  120468. + struct snd_pcm_runtime *runtime = substream->runtime;
  120469. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  120470. + struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
  120471. +
  120472. + pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
  120473. + snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
  120474. + snd_bcm2835_pcm_transfer);
  120475. + return 0;
  120476. +}
  120477. +
  120478. +/* trigger callback */
  120479. +static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  120480. +{
  120481. + struct snd_pcm_runtime *runtime = substream->runtime;
  120482. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  120483. + int err = 0;
  120484. +
  120485. + audio_info(" .. IN\n");
  120486. +
  120487. + switch (cmd) {
  120488. + case SNDRV_PCM_TRIGGER_START:
  120489. + audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n",
  120490. + alsa_stream->running);
  120491. + if (!alsa_stream->running) {
  120492. + err = bcm2835_audio_start(alsa_stream);
  120493. + if (err == 0) {
  120494. + alsa_stream->pcm_indirect.hw_io =
  120495. + alsa_stream->pcm_indirect.hw_data =
  120496. + bytes_to_frames(runtime,
  120497. + alsa_stream->pos);
  120498. + substream->ops->ack(substream);
  120499. + alsa_stream->running = 1;
  120500. + alsa_stream->draining = 1;
  120501. + } else {
  120502. + audio_error(" Failed to START alsa device (%d)\n", err);
  120503. + }
  120504. + }
  120505. + break;
  120506. + case SNDRV_PCM_TRIGGER_STOP:
  120507. + audio_debug
  120508. + ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
  120509. + alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
  120510. + if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
  120511. + audio_info("DRAINING\n");
  120512. + alsa_stream->draining = 1;
  120513. + } else {
  120514. + audio_info("DROPPING\n");
  120515. + alsa_stream->draining = 0;
  120516. + }
  120517. + if (alsa_stream->running) {
  120518. + err = bcm2835_audio_stop(alsa_stream);
  120519. + if (err != 0)
  120520. + audio_error(" Failed to STOP alsa device (%d)\n", err);
  120521. + alsa_stream->running = 0;
  120522. + }
  120523. + break;
  120524. + default:
  120525. + err = -EINVAL;
  120526. + }
  120527. +
  120528. + audio_info(" .. OUT\n");
  120529. + return err;
  120530. +}
  120531. +
  120532. +/* pointer callback */
  120533. +static snd_pcm_uframes_t
  120534. +snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
  120535. +{
  120536. + struct snd_pcm_runtime *runtime = substream->runtime;
  120537. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  120538. +
  120539. + audio_info(" .. IN\n");
  120540. +
  120541. + audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
  120542. + frames_to_bytes(runtime, runtime->status->hw_ptr),
  120543. + frames_to_bytes(runtime, runtime->control->appl_ptr),
  120544. + alsa_stream->pos);
  120545. +
  120546. + audio_info(" .. OUT\n");
  120547. + return snd_pcm_indirect_playback_pointer(substream,
  120548. + &alsa_stream->pcm_indirect,
  120549. + alsa_stream->pos);
  120550. +}
  120551. +
  120552. +static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  120553. + unsigned int cmd, void *arg)
  120554. +{
  120555. + int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
  120556. + audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
  120557. + cmd, arg, arg ? *(unsigned *)arg : 0, ret);
  120558. + return ret;
  120559. +}
  120560. +
  120561. +/* operators */
  120562. +static struct snd_pcm_ops snd_bcm2835_playback_ops = {
  120563. + .open = snd_bcm2835_playback_open,
  120564. + .close = snd_bcm2835_playback_close,
  120565. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  120566. + .hw_params = snd_bcm2835_pcm_hw_params,
  120567. + .hw_free = snd_bcm2835_pcm_hw_free,
  120568. + .prepare = snd_bcm2835_pcm_prepare,
  120569. + .trigger = snd_bcm2835_pcm_trigger,
  120570. + .pointer = snd_bcm2835_pcm_pointer,
  120571. + .ack = snd_bcm2835_pcm_ack,
  120572. +};
  120573. +
  120574. +static struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = {
  120575. + .open = snd_bcm2835_playback_spdif_open,
  120576. + .close = snd_bcm2835_playback_close,
  120577. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  120578. + .hw_params = snd_bcm2835_pcm_hw_params,
  120579. + .hw_free = snd_bcm2835_pcm_hw_free,
  120580. + .prepare = snd_bcm2835_pcm_prepare,
  120581. + .trigger = snd_bcm2835_pcm_trigger,
  120582. + .pointer = snd_bcm2835_pcm_pointer,
  120583. + .ack = snd_bcm2835_pcm_ack,
  120584. +};
  120585. +
  120586. +/* create a pcm device */
  120587. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip)
  120588. +{
  120589. + struct snd_pcm *pcm;
  120590. + int err;
  120591. +
  120592. + audio_info(" .. IN\n");
  120593. + mutex_init(&chip->audio_mutex);
  120594. + if(mutex_lock_interruptible(&chip->audio_mutex))
  120595. + {
  120596. + audio_error("Interrupted whilst waiting for lock\n");
  120597. + return -EINTR;
  120598. + }
  120599. + err =
  120600. + snd_pcm_new(chip->card, "bcm2835 ALSA", 0, MAX_SUBSTREAMS, 0, &pcm);
  120601. + if (err < 0)
  120602. + return err;
  120603. + pcm->private_data = chip;
  120604. + strcpy(pcm->name, "bcm2835 ALSA");
  120605. + chip->pcm = pcm;
  120606. + chip->dest = AUDIO_DEST_AUTO;
  120607. + chip->volume = alsa2chip(0);
  120608. + chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
  120609. + /* set operators */
  120610. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  120611. + &snd_bcm2835_playback_ops);
  120612. +
  120613. + /* pre-allocation of buffers */
  120614. + /* NOTE: this may fail */
  120615. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  120616. + snd_dma_continuous_data
  120617. + (GFP_KERNEL), 64 * 1024,
  120618. + 64 * 1024);
  120619. +
  120620. + mutex_unlock(&chip->audio_mutex);
  120621. + audio_info(" .. OUT\n");
  120622. +
  120623. + return 0;
  120624. +}
  120625. +
  120626. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip)
  120627. +{
  120628. + struct snd_pcm *pcm;
  120629. + int err;
  120630. +
  120631. + audio_info(" .. IN\n");
  120632. + if(mutex_lock_interruptible(&chip->audio_mutex))
  120633. + {
  120634. + audio_error("Interrupted whilst waiting for lock\n");
  120635. + return -EINTR;
  120636. + }
  120637. + err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
  120638. + if (err < 0)
  120639. + return err;
  120640. +
  120641. + pcm->private_data = chip;
  120642. + strcpy(pcm->name, "bcm2835 IEC958/HDMI");
  120643. + chip->pcm_spdif = pcm;
  120644. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  120645. + &snd_bcm2835_playback_spdif_ops);
  120646. +
  120647. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  120648. + snd_dma_continuous_data (GFP_KERNEL),
  120649. + 64 * 1024, 64 * 1024);
  120650. + mutex_unlock(&chip->audio_mutex);
  120651. + audio_info(" .. OUT\n");
  120652. +
  120653. + return 0;
  120654. +}
  120655. diff -Nur linux-3.18.6/sound/arm/bcm2835-vchiq.c linux-rpi/sound/arm/bcm2835-vchiq.c
  120656. --- linux-3.18.6/sound/arm/bcm2835-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  120657. +++ linux-rpi/sound/arm/bcm2835-vchiq.c 2015-02-09 04:40:47.000000000 +0100
  120658. @@ -0,0 +1,902 @@
  120659. +/*****************************************************************************
  120660. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  120661. +*
  120662. +* Unless you and Broadcom execute a separate written software license
  120663. +* agreement governing use of this software, this software is licensed to you
  120664. +* under the terms of the GNU General Public License version 2, available at
  120665. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  120666. +*
  120667. +* Notwithstanding the above, under no circumstances may you combine this
  120668. +* software in any way with any other Broadcom software provided under a
  120669. +* license other than the GPL, without Broadcom's express prior written
  120670. +* consent.
  120671. +*****************************************************************************/
  120672. +
  120673. +#include <linux/device.h>
  120674. +#include <sound/core.h>
  120675. +#include <sound/initval.h>
  120676. +#include <sound/pcm.h>
  120677. +#include <linux/io.h>
  120678. +#include <linux/interrupt.h>
  120679. +#include <linux/fs.h>
  120680. +#include <linux/file.h>
  120681. +#include <linux/mm.h>
  120682. +#include <linux/syscalls.h>
  120683. +#include <asm/uaccess.h>
  120684. +#include <linux/slab.h>
  120685. +#include <linux/delay.h>
  120686. +#include <linux/atomic.h>
  120687. +#include <linux/module.h>
  120688. +#include <linux/completion.h>
  120689. +
  120690. +#include "bcm2835.h"
  120691. +
  120692. +/* ---- Include Files -------------------------------------------------------- */
  120693. +
  120694. +#include "interface/vchi/vchi.h"
  120695. +#include "vc_vchi_audioserv_defs.h"
  120696. +
  120697. +/* ---- Private Constants and Types ------------------------------------------ */
  120698. +
  120699. +#define BCM2835_AUDIO_STOP 0
  120700. +#define BCM2835_AUDIO_START 1
  120701. +#define BCM2835_AUDIO_WRITE 2
  120702. +
  120703. +/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
  120704. +#ifdef AUDIO_DEBUG_ENABLE
  120705. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  120706. + #define LOG_WARN( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  120707. + #define LOG_INFO( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  120708. + #define LOG_DBG( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  120709. +#else
  120710. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  120711. + #define LOG_WARN( fmt, arg... )
  120712. + #define LOG_INFO( fmt, arg... )
  120713. + #define LOG_DBG( fmt, arg... )
  120714. +#endif
  120715. +
  120716. +typedef struct opaque_AUDIO_INSTANCE_T {
  120717. + uint32_t num_connections;
  120718. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  120719. + struct completion msg_avail_comp;
  120720. + struct mutex vchi_mutex;
  120721. + bcm2835_alsa_stream_t *alsa_stream;
  120722. + int32_t result;
  120723. + short peer_version;
  120724. +} AUDIO_INSTANCE_T;
  120725. +
  120726. +bool force_bulk = false;
  120727. +
  120728. +/* ---- Private Variables ---------------------------------------------------- */
  120729. +
  120730. +/* ---- Private Function Prototypes ------------------------------------------ */
  120731. +
  120732. +/* ---- Private Functions ---------------------------------------------------- */
  120733. +
  120734. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream);
  120735. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream);
  120736. +static int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  120737. + uint32_t count, void *src);
  120738. +
  120739. +typedef struct {
  120740. + struct work_struct my_work;
  120741. + bcm2835_alsa_stream_t *alsa_stream;
  120742. + int cmd;
  120743. + void *src;
  120744. + uint32_t count;
  120745. +} my_work_t;
  120746. +
  120747. +static void my_wq_function(struct work_struct *work)
  120748. +{
  120749. + my_work_t *w = (my_work_t *) work;
  120750. + int ret = -9;
  120751. + LOG_DBG(" .. IN %p:%d\n", w->alsa_stream, w->cmd);
  120752. + switch (w->cmd) {
  120753. + case BCM2835_AUDIO_START:
  120754. + ret = bcm2835_audio_start_worker(w->alsa_stream);
  120755. + break;
  120756. + case BCM2835_AUDIO_STOP:
  120757. + ret = bcm2835_audio_stop_worker(w->alsa_stream);
  120758. + break;
  120759. + case BCM2835_AUDIO_WRITE:
  120760. + ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
  120761. + w->src);
  120762. + break;
  120763. + default:
  120764. + LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
  120765. + break;
  120766. + }
  120767. + kfree((void *)work);
  120768. + LOG_DBG(" .. OUT %d\n", ret);
  120769. +}
  120770. +
  120771. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream)
  120772. +{
  120773. + int ret = -1;
  120774. + LOG_DBG(" .. IN\n");
  120775. + if (alsa_stream->my_wq) {
  120776. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  120777. + /*--- Queue some work (item 1) ---*/
  120778. + if (work) {
  120779. + INIT_WORK((struct work_struct *)work, my_wq_function);
  120780. + work->alsa_stream = alsa_stream;
  120781. + work->cmd = BCM2835_AUDIO_START;
  120782. + if (queue_work
  120783. + (alsa_stream->my_wq, (struct work_struct *)work))
  120784. + ret = 0;
  120785. + } else
  120786. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  120787. + }
  120788. + LOG_DBG(" .. OUT %d\n", ret);
  120789. + return ret;
  120790. +}
  120791. +
  120792. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream)
  120793. +{
  120794. + int ret = -1;
  120795. + LOG_DBG(" .. IN\n");
  120796. + if (alsa_stream->my_wq) {
  120797. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  120798. + /*--- Queue some work (item 1) ---*/
  120799. + if (work) {
  120800. + INIT_WORK((struct work_struct *)work, my_wq_function);
  120801. + work->alsa_stream = alsa_stream;
  120802. + work->cmd = BCM2835_AUDIO_STOP;
  120803. + if (queue_work
  120804. + (alsa_stream->my_wq, (struct work_struct *)work))
  120805. + ret = 0;
  120806. + } else
  120807. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  120808. + }
  120809. + LOG_DBG(" .. OUT %d\n", ret);
  120810. + return ret;
  120811. +}
  120812. +
  120813. +int bcm2835_audio_write(bcm2835_alsa_stream_t *alsa_stream,
  120814. + uint32_t count, void *src)
  120815. +{
  120816. + int ret = -1;
  120817. + LOG_DBG(" .. IN\n");
  120818. + if (alsa_stream->my_wq) {
  120819. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  120820. + /*--- Queue some work (item 1) ---*/
  120821. + if (work) {
  120822. + INIT_WORK((struct work_struct *)work, my_wq_function);
  120823. + work->alsa_stream = alsa_stream;
  120824. + work->cmd = BCM2835_AUDIO_WRITE;
  120825. + work->src = src;
  120826. + work->count = count;
  120827. + if (queue_work
  120828. + (alsa_stream->my_wq, (struct work_struct *)work))
  120829. + ret = 0;
  120830. + } else
  120831. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  120832. + }
  120833. + LOG_DBG(" .. OUT %d\n", ret);
  120834. + return ret;
  120835. +}
  120836. +
  120837. +void my_workqueue_init(bcm2835_alsa_stream_t * alsa_stream)
  120838. +{
  120839. + alsa_stream->my_wq = alloc_workqueue("my_queue", WQ_HIGHPRI, 1);
  120840. + return;
  120841. +}
  120842. +
  120843. +void my_workqueue_quit(bcm2835_alsa_stream_t * alsa_stream)
  120844. +{
  120845. + if (alsa_stream->my_wq) {
  120846. + flush_workqueue(alsa_stream->my_wq);
  120847. + destroy_workqueue(alsa_stream->my_wq);
  120848. + alsa_stream->my_wq = NULL;
  120849. + }
  120850. + return;
  120851. +}
  120852. +
  120853. +static void audio_vchi_callback(void *param,
  120854. + const VCHI_CALLBACK_REASON_T reason,
  120855. + void *msg_handle)
  120856. +{
  120857. + AUDIO_INSTANCE_T *instance = (AUDIO_INSTANCE_T *) param;
  120858. + int32_t status;
  120859. + int32_t msg_len;
  120860. + VC_AUDIO_MSG_T m;
  120861. + LOG_DBG(" .. IN instance=%p, handle=%p, alsa=%p, reason=%d, handle=%p\n",
  120862. + instance, instance ? instance->vchi_handle[0] : NULL, instance ? instance->alsa_stream : NULL, reason, msg_handle);
  120863. +
  120864. + if (reason != VCHI_CALLBACK_MSG_AVAILABLE) {
  120865. + return;
  120866. + }
  120867. + if (!instance) {
  120868. + LOG_ERR(" .. instance is null\n");
  120869. + BUG();
  120870. + return;
  120871. + }
  120872. + if (!instance->vchi_handle[0]) {
  120873. + LOG_ERR(" .. instance->vchi_handle[0] is null\n");
  120874. + BUG();
  120875. + return;
  120876. + }
  120877. + status = vchi_msg_dequeue(instance->vchi_handle[0],
  120878. + &m, sizeof m, &msg_len, VCHI_FLAGS_NONE);
  120879. + if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
  120880. + LOG_DBG
  120881. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
  120882. + instance, m.u.result.success);
  120883. + instance->result = m.u.result.success;
  120884. + complete(&instance->msg_avail_comp);
  120885. + } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
  120886. + bcm2835_alsa_stream_t *alsa_stream = instance->alsa_stream;
  120887. + irq_handler_t callback = (irq_handler_t) m.u.complete.callback;
  120888. + LOG_DBG
  120889. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
  120890. + instance, m.u.complete.count);
  120891. + if (alsa_stream && callback) {
  120892. + atomic_add(m.u.complete.count, &alsa_stream->retrieved);
  120893. + callback(0, alsa_stream);
  120894. + } else {
  120895. + LOG_ERR(" .. unexpected alsa_stream=%p, callback=%p\n",
  120896. + alsa_stream, callback);
  120897. + }
  120898. + } else {
  120899. + LOG_ERR(" .. unexpected m.type=%d\n", m.type);
  120900. + }
  120901. + LOG_DBG(" .. OUT\n");
  120902. +}
  120903. +
  120904. +static AUDIO_INSTANCE_T *vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
  120905. + VCHI_CONNECTION_T **
  120906. + vchi_connections,
  120907. + uint32_t num_connections)
  120908. +{
  120909. + uint32_t i;
  120910. + AUDIO_INSTANCE_T *instance;
  120911. + int status;
  120912. +
  120913. + LOG_DBG("%s: start", __func__);
  120914. +
  120915. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  120916. + LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
  120917. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  120918. +
  120919. + return NULL;
  120920. + }
  120921. + /* Allocate memory for this instance */
  120922. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  120923. + if (!instance)
  120924. + return NULL;
  120925. +
  120926. + memset(instance, 0, sizeof(*instance));
  120927. + instance->num_connections = num_connections;
  120928. +
  120929. + /* Create a lock for exclusive, serialized VCHI connection access */
  120930. + mutex_init(&instance->vchi_mutex);
  120931. + /* Open the VCHI service connections */
  120932. + for (i = 0; i < num_connections; i++) {
  120933. + SERVICE_CREATION_T params = {
  120934. + VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
  120935. + VC_AUDIO_SERVER_NAME, // 4cc service code
  120936. + vchi_connections[i], // passed in fn pointers
  120937. + 0, // rx fifo size (unused)
  120938. + 0, // tx fifo size (unused)
  120939. + audio_vchi_callback, // service callback
  120940. + instance, // service callback parameter
  120941. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk recieves
  120942. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
  120943. + 0 // want crc check on bulk transfers
  120944. + };
  120945. +
  120946. + LOG_DBG("%s: about to open %i\n", __func__, i);
  120947. + status = vchi_service_open(vchi_instance, &params,
  120948. + &instance->vchi_handle[i]);
  120949. + LOG_DBG("%s: opened %i: %p=%d\n", __func__, i, instance->vchi_handle[i], status);
  120950. + if (status) {
  120951. + LOG_ERR
  120952. + ("%s: failed to open VCHI service connection (status=%d)\n",
  120953. + __func__, status);
  120954. +
  120955. + goto err_close_services;
  120956. + }
  120957. + /* Finished with the service for now */
  120958. + vchi_service_release(instance->vchi_handle[i]);
  120959. + }
  120960. +
  120961. + LOG_DBG("%s: okay\n", __func__);
  120962. + return instance;
  120963. +
  120964. +err_close_services:
  120965. + for (i = 0; i < instance->num_connections; i++) {
  120966. + LOG_ERR("%s: closing %i: %p\n", __func__, i, instance->vchi_handle[i]);
  120967. + if (instance->vchi_handle[i])
  120968. + vchi_service_close(instance->vchi_handle[i]);
  120969. + }
  120970. +
  120971. + kfree(instance);
  120972. + LOG_ERR("%s: error\n", __func__);
  120973. +
  120974. + return NULL;
  120975. +}
  120976. +
  120977. +static int32_t vc_vchi_audio_deinit(AUDIO_INSTANCE_T * instance)
  120978. +{
  120979. + uint32_t i;
  120980. +
  120981. + LOG_DBG(" .. IN\n");
  120982. +
  120983. + if (instance == NULL) {
  120984. + LOG_ERR("%s: invalid handle %p\n", __func__, instance);
  120985. +
  120986. + return -1;
  120987. + }
  120988. +
  120989. + LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
  120990. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  120991. + {
  120992. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  120993. + return -EINTR;
  120994. + }
  120995. +
  120996. + /* Close all VCHI service connections */
  120997. + for (i = 0; i < instance->num_connections; i++) {
  120998. + int32_t success;
  120999. + LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
  121000. + vchi_service_use(instance->vchi_handle[i]);
  121001. +
  121002. + success = vchi_service_close(instance->vchi_handle[i]);
  121003. + if (success != 0) {
  121004. + LOG_ERR
  121005. + ("%s: failed to close VCHI service connection (status=%d)\n",
  121006. + __func__, success);
  121007. + }
  121008. + }
  121009. +
  121010. + mutex_unlock(&instance->vchi_mutex);
  121011. +
  121012. + kfree(instance);
  121013. +
  121014. + LOG_DBG(" .. OUT\n");
  121015. +
  121016. + return 0;
  121017. +}
  121018. +
  121019. +static int bcm2835_audio_open_connection(bcm2835_alsa_stream_t * alsa_stream)
  121020. +{
  121021. + static VCHI_INSTANCE_T vchi_instance;
  121022. + static VCHI_CONNECTION_T *vchi_connection;
  121023. + static int initted;
  121024. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  121025. + int ret;
  121026. + LOG_DBG(" .. IN\n");
  121027. +
  121028. + LOG_INFO("%s: start\n", __func__);
  121029. + BUG_ON(instance);
  121030. + if (instance) {
  121031. + LOG_ERR("%s: VCHI instance already open (%p)\n",
  121032. + __func__, instance);
  121033. + instance->alsa_stream = alsa_stream;
  121034. + alsa_stream->instance = instance;
  121035. + ret = 0; // xxx todo -1;
  121036. + goto err_free_mem;
  121037. + }
  121038. +
  121039. + /* Initialize and create a VCHI connection */
  121040. + if (!initted) {
  121041. + ret = vchi_initialise(&vchi_instance);
  121042. + if (ret != 0) {
  121043. + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n",
  121044. + __func__, ret);
  121045. +
  121046. + ret = -EIO;
  121047. + goto err_free_mem;
  121048. + }
  121049. + ret = vchi_connect(NULL, 0, vchi_instance);
  121050. + if (ret != 0) {
  121051. + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n",
  121052. + __func__, ret);
  121053. +
  121054. + ret = -EIO;
  121055. + goto err_free_mem;
  121056. + }
  121057. + initted = 1;
  121058. + }
  121059. +
  121060. + /* Initialize an instance of the audio service */
  121061. + instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
  121062. +
  121063. + if (instance == NULL) {
  121064. + LOG_ERR("%s: failed to initialize audio service\n", __func__);
  121065. +
  121066. + ret = -EPERM;
  121067. + goto err_free_mem;
  121068. + }
  121069. +
  121070. + instance->alsa_stream = alsa_stream;
  121071. + alsa_stream->instance = instance;
  121072. +
  121073. + LOG_DBG(" success !\n");
  121074. +err_free_mem:
  121075. + LOG_DBG(" .. OUT\n");
  121076. +
  121077. + return ret;
  121078. +}
  121079. +
  121080. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream)
  121081. +{
  121082. + AUDIO_INSTANCE_T *instance;
  121083. + VC_AUDIO_MSG_T m;
  121084. + int32_t success;
  121085. + int ret;
  121086. + LOG_DBG(" .. IN\n");
  121087. +
  121088. + my_workqueue_init(alsa_stream);
  121089. +
  121090. + ret = bcm2835_audio_open_connection(alsa_stream);
  121091. + if (ret != 0) {
  121092. + ret = -1;
  121093. + goto exit;
  121094. + }
  121095. + instance = alsa_stream->instance;
  121096. + LOG_DBG(" instance (%p)\n", instance);
  121097. +
  121098. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  121099. + {
  121100. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  121101. + return -EINTR;
  121102. + }
  121103. + vchi_service_use(instance->vchi_handle[0]);
  121104. +
  121105. + m.type = VC_AUDIO_MSG_TYPE_OPEN;
  121106. +
  121107. + /* Send the message to the videocore */
  121108. + success = vchi_msg_queue(instance->vchi_handle[0],
  121109. + &m, sizeof m,
  121110. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  121111. +
  121112. + if (success != 0) {
  121113. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  121114. + __func__, success);
  121115. +
  121116. + ret = -1;
  121117. + goto unlock;
  121118. + }
  121119. +
  121120. + ret = 0;
  121121. +
  121122. +unlock:
  121123. + vchi_service_release(instance->vchi_handle[0]);
  121124. + mutex_unlock(&instance->vchi_mutex);
  121125. +exit:
  121126. + LOG_DBG(" .. OUT\n");
  121127. + return ret;
  121128. +}
  121129. +
  121130. +static int bcm2835_audio_set_ctls_chan(bcm2835_alsa_stream_t * alsa_stream,
  121131. + bcm2835_chip_t * chip)
  121132. +{
  121133. + VC_AUDIO_MSG_T m;
  121134. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  121135. + int32_t success;
  121136. + int ret;
  121137. + LOG_DBG(" .. IN\n");
  121138. +
  121139. + LOG_INFO
  121140. + (" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  121141. +
  121142. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  121143. + {
  121144. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  121145. + return -EINTR;
  121146. + }
  121147. + vchi_service_use(instance->vchi_handle[0]);
  121148. +
  121149. + instance->result = -1;
  121150. +
  121151. + m.type = VC_AUDIO_MSG_TYPE_CONTROL;
  121152. + m.u.control.dest = chip->dest;
  121153. + m.u.control.volume = chip->volume;
  121154. +
  121155. + /* Create the message available completion */
  121156. + init_completion(&instance->msg_avail_comp);
  121157. +
  121158. + /* Send the message to the videocore */
  121159. + success = vchi_msg_queue(instance->vchi_handle[0],
  121160. + &m, sizeof m,
  121161. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  121162. +
  121163. + if (success != 0) {
  121164. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  121165. + __func__, success);
  121166. +
  121167. + ret = -1;
  121168. + goto unlock;
  121169. + }
  121170. +
  121171. + /* We are expecting a reply from the videocore */
  121172. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  121173. + if (ret) {
  121174. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  121175. + __func__, success);
  121176. + goto unlock;
  121177. + }
  121178. +
  121179. + if (instance->result != 0) {
  121180. + LOG_ERR("%s: result=%d\n", __func__, instance->result);
  121181. +
  121182. + ret = -1;
  121183. + goto unlock;
  121184. + }
  121185. +
  121186. + ret = 0;
  121187. +
  121188. +unlock:
  121189. + vchi_service_release(instance->vchi_handle[0]);
  121190. + mutex_unlock(&instance->vchi_mutex);
  121191. +
  121192. + LOG_DBG(" .. OUT\n");
  121193. + return ret;
  121194. +}
  121195. +
  121196. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip)
  121197. +{
  121198. + int i;
  121199. + int ret = 0;
  121200. + LOG_DBG(" .. IN\n");
  121201. + LOG_DBG(" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  121202. +
  121203. + /* change ctls for all substreams */
  121204. + for (i = 0; i < MAX_SUBSTREAMS; i++) {
  121205. + if (chip->avail_substreams & (1 << i)) {
  121206. + if (!chip->alsa_stream[i])
  121207. + {
  121208. + LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
  121209. + ret = 0;
  121210. + }
  121211. + else if (bcm2835_audio_set_ctls_chan /* returns 0 on success */
  121212. + (chip->alsa_stream[i], chip) != 0)
  121213. + {
  121214. + LOG_ERR("Couldn't set the controls for stream %d\n", i);
  121215. + ret = -1;
  121216. + }
  121217. + else LOG_DBG(" Controls set for stream %d\n", i);
  121218. + }
  121219. + }
  121220. + LOG_DBG(" .. OUT ret=%d\n", ret);
  121221. + return ret;
  121222. +}
  121223. +
  121224. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  121225. + uint32_t channels, uint32_t samplerate,
  121226. + uint32_t bps)
  121227. +{
  121228. + VC_AUDIO_MSG_T m;
  121229. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  121230. + int32_t success;
  121231. + int ret;
  121232. + LOG_DBG(" .. IN\n");
  121233. +
  121234. + LOG_INFO
  121235. + (" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n",
  121236. + channels, samplerate, bps);
  121237. +
  121238. + /* resend ctls - alsa_stream may not have been open when first send */
  121239. + ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip);
  121240. + if (ret != 0) {
  121241. + LOG_ERR(" Alsa controls not supported\n");
  121242. + return -EINVAL;
  121243. + }
  121244. +
  121245. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  121246. + {
  121247. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  121248. + return -EINTR;
  121249. + }
  121250. + vchi_service_use(instance->vchi_handle[0]);
  121251. +
  121252. + instance->result = -1;
  121253. +
  121254. + m.type = VC_AUDIO_MSG_TYPE_CONFIG;
  121255. + m.u.config.channels = channels;
  121256. + m.u.config.samplerate = samplerate;
  121257. + m.u.config.bps = bps;
  121258. +
  121259. + /* Create the message available completion */
  121260. + init_completion(&instance->msg_avail_comp);
  121261. +
  121262. + /* Send the message to the videocore */
  121263. + success = vchi_msg_queue(instance->vchi_handle[0],
  121264. + &m, sizeof m,
  121265. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  121266. +
  121267. + if (success != 0) {
  121268. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  121269. + __func__, success);
  121270. +
  121271. + ret = -1;
  121272. + goto unlock;
  121273. + }
  121274. +
  121275. + /* We are expecting a reply from the videocore */
  121276. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  121277. + if (ret) {
  121278. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  121279. + __func__, success);
  121280. + goto unlock;
  121281. + }
  121282. +
  121283. + if (instance->result != 0) {
  121284. + LOG_ERR("%s: result=%d", __func__, instance->result);
  121285. +
  121286. + ret = -1;
  121287. + goto unlock;
  121288. + }
  121289. +
  121290. + ret = 0;
  121291. +
  121292. +unlock:
  121293. + vchi_service_release(instance->vchi_handle[0]);
  121294. + mutex_unlock(&instance->vchi_mutex);
  121295. +
  121296. + LOG_DBG(" .. OUT\n");
  121297. + return ret;
  121298. +}
  121299. +
  121300. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream)
  121301. +{
  121302. + LOG_DBG(" .. IN\n");
  121303. +
  121304. + LOG_DBG(" .. OUT\n");
  121305. +
  121306. + return 0;
  121307. +}
  121308. +
  121309. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream)
  121310. +{
  121311. + VC_AUDIO_MSG_T m;
  121312. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  121313. + int32_t success;
  121314. + int ret;
  121315. + LOG_DBG(" .. IN\n");
  121316. +
  121317. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  121318. + {
  121319. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  121320. + return -EINTR;
  121321. + }
  121322. + vchi_service_use(instance->vchi_handle[0]);
  121323. +
  121324. + m.type = VC_AUDIO_MSG_TYPE_START;
  121325. +
  121326. + /* Send the message to the videocore */
  121327. + success = vchi_msg_queue(instance->vchi_handle[0],
  121328. + &m, sizeof m,
  121329. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  121330. +
  121331. + if (success != 0) {
  121332. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  121333. + __func__, success);
  121334. +
  121335. + ret = -1;
  121336. + goto unlock;
  121337. + }
  121338. +
  121339. + ret = 0;
  121340. +
  121341. +unlock:
  121342. + vchi_service_release(instance->vchi_handle[0]);
  121343. + mutex_unlock(&instance->vchi_mutex);
  121344. + LOG_DBG(" .. OUT\n");
  121345. + return ret;
  121346. +}
  121347. +
  121348. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream)
  121349. +{
  121350. + VC_AUDIO_MSG_T m;
  121351. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  121352. + int32_t success;
  121353. + int ret;
  121354. + LOG_DBG(" .. IN\n");
  121355. +
  121356. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  121357. + {
  121358. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  121359. + return -EINTR;
  121360. + }
  121361. + vchi_service_use(instance->vchi_handle[0]);
  121362. +
  121363. + m.type = VC_AUDIO_MSG_TYPE_STOP;
  121364. + m.u.stop.draining = alsa_stream->draining;
  121365. +
  121366. + /* Send the message to the videocore */
  121367. + success = vchi_msg_queue(instance->vchi_handle[0],
  121368. + &m, sizeof m,
  121369. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  121370. +
  121371. + if (success != 0) {
  121372. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  121373. + __func__, success);
  121374. +
  121375. + ret = -1;
  121376. + goto unlock;
  121377. + }
  121378. +
  121379. + ret = 0;
  121380. +
  121381. +unlock:
  121382. + vchi_service_release(instance->vchi_handle[0]);
  121383. + mutex_unlock(&instance->vchi_mutex);
  121384. + LOG_DBG(" .. OUT\n");
  121385. + return ret;
  121386. +}
  121387. +
  121388. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream)
  121389. +{
  121390. + VC_AUDIO_MSG_T m;
  121391. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  121392. + int32_t success;
  121393. + int ret;
  121394. + LOG_DBG(" .. IN\n");
  121395. +
  121396. + my_workqueue_quit(alsa_stream);
  121397. +
  121398. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  121399. + {
  121400. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  121401. + return -EINTR;
  121402. + }
  121403. + vchi_service_use(instance->vchi_handle[0]);
  121404. +
  121405. + m.type = VC_AUDIO_MSG_TYPE_CLOSE;
  121406. +
  121407. + /* Create the message available completion */
  121408. + init_completion(&instance->msg_avail_comp);
  121409. +
  121410. + /* Send the message to the videocore */
  121411. + success = vchi_msg_queue(instance->vchi_handle[0],
  121412. + &m, sizeof m,
  121413. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  121414. +
  121415. + if (success != 0) {
  121416. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  121417. + __func__, success);
  121418. + ret = -1;
  121419. + goto unlock;
  121420. + }
  121421. +
  121422. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  121423. + if (ret) {
  121424. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  121425. + __func__, success);
  121426. + goto unlock;
  121427. + }
  121428. + if (instance->result != 0) {
  121429. + LOG_ERR("%s: failed result (status=%d)\n",
  121430. + __func__, instance->result);
  121431. +
  121432. + ret = -1;
  121433. + goto unlock;
  121434. + }
  121435. +
  121436. + ret = 0;
  121437. +
  121438. +unlock:
  121439. + vchi_service_release(instance->vchi_handle[0]);
  121440. + mutex_unlock(&instance->vchi_mutex);
  121441. +
  121442. + /* Stop the audio service */
  121443. + if (instance) {
  121444. + vc_vchi_audio_deinit(instance);
  121445. + alsa_stream->instance = NULL;
  121446. + }
  121447. + LOG_DBG(" .. OUT\n");
  121448. + return ret;
  121449. +}
  121450. +
  121451. +int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  121452. + uint32_t count, void *src)
  121453. +{
  121454. + VC_AUDIO_MSG_T m;
  121455. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  121456. + int32_t success;
  121457. + int ret;
  121458. +
  121459. + LOG_DBG(" .. IN\n");
  121460. +
  121461. + LOG_INFO(" Writing %d bytes from %p\n", count, src);
  121462. +
  121463. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  121464. + {
  121465. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  121466. + return -EINTR;
  121467. + }
  121468. + vchi_service_use(instance->vchi_handle[0]);
  121469. +
  121470. + if ( instance->peer_version==0 && vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0 ) {
  121471. + LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
  121472. + }
  121473. + m.type = VC_AUDIO_MSG_TYPE_WRITE;
  121474. + m.u.write.count = count;
  121475. + // old version uses bulk, new version uses control
  121476. + m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0:4000;
  121477. + m.u.write.callback = alsa_stream->fifo_irq_handler;
  121478. + m.u.write.cookie = alsa_stream;
  121479. + m.u.write.silence = src == NULL;
  121480. +
  121481. + /* Send the message to the videocore */
  121482. + success = vchi_msg_queue(instance->vchi_handle[0],
  121483. + &m, sizeof m,
  121484. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  121485. +
  121486. + if (success != 0) {
  121487. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  121488. + __func__, success);
  121489. +
  121490. + ret = -1;
  121491. + goto unlock;
  121492. + }
  121493. + if (!m.u.write.silence) {
  121494. + if (m.u.write.max_packet == 0) {
  121495. + /* Send the message to the videocore */
  121496. + success = vchi_bulk_queue_transmit(instance->vchi_handle[0],
  121497. + src, count,
  121498. + 0 *
  121499. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED
  121500. + +
  121501. + 1 *
  121502. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
  121503. + NULL);
  121504. + } else {
  121505. + while (count > 0) {
  121506. + int bytes = min((int)m.u.write.max_packet, (int)count);
  121507. + success = vchi_msg_queue(instance->vchi_handle[0],
  121508. + src, bytes,
  121509. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  121510. + src = (char *)src + bytes;
  121511. + count -= bytes;
  121512. + }
  121513. + }
  121514. + if (success != 0) {
  121515. + LOG_ERR
  121516. + ("%s: failed on vchi_bulk_queue_transmit (status=%d)\n",
  121517. + __func__, success);
  121518. +
  121519. + ret = -1;
  121520. + goto unlock;
  121521. + }
  121522. + }
  121523. + ret = 0;
  121524. +
  121525. +unlock:
  121526. + vchi_service_release(instance->vchi_handle[0]);
  121527. + mutex_unlock(&instance->vchi_mutex);
  121528. + LOG_DBG(" .. OUT\n");
  121529. + return ret;
  121530. +}
  121531. +
  121532. +/**
  121533. + * Returns all buffers from arm->vc
  121534. + */
  121535. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream)
  121536. +{
  121537. + LOG_DBG(" .. IN\n");
  121538. + LOG_DBG(" .. OUT\n");
  121539. + return;
  121540. +}
  121541. +
  121542. +/**
  121543. + * Forces VC to flush(drop) its filled playback buffers and
  121544. + * return them the us. (VC->ARM)
  121545. + */
  121546. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream)
  121547. +{
  121548. + LOG_DBG(" .. IN\n");
  121549. + LOG_DBG(" .. OUT\n");
  121550. +}
  121551. +
  121552. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream)
  121553. +{
  121554. + uint32_t count = atomic_read(&alsa_stream->retrieved);
  121555. + atomic_sub(count, &alsa_stream->retrieved);
  121556. + return count;
  121557. +}
  121558. +
  121559. +module_param(force_bulk, bool, 0444);
  121560. +MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
  121561. diff -Nur linux-3.18.6/sound/arm/Kconfig linux-rpi/sound/arm/Kconfig
  121562. --- linux-3.18.6/sound/arm/Kconfig 2015-02-06 15:53:48.000000000 +0100
  121563. +++ linux-rpi/sound/arm/Kconfig 2015-02-09 04:40:47.000000000 +0100
  121564. @@ -39,5 +39,12 @@
  121565. Say Y or M if you want to support any AC97 codec attached to
  121566. the PXA2xx AC97 interface.
  121567. +config SND_BCM2835
  121568. + tristate "BCM2835 ALSA driver"
  121569. + depends on (ARCH_BCM2708 || ARCH_BCM2709) && BCM2708_VCHIQ && SND
  121570. + select SND_PCM
  121571. + help
  121572. + Say Y or M if you want to support BCM2835 Alsa pcm card driver
  121573. +
  121574. endif # SND_ARM
  121575. diff -Nur linux-3.18.6/sound/arm/Makefile linux-rpi/sound/arm/Makefile
  121576. --- linux-3.18.6/sound/arm/Makefile 2015-02-06 15:53:48.000000000 +0100
  121577. +++ linux-rpi/sound/arm/Makefile 2015-02-09 04:40:47.000000000 +0100
  121578. @@ -14,3 +14,8 @@
  121579. obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o
  121580. snd-pxa2xx-ac97-objs := pxa2xx-ac97.o
  121581. +
  121582. +obj-$(CONFIG_SND_BCM2835) += snd-bcm2835.o
  121583. +snd-bcm2835-objs := bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
  121584. +
  121585. +ccflags-y += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  121586. diff -Nur linux-3.18.6/sound/arm/vc_vchi_audioserv_defs.h linux-rpi/sound/arm/vc_vchi_audioserv_defs.h
  121587. --- linux-3.18.6/sound/arm/vc_vchi_audioserv_defs.h 1970-01-01 01:00:00.000000000 +0100
  121588. +++ linux-rpi/sound/arm/vc_vchi_audioserv_defs.h 2015-02-09 04:40:47.000000000 +0100
  121589. @@ -0,0 +1,116 @@
  121590. +/*****************************************************************************
  121591. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  121592. +*
  121593. +* Unless you and Broadcom execute a separate written software license
  121594. +* agreement governing use of this software, this software is licensed to you
  121595. +* under the terms of the GNU General Public License version 2, available at
  121596. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  121597. +*
  121598. +* Notwithstanding the above, under no circumstances may you combine this
  121599. +* software in any way with any other Broadcom software provided under a
  121600. +* license other than the GPL, without Broadcom's express prior written
  121601. +* consent.
  121602. +*****************************************************************************/
  121603. +
  121604. +#ifndef _VC_AUDIO_DEFS_H_
  121605. +#define _VC_AUDIO_DEFS_H_
  121606. +
  121607. +#define VC_AUDIOSERV_MIN_VER 1
  121608. +#define VC_AUDIOSERV_VER 2
  121609. +
  121610. +// FourCC code used for VCHI connection
  121611. +#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
  121612. +
  121613. +// Maximum message length
  121614. +#define VC_AUDIO_MAX_MSG_LEN (sizeof( VC_AUDIO_MSG_T ))
  121615. +
  121616. +// List of screens that are currently supported
  121617. +// All message types supported for HOST->VC direction
  121618. +typedef enum {
  121619. + VC_AUDIO_MSG_TYPE_RESULT, // Generic result
  121620. + VC_AUDIO_MSG_TYPE_COMPLETE, // Generic result
  121621. + VC_AUDIO_MSG_TYPE_CONFIG, // Configure audio
  121622. + VC_AUDIO_MSG_TYPE_CONTROL, // Configure audio
  121623. + VC_AUDIO_MSG_TYPE_OPEN, // Configure audio
  121624. + VC_AUDIO_MSG_TYPE_CLOSE, // Configure audio
  121625. + VC_AUDIO_MSG_TYPE_START, // Configure audio
  121626. + VC_AUDIO_MSG_TYPE_STOP, // Configure audio
  121627. + VC_AUDIO_MSG_TYPE_WRITE, // Configure audio
  121628. + VC_AUDIO_MSG_TYPE_MAX
  121629. +} VC_AUDIO_MSG_TYPE;
  121630. +
  121631. +// configure the audio
  121632. +typedef struct {
  121633. + uint32_t channels;
  121634. + uint32_t samplerate;
  121635. + uint32_t bps;
  121636. +
  121637. +} VC_AUDIO_CONFIG_T;
  121638. +
  121639. +typedef struct {
  121640. + uint32_t volume;
  121641. + uint32_t dest;
  121642. +
  121643. +} VC_AUDIO_CONTROL_T;
  121644. +
  121645. +// audio
  121646. +typedef struct {
  121647. + uint32_t dummy;
  121648. +
  121649. +} VC_AUDIO_OPEN_T;
  121650. +
  121651. +// audio
  121652. +typedef struct {
  121653. + uint32_t dummy;
  121654. +
  121655. +} VC_AUDIO_CLOSE_T;
  121656. +// audio
  121657. +typedef struct {
  121658. + uint32_t dummy;
  121659. +
  121660. +} VC_AUDIO_START_T;
  121661. +// audio
  121662. +typedef struct {
  121663. + uint32_t draining;
  121664. +
  121665. +} VC_AUDIO_STOP_T;
  121666. +
  121667. +// configure the write audio samples
  121668. +typedef struct {
  121669. + uint32_t count; // in bytes
  121670. + void *callback;
  121671. + void *cookie;
  121672. + uint16_t silence;
  121673. + uint16_t max_packet;
  121674. +} VC_AUDIO_WRITE_T;
  121675. +
  121676. +// Generic result for a request (VC->HOST)
  121677. +typedef struct {
  121678. + int32_t success; // Success value
  121679. +
  121680. +} VC_AUDIO_RESULT_T;
  121681. +
  121682. +// Generic result for a request (VC->HOST)
  121683. +typedef struct {
  121684. + int32_t count; // Success value
  121685. + void *callback;
  121686. + void *cookie;
  121687. +} VC_AUDIO_COMPLETE_T;
  121688. +
  121689. +// Message header for all messages in HOST->VC direction
  121690. +typedef struct {
  121691. + int32_t type; // Message type (VC_AUDIO_MSG_TYPE)
  121692. + union {
  121693. + VC_AUDIO_CONFIG_T config;
  121694. + VC_AUDIO_CONTROL_T control;
  121695. + VC_AUDIO_OPEN_T open;
  121696. + VC_AUDIO_CLOSE_T close;
  121697. + VC_AUDIO_START_T start;
  121698. + VC_AUDIO_STOP_T stop;
  121699. + VC_AUDIO_WRITE_T write;
  121700. + VC_AUDIO_RESULT_T result;
  121701. + VC_AUDIO_COMPLETE_T complete;
  121702. + } u;
  121703. +} VC_AUDIO_MSG_T;
  121704. +
  121705. +#endif // _VC_AUDIO_DEFS_H_
  121706. diff -Nur linux-3.18.6/sound/soc/bcm/bcm2708-i2s.c linux-rpi/sound/soc/bcm/bcm2708-i2s.c
  121707. --- linux-3.18.6/sound/soc/bcm/bcm2708-i2s.c 1970-01-01 01:00:00.000000000 +0100
  121708. +++ linux-rpi/sound/soc/bcm/bcm2708-i2s.c 2015-02-09 04:40:48.000000000 +0100
  121709. @@ -0,0 +1,1009 @@
  121710. +/*
  121711. + * ALSA SoC I2S Audio Layer for Broadcom BCM2708 SoC
  121712. + *
  121713. + * Author: Florian Meier <florian.meier@koalo.de>
  121714. + * Copyright 2013
  121715. + *
  121716. + * Based on
  121717. + * Raspberry Pi PCM I2S ALSA Driver
  121718. + * Copyright (c) by Phil Poole 2013
  121719. + *
  121720. + * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
  121721. + * Vladimir Barinov, <vbarinov@embeddedalley.com>
  121722. + * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  121723. + *
  121724. + * OMAP ALSA SoC DAI driver using McBSP port
  121725. + * Copyright (C) 2008 Nokia Corporation
  121726. + * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
  121727. + * Peter Ujfalusi <peter.ujfalusi@ti.com>
  121728. + *
  121729. + * Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
  121730. + * Author: Timur Tabi <timur@freescale.com>
  121731. + * Copyright 2007-2010 Freescale Semiconductor, Inc.
  121732. + *
  121733. + * This program is free software; you can redistribute it and/or
  121734. + * modify it under the terms of the GNU General Public License
  121735. + * version 2 as published by the Free Software Foundation.
  121736. + *
  121737. + * This program is distributed in the hope that it will be useful, but
  121738. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  121739. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  121740. + * General Public License for more details.
  121741. + */
  121742. +
  121743. +#include "bcm2708-i2s.h"
  121744. +
  121745. +#include <linux/init.h>
  121746. +#include <linux/module.h>
  121747. +#include <linux/device.h>
  121748. +#include <linux/slab.h>
  121749. +#include <linux/delay.h>
  121750. +#include <linux/io.h>
  121751. +#include <linux/clk.h>
  121752. +#include <mach/gpio.h>
  121753. +
  121754. +#include <sound/core.h>
  121755. +#include <sound/pcm.h>
  121756. +#include <sound/pcm_params.h>
  121757. +#include <sound/initval.h>
  121758. +#include <sound/soc.h>
  121759. +#include <sound/dmaengine_pcm.h>
  121760. +
  121761. +#include <asm/system_info.h>
  121762. +
  121763. +/* Clock registers */
  121764. +#define BCM2708_CLK_PCMCTL_REG 0x00
  121765. +#define BCM2708_CLK_PCMDIV_REG 0x04
  121766. +
  121767. +/* Clock register settings */
  121768. +#define BCM2708_CLK_PASSWD (0x5a000000)
  121769. +#define BCM2708_CLK_PASSWD_MASK (0xff000000)
  121770. +#define BCM2708_CLK_MASH(v) ((v) << 9)
  121771. +#define BCM2708_CLK_FLIP BIT(8)
  121772. +#define BCM2708_CLK_BUSY BIT(7)
  121773. +#define BCM2708_CLK_KILL BIT(5)
  121774. +#define BCM2708_CLK_ENAB BIT(4)
  121775. +#define BCM2708_CLK_SRC(v) (v)
  121776. +
  121777. +#define BCM2708_CLK_SHIFT (12)
  121778. +#define BCM2708_CLK_DIVI(v) ((v) << BCM2708_CLK_SHIFT)
  121779. +#define BCM2708_CLK_DIVF(v) (v)
  121780. +#define BCM2708_CLK_DIVF_MASK (0xFFF)
  121781. +
  121782. +enum {
  121783. + BCM2708_CLK_MASH_0 = 0,
  121784. + BCM2708_CLK_MASH_1,
  121785. + BCM2708_CLK_MASH_2,
  121786. + BCM2708_CLK_MASH_3,
  121787. +};
  121788. +
  121789. +enum {
  121790. + BCM2708_CLK_SRC_GND = 0,
  121791. + BCM2708_CLK_SRC_OSC,
  121792. + BCM2708_CLK_SRC_DBG0,
  121793. + BCM2708_CLK_SRC_DBG1,
  121794. + BCM2708_CLK_SRC_PLLA,
  121795. + BCM2708_CLK_SRC_PLLC,
  121796. + BCM2708_CLK_SRC_PLLD,
  121797. + BCM2708_CLK_SRC_HDMI,
  121798. +};
  121799. +
  121800. +/* Most clocks are not useable (freq = 0) */
  121801. +static const unsigned int bcm2708_clk_freq[BCM2708_CLK_SRC_HDMI+1] = {
  121802. + [BCM2708_CLK_SRC_GND] = 0,
  121803. + [BCM2708_CLK_SRC_OSC] = 19200000,
  121804. + [BCM2708_CLK_SRC_DBG0] = 0,
  121805. + [BCM2708_CLK_SRC_DBG1] = 0,
  121806. + [BCM2708_CLK_SRC_PLLA] = 0,
  121807. + [BCM2708_CLK_SRC_PLLC] = 0,
  121808. + [BCM2708_CLK_SRC_PLLD] = 500000000,
  121809. + [BCM2708_CLK_SRC_HDMI] = 0,
  121810. +};
  121811. +
  121812. +/* I2S registers */
  121813. +#define BCM2708_I2S_CS_A_REG 0x00
  121814. +#define BCM2708_I2S_FIFO_A_REG 0x04
  121815. +#define BCM2708_I2S_MODE_A_REG 0x08
  121816. +#define BCM2708_I2S_RXC_A_REG 0x0c
  121817. +#define BCM2708_I2S_TXC_A_REG 0x10
  121818. +#define BCM2708_I2S_DREQ_A_REG 0x14
  121819. +#define BCM2708_I2S_INTEN_A_REG 0x18
  121820. +#define BCM2708_I2S_INTSTC_A_REG 0x1c
  121821. +#define BCM2708_I2S_GRAY_REG 0x20
  121822. +
  121823. +/* I2S register settings */
  121824. +#define BCM2708_I2S_STBY BIT(25)
  121825. +#define BCM2708_I2S_SYNC BIT(24)
  121826. +#define BCM2708_I2S_RXSEX BIT(23)
  121827. +#define BCM2708_I2S_RXF BIT(22)
  121828. +#define BCM2708_I2S_TXE BIT(21)
  121829. +#define BCM2708_I2S_RXD BIT(20)
  121830. +#define BCM2708_I2S_TXD BIT(19)
  121831. +#define BCM2708_I2S_RXR BIT(18)
  121832. +#define BCM2708_I2S_TXW BIT(17)
  121833. +#define BCM2708_I2S_CS_RXERR BIT(16)
  121834. +#define BCM2708_I2S_CS_TXERR BIT(15)
  121835. +#define BCM2708_I2S_RXSYNC BIT(14)
  121836. +#define BCM2708_I2S_TXSYNC BIT(13)
  121837. +#define BCM2708_I2S_DMAEN BIT(9)
  121838. +#define BCM2708_I2S_RXTHR(v) ((v) << 7)
  121839. +#define BCM2708_I2S_TXTHR(v) ((v) << 5)
  121840. +#define BCM2708_I2S_RXCLR BIT(4)
  121841. +#define BCM2708_I2S_TXCLR BIT(3)
  121842. +#define BCM2708_I2S_TXON BIT(2)
  121843. +#define BCM2708_I2S_RXON BIT(1)
  121844. +#define BCM2708_I2S_EN (1)
  121845. +
  121846. +#define BCM2708_I2S_CLKDIS BIT(28)
  121847. +#define BCM2708_I2S_PDMN BIT(27)
  121848. +#define BCM2708_I2S_PDME BIT(26)
  121849. +#define BCM2708_I2S_FRXP BIT(25)
  121850. +#define BCM2708_I2S_FTXP BIT(24)
  121851. +#define BCM2708_I2S_CLKM BIT(23)
  121852. +#define BCM2708_I2S_CLKI BIT(22)
  121853. +#define BCM2708_I2S_FSM BIT(21)
  121854. +#define BCM2708_I2S_FSI BIT(20)
  121855. +#define BCM2708_I2S_FLEN(v) ((v) << 10)
  121856. +#define BCM2708_I2S_FSLEN(v) (v)
  121857. +
  121858. +#define BCM2708_I2S_CHWEX BIT(15)
  121859. +#define BCM2708_I2S_CHEN BIT(14)
  121860. +#define BCM2708_I2S_CHPOS(v) ((v) << 4)
  121861. +#define BCM2708_I2S_CHWID(v) (v)
  121862. +#define BCM2708_I2S_CH1(v) ((v) << 16)
  121863. +#define BCM2708_I2S_CH2(v) (v)
  121864. +
  121865. +#define BCM2708_I2S_TX_PANIC(v) ((v) << 24)
  121866. +#define BCM2708_I2S_RX_PANIC(v) ((v) << 16)
  121867. +#define BCM2708_I2S_TX(v) ((v) << 8)
  121868. +#define BCM2708_I2S_RX(v) (v)
  121869. +
  121870. +#define BCM2708_I2S_INT_RXERR BIT(3)
  121871. +#define BCM2708_I2S_INT_TXERR BIT(2)
  121872. +#define BCM2708_I2S_INT_RXR BIT(1)
  121873. +#define BCM2708_I2S_INT_TXW BIT(0)
  121874. +
  121875. +/* I2S DMA interface */
  121876. +#define BCM2708_I2S_FIFO_PHYSICAL_ADDR 0x7E203004
  121877. +#define BCM2708_DMA_DREQ_PCM_TX 2
  121878. +#define BCM2708_DMA_DREQ_PCM_RX 3
  121879. +
  121880. +/* I2S pin configuration */
  121881. +static int bcm2708_i2s_gpio=BCM2708_I2S_GPIO_AUTO;
  121882. +
  121883. +/* General device struct */
  121884. +struct bcm2708_i2s_dev {
  121885. + struct device *dev;
  121886. + struct snd_dmaengine_dai_dma_data dma_data[2];
  121887. + unsigned int fmt;
  121888. + unsigned int bclk_ratio;
  121889. +
  121890. + struct regmap *i2s_regmap;
  121891. + struct regmap *clk_regmap;
  121892. +};
  121893. +
  121894. +void bcm2708_i2s_set_gpio(int gpio) {
  121895. + bcm2708_i2s_gpio=gpio;
  121896. +}
  121897. +EXPORT_SYMBOL(bcm2708_i2s_set_gpio);
  121898. +
  121899. +
  121900. +static void bcm2708_i2s_start_clock(struct bcm2708_i2s_dev *dev)
  121901. +{
  121902. + /* Start the clock if in master mode */
  121903. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  121904. +
  121905. + switch (master) {
  121906. + case SND_SOC_DAIFMT_CBS_CFS:
  121907. + case SND_SOC_DAIFMT_CBS_CFM:
  121908. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  121909. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  121910. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  121911. + break;
  121912. + default:
  121913. + break;
  121914. + }
  121915. +}
  121916. +
  121917. +static void bcm2708_i2s_stop_clock(struct bcm2708_i2s_dev *dev)
  121918. +{
  121919. + uint32_t clkreg;
  121920. + int timeout = 1000;
  121921. +
  121922. + /* Stop clock */
  121923. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  121924. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  121925. + BCM2708_CLK_PASSWD);
  121926. +
  121927. + /* Wait for the BUSY flag going down */
  121928. + while (--timeout) {
  121929. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  121930. + if (!(clkreg & BCM2708_CLK_BUSY))
  121931. + break;
  121932. + }
  121933. +
  121934. + if (!timeout) {
  121935. + /* KILL the clock */
  121936. + dev_err(dev->dev, "I2S clock didn't stop. Kill the clock!\n");
  121937. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  121938. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD_MASK,
  121939. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD);
  121940. + }
  121941. +}
  121942. +
  121943. +static void bcm2708_i2s_clear_fifos(struct bcm2708_i2s_dev *dev,
  121944. + bool tx, bool rx)
  121945. +{
  121946. + int timeout = 1000;
  121947. + uint32_t syncval;
  121948. + uint32_t csreg;
  121949. + uint32_t i2s_active_state;
  121950. + uint32_t clkreg;
  121951. + uint32_t clk_active_state;
  121952. + uint32_t off;
  121953. + uint32_t clr;
  121954. +
  121955. + off = tx ? BCM2708_I2S_TXON : 0;
  121956. + off |= rx ? BCM2708_I2S_RXON : 0;
  121957. +
  121958. + clr = tx ? BCM2708_I2S_TXCLR : 0;
  121959. + clr |= rx ? BCM2708_I2S_RXCLR : 0;
  121960. +
  121961. + /* Backup the current state */
  121962. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  121963. + i2s_active_state = csreg & (BCM2708_I2S_RXON | BCM2708_I2S_TXON);
  121964. +
  121965. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  121966. + clk_active_state = clkreg & BCM2708_CLK_ENAB;
  121967. +
  121968. + /* Start clock if not running */
  121969. + if (!clk_active_state) {
  121970. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  121971. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  121972. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  121973. + }
  121974. +
  121975. + /* Stop I2S module */
  121976. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, off, 0);
  121977. +
  121978. + /*
  121979. + * Clear the FIFOs
  121980. + * Requires at least 2 PCM clock cycles to take effect
  121981. + */
  121982. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, clr, clr);
  121983. +
  121984. + /* Wait for 2 PCM clock cycles */
  121985. +
  121986. + /*
  121987. + * Toggle the SYNC flag. After 2 PCM clock cycles it can be read back
  121988. + * FIXME: This does not seem to work for slave mode!
  121989. + */
  121990. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &syncval);
  121991. + syncval &= BCM2708_I2S_SYNC;
  121992. +
  121993. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  121994. + BCM2708_I2S_SYNC, ~syncval);
  121995. +
  121996. + /* Wait for the SYNC flag changing it's state */
  121997. + while (--timeout) {
  121998. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  121999. + if ((csreg & BCM2708_I2S_SYNC) != syncval)
  122000. + break;
  122001. + }
  122002. +
  122003. + if (!timeout)
  122004. + dev_err(dev->dev, "I2S SYNC error!\n");
  122005. +
  122006. + /* Stop clock if it was not running before */
  122007. + if (!clk_active_state)
  122008. + bcm2708_i2s_stop_clock(dev);
  122009. +
  122010. + /* Restore I2S state */
  122011. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  122012. + BCM2708_I2S_RXON | BCM2708_I2S_TXON, i2s_active_state);
  122013. +}
  122014. +
  122015. +static int bcm2708_i2s_set_dai_fmt(struct snd_soc_dai *dai,
  122016. + unsigned int fmt)
  122017. +{
  122018. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  122019. + dev->fmt = fmt;
  122020. + return 0;
  122021. +}
  122022. +
  122023. +static int bcm2708_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
  122024. + unsigned int ratio)
  122025. +{
  122026. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  122027. + dev->bclk_ratio = ratio;
  122028. + return 0;
  122029. +}
  122030. +
  122031. +
  122032. +static int bcm2708_i2s_set_function(unsigned offset, int function)
  122033. +{
  122034. + #define GPIOFSEL(x) (0x00+(x)*4)
  122035. + void __iomem *gpio = __io_address(GPIO_BASE);
  122036. + unsigned alt = function <= 3 ? function + 4: function == 4 ? 3 : 2;
  122037. + unsigned gpiodir;
  122038. + unsigned gpio_bank = offset / 10;
  122039. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  122040. +
  122041. + if (offset >= BCM2708_NR_GPIOS)
  122042. + return -EINVAL;
  122043. +
  122044. + gpiodir = readl(gpio + GPIOFSEL(gpio_bank));
  122045. + gpiodir &= ~(7 << gpio_field_offset);
  122046. + gpiodir |= alt << gpio_field_offset;
  122047. + writel(gpiodir, gpio + GPIOFSEL(gpio_bank));
  122048. + return 0;
  122049. +}
  122050. +
  122051. +static void bcm2708_i2s_setup_gpio(void)
  122052. +{
  122053. + /*
  122054. + * This is the common way to handle the GPIO pins for
  122055. + * the Raspberry Pi.
  122056. + * TODO Better way would be to handle
  122057. + * this in the device tree!
  122058. + */
  122059. + int pin,pinconfig,startpin,alt;
  122060. +
  122061. + /* SPI is on different GPIOs on different boards */
  122062. + /* for Raspberry Pi B+, this is pin GPIO18-21, for original on 28-31 */
  122063. + if (bcm2708_i2s_gpio==BCM2708_I2S_GPIO_AUTO) {
  122064. + if ((system_rev & 0xffffff) >= 0x10) {
  122065. + /* Model B+ */
  122066. + pinconfig=BCM2708_I2S_GPIO_PIN18;
  122067. + } else {
  122068. + /* original */
  122069. + pinconfig=BCM2708_I2S_GPIO_PIN28;
  122070. + }
  122071. + } else {
  122072. + pinconfig=bcm2708_i2s_gpio;
  122073. + }
  122074. +
  122075. + if (pinconfig==BCM2708_I2S_GPIO_PIN18) {
  122076. + startpin=18;
  122077. + alt=BCM2708_I2S_GPIO_PIN18_ALT;
  122078. + } else if (pinconfig==BCM2708_I2S_GPIO_PIN28) {
  122079. + startpin=28;
  122080. + alt=BCM2708_I2S_GPIO_PIN28_ALT;
  122081. + } else {
  122082. + printk(KERN_INFO "Can't configure I2S GPIOs, unknown pin mode for I2S: %i\n",pinconfig);
  122083. + return;
  122084. + }
  122085. +
  122086. + /* configure I2S pins to correct ALT mode */
  122087. + for (pin = startpin; pin <= startpin+3; pin++) {
  122088. + bcm2708_i2s_set_function(pin, alt);
  122089. + }
  122090. +}
  122091. +
  122092. +static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
  122093. + struct snd_pcm_hw_params *params,
  122094. + struct snd_soc_dai *dai)
  122095. +{
  122096. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  122097. +
  122098. + unsigned int sampling_rate = params_rate(params);
  122099. + unsigned int data_length, data_delay, bclk_ratio;
  122100. + unsigned int ch1pos, ch2pos, mode, format;
  122101. + unsigned int mash = BCM2708_CLK_MASH_1;
  122102. + unsigned int divi, divf, target_frequency;
  122103. + int clk_src = -1;
  122104. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  122105. + bool bit_master = (master == SND_SOC_DAIFMT_CBS_CFS
  122106. + || master == SND_SOC_DAIFMT_CBS_CFM);
  122107. +
  122108. + bool frame_master = (master == SND_SOC_DAIFMT_CBS_CFS
  122109. + || master == SND_SOC_DAIFMT_CBM_CFS);
  122110. + uint32_t csreg;
  122111. +
  122112. + /*
  122113. + * If a stream is already enabled,
  122114. + * the registers are already set properly.
  122115. + */
  122116. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  122117. +
  122118. + if (csreg & (BCM2708_I2S_TXON | BCM2708_I2S_RXON))
  122119. + return 0;
  122120. +
  122121. +
  122122. + bcm2708_i2s_setup_gpio();
  122123. +
  122124. + /*
  122125. + * Adjust the data length according to the format.
  122126. + * We prefill the half frame length with an integer
  122127. + * divider of 2400 as explained at the clock settings.
  122128. + * Maybe it is overwritten there, if the Integer mode
  122129. + * does not apply.
  122130. + */
  122131. + switch (params_format(params)) {
  122132. + case SNDRV_PCM_FORMAT_S16_LE:
  122133. + data_length = 16;
  122134. + bclk_ratio = 50;
  122135. + break;
  122136. + case SNDRV_PCM_FORMAT_S24_LE:
  122137. + data_length = 24;
  122138. + bclk_ratio = 50;
  122139. + break;
  122140. + case SNDRV_PCM_FORMAT_S32_LE:
  122141. + data_length = 32;
  122142. + bclk_ratio = 100;
  122143. + break;
  122144. + default:
  122145. + return -EINVAL;
  122146. + }
  122147. +
  122148. + /* If bclk_ratio already set, use that one. */
  122149. + if (dev->bclk_ratio)
  122150. + bclk_ratio = dev->bclk_ratio;
  122151. +
  122152. + /*
  122153. + * Clock Settings
  122154. + *
  122155. + * The target frequency of the bit clock is
  122156. + * sampling rate * frame length
  122157. + *
  122158. + * Integer mode:
  122159. + * Sampling rates that are multiples of 8000 kHz
  122160. + * can be driven by the oscillator of 19.2 MHz
  122161. + * with an integer divider as long as the frame length
  122162. + * is an integer divider of 19200000/8000=2400 as set up above.
  122163. + * This is no longer possible if the sampling rate
  122164. + * is too high (e.g. 192 kHz), because the oscillator is too slow.
  122165. + *
  122166. + * MASH mode:
  122167. + * For all other sampling rates, it is not possible to
  122168. + * have an integer divider. Approximate the clock
  122169. + * with the MASH module that induces a slight frequency
  122170. + * variance. To minimize that it is best to have the fastest
  122171. + * clock here. That is PLLD with 500 MHz.
  122172. + */
  122173. + target_frequency = sampling_rate * bclk_ratio;
  122174. + clk_src = BCM2708_CLK_SRC_OSC;
  122175. + mash = BCM2708_CLK_MASH_0;
  122176. +
  122177. + if (bcm2708_clk_freq[clk_src] % target_frequency == 0
  122178. + && bit_master && frame_master) {
  122179. + divi = bcm2708_clk_freq[clk_src] / target_frequency;
  122180. + divf = 0;
  122181. + } else {
  122182. + uint64_t dividend;
  122183. +
  122184. + if (!dev->bclk_ratio) {
  122185. + /*
  122186. + * Overwrite bclk_ratio, because the
  122187. + * above trick is not needed or can
  122188. + * not be used.
  122189. + */
  122190. + bclk_ratio = 2 * data_length;
  122191. + }
  122192. +
  122193. + target_frequency = sampling_rate * bclk_ratio;
  122194. +
  122195. + clk_src = BCM2708_CLK_SRC_PLLD;
  122196. + mash = BCM2708_CLK_MASH_1;
  122197. +
  122198. + dividend = bcm2708_clk_freq[clk_src];
  122199. + dividend <<= BCM2708_CLK_SHIFT;
  122200. + do_div(dividend, target_frequency);
  122201. + divi = dividend >> BCM2708_CLK_SHIFT;
  122202. + divf = dividend & BCM2708_CLK_DIVF_MASK;
  122203. + }
  122204. +
  122205. + /* Clock should only be set up here if CPU is clock master */
  122206. + if (((dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBS_CFS) ||
  122207. + ((dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBS_CFM)) {
  122208. + /* Set clock divider */
  122209. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMDIV_REG, BCM2708_CLK_PASSWD
  122210. + | BCM2708_CLK_DIVI(divi)
  122211. + | BCM2708_CLK_DIVF(divf));
  122212. +
  122213. + /* Setup clock, but don't start it yet */
  122214. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, BCM2708_CLK_PASSWD
  122215. + | BCM2708_CLK_MASH(mash)
  122216. + | BCM2708_CLK_SRC(clk_src));
  122217. + }
  122218. +
  122219. + /* Setup the frame format */
  122220. + format = BCM2708_I2S_CHEN;
  122221. +
  122222. + if (data_length >= 24)
  122223. + format |= BCM2708_I2S_CHWEX;
  122224. +
  122225. + format |= BCM2708_I2S_CHWID((data_length-8)&0xf);
  122226. +
  122227. + switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  122228. + case SND_SOC_DAIFMT_I2S:
  122229. + data_delay = 1;
  122230. + break;
  122231. + default:
  122232. + /*
  122233. + * TODO
  122234. + * Others are possible but are not implemented at the moment.
  122235. + */
  122236. + dev_err(dev->dev, "%s:bad format\n", __func__);
  122237. + return -EINVAL;
  122238. + }
  122239. +
  122240. + ch1pos = data_delay;
  122241. + ch2pos = bclk_ratio / 2 + data_delay;
  122242. +
  122243. + switch (params_channels(params)) {
  122244. + case 2:
  122245. + format = BCM2708_I2S_CH1(format) | BCM2708_I2S_CH2(format);
  122246. + format |= BCM2708_I2S_CH1(BCM2708_I2S_CHPOS(ch1pos));
  122247. + format |= BCM2708_I2S_CH2(BCM2708_I2S_CHPOS(ch2pos));
  122248. + break;
  122249. + default:
  122250. + return -EINVAL;
  122251. + }
  122252. +
  122253. + /*
  122254. + * Set format for both streams.
  122255. + * We cannot set another frame length
  122256. + * (and therefore word length) anyway,
  122257. + * so the format will be the same.
  122258. + */
  122259. + regmap_write(dev->i2s_regmap, BCM2708_I2S_RXC_A_REG, format);
  122260. + regmap_write(dev->i2s_regmap, BCM2708_I2S_TXC_A_REG, format);
  122261. +
  122262. + /* Setup the I2S mode */
  122263. + mode = 0;
  122264. +
  122265. + if (data_length <= 16) {
  122266. + /*
  122267. + * Use frame packed mode (2 channels per 32 bit word)
  122268. + * We cannot set another frame length in the second stream
  122269. + * (and therefore word length) anyway,
  122270. + * so the format will be the same.
  122271. + */
  122272. + mode |= BCM2708_I2S_FTXP | BCM2708_I2S_FRXP;
  122273. + }
  122274. +
  122275. + mode |= BCM2708_I2S_FLEN(bclk_ratio - 1);
  122276. + mode |= BCM2708_I2S_FSLEN(bclk_ratio / 2);
  122277. +
  122278. + /* Master or slave? */
  122279. + switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  122280. + case SND_SOC_DAIFMT_CBS_CFS:
  122281. + /* CPU is master */
  122282. + break;
  122283. + case SND_SOC_DAIFMT_CBM_CFS:
  122284. + /*
  122285. + * CODEC is bit clock master
  122286. + * CPU is frame master
  122287. + */
  122288. + mode |= BCM2708_I2S_CLKM;
  122289. + break;
  122290. + case SND_SOC_DAIFMT_CBS_CFM:
  122291. + /*
  122292. + * CODEC is frame master
  122293. + * CPU is bit clock master
  122294. + */
  122295. + mode |= BCM2708_I2S_FSM;
  122296. + break;
  122297. + case SND_SOC_DAIFMT_CBM_CFM:
  122298. + /* CODEC is master */
  122299. + mode |= BCM2708_I2S_CLKM;
  122300. + mode |= BCM2708_I2S_FSM;
  122301. + break;
  122302. + default:
  122303. + dev_err(dev->dev, "%s:bad master\n", __func__);
  122304. + return -EINVAL;
  122305. + }
  122306. +
  122307. + /*
  122308. + * Invert clocks?
  122309. + *
  122310. + * The BCM approach seems to be inverted to the classical I2S approach.
  122311. + */
  122312. + switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) {
  122313. + case SND_SOC_DAIFMT_NB_NF:
  122314. + /* None. Therefore, both for BCM */
  122315. + mode |= BCM2708_I2S_CLKI;
  122316. + mode |= BCM2708_I2S_FSI;
  122317. + break;
  122318. + case SND_SOC_DAIFMT_IB_IF:
  122319. + /* Both. Therefore, none for BCM */
  122320. + break;
  122321. + case SND_SOC_DAIFMT_NB_IF:
  122322. + /*
  122323. + * Invert only frame sync. Therefore,
  122324. + * invert only bit clock for BCM
  122325. + */
  122326. + mode |= BCM2708_I2S_CLKI;
  122327. + break;
  122328. + case SND_SOC_DAIFMT_IB_NF:
  122329. + /*
  122330. + * Invert only bit clock. Therefore,
  122331. + * invert only frame sync for BCM
  122332. + */
  122333. + mode |= BCM2708_I2S_FSI;
  122334. + break;
  122335. + default:
  122336. + return -EINVAL;
  122337. + }
  122338. +
  122339. + regmap_write(dev->i2s_regmap, BCM2708_I2S_MODE_A_REG, mode);
  122340. +
  122341. + /* Setup the DMA parameters */
  122342. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  122343. + BCM2708_I2S_RXTHR(1)
  122344. + | BCM2708_I2S_TXTHR(1)
  122345. + | BCM2708_I2S_DMAEN, 0xffffffff);
  122346. +
  122347. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_DREQ_A_REG,
  122348. + BCM2708_I2S_TX_PANIC(0x10)
  122349. + | BCM2708_I2S_RX_PANIC(0x30)
  122350. + | BCM2708_I2S_TX(0x30)
  122351. + | BCM2708_I2S_RX(0x20), 0xffffffff);
  122352. +
  122353. + /* Clear FIFOs */
  122354. + bcm2708_i2s_clear_fifos(dev, true, true);
  122355. +
  122356. + return 0;
  122357. +}
  122358. +
  122359. +static int bcm2708_i2s_prepare(struct snd_pcm_substream *substream,
  122360. + struct snd_soc_dai *dai)
  122361. +{
  122362. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  122363. + uint32_t cs_reg;
  122364. +
  122365. + bcm2708_i2s_start_clock(dev);
  122366. +
  122367. + /*
  122368. + * Clear both FIFOs if the one that should be started
  122369. + * is not empty at the moment. This should only happen
  122370. + * after overrun. Otherwise, hw_params would have cleared
  122371. + * the FIFO.
  122372. + */
  122373. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &cs_reg);
  122374. +
  122375. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
  122376. + && !(cs_reg & BCM2708_I2S_TXE))
  122377. + bcm2708_i2s_clear_fifos(dev, true, false);
  122378. + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE
  122379. + && (cs_reg & BCM2708_I2S_RXD))
  122380. + bcm2708_i2s_clear_fifos(dev, false, true);
  122381. +
  122382. + return 0;
  122383. +}
  122384. +
  122385. +static void bcm2708_i2s_stop(struct bcm2708_i2s_dev *dev,
  122386. + struct snd_pcm_substream *substream,
  122387. + struct snd_soc_dai *dai)
  122388. +{
  122389. + uint32_t mask;
  122390. +
  122391. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  122392. + mask = BCM2708_I2S_RXON;
  122393. + else
  122394. + mask = BCM2708_I2S_TXON;
  122395. +
  122396. + regmap_update_bits(dev->i2s_regmap,
  122397. + BCM2708_I2S_CS_A_REG, mask, 0);
  122398. +
  122399. + /* Stop also the clock when not SND_SOC_DAIFMT_CONT */
  122400. + if (!dai->active && !(dev->fmt & SND_SOC_DAIFMT_CONT))
  122401. + bcm2708_i2s_stop_clock(dev);
  122402. +}
  122403. +
  122404. +static int bcm2708_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  122405. + struct snd_soc_dai *dai)
  122406. +{
  122407. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  122408. + uint32_t mask;
  122409. +
  122410. + switch (cmd) {
  122411. + case SNDRV_PCM_TRIGGER_START:
  122412. + case SNDRV_PCM_TRIGGER_RESUME:
  122413. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  122414. + bcm2708_i2s_start_clock(dev);
  122415. +
  122416. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  122417. + mask = BCM2708_I2S_RXON;
  122418. + else
  122419. + mask = BCM2708_I2S_TXON;
  122420. +
  122421. + regmap_update_bits(dev->i2s_regmap,
  122422. + BCM2708_I2S_CS_A_REG, mask, mask);
  122423. + break;
  122424. +
  122425. + case SNDRV_PCM_TRIGGER_STOP:
  122426. + case SNDRV_PCM_TRIGGER_SUSPEND:
  122427. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  122428. + bcm2708_i2s_stop(dev, substream, dai);
  122429. + break;
  122430. + default:
  122431. + return -EINVAL;
  122432. + }
  122433. +
  122434. + return 0;
  122435. +}
  122436. +
  122437. +static int bcm2708_i2s_startup(struct snd_pcm_substream *substream,
  122438. + struct snd_soc_dai *dai)
  122439. +{
  122440. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  122441. +
  122442. + if (dai->active)
  122443. + return 0;
  122444. +
  122445. + /* Should this still be running stop it */
  122446. + bcm2708_i2s_stop_clock(dev);
  122447. +
  122448. + /* Enable PCM block */
  122449. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  122450. + BCM2708_I2S_EN, BCM2708_I2S_EN);
  122451. +
  122452. + /*
  122453. + * Disable STBY.
  122454. + * Requires at least 4 PCM clock cycles to take effect.
  122455. + */
  122456. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  122457. + BCM2708_I2S_STBY, BCM2708_I2S_STBY);
  122458. +
  122459. + return 0;
  122460. +}
  122461. +
  122462. +static void bcm2708_i2s_shutdown(struct snd_pcm_substream *substream,
  122463. + struct snd_soc_dai *dai)
  122464. +{
  122465. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  122466. +
  122467. + bcm2708_i2s_stop(dev, substream, dai);
  122468. +
  122469. + /* If both streams are stopped, disable module and clock */
  122470. + if (dai->active)
  122471. + return;
  122472. +
  122473. + /* Disable the module */
  122474. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  122475. + BCM2708_I2S_EN, 0);
  122476. +
  122477. + /*
  122478. + * Stopping clock is necessary, because stop does
  122479. + * not stop the clock when SND_SOC_DAIFMT_CONT
  122480. + */
  122481. + bcm2708_i2s_stop_clock(dev);
  122482. +}
  122483. +
  122484. +static const struct snd_soc_dai_ops bcm2708_i2s_dai_ops = {
  122485. + .startup = bcm2708_i2s_startup,
  122486. + .shutdown = bcm2708_i2s_shutdown,
  122487. + .prepare = bcm2708_i2s_prepare,
  122488. + .trigger = bcm2708_i2s_trigger,
  122489. + .hw_params = bcm2708_i2s_hw_params,
  122490. + .set_fmt = bcm2708_i2s_set_dai_fmt,
  122491. + .set_bclk_ratio = bcm2708_i2s_set_dai_bclk_ratio
  122492. +};
  122493. +
  122494. +static int bcm2708_i2s_dai_probe(struct snd_soc_dai *dai)
  122495. +{
  122496. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  122497. +
  122498. + dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
  122499. + dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
  122500. +
  122501. + return 0;
  122502. +}
  122503. +
  122504. +static struct snd_soc_dai_driver bcm2708_i2s_dai = {
  122505. + .name = "bcm2708-i2s",
  122506. + .probe = bcm2708_i2s_dai_probe,
  122507. + .playback = {
  122508. + .channels_min = 2,
  122509. + .channels_max = 2,
  122510. + .rates = SNDRV_PCM_RATE_8000_192000,
  122511. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  122512. + | SNDRV_PCM_FMTBIT_S24_LE
  122513. + | SNDRV_PCM_FMTBIT_S32_LE
  122514. + },
  122515. + .capture = {
  122516. + .channels_min = 2,
  122517. + .channels_max = 2,
  122518. + .rates = SNDRV_PCM_RATE_8000_192000,
  122519. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  122520. + | SNDRV_PCM_FMTBIT_S24_LE
  122521. + | SNDRV_PCM_FMTBIT_S32_LE
  122522. + },
  122523. + .ops = &bcm2708_i2s_dai_ops,
  122524. + .symmetric_rates = 1
  122525. +};
  122526. +
  122527. +static bool bcm2708_i2s_volatile_reg(struct device *dev, unsigned int reg)
  122528. +{
  122529. + switch (reg) {
  122530. + case BCM2708_I2S_CS_A_REG:
  122531. + case BCM2708_I2S_FIFO_A_REG:
  122532. + case BCM2708_I2S_INTSTC_A_REG:
  122533. + case BCM2708_I2S_GRAY_REG:
  122534. + return true;
  122535. + default:
  122536. + return false;
  122537. + };
  122538. +}
  122539. +
  122540. +static bool bcm2708_i2s_precious_reg(struct device *dev, unsigned int reg)
  122541. +{
  122542. + switch (reg) {
  122543. + case BCM2708_I2S_FIFO_A_REG:
  122544. + return true;
  122545. + default:
  122546. + return false;
  122547. + };
  122548. +}
  122549. +
  122550. +static bool bcm2708_clk_volatile_reg(struct device *dev, unsigned int reg)
  122551. +{
  122552. + switch (reg) {
  122553. + case BCM2708_CLK_PCMCTL_REG:
  122554. + return true;
  122555. + default:
  122556. + return false;
  122557. + };
  122558. +}
  122559. +
  122560. +static const struct regmap_config bcm2708_regmap_config[] = {
  122561. + {
  122562. + .reg_bits = 32,
  122563. + .reg_stride = 4,
  122564. + .val_bits = 32,
  122565. + .max_register = BCM2708_I2S_GRAY_REG,
  122566. + .precious_reg = bcm2708_i2s_precious_reg,
  122567. + .volatile_reg = bcm2708_i2s_volatile_reg,
  122568. + .cache_type = REGCACHE_RBTREE,
  122569. + .name = "i2s",
  122570. + },
  122571. + {
  122572. + .reg_bits = 32,
  122573. + .reg_stride = 4,
  122574. + .val_bits = 32,
  122575. + .max_register = BCM2708_CLK_PCMDIV_REG,
  122576. + .volatile_reg = bcm2708_clk_volatile_reg,
  122577. + .cache_type = REGCACHE_RBTREE,
  122578. + .name = "clk",
  122579. + },
  122580. +};
  122581. +
  122582. +static const struct snd_soc_component_driver bcm2708_i2s_component = {
  122583. + .name = "bcm2708-i2s-comp",
  122584. +};
  122585. +
  122586. +static const struct snd_pcm_hardware bcm2708_pcm_hardware = {
  122587. + .info = SNDRV_PCM_INFO_INTERLEAVED |
  122588. + SNDRV_PCM_INFO_JOINT_DUPLEX,
  122589. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  122590. + SNDRV_PCM_FMTBIT_S24_LE |
  122591. + SNDRV_PCM_FMTBIT_S32_LE,
  122592. + .period_bytes_min = 32,
  122593. + .period_bytes_max = 64 * PAGE_SIZE,
  122594. + .periods_min = 2,
  122595. + .periods_max = 255,
  122596. + .buffer_bytes_max = 128 * PAGE_SIZE,
  122597. +};
  122598. +
  122599. +static const struct snd_dmaengine_pcm_config bcm2708_dmaengine_pcm_config = {
  122600. + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
  122601. + .pcm_hardware = &bcm2708_pcm_hardware,
  122602. + .prealloc_buffer_size = 256 * PAGE_SIZE,
  122603. +};
  122604. +
  122605. +
  122606. +static int bcm2708_i2s_probe(struct platform_device *pdev)
  122607. +{
  122608. + struct bcm2708_i2s_dev *dev;
  122609. + int i;
  122610. + int ret;
  122611. + struct regmap *regmap[2];
  122612. + struct resource *mem[2];
  122613. +
  122614. + /* Request both ioareas */
  122615. + for (i = 0; i <= 1; i++) {
  122616. + void __iomem *base;
  122617. +
  122618. + mem[i] = platform_get_resource(pdev, IORESOURCE_MEM, i);
  122619. + base = devm_ioremap_resource(&pdev->dev, mem[i]);
  122620. + if (IS_ERR(base))
  122621. + return PTR_ERR(base);
  122622. +
  122623. + regmap[i] = devm_regmap_init_mmio(&pdev->dev, base,
  122624. + &bcm2708_regmap_config[i]);
  122625. + if (IS_ERR(regmap[i])) {
  122626. + dev_err(&pdev->dev, "I2S probe: regmap init failed\n");
  122627. + return PTR_ERR(regmap[i]);
  122628. + }
  122629. + }
  122630. +
  122631. + dev = devm_kzalloc(&pdev->dev, sizeof(*dev),
  122632. + GFP_KERNEL);
  122633. + if (IS_ERR(dev))
  122634. + return PTR_ERR(dev);
  122635. +
  122636. + dev->i2s_regmap = regmap[0];
  122637. + dev->clk_regmap = regmap[1];
  122638. +
  122639. + /* Set the DMA address */
  122640. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
  122641. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  122642. +
  122643. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
  122644. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  122645. +
  122646. + /* Set the DREQ */
  122647. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].slave_id =
  122648. + BCM2708_DMA_DREQ_PCM_TX;
  122649. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].slave_id =
  122650. + BCM2708_DMA_DREQ_PCM_RX;
  122651. +
  122652. + /* Set the bus width */
  122653. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width =
  122654. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  122655. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr_width =
  122656. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  122657. +
  122658. + /* Set burst */
  122659. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].maxburst = 2;
  122660. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].maxburst = 2;
  122661. +
  122662. + /* BCLK ratio - use default */
  122663. + dev->bclk_ratio = 0;
  122664. +
  122665. + /* Store the pdev */
  122666. + dev->dev = &pdev->dev;
  122667. + dev_set_drvdata(&pdev->dev, dev);
  122668. +
  122669. + ret = snd_soc_register_component(&pdev->dev,
  122670. + &bcm2708_i2s_component, &bcm2708_i2s_dai, 1);
  122671. +
  122672. + if (ret) {
  122673. + dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
  122674. + ret = -ENOMEM;
  122675. + return ret;
  122676. + }
  122677. +
  122678. + ret = snd_dmaengine_pcm_register(&pdev->dev,
  122679. + &bcm2708_dmaengine_pcm_config,
  122680. + SND_DMAENGINE_PCM_FLAG_COMPAT);
  122681. + if (ret) {
  122682. + dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
  122683. + snd_soc_unregister_component(&pdev->dev);
  122684. + return ret;
  122685. + }
  122686. +
  122687. + return 0;
  122688. +}
  122689. +
  122690. +static int bcm2708_i2s_remove(struct platform_device *pdev)
  122691. +{
  122692. + snd_dmaengine_pcm_unregister(&pdev->dev);
  122693. + snd_soc_unregister_component(&pdev->dev);
  122694. + return 0;
  122695. +}
  122696. +
  122697. +static const struct of_device_id bcm2708_i2s_of_match[] = {
  122698. + { .compatible = "brcm,bcm2708-i2s", },
  122699. + {},
  122700. +};
  122701. +MODULE_DEVICE_TABLE(of, bcm2708_i2s_of_match);
  122702. +
  122703. +static struct platform_driver bcm2708_i2s_driver = {
  122704. + .probe = bcm2708_i2s_probe,
  122705. + .remove = bcm2708_i2s_remove,
  122706. + .driver = {
  122707. + .name = "bcm2708-i2s",
  122708. + .owner = THIS_MODULE,
  122709. + .of_match_table = bcm2708_i2s_of_match,
  122710. + },
  122711. +};
  122712. +
  122713. +module_platform_driver(bcm2708_i2s_driver);
  122714. +
  122715. +MODULE_ALIAS("platform:bcm2708-i2s");
  122716. +MODULE_DESCRIPTION("BCM2708 I2S interface");
  122717. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  122718. +MODULE_LICENSE("GPL v2");
  122719. diff -Nur linux-3.18.6/sound/soc/bcm/bcm2708-i2s.h linux-rpi/sound/soc/bcm/bcm2708-i2s.h
  122720. --- linux-3.18.6/sound/soc/bcm/bcm2708-i2s.h 1970-01-01 01:00:00.000000000 +0100
  122721. +++ linux-rpi/sound/soc/bcm/bcm2708-i2s.h 2015-02-09 04:40:48.000000000 +0100
  122722. @@ -0,0 +1,35 @@
  122723. +/*
  122724. + * I2S configuration for sound cards.
  122725. + *
  122726. + * Copyright (c) 2014 Daniel Matuschek <daniel@hifiberry.com>
  122727. + *
  122728. + * This program is free software; you can redistribute it and/or modify
  122729. + * it under the terms of the GNU General Public License as published by
  122730. + * the Free Software Foundation; either version 2 of the License, or
  122731. + * (at your option) any later version.
  122732. + *
  122733. + * This program is distributed in the hope that it will be useful,
  122734. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  122735. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  122736. + * GNU General Public License for more details.
  122737. + *
  122738. + * You should have received a copy of the GNU General Public License
  122739. + * along with this program; if not, write to the Free Software
  122740. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  122741. + */
  122742. +
  122743. +#ifndef BCM2708_I2S_H
  122744. +#define BCM2708_I2S_H
  122745. +
  122746. +/* I2S pin assignment */
  122747. +#define BCM2708_I2S_GPIO_AUTO 0
  122748. +#define BCM2708_I2S_GPIO_PIN18 1
  122749. +#define BCM2708_I2S_GPIO_PIN28 2
  122750. +
  122751. +/* Alt mode to enable I2S */
  122752. +#define BCM2708_I2S_GPIO_PIN18_ALT 0
  122753. +#define BCM2708_I2S_GPIO_PIN28_ALT 2
  122754. +
  122755. +extern void bcm2708_i2s_set_gpio(int gpio);
  122756. +
  122757. +#endif
  122758. diff -Nur linux-3.18.6/sound/soc/bcm/bcm2835-i2s.c linux-rpi/sound/soc/bcm/bcm2835-i2s.c
  122759. --- linux-3.18.6/sound/soc/bcm/bcm2835-i2s.c 2015-02-06 15:53:48.000000000 +0100
  122760. +++ linux-rpi/sound/soc/bcm/bcm2835-i2s.c 2015-02-09 04:40:48.000000000 +0100
  122761. @@ -861,6 +861,7 @@
  122762. { .compatible = "brcm,bcm2835-i2s", },
  122763. {},
  122764. };
  122765. +MODULE_DEVICE_TABLE(of, bcm2835_i2s_of_match);
  122766. static struct platform_driver bcm2835_i2s_driver = {
  122767. .probe = bcm2835_i2s_probe,
  122768. diff -Nur linux-3.18.6/sound/soc/bcm/hifiberry_amp.c linux-rpi/sound/soc/bcm/hifiberry_amp.c
  122769. --- linux-3.18.6/sound/soc/bcm/hifiberry_amp.c 1970-01-01 01:00:00.000000000 +0100
  122770. +++ linux-rpi/sound/soc/bcm/hifiberry_amp.c 2015-02-09 04:40:48.000000000 +0100
  122771. @@ -0,0 +1,127 @@
  122772. +/*
  122773. + * ASoC Driver for HifiBerry AMP
  122774. + *
  122775. + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
  122776. + * Copyright 2014
  122777. + *
  122778. + * This program is free software; you can redistribute it and/or
  122779. + * modify it under the terms of the GNU General Public License
  122780. + * version 2 as published by the Free Software Foundation.
  122781. + *
  122782. + * This program is distributed in the hope that it will be useful, but
  122783. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  122784. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  122785. + * General Public License for more details.
  122786. + */
  122787. +
  122788. +#include <linux/module.h>
  122789. +#include <linux/platform_device.h>
  122790. +
  122791. +#include <sound/core.h>
  122792. +#include <sound/pcm.h>
  122793. +#include <sound/pcm_params.h>
  122794. +#include <sound/soc.h>
  122795. +#include <sound/jack.h>
  122796. +
  122797. +static int snd_rpi_hifiberry_amp_init(struct snd_soc_pcm_runtime *rtd)
  122798. +{
  122799. + // ToDo: init of the dsp-registers.
  122800. + return 0;
  122801. +}
  122802. +
  122803. +static int snd_rpi_hifiberry_amp_hw_params( struct snd_pcm_substream *substream,
  122804. + struct snd_pcm_hw_params *params )
  122805. +{
  122806. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  122807. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  122808. +
  122809. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
  122810. +}
  122811. +
  122812. +static struct snd_soc_ops snd_rpi_hifiberry_amp_ops = {
  122813. + .hw_params = snd_rpi_hifiberry_amp_hw_params,
  122814. +};
  122815. +
  122816. +static struct snd_soc_dai_link snd_rpi_hifiberry_amp_dai[] = {
  122817. + {
  122818. + .name = "HifiBerry AMP",
  122819. + .stream_name = "HifiBerry AMP HiFi",
  122820. + .cpu_dai_name = "bcm2708-i2s.0",
  122821. + .codec_dai_name = "tas5713-hifi",
  122822. + .platform_name = "bcm2708-i2s.0",
  122823. + .codec_name = "tas5713.1-001b",
  122824. + .dai_fmt = SND_SOC_DAIFMT_I2S |
  122825. + SND_SOC_DAIFMT_NB_NF |
  122826. + SND_SOC_DAIFMT_CBS_CFS,
  122827. + .ops = &snd_rpi_hifiberry_amp_ops,
  122828. + .init = snd_rpi_hifiberry_amp_init,
  122829. + },
  122830. +};
  122831. +
  122832. +
  122833. +static struct snd_soc_card snd_rpi_hifiberry_amp = {
  122834. + .name = "snd_rpi_hifiberry_amp",
  122835. + .dai_link = snd_rpi_hifiberry_amp_dai,
  122836. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_amp_dai),
  122837. +};
  122838. +
  122839. +static const struct of_device_id snd_rpi_hifiberry_amp_of_match[] = {
  122840. + { .compatible = "hifiberry,hifiberry-amp", },
  122841. + {},
  122842. +};
  122843. +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_amp_of_match);
  122844. +
  122845. +
  122846. +static int snd_rpi_hifiberry_amp_probe(struct platform_device *pdev)
  122847. +{
  122848. + int ret = 0;
  122849. +
  122850. + snd_rpi_hifiberry_amp.dev = &pdev->dev;
  122851. +
  122852. + if (pdev->dev.of_node) {
  122853. + struct device_node *i2s_node;
  122854. + struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_amp_dai[0];
  122855. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  122856. + "i2s-controller", 0);
  122857. +
  122858. + if (i2s_node) {
  122859. + dai->cpu_dai_name = NULL;
  122860. + dai->cpu_of_node = i2s_node;
  122861. + dai->platform_name = NULL;
  122862. + dai->platform_of_node = i2s_node;
  122863. + }
  122864. + }
  122865. +
  122866. + ret = snd_soc_register_card(&snd_rpi_hifiberry_amp);
  122867. +
  122868. + if (ret != 0) {
  122869. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  122870. + }
  122871. +
  122872. + return ret;
  122873. +}
  122874. +
  122875. +
  122876. +static int snd_rpi_hifiberry_amp_remove(struct platform_device *pdev)
  122877. +{
  122878. + return snd_soc_unregister_card(&snd_rpi_hifiberry_amp);
  122879. +}
  122880. +
  122881. +
  122882. +static struct platform_driver snd_rpi_hifiberry_amp_driver = {
  122883. + .driver = {
  122884. + .name = "snd-hifiberry-amp",
  122885. + .owner = THIS_MODULE,
  122886. + .of_match_table = snd_rpi_hifiberry_amp_of_match,
  122887. + },
  122888. + .probe = snd_rpi_hifiberry_amp_probe,
  122889. + .remove = snd_rpi_hifiberry_amp_remove,
  122890. +};
  122891. +
  122892. +
  122893. +module_platform_driver(snd_rpi_hifiberry_amp_driver);
  122894. +
  122895. +
  122896. +MODULE_AUTHOR("Sebastian Eickhoff <basti.eickhoff@googlemail.com>");
  122897. +MODULE_DESCRIPTION("ASoC driver for HiFiBerry-AMP");
  122898. +MODULE_LICENSE("GPL v2");
  122899. diff -Nur linux-3.18.6/sound/soc/bcm/hifiberry_dac.c linux-rpi/sound/soc/bcm/hifiberry_dac.c
  122900. --- linux-3.18.6/sound/soc/bcm/hifiberry_dac.c 1970-01-01 01:00:00.000000000 +0100
  122901. +++ linux-rpi/sound/soc/bcm/hifiberry_dac.c 2015-02-09 04:40:48.000000000 +0100
  122902. @@ -0,0 +1,122 @@
  122903. +/*
  122904. + * ASoC Driver for HifiBerry DAC
  122905. + *
  122906. + * Author: Florian Meier <florian.meier@koalo.de>
  122907. + * Copyright 2013
  122908. + *
  122909. + * This program is free software; you can redistribute it and/or
  122910. + * modify it under the terms of the GNU General Public License
  122911. + * version 2 as published by the Free Software Foundation.
  122912. + *
  122913. + * This program is distributed in the hope that it will be useful, but
  122914. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  122915. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  122916. + * General Public License for more details.
  122917. + */
  122918. +
  122919. +#include <linux/module.h>
  122920. +#include <linux/platform_device.h>
  122921. +
  122922. +#include <sound/core.h>
  122923. +#include <sound/pcm.h>
  122924. +#include <sound/pcm_params.h>
  122925. +#include <sound/soc.h>
  122926. +#include <sound/jack.h>
  122927. +
  122928. +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
  122929. +{
  122930. + return 0;
  122931. +}
  122932. +
  122933. +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
  122934. + struct snd_pcm_hw_params *params)
  122935. +{
  122936. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  122937. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  122938. +
  122939. + unsigned int sample_bits =
  122940. + snd_pcm_format_physical_width(params_format(params));
  122941. +
  122942. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  122943. +}
  122944. +
  122945. +/* machine stream operations */
  122946. +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
  122947. + .hw_params = snd_rpi_hifiberry_dac_hw_params,
  122948. +};
  122949. +
  122950. +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
  122951. +{
  122952. + .name = "HifiBerry DAC",
  122953. + .stream_name = "HifiBerry DAC HiFi",
  122954. + .cpu_dai_name = "bcm2708-i2s.0",
  122955. + .codec_dai_name = "pcm5102a-hifi",
  122956. + .platform_name = "bcm2708-i2s.0",
  122957. + .codec_name = "pcm5102a-codec",
  122958. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  122959. + SND_SOC_DAIFMT_CBS_CFS,
  122960. + .ops = &snd_rpi_hifiberry_dac_ops,
  122961. + .init = snd_rpi_hifiberry_dac_init,
  122962. +},
  122963. +};
  122964. +
  122965. +/* audio machine driver */
  122966. +static struct snd_soc_card snd_rpi_hifiberry_dac = {
  122967. + .name = "snd_rpi_hifiberry_dac",
  122968. + .dai_link = snd_rpi_hifiberry_dac_dai,
  122969. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
  122970. +};
  122971. +
  122972. +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
  122973. +{
  122974. + int ret = 0;
  122975. +
  122976. + snd_rpi_hifiberry_dac.dev = &pdev->dev;
  122977. +
  122978. + if (pdev->dev.of_node) {
  122979. + struct device_node *i2s_node;
  122980. + struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_dac_dai[0];
  122981. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  122982. + "i2s-controller", 0);
  122983. +
  122984. + if (i2s_node) {
  122985. + dai->cpu_dai_name = NULL;
  122986. + dai->cpu_of_node = i2s_node;
  122987. + dai->platform_name = NULL;
  122988. + dai->platform_of_node = i2s_node;
  122989. + }
  122990. + }
  122991. +
  122992. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
  122993. + if (ret)
  122994. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  122995. +
  122996. + return ret;
  122997. +}
  122998. +
  122999. +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
  123000. +{
  123001. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
  123002. +}
  123003. +
  123004. +static const struct of_device_id snd_rpi_hifiberry_dac_of_match[] = {
  123005. + { .compatible = "hifiberry,hifiberry-dac", },
  123006. + {},
  123007. +};
  123008. +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dac_of_match);
  123009. +
  123010. +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
  123011. + .driver = {
  123012. + .name = "snd-hifiberry-dac",
  123013. + .owner = THIS_MODULE,
  123014. + .of_match_table = snd_rpi_hifiberry_dac_of_match,
  123015. + },
  123016. + .probe = snd_rpi_hifiberry_dac_probe,
  123017. + .remove = snd_rpi_hifiberry_dac_remove,
  123018. +};
  123019. +
  123020. +module_platform_driver(snd_rpi_hifiberry_dac_driver);
  123021. +
  123022. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  123023. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
  123024. +MODULE_LICENSE("GPL v2");
  123025. diff -Nur linux-3.18.6/sound/soc/bcm/hifiberry_dacplus.c linux-rpi/sound/soc/bcm/hifiberry_dacplus.c
  123026. --- linux-3.18.6/sound/soc/bcm/hifiberry_dacplus.c 1970-01-01 01:00:00.000000000 +0100
  123027. +++ linux-rpi/sound/soc/bcm/hifiberry_dacplus.c 2015-02-09 04:40:48.000000000 +0100
  123028. @@ -0,0 +1,141 @@
  123029. +/*
  123030. + * ASoC Driver for HiFiBerry DAC+
  123031. + *
  123032. + * Author: Daniel Matuschek
  123033. + * Copyright 2014
  123034. + * based on code by Florian Meier <florian.meier@koalo.de>
  123035. + *
  123036. + * This program is free software; you can redistribute it and/or
  123037. + * modify it under the terms of the GNU General Public License
  123038. + * version 2 as published by the Free Software Foundation.
  123039. + *
  123040. + * This program is distributed in the hope that it will be useful, but
  123041. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  123042. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  123043. + * General Public License for more details.
  123044. + */
  123045. +
  123046. +#include <linux/module.h>
  123047. +#include <linux/platform_device.h>
  123048. +
  123049. +#include <sound/core.h>
  123050. +#include <sound/pcm.h>
  123051. +#include <sound/pcm_params.h>
  123052. +#include <sound/soc.h>
  123053. +#include <sound/jack.h>
  123054. +
  123055. +#include "../codecs/pcm512x.h"
  123056. +
  123057. +static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
  123058. +{
  123059. + struct snd_soc_codec *codec = rtd->codec;
  123060. + snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
  123061. + snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
  123062. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
  123063. + return 0;
  123064. +}
  123065. +
  123066. +static int snd_rpi_hifiberry_dacplus_hw_params(struct snd_pcm_substream *substream,
  123067. + struct snd_pcm_hw_params *params)
  123068. +{
  123069. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  123070. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  123071. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
  123072. +}
  123073. +
  123074. +static int snd_rpi_hifiberry_dacplus_startup(struct snd_pcm_substream *substream) {
  123075. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  123076. + struct snd_soc_codec *codec = rtd->codec;
  123077. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
  123078. + return 0;
  123079. +}
  123080. +
  123081. +static void snd_rpi_hifiberry_dacplus_shutdown(struct snd_pcm_substream *substream) {
  123082. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  123083. + struct snd_soc_codec *codec = rtd->codec;
  123084. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
  123085. +}
  123086. +
  123087. +/* machine stream operations */
  123088. +static struct snd_soc_ops snd_rpi_hifiberry_dacplus_ops = {
  123089. + .hw_params = snd_rpi_hifiberry_dacplus_hw_params,
  123090. + .startup = snd_rpi_hifiberry_dacplus_startup,
  123091. + .shutdown = snd_rpi_hifiberry_dacplus_shutdown,
  123092. +};
  123093. +
  123094. +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = {
  123095. +{
  123096. + .name = "HiFiBerry DAC+",
  123097. + .stream_name = "HiFiBerry DAC+ HiFi",
  123098. + .cpu_dai_name = "bcm2708-i2s.0",
  123099. + .codec_dai_name = "pcm512x-hifi",
  123100. + .platform_name = "bcm2708-i2s.0",
  123101. + .codec_name = "pcm512x.1-004d",
  123102. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  123103. + SND_SOC_DAIFMT_CBS_CFS,
  123104. + .ops = &snd_rpi_hifiberry_dacplus_ops,
  123105. + .init = snd_rpi_hifiberry_dacplus_init,
  123106. +},
  123107. +};
  123108. +
  123109. +/* audio machine driver */
  123110. +static struct snd_soc_card snd_rpi_hifiberry_dacplus = {
  123111. + .name = "snd_rpi_hifiberry_dacplus",
  123112. + .dai_link = snd_rpi_hifiberry_dacplus_dai,
  123113. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai),
  123114. +};
  123115. +
  123116. +static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
  123117. +{
  123118. + int ret = 0;
  123119. +
  123120. + snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
  123121. +
  123122. + if (pdev->dev.of_node) {
  123123. + struct device_node *i2s_node;
  123124. + struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_dacplus_dai[0];
  123125. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  123126. + "i2s-controller", 0);
  123127. +
  123128. + if (i2s_node) {
  123129. + dai->cpu_dai_name = NULL;
  123130. + dai->cpu_of_node = i2s_node;
  123131. + dai->platform_name = NULL;
  123132. + dai->platform_of_node = i2s_node;
  123133. + }
  123134. + }
  123135. +
  123136. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplus);
  123137. + if (ret)
  123138. + dev_err(&pdev->dev,
  123139. + "snd_soc_register_card() failed: %d\n", ret);
  123140. +
  123141. + return ret;
  123142. +}
  123143. +
  123144. +static int snd_rpi_hifiberry_dacplus_remove(struct platform_device *pdev)
  123145. +{
  123146. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dacplus);
  123147. +}
  123148. +
  123149. +static const struct of_device_id snd_rpi_hifiberry_dacplus_of_match[] = {
  123150. + { .compatible = "hifiberry,hifiberry-dacplus", },
  123151. + {},
  123152. +};
  123153. +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplus_of_match);
  123154. +
  123155. +static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
  123156. + .driver = {
  123157. + .name = "snd-rpi-hifiberry-dacplus",
  123158. + .owner = THIS_MODULE,
  123159. + .of_match_table = snd_rpi_hifiberry_dacplus_of_match,
  123160. + },
  123161. + .probe = snd_rpi_hifiberry_dacplus_probe,
  123162. + .remove = snd_rpi_hifiberry_dacplus_remove,
  123163. +};
  123164. +
  123165. +module_platform_driver(snd_rpi_hifiberry_dacplus_driver);
  123166. +
  123167. +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
  123168. +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+");
  123169. +MODULE_LICENSE("GPL v2");
  123170. diff -Nur linux-3.18.6/sound/soc/bcm/hifiberry_digi.c linux-rpi/sound/soc/bcm/hifiberry_digi.c
  123171. --- linux-3.18.6/sound/soc/bcm/hifiberry_digi.c 1970-01-01 01:00:00.000000000 +0100
  123172. +++ linux-rpi/sound/soc/bcm/hifiberry_digi.c 2015-02-09 04:40:48.000000000 +0100
  123173. @@ -0,0 +1,203 @@
  123174. +/*
  123175. + * ASoC Driver for HifiBerry Digi
  123176. + *
  123177. + * Author: Daniel Matuschek <info@crazy-audio.com>
  123178. + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
  123179. + * Copyright 2013
  123180. + *
  123181. + * This program is free software; you can redistribute it and/or
  123182. + * modify it under the terms of the GNU General Public License
  123183. + * version 2 as published by the Free Software Foundation.
  123184. + *
  123185. + * This program is distributed in the hope that it will be useful, but
  123186. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  123187. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  123188. + * General Public License for more details.
  123189. + */
  123190. +
  123191. +#include <linux/module.h>
  123192. +#include <linux/platform_device.h>
  123193. +
  123194. +#include <sound/core.h>
  123195. +#include <sound/pcm.h>
  123196. +#include <sound/pcm_params.h>
  123197. +#include <sound/soc.h>
  123198. +#include <sound/jack.h>
  123199. +
  123200. +#include "../codecs/wm8804.h"
  123201. +
  123202. +static short int auto_shutdown_output = 0;
  123203. +module_param(auto_shutdown_output, short, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  123204. +MODULE_PARM_DESC(auto_shutdown_output, "Shutdown SP/DIF output if playback is stopped");
  123205. +
  123206. +
  123207. +static int samplerate=44100;
  123208. +
  123209. +static int snd_rpi_hifiberry_digi_init(struct snd_soc_pcm_runtime *rtd)
  123210. +{
  123211. + struct snd_soc_codec *codec = rtd->codec;
  123212. +
  123213. + /* enable TX output */
  123214. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  123215. +
  123216. + return 0;
  123217. +}
  123218. +
  123219. +static int snd_rpi_hifiberry_digi_startup(struct snd_pcm_substream *substream) {
  123220. + /* turn on digital output */
  123221. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  123222. + struct snd_soc_codec *codec = rtd->codec;
  123223. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x00);
  123224. + return 0;
  123225. +}
  123226. +
  123227. +static void snd_rpi_hifiberry_digi_shutdown(struct snd_pcm_substream *substream) {
  123228. + /* turn off output */
  123229. + if (auto_shutdown_output) {
  123230. + /* turn off output */
  123231. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  123232. + struct snd_soc_codec *codec = rtd->codec;
  123233. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x3c);
  123234. + }
  123235. +}
  123236. +
  123237. +
  123238. +static int snd_rpi_hifiberry_digi_hw_params(struct snd_pcm_substream *substream,
  123239. + struct snd_pcm_hw_params *params)
  123240. +{
  123241. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  123242. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  123243. + struct snd_soc_codec *codec = rtd->codec;
  123244. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  123245. +
  123246. + int sysclk = 27000000; /* This is fixed on this board */
  123247. +
  123248. + long mclk_freq=0;
  123249. + int mclk_div=1;
  123250. +
  123251. + int ret;
  123252. +
  123253. + samplerate = params_rate(params);
  123254. +
  123255. + switch (samplerate) {
  123256. + case 32000:
  123257. + case 44100:
  123258. + case 48000:
  123259. + case 88200:
  123260. + case 96000:
  123261. + mclk_freq=samplerate*256;
  123262. + mclk_div=WM8804_MCLKDIV_256FS;
  123263. + break;
  123264. + case 176400:
  123265. + case 192000:
  123266. + mclk_freq=samplerate*128;
  123267. + mclk_div=WM8804_MCLKDIV_128FS;
  123268. + break;
  123269. + default:
  123270. + dev_err(substream->pcm->dev,
  123271. + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
  123272. + samplerate);
  123273. + }
  123274. +
  123275. + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  123276. + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
  123277. +
  123278. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
  123279. + sysclk, SND_SOC_CLOCK_OUT);
  123280. + if (ret < 0) {
  123281. + dev_err(substream->pcm->dev,
  123282. + "Failed to set WM8804 SYSCLK: %d\n", ret);
  123283. + return ret;
  123284. + }
  123285. +
  123286. + /* Enable TX output */
  123287. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  123288. +
  123289. + /* Power on */
  123290. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
  123291. +
  123292. + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
  123293. +}
  123294. +
  123295. +/* machine stream operations */
  123296. +static struct snd_soc_ops snd_rpi_hifiberry_digi_ops = {
  123297. + .hw_params = snd_rpi_hifiberry_digi_hw_params,
  123298. + .startup = snd_rpi_hifiberry_digi_startup,
  123299. + .shutdown = snd_rpi_hifiberry_digi_shutdown,
  123300. +};
  123301. +
  123302. +static struct snd_soc_dai_link snd_rpi_hifiberry_digi_dai[] = {
  123303. +{
  123304. + .name = "HifiBerry Digi",
  123305. + .stream_name = "HifiBerry Digi HiFi",
  123306. + .cpu_dai_name = "bcm2708-i2s.0",
  123307. + .codec_dai_name = "wm8804-spdif",
  123308. + .platform_name = "bcm2708-i2s.0",
  123309. + .codec_name = "wm8804.1-003b",
  123310. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  123311. + SND_SOC_DAIFMT_CBM_CFM,
  123312. + .ops = &snd_rpi_hifiberry_digi_ops,
  123313. + .init = snd_rpi_hifiberry_digi_init,
  123314. +},
  123315. +};
  123316. +
  123317. +/* audio machine driver */
  123318. +static struct snd_soc_card snd_rpi_hifiberry_digi = {
  123319. + .name = "snd_rpi_hifiberry_digi",
  123320. + .dai_link = snd_rpi_hifiberry_digi_dai,
  123321. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_digi_dai),
  123322. +};
  123323. +
  123324. +static int snd_rpi_hifiberry_digi_probe(struct platform_device *pdev)
  123325. +{
  123326. + int ret = 0;
  123327. +
  123328. + snd_rpi_hifiberry_digi.dev = &pdev->dev;
  123329. +
  123330. + if (pdev->dev.of_node) {
  123331. + struct device_node *i2s_node;
  123332. + struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_digi_dai[0];
  123333. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  123334. + "i2s-controller", 0);
  123335. +
  123336. + if (i2s_node) {
  123337. + dai->cpu_dai_name = NULL;
  123338. + dai->cpu_of_node = i2s_node;
  123339. + dai->platform_name = NULL;
  123340. + dai->platform_of_node = i2s_node;
  123341. + }
  123342. + }
  123343. +
  123344. + ret = snd_soc_register_card(&snd_rpi_hifiberry_digi);
  123345. + if (ret)
  123346. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  123347. +
  123348. + return ret;
  123349. +}
  123350. +
  123351. +static int snd_rpi_hifiberry_digi_remove(struct platform_device *pdev)
  123352. +{
  123353. + return snd_soc_unregister_card(&snd_rpi_hifiberry_digi);
  123354. +}
  123355. +
  123356. +static const struct of_device_id snd_rpi_hifiberry_digi_of_match[] = {
  123357. + { .compatible = "hifiberry,hifiberry-digi", },
  123358. + {},
  123359. +};
  123360. +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_digi_of_match);
  123361. +
  123362. +static struct platform_driver snd_rpi_hifiberry_digi_driver = {
  123363. + .driver = {
  123364. + .name = "snd-hifiberry-digi",
  123365. + .owner = THIS_MODULE,
  123366. + .of_match_table = snd_rpi_hifiberry_digi_of_match,
  123367. + },
  123368. + .probe = snd_rpi_hifiberry_digi_probe,
  123369. + .remove = snd_rpi_hifiberry_digi_remove,
  123370. +};
  123371. +
  123372. +module_platform_driver(snd_rpi_hifiberry_digi_driver);
  123373. +
  123374. +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
  123375. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry Digi");
  123376. +MODULE_LICENSE("GPL v2");
  123377. diff -Nur linux-3.18.6/sound/soc/bcm/iqaudio-dac.c linux-rpi/sound/soc/bcm/iqaudio-dac.c
  123378. --- linux-3.18.6/sound/soc/bcm/iqaudio-dac.c 1970-01-01 01:00:00.000000000 +0100
  123379. +++ linux-rpi/sound/soc/bcm/iqaudio-dac.c 2015-02-09 04:40:48.000000000 +0100
  123380. @@ -0,0 +1,127 @@
  123381. +/*
  123382. + * ASoC Driver for IQaudIO DAC
  123383. + *
  123384. + * Author: Florian Meier <florian.meier@koalo.de>
  123385. + * Copyright 2013
  123386. + *
  123387. + * This program is free software; you can redistribute it and/or
  123388. + * modify it under the terms of the GNU General Public License
  123389. + * version 2 as published by the Free Software Foundation.
  123390. + *
  123391. + * This program is distributed in the hope that it will be useful, but
  123392. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  123393. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  123394. + * General Public License for more details.
  123395. + */
  123396. +
  123397. +#include <linux/module.h>
  123398. +#include <linux/platform_device.h>
  123399. +
  123400. +#include <sound/core.h>
  123401. +#include <sound/pcm.h>
  123402. +#include <sound/pcm_params.h>
  123403. +#include <sound/soc.h>
  123404. +#include <sound/jack.h>
  123405. +
  123406. +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
  123407. +{
  123408. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  123409. +
  123410. + return 0;
  123411. +}
  123412. +
  123413. +static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream,
  123414. + struct snd_pcm_hw_params *params)
  123415. +{
  123416. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  123417. +// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai;
  123418. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  123419. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  123420. +
  123421. + unsigned int sample_bits =
  123422. + snd_pcm_format_physical_width(params_format(params));
  123423. +
  123424. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  123425. +}
  123426. +
  123427. +/* machine stream operations */
  123428. +static struct snd_soc_ops snd_rpi_iqaudio_dac_ops = {
  123429. + .hw_params = snd_rpi_iqaudio_dac_hw_params,
  123430. +};
  123431. +
  123432. +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
  123433. +{
  123434. + .name = "IQaudIO DAC",
  123435. + .stream_name = "IQaudIO DAC HiFi",
  123436. + .cpu_dai_name = "bcm2708-i2s.0",
  123437. + .codec_dai_name = "pcm512x-hifi",
  123438. + .platform_name = "bcm2708-i2s.0",
  123439. + .codec_name = "pcm512x.1-004c",
  123440. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  123441. + SND_SOC_DAIFMT_CBS_CFS,
  123442. + .ops = &snd_rpi_iqaudio_dac_ops,
  123443. + .init = snd_rpi_iqaudio_dac_init,
  123444. +},
  123445. +};
  123446. +
  123447. +/* audio machine driver */
  123448. +static struct snd_soc_card snd_rpi_iqaudio_dac = {
  123449. + .name = "IQaudIODAC",
  123450. + .dai_link = snd_rpi_iqaudio_dac_dai,
  123451. + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
  123452. +};
  123453. +
  123454. +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
  123455. +{
  123456. + int ret = 0;
  123457. +
  123458. + snd_rpi_iqaudio_dac.dev = &pdev->dev;
  123459. +
  123460. + if (pdev->dev.of_node) {
  123461. + struct device_node *i2s_node;
  123462. + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_dac_dai[0];
  123463. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  123464. + "i2s-controller", 0);
  123465. +
  123466. + if (i2s_node) {
  123467. + dai->cpu_dai_name = NULL;
  123468. + dai->cpu_of_node = i2s_node;
  123469. + dai->platform_name = NULL;
  123470. + dai->platform_of_node = i2s_node;
  123471. + }
  123472. + }
  123473. +
  123474. + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
  123475. + if (ret)
  123476. + dev_err(&pdev->dev,
  123477. + "snd_soc_register_card() failed: %d\n", ret);
  123478. +
  123479. + return ret;
  123480. +}
  123481. +
  123482. +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
  123483. +{
  123484. + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
  123485. +}
  123486. +
  123487. +static const struct of_device_id iqaudio_of_match[] = {
  123488. + { .compatible = "iqaudio,iqaudio-dac", },
  123489. + {},
  123490. +};
  123491. +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
  123492. +
  123493. +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
  123494. + .driver = {
  123495. + .name = "snd-rpi-iqaudio-dac",
  123496. + .owner = THIS_MODULE,
  123497. + .of_match_table = iqaudio_of_match,
  123498. + },
  123499. + .probe = snd_rpi_iqaudio_dac_probe,
  123500. + .remove = snd_rpi_iqaudio_dac_remove,
  123501. +};
  123502. +
  123503. +module_platform_driver(snd_rpi_iqaudio_dac_driver);
  123504. +
  123505. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  123506. +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
  123507. +MODULE_LICENSE("GPL v2");
  123508. diff -Nur linux-3.18.6/sound/soc/bcm/Kconfig linux-rpi/sound/soc/bcm/Kconfig
  123509. --- linux-3.18.6/sound/soc/bcm/Kconfig 2015-02-06 15:53:48.000000000 +0100
  123510. +++ linux-rpi/sound/soc/bcm/Kconfig 2015-02-09 04:40:48.000000000 +0100
  123511. @@ -7,3 +7,56 @@
  123512. Say Y or M if you want to add support for codecs attached to
  123513. the BCM2835 I2S interface. You will also need
  123514. to select the audio interfaces to support below.
  123515. +
  123516. +config SND_BCM2708_SOC_I2S
  123517. + tristate "SoC Audio support for the Broadcom BCM2708 I2S module"
  123518. + depends on MACH_BCM2708 || MACH_BCM2709
  123519. + select REGMAP_MMIO
  123520. + select SND_SOC_DMAENGINE_PCM
  123521. + select SND_SOC_GENERIC_DMAENGINE_PCM
  123522. + help
  123523. + Say Y or M if you want to add support for codecs attached to
  123524. + the BCM2708 I2S interface. You will also need
  123525. + to select the audio interfaces to support below.
  123526. +
  123527. +config SND_BCM2708_SOC_HIFIBERRY_DAC
  123528. + tristate "Support for HifiBerry DAC"
  123529. + depends on SND_BCM2708_SOC_I2S
  123530. + select SND_SOC_PCM5102A
  123531. + help
  123532. + Say Y or M if you want to add support for HifiBerry DAC.
  123533. +
  123534. +config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
  123535. + tristate "Support for HifiBerry DAC+"
  123536. + depends on SND_BCM2708_SOC_I2S
  123537. + select SND_SOC_PCM512x
  123538. + help
  123539. + Say Y or M if you want to add support for HifiBerry DAC+.
  123540. +
  123541. +config SND_BCM2708_SOC_HIFIBERRY_DIGI
  123542. + tristate "Support for HifiBerry Digi"
  123543. + depends on SND_BCM2708_SOC_I2S
  123544. + select SND_SOC_WM8804
  123545. + help
  123546. + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
  123547. +
  123548. +config SND_BCM2708_SOC_HIFIBERRY_AMP
  123549. + tristate "Support for the HifiBerry Amp"
  123550. + depends on SND_BCM2708_SOC_I2S
  123551. + select SND_SOC_TAS5713
  123552. + help
  123553. + Say Y or M if you want to add support for the HifiBerry Amp amplifier board.
  123554. +
  123555. +config SND_BCM2708_SOC_RPI_DAC
  123556. + tristate "Support for RPi-DAC"
  123557. + depends on SND_BCM2708_SOC_I2S
  123558. + select SND_SOC_PCM1794A
  123559. + help
  123560. + Say Y or M if you want to add support for RPi-DAC.
  123561. +
  123562. +config SND_BCM2708_SOC_IQAUDIO_DAC
  123563. + tristate "Support for IQaudIO-DAC"
  123564. + depends on SND_BCM2708_SOC_I2S
  123565. + select SND_SOC_PCM512x_I2C
  123566. + help
  123567. + Say Y or M if you want to add support for IQaudIO-DAC.
  123568. diff -Nur linux-3.18.6/sound/soc/bcm/Makefile linux-rpi/sound/soc/bcm/Makefile
  123569. --- linux-3.18.6/sound/soc/bcm/Makefile 2015-02-06 15:53:48.000000000 +0100
  123570. +++ linux-rpi/sound/soc/bcm/Makefile 2015-02-09 04:40:48.000000000 +0100
  123571. @@ -3,3 +3,22 @@
  123572. obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd-soc-bcm2835-i2s.o
  123573. +# BCM2708 Platform Support
  123574. +snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
  123575. +
  123576. +obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
  123577. +
  123578. +# BCM2708 Machine Support
  123579. +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  123580. +snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
  123581. +snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  123582. +snd-soc-hifiberry-amp-objs := hifiberry_amp.o
  123583. +snd-soc-rpi-dac-objs := rpi-dac.o
  123584. +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  123585. +
  123586. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  123587. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
  123588. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  123589. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
  123590. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  123591. +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  123592. diff -Nur linux-3.18.6/sound/soc/bcm/rpi-dac.c linux-rpi/sound/soc/bcm/rpi-dac.c
  123593. --- linux-3.18.6/sound/soc/bcm/rpi-dac.c 1970-01-01 01:00:00.000000000 +0100
  123594. +++ linux-rpi/sound/soc/bcm/rpi-dac.c 2015-02-09 04:40:48.000000000 +0100
  123595. @@ -0,0 +1,97 @@
  123596. +/*
  123597. + * ASoC Driver for RPi-DAC.
  123598. + *
  123599. + * Author: Florian Meier <florian.meier@koalo.de>
  123600. + * Copyright 2013
  123601. + *
  123602. + * This program is free software; you can redistribute it and/or
  123603. + * modify it under the terms of the GNU General Public License
  123604. + * version 2 as published by the Free Software Foundation.
  123605. + *
  123606. + * This program is distributed in the hope that it will be useful, but
  123607. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  123608. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  123609. + * General Public License for more details.
  123610. + */
  123611. +
  123612. +#include <linux/module.h>
  123613. +#include <linux/platform_device.h>
  123614. +
  123615. +#include <sound/core.h>
  123616. +#include <sound/pcm.h>
  123617. +#include <sound/pcm_params.h>
  123618. +#include <sound/soc.h>
  123619. +#include <sound/jack.h>
  123620. +
  123621. +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
  123622. +{
  123623. + return 0;
  123624. +}
  123625. +
  123626. +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
  123627. + struct snd_pcm_hw_params *params)
  123628. +{
  123629. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  123630. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  123631. +
  123632. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
  123633. +}
  123634. +
  123635. +/* machine stream operations */
  123636. +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
  123637. + .hw_params = snd_rpi_rpi_dac_hw_params,
  123638. +};
  123639. +
  123640. +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
  123641. +{
  123642. + .name = "RPi-DAC",
  123643. + .stream_name = "RPi-DAC HiFi",
  123644. + .cpu_dai_name = "bcm2708-i2s.0",
  123645. + .codec_dai_name = "pcm1794a-hifi",
  123646. + .platform_name = "bcm2708-i2s.0",
  123647. + .codec_name = "pcm1794a-codec",
  123648. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  123649. + SND_SOC_DAIFMT_CBS_CFS,
  123650. + .ops = &snd_rpi_rpi_dac_ops,
  123651. + .init = snd_rpi_rpi_dac_init,
  123652. +},
  123653. +};
  123654. +
  123655. +/* audio machine driver */
  123656. +static struct snd_soc_card snd_rpi_rpi_dac = {
  123657. + .name = "snd_rpi_rpi_dac",
  123658. + .dai_link = snd_rpi_rpi_dac_dai,
  123659. + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
  123660. +};
  123661. +
  123662. +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
  123663. +{
  123664. + int ret = 0;
  123665. +
  123666. + snd_rpi_rpi_dac.dev = &pdev->dev;
  123667. + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
  123668. + if (ret)
  123669. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  123670. +
  123671. + return ret;
  123672. +}
  123673. +
  123674. +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
  123675. +{
  123676. + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
  123677. +}
  123678. +
  123679. +static struct platform_driver snd_rpi_rpi_dac_driver = {
  123680. + .driver = {
  123681. + .name = "snd-rpi-dac",
  123682. + .owner = THIS_MODULE,
  123683. + },
  123684. + .probe = snd_rpi_rpi_dac_probe,
  123685. + .remove = snd_rpi_rpi_dac_remove,
  123686. +};
  123687. +
  123688. +module_platform_driver(snd_rpi_rpi_dac_driver);
  123689. +
  123690. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  123691. +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
  123692. +MODULE_LICENSE("GPL v2");
  123693. diff -Nur linux-3.18.6/sound/soc/codecs/Kconfig linux-rpi/sound/soc/codecs/Kconfig
  123694. --- linux-3.18.6/sound/soc/codecs/Kconfig 2015-02-06 15:53:48.000000000 +0100
  123695. +++ linux-rpi/sound/soc/codecs/Kconfig 2015-02-09 04:40:48.000000000 +0100
  123696. @@ -80,6 +80,8 @@
  123697. select SND_SOC_PCM512x_I2C if I2C
  123698. select SND_SOC_PCM512x_SPI if SPI_MASTER
  123699. select SND_SOC_RT286 if I2C
  123700. + select SND_SOC_PCM5102A if I2C
  123701. + select SND_SOC_PCM1794A if I2C
  123702. select SND_SOC_RT5631 if I2C
  123703. select SND_SOC_RT5640 if I2C
  123704. select SND_SOC_RT5645 if I2C
  123705. @@ -103,6 +105,7 @@
  123706. select SND_SOC_TAS5086 if I2C
  123707. select SND_SOC_TLV320AIC23_I2C if I2C
  123708. select SND_SOC_TLV320AIC23_SPI if SPI_MASTER
  123709. + select SND_SOC_TAS5713 if I2C
  123710. select SND_SOC_TLV320AIC26 if SPI_MASTER
  123711. select SND_SOC_TLV320AIC31XX if I2C
  123712. select SND_SOC_TLV320AIC32X4 if I2C
  123713. @@ -486,6 +489,12 @@
  123714. tristate
  123715. depends on I2C
  123716. +config SND_SOC_PCM1794A
  123717. + tristate
  123718. +
  123719. +config SND_SOC_PCM5102A
  123720. + tristate
  123721. +
  123722. config SND_SOC_RT5631
  123723. tristate
  123724. @@ -577,6 +586,9 @@
  123725. tristate "Texas Instruments TAS5086 speaker amplifier"
  123726. depends on I2C
  123727. +config SND_SOC_TAS5713
  123728. + tristate
  123729. +
  123730. config SND_SOC_TLV320AIC23
  123731. tristate
  123732. diff -Nur linux-3.18.6/sound/soc/codecs/Makefile linux-rpi/sound/soc/codecs/Makefile
  123733. --- linux-3.18.6/sound/soc/codecs/Makefile 2015-02-06 15:53:48.000000000 +0100
  123734. +++ linux-rpi/sound/soc/codecs/Makefile 2015-02-09 04:40:48.000000000 +0100
  123735. @@ -74,6 +74,8 @@
  123736. snd-soc-pcm512x-spi-objs := pcm512x-spi.o
  123737. snd-soc-rl6231-objs := rl6231.o
  123738. snd-soc-rt286-objs := rt286.o
  123739. +snd-soc-pcm1794a-objs := pcm1794a.o
  123740. +snd-soc-pcm5102a-objs := pcm5102a.o
  123741. snd-soc-rt5631-objs := rt5631.o
  123742. snd-soc-rt5640-objs := rt5640.o
  123743. snd-soc-rt5645-objs := rt5645.o
  123744. @@ -101,6 +103,7 @@
  123745. snd-soc-sta529-objs := sta529.o
  123746. snd-soc-stac9766-objs := stac9766.o
  123747. snd-soc-tas5086-objs := tas5086.o
  123748. +snd-soc-tas5713-objs := tas5713.o
  123749. snd-soc-tlv320aic23-objs := tlv320aic23.o
  123750. snd-soc-tlv320aic23-i2c-objs := tlv320aic23-i2c.o
  123751. snd-soc-tlv320aic23-spi-objs := tlv320aic23-spi.o
  123752. @@ -250,6 +253,8 @@
  123753. obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o
  123754. obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o
  123755. obj-$(CONFIG_SND_SOC_RT286) += snd-soc-rt286.o
  123756. +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
  123757. +obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
  123758. obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
  123759. obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
  123760. obj-$(CONFIG_SND_SOC_RT5645) += snd-soc-rt5645.o
  123761. @@ -274,6 +279,7 @@
  123762. obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o
  123763. obj-$(CONFIG_SND_SOC_TAS2552) += snd-soc-tas2552.o
  123764. obj-$(CONFIG_SND_SOC_TAS5086) += snd-soc-tas5086.o
  123765. +obj-$(CONFIG_SND_SOC_TAS5713) += snd-soc-tas5713.o
  123766. obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o
  123767. obj-$(CONFIG_SND_SOC_TLV320AIC23_I2C) += snd-soc-tlv320aic23-i2c.o
  123768. obj-$(CONFIG_SND_SOC_TLV320AIC23_SPI) += snd-soc-tlv320aic23-spi.o
  123769. diff -Nur linux-3.18.6/sound/soc/codecs/pcm1794a.c linux-rpi/sound/soc/codecs/pcm1794a.c
  123770. --- linux-3.18.6/sound/soc/codecs/pcm1794a.c 1970-01-01 01:00:00.000000000 +0100
  123771. +++ linux-rpi/sound/soc/codecs/pcm1794a.c 2015-02-09 04:40:48.000000000 +0100
  123772. @@ -0,0 +1,62 @@
  123773. +/*
  123774. + * Driver for the PCM1794A codec
  123775. + *
  123776. + * Author: Florian Meier <florian.meier@koalo.de>
  123777. + * Copyright 2013
  123778. + *
  123779. + * This program is free software; you can redistribute it and/or
  123780. + * modify it under the terms of the GNU General Public License
  123781. + * version 2 as published by the Free Software Foundation.
  123782. + *
  123783. + * This program is distributed in the hope that it will be useful, but
  123784. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  123785. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  123786. + * General Public License for more details.
  123787. + */
  123788. +
  123789. +
  123790. +#include <linux/init.h>
  123791. +#include <linux/module.h>
  123792. +#include <linux/platform_device.h>
  123793. +
  123794. +#include <sound/soc.h>
  123795. +
  123796. +static struct snd_soc_dai_driver pcm1794a_dai = {
  123797. + .name = "pcm1794a-hifi",
  123798. + .playback = {
  123799. + .channels_min = 2,
  123800. + .channels_max = 2,
  123801. + .rates = SNDRV_PCM_RATE_8000_192000,
  123802. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  123803. + SNDRV_PCM_FMTBIT_S24_LE
  123804. + },
  123805. +};
  123806. +
  123807. +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
  123808. +
  123809. +static int pcm1794a_probe(struct platform_device *pdev)
  123810. +{
  123811. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
  123812. + &pcm1794a_dai, 1);
  123813. +}
  123814. +
  123815. +static int pcm1794a_remove(struct platform_device *pdev)
  123816. +{
  123817. + snd_soc_unregister_codec(&pdev->dev);
  123818. + return 0;
  123819. +}
  123820. +
  123821. +static struct platform_driver pcm1794a_codec_driver = {
  123822. + .probe = pcm1794a_probe,
  123823. + .remove = pcm1794a_remove,
  123824. + .driver = {
  123825. + .name = "pcm1794a-codec",
  123826. + .owner = THIS_MODULE,
  123827. + },
  123828. +};
  123829. +
  123830. +module_platform_driver(pcm1794a_codec_driver);
  123831. +
  123832. +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
  123833. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  123834. +MODULE_LICENSE("GPL v2");
  123835. diff -Nur linux-3.18.6/sound/soc/codecs/pcm5102a.c linux-rpi/sound/soc/codecs/pcm5102a.c
  123836. --- linux-3.18.6/sound/soc/codecs/pcm5102a.c 1970-01-01 01:00:00.000000000 +0100
  123837. +++ linux-rpi/sound/soc/codecs/pcm5102a.c 2015-02-09 04:40:48.000000000 +0100
  123838. @@ -0,0 +1,70 @@
  123839. +/*
  123840. + * Driver for the PCM5102A codec
  123841. + *
  123842. + * Author: Florian Meier <florian.meier@koalo.de>
  123843. + * Copyright 2013
  123844. + *
  123845. + * This program is free software; you can redistribute it and/or
  123846. + * modify it under the terms of the GNU General Public License
  123847. + * version 2 as published by the Free Software Foundation.
  123848. + *
  123849. + * This program is distributed in the hope that it will be useful, but
  123850. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  123851. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  123852. + * General Public License for more details.
  123853. + */
  123854. +
  123855. +
  123856. +#include <linux/init.h>
  123857. +#include <linux/module.h>
  123858. +#include <linux/platform_device.h>
  123859. +
  123860. +#include <sound/soc.h>
  123861. +
  123862. +static struct snd_soc_dai_driver pcm5102a_dai = {
  123863. + .name = "pcm5102a-hifi",
  123864. + .playback = {
  123865. + .channels_min = 2,
  123866. + .channels_max = 2,
  123867. + .rates = SNDRV_PCM_RATE_8000_192000,
  123868. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  123869. + SNDRV_PCM_FMTBIT_S24_LE |
  123870. + SNDRV_PCM_FMTBIT_S32_LE
  123871. + },
  123872. +};
  123873. +
  123874. +static struct snd_soc_codec_driver soc_codec_dev_pcm5102a;
  123875. +
  123876. +static int pcm5102a_probe(struct platform_device *pdev)
  123877. +{
  123878. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm5102a,
  123879. + &pcm5102a_dai, 1);
  123880. +}
  123881. +
  123882. +static int pcm5102a_remove(struct platform_device *pdev)
  123883. +{
  123884. + snd_soc_unregister_codec(&pdev->dev);
  123885. + return 0;
  123886. +}
  123887. +
  123888. +static const struct of_device_id pcm5102a_of_match[] = {
  123889. + { .compatible = "ti,pcm5102a", },
  123890. + { }
  123891. +};
  123892. +MODULE_DEVICE_TABLE(of, pcm5102a_of_match);
  123893. +
  123894. +static struct platform_driver pcm5102a_codec_driver = {
  123895. + .probe = pcm5102a_probe,
  123896. + .remove = pcm5102a_remove,
  123897. + .driver = {
  123898. + .name = "pcm5102a-codec",
  123899. + .owner = THIS_MODULE,
  123900. + .of_match_table = pcm5102a_of_match,
  123901. + },
  123902. +};
  123903. +
  123904. +module_platform_driver(pcm5102a_codec_driver);
  123905. +
  123906. +MODULE_DESCRIPTION("ASoC PCM5102A codec driver");
  123907. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  123908. +MODULE_LICENSE("GPL v2");
  123909. diff -Nur linux-3.18.6/sound/soc/codecs/pcm512x.c linux-rpi/sound/soc/codecs/pcm512x.c
  123910. --- linux-3.18.6/sound/soc/codecs/pcm512x.c 2015-02-06 15:53:48.000000000 +0100
  123911. +++ linux-rpi/sound/soc/codecs/pcm512x.c 2015-02-09 04:40:48.000000000 +0100
  123912. @@ -259,8 +259,8 @@
  123913. pcm512x_ramp_step_text);
  123914. static const struct snd_kcontrol_new pcm512x_controls[] = {
  123915. -SOC_DOUBLE_R_TLV("Digital Playback Volume", PCM512x_DIGITAL_VOLUME_2,
  123916. - PCM512x_DIGITAL_VOLUME_3, 0, 255, 1, digital_tlv),
  123917. +SOC_DOUBLE_R_RANGE_TLV("PCM", PCM512x_DIGITAL_VOLUME_2,
  123918. + PCM512x_DIGITAL_VOLUME_3, 0, 40, 255, 1, digital_tlv),
  123919. SOC_DOUBLE_TLV("Playback Volume", PCM512x_ANALOG_GAIN_CTRL,
  123920. PCM512x_LAGN_SHIFT, PCM512x_RAGN_SHIFT, 1, 1, analog_tlv),
  123921. SOC_DOUBLE_TLV("Playback Boost Volume", PCM512x_ANALOG_GAIN_BOOST,
  123922. diff -Nur linux-3.18.6/sound/soc/codecs/tas5713.c linux-rpi/sound/soc/codecs/tas5713.c
  123923. --- linux-3.18.6/sound/soc/codecs/tas5713.c 1970-01-01 01:00:00.000000000 +0100
  123924. +++ linux-rpi/sound/soc/codecs/tas5713.c 2015-02-09 04:40:48.000000000 +0100
  123925. @@ -0,0 +1,369 @@
  123926. +/*
  123927. + * ASoC Driver for TAS5713
  123928. + *
  123929. + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
  123930. + * Copyright 2014
  123931. + *
  123932. + * This program is free software; you can redistribute it and/or
  123933. + * modify it under the terms of the GNU General Public License
  123934. + * version 2 as published by the Free Software Foundation.
  123935. + *
  123936. + * This program is distributed in the hope that it will be useful, but
  123937. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  123938. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  123939. + * General Public License for more details.
  123940. + */
  123941. +
  123942. +#include <linux/module.h>
  123943. +#include <linux/moduleparam.h>
  123944. +#include <linux/init.h>
  123945. +#include <linux/delay.h>
  123946. +#include <linux/pm.h>
  123947. +#include <linux/i2c.h>
  123948. +#include <linux/of_device.h>
  123949. +#include <linux/spi/spi.h>
  123950. +#include <linux/regmap.h>
  123951. +#include <linux/regulator/consumer.h>
  123952. +#include <linux/slab.h>
  123953. +#include <sound/core.h>
  123954. +#include <sound/pcm.h>
  123955. +#include <sound/pcm_params.h>
  123956. +#include <sound/soc.h>
  123957. +#include <sound/initval.h>
  123958. +#include <sound/tlv.h>
  123959. +
  123960. +#include <linux/kernel.h>
  123961. +#include <linux/string.h>
  123962. +#include <linux/fs.h>
  123963. +#include <asm/uaccess.h>
  123964. +
  123965. +#include "tas5713.h"
  123966. +
  123967. +
  123968. +static struct i2c_client *i2c;
  123969. +
  123970. +struct tas5713_priv {
  123971. + struct regmap *regmap;
  123972. + int mclk_div;
  123973. + struct snd_soc_codec *codec;
  123974. +};
  123975. +
  123976. +static struct tas5713_priv *priv_data;
  123977. +
  123978. +
  123979. +
  123980. +
  123981. +/*
  123982. + * _ _ ___ _ ___ _ _
  123983. + * /_\ | | / __| /_\ / __|___ _ _| |_ _ _ ___| |___
  123984. + * / _ \| |__\__ \/ _ \ | (__/ _ \ ' \ _| '_/ _ \ (_-<
  123985. + * /_/ \_\____|___/_/ \_\ \___\___/_||_\__|_| \___/_/__/
  123986. + *
  123987. + */
  123988. +
  123989. +static const DECLARE_TLV_DB_SCALE(tas5713_vol_tlv, -10000, 50, 1);
  123990. +
  123991. +
  123992. +static const struct snd_kcontrol_new tas5713_snd_controls[] = {
  123993. + SOC_SINGLE_TLV ("Master" , TAS5713_VOL_MASTER, 0, 248, 1, tas5713_vol_tlv),
  123994. + SOC_DOUBLE_R_TLV("Channels" , TAS5713_VOL_CH1, TAS5713_VOL_CH2, 0, 248, 1, tas5713_vol_tlv)
  123995. +};
  123996. +
  123997. +
  123998. +
  123999. +
  124000. +/*
  124001. + * __ __ _ _ ___ _
  124002. + * | \/ |__ _ __| |_ (_)_ _ ___ | \ _ _(_)_ _____ _ _
  124003. + * | |\/| / _` / _| ' \| | ' \/ -_) | |) | '_| \ V / -_) '_|
  124004. + * |_| |_\__,_\__|_||_|_|_||_\___| |___/|_| |_|\_/\___|_|
  124005. + *
  124006. + */
  124007. +
  124008. +static int tas5713_hw_params(struct snd_pcm_substream *substream,
  124009. + struct snd_pcm_hw_params *params,
  124010. + struct snd_soc_dai *dai)
  124011. +{
  124012. + u16 blen = 0x00;
  124013. +
  124014. + struct snd_soc_codec *codec;
  124015. + codec = dai->codec;
  124016. + priv_data->codec = dai->codec;
  124017. +
  124018. + switch (params_format(params)) {
  124019. + case SNDRV_PCM_FORMAT_S16_LE:
  124020. + blen = 0x03;
  124021. + break;
  124022. + case SNDRV_PCM_FORMAT_S20_3LE:
  124023. + blen = 0x1;
  124024. + break;
  124025. + case SNDRV_PCM_FORMAT_S24_LE:
  124026. + blen = 0x04;
  124027. + break;
  124028. + case SNDRV_PCM_FORMAT_S32_LE:
  124029. + blen = 0x05;
  124030. + break;
  124031. + default:
  124032. + dev_err(dai->dev, "Unsupported word length: %u\n",
  124033. + params_format(params));
  124034. + return -EINVAL;
  124035. + }
  124036. +
  124037. + // set word length
  124038. + snd_soc_update_bits(codec, TAS5713_SERIAL_DATA_INTERFACE, 0x7, blen);
  124039. +
  124040. + return 0;
  124041. +}
  124042. +
  124043. +
  124044. +static int tas5713_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
  124045. +{
  124046. + unsigned int val = 0;
  124047. +
  124048. + struct tas5713_priv *tas5713;
  124049. + struct snd_soc_codec *codec = dai->codec;
  124050. + tas5713 = snd_soc_codec_get_drvdata(codec);
  124051. +
  124052. + if (mute) {
  124053. + val = TAS5713_SOFT_MUTE_ALL;
  124054. + }
  124055. +
  124056. + return regmap_write(tas5713->regmap, TAS5713_SOFT_MUTE, val);
  124057. +}
  124058. +
  124059. +
  124060. +static const struct snd_soc_dai_ops tas5713_dai_ops = {
  124061. + .hw_params = tas5713_hw_params,
  124062. + .mute_stream = tas5713_mute_stream,
  124063. +};
  124064. +
  124065. +
  124066. +static struct snd_soc_dai_driver tas5713_dai = {
  124067. + .name = "tas5713-hifi",
  124068. + .playback = {
  124069. + .stream_name = "Playback",
  124070. + .channels_min = 2,
  124071. + .channels_max = 2,
  124072. + .rates = SNDRV_PCM_RATE_8000_48000,
  124073. + .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE ),
  124074. + },
  124075. + .ops = &tas5713_dai_ops,
  124076. +};
  124077. +
  124078. +
  124079. +
  124080. +
  124081. +/*
  124082. + * ___ _ ___ _
  124083. + * / __|___ __| |___ __ | \ _ _(_)_ _____ _ _
  124084. + * | (__/ _ \/ _` / -_) _| | |) | '_| \ V / -_) '_|
  124085. + * \___\___/\__,_\___\__| |___/|_| |_|\_/\___|_|
  124086. + *
  124087. + */
  124088. +
  124089. +static int tas5713_remove(struct snd_soc_codec *codec)
  124090. +{
  124091. + struct tas5713_priv *tas5713;
  124092. +
  124093. + tas5713 = snd_soc_codec_get_drvdata(codec);
  124094. +
  124095. + return 0;
  124096. +}
  124097. +
  124098. +
  124099. +static int tas5713_probe(struct snd_soc_codec *codec)
  124100. +{
  124101. + struct tas5713_priv *tas5713;
  124102. + int i, ret;
  124103. +
  124104. + i2c = container_of(codec->dev, struct i2c_client, dev);
  124105. +
  124106. + tas5713 = snd_soc_codec_get_drvdata(codec);
  124107. +
  124108. + // Reset error
  124109. + ret = snd_soc_write(codec, TAS5713_ERROR_STATUS, 0x00);
  124110. + if (ret < 0) return ret;
  124111. +
  124112. + // Trim oscillator
  124113. + ret = snd_soc_write(codec, TAS5713_OSC_TRIM, 0x00);
  124114. + if (ret < 0) return ret;
  124115. + msleep(1000);
  124116. +
  124117. + // Reset error
  124118. + ret = snd_soc_write(codec, TAS5713_ERROR_STATUS, 0x00);
  124119. + if (ret < 0) return ret;
  124120. +
  124121. + // Clock mode: 44/48kHz, MCLK=64xfs
  124122. + ret = snd_soc_write(codec, TAS5713_CLOCK_CTRL, 0x60);
  124123. + if (ret < 0) return ret;
  124124. +
  124125. + // I2S 24bit
  124126. + ret = snd_soc_write(codec, TAS5713_SERIAL_DATA_INTERFACE, 0x05);
  124127. + if (ret < 0) return ret;
  124128. +
  124129. + // Unmute
  124130. + ret = snd_soc_write(codec, TAS5713_SYSTEM_CTRL2, 0x00);
  124131. + if (ret < 0) return ret;
  124132. + ret = snd_soc_write(codec, TAS5713_SOFT_MUTE, 0x00);
  124133. + if (ret < 0) return ret;
  124134. +
  124135. + // Set volume to 0db
  124136. + ret = snd_soc_write(codec, TAS5713_VOL_MASTER, 0x00);
  124137. + if (ret < 0) return ret;
  124138. +
  124139. + // Now start programming the default initialization sequence
  124140. + for (i = 0; i < ARRAY_SIZE(tas5713_init_sequence); ++i) {
  124141. + ret = i2c_master_send(i2c,
  124142. + tas5713_init_sequence[i].data,
  124143. + tas5713_init_sequence[i].size);
  124144. + if (ret < 0) {
  124145. + printk(KERN_INFO "TAS5713 CODEC PROBE: InitSeq returns: %d\n", ret);
  124146. + }
  124147. + }
  124148. +
  124149. + // Unmute
  124150. + ret = snd_soc_write(codec, TAS5713_SYSTEM_CTRL2, 0x00);
  124151. + if (ret < 0) return ret;
  124152. +
  124153. + return 0;
  124154. +}
  124155. +
  124156. +
  124157. +static struct snd_soc_codec_driver soc_codec_dev_tas5713 = {
  124158. + .probe = tas5713_probe,
  124159. + .remove = tas5713_remove,
  124160. + .controls = tas5713_snd_controls,
  124161. + .num_controls = ARRAY_SIZE(tas5713_snd_controls),
  124162. +};
  124163. +
  124164. +
  124165. +
  124166. +
  124167. +/*
  124168. + * ___ ___ ___ ___ _
  124169. + * |_ _|_ ) __| | \ _ _(_)_ _____ _ _
  124170. + * | | / / (__ | |) | '_| \ V / -_) '_|
  124171. + * |___/___\___| |___/|_| |_|\_/\___|_|
  124172. + *
  124173. + */
  124174. +
  124175. +static const struct reg_default tas5713_reg_defaults[] = {
  124176. + { 0x07 ,0x80 }, // R7 - VOL_MASTER - -40dB
  124177. + { 0x08 , 30 }, // R8 - VOL_CH1 - 0dB
  124178. + { 0x09 , 30 }, // R9 - VOL_CH2 - 0dB
  124179. + { 0x0A ,0x80 }, // R10 - VOL_HEADPHONE - -40dB
  124180. +};
  124181. +
  124182. +
  124183. +static bool tas5713_reg_volatile(struct device *dev, unsigned int reg)
  124184. +{
  124185. + switch (reg) {
  124186. + case TAS5713_DEVICE_ID:
  124187. + case TAS5713_ERROR_STATUS:
  124188. + return true;
  124189. + default:
  124190. + return false;
  124191. + }
  124192. +}
  124193. +
  124194. +
  124195. +static const struct of_device_id tas5713_of_match[] = {
  124196. + { .compatible = "ti,tas5713", },
  124197. + { }
  124198. +};
  124199. +MODULE_DEVICE_TABLE(of, tas5713_of_match);
  124200. +
  124201. +
  124202. +static struct regmap_config tas5713_regmap_config = {
  124203. + .reg_bits = 8,
  124204. + .val_bits = 8,
  124205. +
  124206. + .max_register = TAS5713_MAX_REGISTER,
  124207. + .volatile_reg = tas5713_reg_volatile,
  124208. +
  124209. + .cache_type = REGCACHE_RBTREE,
  124210. + .reg_defaults = tas5713_reg_defaults,
  124211. + .num_reg_defaults = ARRAY_SIZE(tas5713_reg_defaults),
  124212. +};
  124213. +
  124214. +
  124215. +static int tas5713_i2c_probe(struct i2c_client *i2c,
  124216. + const struct i2c_device_id *id)
  124217. +{
  124218. + int ret;
  124219. +
  124220. + priv_data = devm_kzalloc(&i2c->dev, sizeof *priv_data, GFP_KERNEL);
  124221. + if (!priv_data)
  124222. + return -ENOMEM;
  124223. +
  124224. + priv_data->regmap = devm_regmap_init_i2c(i2c, &tas5713_regmap_config);
  124225. + if (IS_ERR(priv_data->regmap)) {
  124226. + ret = PTR_ERR(priv_data->regmap);
  124227. + return ret;
  124228. + }
  124229. +
  124230. + i2c_set_clientdata(i2c, priv_data);
  124231. +
  124232. + ret = snd_soc_register_codec(&i2c->dev,
  124233. + &soc_codec_dev_tas5713, &tas5713_dai, 1);
  124234. +
  124235. + return ret;
  124236. +}
  124237. +
  124238. +
  124239. +static int tas5713_i2c_remove(struct i2c_client *i2c)
  124240. +{
  124241. + snd_soc_unregister_codec(&i2c->dev);
  124242. + i2c_set_clientdata(i2c, NULL);
  124243. +
  124244. + kfree(priv_data);
  124245. +
  124246. + return 0;
  124247. +}
  124248. +
  124249. +
  124250. +static const struct i2c_device_id tas5713_i2c_id[] = {
  124251. + { "tas5713", 0 },
  124252. + { }
  124253. +};
  124254. +
  124255. +MODULE_DEVICE_TABLE(i2c, tas5713_i2c_id);
  124256. +
  124257. +
  124258. +static struct i2c_driver tas5713_i2c_driver = {
  124259. + .driver = {
  124260. + .name = "tas5713",
  124261. + .owner = THIS_MODULE,
  124262. + .of_match_table = tas5713_of_match,
  124263. + },
  124264. + .probe = tas5713_i2c_probe,
  124265. + .remove = tas5713_i2c_remove,
  124266. + .id_table = tas5713_i2c_id
  124267. +};
  124268. +
  124269. +
  124270. +static int __init tas5713_modinit(void)
  124271. +{
  124272. + int ret = 0;
  124273. +
  124274. + ret = i2c_add_driver(&tas5713_i2c_driver);
  124275. + if (ret) {
  124276. + printk(KERN_ERR "Failed to register tas5713 I2C driver: %d\n",
  124277. + ret);
  124278. + }
  124279. +
  124280. + return ret;
  124281. +}
  124282. +module_init(tas5713_modinit);
  124283. +
  124284. +
  124285. +static void __exit tas5713_exit(void)
  124286. +{
  124287. + i2c_del_driver(&tas5713_i2c_driver);
  124288. +}
  124289. +module_exit(tas5713_exit);
  124290. +
  124291. +
  124292. +MODULE_AUTHOR("Sebastian Eickhoff <basti.eickhoff@googlemail.com>");
  124293. +MODULE_DESCRIPTION("ASoC driver for TAS5713");
  124294. +MODULE_LICENSE("GPL v2");
  124295. diff -Nur linux-3.18.6/sound/soc/codecs/tas5713.h linux-rpi/sound/soc/codecs/tas5713.h
  124296. --- linux-3.18.6/sound/soc/codecs/tas5713.h 1970-01-01 01:00:00.000000000 +0100
  124297. +++ linux-rpi/sound/soc/codecs/tas5713.h 2015-02-09 04:40:48.000000000 +0100
  124298. @@ -0,0 +1,210 @@
  124299. +/*
  124300. + * ASoC Driver for TAS5713
  124301. + *
  124302. + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
  124303. + * Copyright 2014
  124304. + *
  124305. + * This program is free software; you can redistribute it and/or
  124306. + * modify it under the terms of the GNU General Public License
  124307. + * version 2 as published by the Free Software Foundation.
  124308. + *
  124309. + * This program is distributed in the hope that it will be useful, but
  124310. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  124311. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  124312. + * General Public License for more details.
  124313. + */
  124314. +
  124315. +#ifndef _TAS5713_H
  124316. +#define _TAS5713_H
  124317. +
  124318. +
  124319. +// TAS5713 I2C-bus register addresses
  124320. +
  124321. +#define TAS5713_CLOCK_CTRL 0x00
  124322. +#define TAS5713_DEVICE_ID 0x01
  124323. +#define TAS5713_ERROR_STATUS 0x02
  124324. +#define TAS5713_SYSTEM_CTRL1 0x03
  124325. +#define TAS5713_SERIAL_DATA_INTERFACE 0x04
  124326. +#define TAS5713_SYSTEM_CTRL2 0x05
  124327. +#define TAS5713_SOFT_MUTE 0x06
  124328. +#define TAS5713_VOL_MASTER 0x07
  124329. +#define TAS5713_VOL_CH1 0x08
  124330. +#define TAS5713_VOL_CH2 0x09
  124331. +#define TAS5713_VOL_HEADPHONE 0x0A
  124332. +#define TAS5713_VOL_CONFIG 0x0E
  124333. +#define TAS5713_MODULATION_LIMIT 0x10
  124334. +#define TAS5713_IC_DLY_CH1 0x11
  124335. +#define TAS5713_IC_DLY_CH2 0x12
  124336. +#define TAS5713_IC_DLY_CH3 0x13
  124337. +#define TAS5713_IC_DLY_CH4 0x14
  124338. +
  124339. +#define TAS5713_START_STOP_PERIOD 0x1A
  124340. +#define TAS5713_OSC_TRIM 0x1B
  124341. +#define TAS5713_BKND_ERR 0x1C
  124342. +
  124343. +#define TAS5713_INPUT_MUX 0x20
  124344. +#define TAS5713_SRC_SELECT_CH4 0x21
  124345. +#define TAS5713_PWM_MUX 0x25
  124346. +
  124347. +#define TAS5713_CH1_BQ0 0x29
  124348. +#define TAS5713_CH1_BQ1 0x2A
  124349. +#define TAS5713_CH1_BQ2 0x2B
  124350. +#define TAS5713_CH1_BQ3 0x2C
  124351. +#define TAS5713_CH1_BQ4 0x2D
  124352. +#define TAS5713_CH1_BQ5 0x2E
  124353. +#define TAS5713_CH1_BQ6 0x2F
  124354. +#define TAS5713_CH1_BQ7 0x58
  124355. +#define TAS5713_CH1_BQ8 0x59
  124356. +
  124357. +#define TAS5713_CH2_BQ0 0x30
  124358. +#define TAS5713_CH2_BQ1 0x31
  124359. +#define TAS5713_CH2_BQ2 0x32
  124360. +#define TAS5713_CH2_BQ3 0x33
  124361. +#define TAS5713_CH2_BQ4 0x34
  124362. +#define TAS5713_CH2_BQ5 0x35
  124363. +#define TAS5713_CH2_BQ6 0x36
  124364. +#define TAS5713_CH2_BQ7 0x5C
  124365. +#define TAS5713_CH2_BQ8 0x5D
  124366. +
  124367. +#define TAS5713_CH4_BQ0 0x5A
  124368. +#define TAS5713_CH4_BQ1 0x5B
  124369. +#define TAS5713_CH3_BQ0 0x5E
  124370. +#define TAS5713_CH3_BQ1 0x5F
  124371. +
  124372. +#define TAS5713_DRC1_SOFTENING_FILTER_ALPHA_OMEGA 0x3B
  124373. +#define TAS5713_DRC1_ATTACK_RELEASE_RATE 0x3C
  124374. +#define TAS5713_DRC2_SOFTENING_FILTER_ALPHA_OMEGA 0x3E
  124375. +#define TAS5713_DRC2_ATTACK_RELEASE_RATE 0x3F
  124376. +#define TAS5713_DRC1_ATTACK_RELEASE_THRES 0x40
  124377. +#define TAS5713_DRC2_ATTACK_RELEASE_THRES 0x43
  124378. +#define TAS5713_DRC_CTRL 0x46
  124379. +
  124380. +#define TAS5713_BANK_SW_CTRL 0x50
  124381. +#define TAS5713_CH1_OUTPUT_MIXER 0x51
  124382. +#define TAS5713_CH2_OUTPUT_MIXER 0x52
  124383. +#define TAS5713_CH1_INPUT_MIXER 0x53
  124384. +#define TAS5713_CH2_INPUT_MIXER 0x54
  124385. +#define TAS5713_OUTPUT_POST_SCALE 0x56
  124386. +#define TAS5713_OUTPUT_PRESCALE 0x57
  124387. +
  124388. +#define TAS5713_IDF_POST_SCALE 0x62
  124389. +
  124390. +#define TAS5713_CH1_INLINE_MIXER 0x70
  124391. +#define TAS5713_CH1_INLINE_DRC_EN_MIXER 0x71
  124392. +#define TAS5713_CH1_R_CHANNEL_MIXER 0x72
  124393. +#define TAS5713_CH1_L_CHANNEL_MIXER 0x73
  124394. +#define TAS5713_CH2_INLINE_MIXER 0x74
  124395. +#define TAS5713_CH2_INLINE_DRC_EN_MIXER 0x75
  124396. +#define TAS5713_CH2_L_CHANNEL_MIXER 0x76
  124397. +#define TAS5713_CH2_R_CHANNEL_MIXER 0x77
  124398. +
  124399. +#define TAS5713_UPDATE_DEV_ADDR_KEY 0xF8
  124400. +#define TAS5713_UPDATE_DEV_ADDR_REG 0xF9
  124401. +
  124402. +#define TAS5713_REGISTER_COUNT 0x46
  124403. +#define TAS5713_MAX_REGISTER 0xF9
  124404. +
  124405. +
  124406. +// Bitmasks for registers
  124407. +#define TAS5713_SOFT_MUTE_ALL 0x07
  124408. +
  124409. +
  124410. +
  124411. +struct tas5713_init_command {
  124412. + const int size;
  124413. + const char *const data;
  124414. +};
  124415. +
  124416. +static const struct tas5713_init_command tas5713_init_sequence[] = {
  124417. +
  124418. + // Trim oscillator
  124419. + { .size = 2, .data = "\x1B\x00" },
  124420. + // System control register 1 (0x03): block DC
  124421. + { .size = 2, .data = "\x03\x80" },
  124422. + // Mute everything
  124423. + { .size = 2, .data = "\x05\x40" },
  124424. + // Modulation limit register (0x10): 97.7%
  124425. + { .size = 2, .data = "\x10\x02" },
  124426. + // Interchannel delay registers
  124427. + // (0x11, 0x12, 0x13, and 0x14): BD mode
  124428. + { .size = 2, .data = "\x11\xB8" },
  124429. + { .size = 2, .data = "\x12\x60" },
  124430. + { .size = 2, .data = "\x13\xA0" },
  124431. + { .size = 2, .data = "\x14\x48" },
  124432. + // PWM shutdown group register (0x19): no shutdown
  124433. + { .size = 2, .data = "\x19\x00" },
  124434. + // Input multiplexer register (0x20): BD mode
  124435. + { .size = 2, .data = "\x20\x00\x89\x77\x72" },
  124436. + // PWM output mux register (0x25)
  124437. + // Channel 1 --> OUTA, channel 1 neg --> OUTB
  124438. + // Channel 2 --> OUTC, channel 2 neg --> OUTD
  124439. + { .size = 5, .data = "\x25\x01\x02\x13\x45" },
  124440. + // DRC control (0x46): DRC off
  124441. + { .size = 5, .data = "\x46\x00\x00\x00\x00" },
  124442. + // BKND_ERR register (0x1C): 299ms reset period
  124443. + { .size = 2, .data = "\x1C\x07" },
  124444. + // Mute channel 3
  124445. + { .size = 2, .data = "\x0A\xFF" },
  124446. + // Volume configuration register (0x0E): volume slew 512 steps
  124447. + { .size = 2, .data = "\x0E\x90" },
  124448. + // Clock control register (0x00): 44/48kHz, MCLK=64xfs
  124449. + { .size = 2, .data = "\x00\x60" },
  124450. + // Bank switch and eq control (0x50): no bank switching
  124451. + { .size = 5, .data = "\x50\x00\x00\x00\x00" },
  124452. + // Volume registers (0x07, 0x08, 0x09, 0x0A)
  124453. + { .size = 2, .data = "\x07\x20" },
  124454. + { .size = 2, .data = "\x08\x30" },
  124455. + { .size = 2, .data = "\x09\x30" },
  124456. + { .size = 2, .data = "\x0A\xFF" },
  124457. + // 0x72, 0x73, 0x76, 0x77 input mixer:
  124458. + // no intermix between channels
  124459. + { .size = 5, .data = "\x72\x00\x00\x00\x00" },
  124460. + { .size = 5, .data = "\x73\x00\x80\x00\x00" },
  124461. + { .size = 5, .data = "\x76\x00\x00\x00\x00" },
  124462. + { .size = 5, .data = "\x77\x00\x80\x00\x00" },
  124463. + // 0x70, 0x71, 0x74, 0x75 inline DRC mixer:
  124464. + // no inline DRC inmix
  124465. + { .size = 5, .data = "\x70\x00\x80\x00\x00" },
  124466. + { .size = 5, .data = "\x71\x00\x00\x00\x00" },
  124467. + { .size = 5, .data = "\x74\x00\x80\x00\x00" },
  124468. + { .size = 5, .data = "\x75\x00\x00\x00\x00" },
  124469. + // 0x56, 0x57 Output scale
  124470. + { .size = 5, .data = "\x56\x00\x80\x00\x00" },
  124471. + { .size = 5, .data = "\x57\x00\x02\x00\x00" },
  124472. + // 0x3B, 0x3c
  124473. + { .size = 9, .data = "\x3B\x00\x08\x00\x00\x00\x78\x00\x00" },
  124474. + { .size = 9, .data = "\x3C\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
  124475. + { .size = 9, .data = "\x3E\x00\x08\x00\x00\x00\x78\x00\x00" },
  124476. + { .size = 9, .data = "\x3F\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
  124477. + { .size = 9, .data = "\x40\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
  124478. + { .size = 9, .data = "\x43\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
  124479. + // 0x51, 0x52: output mixer
  124480. + { .size = 9, .data = "\x51\x00\x80\x00\x00\x00\x00\x00\x00" },
  124481. + { .size = 9, .data = "\x52\x00\x80\x00\x00\x00\x00\x00\x00" },
  124482. + // PEQ defaults
  124483. + { .size = 21, .data = "\x29\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124484. + { .size = 21, .data = "\x2A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124485. + { .size = 21, .data = "\x2B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124486. + { .size = 21, .data = "\x2C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124487. + { .size = 21, .data = "\x2D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124488. + { .size = 21, .data = "\x2E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124489. + { .size = 21, .data = "\x2F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124490. + { .size = 21, .data = "\x30\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124491. + { .size = 21, .data = "\x31\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124492. + { .size = 21, .data = "\x32\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124493. + { .size = 21, .data = "\x33\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124494. + { .size = 21, .data = "\x34\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124495. + { .size = 21, .data = "\x35\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124496. + { .size = 21, .data = "\x36\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124497. + { .size = 21, .data = "\x58\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124498. + { .size = 21, .data = "\x59\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124499. + { .size = 21, .data = "\x5C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124500. + { .size = 21, .data = "\x5D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124501. + { .size = 21, .data = "\x5E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124502. + { .size = 21, .data = "\x5F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124503. + { .size = 21, .data = "\x5A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124504. + { .size = 21, .data = "\x5B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124505. +};
  124506. +
  124507. +
  124508. +#endif /* _TAS5713_H */
  124509. diff -Nur linux-3.18.6/sound/soc/codecs/wm8804.c linux-rpi/sound/soc/codecs/wm8804.c
  124510. --- linux-3.18.6/sound/soc/codecs/wm8804.c 2015-02-06 15:53:48.000000000 +0100
  124511. +++ linux-rpi/sound/soc/codecs/wm8804.c 2015-02-09 04:40:48.000000000 +0100
  124512. @@ -278,6 +278,7 @@
  124513. blen = 0x1;
  124514. break;
  124515. case 24:
  124516. + case 32:
  124517. blen = 0x2;
  124518. break;
  124519. default:
  124520. @@ -624,7 +625,7 @@
  124521. };
  124522. #define WM8804_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  124523. - SNDRV_PCM_FMTBIT_S24_LE)
  124524. + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  124525. #define WM8804_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  124526. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
  124527. @@ -655,7 +656,7 @@
  124528. .probe = wm8804_probe,
  124529. .remove = wm8804_remove,
  124530. .set_bias_level = wm8804_set_bias_level,
  124531. - .idle_bias_off = true,
  124532. + .idle_bias_off = false,
  124533. .controls = wm8804_snd_controls,
  124534. .num_controls = ARRAY_SIZE(wm8804_snd_controls),